@loopingai/core 0.3.1 → 0.5.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.
Files changed (110) hide show
  1. package/README.md +83 -28
  2. package/dist/a2a/caller.d.ts +24 -0
  3. package/dist/a2a/caller.d.ts.map +1 -0
  4. package/dist/a2a/caller.js +34 -0
  5. package/dist/a2a/caller.js.map +1 -0
  6. package/dist/a2a/card.d.ts +7 -2
  7. package/dist/a2a/card.d.ts.map +1 -1
  8. package/dist/a2a/card.js +16 -7
  9. package/dist/a2a/card.js.map +1 -1
  10. package/dist/a2a/index.d.ts +15 -0
  11. package/dist/a2a/index.d.ts.map +1 -1
  12. package/dist/a2a/index.js +15 -0
  13. package/dist/a2a/index.js.map +1 -1
  14. package/dist/a2a/notify.d.ts +27 -5
  15. package/dist/a2a/notify.d.ts.map +1 -1
  16. package/dist/a2a/notify.js +18 -8
  17. package/dist/a2a/notify.js.map +1 -1
  18. package/dist/a2a/push.d.ts +71 -0
  19. package/dist/a2a/push.d.ts.map +1 -0
  20. package/dist/a2a/push.js +54 -0
  21. package/dist/a2a/push.js.map +1 -0
  22. package/dist/a2a/verify.d.ts +28 -36
  23. package/dist/a2a/verify.d.ts.map +1 -1
  24. package/dist/a2a/verify.js +20 -25
  25. package/dist/a2a/verify.js.map +1 -1
  26. package/dist/agent/index.d.ts +16 -5
  27. package/dist/agent/index.d.ts.map +1 -1
  28. package/dist/agent/index.js +16 -5
  29. package/dist/agent/index.js.map +1 -1
  30. package/dist/config.d.ts +49 -7
  31. package/dist/config.d.ts.map +1 -1
  32. package/dist/config.js +25 -3
  33. package/dist/config.js.map +1 -1
  34. package/dist/contract/recipe.d.ts +14 -2
  35. package/dist/contract/recipe.d.ts.map +1 -1
  36. package/dist/contract/validation.d.ts +22 -18
  37. package/dist/contract/validation.d.ts.map +1 -1
  38. package/dist/contract/validation.js +19 -10
  39. package/dist/contract/validation.js.map +1 -1
  40. package/dist/db/models/tasks.d.ts +19 -5
  41. package/dist/db/models/tasks.d.ts.map +1 -1
  42. package/dist/db/models/tasks.js +38 -8
  43. package/dist/db/models/tasks.js.map +1 -1
  44. package/dist/host/agent.d.ts +217 -0
  45. package/dist/host/agent.d.ts.map +1 -0
  46. package/dist/host/agent.js +304 -0
  47. package/dist/host/agent.js.map +1 -0
  48. package/dist/host/index.d.ts +21 -0
  49. package/dist/host/index.d.ts.map +1 -0
  50. package/dist/host/index.js +20 -0
  51. package/dist/host/index.js.map +1 -0
  52. package/dist/host/plugin-host.d.ts +43 -0
  53. package/dist/host/plugin-host.d.ts.map +1 -0
  54. package/dist/host/plugin-host.js +2 -0
  55. package/dist/host/plugin-host.js.map +1 -0
  56. package/dist/round/agent.d.ts +267 -0
  57. package/dist/round/agent.d.ts.map +1 -0
  58. package/dist/round/agent.js +691 -0
  59. package/dist/round/agent.js.map +1 -0
  60. package/dist/round/index.d.ts +25 -0
  61. package/dist/round/index.d.ts.map +1 -0
  62. package/dist/round/index.js +24 -0
  63. package/dist/round/index.js.map +1 -0
  64. package/dist/round/policy.d.ts +99 -0
  65. package/dist/round/policy.d.ts.map +1 -0
  66. package/dist/round/policy.js +2 -0
  67. package/dist/round/policy.js.map +1 -0
  68. package/dist/round/subagent.d.ts +67 -0
  69. package/dist/round/subagent.d.ts.map +1 -0
  70. package/dist/round/subagent.js +89 -0
  71. package/dist/round/subagent.js.map +1 -0
  72. package/dist/round/turn.d.ts +231 -0
  73. package/dist/round/turn.d.ts.map +1 -0
  74. package/dist/round/turn.js +497 -0
  75. package/dist/round/turn.js.map +1 -0
  76. package/dist/round/workflow.d.ts +109 -0
  77. package/dist/round/workflow.d.ts.map +1 -0
  78. package/dist/round/workflow.js +316 -0
  79. package/dist/round/workflow.js.map +1 -0
  80. package/dist/runtime/index.d.ts +5 -1
  81. package/dist/runtime/index.d.ts.map +1 -1
  82. package/dist/runtime/index.js +2 -6
  83. package/dist/runtime/index.js.map +1 -1
  84. package/dist/subagent/fingerprint.d.ts.map +1 -1
  85. package/dist/subagent/fingerprint.js +7 -2
  86. package/dist/subagent/fingerprint.js.map +1 -1
  87. package/dist/testing/auth.d.ts.map +1 -1
  88. package/dist/testing/auth.js +10 -7
  89. package/dist/testing/auth.js.map +1 -1
  90. package/dist/testing/fixtures.d.ts +17 -0
  91. package/dist/testing/fixtures.d.ts.map +1 -1
  92. package/dist/testing/fixtures.js +17 -0
  93. package/dist/testing/fixtures.js.map +1 -1
  94. package/dist/testing/harness.d.ts +98 -0
  95. package/dist/testing/harness.d.ts.map +1 -0
  96. package/dist/testing/harness.js +139 -0
  97. package/dist/testing/harness.js.map +1 -0
  98. package/dist/testing/index.d.ts +2 -1
  99. package/dist/testing/index.d.ts.map +1 -1
  100. package/dist/testing/index.js +2 -1
  101. package/dist/testing/index.js.map +1 -1
  102. package/dist/worker/define-agent.d.ts +124 -0
  103. package/dist/worker/define-agent.d.ts.map +1 -0
  104. package/dist/worker/define-agent.js +21 -0
  105. package/dist/worker/define-agent.js.map +1 -0
  106. package/dist/worker/index.d.ts +29 -4
  107. package/dist/worker/index.d.ts.map +1 -1
  108. package/dist/worker/index.js +70 -12
  109. package/dist/worker/index.js.map +1 -1
  110. package/package.json +12 -3
