@relkit/runtime-hono 0.4.0 → 0.5.1

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 (250) hide show
  1. package/dist/agent-active-execution.d.ts +13 -0
  2. package/dist/agent-active-execution.d.ts.map +1 -0
  3. package/dist/agent-active-execution.js +8 -0
  4. package/dist/agent-active-execution.js.map +1 -0
  5. package/dist/agent-approval-coordinator.d.ts +20 -0
  6. package/dist/agent-approval-coordinator.d.ts.map +1 -0
  7. package/dist/agent-approval-coordinator.js +148 -0
  8. package/dist/agent-approval-coordinator.js.map +1 -0
  9. package/dist/agent-capability-negotiation.d.ts +2 -0
  10. package/dist/agent-capability-negotiation.d.ts.map +1 -0
  11. package/dist/agent-capability-negotiation.js +16 -0
  12. package/dist/agent-capability-negotiation.js.map +1 -0
  13. package/dist/agent-compatibility.d.ts +5 -0
  14. package/dist/agent-compatibility.d.ts.map +1 -0
  15. package/dist/agent-compatibility.js +47 -0
  16. package/dist/agent-compatibility.js.map +1 -0
  17. package/dist/agent-content-sink.d.ts +11 -0
  18. package/dist/agent-content-sink.d.ts.map +1 -0
  19. package/dist/agent-content-sink.js +132 -0
  20. package/dist/agent-content-sink.js.map +1 -0
  21. package/dist/agent-control-worker.d.ts +8 -0
  22. package/dist/agent-control-worker.d.ts.map +1 -0
  23. package/dist/agent-control-worker.js +131 -0
  24. package/dist/agent-control-worker.js.map +1 -0
  25. package/dist/agent-follow-up.d.ts +12 -0
  26. package/dist/agent-follow-up.d.ts.map +1 -0
  27. package/dist/agent-follow-up.js +106 -0
  28. package/dist/agent-follow-up.js.map +1 -0
  29. package/dist/agent-inspector-projection.d.ts +7 -0
  30. package/dist/agent-inspector-projection.d.ts.map +1 -0
  31. package/dist/agent-inspector-projection.js +121 -0
  32. package/dist/agent-inspector-projection.js.map +1 -0
  33. package/dist/agent-inspector.d.ts +5 -0
  34. package/dist/agent-inspector.d.ts.map +1 -0
  35. package/dist/agent-inspector.js +107 -0
  36. package/dist/agent-inspector.js.map +1 -0
  37. package/dist/agent-progress-sink.d.ts +10 -0
  38. package/dist/agent-progress-sink.d.ts.map +1 -0
  39. package/dist/agent-progress-sink.js +52 -0
  40. package/dist/agent-progress-sink.js.map +1 -0
  41. package/dist/agent-protocol-encoding.d.ts +3 -0
  42. package/dist/agent-protocol-encoding.d.ts.map +1 -0
  43. package/dist/agent-protocol-encoding.js +123 -0
  44. package/dist/agent-protocol-encoding.js.map +1 -0
  45. package/dist/agent-protocol-frame-state.d.ts +8 -0
  46. package/dist/agent-protocol-frame-state.d.ts.map +1 -0
  47. package/dist/agent-protocol-frame-state.js +124 -0
  48. package/dist/agent-protocol-frame-state.js.map +1 -0
  49. package/dist/agent-protocol-progress.d.ts +8 -0
  50. package/dist/agent-protocol-progress.d.ts.map +1 -0
  51. package/dist/agent-protocol-progress.js +5 -0
  52. package/dist/agent-protocol-progress.js.map +1 -0
  53. package/dist/agent-protocol-stream.d.ts +57 -0
  54. package/dist/agent-protocol-stream.d.ts.map +1 -0
  55. package/dist/agent-protocol-stream.js +77 -0
  56. package/dist/agent-protocol-stream.js.map +1 -0
  57. package/dist/agent-protocol-support.d.ts +19 -0
  58. package/dist/agent-protocol-support.d.ts.map +1 -0
  59. package/dist/agent-protocol-support.js +108 -0
  60. package/dist/agent-protocol-support.js.map +1 -0
  61. package/dist/agent-protocol-tool.d.ts +12 -0
  62. package/dist/agent-protocol-tool.d.ts.map +1 -0
  63. package/dist/agent-protocol-tool.js +65 -0
  64. package/dist/agent-protocol-tool.js.map +1 -0
  65. package/dist/agent-protocol.d.ts +4 -0
  66. package/dist/agent-protocol.d.ts.map +1 -0
  67. package/dist/agent-protocol.js +101 -0
  68. package/dist/agent-protocol.js.map +1 -0
  69. package/dist/agent-rpc-errors.d.ts +5 -0
  70. package/dist/agent-rpc-errors.d.ts.map +1 -0
  71. package/dist/agent-rpc-errors.js +65 -0
  72. package/dist/agent-rpc-errors.js.map +1 -0
  73. package/dist/agent-rpc-read.d.ts +42 -0
  74. package/dist/agent-rpc-read.d.ts.map +1 -0
  75. package/dist/agent-rpc-read.js +127 -0
  76. package/dist/agent-rpc-read.js.map +1 -0
  77. package/dist/agent-rpc-resume.d.ts +13 -0
  78. package/dist/agent-rpc-resume.d.ts.map +1 -0
  79. package/dist/agent-rpc-resume.js +72 -0
  80. package/dist/agent-rpc-resume.js.map +1 -0
  81. package/dist/agent-rpc-support.d.ts +44 -0
  82. package/dist/agent-rpc-support.d.ts.map +1 -0
  83. package/dist/agent-rpc-support.js +111 -0
  84. package/dist/agent-rpc-support.js.map +1 -0
  85. package/dist/agent-rpc-worker.d.ts +7 -0
  86. package/dist/agent-rpc-worker.d.ts.map +1 -0
  87. package/dist/agent-rpc-worker.js +135 -0
  88. package/dist/agent-rpc-worker.js.map +1 -0
  89. package/dist/agent-rpc-write.d.ts +6 -0
  90. package/dist/agent-rpc-write.d.ts.map +1 -0
  91. package/dist/agent-rpc-write.js +109 -0
  92. package/dist/agent-rpc-write.js.map +1 -0
  93. package/dist/agent-rpc.d.ts +21 -0
  94. package/dist/agent-rpc.d.ts.map +1 -0
  95. package/dist/agent-rpc.js +42 -0
  96. package/dist/agent-rpc.js.map +1 -0
  97. package/dist/agent-run-journal.d.ts +12 -0
  98. package/dist/agent-run-journal.d.ts.map +1 -0
  99. package/dist/agent-run-journal.js +96 -0
  100. package/dist/agent-run-journal.js.map +1 -0
  101. package/dist/agent-run-tasks.d.ts +3 -0
  102. package/dist/agent-run-tasks.d.ts.map +1 -0
  103. package/dist/agent-run-tasks.js +16 -0
  104. package/dist/agent-run-tasks.js.map +1 -0
  105. package/dist/agent-runtime.d.ts +17 -0
  106. package/dist/agent-runtime.d.ts.map +1 -0
  107. package/dist/agent-runtime.js +2 -0
  108. package/dist/agent-runtime.js.map +1 -0
  109. package/dist/api-docs.js +1 -1
  110. package/dist/api-docs.js.map +1 -1
  111. package/dist/auth.d.ts +3 -1
  112. package/dist/auth.d.ts.map +1 -1
  113. package/dist/auth.js +5 -1
  114. package/dist/auth.js.map +1 -1
  115. package/dist/bun.d.ts +2 -0
  116. package/dist/bun.d.ts.map +1 -0
  117. package/dist/bun.js +2 -0
  118. package/dist/bun.js.map +1 -0
  119. package/dist/client-authorization.d.ts +2 -0
  120. package/dist/client-authorization.d.ts.map +1 -0
  121. package/dist/client-authorization.js +21 -0
  122. package/dist/client-authorization.js.map +1 -0
  123. package/dist/client-identity.d.ts +24 -0
  124. package/dist/client-identity.d.ts.map +1 -0
  125. package/dist/client-identity.js +46 -0
  126. package/dist/client-identity.js.map +1 -0
  127. package/dist/create-app.d.ts +2 -0
  128. package/dist/create-app.d.ts.map +1 -1
  129. package/dist/create-app.js +10 -0
  130. package/dist/create-app.js.map +1 -1
  131. package/dist/index.d.ts +11 -0
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.js +11 -0
  134. package/dist/index.js.map +1 -1
  135. package/dist/internal-endpoint-paths.d.ts +4 -0
  136. package/dist/internal-endpoint-paths.d.ts.map +1 -0
  137. package/dist/internal-endpoint-paths.js +16 -0
  138. package/dist/internal-endpoint-paths.js.map +1 -0
  139. package/dist/internal-endpoints.d.ts +1 -3
  140. package/dist/internal-endpoints.d.ts.map +1 -1
  141. package/dist/internal-endpoints.js +4 -12
  142. package/dist/internal-endpoints.js.map +1 -1
  143. package/dist/jobs/authorization.d.ts +14 -0
  144. package/dist/jobs/authorization.d.ts.map +1 -0
  145. package/dist/jobs/authorization.js +60 -0
  146. package/dist/jobs/authorization.js.map +1 -0
  147. package/dist/jobs/common.d.ts +22 -0
  148. package/dist/jobs/common.d.ts.map +1 -0
  149. package/dist/jobs/common.js +127 -0
  150. package/dist/jobs/common.js.map +1 -0
  151. package/dist/jobs/cursors.d.ts +10 -0
  152. package/dist/jobs/cursors.d.ts.map +1 -0
  153. package/dist/jobs/cursors.js +64 -0
  154. package/dist/jobs/cursors.js.map +1 -0
  155. package/dist/jobs/handlers-mutations.d.ts +8 -0
  156. package/dist/jobs/handlers-mutations.d.ts.map +1 -0
  157. package/dist/jobs/handlers-mutations.js +73 -0
  158. package/dist/jobs/handlers-mutations.js.map +1 -0
  159. package/dist/jobs/handlers-read.d.ts +8 -0
  160. package/dist/jobs/handlers-read.d.ts.map +1 -0
  161. package/dist/jobs/handlers-read.js +70 -0
  162. package/dist/jobs/handlers-read.js.map +1 -0
  163. package/dist/jobs/handlers-stream.d.ts +7 -0
  164. package/dist/jobs/handlers-stream.d.ts.map +1 -0
  165. package/dist/jobs/handlers-stream.js +72 -0
  166. package/dist/jobs/handlers-stream.js.map +1 -0
  167. package/dist/jobs/handlers-validation.d.ts +6 -0
  168. package/dist/jobs/handlers-validation.d.ts.map +1 -0
  169. package/dist/jobs/handlers-validation.js +119 -0
  170. package/dist/jobs/handlers-validation.js.map +1 -0
  171. package/dist/jobs/handlers.d.ts +4 -0
  172. package/dist/jobs/handlers.d.ts.map +1 -0
  173. package/dist/jobs/handlers.js +4 -0
  174. package/dist/jobs/handlers.js.map +1 -0
  175. package/dist/jobs/projection-stream.d.ts +4 -0
  176. package/dist/jobs/projection-stream.d.ts.map +1 -0
  177. package/dist/jobs/projection-stream.js +82 -0
  178. package/dist/jobs/projection-stream.js.map +1 -0
  179. package/dist/jobs/projection-validation.d.ts +5 -0
  180. package/dist/jobs/projection-validation.d.ts.map +1 -0
  181. package/dist/jobs/projection-validation.js +143 -0
  182. package/dist/jobs/projection-validation.js.map +1 -0
  183. package/dist/jobs/projection.d.ts +11 -0
  184. package/dist/jobs/projection.d.ts.map +1 -0
  185. package/dist/jobs/projection.js +89 -0
  186. package/dist/jobs/projection.js.map +1 -0
  187. package/dist/jobs/rpc.d.ts +5 -0
  188. package/dist/jobs/rpc.d.ts.map +1 -0
  189. package/dist/jobs/rpc.js +115 -0
  190. package/dist/jobs/rpc.js.map +1 -0
  191. package/dist/jobs/support.d.ts +31 -0
  192. package/dist/jobs/support.d.ts.map +1 -0
  193. package/dist/jobs/support.js +144 -0
  194. package/dist/jobs/support.js.map +1 -0
  195. package/dist/jobs/types.d.ts +48 -0
  196. package/dist/jobs/types.d.ts.map +1 -0
  197. package/dist/jobs/types.js +22 -0
  198. package/dist/jobs/types.js.map +1 -0
  199. package/dist/materialize-routes-utils.d.ts.map +1 -1
  200. package/dist/materialize-routes-utils.js +12 -0
  201. package/dist/materialize-routes-utils.js.map +1 -1
  202. package/dist/materialize-routes-validation.d.ts +3 -0
  203. package/dist/materialize-routes-validation.d.ts.map +1 -0
  204. package/dist/materialize-routes-validation.js +28 -0
  205. package/dist/materialize-routes-validation.js.map +1 -0
  206. package/dist/materialize-routes.d.ts +21 -1
  207. package/dist/materialize-routes.d.ts.map +1 -1
  208. package/dist/materialize-routes.js +12 -28
  209. package/dist/materialize-routes.js.map +1 -1
  210. package/dist/native-stream.d.ts +3 -0
  211. package/dist/native-stream.d.ts.map +1 -0
  212. package/dist/native-stream.js +72 -0
  213. package/dist/native-stream.js.map +1 -0
  214. package/dist/realtime-rpc-support.d.ts +19 -0
  215. package/dist/realtime-rpc-support.d.ts.map +1 -0
  216. package/dist/realtime-rpc-support.js +63 -0
  217. package/dist/realtime-rpc-support.js.map +1 -0
  218. package/dist/realtime-rpc.d.ts +4 -0
  219. package/dist/realtime-rpc.d.ts.map +1 -0
  220. package/dist/realtime-rpc.js +134 -0
  221. package/dist/realtime-rpc.js.map +1 -0
  222. package/dist/realtime-runtime.d.ts +13 -0
  223. package/dist/realtime-runtime.d.ts.map +1 -0
  224. package/dist/realtime-runtime.js +2 -0
  225. package/dist/realtime-runtime.js.map +1 -0
  226. package/dist/rpc-identity.d.ts +10 -0
  227. package/dist/rpc-identity.d.ts.map +1 -0
  228. package/dist/rpc-identity.js +26 -0
  229. package/dist/rpc-identity.js.map +1 -0
  230. package/dist/rpc-response.d.ts +5 -0
  231. package/dist/rpc-response.d.ts.map +1 -0
  232. package/dist/rpc-response.js +45 -0
  233. package/dist/rpc-response.js.map +1 -0
  234. package/dist/rpc-route-types.d.ts +10 -0
  235. package/dist/rpc-route-types.d.ts.map +1 -0
  236. package/dist/rpc-route-types.js +50 -0
  237. package/dist/rpc-route-types.js.map +1 -0
  238. package/dist/rpc-websocket.d.ts +6 -0
  239. package/dist/rpc-websocket.d.ts.map +1 -0
  240. package/dist/rpc-websocket.js +48 -0
  241. package/dist/rpc-websocket.js.map +1 -0
  242. package/dist/rpc.d.ts +8 -0
  243. package/dist/rpc.d.ts.map +1 -1
  244. package/dist/rpc.js +46 -59
  245. package/dist/rpc.js.map +1 -1
  246. package/dist/transport-security.d.ts +19 -0
  247. package/dist/transport-security.d.ts.map +1 -0
  248. package/dist/transport-security.js +124 -0
  249. package/dist/transport-security.js.map +1 -0
  250. package/package.json +25 -11
