@finalai/agent-provider 0.1.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.

Potentially problematic release.


This version of @finalai/agent-provider might be problematic. Click here for more details.

Files changed (176) hide show
  1. package/README.md +12 -0
  2. package/dist/modules/channel-context.d.mts +102 -0
  3. package/dist/modules/channel-context.mjs +52 -0
  4. package/dist/modules/channel-context.mjs.map +7 -0
  5. package/dist/modules/channel-socket.d.mts +65 -0
  6. package/dist/modules/channel-socket.mjs +188 -0
  7. package/dist/modules/channel-socket.mjs.map +7 -0
  8. package/dist/modules/channel.d.mts +382 -0
  9. package/dist/modules/channel.mjs +146 -0
  10. package/dist/modules/channel.mjs.map +7 -0
  11. package/dist/modules/conformance/agent.d.mts +20 -0
  12. package/dist/modules/conformance/agent.mjs +623 -0
  13. package/dist/modules/conformance/agent.mjs.map +7 -0
  14. package/dist/modules/conformance/fixtures.d.mts +41 -0
  15. package/dist/modules/conformance/fixtures.mjs +190 -0
  16. package/dist/modules/conformance/fixtures.mjs.map +7 -0
  17. package/dist/modules/conformance/harness-kit.d.mts +82 -0
  18. package/dist/modules/conformance/harness-kit.mjs +1303 -0
  19. package/dist/modules/conformance/harness-kit.mjs.map +7 -0
  20. package/dist/modules/conformance/image.d.mts +2 -0
  21. package/dist/modules/conformance/image.mjs +79 -0
  22. package/dist/modules/conformance/image.mjs.map +7 -0
  23. package/dist/modules/conformance/index.d.mts +8 -0
  24. package/dist/modules/conformance/index.mjs +12 -0
  25. package/dist/modules/conformance/index.mjs.map +7 -0
  26. package/dist/modules/conformance/local-harness.d.mts +25 -0
  27. package/dist/modules/conformance/local-harness.mjs +108 -0
  28. package/dist/modules/conformance/local-harness.mjs.map +7 -0
  29. package/dist/modules/conformance/protocol.d.mts +30 -0
  30. package/dist/modules/conformance/protocol.mjs +56 -0
  31. package/dist/modules/conformance/protocol.mjs.map +7 -0
  32. package/dist/modules/conformance/sandbox-kit.d.mts +19 -0
  33. package/dist/modules/conformance/sandbox-kit.mjs +320 -0
  34. package/dist/modules/conformance/sandbox-kit.mjs.map +7 -0
  35. package/dist/modules/conformance/scripted-model/chat-completions.d.mts +30 -0
  36. package/dist/modules/conformance/scripted-model/chat-completions.mjs +125 -0
  37. package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +7 -0
  38. package/dist/modules/conformance/scripted-model/directives.d.mts +84 -0
  39. package/dist/modules/conformance/scripted-model/directives.mjs +304 -0
  40. package/dist/modules/conformance/scripted-model/directives.mjs.map +7 -0
  41. package/dist/modules/conformance/scripted-model/handler.d.mts +14 -0
  42. package/dist/modules/conformance/scripted-model/handler.mjs +133 -0
  43. package/dist/modules/conformance/scripted-model/handler.mjs.map +7 -0
  44. package/dist/modules/conformance/scripted-model/index.d.mts +6 -0
  45. package/dist/modules/conformance/scripted-model/index.mjs +7 -0
  46. package/dist/modules/conformance/scripted-model/index.mjs.map +7 -0
  47. package/dist/modules/conformance/scripted-model/messages.d.mts +39 -0
  48. package/dist/modules/conformance/scripted-model/messages.mjs +139 -0
  49. package/dist/modules/conformance/scripted-model/messages.mjs.map +7 -0
  50. package/dist/modules/conformance/scripted-model/responses.d.mts +62 -0
  51. package/dist/modules/conformance/scripted-model/responses.mjs +273 -0
  52. package/dist/modules/conformance/scripted-model/responses.mjs.map +7 -0
  53. package/dist/modules/conformance/scripted-model/sse.d.mts +15 -0
  54. package/dist/modules/conformance/scripted-model/sse.mjs +75 -0
  55. package/dist/modules/conformance/scripted-model/sse.mjs.map +7 -0
  56. package/dist/modules/conformance/v1-agent.d.mts +24 -0
  57. package/dist/modules/conformance/v1-agent.mjs +40 -0
  58. package/dist/modules/conformance/v1-agent.mjs.map +7 -0
  59. package/dist/modules/credential-routes.d.mts +24 -0
  60. package/dist/modules/credential-routes.mjs +25 -0
  61. package/dist/modules/credential-routes.mjs.map +7 -0
  62. package/dist/modules/credentials.d.mts +206 -0
  63. package/dist/modules/credentials.mjs +207 -0
  64. package/dist/modules/credentials.mjs.map +7 -0
  65. package/dist/modules/dynamic.d.mts +32 -0
  66. package/dist/modules/dynamic.mjs +77 -0
  67. package/dist/modules/dynamic.mjs.map +7 -0
  68. package/dist/modules/harness.d.mts +397 -0
  69. package/dist/modules/harness.mjs +213 -0
  70. package/dist/modules/harness.mjs.map +7 -0
  71. package/dist/modules/index.d.mts +15 -0
  72. package/dist/modules/index.mjs +40 -0
  73. package/dist/modules/index.mjs.map +7 -0
  74. package/dist/modules/json.d.mts +12 -0
  75. package/dist/modules/json.mjs +19 -0
  76. package/dist/modules/json.mjs.map +7 -0
  77. package/dist/modules/local-channel-socket.d.mts +23 -0
  78. package/dist/modules/local-channel-socket.mjs +141 -0
  79. package/dist/modules/local-channel-socket.mjs.map +7 -0
  80. package/dist/modules/manifest.d.mts +558 -0
  81. package/dist/modules/manifest.mjs +266 -0
  82. package/dist/modules/manifest.mjs.map +7 -0
  83. package/dist/modules/mcp-content.d.mts +21 -0
  84. package/dist/modules/mcp-content.mjs +86 -0
  85. package/dist/modules/mcp-content.mjs.map +7 -0
  86. package/dist/modules/provider-ref.d.mts +29 -0
  87. package/dist/modules/provider-ref.mjs +55 -0
  88. package/dist/modules/provider-ref.mjs.map +7 -0
  89. package/dist/modules/sandbox/bytes.d.mts +9 -0
  90. package/dist/modules/sandbox/bytes.mjs +154 -0
  91. package/dist/modules/sandbox/bytes.mjs.map +7 -0
  92. package/dist/modules/sandbox/client.d.mts +51 -0
  93. package/dist/modules/sandbox/client.mjs +500 -0
  94. package/dist/modules/sandbox/client.mjs.map +7 -0
  95. package/dist/modules/sandbox/confined-files.d.mts +22 -0
  96. package/dist/modules/sandbox/confined-files.mjs +142 -0
  97. package/dist/modules/sandbox/confined-files.mjs.map +7 -0
  98. package/dist/modules/sandbox/convenience.d.mts +10 -0
  99. package/dist/modules/sandbox/convenience.mjs +116 -0
  100. package/dist/modules/sandbox/convenience.mjs.map +7 -0
  101. package/dist/modules/sandbox/editor.d.mts +49 -0
  102. package/dist/modules/sandbox/editor.mjs +43 -0
  103. package/dist/modules/sandbox/editor.mjs.map +7 -0
  104. package/dist/modules/sandbox/frame-channel.d.mts +47 -0
  105. package/dist/modules/sandbox/frame-channel.mjs +153 -0
  106. package/dist/modules/sandbox/frame-channel.mjs.map +7 -0
  107. package/dist/modules/sandbox/index.d.mts +18 -0
  108. package/dist/modules/sandbox/index.mjs +70 -0
  109. package/dist/modules/sandbox/index.mjs.map +7 -0
  110. package/dist/modules/sandbox/mcp-channel.d.mts +9 -0
  111. package/dist/modules/sandbox/mcp-channel.mjs +77 -0
  112. package/dist/modules/sandbox/mcp-channel.mjs.map +7 -0
  113. package/dist/modules/sandbox/mcp-hosted.d.mts +46 -0
  114. package/dist/modules/sandbox/mcp-hosted.mjs +221 -0
  115. package/dist/modules/sandbox/mcp-hosted.mjs.map +7 -0
  116. package/dist/modules/sandbox/mcp-search.d.mts +51 -0
  117. package/dist/modules/sandbox/mcp-search.mjs +129 -0
  118. package/dist/modules/sandbox/mcp-search.mjs.map +7 -0
  119. package/dist/modules/sandbox/mcp-shell.d.mts +21 -0
  120. package/dist/modules/sandbox/mcp-shell.mjs +205 -0
  121. package/dist/modules/sandbox/mcp-shell.mjs.map +7 -0
  122. package/dist/modules/sandbox/mcp-testing.d.mts +11 -0
  123. package/dist/modules/sandbox/mcp-testing.mjs +33 -0
  124. package/dist/modules/sandbox/mcp-testing.mjs.map +7 -0
  125. package/dist/modules/sandbox/mcp.d.mts +83 -0
  126. package/dist/modules/sandbox/mcp.mjs +971 -0
  127. package/dist/modules/sandbox/mcp.mjs.map +7 -0
  128. package/dist/modules/sandbox/memory-sandbox.d.mts +32 -0
  129. package/dist/modules/sandbox/memory-sandbox.mjs +416 -0
  130. package/dist/modules/sandbox/memory-sandbox.mjs.map +7 -0
  131. package/dist/modules/sandbox/memory-shell.d.mts +29 -0
  132. package/dist/modules/sandbox/memory-shell.mjs +278 -0
  133. package/dist/modules/sandbox/memory-shell.mjs.map +7 -0
  134. package/dist/modules/sandbox/open-scope-node.d.mts +4 -0
  135. package/dist/modules/sandbox/open-scope-node.mjs +19 -0
  136. package/dist/modules/sandbox/open-scope-node.mjs.map +7 -0
  137. package/dist/modules/sandbox/open-scope.d.mts +16 -0
  138. package/dist/modules/sandbox/open-scope.mjs +66 -0
  139. package/dist/modules/sandbox/open-scope.mjs.map +7 -0
  140. package/dist/modules/sandbox/paths.d.mts +7 -0
  141. package/dist/modules/sandbox/paths.mjs +50 -0
  142. package/dist/modules/sandbox/paths.mjs.map +7 -0
  143. package/dist/modules/sandbox/rpc-peer.d.mts +35 -0
  144. package/dist/modules/sandbox/rpc-peer.mjs +224 -0
  145. package/dist/modules/sandbox/rpc-peer.mjs.map +7 -0
  146. package/dist/modules/sandbox/seeds.d.mts +26 -0
  147. package/dist/modules/sandbox/seeds.mjs +228 -0
  148. package/dist/modules/sandbox/seeds.mjs.map +7 -0
  149. package/dist/modules/sandbox/server.d.mts +66 -0
  150. package/dist/modules/sandbox/server.mjs +567 -0
  151. package/dist/modules/sandbox/server.mjs.map +7 -0
  152. package/dist/modules/sandbox/snapshots.d.mts +49 -0
  153. package/dist/modules/sandbox/snapshots.mjs +55 -0
  154. package/dist/modules/sandbox/snapshots.mjs.map +7 -0
  155. package/dist/modules/sandbox/stream-mux.d.mts +18 -0
  156. package/dist/modules/sandbox/stream-mux.mjs +285 -0
  157. package/dist/modules/sandbox/stream-mux.mjs.map +7 -0
  158. package/dist/modules/sandbox/testing.d.mts +25 -0
  159. package/dist/modules/sandbox/testing.mjs +64 -0
  160. package/dist/modules/sandbox/testing.mjs.map +7 -0
  161. package/dist/modules/sandbox/types.d.mts +352 -0
  162. package/dist/modules/sandbox/types.mjs +86 -0
  163. package/dist/modules/sandbox/types.mjs.map +7 -0
  164. package/dist/modules/sandbox/wire.d.mts +671 -0
  165. package/dist/modules/sandbox/wire.mjs +537 -0
  166. package/dist/modules/sandbox/wire.mjs.map +7 -0
  167. package/dist/modules/sandbox/workspace-root.d.mts +8 -0
  168. package/dist/modules/sandbox/workspace-root.mjs +79 -0
  169. package/dist/modules/sandbox/workspace-root.mjs.map +7 -0
  170. package/dist/modules/schemas.d.mts +121 -0
  171. package/dist/modules/schemas.mjs +146 -0
  172. package/dist/modules/schemas.mjs.map +7 -0
  173. package/dist/modules/semantic-events.d.mts +31 -0
  174. package/dist/modules/semantic-events.mjs +23 -0
  175. package/dist/modules/semantic-events.mjs.map +7 -0
  176. package/package.json +199 -0