@@ -0,0 +1,98 @@
1
+ import type { PlainTask } from "../a2a/task.js";
2
+ /**
3
+ * Drive one A2A turn against a Worker the way a gateway does.
4
+ *
5
+ * Core already shipped every *piece* of this — a token signer, Ed25519 fixtures,
6
+ * a fake session, a scripted model — and no assembly, so every consumer wrote the
7
+ * assembly themselves and got the same four things wrong first: the token's
8
+ * audience is the **endpoint** and not the origin, the tenant claim has to match
9
+ * the tenant in the body, `SendMessage` is refused without a push config, and the
10
+ * gateway's own JWKS has to be reachable or verification fails before anything
11
+ * interesting happens.
12
+ *
13
+ * None of that is a property of any one agent, so none of it should be written
14
+ * more than once.
15
+ *
16
+ * ```ts
17
+ * const harness = createAgentHarness({ worker, env, tenant: "reactive" });
18
+ * using _ = harness.interceptGateway();
19
+ *
20
+ * const accepted = await harness.send("what's the weather?");
21
+ * expect(accepted.status.state).toBe(TaskState.TASK_STATE_SUBMITTED);
22
+ * ```
23
+ *
24
+ * What it covers is the **synchronous accept**: everything from the gateway's
25
+ * bearer token to the `submitted` Task the Worker returns. The turn itself runs
26
+ * in a Workflow the test runtime does not start, so assert on the callbacks with
27
+ * {@link AgentHarness.callbacks} while driving the workflow body directly with a
28
+ * fake `step`.
29
+ */
30
+ /** The minimum of an `ExportedHandler` this harness calls. */
31
+ export interface HarnessWorker<TEnv> {
32
+ fetch(request: Request, env: TEnv): Promise<Response> | Response;
33
+ }
34
+ export interface AgentHarnessOptions<TEnv> {
35
+ /** The Worker module under test — usually `import worker from "@/index"`. */
36
+ worker: HarnessWorker<TEnv>;
37
+ /** The `env` the pool built from `wrangler.jsonc`. */
38
+ env: TEnv;
39
+ /** Which agent to address. Must be a tenant the Worker mounts. */
40
+ tenant?: string;
41
+ /** Where the Worker serves JSON-RPC. Defaults to core's `/a2a`. */
42
+ rpcPath?: string;
43
+ /** The origin the Worker is addressed on. Defaults to the test fixture's. */
44
+ origin?: string;
45
+ }
46
+ /** One push notification the agent POSTed back, already decoded. */
47
+ export interface CapturedCallback {
48
+ /** The `taskId` the callback was about. */
49
+ taskId: string;
50
+ /** The task state, e.g. `TASK_STATE_WORKING`. */
51
+ state: string;
52
+ /** The message text, joined across parts. `""` for a no-reply completion. */
53
+ text: string;
54
+ /** The per-task validation token echoed in the callback header. */
55
+ token: string | null;
56
+ /** The raw decoded body, for anything the projection above drops. */
57
+ body: unknown;
58
+ }
59
+ export interface AgentHarness {
60
+ /** The endpoint a token is minted for — the audience, not the origin. */
61
+ readonly endpoint: string;
62
+ /** The gateway webhook the agent is told to call back on. */
63
+ readonly pushUrl: string;
64
+ /**
65
+ * Send one turn and return the accepted Task.
66
+ *
67
+ * Throws on a JSON-RPC error rather than returning it, so a spec asserting the
68
+ * happy path fails with the agent's own message instead of on a later
69
+ * `undefined`. Use {@link rpc} for the refusal cases.
70
+ */
71
+ send(text: string, options?: {
72
+ taskId?: string;
73
+ }): Promise<PlainTask>;
74
+ /**
75
+ * One raw JSON-RPC call with a valid gateway token, returning the `Response`.
76
+ * For specs about what the edge *refuses*.
77
+ */
78
+ rpc(body: unknown, init?: {
79
+ token?: string;
80
+ }): Promise<Response>;
81
+ /** A valid gateway token for this harness's tenant and endpoint. */
82
+ token(overrides?: {
83
+ tenant?: string;
84
+ }): Promise<string>;
85
+ /**
86
+ * Stub `fetch` so the gateway's JWKS resolves and every push callback is
87
+ * captured instead of leaving the isolate.
88
+ *
89
+ * Returns a disposable — `using _ = harness.interceptGateway()` — that restores
90
+ * the global on scope exit. Anything neither the JWKS nor the webhook 404s, so
91
+ * an unexpected outbound call fails loudly rather than hanging.
92
+ */
93
+ interceptGateway(): Disposable;
94
+ /** Callbacks captured since {@link interceptGateway}, in arrival order. */
95
+ readonly callbacks: CapturedCallback[];
96
+ }
97
+ export declare function createAgentHarness<TEnv>(options: AgentHarnessOptions<TEnv>): AgentHarness;
98
+ //# sourceMappingURL=harness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/testing/harness.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,8DAA8D;AAC9D,MAAM,WAAW,aAAa,CAAC,IAAI;IACjC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;CAClE;AAED,MAAM,WAAW,mBAAmB,CAAC,IAAI;IACvC,6EAA6E;IAC7E,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;IAC5B,sDAAsD;IACtD,GAAG,EAAE,IAAI,CAAC;IACV,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,OA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k";
2
+ import { A2A_RPC_PATH, NOTIFICATION_TOKEN_HEADER, endpointUrl, jwksUrl } from "@loopingai/a2a-protocol";
3
+ import { makeGatewayToken, TEST_TENANT } from "./auth.js";
4
+ import { AGENT_ORIGIN, GATEWAY_ORIGIN, gatewayPublicJwks } from "./fixtures.js";
5
+ /**
6
+ * Project the push envelope onto the three fields a spec usually asserts.
7
+ *
8
+ * Reads `status.message.parts` — the key the wire form actually uses. It read
9
+ * `content` until `harness.spec.ts` drove a real callback through it, which
10
+ * made `text` the empty string on every capture: silently, since a harness
11
+ * reporting `""` for what an agent said looks exactly like an agent that said
12
+ * nothing, and the no-reply completion is a legitimate outcome.
13
+ */
14
+ function projectCallback(body, token) {
15
+ const task = body.task ?? body;
16
+ const t = task;
17
+ const parts = t.status?.message?.parts ?? [];
18
+ return {
19
+ taskId: t.id ?? "",
20
+ state: t.status?.state ?? "",
21
+ text: parts
22
+ .map((p) => p.text ?? "")
23
+ .join("")
24
+ .trim(),
25
+ token,
26
+ body
27
+ };
28
+ }
29
+ export function createAgentHarness(options) {
30
+ const origin = options.origin ?? AGENT_ORIGIN;
31
+ const rpcPath = options.rpcPath ?? A2A_RPC_PATH;
32
+ // The audience a gateway actually mints: the endpoint this deployment serves,
33
+ // which is also exactly what its card advertises as its interface. Composed
34
+ // with the protocol package's own helper, so a harness cannot agree with the
35
+ // verifier while disagreeing with what a real gateway would send.
36
+ const endpoint = endpointUrl(origin, rpcPath);
37
+ const tenant = options.tenant ?? TEST_TENANT;
38
+ const pushUrl = `${GATEWAY_ORIGIN}/a2a/push`;
39
+ const pushToken = "harness-push-token";
40
+ const callbacks = [];
41
+ const token = (overrides = {}) => makeGatewayToken({
42
+ audience: endpoint,
43
+ tenant: overrides.tenant ?? tenant
44
+ });
45
+ const rpc = async (body, init = {}) => options.worker.fetch(new Request(endpoint, {
46
+ method: "POST",
47
+ headers: {
48
+ "content-type": "application/json",
49
+ "A2A-Version": A2A_PROTOCOL_VERSION,
50
+ authorization: `Bearer ${init.token ?? (await token())}`
51
+ },
52
+ body: JSON.stringify(body)
53
+ }), options.env);
54
+ return {
55
+ endpoint,
56
+ pushUrl,
57
+ callbacks,
58
+ token,
59
+ rpc,
60
+ async send(text, sendOptions = {}) {
61
+ const messageId = crypto.randomUUID();
62
+ const res = await rpc({
63
+ jsonrpc: "2.0",
64
+ id: 1,
65
+ method: "SendMessage",
66
+ // `SendMessageRequest` is **flat**: `tenant`, `message`, `configuration`,
67
+ // `metadata`. There is no `request` wrapper, and wrapping is silent when
68
+ // you do it — `fromJSON` drops unknown keys rather than rejecting them,
69
+ // so the whole turn decodes to an empty message with no push config and
70
+ // the agent refuses it for "missing" fields the caller did send.
71
+ //
72
+ // This harness shipped with exactly that envelope. Nothing caught it,
73
+ // because nothing in this package drove the harness against a real
74
+ // Worker until `harness.spec.ts` — which is the argument for that spec
75
+ // existing, made by the code it tests.
76
+ params: {
77
+ tenant,
78
+ message: {
79
+ messageId,
80
+ role: "ROLE_USER",
81
+ // `parts`, not `content`. The decoded `Message` exposes `parts`, and
82
+ // `fromJSON` silently yields an empty list for anything else — so a
83
+ // turn sent under the wrong key arrives as a message with no text
84
+ // and the agent answers a blank prompt.
85
+ parts: [{ text }],
86
+ ...(sendOptions.taskId ? { taskId: sendOptions.taskId } : {})
87
+ },
88
+ configuration: {
89
+ // Required by the accept-and-notify contract: an agent that replies
90
+ // out of band and is given nowhere to call back has accepted a turn
91
+ // it can never answer.
92
+ taskPushNotificationConfig: { url: pushUrl, token: pushToken }
93
+ }
94
+ }
95
+ });
96
+ const envelope = await res.json();
97
+ if (envelope.error) {
98
+ throw new Error(`SendMessage was refused (${envelope.error.code}): ${envelope.error.message}`);
99
+ }
100
+ const result = envelope.result;
101
+ const task = (result?.task ?? result);
102
+ if (!task) {
103
+ throw new Error(`SendMessage returned no task: ${JSON.stringify(envelope)}`);
104
+ }
105
+ return task;
106
+ },
107
+ interceptGateway() {
108
+ const original = globalThis.fetch;
109
+ globalThis.fetch = (async (input, init) => {
110
+ const url = typeof input === "string" ? input : String(input);
111
+ // The gateway's public JWKS — without it every token fails to verify and
112
+ // every spec below it reports a 401 that has nothing to do with its subject.
113
+ if (url === jwksUrl(GATEWAY_ORIGIN)) {
114
+ return new Response(gatewayPublicJwks(), {
115
+ headers: { "content-type": "application/json" }
116
+ });
117
+ }
118
+ if (url === pushUrl) {
119
+ const request = new Request(input, init);
120
+ const body = await request.json().catch(() => null);
121
+ callbacks.push(projectCallback(body, request.headers.get(NOTIFICATION_TOKEN_HEADER)));
122
+ return new Response(null, { status: 202 });
123
+ }
124
+ // Anything else is a call this harness did not expect. 404 rather than
125
+ // pass through: a spec that silently reaches the real network is a spec
126
+ // that passes for the wrong reason.
127
+ return new Response(`unexpected outbound fetch: ${url}`, {
128
+ status: 404
129
+ });
130
+ });
131
+ return {
132
+ [Symbol.dispose]() {
133
+ globalThis.fetch = original;
134
+ }
135
+ };
136
+ }
137
+ };
138
+ }
139
+ //# sourceMappingURL=harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.js","sourceRoot":"","sources":["../../src/testing/harness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,WAAW,EACX,OAAO,EACR,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAgGhF;;;;;;;;GAQG;AACH,SAAS,eAAe,CACtB,IAAa,EACb,KAAoB;IAEpB,MAAM,IAAI,GAAI,IAA2B,CAAC,IAAI,IAAI,IAAI,CAAC;IACvD,MAAM,CAAC,GAAG,IAGT,CAAC;IACF,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC;IAC7C,OAAO;QACL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AAC,CAC/C,CACF,CAAC;oBACF,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;gBAC7C,CAAC;gBAED,uEAAuE;gBACvE,wEAAwE;gBACxE,oCAAoC;gBACpC,OAAO,IAAI,QAAQ,CAAC,8BAA8B,GAAG,EAAE,EAAE;oBACvD,MAAM,EAAE,GAAG;iBACZ,CAAC,CAAC;YACL,CAAC,CAAiB,CAAC;YAEnB,OAAO;gBACL,CAAC,MAAM,CAAC,OAAO,CAAC;oBACd,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC;gBAC9B,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -26,6 +26,7 @@ export { VCR_CONTROL_ORIGIN, VCR_MARKER_HEADER, CASSETTE_NAME_RE, type VcrReleas
26
26
  export { FakeSession } from "./fake-session.js";
