mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
Adds "list-capabilities" entry to A2A_SKILL_HANDLERS in taskExecution.ts (dynamic import pattern, consistent with the 5 existing skills) and adds the 6th skill entry to /.well-known/agent.json with tags [discovery, capabilities] and example questions for agent discovery.
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import type { A2ATask, TaskArtifact } from "./taskManager";
|
|
|
|
type TaskManagerLike = {
|
|
updateTask: (
|
|
taskId: string,
|
|
state: "completed" | "failed",
|
|
artifacts?: Array<{ type: string; content: string }>,
|
|
message?: string
|
|
) => unknown;
|
|
};
|
|
|
|
type StreamTaskResult = {
|
|
artifacts: TaskArtifact[];
|
|
metadata: Record<string, unknown>;
|
|
};
|
|
|
|
export type A2ASkillHandler = (task: A2ATask) => Promise<StreamTaskResult>;
|
|
|
|
export const A2A_SKILL_HANDLERS: Record<string, A2ASkillHandler> = {
|
|
"smart-routing": async (task) => {
|
|
const skillModule = await import("./skills/smartRouting");
|
|
return skillModule.executeSmartRouting(task);
|
|
},
|
|
"quota-management": async (task) => {
|
|
const skillModule = await import("./skills/quotaManagement");
|
|
return skillModule.executeQuotaManagement(task);
|
|
},
|
|
"provider-discovery": async (task) => {
|
|
const skillModule = await import("./skills/providerDiscovery");
|
|
return skillModule.executeProviderDiscovery(task);
|
|
},
|
|
"cost-analysis": async (task) => {
|
|
const skillModule = await import("./skills/costAnalysis");
|
|
return skillModule.executeCostAnalysis(task);
|
|
},
|
|
"health-report": async (task) => {
|
|
const skillModule = await import("./skills/healthReport");
|
|
return skillModule.executeHealthReport(task);
|
|
},
|
|
"list-capabilities": async (task) => {
|
|
const skillModule = await import("./skills/listCapabilities");
|
|
return skillModule.executeListCapabilities(task);
|
|
},
|
|
};
|
|
|
|
export async function executeA2ATaskWithState(
|
|
tm: TaskManagerLike,
|
|
task: A2ATask,
|
|
handler: (task: A2ATask) => Promise<StreamTaskResult>
|
|
) {
|
|
try {
|
|
const result = await handler(task);
|
|
tm.updateTask(task.id, "completed", result.artifacts);
|
|
return result;
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err);
|
|
try {
|
|
tm.updateTask(task.id, "failed", [{ type: "error", content: msg }], msg);
|
|
} catch {
|
|
// Task may already be terminal (e.g., cancelled). Preserve original error.
|
|
}
|
|
throw err;
|
|
}
|
|
}
|