@@ -0,0 +1,75 @@
1
+ const sseEvent = (event, data) => ({
2
+ event,
3
+ data: JSON.stringify(data)
4
+ });
5
+ const encodeEvent = (event) => `${event.event == null ? "" : `event: ${event.event}
6
+ `}data: ${event.data}
7
+
8
+ `;
9
+ const SSE_HEADERS = {
10
+ "content-type": "text/event-stream",
11
+ "cache-control": "no-cache"
12
+ };
13
+ const sseResponse = (events) => new Response(events.map(encodeEvent).join(""), { status: 200, headers: SSE_HEADERS });
14
+ const jsonResponse = (status, body) => new Response(JSON.stringify(body), {
15
+ status,
16
+ headers: { "content-type": "application/json" }
17
+ });
18
+ const DEFAULT_HELD_STREAM_TIMING = {
19
+ holdMs: 10 * 6e4,
20
+ keepaliveMs: 15e3
21
+ };
22
+ const heldSseResponse = (events, timing) => {
23
+ const encoder = new TextEncoder();
24
+ let keepalive = null;
25
+ let deadline = null;
26
+ const stop = () => {
27
+ if (keepalive != null) clearInterval(keepalive);
28
+ if (deadline != null) clearTimeout(deadline);
29
+ keepalive = null;
30
+ deadline = null;
31
+ };
32
+ const body = new ReadableStream({
33
+ start: (controller) => {
34
+ controller.enqueue(encoder.encode(events.map(encodeEvent).join("")));
35
+ keepalive = setInterval(() => {
36
+ controller.enqueue(encoder.encode(": keepalive\n\n"));
37
+ }, timing.keepaliveMs);
38
+ deadline = setTimeout(() => {
39
+ stop();
40
+ controller.close();
41
+ }, timing.holdMs);
42
+ },
43
+ cancel: stop
44
+ });
45
+ return new Response(body, { status: 200, headers: SSE_HEADERS });
46
+ };
47
+ const pausedSseResponse = (head, tail, pauseMs) => {
48
+ if (pauseMs <= 0) return sseResponse([...head, ...tail]);
49
+ const encoder = new TextEncoder();
50
+ let timer = null;
51
+ const body = new ReadableStream({
52
+ start: (controller) => {
53
+ controller.enqueue(encoder.encode(head.map(encodeEvent).join("")));
54
+ timer = setTimeout(() => {
55
+ timer = null;
56
+ controller.enqueue(encoder.encode(tail.map(encodeEvent).join("")));
57
+ controller.close();
58
+ }, pauseMs);
59
+ },
60
+ cancel: () => {
61
+ if (timer != null) clearTimeout(timer);
62
+ timer = null;
63
+ }
64
+ });
65
+ return new Response(body, { status: 200, headers: SSE_HEADERS });
66
+ };
67
+ export {
68
+ DEFAULT_HELD_STREAM_TIMING,
69
+ heldSseResponse,
70
+ jsonResponse,
71
+ pausedSseResponse,
72
+ sseEvent,
73
+ sseResponse
74
+ };
75
+ //# sourceMappingURL=sse.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/conformance/scripted-model/sse.ts"],
4
+ "sourcesContent": ["import type { JsonValue } from \"../../json.mjs\";\n\n// Server-sent events and JSON responses for the scripted model's wires. Web\n// APIs only, so the same code serves from Node and workerd.\n\nexport interface SseEventIface {\n // The `event:` field; chat completions send data-only events.\n event: string | null;\n // Serialized already (`[DONE]` is not JSON).\n data: string;\n}\n\nexport const sseEvent = (event: string | null, data: JsonValue): SseEventIface => ({\n event,\n data: JSON.stringify(data),\n});\n\nconst encodeEvent = (event: SseEventIface): string =>\n `${event.event == null ? '' : `event: ${event.event}\\n`}data: ${event.data}\\n\\n`;\n\nconst SSE_HEADERS = {\n 'content-type': 'text/event-stream',\n 'cache-control': 'no-cache',\n};\n\nexport const sseResponse = (events: SseEventIface[]): Response =>\n new Response(events.map(encodeEvent).join(''), { status: 200, headers: SSE_HEADERS });\n\nexport const jsonResponse = (status: number, body: JsonValue): Response =>\n new Response(JSON.stringify(body), {\n status,\n headers: { 'content-type': 'application/json' },\n });\n\nexport interface HeldStreamTimingIface {\n // How long a held response stays open before it ends unfinished.\n holdMs: number;\n // SSE comments while held, so proxies keep an idle stream open.\n keepaliveMs: number;\n}\n\nexport const DEFAULT_HELD_STREAM_TIMING: HeldStreamTimingIface = {\n holdMs: 10 * 60_000,\n keepaliveMs: 15_000,\n};\n\n// Sends `events`, then keeps the response open (a model still generating)\n// until the caller aborts it, which cancels the body, or the hold ends.\nexport const heldSseResponse = (\n events: SseEventIface[],\n timing: HeldStreamTimingIface,\n): Response => {\n const encoder = new TextEncoder();\n let keepalive: ReturnType<typeof setInterval> | null = null;\n let deadline: ReturnType<typeof setTimeout> | null = null;\n const stop = (): void => {\n if (keepalive != null) clearInterval(keepalive);\n if (deadline != null) clearTimeout(deadline);\n keepalive = null;\n deadline = null;\n };\n const body = new ReadableStream<Uint8Array>({\n start: (controller) => {\n controller.enqueue(encoder.encode(events.map(encodeEvent).join('')));\n keepalive = setInterval(() => {\n controller.enqueue(encoder.encode(': keepalive\\n\\n'));\n }, timing.keepaliveMs);\n deadline = setTimeout(() => {\n stop();\n controller.close();\n }, timing.holdMs);\n },\n cancel: stop,\n });\n return new Response(body, { status: 200, headers: SSE_HEADERS });\n};\n\n// Sends `head`, pauses `pauseMs` (a model thinking mid-reply), then `tail`;\n// an abort meanwhile cancels the body and the rest is never sent.\nexport const pausedSseResponse = (\n head: SseEventIface[],\n tail: SseEventIface[],\n pauseMs: number,\n): Response => {\n if (pauseMs <= 0) return sseResponse([...head, ...tail]);\n const encoder = new TextEncoder();\n let timer: ReturnType<typeof setTimeout> | null = null;\n const body = new ReadableStream<Uint8Array>({\n start: (controller) => {\n controller.enqueue(encoder.encode(head.map(encodeEvent).join('')));\n timer = setTimeout(() => {\n timer = null;\n controller.enqueue(encoder.encode(tail.map(encodeEvent).join('')));\n controller.close();\n }, pauseMs);\n },\n cancel: () => {\n if (timer != null) clearTimeout(timer);\n timer = null;\n },\n });\n return new Response(body, { status: 200, headers: SSE_HEADERS });\n};\n"],
5
+ "mappings": "AAYO,MAAM,WAAW,CAAC,OAAsB,UAAoC;AAAA,EACjF;AAAA,EACA,MAAM,KAAK,UAAU,IAAI;AAC3B;AAEA,MAAM,cAAc,CAAC,UACnB,GAAG,MAAM,SAAS,OAAO,KAAK,UAAU,MAAM,KAAK;AAAA,CAAI,SAAS,MAAM,IAAI;AAAA;AAAA;AAE5E,MAAM,cAAc;AAAA,EAClB,gBAAgB;AAAA,EAChB,iBAAiB;AACnB;AAEO,MAAM,cAAc,CAAC,WAC1B,IAAI,SAAS,OAAO,IAAI,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,KAAK,SAAS,YAAY,CAAC;AAE/E,MAAM,eAAe,CAAC,QAAgB,SAC3C,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,EACjC;AAAA,EACA,SAAS,EAAE,gBAAgB,mBAAmB;AAChD,CAAC;AASI,MAAM,6BAAoD;AAAA,EAC/D,QAAQ,KAAK;AAAA,EACb,aAAa;AACf;AAIO,MAAM,kBAAkB,CAC7B,QACA,WACa;AACb,QAAM,UAAU,IAAI,YAAY;AAChC,MAAI,YAAmD;AACvD,MAAI,WAAiD;AACrD,QAAM,OAAO,MAAY;AACvB,QAAI,aAAa,KAAM,eAAc,SAAS;AAC9C,QAAI,YAAY,KAAM,cAAa,QAAQ;AAC3C,gBAAY;AACZ,eAAW;AAAA,EACb;AACA,QAAM,OAAO,IAAI,eAA2B;AAAA,IAC1C,OAAO,CAAC,eAAe;AACrB,iBAAW,QAAQ,QAAQ,OAAO,OAAO,IAAI,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;AACnE,kBAAY,YAAY,MAAM;AAC5B,mBAAW,QAAQ,QAAQ,OAAO,iBAAiB,CAAC;AAAA,MACtD,GAAG,OAAO,WAAW;AACrB,iBAAW,WAAW,MAAM;AAC1B,aAAK;AACL,mBAAW,MAAM;AAAA,MACnB,GAAG,OAAO,MAAM;AAAA,IAClB;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACD,SAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,SAAS,YAAY,CAAC;AACjE;AAIO,MAAM,oBAAoB,CAC/B,MACA,MACA,YACa;AACb,MAAI,WAAW,EAAG,QAAO,YAAY,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;AACvD,QAAM,UAAU,IAAI,YAAY;AAChC,MAAI,QAA8C;AAClD,QAAM,OAAO,IAAI,eAA2B;AAAA,IAC1C,OAAO,CAAC,eAAe;AACrB,iBAAW,QAAQ,QAAQ,OAAO,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;AACjE,cAAQ,WAAW,MAAM;AACvB,gBAAQ;AACR,mBAAW,QAAQ,QAAQ,OAAO,KAAK,IAAI,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;AACjE,mBAAW,MAAM;AAAA,MACnB,GAAG,OAAO;AAAA,IACZ;AAAA,IACA,QAAQ,MAAM;AACZ,UAAI,SAAS,KAAM,cAAa,KAAK;AACrC,cAAQ;AAAA,IACV;AAAA,EACF,CAAC;AACD,SAAO,IAAI,SAAS,MAAM,EAAE,QAAQ,KAAK,SAAS,YAAY,CAAC;AACjE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,24 @@
1
+ import type { Stream } from '@agentclientprotocol/sdk/experimental/v2';
2
+ export declare const V1_INITIALIZE_RESULT: {
3
+ protocolVersion: number;
4
+ agentCapabilities: {
5
+ loadSession: boolean;
6
+ promptCapabilities: {
7
+ image: boolean;
8
+ embeddedContext: boolean;
9
+ };
10
+ mcpCapabilities: {
11
+ http: boolean;
12
+ };
13
+ };
14
+ agentInfo: {
15
+ name: string;
16
+ version: string;
17
+ };
18
+ authMethods: never[];
19
+ };
20
+ export interface LegacyProtocolAgentIface {
21
+ stream: Stream;
22
+ received: string[];
23
+ }
24
+ export declare const createLegacyProtocolAgent: () => LegacyProtocolAgentIface;
@@ -0,0 +1,40 @@
1
+ import * as z from "zod";
2
+ const V1_INITIALIZE_RESULT = {
3
+ protocolVersion: 1,
4
+ agentCapabilities: {
5
+ loadSession: true,
6
+ promptCapabilities: { image: true, embeddedContext: true },
7
+ mcpCapabilities: { http: true }
8
+ },
9
+ agentInfo: { name: "acp-v1-fixture", version: "0.9.0" },
10
+ authMethods: []
11
+ };
12
+ const requestSchema = z.object({ id: z.union([z.string(), z.number()]), method: z.string() });
13
+ const createLegacyProtocolAgent = () => {
14
+ const received = [];
15
+ const toClient = new TransformStream();
16
+ const writer = toClient.writable.getWriter();
17
+ const writable = new WritableStream({
18
+ write: async (wire) => {
19
+ for (const message of Array.isArray(wire) ? wire : [wire]) {
20
+ const request = requestSchema.safeParse(message);
21
+ if (!request.success) continue;
22
+ received.push(request.data.method);
23
+ await writer.write(
24
+ request.data.method === "initialize" ? { jsonrpc: "2.0", id: request.data.id, result: V1_INITIALIZE_RESULT } : {
25
+ jsonrpc: "2.0",
26
+ id: request.data.id,
27
+ error: { code: -32601, message: "this agent speaks ACP v1 only" }
28
+ }
29
+ );
30
+ }
31
+ },
32
+ close: () => writer.close().catch(() => void 0)
33
+ });
34
+ return { stream: { readable: toClient.readable, writable }, received };
35
+ };
36
+ export {
37
+ V1_INITIALIZE_RESULT,
38
+ createLegacyProtocolAgent
39
+ };
40
+ //# sourceMappingURL=v1-agent.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/conformance/v1-agent.ts"],
4
+ "sourcesContent": ["import type { AnyWireMessage, Stream } from '@agentclientprotocol/sdk/experimental/v2';\nimport * as z from 'zod';\n\n// An ACP v1 agent as a v2 client meets it: it answers `initialize` with the\n// latest version it speaks (1) in v1's shape (`agentCapabilities`,\n// `agentInfo`, no `info`) and errors every other request. Every party in the\n// plane must refuse it at `initialize` with `unsupported_protocol_version`; nothing negotiates or converts v1.\n\nexport const V1_INITIALIZE_RESULT = {\n protocolVersion: 1,\n agentCapabilities: {\n loadSession: true,\n promptCapabilities: { image: true, embeddedContext: true },\n mcpCapabilities: { http: true },\n },\n agentInfo: { name: 'acp-v1-fixture', version: '0.9.0' },\n authMethods: [],\n};\n\nconst requestSchema = z.object({ id: z.union([z.string(), z.number()]), method: z.string() });\n\nexport interface LegacyProtocolAgentIface {\n // The client side of the connection: what a dialer would get.\n stream: Stream;\n // Methods the agent received, in order.\n received: string[];\n}\n\nexport const createLegacyProtocolAgent = (): LegacyProtocolAgentIface => {\n const received: string[] = [];\n const toClient = new TransformStream<AnyWireMessage, AnyWireMessage>();\n const writer = toClient.writable.getWriter();\n const writable = new WritableStream<AnyWireMessage>({\n write: async (wire) => {\n for (const message of Array.isArray(wire) ? wire : [wire]) {\n const request = requestSchema.safeParse(message);\n if (!request.success) continue;\n received.push(request.data.method);\n await writer.write(\n request.data.method === 'initialize'\n ? { jsonrpc: '2.0', id: request.data.id, result: V1_INITIALIZE_RESULT }\n : {\n jsonrpc: '2.0',\n id: request.data.id,\n error: { code: -32601, message: 'this agent speaks ACP v1 only' },\n },\n );\n }\n },\n close: () => writer.close().catch(() => undefined),\n });\n return { stream: { readable: toClient.readable, writable }, received };\n};\n"],
5
+ "mappings": "AACA,YAAY,OAAO;AAOZ,MAAM,uBAAuB;AAAA,EAClC,iBAAiB;AAAA,EACjB,mBAAmB;AAAA,IACjB,aAAa;AAAA,IACb,oBAAoB,EAAE,OAAO,MAAM,iBAAiB,KAAK;AAAA,IACzD,iBAAiB,EAAE,MAAM,KAAK;AAAA,EAChC;AAAA,EACA,WAAW,EAAE,MAAM,kBAAkB,SAAS,QAAQ;AAAA,EACtD,aAAa,CAAC;AAChB;AAEA,MAAM,gBAAgB,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,CAAC;AASrF,MAAM,4BAA4B,MAAgC;AACvE,QAAM,WAAqB,CAAC;AAC5B,QAAM,WAAW,IAAI,gBAAgD;AACrE,QAAM,SAAS,SAAS,SAAS,UAAU;AAC3C,QAAM,WAAW,IAAI,eAA+B;AAAA,IAClD,OAAO,OAAO,SAAS;AACrB,iBAAW,WAAW,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG;AACzD,cAAM,UAAU,cAAc,UAAU,OAAO;AAC/C,YAAI,CAAC,QAAQ,QAAS;AACtB,iBAAS,KAAK,QAAQ,KAAK,MAAM;AACjC,cAAM,OAAO;AAAA,UACX,QAAQ,KAAK,WAAW,eACpB,EAAE,SAAS,OAAO,IAAI,QAAQ,KAAK,IAAI,QAAQ,qBAAqB,IACpE;AAAA,YACE,SAAS;AAAA,YACT,IAAI,QAAQ,KAAK;AAAA,YACjB,OAAO,EAAE,MAAM,QAAQ,SAAS,gCAAgC;AAAA,UAClE;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,IACA,OAAO,MAAM,OAAO,MAAM,EAAE,MAAM,MAAM,MAAS;AAAA,EACnD,CAAC;AACD,SAAO,EAAE,QAAQ,EAAE,UAAU,SAAS,UAAU,SAAS,GAAG,SAAS;AACvE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,24 @@
1
+ import * as z from 'zod';
2
+ export declare enum CredentialRoute {
3
+ Model = "model",
4
+ Mcp = "mcp",
5
+ Sandbox = "sandbox",
6
+ TranscriptStore = "transcript-store",
7
+ SubscriptionRelay = "subscription-relay",
8
+ FinalMcp = "final-mcp"
9
+ }
10
+ export interface RouteGrantIface {
11
+ route: CredentialRoute;
12
+ token: string;
13
+ expiresAt: string;
14
+ }
15
+ export declare const routeGrantSchema: z.ZodObject<{
16
+ route: z.ZodEnum<typeof CredentialRoute>;
17
+ token: z.ZodString;
18
+ expiresAt: z.ZodString;
19
+ }, z.core.$strip>;
20
+ export declare const credentialRefreshRequestSchema: z.ZodObject<{
21
+ harnessSessionId: z.ZodString;
22
+ routes: z.ZodArray<z.ZodEnum<typeof CredentialRoute>>;
23
+ }, z.core.$strip>;
24
+ export type CredentialRefreshRequestIface = z.infer<typeof credentialRefreshRequestSchema>;
@@ -0,0 +1,25 @@
1
+ import * as z from "zod";
2
+ var CredentialRoute = /* @__PURE__ */ ((CredentialRoute2) => {
3
+ CredentialRoute2["Model"] = "model";
4
+ CredentialRoute2["Mcp"] = "mcp";
5
+ CredentialRoute2["Sandbox"] = "sandbox";
6
+ CredentialRoute2["TranscriptStore"] = "transcript-store";
7
+ CredentialRoute2["SubscriptionRelay"] = "subscription-relay";
8
+ CredentialRoute2["FinalMcp"] = "final-mcp";
9
+ return CredentialRoute2;
10
+ })(CredentialRoute || {});
11
+ const routeGrantSchema = z.object({
12
+ route: z.nativeEnum(CredentialRoute),
13
+ token: z.string().min(1),
14
+ expiresAt: z.string()
15
+ });
16
+ const credentialRefreshRequestSchema = z.object({
17
+ harnessSessionId: z.string().uuid(),
18
+ routes: z.array(z.nativeEnum(CredentialRoute)).min(1).max(8)
19
+ });
20
+ export {
21
+ CredentialRoute,
22
+ credentialRefreshRequestSchema,
23
+ routeGrantSchema
24
+ };
25
+ //# sourceMappingURL=credential-routes.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/credential-routes.ts"],
4
+ "sourcesContent": ["import * as z from 'zod';\n\n// Route-scoped, short-lived grants. A harness reads its model\n// credential through the broker's `model` route with `token`; it never sees a\n// subscription secret unless it is Final-managed and the grant says so. A leaf\n// module: a harness session's Durable Object evaluates it (with the relay\n// contract) before its started line, without the rest of harness.ts.\n\nexport enum CredentialRoute {\n Model = 'model',\n Mcp = 'mcp',\n Sandbox = 'sandbox',\n TranscriptStore = 'transcript-store',\n SubscriptionRelay = 'subscription-relay',\n // Attached only by the MCP host to the configured Final MCP endpoint.\n FinalMcp = 'final-mcp',\n}\n\nexport interface RouteGrantIface {\n route: CredentialRoute;\n token: string;\n expiresAt: string;\n}\n\nexport const routeGrantSchema = z.object({\n route: z.nativeEnum(CredentialRoute),\n token: z.string().min(1),\n expiresAt: z.string(),\n}) satisfies z.ZodType<RouteGrantIface>;\n\n// The body of a refresh: the harness session the token belongs to and the\n// routes to renew (at-open harnesses: `model`, whose renewal carries `atOpen`;\n// `mcp` and `sandbox` for the MCP headers and sandbox endpoints they hold).\nexport const credentialRefreshRequestSchema = z.object({\n harnessSessionId: z.string().uuid(),\n routes: z.array(z.nativeEnum(CredentialRoute)).min(1).max(8),\n});\n\nexport type CredentialRefreshRequestIface = z.infer<typeof credentialRefreshRequestSchema>;\n"],
5
+ "mappings": "AAAA,YAAY,OAAO;AAQZ,IAAK,kBAAL,kBAAKA,qBAAL;AACL,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,SAAM;AACN,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,qBAAkB;AAClB,EAAAA,iBAAA,uBAAoB;AAEpB,EAAAA,iBAAA,cAAW;AAPD,SAAAA;AAAA,GAAA;AAgBL,MAAM,mBAAmB,EAAE,OAAO;AAAA,EACvC,OAAO,EAAE,WAAW,eAAe;AAAA,EACnC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACvB,WAAW,EAAE,OAAO;AACtB,CAAC;AAKM,MAAM,iCAAiC,EAAE,OAAO;AAAA,EACrD,kBAAkB,EAAE,OAAO,EAAE,KAAK;AAAA,EAClC,QAAQ,EAAE,MAAM,EAAE,WAAW,eAAe,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC;AAC7D,CAAC;",
6
+ "names": ["CredentialRoute"]
7
+ }
@@ -0,0 +1,206 @@
1
+ import * as z from 'zod';
2
+ import { DynamicEvent } from "./dynamic.mjs";
3
+ export declare enum CredentialPayer {
4
+ AgentOwner = "agent-owner",
5
+ Organization = "organization",
6
+ PromptingUser = "prompting-user",
7
+ ConversationOwner = "conversation-owner"
8
+ }
9
+ export declare enum CredentialOwner {
10
+ Payer = "payer",
11
+ Organization = "organization"
12
+ }
13
+ export declare enum CredentialNodeKind {
14
+ Subscription = "subscription",
15
+ ApiKey = "api-key",
16
+ Platform = "platform",
17
+ HarnessOwned = "harness-owned",
18
+ Custom = "custom"
19
+ }
20
+ export declare enum InferenceCredentialKind {
21
+ Subscription = "subscription",
22
+ ApiKey = "api-key",
23
+ Platform = "platform",
24
+ HarnessOwned = "harness-owned"
25
+ }
26
+ export declare enum CredentialDelivery {
27
+ PerRequest = "per-request",
28
+ AtOpen = "at-open"
29
+ }
30
+ export declare const KNOWN_INFERENCE_VENDORS: readonly ["openai", "anthropic", "openrouter", "google", "bedrock"];
31
+ export declare const subscriptionNodeSchema: z.ZodObject<{
32
+ kind: z.ZodLiteral<CredentialNodeKind.Subscription>;
33
+ owner: z.ZodEnum<typeof CredentialOwner>;
34
+ vendor: z.ZodOptional<z.ZodString>;
35
+ pin: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strip>;
37
+ export declare const apiKeyOwnerNodeSchema: z.ZodObject<{
38
+ pin: z.ZodOptional<z.ZodString>;
39
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
40
+ owner: z.ZodEnum<typeof CredentialOwner>;
41
+ vendor: z.ZodOptional<z.ZodString>;
42
+ }, z.core.$strip>;
43
+ export declare const apiKeySecretNodeSchema: z.ZodObject<{
44
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
45
+ secret: z.ZodString;
46
+ baseUrl: z.ZodOptional<z.ZodString>;
47
+ vendor: z.ZodOptional<z.ZodString>;
48
+ }, z.core.$strip>;
49
+ export declare const platformNodeSchema: z.ZodObject<{
50
+ kind: z.ZodLiteral<CredentialNodeKind.Platform>;
51
+ budget: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$strip>;
53
+ export declare const harnessNodeSchema: z.ZodObject<{
54
+ kind: z.ZodLiteral<CredentialNodeKind.HarnessOwned>;
55
+ }, z.core.$strip>;
56
+ export declare const customNodeSchema: z.ZodObject<{
57
+ kind: z.ZodLiteral<CredentialNodeKind.Custom>;
58
+ resolver: z.ZodString;
59
+ events: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof DynamicEvent>>>;
60
+ }, z.core.$strip>;
61
+ export declare const credentialNodeSchema: z.ZodUnion<readonly [z.ZodObject<{
62
+ kind: z.ZodLiteral<CredentialNodeKind.Subscription>;
63
+ owner: z.ZodEnum<typeof CredentialOwner>;
64
+ vendor: z.ZodOptional<z.ZodString>;
65
+ pin: z.ZodOptional<z.ZodString>;
66
+ }, z.core.$strip>, z.ZodObject<{
67
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
68
+ secret: z.ZodString;
69
+ baseUrl: z.ZodOptional<z.ZodString>;
70
+ vendor: z.ZodOptional<z.ZodString>;
71
+ }, z.core.$strip>, z.ZodObject<{
72
+ pin: z.ZodOptional<z.ZodString>;
73
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
74
+ owner: z.ZodEnum<typeof CredentialOwner>;
75
+ vendor: z.ZodOptional<z.ZodString>;
76
+ }, z.core.$strip>, z.ZodObject<{
77
+ kind: z.ZodLiteral<CredentialNodeKind.Platform>;
78
+ budget: z.ZodOptional<z.ZodString>;
79
+ }, z.core.$strip>, z.ZodObject<{
80
+ kind: z.ZodLiteral<CredentialNodeKind.HarnessOwned>;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ kind: z.ZodLiteral<CredentialNodeKind.Custom>;
83
+ resolver: z.ZodString;
84
+ events: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof DynamicEvent>>>;
85
+ }, z.core.$strip>]>;
86
+ export declare const credentialPolicySchema: z.ZodObject<{
87
+ payer: z.ZodEnum<typeof CredentialPayer>;
88
+ tryInOrder: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
89
+ kind: z.ZodLiteral<CredentialNodeKind.Subscription>;
90
+ owner: z.ZodEnum<typeof CredentialOwner>;
91
+ vendor: z.ZodOptional<z.ZodString>;
92
+ pin: z.ZodOptional<z.ZodString>;
93
+ }, z.core.$strip>, z.ZodObject<{
94
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
95
+ secret: z.ZodString;
96
+ baseUrl: z.ZodOptional<z.ZodString>;
97
+ vendor: z.ZodOptional<z.ZodString>;
98
+ }, z.core.$strip>, z.ZodObject<{
99
+ pin: z.ZodOptional<z.ZodString>;
100
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
101
+ owner: z.ZodEnum<typeof CredentialOwner>;
102
+ vendor: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$strip>, z.ZodObject<{
104
+ kind: z.ZodLiteral<CredentialNodeKind.Platform>;
105
+ budget: z.ZodOptional<z.ZodString>;
106
+ }, z.core.$strip>, z.ZodObject<{
107
+ kind: z.ZodLiteral<CredentialNodeKind.HarnessOwned>;
108
+ }, z.core.$strip>, z.ZodObject<{
109
+ kind: z.ZodLiteral<CredentialNodeKind.Custom>;
110
+ resolver: z.ZodString;
111
+ events: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof DynamicEvent>>>;
112
+ }, z.core.$strip>]>>;
113
+ }, z.core.$strip>;
114
+ export type SubscriptionNodeIface = z.infer<typeof subscriptionNodeSchema>;
115
+ export type ApiKeyOwnerNodeIface = z.infer<typeof apiKeyOwnerNodeSchema>;
116
+ export type ApiKeySecretNodeIface = z.infer<typeof apiKeySecretNodeSchema>;
117
+ export type PlatformNodeIface = z.infer<typeof platformNodeSchema>;
118
+ export type HarnessOwnedNodeIface = z.infer<typeof harnessNodeSchema>;
119
+ export type CustomNodeIface = z.infer<typeof customNodeSchema>;
120
+ export type CredentialNode = z.infer<typeof credentialNodeSchema>;
121
+ export type CredentialPolicyIface = z.infer<typeof credentialPolicySchema>;
122
+ export declare const customResolverResultSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodObject<{
123
+ kind: z.ZodLiteral<CredentialNodeKind.Subscription>;
124
+ owner: z.ZodEnum<typeof CredentialOwner>;
125
+ vendor: z.ZodOptional<z.ZodString>;
126
+ pin: z.ZodOptional<z.ZodString>;
127
+ }, z.core.$strip>, z.ZodObject<{
128
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
129
+ secret: z.ZodString;
130
+ baseUrl: z.ZodOptional<z.ZodString>;
131
+ vendor: z.ZodOptional<z.ZodString>;
132
+ }, z.core.$strip>, z.ZodObject<{
133
+ pin: z.ZodOptional<z.ZodString>;
134
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
135
+ owner: z.ZodEnum<typeof CredentialOwner>;
136
+ vendor: z.ZodOptional<z.ZodString>;
137
+ }, z.core.$strip>, z.ZodObject<{
138
+ kind: z.ZodLiteral<CredentialNodeKind.Platform>;
139
+ budget: z.ZodOptional<z.ZodString>;
140
+ }, z.core.$strip>, z.ZodObject<{
141
+ kind: z.ZodLiteral<CredentialNodeKind.HarnessOwned>;
142
+ }, z.core.$strip>, z.ZodObject<{
143
+ kind: z.ZodLiteral<CredentialNodeKind.Custom>;
144
+ resolver: z.ZodString;
145
+ events: z.ZodDefault<z.ZodArray<z.ZodEnum<typeof DynamicEvent>>>;
146
+ }, z.core.$strip>]>, z.ZodObject<{
147
+ kind: z.ZodLiteral<CredentialNodeKind.ApiKey>;
148
+ value: z.ZodString;
149
+ vendor: z.ZodOptional<z.ZodString>;
150
+ baseUrl: z.ZodOptional<z.ZodString>;
151
+ }, z.core.$strip>]>;
152
+ export type CustomResolverResult = z.infer<typeof customResolverResultSchema>;
153
+ interface SubscriptionArgsIface {
154
+ owner: CredentialOwner | `${CredentialOwner}`;
155
+ vendor?: string;
156
+ pin?: string;
157
+ }
158
+ interface ApiKeyOwnerArgsIface {
159
+ pin?: string;
160
+ owner: CredentialOwner | `${CredentialOwner}`;
161
+ vendor?: string;
162
+ }
163
+ interface ApiKeySecretArgsIface {
164
+ secret: string;
165
+ baseUrl?: string;
166
+ vendor?: string;
167
+ }
168
+ interface ChainArgsIface {
169
+ payer: CredentialPayer | `${CredentialPayer}`;
170
+ tryInOrder: CredentialNode[];
171
+ }
172
+ interface CustomResolverRefIface {
173
+ resolverExport: string;
174
+ events?: DynamicEvent[];
175
+ }
176
+ export declare const credentials: {
177
+ chain: (args: ChainArgsIface) => CredentialPolicyIface;
178
+ subscription: (args: SubscriptionArgsIface) => SubscriptionNodeIface;
179
+ apiKey: (args: ApiKeyOwnerArgsIface | ApiKeySecretArgsIface) => CredentialNode;
180
+ platform: (args?: {
181
+ budget?: string;
182
+ }) => PlatformNodeIface;
183
+ harness: () => HarnessOwnedNodeIface;
184
+ custom: (ref: CustomResolverRefIface) => CustomNodeIface;
185
+ };
186
+ export declare const defaultPersonalCredentialPolicy: () => CredentialPolicyIface;
187
+ export declare const defaultOrganizationCredentialPolicy: () => CredentialPolicyIface;
188
+ export declare const inferenceKindOfNode: (node: CredentialNode) => InferenceCredentialKind | null;
189
+ export declare enum CredentialFailureReason {
190
+ SubscriptionNotConnected = "subscription_not_connected",
191
+ UsageExhausted = "usage_exhausted",
192
+ BudgetExceeded = "budget_exceeded",
193
+ CredentialInvalid = "credential_invalid",
194
+ HarnessIncompatible = "harness_incompatible"
195
+ }
196
+ export declare enum CredentialFallbackReason {
197
+ Archived = "archived",
198
+ Invalid = "invalid",
199
+ VendorMismatch = "vendor_mismatch",
200
+ Exhausted = "exhausted",
201
+ NotGranted = "not_granted",
202
+ OverBudget = "over_budget",
203
+ KindUnsupported = "kind_unsupported",
204
+ Missing = "missing"
205
+ }
206
+ export {};
@@ -0,0 +1,207 @@
1
+ import * as z from "zod";
2
+ import { DynamicEvent } from "./dynamic.mjs";
3
+ var CredentialPayer = /* @__PURE__ */ ((CredentialPayer2) => {
4
+ CredentialPayer2["AgentOwner"] = "agent-owner";
5
+ CredentialPayer2["Organization"] = "organization";
6
+ CredentialPayer2["PromptingUser"] = "prompting-user";
7
+ CredentialPayer2["ConversationOwner"] = "conversation-owner";
8
+ return CredentialPayer2;
9
+ })(CredentialPayer || {});
10
+ var CredentialOwner = /* @__PURE__ */ ((CredentialOwner2) => {
11
+ CredentialOwner2["Payer"] = "payer";
12
+ CredentialOwner2["Organization"] = "organization";
13
+ return CredentialOwner2;
14
+ })(CredentialOwner || {});
15
+ var CredentialNodeKind = /* @__PURE__ */ ((CredentialNodeKind2) => {
16
+ CredentialNodeKind2["Subscription"] = "subscription";
17
+ CredentialNodeKind2["ApiKey"] = "api-key";
18
+ CredentialNodeKind2["Platform"] = "platform";
19
+ CredentialNodeKind2["HarnessOwned"] = "harness-owned";
20
+ CredentialNodeKind2["Custom"] = "custom";
21
+ return CredentialNodeKind2;
22
+ })(CredentialNodeKind || {});
23
+ var InferenceCredentialKind = /* @__PURE__ */ ((InferenceCredentialKind2) => {
24
+ InferenceCredentialKind2["Subscription"] = "subscription";
25
+ InferenceCredentialKind2["ApiKey"] = "api-key";
26
+ InferenceCredentialKind2["Platform"] = "platform";
27
+ InferenceCredentialKind2["HarnessOwned"] = "harness-owned";
28
+ return InferenceCredentialKind2;
29
+ })(InferenceCredentialKind || {});
30
+ var CredentialDelivery = /* @__PURE__ */ ((CredentialDelivery2) => {
31
+ CredentialDelivery2["PerRequest"] = "per-request";
32
+ CredentialDelivery2["AtOpen"] = "at-open";
33
+ return CredentialDelivery2;
34
+ })(CredentialDelivery || {});
35
+ const KNOWN_INFERENCE_VENDORS = [
36
+ "openai",
37
+ "anthropic",
38
+ "openrouter",
39
+ "google",
40
+ "bedrock"
41
+ ];
42
+ const subscriptionNodeSchema = z.object({
43
+ kind: z.literal("subscription" /* Subscription */),
44
+ owner: z.nativeEnum(CredentialOwner),
45
+ vendor: z.string().min(1).optional(),
46
+ pin: z.string().min(1).optional()
47
+ });
48
+ const apiKeyOwnerNodeSchema = z.object({
49
+ pin: z.string().min(1).optional(),
50
+ kind: z.literal("api-key" /* ApiKey */),
51
+ owner: z.nativeEnum(CredentialOwner),
52
+ vendor: z.string().min(1).optional()
53
+ });
54
+ const apiKeySecretNodeSchema = z.object({
55
+ kind: z.literal("api-key" /* ApiKey */),
56
+ secret: z.string().min(1),
57
+ baseUrl: z.string().url().optional(),
58
+ vendor: z.string().min(1).optional()
59
+ });
60
+ const platformNodeSchema = z.object({
61
+ kind: z.literal("platform" /* Platform */),
62
+ budget: z.string().min(1).optional()
63
+ });
64
+ const harnessNodeSchema = z.object({
65
+ kind: z.literal("harness-owned" /* HarnessOwned */)
66
+ });
67
+ const customNodeSchema = z.object({
68
+ kind: z.literal("custom" /* Custom */),
69
+ // Bundle export of a defineDynamic resolver returning one of the other nodes,
70
+ // or `{ kind: 'api-key', value }` held in memory by the broker.
71
+ resolver: z.string().min(1),
72
+ events: z.array(z.nativeEnum(DynamicEvent)).default([DynamicEvent.SessionStarted])
73
+ });
74
+ const credentialNodeSchema = z.union([
75
+ subscriptionNodeSchema,
76
+ apiKeySecretNodeSchema,
77
+ apiKeyOwnerNodeSchema,
78
+ platformNodeSchema,
79
+ harnessNodeSchema,
80
+ customNodeSchema
81
+ ]);
82
+ const credentialPolicySchema = z.object({
83
+ payer: z.nativeEnum(CredentialPayer),
84
+ tryInOrder: z.array(credentialNodeSchema).min(1)
85
+ });
86
+ const customResolverResultSchema = z.union([
87
+ credentialNodeSchema,
88
+ z.object({
89
+ kind: z.literal("api-key" /* ApiKey */),
90
+ value: z.string().min(1),
91
+ vendor: z.string().min(1).optional(),
92
+ baseUrl: z.string().url().optional()
93
+ })
94
+ ]);
95
+ const ownerSchema = z.nativeEnum(CredentialOwner);
96
+ const toOwner = (owner) => ownerSchema.parse(owner);
97
+ const payerSchema = z.nativeEnum(CredentialPayer);
98
+ const toPayer = (payer) => payerSchema.parse(payer);
99
+ const credentials = {
100
+ chain: (args) => credentialPolicySchema.parse({ payer: toPayer(args.payer), tryInOrder: args.tryInOrder }),
101
+ subscription: (args) => {
102
+ const node = {
103
+ kind: "subscription" /* Subscription */,
104
+ owner: toOwner(args.owner)
105
+ };
106
+ if (args.vendor != null) node.vendor = args.vendor;
107
+ if (args.pin != null) node.pin = args.pin;
108
+ return node;
109
+ },
110
+ apiKey: (args) => {
111
+ if ("secret" in args) {
112
+ const node2 = { kind: "api-key" /* ApiKey */, secret: args.secret };
113
+ if (args.baseUrl != null) node2.baseUrl = args.baseUrl;
114
+ if (args.vendor != null) node2.vendor = args.vendor;
115
+ return node2;
116
+ }
117
+ const node = {
118
+ kind: "api-key" /* ApiKey */,
119
+ owner: toOwner(args.owner)
120
+ };
121
+ if (args.vendor != null) node.vendor = args.vendor;
122
+ if (args.pin != null) node.pin = args.pin;
123
+ return node;
124
+ },
125
+ platform: (args) => {
126
+ const node = { kind: "platform" /* Platform */ };
127
+ if (args?.budget != null) node.budget = args.budget;
128
+ return node;
129
+ },
130
+ harness: () => ({ kind: "harness-owned" /* HarnessOwned */ }),
131
+ custom: (ref) => ({
132
+ kind: "custom" /* Custom */,
133
+ resolver: ref.resolverExport,
134
+ events: ref.events ?? [DynamicEvent.SessionStarted]
135
+ })
136
+ };
137
+ const defaultPersonalCredentialPolicy = () => credentials.chain({
138
+ payer: "agent-owner" /* AgentOwner */,
139
+ tryInOrder: [
140
+ credentials.subscription({ owner: "payer" /* Payer */ }),
141
+ credentials.platform()
142
+ ]
143
+ });
144
+ const defaultOrganizationCredentialPolicy = () => credentials.chain({
145
+ payer: "organization" /* Organization */,
146
+ tryInOrder: [
147
+ credentials.subscription({ owner: "organization" /* Organization */ }),
148
+ credentials.platform()
149
+ ]
150
+ });
151
+ const inferenceKindOfNode = (node) => {
152
+ switch (node.kind) {
153
+ case "subscription" /* Subscription */:
154
+ return "subscription" /* Subscription */;
155
+ case "api-key" /* ApiKey */:
156
+ return "api-key" /* ApiKey */;
157
+ case "platform" /* Platform */:
158
+ return "platform" /* Platform */;
159
+ case "harness-owned" /* HarnessOwned */:
160
+ return "harness-owned" /* HarnessOwned */;
161
+ case "custom" /* Custom */:
162
+ return null;
163
+ }
164
+ };
165
+ var CredentialFailureReason = /* @__PURE__ */ ((CredentialFailureReason2) => {
166
+ CredentialFailureReason2["SubscriptionNotConnected"] = "subscription_not_connected";
167
+ CredentialFailureReason2["UsageExhausted"] = "usage_exhausted";
168
+ CredentialFailureReason2["BudgetExceeded"] = "budget_exceeded";
169
+ CredentialFailureReason2["CredentialInvalid"] = "credential_invalid";
170
+ CredentialFailureReason2["HarnessIncompatible"] = "harness_incompatible";
171
+ return CredentialFailureReason2;
172
+ })(CredentialFailureReason || {});
173
+ var CredentialFallbackReason = /* @__PURE__ */ ((CredentialFallbackReason2) => {
174
+ CredentialFallbackReason2["Archived"] = "archived";
175
+ CredentialFallbackReason2["Invalid"] = "invalid";
176
+ CredentialFallbackReason2["VendorMismatch"] = "vendor_mismatch";
177
+ CredentialFallbackReason2["Exhausted"] = "exhausted";
178
+ CredentialFallbackReason2["NotGranted"] = "not_granted";
179
+ CredentialFallbackReason2["OverBudget"] = "over_budget";
180
+ CredentialFallbackReason2["KindUnsupported"] = "kind_unsupported";
181
+ CredentialFallbackReason2["Missing"] = "missing";
182
+ return CredentialFallbackReason2;
183
+ })(CredentialFallbackReason || {});
184
+ export {
185
+ CredentialDelivery,
186
+ CredentialFailureReason,
187
+ CredentialFallbackReason,
188
+ CredentialNodeKind,
189
+ CredentialOwner,
190
+ CredentialPayer,
191
+ InferenceCredentialKind,
192
+ KNOWN_INFERENCE_VENDORS,
193
+ apiKeyOwnerNodeSchema,
194
+ apiKeySecretNodeSchema,
195
+ credentialNodeSchema,
196
+ credentialPolicySchema,
197
+ credentials,
198
+ customNodeSchema,
199
+ customResolverResultSchema,
200
+ defaultOrganizationCredentialPolicy,
201
+ defaultPersonalCredentialPolicy,
202
+ harnessNodeSchema,
203
+ inferenceKindOfNode,
204
+ platformNodeSchema,
205
+ subscriptionNodeSchema
206
+ };
207
+ //# sourceMappingURL=credentials.mjs.map