27
27
  export { mockModel, finalReply, type MockStep } from "./mock-model.js";
28
28
  export { makeGatewayToken, type GatewayTokenOptions } from "./auth.js";
29
- export { AGENT_ORIGIN, GATEWAY_ORIGIN, TEST_AGENT_PRIVATE_JWK, TEST_GATEWAY_PRIVATE_JWK, gatewayPublicJwks, testAgentMessage, testStatus, testTask } from "./fixtures.js";
29
+ export { AGENT_ORIGIN, GATEWAY_ORIGIN, TEST_AGENT_PRIVATE_JWK, TEST_GATEWAY_PRIVATE_JWK, TEST_MODELS, gatewayPublicJwks, testAgentMessage, testStatus, testTask } from "./fixtures.js";
30
30
  export { doStorage, makeDoHelpers, type DoTestHelpers } from "./do.js";
31
+ export { createAgentHarness, type AgentHarness, type AgentHarnessOptions, type CapturedCallback, type HarnessWorker } from "./harness.js";
31
32
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,cAAc,EACd,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,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAEvE,OAAO,EACL,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC"}
@@ -26,6 +26,7 @@ export { VCR_CONTROL_ORIGIN, VCR_MARKER_HEADER, CASSETTE_NAME_RE } from "./vcr-s
26
26
  export { FakeSession } from "./fake-session.js";