@@ -0,0 +1,101 @@
1
+ import { EventType, RunAgentInputSchema } from "@ag-ui/core";
2
+ import { AGENT_CAPABILITY_HEADER, AGENT_CAPABILITY_VALUE } from "@relkit/contracts";
3
+ import { acceptAgentRun } from "./agent-rpc-write.js";
4
+ import { loadAgent } from "./agent-rpc-read.js";
5
+ import { requireAgentThreadId } from "./agent-rpc-support.js";
6
+ import { agUiFrames } from "./agent-protocol-encoding.js";
7
+ import { agentProtocolFrames } from "./agent-protocol-stream.js";
8
+ import { encodeAgentCursor, eventStream, isRecord, latestUserText, operationId, parseAgentCursor, protocolEndpoint, serverSentEvent, } from "./agent-protocol-support.js";
9
+ import { assertAgentCapabilities } from "./agent-capability-negotiation.js";
10
+ const AGENT_STREAM_HEADERS = { [AGENT_CAPABILITY_HEADER]: AGENT_CAPABILITY_VALUE };
11
+ export function installAgentProtocolEndpoints(app, options) {
12
+ if (options.agentRuntime === undefined || options.clientIdentity === undefined)
13
+ return;
14
+ app.post("/_relkit/v1/agents/:agentId/ag-ui", (context) => protocolEndpoint(context, () => agUi(context, options)));
15
+ }
16
+ async function agUi(context, options) {
17
+ assertAgentCapabilities(context.req.raw);
18
+ const body = await context.req.json().catch(() => undefined);
19
+ if (context.req.header("x-relkit-agent-observe") === "1") {
20
+ return observeAgUi(context, options, body);
21
+ }
22
+ const parsed = RunAgentInputSchema.safeParse(body);
23
+ if (!parsed.success)
24
+ return context.json({ error: "invalid-agent-request" }, 422);
25
+ const rpc = rpcContext(context, options);
26
+ const agentId = requiredAgentId(context);
27
+ const after = parseAgentCursor(context.req.header("last-event-id"));
28
+ const receipt = await acceptAgentRun({
29
+ agentId,
30
+ threadId: parsed.data.threadId,
31
+ kind: "run",
32
+ operationId: operationId(context),
33
+ payload: latestUserText(parsed.data.messages) ?? parsed.data.state,
34
+ }, rpc, options);
35
+ return eventStream(async function* (signal) {
36
+ if (after === undefined) {
37
+ yield serverSentEvent({
38
+ type: EventType.RUN_STARTED,
39
+ threadId: receipt.threadId,
40
+ runId: receipt.runId,
41
+ });
42
+ }
43
+ for await (const emission of agentProtocolFrames(rpc, options, agentId, receipt, after, signal)) {
44
+ const frames = [...agUiFrames(emission.frame)];
45
+ for (let index = 0; index < frames.length; index += 1) {
46
+ const cursor = index === frames.length - 1 && emission.checkpoint !== undefined
47
+ ? encodeAgentCursor(emission.checkpoint)
48
+ : undefined;
49
+ yield serverSentEvent(index === frames.length - 1
50
+ ? withObservation(frames[index], emission.observation)
51
+ : frames[index], cursor);
52
+ }
53
+ }
54
+ }, AGENT_STREAM_HEADERS);
55
+ }
56
+ async function observeAgUi(context, options, body) {
57
+ if (!isRecord(body))
58
+ return context.json({ error: "invalid-agent-request" }, 422);
59
+ const threadId = requireAgentThreadId(body.threadId);
60
+ const rpc = rpcContext(context, options);
61
+ const agentId = requiredAgentId(context);
62
+ const snapshot = await loadAgent({ agentId, threadId }, rpc, options);
63
+ const runId = typeof body.runId === "string" ? body.runId.trim() : "";
64
+ if (runId === "" && snapshot.currentRuns.length === 0) {
65
+ return eventStream(async function* () { });
66
+ }
67
+ if (runId === "")
68
+ throw new TypeError("runId is required for a thread with runs.");
69
+ if (!snapshot.currentRuns.some((run) => run.runId === runId)) {
70
+ throw new TypeError("runId does not belong to the requested thread.");
71
+ }
72
+ const after = parseAgentCursor(context.req.header("last-event-id"));
73
+ return eventStream(async function* (signal) {
74
+ for await (const emission of agentProtocolFrames(rpc, options, agentId, { threadId, runId }, after, signal, true)) {
75
+ const frames = [...agUiFrames(emission.frame)];
76
+ for (let index = 0; index < frames.length; index += 1) {
77
+ const last = index === frames.length - 1;
78
+ yield serverSentEvent(last ? withObservation(frames[index], emission.observation) : frames[index], last && emission.checkpoint !== undefined
79
+ ? encodeAgentCursor(emission.checkpoint)
80
+ : undefined);
81
+ }
82
+ }
83
+ }, AGENT_STREAM_HEADERS);
84
+ }
85
+ function withObservation(frame, observation) {
86
+ if (!isRecord(frame) || observation === undefined)
87
+ return frame;
88
+ const metadata = isRecord(frame.metadata) ? frame.metadata : {};
89
+ const relkit = isRecord(metadata.relkit) ? metadata.relkit : {};
90
+ return { ...frame, metadata: { ...metadata, relkit: { ...relkit, observation } } };
91
+ }
92
+ function rpcContext(context, options) {
93
+ return { hono: context, auth: options.auth?.contextFor(context.req.raw) };
94
+ }
95
+ function requiredAgentId(context) {
96
+ const value = context.req.param("agentId");
97
+ if (value === undefined || value === "")
98
+ throw new TypeError("Agent ID is required.");
99
+ return value;
100
+ }
101
+ //# sourceMappingURL=agent-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-protocol.js","sourceRoot":"","sources":["../src/agent-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EACL,iBAAiB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AC,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAChE,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;AACrF,CAAC;AAED,SAAS,UAAU,CAAC,OAAgB,EAAE,OAAoC;IACxE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED,SAAS,eAAe,CAAC,OAAgB;IACvC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAC;IACtF,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ORPCError } from "@orpc/server";
2
+ export declare function agentRpcCall<Value>(action: () => Promise<Value>): Promise<Value>;
3
+ export declare function agentRpcStream<Value>(action: () => AsyncIterable<Value>): AsyncIterable<Value>;
4
+ export declare function agentRpcError(error: unknown): ORPCError<string, unknown>;
5
+ //# sourceMappingURL=agent-rpc-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-errors.d.ts","sourceRoot":"","sources":["../src/agent-rpc-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAqBzC,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAMtF;AAED,wBAAuB,cAAc,CAAC,KAAK,EACzC,MAAM,EAAE,MAAM,aAAa,CAAC,KAAK,CAAC,GACjC,aAAa,CAAC,KAAK,CAAC,CAMtB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAQxE"}
@@ -0,0 +1,65 @@
1
+ import { ORPCError } from "@orpc/server";
2
+ const publicCodes = new Set([
3
+ "AGENT_CAPABILITIES_UNSUPPORTED",
4
+ "AGENT_APPROVAL_REQUIRED",
5
+ "AGENT_BUSY",
6
+ "AGENT_CONTROL_OVERLOADED",
7
+ "AGENT_OUTPUT_TOO_LARGE",
8
+ "AGENT_PRINCIPAL_OVERLOADED",
9
+ "AGENT_PROVIDER_OVERLOADED",
10
+ "AGENT_STOPPING",
11
+ "AGENT_WORKER_INTERRUPTED",
12
+ "AGENT_RUN_READ_ONLY",
13
+ "GENERATION_UNAVAILABLE",
14
+ "IDENTITY_PRECONDITION_FAILED",
15
+ "IDEMPOTENCY_CONFLICT",
16
+ "IDEMPOTENCY_WINDOW_EXPIRED",
17
+ "PROVIDER_STATE_LOST",
18
+ "NOT_FOUND",
19
+ ]);
20
+ export async function agentRpcCall(action) {
21
+ try {
22
+ return await action();
23
+ }
24
+ catch (error) {
25
+ throw agentRpcError(error);
26
+ }
27
+ }
28
+ export async function* agentRpcStream(action) {
29
+ try {
30
+ yield* action();
31
+ }
32
+ catch (error) {
33
+ throw agentRpcError(error);
34
+ }
35
+ }
36
+ export function agentRpcError(error) {
37
+ if (error instanceof ORPCError)
38
+ return error;
39
+ if (error instanceof TypeError)
40
+ return new ORPCError("BAD_REQUEST", { message: error.message });
41
+ const code = errorCode(error);
42
+ if (code !== undefined && publicCodes.has(code)) {
43
+ return new ORPCError(code, { message: publicMessage(code) });
44
+ }
45
+ return new ORPCError("INTERNAL_SERVER_ERROR");
46
+ }
47
+ function errorCode(error) {
48
+ if (error === null || typeof error !== "object")
49
+ return undefined;
50
+ return typeof error.code === "string"
51
+ ? error.code
52
+ : undefined;
53
+ }
54
+ function publicMessage(code) {
55
+ if (code === "NOT_FOUND")
56
+ return "Agent resource was not found.";
57
+ if (code === "PROVIDER_STATE_LOST")
58
+ return "Agent provider state changed.";
59
+ if (code === "IDEMPOTENCY_WINDOW_EXPIRED")
60
+ return "The idempotency window expired.";
61
+ if (code === "IDEMPOTENCY_CONFLICT")
62
+ return "The operation ID was reused with different content.";
63
+ return code.toLowerCase().replaceAll("_", " ");
64
+ }
65
+ //# sourceMappingURL=agent-rpc-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-errors.js","sourceRoot":"","sources":["../src/agent-rpc-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,gCAAgC;IAChC,yBAAyB;IACzB,YAAY;IACZ,0BAA0B;IAC1B,wBAAwB;IACxB,4BAA4B;IAC5B,2BAA2B;IAC3B,gBAAgB;IAChB,0BAA0B;IAC1B,qBAAqB;IACrB,wBAAwB;IACxB,8BAA8B;IAC9B,sBAAsB;IACtB,4BAA4B;IAC5B,qBAAqB;IACrB,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAQ,MAA4B;IACpE,IAAI,CAAC;QACH,OAAO,MAAM,MAAM,EAAE,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,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AClG,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { RouteMaterializationOptions } from "./materialize-routes.js";
2
+ import type { RpcContext } from "./rpc.js";
3
+ import { type AgentInput } from "./agent-rpc-support.js";
4
+ export declare function listAgentThreads(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions): Promise<import("@relkit/agents").ThreadList>;
5
+ export declare function loadAgent(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions): Promise<import("@relkit/contracts").ThreadSnapshot>;
6
+ export declare function observeAgent(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions, signal?: AbortSignal): AsyncGenerator<{
7
+ kind: "gap";
8
+ reason: "expired" | "foreign" | "future" | "session" | "provider-reset";
9
+ snapshot: import("@relkit/contracts").ThreadSnapshot;
10
+ event?: never;
11
+ } | {
12
+ kind: "event";
13
+ event: import("@relkit/contracts").AgentClientEvent;
14
+ reason?: never;
15
+ snapshot?: never;
16
+ } | {
17
+ kind: "snapshot";
18
+ snapshot: import("@relkit/contracts").ThreadSnapshot;
19
+ reason?: never;
20
+ event?: never;
21
+ }, void, unknown>;
22
+ export declare function lookupAgentReceipt(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions): Promise<{
23
+ readonly status: "not-found";
24
+ readonly providerEpoch: string;
25
+ } | {
26
+ readonly status: "expired";
27
+ readonly expiredAt: string;
28
+ } | {
29
+ readonly status: "state-lost";
30
+ readonly previousEpoch?: string;
31
+ } | {
32
+ readonly status: "found";
33
+ readonly receipt: import("@relkit/agents").ContinuationReceipt;
34
+ } | {
35
+ readonly status: "found";
36
+ readonly receipt: import("@relkit/agents").ControlReceipt;
37
+ } | {
38
+ readonly status: "found";
39
+ readonly receipt: import("@relkit/agents").AcceptRunReceipt | import("@relkit/agents").CompletionReceipt;
40
+ }>;
41
+ export declare function readAgentHistory(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions): Promise<import("@relkit/agents").SnapshotHistoryPage>;
42
+ //# sourceMappingURL=agent-rpc-read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-read.d.ts","sourceRoot":"","sources":["../src/agent-rpc-read.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAsC,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAG7F,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B,gDAKrC;AAED,wBAAsB,SAAS,CAC7B,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B,uDAYrC;AAED,wBAAuB,YAAY,CACjC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B,EACpC,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;kBAoDrB;AAWD,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B;;;;;;;;;;;;;;;;;;GAmCrC;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B,yDAcrC"}
@@ -0,0 +1,127 @@
1
+ import { REALTIME_RUNTIME_LIMITS } from "@relkit/contracts";
2
+ import { agentClientEvents } from "@relkit/agents";
3
+ import { assertExpectedIdentity } from "./rpc-identity.js";
4
+ import { agentContext, requireAgentThreadId } from "./agent-rpc-support.js";
5
+ import { clientAgentSnapshot } from "./agent-compatibility.js";
6
+ export async function listAgentThreads(input, context, options) {
7
+ await assertExpectedIdentity(context, options.clientIdentity, input.expectedIdentity);
8
+ const resolved = await agentContext(input, context, options, "list");
9
+ return resolved.provider.listThreads({ ...resolved.scope, limit: 100 });
10
+ }
11
+ export async function loadAgent(input, context, options) {
12
+ await assertExpectedIdentity(context, options.clientIdentity);
13
+ const threadId = requireAgentThreadId(input.threadId);
14
+ const resolved = await agentContext({ ...input, threadId }, context, options, "load");
15
+ return clientAgentSnapshot(await resolved.provider.loadThread({
16
+ ...resolved.scope,
17
+ threadId,
18
+ maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
19
+ }));
20
+ }
21
+ export async function* observeAgent(input, context, options, signal) {
22
+ await assertExpectedIdentity(context, options.clientIdentity, input.expectedIdentity);
23
+ const threadId = requireAgentThreadId(input.threadId);
24
+ if (input.after === undefined)
25
+ throw new TypeError("checkpoint is required.");
26
+ let resolved = await agentContext({ ...input, threadId }, context, options, "observe");
27
+ let after = input.after;
28
+ const controller = signal ?? new AbortController().signal;
29
+ while (!controller.aborted) {
30
+ await assertExpectedIdentity(context, options.clientIdentity, input.expectedIdentity);
31
+ resolved = await agentContext({ ...input, threadId }, context, options, "observe");
32
+ const page = await resolved.provider.readJournal({
33
+ ...resolved.scope,
34
+ threadId,
35
+ after,
36
+ limit: 100,
37
+ maxEncodedBytes: 1024 * 1024,
38
+ });
39
+ if (page.gap !== undefined) {
40
+ const snapshot = clientAgentSnapshot(await resolved.provider.loadThread({
41
+ ...resolved.scope,
42
+ threadId,
43
+ maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
44
+ }));
45
+ after = snapshot.checkpoint;
46
+ yield { kind: "gap", reason: page.gap, snapshot };
47
+ continue;
48
+ }
49
+ after = page.checkpoint;
50
+ for (const record of page.records)
51
+ for (const event of agentClientEvents(record))
52
+ yield { kind: "event", event };
53
+ if (page.records.some(requiresSnapshot)) {
54
+ const snapshot = clientAgentSnapshot(await resolved.provider.loadThread({
55
+ ...resolved.scope,
56
+ threadId,
57
+ maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
58
+ }));
59
+ yield { kind: "snapshot", snapshot };
60
+ }
61
+ if (!page.hasMore)
62
+ await resolved.provider.waitForJournal({
63
+ ...resolved.scope,
64
+ threadId,
65
+ after,
66
+ deadlineMs: Date.now() + 15_000,
67
+ signal: controller,
68
+ });
69
+ }
70
+ }
71
+ function requiresSnapshot(record) {
72
+ return (record.kind === "approval" ||
73
+ record.kind === "control" ||
74
+ record.kind === "terminal" ||
75
+ record.kind === "interruption");
76
+ }
77
+ export async function lookupAgentReceipt(input, context, options) {
78
+ await assertExpectedIdentity(context, options.clientIdentity);
79
+ if (input.operationId === undefined || input.requestDigest === undefined)
80
+ throw new TypeError("Receipt request is invalid.");
81
+ const resolved = await agentContext(input, context, options, "receipt");
82
+ if (input.kind === "continuation") {
83
+ const threadId = requireAgentThreadId(input.threadId);
84
+ return resolved.provider.lookupContinuationReceipt({
85
+ ...resolved.scope,
86
+ operationId: input.operationId,
87
+ threadId,
88
+ semanticDigest: input.requestDigest,
89
+ now: new Date().toISOString(),
90
+ });
91
+ }
92
+ if (input.kind === "agent-control") {
93
+ const threadId = requireAgentThreadId(input.threadId);
94
+ if (input.runId === undefined)
95
+ throw new TypeError("Control receipt request is invalid.");
96
+ return resolved.provider.lookupControlReceipt({
97
+ ...resolved.scope,
98
+ operationId: input.operationId,
99
+ threadId,
100
+ runId: input.runId,
101
+ semanticDigest: input.requestDigest,
102
+ now: new Date().toISOString(),
103
+ });
104
+ }
105
+ return resolved.provider.lookupRunReceipt({
106
+ ...resolved.scope,
107
+ operationId: input.operationId,
108
+ ...(input.threadId === undefined ? {} : { threadId: input.threadId }),
109
+ semanticDigest: input.requestDigest,
110
+ now: new Date().toISOString(),
111
+ });
112
+ }
113
+ export async function readAgentHistory(input, context, options) {
114
+ await assertExpectedIdentity(context, options.clientIdentity);
115
+ const threadId = requireAgentThreadId(input.threadId);
116
+ if (input.snapshotId === undefined || input.cursor === undefined)
117
+ throw new TypeError("Snapshot and cursor are required.");
118
+ const resolved = await agentContext({ ...input, threadId }, context, options, "history");
119
+ return resolved.provider.readSnapshotHistory({
120
+ ...resolved.scope,
121
+ threadId,
122
+ snapshotId: input.snapshotId,
123
+ cursor: input.cursor,
124
+ maxEncodedBytes: REALTIME_RUNTIME_LIMITS.snapshotHistoryPageBytes,
125
+ });
126
+ }
127
+ //# sourceMappingURL=agent-rpc-read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-read.js","sourceRoot":"","sources":["../src/agent-rpc-read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAmB,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAiB,EACjB,OAAmB,EACnB,OAAoC;IAEpC,MAAM,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAe,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACvF,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACrE,OAAO,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,GAAG,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAiB,EACjB,OAAmB,EACnB,OAAoC;IAEpC,MAAM,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAe,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,CAAC,QAAQ,CAAC,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E,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACzF,OAAO,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC3C,GAAG,QAAQ,CAAC,KAAK;QACjB,QAAQ;QACR,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,eAAe,EAAE,uBAAuB,CAAC,wBAAwB;KAClE,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type OperationId } from "@relkit/contracts";
2
+ import type { RouteMaterializationOptions } from "./materialize-routes.js";
3
+ import { agentContext, type AgentInput } from "./agent-rpc-support.js";
4
+ type ResolvedAgent = Awaited<ReturnType<typeof agentContext>>;
5
+ export declare function acceptAgentResume(input: AgentInput, threadId: string, operationId: OperationId, resolved: ResolvedAgent, options: RouteMaterializationOptions): Promise<{
6
+ operationId: OperationId;
7
+ threadId: string;
8
+ runId: string;
9
+ status: "accepted";
10
+ duplicate: boolean;
11
+ }>;
12
+ export {};
13
+ //# sourceMappingURL=agent-rpc-resume.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-resume.d.ts","sourceRoot":"","sources":["../src/agent-rpc-resume.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EACL,YAAY,EAEZ,KAAK,UAAU,EAEhB,MAAM,wBAAwB,CAAC;AAKhC,KAAK,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC;AAE9D,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,2BAA2B;;;;;;GAuDrC"}
@@ -0,0 +1,72 @@
1
+ import { isGraphDescriptor, validateGraphResumeInput, validateNativeAgentResumeInput, } from "@relkit/agents";
2
+ import { REALTIME_RUNTIME_LIMITS } from "@relkit/contracts";
3
+ import { agentContext, digest, verifiedAgentRequestDigest, } from "./agent-rpc-support.js";
4
+ import { startAgentRun } from "./agent-rpc-worker.js";
5
+ import { waitForAgentRun } from "./agent-run-tasks.js";
6
+ import { assertAgentRunWritable } from "./agent-compatibility.js";
7
+ export async function acceptAgentResume(input, threadId, operationId, resolved, options) {
8
+ if (typeof input.waitingRevision !== "string" || input.waitingRevision.length === 0) {
9
+ throw new TypeError("Agent resume requires the observed waiting revision.");
10
+ }
11
+ const requestDigest = verifiedAgentRequestDigest(input);
12
+ const snapshot = await resolved.provider.loadThread({
13
+ ...resolved.scope,
14
+ threadId,
15
+ maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
16
+ });
17
+ const waiting = snapshot.waiting;
18
+ assertAgentRunWritable(snapshot, waiting?.runId);
19
+ if (waiting === undefined) {
20
+ const prior = await resolved.provider.lookupContinuationReceipt({
21
+ ...resolved.scope,
22
+ operationId,
23
+ threadId,
24
+ semanticDigest: requestDigest,
25
+ now: new Date().toISOString(),
26
+ });
27
+ if (prior.status === "found") {
28
+ const accepted = asAcceptedRun({ ...prior.receipt, duplicate: true });
29
+ startAgentRun(resolved, accepted, input.payload, options, true);
30
+ return accepted;
31
+ }
32
+ throw new TypeError("Agent has no waiting continuation.");
33
+ }
34
+ if (input.waitingRevision !== waiting.revision) {
35
+ throw new TypeError("Agent waiting revision is stale.");
36
+ }
37
+ let reply;
38
+ try {
39
+ reply = isGraphDescriptor(resolved.descriptor)
40
+ ? await validateGraphResumeInput(resolved.descriptor, waiting.requests, input.payload)
41
+ : validateNativeAgentResumeInput(waiting.requests, input.payload);
42
+ }
43
+ catch {
44
+ throw new TypeError("Agent resume input validation failed.");
45
+ }
46
+ await waitForAgentRun(waiting.runId);
47
+ const continuation = await resolved.provider.admitContinuation({
48
+ ...resolved.scope,
49
+ kind: "resume",
50
+ operationId,
51
+ semanticDigest: requestDigest,
52
+ threadId,
53
+ interruptedRunId: waiting.runId,
54
+ interruptSetDigest: digest(waiting),
55
+ waitingRevision: waiting.revision,
56
+ admittedAt: new Date().toISOString(),
57
+ receiptExpiresAt: new Date(Date.now() + REALTIME_RUNTIME_LIMITS.agentReceiptMs).toISOString(),
58
+ });
59
+ const accepted = asAcceptedRun(continuation);
60
+ startAgentRun(resolved, accepted, reply, options, true);
61
+ return accepted;
62
+ }
63
+ function asAcceptedRun(continuation) {
64
+ return {
65
+ operationId: continuation.operationId,
66
+ threadId: continuation.threadId,
67
+ runId: continuation.runId,
68
+ status: "accepted",
69
+ duplicate: continuation.duplicate,
70
+ };
71
+ }
72
+ //# sourceMappingURL=agent-rpc-resume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-resume.js","sourceRoot":"","sources":["../src/agent-rpc-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAoB,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EACL,YAAY,EACZ,MAAM,EAEN,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAIlE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAiB,EACjB,QAAgB,EAChB,WAAwB,EACxB,QAAuB,EACvB,OAAoC;IAEpC,IAAI,OAAO,KAAK,CAAC,eAAe,KAAK,QAAQ,IAAI,KAAK,CAAC,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpF,MAAM,IAAI,SAAS,CAAC,sDAAsD,CAAC,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AC"}
@@ -0,0 +1,44 @@
1
+ import { type OperationId } from "@relkit/contracts";
2
+ import type { AgentRequestScope, AgentStateLimits, RunOwner } from "@relkit/agents";
3
+ import { type StandardSchemaV1 } from "@relkit/schema";
4
+ import type { RouteMaterializationOptions } from "./materialize-routes.js";
5
+ import type { RpcContext } from "./rpc.js";
6
+ export interface AgentInput {
7
+ readonly agentId: string;
8
+ readonly expectedIdentity?: import("@relkit/contracts").ExpectedClientIdentity;
9
+ readonly threadId?: string;
10
+ readonly resume?: boolean;
11
+ readonly waitingRevision?: string;
12
+ readonly runId?: string;
13
+ readonly operationId?: OperationId;
14
+ readonly kind?: string;
15
+ readonly payload?: unknown;
16
+ readonly after?: unknown;
17
+ readonly requestDigest?: string;
18
+ readonly snapshotId?: string;
19
+ readonly cursor?: string;
20
+ }
21
+ export declare function requireAgentThreadId(value: unknown): string;
22
+ export declare function agentContext(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions, operation: string): Promise<{
23
+ descriptor: {
24
+ readonly input: StandardSchemaV1;
25
+ readonly output: StandardSchemaV1;
26
+ readonly client?: unknown;
27
+ readonly chat?: {
28
+ readonly input?: unknown;
29
+ readonly output?: unknown;
30
+ };
31
+ };
32
+ node: import("@relkit/graph").AgentRegistration;
33
+ provider: import("@relkit/agents").AgentStateProvider;
34
+ scope: AgentRequestScope;
35
+ trusted: unknown;
36
+ }>;
37
+ export declare function validateAgentValue(schema: StandardSchemaV1, value: unknown): Promise<unknown>;
38
+ export declare function validateAgentInput(resolved: Awaited<ReturnType<typeof agentContext>>, payload: unknown): Promise<unknown>;
39
+ export declare const agentLimits: AgentStateLimits;
40
+ export declare function digest(value: unknown): string;
41
+ export declare function verifiedAgentRequestDigest(input: AgentInput): string;
42
+ export declare function encodedBytes(value: unknown): number;
43
+ export declare function agentOwner(options: RouteMaterializationOptions, profile: string): RunOwner;
44
+ //# sourceMappingURL=agent-rpc-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-rpc-support.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ACpC,SAAS,EAAE,MAAM;;wBAkHD,gBAAgB;yBACf,gBAAgB;0BACf,OAAO;wBACT;YAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;YAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;SAAE;;;;;;GArExE;AAED,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,OAAO,oBAIhF;AAED,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,EAClD,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,eAAO,MAAM,WAAW,EAAE,gBAWzB,CAAC;AAEF,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAI7C;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAUpE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,2BAA2B,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAQ1F"}
@@ -0,0 +1,111 @@
1
+ import { createHash } from "node:crypto";
2
+ import { AGENT_STATE_SCHEMA_VERSION, AGENT_STREAM_VERSION, canonicalJson, REALTIME_RUNTIME_LIMITS, } from "@relkit/contracts";
3
+ import { validate } from "@relkit/schema";
4
+ import { resolveClientIdentity } from "./client-identity.js";
5
+ import { getEntry, isRecord } from "./materialize-routes-utils.js";
6
+ import { ORPCError } from "@orpc/server";
7
+ import { requireClientAuthorization } from "./client-authorization.js";
8
+ export function requireAgentThreadId(value) {
9
+ if (typeof value !== "string" || value.length === 0 || value !== value.trim()) {
10
+ throw new TypeError("threadId must be a non-empty string without surrounding whitespace.");
11
+ }
12
+ return value;
13
+ }
14
+ export async function agentContext(input, context, options, operation) {
15
+ if (options.agentRuntime === undefined || options.clientIdentity === undefined)
16
+ throw new Error("Agent client runtime is unavailable.");
17
+ const node = options.plan.agents.find((candidate) => candidate.id === input.agentId);
18
+ const descriptor = getEntry(options.manifest.agents ?? {}, input.agentId);
19
+ if (node === undefined || node.client === undefined || !isAgent(descriptor))
20
+ throw new ORPCError("NOT_FOUND", { message: "Agent resource was not found." });
21
+ const identity = await resolveClientIdentity(options.clientIdentity, context.hono.req.raw, context.auth, true);
22
+ const trusted = await options.agentRuntime.trustedContext?.({
23
+ request: context.hono.req.raw,
24
+ ...(context.auth === undefined ? {} : { auth: context.auth }),
25
+ });
26
+ const authorize = isRecord(descriptor.client) ? descriptor.client.authorize : undefined;
27
+ if (typeof authorize === "function") {
28
+ await requireClientAuthorization(() => authorize({
29
+ agentId: input.agentId,
30
+ threadId: input.threadId,
31
+ runId: input.runId,
32
+ operation,
33
+ input: input.payload,
34
+ }, trusted), "agent");
35
+ }
36
+ const profile = node.stateProfile ?? "default";
37
+ const provider = await options.agentRuntime.provider(profile);
38
+ const scope = {
39
+ ...identity,
40
+ applicationId: options.agentRuntime.applicationId,
41
+ environment: options.agentRuntime.environment,
42
+ profile,
43
+ providerEpoch: await provider.getEpoch(),
44
+ agentId: input.agentId,
45
+ ownerScope: identity.identityScope,
46
+ authorizationGrantId: digest({ identity, agentId: input.agentId }),
47
+ };
48
+ return { descriptor, node, provider, scope, trusted };
49
+ }
50
+ export async function validateAgentValue(schema, value) {
51
+ const result = await validate(schema, value);
52
+ if (!("value" in result))
53
+ throw new TypeError("Agent value validation failed.");
54
+ return result.value;
55
+ }
56
+ export async function validateAgentInput(resolved, payload) {
57
+ try {
58
+ return await validateAgentValue(resolved.descriptor.input, payload);
59
+ }
60
+ catch (error) {
61
+ if (resolved.descriptor.chat?.input !== "message" || typeof payload !== "string")
62
+ throw error;
63
+ return validateAgentValue(resolved.descriptor.input, { message: payload });
64
+ }
65
+ }
66
+ export const agentLimits = {
67
+ maxSnapshotBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
68
+ maxHistoryPageBytes: REALTIME_RUNTIME_LIMITS.snapshotHistoryPageBytes,
69
+ maxJournalRecordBytes: REALTIME_RUNTIME_LIMITS.progressRecordBytes,
70
+ maxJournalBytesPerThread: REALTIME_RUNTIME_LIMITS.journalBytesPerThread,
71
+ maxStateBytesPerApplication: REALTIME_RUNTIME_LIMITS.agentStateBytes,
72
+ maxThreadsPerPrincipal: REALTIME_RUNTIME_LIMITS.threadsPerPrincipal,
73
+ maxActiveRunsPerPrincipal: REALTIME_RUNTIME_LIMITS.activeRunsPerPrincipal,
74
+ maxActiveRunsPerApplication: REALTIME_RUNTIME_LIMITS.activeRunsPerApplication,
75
+ terminalReserveBytes: REALTIME_RUNTIME_LIMITS.terminalReserveBytes,
76
+ terminalReserveRecords: REALTIME_RUNTIME_LIMITS.terminalReserveRecords,
77
+ };
78
+ export function digest(value) {
79
+ return `sha256:${createHash("sha256")
80
+ .update(canonicalJson(value))
81
+ .digest("hex")}`;
82
+ }
83
+ export function verifiedAgentRequestDigest(input) {
84
+ const value = input.resume === true
85
+ ? { payload: input.payload, waitingRevision: input.waitingRevision }
86
+ : input.payload;
87
+ const actual = digest(value);
88
+ if (input.requestDigest !== undefined && input.requestDigest !== actual) {
89
+ throw new TypeError("Agent request digest does not match its payload.");
90
+ }
91
+ return actual;
92
+ }
93
+ export function encodedBytes(value) {
94
+ return new TextEncoder().encode(JSON.stringify(value)).byteLength;
95
+ }
96
+ export function agentOwner(options, profile) {
97
+ return {
98
+ generationId: options.agentRuntime.generationId,
99
+ publicFingerprint: options.agentRuntime.publicFingerprint,
100
+ protocolVersion: AGENT_STREAM_VERSION,
101
+ schemaVersion: AGENT_STATE_SCHEMA_VERSION,
102
+ providerScope: profile,
103
+ };
104
+ }
105
+ function isAgent(value) {
106
+ return isRecord(value) && isSchema(value.input) && isSchema(value.output);
107
+ }
108
+ function isSchema(value) {
109
+ return isRecord(value) && isRecord(value["~standard"]) && value["~standard"].version === 1;
110
+ }
111
+ //# sourceMappingURL=agent-rpc-support.js.map