foldkit-agent-a2a 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Agent } from "foldkit-agent";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
-
//#region src/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* The bound contract, with its capability maps left open.
|
|
6
5
|
*
|
|
@@ -85,8 +84,6 @@ interface Task {
|
|
|
85
84
|
readonly status: TaskStatus;
|
|
86
85
|
readonly history: ReadonlyArray<Message>;
|
|
87
86
|
}
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/card.d.ts
|
|
90
87
|
/** Where an A2A client looks for the card. */
|
|
91
88
|
declare const AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
92
89
|
/** One thing this agent can do. Derived from an exposed capability. */
|
|
@@ -152,8 +149,6 @@ interface AgentCardOptions {
|
|
|
152
149
|
* card is static while availability is not.
|
|
153
150
|
*/
|
|
154
151
|
declare const agentCard: (definition: Definition, options: AgentCardOptions) => AgentCard;
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/handler.d.ts
|
|
157
152
|
interface HandlerOptions {
|
|
158
153
|
readonly agent: AgentRuntime;
|
|
159
154
|
/** Tasks kept for `tasks/get`. Defaults to 200. */
|
|
@@ -177,6 +172,5 @@ declare const handler: (options: HandlerOptions) => Handler;
|
|
|
177
172
|
declare namespace agentA2a_d_exports {
|
|
178
173
|
export { A2A_VERSION, AGENT_CARD_PATH, AgentCard, AgentCardOptions, AgentSkill, Handler, HandlerOptions, agentCard, handler };
|
|
179
174
|
}
|
|
180
|
-
//#endregion
|
|
181
175
|
export { agentA2a_d_exports as AgentA2a, type Message, type Part, type Response, type Task, type TaskState, type TaskStatus };
|
|
182
176
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/card.ts","../src/handler.ts","../src/agentA2a.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/card.ts","../src/handler.ts","../src/agentA2a.ts"],"mappings":";;;;;;;;KASY,eAAe,MAAM;KAErB,aAAa,MAAM;;;;;;;;KASnB;UAuBK;WACN;WACA,IAAI;;WAEJ,QAAQ;;UAGF;WACN;WACA,IAAI;WACJ;aAAkB;aAAuB;;;KAGxC,WAAW,UAAU;;;;;;;KA0BrB;UAUK;WACN,OAAO;WACP;;WAEA,UAAU;;;;;;;;cASR,YAAU,OAAA,gBAAA,OAAA;;;;;;;KAQX,cAAc,WAAW;;;;;cAMxB,eAAa,OAAA;;;;;;;;;;;;;;KASd,iBAAiB,cAAc;UAK1B;WACN;WACA;WACA;WACA,QAAQ;WACR,SAAS,cAAc;;;cCtIrB;;UAGI;WACN;WACA;WACA;WACA,MAAM;;;;;;;;;;;;;;;;;;WAkBN,aAAa;;UAGP;WACN;WACA;WACA;;WAEA;;WAEA;WACA;WACA;aACE;aACA;;WAEF,mBAAmB;WACnB,oBAAoB;WACpB,QAAQ,cAAc;WACtB,kBAAkB;WAClB,WAAW,cAAc,eAAe;;cAGtC;UAEI;WACN;WACA;;WAEA;WACA;;WAEA,kBAAkB;WAClB,WAAW,cAAc,eAAe;;;;;;;;;cAUtC,YAAS,YAAgB,YAAU,SAAW,qBAAmB;UCtD7D;WACN,OAAO;;WAEP;;WAEA;WACA,eAAe;;UAGT;WACN,SAAS,qBAAqB,QAAQ;WACtC;;;;;;;;;cA+CE,UAAO,SAAa,mBAAiB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.mjs";
|
|
2
2
|
import { Agent } from "foldkit-agent";
|
|
3
3
|
import { Effect, Schema } from "effect";
|
|
4
|
-
|
|
4
|
+
// src/card.ts
|
|
5
5
|
/** Where an A2A client looks for the card. */
|
|
6
6
|
const AGENT_CARD_PATH = "/.well-known/agent-card.json";
|
|
7
7
|
const A2A_VERSION = "0.3.0";
|
|
@@ -35,8 +35,7 @@ const agentCard = (definition, options) => ({
|
|
|
35
35
|
...options.securitySchemes === void 0 ? {} : { securitySchemes: options.securitySchemes },
|
|
36
36
|
...options.security === void 0 ? {} : { security: options.security }
|
|
37
37
|
});
|
|
38
|
-
|
|
39
|
-
//#region src/types.ts
|
|
38
|
+
// src/types.ts
|
|
40
39
|
/**
|
|
41
40
|
* The envelope, decoded before anything reads a field off it.
|
|
42
41
|
*
|
|
@@ -109,8 +108,7 @@ const text = (body) => ({
|
|
|
109
108
|
kind: "text",
|
|
110
109
|
text: body
|
|
111
110
|
});
|
|
112
|
-
|
|
113
|
-
//#region src/handler.ts
|
|
111
|
+
// src/handler.ts
|
|
114
112
|
const randomId = () => typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `a2a-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
115
113
|
/**
|
|
116
114
|
* How a refused or finished dispatch reads as a task state.
|
|
@@ -296,15 +294,13 @@ const handler = (options) => {
|
|
|
296
294
|
}
|
|
297
295
|
};
|
|
298
296
|
};
|
|
299
|
-
|
|
300
|
-
//#region src/agentA2a.ts
|
|
297
|
+
// src/agentA2a.ts
|
|
301
298
|
var agentA2a_exports = /* @__PURE__ */ __exportAll({
|
|
302
299
|
A2A_VERSION: () => A2A_VERSION,
|
|
303
300
|
AGENT_CARD_PATH: () => AGENT_CARD_PATH,
|
|
304
301
|
agentCard: () => agentCard,
|
|
305
302
|
handler: () => handler
|
|
306
303
|
});
|
|
307
|
-
//#endregion
|
|
308
304
|
export { agentA2a_exports as AgentA2a };
|
|
309
305
|
|
|
310
306
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/card.ts","../src/types.ts","../src/handler.ts","../src/agentA2a.ts"],"sourcesContent":["import { Agent } from 'foldkit-agent'\nimport type { Definition } from './types.js'\n\n/** Where an A2A client looks for the card. */\nexport const AGENT_CARD_PATH = '/.well-known/agent-card.json'\n\n/** One thing this agent can do. Derived from an exposed capability. */\nexport interface AgentSkill {\n readonly id: string\n readonly name: string\n readonly description: string\n readonly tags: ReadonlyArray<string>\n /**\n * The JSON Schema for this skill's input, as the contract derived it.\n *\n * Deliberately beyond the spec. A 0.3.0 `AgentSkill` describes its input only\n * in prose -- `inputModes` carries media types, not shapes -- so a caller has\n * nothing to construct a valid request from, which is the one thing this\n * contract already knows. The card validates because `AgentSkill` leaves\n * `additionalProperties` unset, not because the field is sanctioned.\n *\n * The risk is a later spec claiming this name for something else: the card\n * would not fail, it would quietly mean something a conforming client reads\n * differently. The spec-legal alternative is an `AgentExtension` under\n * `capabilities.extensions`, whose `params` would hold a skill-id-keyed map --\n * worth moving to when a real client consumes this, or the moment A2A\n * proposes a per-skill schema field. A conformance test pins the set of extra\n * keys so a second one cannot appear unnoticed.\n */\n readonly inputSchema: Record<string, unknown>\n}\n\nexport interface AgentCard {\n readonly protocolVersion: string\n readonly name: string\n readonly description: string\n /** Where this agent accepts A2A requests. */\n readonly url: string\n /** The transport bound to `url`. This adapter speaks JSON-RPC and nothing else. */\n readonly preferredTransport: 'JSONRPC'\n readonly version: string\n readonly capabilities: {\n readonly streaming: boolean\n readonly pushNotifications: boolean\n }\n readonly defaultInputModes: ReadonlyArray<string>\n readonly defaultOutputModes: ReadonlyArray<string>\n readonly skills: ReadonlyArray<AgentSkill>\n readonly securitySchemes?: Record<string, unknown> | undefined\n readonly security?: ReadonlyArray<Record<string, ReadonlyArray<string>>> | undefined\n}\n\nexport const A2A_VERSION = '0.3.0'\n\nexport interface AgentCardOptions {\n readonly name: string\n readonly description: string\n /** The endpoint that answers `message/send`. */\n readonly url: string\n readonly version?: string | undefined\n /** Declared so a client knows how to authenticate before it calls. */\n readonly securitySchemes?: Record<string, unknown> | undefined\n readonly security?: ReadonlyArray<Record<string, ReadonlyArray<string>>> | undefined\n}\n\n/**\n * Builds the card an A2A client fetches before calling.\n *\n * Skills are the exposed capabilities: the same descriptors MCP lists as tools.\n * A capability that is only available in some Model states is tagged, because a\n * card is static while availability is not.\n */\nexport const agentCard = (definition: Definition, options: AgentCardOptions): AgentCard => ({\n protocolVersion: A2A_VERSION,\n name: options.name,\n description: options.description,\n url: options.url,\n preferredTransport: 'JSONRPC',\n version: options.version ?? '0.1.0',\n // Streaming and push notifications are not implemented; saying otherwise\n // would have clients wait for events that never arrive.\n capabilities: { streaming: false, pushNotifications: false },\n defaultInputModes: ['application/json'],\n defaultOutputModes: ['application/json'],\n skills: Agent.messages(definition).map(capability => ({\n id: capability.name,\n name: capability.name,\n description: capability.description,\n tags: [\n ...(capability.modelDependent ? ['conditional'] : []),\n ...(capability.requiresAuthorization ? ['authorized'] : []),\n ],\n inputSchema: capability.inputSchema,\n })),\n ...(options.securitySchemes === undefined ? {} : { securitySchemes: options.securitySchemes }),\n ...(options.security === undefined ? {} : { security: options.security }),\n})\n","import { Schema } from 'effect'\nimport type { Agent } from 'foldkit-agent'\n\n/**\n * The bound contract, with its capability maps left open.\n *\n * An adapter reads names off the wire, so it works against the permissive maps\n * rather than a particular application's.\n */\nexport type AgentRuntime = Agent.AgentRuntime<any, any, any, any, any>\n\nexport type Definition = Agent.Definition<any, any, any, any, any>\n\n/**\n * The JSON-RPC envelope A2A uses.\n *\n * Deliberately a local copy rather than shared with `foldkit-agent-mcp`: two\n * protocols that happen to use the same envelope should not be coupled through\n * it.\n */\nexport type Id = string | number\n\nexport interface Request {\n readonly jsonrpc: '2.0'\n readonly id: Id\n readonly method: string\n /** Unvalidated until a method decides what its own params must look like. */\n readonly params?: unknown\n}\n\n/**\n * The envelope, decoded before anything reads a field off it.\n *\n * `params` stays `unknown` here: what a method requires is the method's\n * business, and deciding it here would answer bad params with the wrong code.\n */\nexport const RequestSchema = Schema.Struct({\n jsonrpc: Schema.Literal('2.0'),\n id: Schema.optional(Schema.Union([Schema.String, Schema.Number])),\n method: Schema.String,\n params: Schema.optional(Schema.Unknown),\n})\n\nexport interface Success {\n readonly jsonrpc: '2.0'\n readonly id: Id\n /** Every method this adapter answers successfully answers with a task. */\n readonly result: Task\n}\n\nexport interface Failure {\n readonly jsonrpc: '2.0'\n readonly id: Id | null\n readonly error: { readonly code: number; readonly message: string }\n}\n\nexport type Response = Success | Failure\n\nexport const code = {\n INVALID_REQUEST: -32600,\n METHOD_NOT_FOUND: -32601,\n INVALID_PARAMS: -32602,\n /** A2A: the task id is not one this agent issued. */\n TASK_NOT_FOUND: -32001,\n /** A2A: the task has already settled, so there is nothing left to cancel. */\n TASK_NOT_CANCELABLE: -32002,\n} as const\n\nexport const success = (id: Id, result: Task): Success => ({ jsonrpc: '2.0', id, result })\n\nexport const failure = (id: Id | null, errorCode: number, message: string): Failure => ({\n jsonrpc: '2.0',\n id,\n error: { code: errorCode, message },\n})\n\n/**\n * The subset of A2A 0.3.0 task states this adapter produces.\n *\n * `input-required`, `auth-required` and `unknown` are spec states no dispatch\n * here can reach, so they are left out rather than declared and never used.\n */\nexport type TaskState = 'submitted' | 'working' | 'completed' | 'failed' | 'canceled' | 'rejected'\n\n/** States a task cannot leave. A later settle must not overwrite one. */\nexport const terminal: ReadonlySet<TaskState> = new Set<TaskState>([\n 'completed',\n 'failed',\n 'canceled',\n 'rejected',\n])\n\nexport interface TaskStatus {\n readonly state: TaskState\n readonly timestamp: string\n /** What happened, in the agent's own words. */\n readonly message?: Message | undefined\n}\n\n/**\n * A part carries either text or data, and which one is not optional.\n *\n * A single struct with both fields optional would accept\n * `{ kind: 'data' }` and leave every reader to re-check.\n */\nexport const PartSchema = Schema.Union([\n Schema.Struct({ kind: Schema.Literal('text'), text: Schema.String }),\n Schema.Struct({\n kind: Schema.Literal('data'),\n data: Schema.Record(Schema.String, Schema.Unknown),\n }),\n])\n\nexport type Part = typeof PartSchema.Type\n\n/**\n * `kind` is required by the spec, not decoration: `Task | Message` is a union a\n * client discriminates on, so a message without it is not a Message.\n */\nexport const MessageSchema = Schema.Struct({\n kind: Schema.Literal('message'),\n role: Schema.Literals(['user', 'agent']),\n parts: Schema.Array(PartSchema),\n messageId: Schema.String,\n taskId: Schema.optional(Schema.String),\n contextId: Schema.optional(Schema.String),\n})\n\nexport type Message = typeof MessageSchema.Type\n\n/** What `message/send` requires of its params. */\nexport const SendParamsSchema = Schema.Struct({ message: MessageSchema })\n\nexport interface Task {\n readonly kind: 'task'\n readonly id: string\n readonly contextId: string\n readonly status: TaskStatus\n readonly history: ReadonlyArray<Message>\n}\n\nexport const text = (body: string): Part => ({ kind: 'text', text: body })\n","import { Agent } from 'foldkit-agent'\nimport { Effect, Schema } from 'effect'\nimport {\n type AgentRuntime,\n type Id,\n type Message,\n RequestSchema,\n type Response,\n SendParamsSchema,\n type Task,\n type TaskState,\n code,\n failure,\n success,\n terminal,\n text,\n} from './types.js'\n\nexport interface HandlerOptions {\n readonly agent: AgentRuntime\n /** Tasks kept for `tasks/get`. Defaults to 200. */\n readonly capacity?: number | undefined\n /** Injected for tests. */\n readonly newId?: (() => string) | undefined\n readonly clock?: (() => Date) | undefined\n}\n\nexport interface Handler {\n readonly handle: (message: unknown) => Promise<Response | undefined>\n readonly close: () => void\n}\n\nconst randomId = (): string =>\n typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'\n ? crypto.randomUUID()\n : `a2a-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`\n\n/**\n * How a refused or finished dispatch reads as a task state.\n *\n * `rejected` is for a request the agent declined outright -- an unknown skill,\n * bad input, a caller who may not. `failed` is for work that was accepted and\n * did not succeed, which is a different thing to a client deciding what to do\n * next.\n */\nconst stateFor = (failureTag: string): TaskState => {\n switch (failureTag) {\n case 'AgentCancelledError':\n return 'canceled'\n case 'AgentCompletionTimeoutError':\n return 'failed'\n default:\n return 'rejected'\n }\n}\n\n/** The capability and input a client asked for, carried in a data part. */\nconst skillFrom = (\n message: Message,\n): { readonly skill: string; readonly input: unknown } | undefined => {\n const part = message.parts.find(candidate => candidate.kind === 'data')\n if (part === undefined) return undefined\n const skill = part.data['skill']\n return typeof skill === 'string' ? { skill, input: part.data['input'] ?? {} } : undefined\n}\n\nconst decodeRequest = Schema.decodeUnknownResult(RequestSchema)\nconst decodeSendParams = Schema.decodeUnknownResult(SendParamsSchema)\n\n/**\n * Serves a contract as an A2A agent, with no transport attached.\n *\n * One exposed capability is one skill. A capability with no completion contract\n * finishes at validated dispatch, so its task is `completed` immediately; one\n * that declares completion finishes when its Message arrives.\n */\nexport const handler = (options: HandlerOptions): Handler => {\n const { agent } = options\n const capacity = Math.max(1, options.capacity ?? 200)\n const newId = options.newId ?? randomId\n const clock = options.clock ?? (() => new Date())\n\n const tasks = new Map<string, Task>()\n const running = new Map<string, AbortController>()\n\n const remember = (task: Task): Task => {\n tasks.set(task.id, task)\n if (tasks.size > capacity) {\n const oldest = tasks.keys().next().value\n if (oldest !== undefined) tasks.delete(oldest)\n }\n return task\n }\n\n /**\n * Records how a task finished, unless it already finished.\n *\n * A cancel lands while the dispatch is still unwinding, so the settling write\n * arrives second and must not undo it. The task that stands is returned, so\n * the pending `message/send` answers with the same outcome `tasks/get` shows.\n */\n const settle = (task: Task): Task => {\n const current = tasks.get(task.id)\n return current !== undefined && terminal.has(current.status.state) ? current : remember(task)\n }\n\n const agentMessage = (body: string, taskId: string, contextId: string): Message => ({\n kind: 'message',\n role: 'agent',\n parts: [text(body)],\n messageId: newId(),\n taskId,\n contextId,\n })\n\n const send = async (id: Id, params: unknown): Promise<Response> => {\n const decoded = decodeSendParams(params)\n if (decoded._tag === 'Failure') {\n return failure(\n id,\n code.INVALID_PARAMS,\n 'message/send needs params as { message } with kind \"message\", a role, a messageId, and parts',\n )\n }\n\n const { message } = decoded.success\n const asked = skillFrom(message)\n\n if (asked === undefined) {\n return failure(\n id,\n code.INVALID_PARAMS,\n 'message/send needs a data part naming a skill, as { skill, input }',\n )\n }\n\n const taskId = newId()\n const contextId = message.contextId ?? newId()\n const history: ReadonlyArray<Message> = [message]\n\n const controller = new AbortController()\n running.set(taskId, controller)\n\n // Recorded before the work starts: a task a client cannot address while it\n // runs is a task it cannot get or cancel.\n remember({\n kind: 'task',\n id: taskId,\n contextId,\n status: { state: 'working', timestamp: clock().toISOString() },\n history,\n })\n\n try {\n // The signal reaches the run as well as the invocation. The runtime now\n // races the completion wait against it, so the invocation settles on its\n // own; interrupting the fiber additionally covers what the runtime cannot\n // see -- an abort landing while Schema decoding or a suspending authorize\n // hook is still in flight.\n const outcome = await Effect.runPromise(\n Effect.result(\n agent.messages.dispatchUnknown(asked.skill, asked.input, {\n id: taskId,\n transport: 'a2a',\n signal: controller.signal,\n }),\n ),\n { signal: controller.signal },\n )\n\n if (outcome._tag === 'Failure') {\n const error = outcome.failure\n return success(\n id,\n settle({\n kind: 'task',\n id: taskId,\n contextId,\n status: {\n state: stateFor(error._tag),\n timestamp: clock().toISOString(),\n message: agentMessage(error.message, taskId, contextId),\n },\n history,\n }),\n )\n }\n\n const result = outcome.success\n const summary = Agent.summarize(result)\n // A declared failure Message is work that ran and did not succeed.\n const state: TaskState = summary.ok ? 'completed' : 'failed'\n\n return success(\n id,\n settle({\n kind: 'task',\n id: taskId,\n contextId,\n status: {\n state,\n timestamp: clock().toISOString(),\n message: agentMessage(summary.text, taskId, contextId),\n },\n history,\n }),\n )\n } catch {\n return success(\n id,\n settle({\n kind: 'task',\n id: taskId,\n contextId,\n status: {\n state: 'failed',\n timestamp: clock().toISOString(),\n message: agentMessage(`Skill \"${asked.skill}\" failed unexpectedly`, taskId, contextId),\n },\n history,\n }),\n )\n } finally {\n running.delete(taskId)\n }\n }\n\n const handleRequest = async (id: Id, method: string, raw: unknown): Promise<Response> => {\n const params: Record<string, unknown> =\n typeof raw === 'object' && raw !== null && !Array.isArray(raw)\n ? (raw as Record<string, unknown>)\n : {}\n\n switch (method) {\n case 'message/send':\n return send(id, raw)\n\n case 'tasks/get': {\n const taskId = params['id']\n const task = typeof taskId === 'string' ? tasks.get(taskId) : undefined\n return task === undefined\n ? failure(id, code.TASK_NOT_FOUND, 'No such task')\n : success(id, task)\n }\n\n case 'tasks/cancel': {\n const taskId = params['id']\n const task = typeof taskId === 'string' ? tasks.get(taskId) : undefined\n if (task === undefined) return failure(id, code.TASK_NOT_FOUND, 'No such task')\n\n if (terminal.has(task.status.state)) {\n return failure(id, code.TASK_NOT_CANCELABLE, 'Task cannot be canceled')\n }\n\n // The canceled state is recorded before the abort, so the dispatch it\n // interrupts cannot settle over it on its way out. Cancelling stops the\n // waiting, not the Messages already dispatched.\n const canceled = remember({\n ...task,\n status: {\n state: 'canceled',\n timestamp: clock().toISOString(),\n message: agentMessage('Canceled by the client', task.id, task.contextId),\n },\n })\n running.get(task.id)?.abort()\n\n return success(id, canceled)\n }\n\n // Streaming is declared unsupported on the card, so it is refused here\n // rather than answered with something a client cannot consume.\n case 'message/stream':\n return failure(id, code.METHOD_NOT_FOUND, 'This agent does not support streaming')\n\n default:\n return failure(id, code.METHOD_NOT_FOUND, `Unknown method: ${method}`)\n }\n }\n\n return {\n handle: async (incoming: unknown): Promise<Response | undefined> => {\n if (Array.isArray(incoming)) {\n return failure(null, code.INVALID_REQUEST, 'Batched requests are not supported')\n }\n\n const decoded = decodeRequest(incoming)\n if (decoded._tag === 'Failure') {\n return failure(null, code.INVALID_REQUEST, 'Not a JSON-RPC 2.0 message')\n }\n\n const request = decoded.success\n // A notification carries no id and expects no reply.\n if (request.id === undefined) return undefined\n\n return handleRequest(request.id, request.method, request.params)\n },\n\n close: () => {\n for (const controller of running.values()) controller.abort()\n running.clear()\n tasks.clear()\n },\n }\n}\n","export {\n AGENT_CARD_PATH,\n A2A_VERSION,\n agentCard,\n type AgentCard,\n type AgentCardOptions,\n type AgentSkill,\n} from './card.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;GACtC,IAAI,QAAQ,SAAS,WACnB,OAAO,QAAQ,MAAM,KAAK,iBAAiB,4BAA4B;GAGzE,MAAM,UAAU,QAAQ;GAExB,IAAI,QAAQ,OAAO,KAAA,GAAW,OAAO,KAAA;GAErC,OAAO,cAAc,QAAQ,IAAI,QAAQ,QAAQ,QAAQ,MAAM;EACjE;EAEA,aAAa;GACX,KAAK,MAAM,cAAc,QAAQ,OAAO,GAAG,WAAW,MAAM;GAC5D,QAAQ,MAAM;GACd,MAAM,MAAM;EACd;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/card.ts","../src/types.ts","../src/handler.ts","../src/agentA2a.ts"],"sourcesContent":["import { Agent } from 'foldkit-agent'\nimport type { Definition } from './types.js'\n\n/** Where an A2A client looks for the card. */\nexport const AGENT_CARD_PATH = '/.well-known/agent-card.json'\n\n/** One thing this agent can do. Derived from an exposed capability. */\nexport interface AgentSkill {\n readonly id: string\n readonly name: string\n readonly description: string\n readonly tags: ReadonlyArray<string>\n /**\n * The JSON Schema for this skill's input, as the contract derived it.\n *\n * Deliberately beyond the spec. A 0.3.0 `AgentSkill` describes its input only\n * in prose -- `inputModes` carries media types, not shapes -- so a caller has\n * nothing to construct a valid request from, which is the one thing this\n * contract already knows. The card validates because `AgentSkill` leaves\n * `additionalProperties` unset, not because the field is sanctioned.\n *\n * The risk is a later spec claiming this name for something else: the card\n * would not fail, it would quietly mean something a conforming client reads\n * differently. The spec-legal alternative is an `AgentExtension` under\n * `capabilities.extensions`, whose `params` would hold a skill-id-keyed map --\n * worth moving to when a real client consumes this, or the moment A2A\n * proposes a per-skill schema field. A conformance test pins the set of extra\n * keys so a second one cannot appear unnoticed.\n */\n readonly inputSchema: Record<string, unknown>\n}\n\nexport interface AgentCard {\n readonly protocolVersion: string\n readonly name: string\n readonly description: string\n /** Where this agent accepts A2A requests. */\n readonly url: string\n /** The transport bound to `url`. This adapter speaks JSON-RPC and nothing else. */\n readonly preferredTransport: 'JSONRPC'\n readonly version: string\n readonly capabilities: {\n readonly streaming: boolean\n readonly pushNotifications: boolean\n }\n readonly defaultInputModes: ReadonlyArray<string>\n readonly defaultOutputModes: ReadonlyArray<string>\n readonly skills: ReadonlyArray<AgentSkill>\n readonly securitySchemes?: Record<string, unknown> | undefined\n readonly security?: ReadonlyArray<Record<string, ReadonlyArray<string>>> | undefined\n}\n\nexport const A2A_VERSION = '0.3.0'\n\nexport interface AgentCardOptions {\n readonly name: string\n readonly description: string\n /** The endpoint that answers `message/send`. */\n readonly url: string\n readonly version?: string | undefined\n /** Declared so a client knows how to authenticate before it calls. */\n readonly securitySchemes?: Record<string, unknown> | undefined\n readonly security?: ReadonlyArray<Record<string, ReadonlyArray<string>>> | undefined\n}\n\n/**\n * Builds the card an A2A client fetches before calling.\n *\n * Skills are the exposed capabilities: the same descriptors MCP lists as tools.\n * A capability that is only available in some Model states is tagged, because a\n * card is static while availability is not.\n */\nexport const agentCard = (definition: Definition, options: AgentCardOptions): AgentCard => ({\n protocolVersion: A2A_VERSION,\n name: options.name,\n description: options.description,\n url: options.url,\n preferredTransport: 'JSONRPC',\n version: options.version ?? '0.1.0',\n // Streaming and push notifications are not implemented; saying otherwise\n // would have clients wait for events that never arrive.\n capabilities: { streaming: false, pushNotifications: false },\n defaultInputModes: ['application/json'],\n defaultOutputModes: ['application/json'],\n skills: Agent.messages(definition).map(capability => ({\n id: capability.name,\n name: capability.name,\n description: capability.description,\n tags: [\n ...(capability.modelDependent ? ['conditional'] : []),\n ...(capability.requiresAuthorization ? ['authorized'] : []),\n ],\n inputSchema: capability.inputSchema,\n })),\n ...(options.securitySchemes === undefined ? {} : { securitySchemes: options.securitySchemes }),\n ...(options.security === undefined ? {} : { security: options.security }),\n})\n","import { Schema } from 'effect'\nimport type { Agent } from 'foldkit-agent'\n\n/**\n * The bound contract, with its capability maps left open.\n *\n * An adapter reads names off the wire, so it works against the permissive maps\n * rather than a particular application's.\n */\nexport type AgentRuntime = Agent.AgentRuntime<any, any, any, any, any>\n\nexport type Definition = Agent.Definition<any, any, any, any, any>\n\n/**\n * The JSON-RPC envelope A2A uses.\n *\n * Deliberately a local copy rather than shared with `foldkit-agent-mcp`: two\n * protocols that happen to use the same envelope should not be coupled through\n * it.\n */\nexport type Id = string | number\n\nexport interface Request {\n readonly jsonrpc: '2.0'\n readonly id: Id\n readonly method: string\n /** Unvalidated until a method decides what its own params must look like. */\n readonly params?: unknown\n}\n\n/**\n * The envelope, decoded before anything reads a field off it.\n *\n * `params` stays `unknown` here: what a method requires is the method's\n * business, and deciding it here would answer bad params with the wrong code.\n */\nexport const RequestSchema = Schema.Struct({\n jsonrpc: Schema.Literal('2.0'),\n id: Schema.optional(Schema.Union([Schema.String, Schema.Number])),\n method: Schema.String,\n params: Schema.optional(Schema.Unknown),\n})\n\nexport interface Success {\n readonly jsonrpc: '2.0'\n readonly id: Id\n /** Every method this adapter answers successfully answers with a task. */\n readonly result: Task\n}\n\nexport interface Failure {\n readonly jsonrpc: '2.0'\n readonly id: Id | null\n readonly error: { readonly code: number; readonly message: string }\n}\n\nexport type Response = Success | Failure\n\nexport const code = {\n INVALID_REQUEST: -32600,\n METHOD_NOT_FOUND: -32601,\n INVALID_PARAMS: -32602,\n /** A2A: the task id is not one this agent issued. */\n TASK_NOT_FOUND: -32001,\n /** A2A: the task has already settled, so there is nothing left to cancel. */\n TASK_NOT_CANCELABLE: -32002,\n} as const\n\nexport const success = (id: Id, result: Task): Success => ({ jsonrpc: '2.0', id, result })\n\nexport const failure = (id: Id | null, errorCode: number, message: string): Failure => ({\n jsonrpc: '2.0',\n id,\n error: { code: errorCode, message },\n})\n\n/**\n * The subset of A2A 0.3.0 task states this adapter produces.\n *\n * `input-required`, `auth-required` and `unknown` are spec states no dispatch\n * here can reach, so they are left out rather than declared and never used.\n */\nexport type TaskState = 'submitted' | 'working' | 'completed' | 'failed' | 'canceled' | 'rejected'\n\n/** States a task cannot leave. A later settle must not overwrite one. */\nexport const terminal: ReadonlySet<TaskState> = new Set<TaskState>([\n 'completed',\n 'failed',\n 'canceled',\n 'rejected',\n])\n\nexport interface TaskStatus {\n readonly state: TaskState\n readonly timestamp: string\n /** What happened, in the agent's own words. */\n readonly message?: Message | undefined\n}\n\n/**\n * A part carries either text or data, and which one is not optional.\n *\n * A single struct with both fields optional would accept\n * `{ kind: 'data' }` and leave every reader to re-check.\n */\nexport const PartSchema = Schema.Union([\n Schema.Struct({ kind: Schema.Literal('text'), text: Schema.String }),\n Schema.Struct({\n kind: Schema.Literal('data'),\n data: Schema.Record(Schema.String, Schema.Unknown),\n }),\n])\n\nexport type Part = typeof PartSchema.Type\n\n/**\n * `kind` is required by the spec, not decoration: `Task | Message` is a union a\n * client discriminates on, so a message without it is not a Message.\n */\nexport const MessageSchema = Schema.Struct({\n kind: Schema.Literal('message'),\n role: Schema.Literals(['user', 'agent']),\n parts: Schema.Array(PartSchema),\n messageId: Schema.String,\n taskId: Schema.optional(Schema.String),\n contextId: Schema.optional(Schema.String),\n})\n\nexport type Message = typeof MessageSchema.Type\n\n/** What `message/send` requires of its params. */\nexport const SendParamsSchema = Schema.Struct({ message: MessageSchema })\n\nexport interface Task {\n readonly kind: 'task'\n readonly id: string\n readonly contextId: string\n readonly status: TaskStatus\n readonly history: ReadonlyArray<Message>\n}\n\nexport const text = (body: string): Part => ({ kind: 'text', text: body })\n","import { Agent } from 'foldkit-agent'\nimport { Effect, Schema } from 'effect'\nimport {\n type AgentRuntime,\n type Id,\n type Message,\n RequestSchema,\n type Response,\n SendParamsSchema,\n type Task,\n type TaskState,\n code,\n failure,\n success,\n terminal,\n text,\n} from './types.js'\n\nexport interface HandlerOptions {\n readonly agent: AgentRuntime\n /** Tasks kept for `tasks/get`. Defaults to 200. */\n readonly capacity?: number | undefined\n /** Injected for tests. */\n readonly newId?: (() => string) | undefined\n readonly clock?: (() => Date) | undefined\n}\n\nexport interface Handler {\n readonly handle: (message: unknown) => Promise<Response | undefined>\n readonly close: () => void\n}\n\nconst randomId = (): string =>\n typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'\n ? crypto.randomUUID()\n : `a2a-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`\n\n/**\n * How a refused or finished dispatch reads as a task state.\n *\n * `rejected` is for a request the agent declined outright -- an unknown skill,\n * bad input, a caller who may not. `failed` is for work that was accepted and\n * did not succeed, which is a different thing to a client deciding what to do\n * next.\n */\nconst stateFor = (failureTag: string): TaskState => {\n switch (failureTag) {\n case 'AgentCancelledError':\n return 'canceled'\n case 'AgentCompletionTimeoutError':\n return 'failed'\n default:\n return 'rejected'\n }\n}\n\n/** The capability and input a client asked for, carried in a data part. */\nconst skillFrom = (\n message: Message,\n): { readonly skill: string; readonly input: unknown } | undefined => {\n const part = message.parts.find(candidate => candidate.kind === 'data')\n if (part === undefined) return undefined\n const skill = part.data['skill']\n return typeof skill === 'string' ? { skill, input: part.data['input'] ?? {} } : undefined\n}\n\nconst decodeRequest = Schema.decodeUnknownResult(RequestSchema)\nconst decodeSendParams = Schema.decodeUnknownResult(SendParamsSchema)\n\n/**\n * Serves a contract as an A2A agent, with no transport attached.\n *\n * One exposed capability is one skill. A capability with no completion contract\n * finishes at validated dispatch, so its task is `completed` immediately; one\n * that declares completion finishes when its Message arrives.\n */\nexport const handler = (options: HandlerOptions): Handler => {\n const { agent } = options\n const capacity = Math.max(1, options.capacity ?? 200)\n const newId = options.newId ?? randomId\n const clock = options.clock ?? (() => new Date())\n\n const tasks = new Map<string, Task>()\n const running = new Map<string, AbortController>()\n\n const remember = (task: Task): Task => {\n tasks.set(task.id, task)\n if (tasks.size > capacity) {\n const oldest = tasks.keys().next().value\n if (oldest !== undefined) tasks.delete(oldest)\n }\n return task\n }\n\n /**\n * Records how a task finished, unless it already finished.\n *\n * A cancel lands while the dispatch is still unwinding, so the settling write\n * arrives second and must not undo it. The task that stands is returned, so\n * the pending `message/send` answers with the same outcome `tasks/get` shows.\n */\n const settle = (task: Task): Task => {\n const current = tasks.get(task.id)\n return current !== undefined && terminal.has(current.status.state) ? current : remember(task)\n }\n\n const agentMessage = (body: string, taskId: string, contextId: string): Message => ({\n kind: 'message',\n role: 'agent',\n parts: [text(body)],\n messageId: newId(),\n taskId,\n contextId,\n })\n\n const send = async (id: Id, params: unknown): Promise<Response> => {\n const decoded = decodeSendParams(params)\n if (decoded._tag === 'Failure') {\n return failure(\n id,\n code.INVALID_PARAMS,\n 'message/send needs params as { message } with kind \"message\", a role, a messageId, and parts',\n )\n }\n\n const { message } = decoded.success\n const asked = skillFrom(message)\n\n if (asked === undefined) {\n return failure(\n id,\n code.INVALID_PARAMS,\n 'message/send needs a data part naming a skill, as { skill, input }',\n )\n }\n\n const taskId = newId()\n const contextId = message.contextId ?? newId()\n const history: ReadonlyArray<Message> = [message]\n\n const controller = new AbortController()\n running.set(taskId, controller)\n\n // Recorded before the work starts: a task a client cannot address while it\n // runs is a task it cannot get or cancel.\n remember({\n kind: 'task',\n id: taskId,\n contextId,\n status: { state: 'working', timestamp: clock().toISOString() },\n history,\n })\n\n try {\n // The signal reaches the run as well as the invocation. The runtime now\n // races the completion wait against it, so the invocation settles on its\n // own; interrupting the fiber additionally covers what the runtime cannot\n // see -- an abort landing while Schema decoding or a suspending authorize\n // hook is still in flight.\n const outcome = await Effect.runPromise(\n Effect.result(\n agent.messages.dispatchUnknown(asked.skill, asked.input, {\n id: taskId,\n transport: 'a2a',\n signal: controller.signal,\n }),\n ),\n { signal: controller.signal },\n )\n\n if (outcome._tag === 'Failure') {\n const error = outcome.failure\n return success(\n id,\n settle({\n kind: 'task',\n id: taskId,\n contextId,\n status: {\n state: stateFor(error._tag),\n timestamp: clock().toISOString(),\n message: agentMessage(error.message, taskId, contextId),\n },\n history,\n }),\n )\n }\n\n const result = outcome.success\n const summary = Agent.summarize(result)\n // A declared failure Message is work that ran and did not succeed.\n const state: TaskState = summary.ok ? 'completed' : 'failed'\n\n return success(\n id,\n settle({\n kind: 'task',\n id: taskId,\n contextId,\n status: {\n state,\n timestamp: clock().toISOString(),\n message: agentMessage(summary.text, taskId, contextId),\n },\n history,\n }),\n )\n } catch {\n return success(\n id,\n settle({\n kind: 'task',\n id: taskId,\n contextId,\n status: {\n state: 'failed',\n timestamp: clock().toISOString(),\n message: agentMessage(`Skill \"${asked.skill}\" failed unexpectedly`, taskId, contextId),\n },\n history,\n }),\n )\n } finally {\n running.delete(taskId)\n }\n }\n\n const handleRequest = async (id: Id, method: string, raw: unknown): Promise<Response> => {\n const params: Record<string, unknown> =\n typeof raw === 'object' && raw !== null && !Array.isArray(raw)\n ? (raw as Record<string, unknown>)\n : {}\n\n switch (method) {\n case 'message/send':\n return send(id, raw)\n\n case 'tasks/get': {\n const taskId = params['id']\n const task = typeof taskId === 'string' ? tasks.get(taskId) : undefined\n return task === undefined\n ? failure(id, code.TASK_NOT_FOUND, 'No such task')\n : success(id, task)\n }\n\n case 'tasks/cancel': {\n const taskId = params['id']\n const task = typeof taskId === 'string' ? tasks.get(taskId) : undefined\n if (task === undefined) return failure(id, code.TASK_NOT_FOUND, 'No such task')\n\n if (terminal.has(task.status.state)) {\n return failure(id, code.TASK_NOT_CANCELABLE, 'Task cannot be canceled')\n }\n\n // The canceled state is recorded before the abort, so the dispatch it\n // interrupts cannot settle over it on its way out. Cancelling stops the\n // waiting, not the Messages already dispatched.\n const canceled = remember({\n ...task,\n status: {\n state: 'canceled',\n timestamp: clock().toISOString(),\n message: agentMessage('Canceled by the client', task.id, task.contextId),\n },\n })\n running.get(task.id)?.abort()\n\n return success(id, canceled)\n }\n\n // Streaming is declared unsupported on the card, so it is refused here\n // rather than answered with something a client cannot consume.\n case 'message/stream':\n return failure(id, code.METHOD_NOT_FOUND, 'This agent does not support streaming')\n\n default:\n return failure(id, code.METHOD_NOT_FOUND, `Unknown method: ${method}`)\n }\n }\n\n return {\n handle: async (incoming: unknown): Promise<Response | undefined> => {\n if (Array.isArray(incoming)) {\n return failure(null, code.INVALID_REQUEST, 'Batched requests are not supported')\n }\n\n const decoded = decodeRequest(incoming)\n if (decoded._tag === 'Failure') {\n return failure(null, code.INVALID_REQUEST, 'Not a JSON-RPC 2.0 message')\n }\n\n const request = decoded.success\n // A notification carries no id and expects no reply.\n if (request.id === undefined) return undefined\n\n return handleRequest(request.id, request.method, request.params)\n },\n\n close: () => {\n for (const controller of running.values()) controller.abort()\n running.clear()\n tasks.clear()\n },\n }\n}\n","export {\n AGENT_CARD_PATH,\n A2A_VERSION,\n agentCard,\n type AgentCard,\n type AgentCardOptions,\n type AgentSkill,\n} from './card.js'\nexport { handler, type Handler, type HandlerOptions } from './handler.js'\n"],"mappings":";;;;;AAIA,MAAa,kBAAkB;AAgD/B,MAAa,cAAc;;;;;;;;AAoB3B,MAAa,aAAa,YAAwB,aAA0C;CAC1F,iBAAiB;CACjB,MAAM,QAAQ;CACd,aAAa,QAAQ;CACrB,KAAK,QAAQ;CACb,oBAAoB;CACpB,SAAS,QAAQ,WAAW;CAG5B,cAAc;EAAE,WAAW;EAAO,mBAAmB;CAAM;CAC3D,mBAAmB,CAAC,kBAAkB;CACtC,oBAAoB,CAAC,kBAAkB;CACvC,QAAQ,MAAM,SAAS,UAAU,CAAC,CAAC,KAAI,gBAAe;EACpD,IAAI,WAAW;EACf,MAAM,WAAW;EACjB,aAAa,WAAW;EACxB,MAAM,CACJ,GAAI,WAAW,iBAAiB,CAAC,aAAa,IAAI,CAAC,GACnD,GAAI,WAAW,wBAAwB,CAAC,YAAY,IAAI,CAAC,CAC3D;EACA,aAAa,WAAW;CAC1B,EAAE;CACF,GAAI,QAAQ,oBAAoB,KAAA,IAAY,CAAC,IAAI,EAAE,iBAAiB,QAAQ,gBAAgB;CAC5F,GAAI,QAAQ,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,QAAQ,SAAS;AACzE;;;;;;;;AC5DA,MAAa,gBAAgB,OAAO,OAAO;CACzC,SAAS,OAAO,QAAQ,KAAK;CAC7B,IAAI,OAAO,SAAS,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC,CA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,IAAI,QAAQ;GAC7B;GAIA,KAAK,kBACH,OAAO,QAAQ,IAAI,KAAK,kBAAkB,uCAAuC;GAEnF,SACE,OAAO,QAAQ,IAAI,KAAK,kBAAkB,mBAAmB,QAAQ;EACzE;CACF;CAEA,OAAO;EACL,QAAQ,OAAO,aAAqD;GAClE,IAAI,MAAM,QAAQ,QAAQ,GACxB,OAAO,QAAQ,MAAM,KAAK,iBAAiB,oCAAoC;GAGjF,MAAM,UAAU,cAAc,QAAQ;GACtC,IAAI,QAAQ,SAAS,WACnB,OAAO,QAAQ,MAAM,KAAK,iBAAiB,4BAA4B;GAGzE,MAAM,UAAU,QAAQ;GAExB,IAAI,QAAQ,OAAO,KAAA,GAAW,OAAO,KAAA;GAErC,OAAO,cAAc,QAAQ,IAAI,QAAQ,QAAQ,QAAQ,MAAM;EACjE;EAEA,aAAa;GACX,KAAK,MAAM,cAAc,QAAQ,OAAO,GAAG,WAAW,MAAM;GAC5D,QAAQ,MAAM;GACd,MAAM,MAAM;EACd;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
@@ -9,5 +9,4 @@ var __exportAll = (all, no_symbols) => {
|
|
|
9
9
|
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
10
|
return target;
|
|
11
11
|
};
|
|
12
|
-
//#endregion
|
|
13
12
|
export { __exportAll as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-agent-a2a",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A2A adapter for foldkit-agent. Serves a Foldkit agent contract as an A2A agent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -37,20 +37,20 @@
|
|
|
37
37
|
"LICENSE"
|
|
38
38
|
],
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"effect": "^4.
|
|
41
|
-
"foldkit": "^0.
|
|
42
|
-
"foldkit-agent": "^0.
|
|
40
|
+
"effect": "^4.1.0",
|
|
41
|
+
"foldkit": "^0.170.0",
|
|
42
|
+
"foldkit-agent": "^0.10.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@effect/platform-browser": "^4.
|
|
46
|
-
"effect": "^4.
|
|
47
|
-
"foldkit": "0.
|
|
45
|
+
"@effect/platform-browser": "^4.1.1",
|
|
46
|
+
"effect": "^4.1.1",
|
|
47
|
+
"foldkit": "0.170.0",
|
|
48
48
|
"tsdown": "^0.23.1",
|
|
49
49
|
"typescript": "7.0.2",
|
|
50
|
-
"foldkit-agent": "0.
|
|
50
|
+
"foldkit-agent": "0.10.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "tsdown",
|
|
53
|
+
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|
|
54
54
|
"typecheck": "tsc -b"
|
|
55
55
|
}
|
|
56
56
|
}
|