27
27
  export { mockModel, finalReply } from "./mock-model.js";
28
28
  export { makeGatewayToken } from "./auth.js";
29
- export { AGENT_ORIGIN, GATEWAY_ORIGIN, TEST_AGENT_PRIVATE_JWK, TEST_GATEWAY_PRIVATE_JWK, gatewayPublicJwks, testAgentMessage, testStatus, testTask } from "./fixtures.js";
29
+ export { AGENT_ORIGIN, GATEWAY_ORIGIN, TEST_AGENT_PRIVATE_JWK, TEST_GATEWAY_PRIVATE_JWK, TEST_MODELS, gatewayPublicJwks, testAgentMessage, testStatus, testTask } from "./fixtures.js";
30
30
  export { doStorage, makeDoHelpers } from "./do.js";
31
+ export { createAgentHarness } from "./harness.js";
31
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,cAAc,EACd,eAAe,EAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAA4B,MAAM,WAAW,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,cAAc,EACd,sBAAsB,EACtB,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAsB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EACL,cAAc,EACd,eAAe,EAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAA4B,MAAM,WAAW,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,cAAc,EACd,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACT,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAsB,MAAM,SAAS,CAAC;AAEvE,OAAO,EACL,kBAAkB,EAKnB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,124 @@
1
+ import type { AgentManifest } from "../a2a/card.js";
2
+ import type { GatewayIdentity } from "../a2a/verify.js";
3
+ import type { TaskAgent } from "../a2a/agent-stub.js";
4
+ import { type AcceptedTurn } from "../a2a/executor.js";
5
+ /**
6
+ * One agent's wiring, declared once.
7
+ *
8
+ * ## What this replaces
9
+ *
10
+ * Mounting an agent used to mean writing the same four things by hand and keeping
11
+ * them in agreement: a `getAgent(identity)` that guards `identity.key` and reads a
12
+ * Durable Object binding, a `startTurn` that derives an idempotent workflow id and
13
+ * swallows the already-exists race, an entry in the `tenants` map, and — in the
14
+ * agent's own Workflow entrypoint — a second reference to the same DO binding.
15
+ *
16
+ * Four copies of one fact, and only the first two were even adjacent. The wiring
17
+ * also type-checked when it was **wrong**: naming a sibling's workflow binding on
18
+ * a tenant compiles perfectly and fails at runtime, after auth, after the turn was
19
+ * accepted, as a task that simply never calls back.
20
+ *
21
+ * ```ts
22
+ * export const reactive = defineAgent({
23
+ * tenant: "reactive",
24
+ * manifest,
25
+ * agent: (env: Env) => env.ReactiveAgent,
26
+ * workflow: (env: Env) => env.HANDLE_TASK_WORKFLOW
27
+ * });
28
+ *
29
+ * // the Worker entry
30
+ * export default {
31
+ * fetch: createA2AWorker<Env>({ manifest: hostManifest, agents: [reactive] })
32
+ * };
33
+ *
34
+ * // the agent's Workflow entrypoint
35
+ * await runHandleTask(event.payload, step, {
36
+ * resolveAgent: (identity) => reactive.resolveAgent(this.env, identity),
37
+ * …
38
+ * });
39
+ * ```
40
+ *
41
+ * ## Why accessors rather than binding names
42
+ *
43
+ * `agent` and `workflow` are functions of `env`, not strings. A string would have
44
+ * to be checked against `keyof Env` and then widened back to a namespace, which
45
+ * loses the Durable Object's own class — so the Workflow could not see the very
46
+ * methods it exists to drive. An accessor infers both: the tenant is mounted and
47
+ * the Workflow is driven from one declaration, `env.RactiveAgent` is a compile
48
+ * error, and `resolveAgent` comes back typed as the agent itself.
49
+ *
50
+ * `env` stays a parameter throughout, for the reason `src/env.ts` gives: core
51
+ * never reaches for a consumer's ambient bindings, and on Workers `env` does not
52
+ * exist at module scope anyway.
53
+ */
54
+ /**
55
+ * What `createA2AWorker` needs in order to mount an agent. The Durable Object's
56
+ * own class is irrelevant to routing, so this shape forgets it —
57
+ * {@link AgentDefinition} keeps it for the agent's Workflow.
58
+ */
59
+ export interface MountedAgent<TEnv> {
60
+ /** The tenant id a caller addresses this agent with. */
61
+ tenant: string;
62
+ /** The transport-independent half of this agent's card. */
63
+ manifest: AgentManifest;
64
+ resolveAgent(env: TEnv, identity: GatewayIdentity): TaskAgent;
65
+ startTurn(env: TEnv, turn: AcceptedTurn): Promise<void>;
66
+ }
67
+ /**
68
+ * {@link AgentDefinition} deliberately does **not** declare `extends
69
+ * MountedAgent`, even though every one satisfies it.
70
+ *
71
+ * A generic `DurableObjectStub<TAgent>` cannot be proven assignable to
72
+ * {@link TaskAgent} while `TAgent` is unresolved: the RPC stub type widens an
73
+ * *optional* method (`listTasks?`) to `Promise<undefined> | (…) => …`, and
74
+ * forcing the comparison also trips TypeScript's instantiation-depth limit — the
75
+ * same wall that made `PlainTask` necessary. At a concrete call site, where
76
+ * `TAgent` is a real agent class, the assignment resolves normally. So the check
77
+ * happens where it can actually succeed: passing `agents: [reactive]` to
78
+ * `createA2AWorker`.
79
+ */
80
+ export interface DefineAgentOptions<TEnv, TAgent extends Rpc.DurableObjectBranded> {
81
+ /**
82
+ * The tenant id a caller addresses this agent with, and what a gateway
83
+ * registers against. Renaming one is a re-registration, not a refactor.
84
+ */
85
+ tenant: string;
86
+ /** The transport-independent half of this agent's card. */
87
+ manifest: AgentManifest;
88
+ /**
89
+ * This agent's Durable Object namespace. One instance per verified caller —
90
+ * the tenant picks the agent, `identity.key` picks which instance of it.
91
+ */
92
+ agent: (env: TEnv) => DurableObjectNamespace<TAgent>;
93
+ /** The Workflow this agent's turns run on. */
94
+ workflow: (env: TEnv) => Workflow<AcceptedTurn>;
95
+ }
96
+ export interface AgentDefinition<TEnv, TAgent extends Rpc.DurableObjectBranded> {
97
+ /** The tenant id a caller addresses this agent with. */
98
+ tenant: string;
99
+ /** The transport-independent half of this agent's card. */
100
+ manifest: AgentManifest;
101
+ /**
102
+ * Resolve the per-caller agent DO stub, keyed by the verified `identity.key`.
103
+ *
104
+ * Typed as the agent's **own** class, so the Workflow that drives its round
105
+ * methods reaches them through the same declaration the tenant is mounted with
106
+ * — the two cannot address different Durable Objects.
107
+ *
108
+ * Refuses a caller with no key rather than falling back to a shared instance:
109
+ * that key is what makes one caller's tasks unreachable from another's, so a
110
+ * missing one is a routing failure, not a default.
111
+ */
112
+ resolveAgent(env: TEnv, identity: GatewayIdentity): DurableObjectStub<TAgent>;
113
+ /**
114
+ * Start this agent's durable turn, idempotently.
115
+ *
116
+ * The instance id is derived from the gateway's `messageId`, which is stable
117
+ * across dispatch retries — so a retry finding its instance already running is
118
+ * the idempotency working, not a failure. {@link ignoreAlreadyExists} swallows
119
+ * exactly that race and rethrows everything else.
120
+ */
121
+ startTurn(env: TEnv, turn: AcceptedTurn): Promise<void>;
122
+ }
123
+ export declare function defineAgent<TEnv, TAgent extends Rpc.DurableObjectBranded>(options: DefineAgentOptions<TEnv, TAgent>): AgentDefinition<TEnv, TAgent>;
124
+ //# sourceMappingURL=define-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-agent.d.ts","sourceRoot":"","sources":["../../src/worker/define-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,IAAI;IAChC,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAC;IAC9D,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,kBAAkB,CACjC,IAAI,EACJ,MAAM,SAAS,GAAG,CAAC,oBAAoB;IAEvC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,QAAQ,EAAE,aAAa,CAAC;IACxB;;;OAGG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACrD,8CAA8C;IAC9C,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,QAAQ,CAAC,YAAY,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,eAAe,CAC9B,IAAI,EACJ,MAAM,SAAS,GAAG,CAAC,oBAAoB;IAEvC,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,QAAQ,EAAE,aAAa,CAAC;IACxB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9E;;;;;;;OAOG;IACH,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,SAAS,GAAG,CAAC,oBAAoB,EACvE,OAAO,EAAE,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,GACxC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,CAsB/B"}
@@ -0,0 +1,21 @@
1
+ import { ignoreAlreadyExists, workflowIdForMessage } from "../a2a/executor.js";
2
+ export function defineAgent(options) {
3
+ return {
4
+ tenant: options.tenant,
5
+ manifest: options.manifest,
6
+ resolveAgent(env, identity) {
7
+ if (!identity.key) {
8
+ throw new Error("identity.key is required to route to the agent DO");
9
+ }
10
+ const ns = options.agent(env);
11
+ return ns.get(ns.idFromName(identity.key));
12
+ },
13
+ startTurn(env, turn) {
14
+ return ignoreAlreadyExists(() => options.workflow(env).create({
15
+ id: workflowIdForMessage(turn.messageId),
16
+ params: { ...turn }
17
+ }));
18
+ }
19
+ };
20
+ }
21
+ //# sourceMappingURL=define-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-agent.js","sourceRoot":"","sources":["../../src/worker/define-agent.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EAErB,MAAM,oBAAoB,CAAC;AAmI5B,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEzC,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAE1B,YAAY,CAAC,GAAG,EAAE,QAAQ;YACxB,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACvE,CAAC;YACD,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9B,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED,SAAS,CAAC,GAAG,EAAE,IAAI;YACjB,OAAO,mBAAmB,CAAC,GAAG,EAAE,CAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;gBAC3B,EAAE,EAAE,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC;gBACxC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;aACpB,CAAC,CACH,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -2,6 +2,7 @@ import { type AgentManifest } from "../a2a/card.js";
2
2
  import { type TurnStarter } from "../a2a/executor.js";
3
3
  import type { AgentResolver } from "../a2a/agent-stub.js";
4
4
  import { type A2ASecretsEnv } from "../env.js";
5
+ import type { MountedAgent } from "./define-agent.js";
5
6
  /**
6
7
  * The A2A Worker: the zero-trust, no-shared-secrets edge every Looping agent
7
8
  * puts in front of its Durable Object.
@@ -53,8 +54,17 @@ import { type A2ASecretsEnv } from "../env.js";
53
54
  * agent on it*. The second is what makes `tenant` more than an unauthenticated
54
55
  * routing hint in the request body.
55
56
  */
56
- /** Default path serving the card-signing public JWKS (the card's `jku`). */
57
- export declare const JWKS_PATH = "/.well-known/jwks.json";
57
+ export { defineAgent, type AgentDefinition, type DefineAgentOptions, type MountedAgent } from "./define-agent.js";
58
+ /**
59
+ * Default path serving the card-signing public JWKS (the card's `jku`).
60
+ *
61
+ * From `@loopingai/a2a-protocol`, because the gateway serves its own JWKS at
62
+ * the same path and fetches ours from whatever `jku` says — see
63
+ * {@link file://../a2a/verify.ts} for why the two sides share a package rather
64
+ * than a comment. Re-exported so this stays importable from
65
+ * `@loopingai/core/worker`, where it has always lived.
66
+ */
67
+ export { JWKS_PATH } from "@loopingai/a2a-protocol";
58
68
  /** The two secrets a mount signs and verifies with, already read off `env`. */
59
69
  export interface A2ASecrets {
60
70
  /** Ed25519 private JWK, as JSON. See {@link A2ASecretsEnv.A2A_SIGNING_KEY}. */
@@ -88,7 +98,7 @@ export interface A2AWorkerOptions<TEnv = A2ASecretsEnv> {
88
98
  */
89
99
  manifest: AgentManifest;
90
100
  /**
91
- * The agents on this origin, keyed by tenant id. At least one.
101
+ * The agents on this origin, keyed by tenant id.
92
102
  *
93
103
  * The id is opaque to the protocol — "an opaque string used for routing
94
104
  * requests to a specific agent or tenant when multiple agents are served
@@ -98,8 +108,23 @@ export interface A2AWorkerOptions<TEnv = A2ASecretsEnv> {
98
108
  * The tenant chooses *which agent*; the verified `identity.key` still chooses
99
109
  * *which instance of it*, so two callers of one tenant stay in separate
100
110
  * Durable Objects exactly as before.
111
+ *
112
+ * The escape hatch, and still fully supported: use it for an agent whose
113
+ * routing or turn-start is genuinely its own. {@link A2AWorkerOptions.agents}
114
+ * is the shorter form for the ordinary case. Supply at least one of the two.
115
+ */
116
+ tenants?: Record<string, TenantAgent>;
117
+ /**
118
+ * The agents on this origin, each declared once with
119
+ * {@link file://./define-agent.ts defineAgent}.
120
+ *
121
+ * Prefer this to {@link A2AWorkerOptions.tenants}: one declaration produces the
122
+ * tenant entry here *and* the resolver the agent's Workflow entrypoint uses, so
123
+ * the two cannot drift, and the binding names are type-constrained to bindings
124
+ * of the right kind. Merged over `tenants`, which is checked for duplicate
125
+ * tenant ids rather than silently overriding.
101
126
  */
102
- tenants: Record<string, TenantAgent>;
127
+ agents?: readonly MountedAgent<TEnv>[];
103
128
  /** Path serving the public JWKS. Defaults to {@link JWKS_PATH}. */
104
129
  jwksPath?: string;
105
130
  /** Path this agent answers JSON-RPC on. Defaults to `/a2a`. */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAOL,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,SAAS,2BAA2B,CAAC;AAKlD,+EAA+E;AAC/E,MAAM,WAAW,UAAU;IACzB,+EAA+E;IAC/E,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,iFAAiF;AACjF,MAAM,WAAW,WAAW;IAC1B,2DAA2D;IAC3D,QAAQ,EAAE,aAAa,CAAC;IACxB,uDAAuD;IACvD,YAAY,EAAE,aAAa,CAAC;IAC5B,4EAA4E;IAC5E,SAAS,EAAE,WAAW,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB,CAAC,IAAI,GAAG,aAAa;IACpD;;;;;;;;;;;;;OAaG;IACH,QAAQ,EAAE,aAAa,CAAC;I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