eve 0.83.2 → 0.84.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 (1562) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +1 -5
  3. package/dist/src/_virtual/_rolldown/runtime.js +1 -1
  4. package/dist/src/acp/adapter.d.ts +8 -5
  5. package/dist/src/acp/adapter.js +1 -1
  6. package/dist/src/ai/decide.d.ts +3 -7
  7. package/dist/src/ai/decide.js +1 -1
  8. package/dist/src/ai/decision-adapter.d.ts +7 -0
  9. package/dist/src/ai/decision-adapter.js +1 -0
  10. package/dist/src/ai/decision-types.d.ts +86 -0
  11. package/dist/src/approval/definition.d.ts +5 -12
  12. package/dist/src/approval/evaluation.d.ts +48 -0
  13. package/dist/src/approval/evaluation.js +1 -0
  14. package/dist/src/approval/status.d.ts +14 -0
  15. package/dist/src/approval/status.js +1 -0
  16. package/dist/src/channel/adapter-context.d.ts +1 -3
  17. package/dist/src/channel/adapter-context.js +1 -1
  18. package/dist/src/channel/adapter.d.ts +34 -26
  19. package/dist/src/channel/adapter.js +1 -1
  20. package/dist/src/channel/audience.d.ts +0 -3
  21. package/dist/src/channel/audience.js +1 -1
  22. package/dist/src/channel/auth/definitions.d.ts +532 -0
  23. package/dist/src/channel/auth/definitions.js +1 -0
  24. package/dist/src/channel/auth/jwt-ecdsa.js +1 -1
  25. package/dist/src/channel/auth/jwt-hmac.js +1 -1
  26. package/dist/src/channel/auth/oidc.js +1 -1
  27. package/dist/src/channel/channel-address.d.ts +12 -10
  28. package/dist/src/channel/channel-address.js +1 -1
  29. package/dist/src/channel/channel-operations.d.ts +21 -22
  30. package/dist/src/channel/channel-operations.js +1 -1
  31. package/dist/src/channel/compiled-channel.d.ts +4 -4
  32. package/dist/src/channel/conversation-context.js +1 -1
  33. package/dist/src/channel/cors.d.ts +2 -2
  34. package/dist/src/channel/cors.js +1 -1
  35. package/dist/src/channel/cross-channel-receive.d.ts +3 -3
  36. package/dist/src/channel/delivery-idempotency.d.ts +6 -0
  37. package/dist/src/channel/delivery-idempotency.js +1 -1
  38. package/dist/src/channel/delivery-metadata.d.ts +2 -2
  39. package/dist/src/channel/delivery.d.ts +8 -0
  40. package/dist/src/channel/delivery.js +1 -0
  41. package/dist/src/channel/interaction-prompts.d.ts +54 -0
  42. package/dist/src/channel/interaction-prompts.js +1 -0
  43. package/dist/src/channel/invoke-tool.d.ts +11 -18
  44. package/dist/src/channel/pending-authorization.d.ts +3 -14
  45. package/dist/src/channel/pending-authorization.js +1 -1
  46. package/dist/src/channel/prompt-queue.d.ts +11 -19
  47. package/dist/src/channel/prompt-queue.js +1 -1
  48. package/dist/src/channel/resolve-text.d.ts +11 -18
  49. package/dist/src/channel/resolve-text.js +2 -2
  50. package/dist/src/channel/resolved-prompt.d.ts +7 -5
  51. package/dist/src/channel/resolved-prompt.js +1 -1
  52. package/dist/src/channel/routes.d.ts +4 -4
  53. package/dist/src/channel/schedule.d.ts +2 -2
  54. package/dist/src/channel/schedule.js +1 -1
  55. package/dist/src/channel/send-input.d.ts +3 -3
  56. package/dist/src/channel/send-input.js +1 -1
  57. package/dist/src/channel/session-callback.js +1 -1
  58. package/dist/src/channel/session-not-active-error.d.ts +8 -12
  59. package/dist/src/channel/session-not-active-error.js +1 -1
  60. package/dist/src/channel/session.d.ts +33 -59
  61. package/dist/src/channel/session.js +1 -1
  62. package/dist/src/channel/sign-in.d.ts +61 -0
  63. package/dist/src/channel/sign-in.js +3 -0
  64. package/dist/src/channel/surface.d.ts +44 -0
  65. package/dist/src/channel/surface.js +1 -0
  66. package/dist/src/channel/task-card.d.ts +24 -114
  67. package/dist/src/channel/task-card.js +1 -1
  68. package/dist/src/channel/types.d.ts +116 -110
  69. package/dist/src/channel/types.js +1 -1
  70. package/dist/src/chunks/use-eve-agent-BbbguIdB.js +5030 -0
  71. package/dist/src/chunks/use-eve-agent-DWjyzplb.js +5077 -0
  72. package/dist/src/cli/commands/logs-events.d.ts +2 -0
  73. package/dist/src/cli/commands/logs-events.js +2 -2
  74. package/dist/src/cli/dev/command.js +1 -1
  75. package/dist/src/cli/dev/remote-print.d.ts +8 -0
  76. package/dist/src/cli/dev/remote-print.js +1 -0
  77. package/dist/src/cli/dev/tui/conversation-view.d.ts +24 -19
  78. package/dist/src/cli/dev/tui/conversation-view.js +1 -1
  79. package/dist/src/cli/dev/tui/diagnostic-presentation.d.ts +0 -10
  80. package/dist/src/cli/dev/tui/diagnostic-presentation.js +2 -3
  81. package/dist/src/cli/dev/tui/errors.d.ts +9 -65
  82. package/dist/src/cli/dev/tui/errors.js +1 -1
  83. package/dist/src/cli/dev/tui/prompt-command-handler.js +1 -1
  84. package/dist/src/cli/dev/tui/runner.js +3 -3
  85. package/dist/src/cli/dev/tui/task-records.d.ts +3 -3
  86. package/dist/src/cli/dev/tui/task-records.js +1 -1
  87. package/dist/src/cli/dev/tui/terminal-renderer.js +10 -10
  88. package/dist/src/cli/dev/tui/terminal-tool-part.d.ts +2 -2
  89. package/dist/src/cli/dev/tui/terminal-tool-part.js +1 -1
  90. package/dist/src/cli/dev/tui/test/fake-eve-server.d.ts +3 -3
  91. package/dist/src/cli/dev/tui/test/fake-eve-server.js +1 -1
  92. package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
  93. package/dist/src/cli/dev/tui/transcript-parts.d.ts +16 -16
  94. package/dist/src/cli/dev/tui/transcript-parts.js +3 -3
  95. package/dist/src/cli/dev/tui/transcript.d.ts +0 -4
  96. package/dist/src/cli/dev/tui/transcript.js +1 -1
  97. package/dist/src/cli/dev/tui/tui.js +1 -1
  98. package/dist/src/cli/run.d.ts +0 -2
  99. package/dist/src/cli/run.js +1 -1
  100. package/dist/src/cli/telemetry/index.js +1 -1
  101. package/dist/src/client/agent-base-url.d.ts +4 -0
  102. package/dist/src/client/agent-base-url.js +1 -0
  103. package/dist/src/client/agent-info-schema.d.ts +1 -923
  104. package/dist/src/client/agent-info-schema.js +1 -1
  105. package/dist/src/client/agent-info-types.d.ts +281 -0
  106. package/dist/src/client/agent-session.d.ts +19 -22
  107. package/dist/src/client/agent-session.js +1 -1
  108. package/dist/src/client/agent-stream-follower.d.ts +11 -20
  109. package/dist/src/client/agent-stream-follower.js +1 -1
  110. package/dist/src/client/client-error.d.ts +2 -1
  111. package/dist/src/client/client-error.js +1 -1
  112. package/dist/src/client/client.d.ts +1 -1
  113. package/dist/src/client/client.js +1 -1
  114. package/dist/src/client/conversation-client.d.ts +37 -28
  115. package/dist/src/client/conversation-client.js +1 -1
  116. package/dist/src/client/conversation-state.d.ts +70 -73
  117. package/dist/src/client/conversation-state.js +1 -1
  118. package/dist/src/client/conversation.d.ts +51 -0
  119. package/dist/src/client/conversation.js +1 -0
  120. package/dist/src/client/delivery-events.d.ts +3 -0
  121. package/dist/src/client/delivery-events.js +1 -0
  122. package/dist/src/client/delivery.d.ts +36 -0
  123. package/dist/src/client/delivery.js +1 -0
  124. package/dist/src/client/file-parts.d.ts +9 -4
  125. package/dist/src/client/file-parts.js +1 -1
  126. package/dist/src/client/health-schema.d.ts +1 -1
  127. package/dist/src/client/health-types.d.ts +6 -0
  128. package/dist/src/client/index.d.ts +17 -23
  129. package/dist/src/client/index.js +1 -1
  130. package/dist/src/client/message-types.d.ts +92 -0
  131. package/dist/src/client/message-types.js +1 -0
  132. package/dist/src/client/messages.d.ts +30 -0
  133. package/dist/src/client/messages.js +1 -0
  134. package/dist/src/client/ndjson.d.ts +6 -11
  135. package/dist/src/client/ndjson.js +3 -3
  136. package/dist/src/client/open-stream.d.ts +47 -20
  137. package/dist/src/client/open-stream.js +1 -1
  138. package/dist/src/client/optimistic-message-submissions.d.ts +10 -19
  139. package/dist/src/client/optimistic-message-submissions.js +1 -1
  140. package/dist/src/client/session-controls.d.ts +23 -26
  141. package/dist/src/client/session-controls.js +1 -1
  142. package/dist/src/client/session-event-stream.d.ts +5 -16
  143. package/dist/src/client/session-event-stream.js +1 -1
  144. package/dist/src/client/session-store-helpers.d.ts +8 -0
  145. package/dist/src/client/session-store-helpers.js +2 -0
  146. package/dist/src/client/session-store-state.d.ts +80 -0
  147. package/dist/src/client/session-store-state.js +1 -0
  148. package/dist/src/client/session-store.d.ts +48 -0
  149. package/dist/src/client/session-store.js +1 -0
  150. package/dist/src/client/session-utils.d.ts +45 -41
  151. package/dist/src/client/session-utils.js +2 -1
  152. package/dist/src/client/session.d.ts +32 -23
  153. package/dist/src/client/session.js +1 -1
  154. package/dist/src/client/sessions.d.ts +2 -2
  155. package/dist/src/client/stream-version.d.ts +3 -1
  156. package/dist/src/client/stream-version.js +1 -1
  157. package/dist/src/client/transcript.d.ts +43 -0
  158. package/dist/src/client/transcript.js +2 -0
  159. package/dist/src/client/types.d.ts +21 -82
  160. package/dist/src/client/url.d.ts +3 -3
  161. package/dist/src/compiled/.vendor-stamp.json +1 -1
  162. package/dist/src/compiled/@ai-sdk/anthropic/index.d.ts +34 -34
  163. package/dist/src/compiled/@ai-sdk/google/index.d.ts +15 -15
  164. package/dist/src/compiled/@ai-sdk/openai/index.d.ts +38 -38
  165. package/dist/src/compiled/@chat-adapter/slack/fetch-QqNM_Ef3.d.ts +4 -0
  166. package/dist/src/compiled/@chat-adapter/twilio/types-BaIqtt65.d.ts +100 -0
  167. package/dist/src/compiled/@linqapp/chat-sdk-adapter/adapter.d.ts +129 -0
  168. package/dist/src/compiled/@linqapp/chat-sdk-adapter/message-parser.d.ts +14 -0
  169. package/dist/src/compiled/@linqapp/chat-sdk-adapter/text-decorations.d.ts +28 -0
  170. package/dist/src/compiled/@workflow/core/runtime/step-executor.d.ts +1 -1
  171. package/dist/src/compiled/@workflow/core/serialization/types.d.ts +1 -1
  172. package/dist/src/compiled/@workflow/core/serialization.d.ts +2 -2
  173. package/dist/src/compiled/@workflow/core/telemetry/semantic-conventions.d.ts +2 -2
  174. package/dist/src/compiled/semver/index.d.ts +2 -0
  175. package/dist/src/compiler/development-extensions.js +1 -1
  176. package/dist/src/compiler/extension-compatibility.d.ts +19 -290
  177. package/dist/src/compiler/extension-compatibility.js +1 -1
  178. package/dist/src/compiler/manifest.d.ts +1 -9
  179. package/dist/src/compiler/manifest.js +1 -1
  180. package/dist/src/compiler/normalize-agent-config.js +1 -1
  181. package/dist/src/compiler/normalize-connection.js +1 -1
  182. package/dist/src/compiler/normalize-hook.js +1 -1
  183. package/dist/src/compiler/normalize-instructions.js +1 -1
  184. package/dist/src/compiler/normalize-manifest.js +1 -1
  185. package/dist/src/compiler/normalize-memory.js +1 -1
  186. package/dist/src/compiler/normalize-schedule.js +1 -1
  187. package/dist/src/compiler/normalize-skill.js +1 -1
  188. package/dist/src/compiler/normalize-subagent.d.ts +0 -5
  189. package/dist/src/compiler/normalize-subagent.js +1 -1
  190. package/dist/src/compiler/normalize-tool.js +1 -1
  191. package/dist/src/compiler/remote-agent-node.d.ts +1 -6
  192. package/dist/src/compiler/source-graph.d.ts +0 -1
  193. package/dist/src/compiler/source-graph.js +1 -1
  194. package/dist/src/computer-use/extension/lib/computer-use-sandbox.js +1 -1
  195. package/dist/src/computer-use/extension/lib/sandbox.d.ts +1 -1
  196. package/dist/src/computer-use/extension/lib/sandbox.js +1 -1
  197. package/dist/src/computer-use/extension/tools/computer_use.js +1 -1
  198. package/dist/src/connections/errors.d.ts +3 -3
  199. package/dist/src/context/accessors.d.ts +0 -13
  200. package/dist/src/context/accessors.js +1 -1
  201. package/dist/src/context/container.d.ts +8 -11
  202. package/dist/src/context/container.js +1 -1
  203. package/dist/src/context/key-names.d.ts +1 -0
  204. package/dist/src/context/key-names.js +1 -1
  205. package/dist/src/context/keys.d.ts +20 -104
  206. package/dist/src/context/keys.js +1 -1
  207. package/dist/src/context/memory-tools.d.ts +4 -2
  208. package/dist/src/context/memory-tools.js +1 -1
  209. package/dist/src/context/providers/connection.js +1 -1
  210. package/dist/src/context/providers/session.js +1 -1
  211. package/dist/src/context/schedule-collection-tools.d.ts +2 -2
  212. package/dist/src/context/schedule-collection-tools.js +1 -1
  213. package/dist/src/context/session-context.d.ts +4 -2
  214. package/dist/src/discover/extensions.d.ts +2 -3
  215. package/dist/src/discover/extensions.js +1 -1
  216. package/dist/src/discover/manifest.js +1 -1
  217. package/dist/src/discover/skills.js +1 -1
  218. package/dist/src/dynamic/definition.d.ts +98 -108
  219. package/dist/src/dynamic/definition.js +1 -1
  220. package/dist/src/evals/assertions/collector.js +1 -1
  221. package/dist/src/evals/assertions/run.d.ts +12 -11
  222. package/dist/src/evals/assertions/run.js +2 -2
  223. package/dist/src/evals/assertions/scoped.js +1 -1
  224. package/dist/src/evals/cli/eval-client.js +1 -1
  225. package/dist/src/evals/cli/eval.js +2 -2
  226. package/dist/src/evals/context.js +1 -1
  227. package/dist/src/evals/expect/index.d.ts +0 -1
  228. package/dist/src/evals/index.d.ts +2 -5
  229. package/dist/src/evals/judge.js +1 -1
  230. package/dist/src/evals/match.d.ts +20 -17
  231. package/dist/src/evals/match.js +1 -1
  232. package/dist/src/evals/mock-model.d.ts +5 -1
  233. package/dist/src/evals/mock-model.js +1 -1
  234. package/dist/src/evals/output.d.ts +3 -0
  235. package/dist/src/evals/output.js +1 -0
  236. package/dist/src/evals/reported-tool-name.js +1 -1
  237. package/dist/src/evals/reporters/index.d.ts +4 -4
  238. package/dist/src/evals/reporters/index.js +1 -1
  239. package/dist/src/evals/runner/artifacts.js +1 -1
  240. package/dist/src/evals/runner/derive-run-facts.d.ts +8 -40
  241. package/dist/src/evals/runner/derive-run-facts.js +1 -1
  242. package/dist/src/evals/runner/execute-eval.js +1 -1
  243. package/dist/src/evals/runner/execute-task.d.ts +3 -1
  244. package/dist/src/evals/runner/execute-task.js +1 -1
  245. package/dist/src/evals/runner/reporters/braintrust.d.ts +1 -1
  246. package/dist/src/evals/runner/reporters/braintrust.js +2 -2
  247. package/dist/src/evals/runner/reporters/console.d.ts +1 -1
  248. package/dist/src/evals/runner/reporters/console.js +1 -1
  249. package/dist/src/evals/runner/reporters/datadog.d.ts +1 -1
  250. package/dist/src/evals/runner/reporters/datadog.js +2 -2
  251. package/dist/src/evals/runner/reporters/junit.d.ts +1 -1
  252. package/dist/src/evals/runner/reporters/junit.js +2 -2
  253. package/dist/src/evals/runner/reporters/types.d.ts +2 -2
  254. package/dist/src/evals/runner/run-evals.d.ts +1 -1
  255. package/dist/src/evals/session-cleanup.d.ts +1 -1
  256. package/dist/src/evals/session-cleanup.js +1 -1
  257. package/dist/src/evals/session-content.d.ts +2 -2
  258. package/dist/src/evals/session-content.js +2 -1
  259. package/dist/src/evals/session-manager.d.ts +3 -6
  260. package/dist/src/evals/session-manager.js +1 -1
  261. package/dist/src/evals/session.d.ts +33 -24
  262. package/dist/src/evals/session.js +2 -2
  263. package/dist/src/evals/target.js +1 -1
  264. package/dist/src/evals/types.d.ts +115 -94
  265. package/dist/src/eve-channel/create-request.d.ts +3 -5
  266. package/dist/src/eve-channel/descendant-stream.d.ts +9 -0
  267. package/dist/src/eve-channel/descendant-stream.js +1 -0
  268. package/dist/src/eve-channel/index.d.ts +2 -2
  269. package/dist/src/eve-channel/index.js +1 -1
  270. package/dist/src/eve-channel/request.d.ts +7 -6
  271. package/dist/src/eve-channel/request.js +1 -3
  272. package/dist/src/eve-channel/stream-headers.d.ts +1 -1
  273. package/dist/src/eve-channel/stream-headers.js +1 -1
  274. package/dist/src/eve-channel/support.d.ts +25 -13
  275. package/dist/src/eve-channel/support.js +2 -2
  276. package/dist/src/eve-channel/types.d.ts +7 -30
  277. package/dist/src/execution/agent-sessions/message.d.ts +4 -0
  278. package/dist/src/execution/agent-sessions/message.js +1 -0
  279. package/dist/src/execution/agent-sessions/metadata.js +1 -1
  280. package/dist/src/execution/agent-sessions/remote-credentials.d.ts +19 -0
  281. package/dist/src/execution/agent-sessions/remote-credentials.js +1 -0
  282. package/dist/src/execution/agent-sessions/remote.d.ts +35 -13
  283. package/dist/src/execution/agent-sessions/remote.js +1 -1
  284. package/dist/src/execution/agent-sessions/requests.d.ts +6 -6
  285. package/dist/src/execution/agent-sessions/requests.js +1 -1
  286. package/dist/src/execution/agent-sessions/session.js +1 -1
  287. package/dist/src/execution/agent-sessions/steps.d.ts +26 -4
  288. package/dist/src/execution/agent-sessions/steps.js +1 -1
  289. package/dist/src/execution/agent-sessions/target.d.ts +2 -1
  290. package/dist/src/execution/agent-sessions/target.js +1 -1
  291. package/dist/src/execution/agent-sessions/usage.d.ts +0 -8
  292. package/dist/src/execution/agent-sessions/usage.js +1 -1
  293. package/dist/src/execution/cancelled-model-call-batch.d.ts +4 -2
  294. package/dist/src/execution/cancelled-model-call-batch.js +1 -1
  295. package/dist/src/execution/cancelled-turn-message.d.ts +2 -2
  296. package/dist/src/execution/cancelled-turn-message.js +1 -1
  297. package/dist/src/execution/catalog/connection-auth.js +1 -1
  298. package/dist/src/execution/catalog/connection-entry.js +1 -1
  299. package/dist/src/execution/catalog/rank.js +1 -1
  300. package/dist/src/execution/catalog/search.js +1 -1
  301. package/dist/src/execution/catalog/skills.js +1 -1
  302. package/dist/src/execution/catalog/step-catalog.js +1 -1
  303. package/dist/src/execution/child-binding.d.ts +19 -0
  304. package/dist/src/execution/child-binding.js +1 -0
  305. package/dist/src/execution/close-session-stream-step.d.ts +9 -0
  306. package/dist/src/execution/close-session-stream-step.js +1 -0
  307. package/dist/src/execution/coordination-dispatch-shared.d.ts +13 -3
  308. package/dist/src/execution/coordination-dispatch-shared.js +1 -1
  309. package/dist/src/execution/coordination-dispatch-step.d.ts +9 -13
  310. package/dist/src/execution/coordination-dispatch-step.js +1 -1
  311. package/dist/src/execution/deliver-payloads.js +1 -1
  312. package/dist/src/execution/durable-session-store.d.ts +2 -5
  313. package/dist/src/execution/dynamic-workflow/tool.js +1 -1
  314. package/dist/src/execution/dynamic-workflow/workflow.js +1 -1
  315. package/dist/src/execution/failure-summary.d.ts +11 -0
  316. package/dist/src/execution/failure-summary.js +1 -0
  317. package/dist/src/execution/forward-session-input.d.ts +2 -2
  318. package/dist/src/execution/forward-session-input.js +1 -1
  319. package/dist/src/execution/invoke-tool.js +1 -1
  320. package/dist/src/execution/legacy-session/prepare-step.js +1 -1
  321. package/dist/src/execution/legacy-session/snapshot.d.ts +4 -1
  322. package/dist/src/execution/legacy-session/snapshot.js +1 -1
  323. package/dist/src/execution/model-call-batching.d.ts +3 -3
  324. package/dist/src/execution/model-call-batching.js +1 -1
  325. package/dist/src/execution/ndjson-stream.d.ts +1 -1
  326. package/dist/src/execution/node-step.d.ts +2 -8
  327. package/dist/src/execution/node-step.js +1 -1
  328. package/dist/src/execution/proxied-deliver-step.d.ts +8 -3
  329. package/dist/src/execution/proxied-deliver-step.js +1 -1
  330. package/dist/src/execution/public-destination.d.ts +34 -0
  331. package/dist/src/execution/public-destination.js +1 -0
  332. package/dist/src/execution/publish-session-events.d.ts +98 -36
  333. package/dist/src/execution/publish-session-events.js +1 -1
  334. package/dist/src/execution/runtime-context.js +1 -1
  335. package/dist/src/execution/sandbox/abort-bound-session.js +1 -1
  336. package/dist/src/execution/sandbox/bash.js +1 -1
  337. package/dist/src/execution/sandbox/bindings/docker-connection.js +1 -1
  338. package/dist/src/execution/sandbox/bindings/docker.js +1 -1
  339. package/dist/src/execution/sandbox/bindings/eve-image.d.ts +0 -2
  340. package/dist/src/execution/sandbox/bindings/eve-image.js +1 -1
  341. package/dist/src/execution/sandbox/bindings/just-bash-runtime.js +1 -1
  342. package/dist/src/execution/sandbox/bindings/vercel.js +1 -1
  343. package/dist/src/execution/sandbox/ensure.js +1 -1
  344. package/dist/src/{extensions/code/extension/lib → execution/sandbox}/grep-search.d.ts +3 -2
  345. package/dist/src/execution/sandbox/grep-search.js +6 -0
  346. package/dist/src/execution/sandbox/read-file.d.ts +1 -1
  347. package/dist/src/execution/sandbox/session.js +1 -1
  348. package/dist/src/execution/sandbox/workspace-root.d.ts +31 -0
  349. package/dist/src/execution/sandbox/workspace-root.js +1 -0
  350. package/dist/src/execution/session/active-turn.d.ts +12 -6
  351. package/dist/src/execution/session/active-turn.js +1 -1
  352. package/dist/src/execution/session/admission.d.ts +7 -2
  353. package/dist/src/execution/session/admission.js +1 -1
  354. package/dist/src/execution/session/answer-caller.d.ts +4 -4
  355. package/dist/src/execution/session/answer-caller.js +1 -1
  356. package/dist/src/execution/session/checkpoint-migrations.d.ts +4 -6
  357. package/dist/src/execution/session/checkpoint-migrations.js +1 -1
  358. package/dist/src/execution/session/control-delivery.d.ts +4 -0
  359. package/dist/src/execution/session/control-delivery.js +1 -0
  360. package/dist/src/execution/session/delivery-facts.d.ts +27 -0
  361. package/dist/src/execution/session/delivery-facts.js +1 -0
  362. package/dist/src/execution/session/end-sandbox-step.js +1 -1
  363. package/dist/src/execution/session/entry.js +1 -1
  364. package/dist/src/execution/session/finalization.d.ts +4 -0
  365. package/dist/src/execution/session/finalization.js +1 -1
  366. package/dist/src/execution/session/handoff-state.js +1 -1
  367. package/dist/src/execution/session/handoff-steps.d.ts +1 -8
  368. package/dist/src/execution/session/handoff-steps.js +1 -1
  369. package/dist/src/execution/session/handoff.d.ts +5 -3
  370. package/dist/src/execution/session/handoff.js +1 -1
  371. package/dist/src/execution/session/input-queue.d.ts +8 -2
  372. package/dist/src/execution/session/input-queue.js +1 -1
  373. package/dist/src/execution/session/interrupted-step.d.ts +64 -0
  374. package/dist/src/execution/session/interrupted-step.js +3 -0
  375. package/dist/src/execution/session/next-input.d.ts +7 -1
  376. package/dist/src/execution/session/next-input.js +1 -1
  377. package/dist/src/execution/session/pending-turn-state.d.ts +32 -12
  378. package/dist/src/execution/session/pending-turn-state.js +1 -1
  379. package/dist/src/execution/session/prewarm-step.d.ts +1 -1
  380. package/dist/src/execution/session/prewarm-step.js +1 -1
  381. package/dist/src/execution/session/program.js +1 -1
  382. package/dist/src/execution/session/settle-control-delivery-step.d.ts +8 -0
  383. package/dist/src/execution/session/settle-control-delivery-step.js +1 -0
  384. package/dist/src/execution/session/settle-duplicate-delivery-step.d.ts +8 -0
  385. package/dist/src/execution/session/settle-duplicate-delivery-step.js +1 -0
  386. package/dist/src/execution/session/state-delta.d.ts +2 -12
  387. package/dist/src/execution/session/state-delta.js +1 -1
  388. package/dist/src/execution/session/step-decision-check.d.ts +9 -0
  389. package/dist/src/execution/session/step-decision-check.js +1 -0
  390. package/dist/src/execution/session/step-state-delta.d.ts +16 -0
  391. package/dist/src/execution/session/step-state-delta.js +1 -0
  392. package/dist/src/execution/session/task-tool-tracing-step.d.ts +0 -3
  393. package/dist/src/execution/session/task-tool-tracing-step.js +1 -1
  394. package/dist/src/execution/session/turn-event-handler.d.ts +6 -16
  395. package/dist/src/execution/session/turn-event-handler.js +1 -1
  396. package/dist/src/execution/session/turn-step-result.d.ts +7 -2
  397. package/dist/src/execution/session/turn-step-result.js +1 -1
  398. package/dist/src/execution/session/turn-step-types.d.ts +35 -33
  399. package/dist/src/execution/session/turn-step.js +1 -1
  400. package/dist/src/execution/session/turn.d.ts +19 -32
  401. package/dist/src/execution/session/turn.js +1 -1
  402. package/dist/src/execution/session-callback-request.d.ts +7 -1
  403. package/dist/src/execution/session-callback-request.js +1 -1
  404. package/dist/src/execution/session-event-stream.d.ts +37 -16
  405. package/dist/src/execution/session-event-stream.js +1 -1
  406. package/dist/src/execution/session-inbox/end-stranded-session.d.ts +7 -1
  407. package/dist/src/execution/session-inbox/end-stranded-session.js +1 -1
  408. package/dist/src/execution/session-inbox/inbox.js +1 -1
  409. package/dist/src/execution/session-inbox/owner.d.ts +5 -2
  410. package/dist/src/execution/session-inbox/owner.js +1 -1
  411. package/dist/src/execution/session-inbox/pre-v27.d.ts +5 -0
  412. package/dist/src/execution/session-inbox/pre-v27.js +1 -0
  413. package/dist/src/execution/session-inbox/protocol.js +1 -1
  414. package/dist/src/execution/session-inbox/resume.js +1 -1
  415. package/dist/src/execution/session-inbox/stranded-replay-guard.js +1 -1
  416. package/dist/src/execution/session-workflow-tool-run.js +1 -1
  417. package/dist/src/execution/session.d.ts +3 -14
  418. package/dist/src/execution/session.js +2 -2
  419. package/dist/src/execution/settle-cancelled-turn-step.d.ts +3 -0
  420. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  421. package/dist/src/execution/stop-runs.d.ts +35 -0
  422. package/dist/src/execution/stop-runs.js +1 -0
  423. package/dist/src/execution/tasks/model-step.d.ts +5 -9
  424. package/dist/src/execution/tasks/model-step.js +1 -1
  425. package/dist/src/execution/tasks/render.d.ts +5 -2
  426. package/dist/src/execution/tasks/render.js +1 -1
  427. package/dist/src/execution/tasks/session.d.ts +6 -3
  428. package/dist/src/execution/tasks/session.js +1 -1
  429. package/dist/src/execution/tasks/start.d.ts +9 -6
  430. package/dist/src/execution/tasks/start.js +1 -1
  431. package/dist/src/execution/tasks/steps.d.ts +11 -6
  432. package/dist/src/execution/tasks/steps.js +1 -1
  433. package/dist/src/execution/tasks/table.d.ts +18 -5
  434. package/dist/src/execution/tasks/table.js +1 -1
  435. package/dist/src/execution/tasks/task-id-input.js +1 -1
  436. package/dist/src/execution/terminal-session-completion-step.d.ts +11 -1
  437. package/dist/src/execution/terminal-session-completion-step.js +1 -1
  438. package/dist/src/execution/terminal-session-failure-step.d.ts +6 -1
  439. package/dist/src/execution/terminal-session-failure-step.js +1 -1
  440. package/dist/src/execution/terminate-child-sessions-step.d.ts +5 -1
  441. package/dist/src/execution/terminate-child-sessions-step.js +1 -1
  442. package/dist/src/execution/tools/agent-router-workflow.js +1 -1
  443. package/dist/src/execution/tools/workflow/answer.d.ts +4 -5
  444. package/dist/src/execution/tools/workflow/answer.js +1 -1
  445. package/dist/src/execution/tools/workflow/apply-run-messages-step.d.ts +1 -1
  446. package/dist/src/execution/tools/workflow/apply-run-messages-step.js +1 -1
  447. package/dist/src/execution/tools/workflow/ask.d.ts +3 -3
  448. package/dist/src/execution/tools/workflow/body.js +1 -1
  449. package/dist/src/execution/tools/workflow/harness-definition.js +1 -1
  450. package/dist/src/execution/tools/workflow/messages.d.ts +25 -33
  451. package/dist/src/execution/tools/workflow/messages.js +1 -1
  452. package/dist/src/execution/tools/workflow/owner-inbox.d.ts +9 -5
  453. package/dist/src/execution/tools/workflow/owner-inbox.js +1 -1
  454. package/dist/src/execution/tools/workflow/owner.d.ts +3 -3
  455. package/dist/src/execution/tools/workflow/owner.js +1 -1
  456. package/dist/src/execution/tools/workflow/serve.js +1 -1
  457. package/dist/src/execution/tools/workflow/step.js +1 -1
  458. package/dist/src/execution/tools/workflow/withdraw-step.d.ts +2 -2
  459. package/dist/src/execution/tools/workflow/withdraw-step.js +1 -1
  460. package/dist/src/execution/v26-history.d.ts +28 -0
  461. package/dist/src/execution/v26-history.fixtures.d.ts +4 -0
  462. package/dist/src/execution/v26-history.fixtures.js +2 -0
  463. package/dist/src/execution/v26-history.js +1 -0
  464. package/dist/src/execution/web-fetch/html.js +3 -4
  465. package/dist/src/execution/web-fetch/request.js +1 -1
  466. package/dist/src/execution/workflow-errors.d.ts +5 -0
  467. package/dist/src/execution/workflow-errors.js +1 -1
  468. package/dist/src/execution/workflow-runtime.js +1 -1
  469. package/dist/src/extensions/code/extension/extension.d.ts +1 -11
  470. package/dist/src/extensions/code/extension/extension.js +1 -1
  471. package/dist/src/extensions/code/extension/lib/prwatch-github.d.ts +5 -1
  472. package/dist/src/extensions/code/extension/lib/prwatch-github.js +1 -1
  473. package/dist/src/extensions/code/extension/lib/repository-root.js +1 -1
  474. package/dist/src/extensions/code/extension/lib/sandbox.d.ts +0 -4
  475. package/dist/src/extensions/code/extension/lib/sandbox.js +2 -2
  476. package/dist/src/extensions/code/extension/lib/tooling.d.ts +1 -1
  477. package/dist/src/extensions/code/extension/lib/tooling.js +1 -1
  478. package/dist/src/extensions/code/extension/lib/workspace-root.d.ts +1 -31
  479. package/dist/src/extensions/code/extension/lib/workspace-root.js +1 -1
  480. package/dist/src/extensions/code/extension/subagents/worker/agent.d.ts +1 -1
  481. package/dist/src/extensions/code/extension/subagents/worker/agent.js +1 -1
  482. package/dist/src/extensions/code/extension/tools/apply_patch.js +2 -2
  483. package/dist/src/extensions/code/extension/tools/grep.d.ts +1 -28
  484. package/dist/src/extensions/code/extension/tools/grep.js +1 -1
  485. package/dist/src/extensions/code/sandbox.d.ts +1 -0
  486. package/dist/src/extensions/code/sandbox.js +1 -0
  487. package/dist/src/extensions/code/tools.d.ts +1 -5
  488. package/dist/src/extensions/code/tools.js +1 -1
  489. package/dist/src/extensions/git/extension/extension.d.ts +3 -3
  490. package/dist/src/extensions/git/extension/instructions/github.d.ts +1 -1
  491. package/dist/src/extensions/git/extension/instructions/github.js +1 -1
  492. package/dist/src/extensions/git/extension/lib/gh-tool.d.ts +2 -11
  493. package/dist/src/extensions/git/extension/lib/gh-tool.js +1 -1
  494. package/dist/src/extensions/git/extension/lib/github-shell.d.ts +13 -3
  495. package/dist/src/extensions/git/extension/lib/sandbox.d.ts +0 -4
  496. package/dist/src/extensions/git/extension/lib/sandbox.js +1 -1
  497. package/dist/src/extensions/git/extension/skills/pr.d.ts +1 -4
  498. package/dist/src/extensions/git/extension/skills/pr.js +1 -1
  499. package/dist/src/extensions/git/extension/tools/gh.d.ts +1 -26
  500. package/dist/src/extensions/git/extension/tools/gh.js +1 -1
  501. package/dist/src/framework/sources/modules/schedule-collection-wrapper.js +1 -1
  502. package/dist/src/harness/action-presentation.d.ts +3 -5
  503. package/dist/src/harness/action-presentation.js +1 -1
  504. package/dist/src/harness/action-result-helpers.d.ts +2 -8
  505. package/dist/src/harness/action-result-helpers.js +1 -1
  506. package/dist/src/harness/approval-outcome.d.ts +32 -0
  507. package/dist/src/harness/approval-outcome.js +1 -0
  508. package/dist/src/harness/attachment-staging.js +1 -1
  509. package/dist/src/harness/authorization.d.ts +2 -3
  510. package/dist/src/harness/authorization.js +1 -1
  511. package/dist/src/harness/call-executor.d.ts +118 -0
  512. package/dist/src/harness/call-executor.js +1 -0
  513. package/dist/src/harness/call-facts.d.ts +31 -0
  514. package/dist/src/harness/call-facts.js +1 -0
  515. package/dist/src/harness/call-outcome.d.ts +6 -0
  516. package/dist/src/harness/call-outcome.js +1 -0
  517. package/dist/src/harness/compaction/engine.d.ts +11 -0
  518. package/dist/src/harness/compaction/engine.js +2 -2
  519. package/dist/src/harness/compaction/over-limit-error.d.ts +7 -0
  520. package/dist/src/harness/compaction/over-limit-error.js +1 -0
  521. package/dist/src/harness/compaction/prompt.js +1 -1
  522. package/dist/src/harness/compaction/step.d.ts +34 -5
  523. package/dist/src/harness/compaction/step.js +1 -1
  524. package/dist/src/harness/coordination.js +1 -1
  525. package/dist/src/harness/current-messages.d.ts +10 -0
  526. package/dist/src/harness/current-messages.js +1 -1
  527. package/dist/src/harness/emission.d.ts +9 -15
  528. package/dist/src/harness/emission.js +1 -1
  529. package/dist/src/harness/execute-call.d.ts +6 -23
  530. package/dist/src/harness/execute-call.js +1 -1
  531. package/dist/src/harness/execute-tool.d.ts +7 -3
  532. package/dist/src/harness/facts.d.ts +82 -0
  533. package/dist/src/harness/facts.js +1 -0
  534. package/dist/src/harness/finish-reason.d.ts +6 -1
  535. package/dist/src/harness/generation-steering.d.ts +4 -2
  536. package/dist/src/harness/generation-steering.js +1 -1
  537. package/dist/src/harness/hitl/approval-prompt.d.ts +3 -3
  538. package/dist/src/harness/hitl/approval-prompt.js +3 -3
  539. package/dist/src/harness/hitl/approvals.d.ts +66 -78
  540. package/dist/src/harness/hitl/approvals.js +2 -1
  541. package/dist/src/harness/hitl/approved-calls.d.ts +14 -36
  542. package/dist/src/harness/hitl/approved-calls.js +1 -1
  543. package/dist/src/harness/hitl/budget-request.d.ts +8 -46
  544. package/dist/src/harness/hitl/budget-request.js +1 -1
  545. package/dist/src/harness/hitl/budget.d.ts +9 -8
  546. package/dist/src/harness/hitl/budget.js +1 -1
  547. package/dist/src/harness/hitl/delivery.d.ts +16 -17
  548. package/dist/src/harness/hitl/delivery.js +1 -1
  549. package/dist/src/harness/hitl/index.d.ts +14 -19
  550. package/dist/src/harness/hitl/index.js +1 -1
  551. package/dist/src/harness/hitl/intake.d.ts +32 -43
  552. package/dist/src/harness/hitl/intake.js +1 -1
  553. package/dist/src/harness/hitl/relays.d.ts +7 -51
  554. package/dist/src/harness/hitl/relays.js +1 -1
  555. package/dist/src/harness/hitl/requests.d.ts +11 -53
  556. package/dist/src/harness/hitl/requests.js +1 -1
  557. package/dist/src/harness/hitl/responders.d.ts +50 -0
  558. package/dist/src/harness/hitl/responders.js +1 -0
  559. package/dist/src/harness/hitl/sign-ins.d.ts +7 -3
  560. package/dist/src/harness/hitl/sign-ins.js +1 -1
  561. package/dist/src/harness/hitl/stale-responses.d.ts +11 -11
  562. package/dist/src/harness/hitl/stale-responses.js +3 -3
  563. package/dist/src/harness/inline-tool-authorization.d.ts +8 -9
  564. package/dist/src/harness/inline-tool-authorization.js +1 -1
  565. package/dist/src/harness/interaction-facts.d.ts +36 -0
  566. package/dist/src/harness/interaction-facts.js +1 -0
  567. package/dist/src/harness/interaction-relay.d.ts +10 -0
  568. package/dist/src/harness/interaction-relay.js +1 -0
  569. package/dist/src/harness/interrupted-attempt.d.ts +19 -0
  570. package/dist/src/harness/interrupted-attempt.js +2 -0
  571. package/dist/src/harness/messages.d.ts +28 -15
  572. package/dist/src/harness/messages.js +1 -1
  573. package/dist/src/harness/model-call/call.d.ts +31 -13
  574. package/dist/src/harness/model-call/call.js +1 -1
  575. package/dist/src/harness/model-call/errors.js +1 -1
  576. package/dist/src/harness/model-call/failure.d.ts +10 -48
  577. package/dist/src/harness/model-call/failure.js +1 -1
  578. package/dist/src/harness/model-call/model.js +1 -1
  579. package/dist/src/harness/model-call/recovery.d.ts +4 -32
  580. package/dist/src/harness/model-call/recovery.js +1 -1
  581. package/dist/src/harness/model-call/request.d.ts +0 -1
  582. package/dist/src/harness/model-call/request.js +1 -1
  583. package/dist/src/harness/model-call/response.d.ts +22 -12
  584. package/dist/src/harness/model-call/response.js +1 -1
  585. package/dist/src/harness/model-call/retry.d.ts +23 -6
  586. package/dist/src/harness/model-call/retry.js +1 -1
  587. package/dist/src/harness/model-call/run.d.ts +4 -12
  588. package/dist/src/harness/model-call/run.js +1 -1
  589. package/dist/src/harness/model-call/tools.d.ts +0 -19
  590. package/dist/src/harness/model-call/tools.js +1 -1
  591. package/dist/src/harness/model-call/unique-call-ids.d.ts +13 -0
  592. package/dist/src/harness/model-call/unique-call-ids.js +1 -0
  593. package/dist/src/harness/model-call/usage.d.ts +7 -5
  594. package/dist/src/harness/model-call/usage.js +1 -1
  595. package/dist/src/harness/ordered-stream-emitter.d.ts +1 -0
  596. package/dist/src/harness/ordered-stream-emitter.js +1 -1
  597. package/dist/src/harness/provider-tool-history.js +1 -1
  598. package/dist/src/harness/publication.d.ts +4 -0
  599. package/dist/src/harness/publication.js +1 -0
  600. package/dist/src/harness/request-envelope.d.ts +0 -3
  601. package/dist/src/harness/request-envelope.js +1 -1
  602. package/dist/src/harness/running-work.d.ts +10 -0
  603. package/dist/src/harness/running-work.js +1 -0
  604. package/dist/src/harness/session-machine/cascade.d.ts +17 -0
  605. package/dist/src/harness/session-machine/cascade.js +1 -0
  606. package/dist/src/harness/session-machine/commit.d.ts +16 -16
  607. package/dist/src/harness/session-machine/commit.js +1 -1
  608. package/dist/src/harness/session-machine/current.d.ts +25 -9
  609. package/dist/src/harness/session-machine/current.js +1 -1
  610. package/dist/src/harness/session-machine/state.d.ts +43 -16
  611. package/dist/src/harness/session-machine/state.js +1 -1
  612. package/dist/src/harness/session-machine/suspended-steps.d.ts +22 -0
  613. package/dist/src/harness/session-machine/suspended-steps.js +1 -0
  614. package/dist/src/harness/session-machine/transitions.d.ts +144 -120
  615. package/dist/src/harness/session-machine/transitions.js +1 -1
  616. package/dist/src/harness/session-machine/view.d.ts +12 -8
  617. package/dist/src/harness/session-machine/view.js +1 -1
  618. package/dist/src/harness/session-machine/waiting.d.ts +16 -0
  619. package/dist/src/harness/session-machine/waiting.js +1 -0
  620. package/dist/src/harness/session-usage.d.ts +22 -0
  621. package/dist/src/harness/session-usage.js +1 -0
  622. package/dist/src/harness/step/after-model.d.ts +1 -4
  623. package/dist/src/harness/step/after-model.js +1 -1
  624. package/dist/src/harness/step/context.d.ts +21 -21
  625. package/dist/src/harness/step/context.js +1 -1
  626. package/dist/src/harness/step/intake.d.ts +7 -8
  627. package/dist/src/harness/step/intake.js +1 -1
  628. package/dist/src/harness/step/park.d.ts +19 -0
  629. package/dist/src/harness/step/park.js +1 -0
  630. package/dist/src/harness/step/prompt.d.ts +4 -5
  631. package/dist/src/harness/step/prompt.js +1 -1
  632. package/dist/src/harness/step-hooks.d.ts +24 -24
  633. package/dist/src/harness/step-hooks.js +1 -1
  634. package/dist/src/harness/stream-actions.d.ts +3 -9
  635. package/dist/src/harness/stream-actions.js +1 -1
  636. package/dist/src/harness/token-estimate.js +1 -1
  637. package/dist/src/harness/tool-history-repair.js +1 -1
  638. package/dist/src/harness/tool-loop.js +1 -1
  639. package/dist/src/harness/tools.d.ts +22 -38
  640. package/dist/src/harness/tools.js +1 -1
  641. package/dist/src/harness/types.d.ts +69 -67
  642. package/dist/src/harness/user-parts.d.ts +4 -0
  643. package/dist/src/harness/user-parts.js +1 -0
  644. package/dist/src/harness/workflow-tool-runs.d.ts +0 -1
  645. package/dist/src/harness/workflow-tool-runs.js +1 -1
  646. package/dist/src/instrumentation/ai-sdk-hook-bridge.d.ts +2 -2
  647. package/dist/src/instrumentation/ai-sdk-hook-bridge.js +1 -1
  648. package/dist/src/instrumentation/channel-delivery.d.ts +4 -23
  649. package/dist/src/instrumentation/channel-delivery.js +1 -1
  650. package/dist/src/instrumentation/content.d.ts +1 -7
  651. package/dist/src/instrumentation/content.js +1 -1
  652. package/dist/src/instrumentation/dispatch.js +1 -1
  653. package/dist/src/instrumentation/lifecycle.d.ts +135 -198
  654. package/dist/src/instrumentation/lifecycle.js +1 -1
  655. package/dist/src/instrumentation/memory.d.ts +4 -2
  656. package/dist/src/instrumentation/memory.js +1 -1
  657. package/dist/src/instrumentation/native-events.d.ts +17 -10
  658. package/dist/src/instrumentation/native-events.js +1 -1
  659. package/dist/src/instrumentation/prepare-trace-context.d.ts +3 -3
  660. package/dist/src/instrumentation/provider.d.ts +20 -28
  661. package/dist/src/instrumentation/providers.js +1 -1
  662. package/dist/src/instrumentation/runtime-context.d.ts +1 -0
  663. package/dist/src/instrumentation/runtime-context.js +1 -1
  664. package/dist/src/instrumentation/runtime.d.ts +9 -30
  665. package/dist/src/instrumentation/runtime.js +1 -1
  666. package/dist/src/instrumentation/scope.d.ts +6 -0
  667. package/dist/src/instrumentation/scope.js +1 -0
  668. package/dist/src/instrumentation/session-context.d.ts +1 -1
  669. package/dist/src/instrumentation/session-context.js +1 -1
  670. package/dist/src/instrumentation/session-init.js +1 -1
  671. package/dist/src/instrumentation/setup-context.d.ts +2 -2
  672. package/dist/src/instrumentation/setup-context.js +1 -1
  673. package/dist/src/instrumentation/state.d.ts +0 -21
  674. package/dist/src/instrumentation/state.js +1 -1
  675. package/dist/src/internal/application/dev-environment.d.ts +8 -2
  676. package/dist/src/internal/application/dev-environment.js +1 -1
  677. package/dist/src/internal/application/optional-package-install.js +1 -1
  678. package/dist/src/internal/application/stamped-package-version.js +1 -1
  679. package/dist/src/internal/authored-asset-import-plugin.d.ts +8 -7
  680. package/dist/src/internal/authored-asset-import-plugin.js +1 -1
  681. package/dist/src/internal/authored-definition/approval.d.ts +2 -4
  682. package/dist/src/internal/authored-definition/approval.js +1 -1
  683. package/dist/src/internal/authored-definition/connection.js +1 -1
  684. package/dist/src/internal/authored-definition/core.d.ts +1 -1
  685. package/dist/src/internal/authored-definition/core.js +1 -1
  686. package/dist/src/internal/authored-definition/memory.js +1 -1
  687. package/dist/src/internal/authored-definition/schema-backed.d.ts +0 -3
  688. package/dist/src/internal/authored-definition/schema-backed.js +1 -1
  689. package/dist/src/internal/authored-module-loader.d.ts +0 -1
  690. package/dist/src/internal/authored-module-loader.js +1 -1
  691. package/dist/src/internal/authored-package-boundary.js +1 -1
  692. package/dist/src/internal/git.d.ts +2 -0
  693. package/dist/src/internal/git.js +1 -0
  694. package/dist/src/internal/grep.d.ts +1 -0
  695. package/dist/src/internal/grep.js +1 -0
  696. package/dist/src/internal/helpers/markdown.js +1 -1
  697. package/dist/src/internal/invocation/agent-invocation.d.ts +16 -19
  698. package/dist/src/internal/invocation/metadata.d.ts +0 -2
  699. package/dist/src/internal/invocation/metadata.js +1 -1
  700. package/dist/src/internal/invocation/workflow-execution.d.ts +4 -4
  701. package/dist/src/internal/invocation/workflow-execution.js +1 -1
  702. package/dist/src/internal/legacy-events.d.ts +5 -0
  703. package/dist/src/internal/legacy-events.js +1 -0
  704. package/dist/src/internal/logging.d.ts +0 -12
  705. package/dist/src/internal/logging.js +1 -1
  706. package/dist/src/internal/mcp/protected-resource.js +1 -1
  707. package/dist/src/internal/mcp/published-tools.js +1 -1
  708. package/dist/src/internal/model-auth/api-key.js +1 -1
  709. package/dist/src/internal/model-auth/development-broker-client.js +1 -1
  710. package/dist/src/internal/model-auth/development-broker-server.js +1 -1
  711. package/dist/src/internal/model-auth/transport.js +1 -1
  712. package/dist/src/internal/nitro/dev-client-address.d.ts +12 -0
  713. package/dist/src/internal/nitro/dev-client-address.js +1 -1
  714. package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
  715. package/dist/src/internal/nitro/dev-runtime-generation-metadata.js +1 -1
  716. package/dist/src/internal/nitro/host/build-extension.js +2 -2
  717. package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
  718. package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -1
  719. package/dist/src/internal/nitro/host/dev-server-state.js +1 -1
  720. package/dist/src/internal/nitro/host/drained-nitro-dev-server.js +1 -1
  721. package/dist/src/internal/nitro/host/start-development-server.js +1 -1
  722. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.js +1 -1
  723. package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
  724. package/dist/src/internal/nitro/routes/channel-request-instrumentation.d.ts +6 -3
  725. package/dist/src/internal/nitro/routes/channel-request-instrumentation.js +1 -1
  726. package/dist/src/internal/nitro/routes/channel-route-context.d.ts +8 -1
  727. package/dist/src/internal/nitro/routes/info.js +1 -1
  728. package/dist/src/internal/nitro/routes/schedule-task.js +1 -1
  729. package/dist/src/internal/scaffold.d.ts +5 -0
  730. package/dist/src/internal/scaffold.js +1 -0
  731. package/dist/src/internal/workflow/cancel-expired-development-run.js +1 -1
  732. package/dist/src/internal/workflow/development-world-client.js +1 -1
  733. package/dist/src/internal/workflow/development-world-server.js +1 -1
  734. package/dist/src/internal/workflow/local-world-data-directory.js +1 -1
  735. package/dist/src/internal/workspace.d.ts +1 -0
  736. package/dist/src/internal/workspace.js +1 -0
  737. package/dist/src/models/auto.d.ts +27 -14
  738. package/dist/src/models/auto.js +2 -2
  739. package/dist/src/protocol/delivery.d.ts +11 -0
  740. package/dist/src/protocol/delivery.js +1 -0
  741. package/dist/src/protocol/descendant-observation.d.ts +12 -0
  742. package/dist/src/protocol/descendant-observation.js +1 -0
  743. package/dist/src/protocol/interaction-json.d.ts +66 -0
  744. package/dist/src/protocol/interaction-json.js +1 -0
  745. package/dist/src/protocol/interaction-options.d.ts +4 -0
  746. package/dist/src/protocol/interaction-options.js +1 -0
  747. package/dist/src/protocol/remote-agent-protocol.d.ts +28 -1
  748. package/dist/src/protocol/remote-agent-protocol.js +1 -1
  749. package/dist/src/protocol/routes.d.ts +3 -2
  750. package/dist/src/protocol/routes.js +1 -1
  751. package/dist/src/protocol/session-event.d.ts +22 -0
  752. package/dist/src/protocol/session-event.js +1 -0
  753. package/dist/src/protocol/session-events/authoring.d.ts +2 -0
  754. package/dist/src/protocol/session-events/authoring.js +1 -0
  755. package/dist/src/protocol/session-events/catalog.d.ts +50 -0
  756. package/dist/src/protocol/session-events/catalog.js +1 -0
  757. package/dist/src/protocol/session-events/checker.d.ts +23 -0
  758. package/dist/src/protocol/session-events/checker.js +1 -0
  759. package/dist/src/protocol/session-events/common.d.ts +105 -0
  760. package/dist/src/protocol/session-events/common.js +1 -0
  761. package/dist/src/protocol/session-events/envelope.d.ts +174 -0
  762. package/dist/src/protocol/session-events/envelope.js +1 -0
  763. package/dist/src/protocol/session-events/facts.d.ts +24 -0
  764. package/dist/src/protocol/session-events/facts.js +1 -0
  765. package/dist/src/protocol/session-events/families/call.d.ts +142 -0
  766. package/dist/src/protocol/session-events/families/call.js +1 -0
  767. package/dist/src/protocol/session-events/families/child.d.ts +51 -0
  768. package/dist/src/protocol/session-events/families/child.js +1 -0
  769. package/dist/src/protocol/session-events/families/content.d.ts +56 -0
  770. package/dist/src/protocol/session-events/families/content.js +1 -0
  771. package/dist/src/protocol/session-events/families/context.d.ts +55 -0
  772. package/dist/src/protocol/session-events/families/context.js +1 -0
  773. package/dist/src/protocol/session-events/families/delivery.d.ts +86 -0
  774. package/dist/src/protocol/session-events/families/delivery.js +1 -0
  775. package/dist/src/protocol/session-events/families/interaction.d.ts +163 -0
  776. package/dist/src/protocol/session-events/families/interaction.js +1 -0
  777. package/dist/src/protocol/session-events/families/model.d.ts +88 -0
  778. package/dist/src/protocol/session-events/families/model.js +1 -0
  779. package/dist/src/protocol/session-events/families/response.d.ts +66 -0
  780. package/dist/src/protocol/session-events/families/response.js +1 -0
  781. package/dist/src/protocol/session-events/families/session.d.ts +73 -0
  782. package/dist/src/protocol/session-events/families/session.js +1 -0
  783. package/dist/src/protocol/session-events/families/task.d.ts +46 -0
  784. package/dist/src/protocol/session-events/families/task.js +1 -0
  785. package/dist/src/protocol/session-events/families/turn.d.ts +68 -0
  786. package/dist/src/protocol/session-events/families/turn.js +1 -0
  787. package/dist/src/protocol/session-events/families/usage.d.ts +30 -0
  788. package/dist/src/protocol/session-events/families/usage.js +1 -0
  789. package/dist/src/protocol/session-events/guards.d.ts +11 -0
  790. package/dist/src/protocol/session-events/guards.js +1 -0
  791. package/dist/src/protocol/session-events/index.d.ts +16 -0
  792. package/dist/src/protocol/session-events/index.js +1 -0
  793. package/dist/src/protocol/session-events/json.d.ts +20 -0
  794. package/dist/src/protocol/session-events/json.js +1 -0
  795. package/dist/src/protocol/session-events/schemas.d.ts +320 -0
  796. package/dist/src/protocol/session-events/schemas.js +1 -0
  797. package/dist/src/protocol/session-http.d.ts +7 -0
  798. package/dist/src/protocol/session-http.js +1 -0
  799. package/dist/src/protocol/session-lines.d.ts +19 -0
  800. package/dist/src/protocol/session-lines.js +1 -0
  801. package/dist/src/protocol/session-projection/fold.d.ts +75 -0
  802. package/dist/src/protocol/session-projection/fold.js +1 -0
  803. package/dist/src/protocol/session-projection/index.d.ts +4 -0
  804. package/dist/src/protocol/session-projection/index.js +1 -0
  805. package/dist/src/protocol/session-projection/observations.d.ts +150 -0
  806. package/dist/src/protocol/session-projection/observations.js +1 -0
  807. package/dist/src/protocol/session-projection/public-view.d.ts +74 -0
  808. package/dist/src/protocol/session-projection/public-view.js +1 -0
  809. package/dist/src/protocol/session-projection/reader.d.ts +62 -0
  810. package/dist/src/protocol/session-projection/reader.js +1 -0
  811. package/dist/src/protocol/session-projection/request-status.d.ts +7 -0
  812. package/dist/src/protocol/session-projection/request-status.js +1 -0
  813. package/dist/src/protocol/session-projection/selectors.d.ts +169 -0
  814. package/dist/src/protocol/session-projection/selectors.js +2 -0
  815. package/dist/src/protocol/session-projection/session-view.d.ts +18 -0
  816. package/dist/src/protocol/session-projection/session-view.js +1 -0
  817. package/dist/src/protocol/session-projection/tables.d.ts +237 -0
  818. package/dist/src/protocol/session-projection/tables.js +1 -0
  819. package/dist/src/protocol/session-projection/tree.d.ts +72 -0
  820. package/dist/src/protocol/session-projection/tree.js +1 -0
  821. package/dist/src/protocol/session-projection.d.ts +38 -157
  822. package/dist/src/protocol/session-projection.js +1 -1
  823. package/dist/src/protocol/task-tools.d.ts +8 -6
  824. package/dist/src/protocol/task-tools.js +1 -1
  825. package/dist/src/protocol/v26-interactions.d.ts +11 -0
  826. package/dist/src/protocol/v26-interactions.js +1 -0
  827. package/dist/src/protocol/v26-lines.d.ts +5 -0
  828. package/dist/src/protocol/v26-lines.js +1 -0
  829. package/dist/src/public/agents/auth.d.ts +2 -2
  830. package/dist/src/public/agents/auth.js +1 -1
  831. package/dist/src/public/ai/index.d.ts +1 -0
  832. package/dist/src/public/channels/auth.d.ts +2 -518
  833. package/dist/src/public/channels/auth.js +1 -1
  834. package/dist/src/public/channels/chat-sdk/authorization.d.ts +5 -2
  835. package/dist/src/public/channels/chat-sdk/authorization.js +1 -3
  836. package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +16 -11
  837. package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +1 -3
  838. package/dist/src/public/channels/chat-sdk/index.d.ts +1 -1
  839. package/dist/src/public/channels/chat-sdk/index.js +1 -1
  840. package/dist/src/public/channels/chat-sdk/input-actions.d.ts +4 -4
  841. package/dist/src/public/channels/chat-sdk/input-actions.js +3 -3
  842. package/dist/src/public/channels/chat-sdk/{messageToUserContent.d.ts → message-content.d.ts} +3 -3
  843. package/dist/src/public/channels/chat-sdk/message-content.js +1 -0
  844. package/dist/src/public/channels/discord/api.d.ts +8 -11
  845. package/dist/src/public/channels/discord/api.js +1 -1
  846. package/dist/src/public/channels/discord/attachments.d.ts +2 -2
  847. package/dist/src/public/channels/discord/authorization.d.ts +3 -13
  848. package/dist/src/public/channels/discord/authorization.js +2 -2
  849. package/dist/src/public/channels/discord/credentials.d.ts +11 -0
  850. package/dist/src/public/channels/discord/credentials.js +1 -0
  851. package/dist/src/public/channels/discord/defaults.d.ts +7 -1
  852. package/dist/src/public/channels/discord/defaults.js +1 -3
  853. package/dist/src/public/channels/discord/discordChannel.d.ts +36 -48
  854. package/dist/src/public/channels/discord/discordChannel.js +1 -1
  855. package/dist/src/public/channels/discord/hitl.d.ts +5 -4
  856. package/dist/src/public/channels/discord/hitl.js +1 -1
  857. package/dist/src/public/channels/discord/index.d.ts +4 -12
  858. package/dist/src/public/channels/discord/index.js +1 -1
  859. package/dist/src/public/channels/discord/messages.js +1 -1
  860. package/dist/src/public/channels/github/defaults.js +2 -4
  861. package/dist/src/public/channels/github/githubChannel.d.ts +23 -36
  862. package/dist/src/public/channels/github/githubChannel.js +1 -1
  863. package/dist/src/public/channels/github/index.d.ts +3 -2
  864. package/dist/src/public/channels/github/index.js +1 -1
  865. package/dist/src/public/channels/github/state.d.ts +2 -0
  866. package/dist/src/public/channels/imessage-tapbacks.d.ts +1 -1
  867. package/dist/src/public/channels/index.d.ts +16 -37
  868. package/dist/src/public/channels/index.js +1 -1
  869. package/dist/src/public/channels/linear/defaults.js +2 -4
  870. package/dist/src/public/channels/linear/hitl.d.ts +3 -3
  871. package/dist/src/public/channels/linear/hitl.js +2 -2
  872. package/dist/src/public/channels/linear/inbound-uploads.d.ts +3 -3
  873. package/dist/src/public/channels/linear/inbound-uploads.js +1 -1
  874. package/dist/src/public/channels/linear/inbound.d.ts +5 -3
  875. package/dist/src/public/channels/linear/inbound.js +1 -1
  876. package/dist/src/public/channels/linear/index.d.ts +4 -6
  877. package/dist/src/public/channels/linear/index.js +1 -1
  878. package/dist/src/public/channels/linear/linearChannel.d.ts +19 -30
  879. package/dist/src/public/channels/linear/linearChannel.js +1 -1
  880. package/dist/src/public/channels/linq/inboundContent.d.ts +2 -2
  881. package/dist/src/public/channels/linq/inboundContent.js +1 -1
  882. package/dist/src/public/channels/linq/index.d.ts +1 -1
  883. package/dist/src/public/channels/linq/linqChannel.d.ts +1 -2
  884. package/dist/src/public/channels/mcp.d.ts +2 -2
  885. package/dist/src/public/channels/mcp.js +1 -1
  886. package/dist/src/public/channels/photon/inboundContent.d.ts +2 -2
  887. package/dist/src/public/channels/photon/inboundContent.js +1 -1
  888. package/dist/src/public/channels/photon/index.d.ts +1 -1
  889. package/dist/src/public/channels/photon/photonIMessageChannel.d.ts +1 -2
  890. package/dist/src/public/channels/reply.d.ts +22 -0
  891. package/dist/src/public/channels/reply.js +3 -0
  892. package/dist/src/public/channels/slack/action-status.js +1 -1
  893. package/dist/src/public/channels/slack/{input-response.d.ts → answers.d.ts} +5 -5
  894. package/dist/src/public/channels/slack/answers.js +1 -0
  895. package/dist/src/public/channels/slack/api.d.ts +5 -2
  896. package/dist/src/public/channels/slack/api.js +1 -1
  897. package/dist/src/public/channels/slack/approval-cards.d.ts +15 -5
  898. package/dist/src/public/channels/slack/approval-cards.js +2 -2
  899. package/dist/src/public/channels/slack/attachments.d.ts +6 -6
  900. package/dist/src/public/channels/slack/attachments.js +1 -1
  901. package/dist/src/public/channels/slack/blocks.d.ts +1 -1
  902. package/dist/src/public/channels/slack/blocks.js +1 -1
  903. package/dist/src/public/channels/slack/cards.d.ts +576 -0
  904. package/dist/src/public/channels/slack/cards.js +1 -0
  905. package/dist/src/public/channels/slack/connections.d.ts +4 -22
  906. package/dist/src/public/channels/slack/connections.js +1 -1
  907. package/dist/src/public/channels/slack/defaults.d.ts +13 -2
  908. package/dist/src/public/channels/slack/defaults.js +5 -5
  909. package/dist/src/public/channels/slack/hitl.d.ts +20 -19
  910. package/dist/src/public/channels/slack/hitl.js +3 -3
  911. package/dist/src/public/channels/slack/index.d.ts +7 -16
  912. package/dist/src/public/channels/slack/index.js +1 -1
  913. package/dist/src/public/channels/slack/interaction-cards.js +1 -1
  914. package/dist/src/public/channels/slack/interactions.d.ts +2 -2
  915. package/dist/src/public/channels/slack/interactions.js +1 -1
  916. package/dist/src/public/channels/slack/limits.js +1 -1
  917. package/dist/src/public/channels/slack/private-approval-delivery.d.ts +3 -3
  918. package/dist/src/public/channels/slack/private-approval-delivery.js +1 -1
  919. package/dist/src/public/channels/slack/renderers.d.ts +21 -27
  920. package/dist/src/public/channels/slack/renderers.js +1 -1
  921. package/dist/src/public/channels/slack/reply-delivery.d.ts +5 -11
  922. package/dist/src/public/channels/slack/reply-delivery.js +1 -1
  923. package/dist/src/public/channels/slack/session-operations.d.ts +4 -4
  924. package/dist/src/public/channels/slack/sign-in-cancel.js +1 -1
  925. package/dist/src/public/channels/slack/slackChannel.d.ts +32 -43
  926. package/dist/src/public/channels/slack/slackChannel.js +1 -1
  927. package/dist/src/public/channels/slack/task-card.d.ts +9 -9
  928. package/dist/src/public/channels/slack/task-card.js +1 -1
  929. package/dist/src/public/channels/teams/api.d.ts +3 -7
  930. package/dist/src/public/channels/teams/attachments.d.ts +4 -4
  931. package/dist/src/public/channels/teams/authorization.d.ts +5 -9
  932. package/dist/src/public/channels/teams/authorization.js +1 -1
  933. package/dist/src/public/channels/teams/credentials.d.ts +13 -0
  934. package/dist/src/public/channels/teams/credentials.js +1 -0
  935. package/dist/src/public/channels/teams/defaults.d.ts +2 -6
  936. package/dist/src/public/channels/teams/defaults.js +1 -3
  937. package/dist/src/public/channels/teams/hitl.d.ts +8 -7
  938. package/dist/src/public/channels/teams/hitl.js +1 -1
  939. package/dist/src/public/channels/teams/index.d.ts +6 -8
  940. package/dist/src/public/channels/teams/index.js +1 -1
  941. package/dist/src/public/channels/teams/teamsChannel.d.ts +25 -44
  942. package/dist/src/public/channels/teams/teamsChannel.js +1 -1
  943. package/dist/src/public/channels/telegram/api.d.ts +3 -4
  944. package/dist/src/public/channels/telegram/attachments.d.ts +5 -5
  945. package/dist/src/public/channels/telegram/authorization-callback.js +1 -1
  946. package/dist/src/public/channels/telegram/authorization.d.ts +4 -8
  947. package/dist/src/public/channels/telegram/authorization.js +2 -2
  948. package/dist/src/public/channels/telegram/credentials.d.ts +9 -0
  949. package/dist/src/public/channels/telegram/credentials.js +1 -0
  950. package/dist/src/public/channels/telegram/defaults.js +1 -3
  951. package/dist/src/public/channels/telegram/hitl.d.ts +22 -20
  952. package/dist/src/public/channels/telegram/hitl.js +2 -2
  953. package/dist/src/public/channels/telegram/index.d.ts +5 -7
  954. package/dist/src/public/channels/telegram/index.js +1 -1
  955. package/dist/src/public/channels/telegram/telegramChannel.d.ts +23 -36
  956. package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
  957. package/dist/src/public/channels/text.d.ts +4 -0
  958. package/dist/src/public/channels/text.js +1 -0
  959. package/dist/src/public/channels/twilio/api.d.ts +8 -8
  960. package/dist/src/public/channels/twilio/api.js +1 -1
  961. package/dist/src/public/channels/twilio/credentials.d.ts +7 -0
  962. package/dist/src/public/channels/twilio/credentials.js +1 -0
  963. package/dist/src/public/channels/twilio/defaults.d.ts +0 -1
  964. package/dist/src/public/channels/twilio/defaults.js +1 -5
  965. package/dist/src/public/channels/twilio/inbound.d.ts +2 -2
  966. package/dist/src/public/channels/twilio/index.d.ts +4 -4
  967. package/dist/src/public/channels/twilio/index.js +1 -1
  968. package/dist/src/public/channels/twilio/twilioChannel.d.ts +24 -37
  969. package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
  970. package/dist/src/public/channels/twilio/verify.d.ts +6 -4
  971. package/dist/src/public/channels/undelivered-reply.d.ts +30 -0
  972. package/dist/src/public/channels/undelivered-reply.js +1 -0
  973. package/dist/src/public/channels/upload-policy.d.ts +7 -7
  974. package/dist/src/public/connections/index.d.ts +3 -5
  975. package/dist/src/public/context/index.d.ts +3 -2
  976. package/dist/src/public/definitions/agent.d.ts +18 -18
  977. package/dist/src/public/definitions/agent.js +1 -1
  978. package/dist/src/public/definitions/approval.d.ts +1 -1
  979. package/dist/src/public/definitions/channel.d.ts +57 -60
  980. package/dist/src/public/definitions/channel.js +1 -1
  981. package/dist/src/public/definitions/connections/dynamic.d.ts +3 -15
  982. package/dist/src/public/definitions/connections/dynamic.js +1 -1
  983. package/dist/src/public/definitions/connections/events.d.ts +9 -9
  984. package/dist/src/public/definitions/connections/mcp.d.ts +5 -3
  985. package/dist/src/public/definitions/connections/openapi.d.ts +1 -1
  986. package/dist/src/public/definitions/extension.d.ts +2 -4
  987. package/dist/src/public/definitions/extension.js +1 -1
  988. package/dist/src/public/definitions/hook.d.ts +63 -85
  989. package/dist/src/public/definitions/hook.js +1 -1
  990. package/dist/src/public/definitions/instructions.d.ts +3 -10
  991. package/dist/src/public/definitions/instructions.js +1 -1
  992. package/dist/src/public/definitions/model.d.ts +21 -0
  993. package/dist/src/public/definitions/model.js +1 -0
  994. package/dist/src/public/definitions/removed-event-keys.d.ts +2 -0
  995. package/dist/src/public/definitions/removed-event-keys.js +1 -0
  996. package/dist/src/public/definitions/sandbox.d.ts +1 -1
  997. package/dist/src/public/definitions/schedule.d.ts +4 -4
  998. package/dist/src/public/definitions/skill.d.ts +5 -0
  999. package/dist/src/public/definitions/skill.js +1 -1
  1000. package/dist/src/public/events/index.d.ts +27 -0
  1001. package/dist/src/public/events/index.js +1 -0
  1002. package/dist/src/public/experimental/connections/index.d.ts +1 -0
  1003. package/dist/src/public/experimental/connections/index.js +1 -0
  1004. package/dist/src/public/experimental/schedules/client.js +1 -1
  1005. package/dist/src/public/hooks/index.d.ts +4 -3
  1006. package/dist/src/public/index.d.ts +3 -2
  1007. package/dist/src/public/instructions/index.d.ts +2 -2
  1008. package/dist/src/public/instrumentation/index.d.ts +9 -28
  1009. package/dist/src/public/instrumentation/index.js +1 -1
  1010. package/dist/src/public/instrumentation/otel.d.ts +1 -1
  1011. package/dist/src/public/instrumentation/otel.js +1 -1
  1012. package/dist/src/public/instrumentation/provider.d.ts +1 -1
  1013. package/dist/src/public/instrumentation/provider.js +1 -1
  1014. package/dist/src/public/local-dev.d.ts +3 -1
  1015. package/dist/src/public/memory/file/backend.d.ts +1 -1
  1016. package/dist/src/public/memory/file/backends/in-memory.js +1 -1
  1017. package/dist/src/public/memory/file/backends/vercel-blob.js +1 -1
  1018. package/dist/src/public/memory/file/provider.js +1 -1
  1019. package/dist/src/public/memory/index.d.ts +14 -20
  1020. package/dist/src/public/models/index.d.ts +3 -0
  1021. package/dist/src/public/models/index.js +1 -1
  1022. package/dist/src/public/models/openai/index.d.ts +0 -2
  1023. package/dist/src/public/models/openai/index.js +1 -1
  1024. package/dist/src/public/next/index.d.ts +5 -36
  1025. package/dist/src/public/next/index.js +1 -1
  1026. package/dist/src/public/nuxt/index.d.ts +1 -1
  1027. package/dist/src/public/nuxt/module.d.ts +5 -2
  1028. package/dist/src/public/sandbox/index.d.ts +1 -1
  1029. package/dist/src/public/sandbox/vercel-sandbox.d.ts +52 -12
  1030. package/dist/src/public/sandbox/vercel.d.ts +1 -1
  1031. package/dist/src/public/schedules/subscription.d.ts +5 -8
  1032. package/dist/src/public/server/index.d.ts +2 -14
  1033. package/dist/src/public/server/index.js +1 -1
  1034. package/dist/src/public/sessions/index.d.ts +6 -0
  1035. package/dist/src/public/sessions/index.js +1 -0
  1036. package/dist/src/public/skills/index.d.ts +2 -2
  1037. package/dist/src/public/skills/index.js +1 -1
  1038. package/dist/src/public/sveltekit/routing.d.ts +0 -4
  1039. package/dist/src/public/sveltekit/routing.js +1 -1
  1040. package/dist/src/public/tools/approval/index.d.ts +1 -1
  1041. package/dist/src/public/tools/bash.d.ts +1 -1
  1042. package/dist/src/public/tools/bash.js +1 -1
  1043. package/dist/src/public/tools/glob.d.ts +1 -1
  1044. package/dist/src/public/tools/glob.js +1 -1
  1045. package/dist/src/public/tools/grep.d.ts +1 -1
  1046. package/dist/src/public/tools/grep.js +1 -1
  1047. package/dist/src/public/tools/index.d.ts +5 -9
  1048. package/dist/src/public/tools/index.js +1 -1
  1049. package/dist/src/public/tools/read-file.d.ts +1 -1
  1050. package/dist/src/public/tools/read-file.js +1 -1
  1051. package/dist/src/public/tools/result.d.ts +17 -9
  1052. package/dist/src/public/tools/result.js +1 -1
  1053. package/dist/src/public/tools/web-fetch.d.ts +1 -1
  1054. package/dist/src/public/tools/web-fetch.js +1 -1
  1055. package/dist/src/public/tools/web-search.d.ts +1 -3
  1056. package/dist/src/public/tools/web-search.js +1 -1
  1057. package/dist/src/public/tools/write-file.d.ts +1 -1
  1058. package/dist/src/public/tools/write-file.js +1 -1
  1059. package/dist/src/public/workflow-modules.d.ts +8 -2
  1060. package/dist/src/react/index.d.ts +4 -7
  1061. package/dist/src/react/index.js +1 -1
  1062. package/dist/src/react/use-eve-agent.d.ts +68 -50
  1063. package/dist/src/react/use-eve-agent.js +1 -1
  1064. package/dist/src/reactions/bundle.d.ts +4 -0
  1065. package/dist/src/reactions/bundle.js +1 -0
  1066. package/dist/src/reactions/frame.d.ts +13 -0
  1067. package/dist/src/reactions/frame.js +1 -0
  1068. package/dist/src/reactions/intents.d.ts +22 -0
  1069. package/dist/src/reactions/intents.js +1 -0
  1070. package/dist/src/reactions/kinds/connection.d.ts +18 -0
  1071. package/dist/src/reactions/kinds/connection.js +1 -0
  1072. package/dist/src/reactions/kinds/hook.d.ts +8 -0
  1073. package/dist/src/reactions/kinds/hook.js +1 -0
  1074. package/dist/src/reactions/kinds/instructions.d.ts +21 -0
  1075. package/dist/src/reactions/kinds/instructions.js +1 -0
  1076. package/dist/src/reactions/kinds/memory.d.ts +72 -0
  1077. package/dist/src/reactions/kinds/memory.js +1 -0
  1078. package/dist/src/reactions/kinds/model.d.ts +21 -0
  1079. package/dist/src/reactions/kinds/model.js +1 -0
  1080. package/dist/src/reactions/kinds/skill.d.ts +27 -0
  1081. package/dist/src/reactions/kinds/skill.js +1 -0
  1082. package/dist/src/reactions/kinds/subagent.d.ts +16 -0
  1083. package/dist/src/reactions/kinds/subagent.js +1 -0
  1084. package/dist/src/reactions/kinds/tool.d.ts +16 -0
  1085. package/dist/src/reactions/kinds/tool.js +1 -0
  1086. package/dist/src/reactions/policy.d.ts +13 -0
  1087. package/dist/src/reactions/policy.js +1 -0
  1088. package/dist/src/reactions/reaction.d.ts +83 -0
  1089. package/dist/src/reactions/reaction.js +1 -0
  1090. package/dist/src/reactions/records.d.ts +40 -0
  1091. package/dist/src/reactions/records.js +1 -0
  1092. package/dist/src/reactions/remote.d.ts +25 -0
  1093. package/dist/src/reactions/remote.js +1 -0
  1094. package/dist/src/reactions/runner.d.ts +45 -0
  1095. package/dist/src/reactions/runner.js +1 -0
  1096. package/dist/src/reactions/state.d.ts +102 -0
  1097. package/dist/src/reactions/state.js +1 -0
  1098. package/dist/src/reactions/turn.d.ts +12 -0
  1099. package/dist/src/reactions/turn.js +2 -0
  1100. package/dist/src/runtime/agent/bootstrap.d.ts +1 -3
  1101. package/dist/src/runtime/agent/mock-model-adapter.js +1 -1
  1102. package/dist/src/runtime/agent/resolve-model.js +1 -1
  1103. package/dist/src/runtime/connections/mcp-client.d.ts +5 -2
  1104. package/dist/src/runtime/connections/mcp-client.js +1 -1
  1105. package/dist/src/runtime/connections/openapi-client.js +1 -1
  1106. package/dist/src/runtime/connections/openapi-operations.d.ts +4 -0
  1107. package/dist/src/runtime/connections/openapi-operations.js +1 -1
  1108. package/dist/src/runtime/connections/openapi-schema.d.ts +19 -14
  1109. package/dist/src/runtime/connections/openapi-schema.js +1 -1
  1110. package/dist/src/runtime/connections/principal.d.ts +2 -0
  1111. package/dist/src/runtime/connections/principal.js +1 -1
  1112. package/dist/src/runtime/connections/registry.d.ts +2 -2
  1113. package/dist/src/runtime/connections/registry.js +1 -1
  1114. package/dist/src/runtime/connections/scoped-authorization.d.ts +8 -1
  1115. package/dist/src/runtime/connections/scoped-authorization.js +1 -1
  1116. package/dist/src/runtime/graph.d.ts +0 -6
  1117. package/dist/src/runtime/local-dev-capability.d.ts +4 -5
  1118. package/dist/src/runtime/local-dev-capability.js +1 -1
  1119. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  1120. package/dist/src/runtime/resolve-agent.js +1 -1
  1121. package/dist/src/runtime/resolve-connection.js +1 -1
  1122. package/dist/src/runtime/resolve-dynamic.d.ts +9 -0
  1123. package/dist/src/runtime/resolve-dynamic.js +1 -0
  1124. package/dist/src/runtime/resolve-hook.js +1 -1
  1125. package/dist/src/runtime/resolve-memory.js +1 -1
  1126. package/dist/src/runtime/resolve-tool.js +1 -1
  1127. package/dist/src/runtime/schedules/collection-client.js +1 -1
  1128. package/dist/src/runtime/schedules/dispatch-occurrence.js +1 -1
  1129. package/dist/src/runtime/sessions/compiled-agent-cache.d.ts +0 -2
  1130. package/dist/src/runtime/sessions/compiled-agent-cache.js +1 -1
  1131. package/dist/src/runtime/subagents/dynamic-agent-config.js +1 -1
  1132. package/dist/src/runtime/subagents/dynamic-remote-agent-config.d.ts +16 -3
  1133. package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
  1134. package/dist/src/runtime/subagents/workflow.js +1 -1
  1135. package/dist/src/runtime/types.d.ts +22 -39
  1136. package/dist/src/sandbox/provider.d.ts +3 -3
  1137. package/dist/src/sandbox/providers/default.d.ts +4 -2
  1138. package/dist/src/sandbox/providers/default.js +1 -1
  1139. package/dist/src/self-modification/agent.d.ts +3 -3
  1140. package/dist/src/self-modification/agent.js +1 -1
  1141. package/dist/src/self-modification/config.d.ts +1 -1
  1142. package/dist/src/self-modification/config.js +1 -1
  1143. package/dist/src/self-modification/deployed-sandbox.js +1 -1
  1144. package/dist/src/self-modification/extension/extension.d.ts +1 -0
  1145. package/dist/src/self-modification/extension/local-only.d.ts +1 -1
  1146. package/dist/src/self-modification/extension/local-only.js +1 -1
  1147. package/dist/src/self-modification/extension/subagents/agent/agent.d.ts +15 -4
  1148. package/dist/src/self-modification/extension/subagents/agent/agent.js +1 -1
  1149. package/dist/src/self-modification/extension/subagents/agent/instructions.d.ts +1 -1
  1150. package/dist/src/self-modification/extension/subagents/agent/instructions.js +2 -2
  1151. package/dist/src/self-modification/extension/subagents/agent/sandbox.d.ts +2 -2
  1152. package/dist/src/self-modification/extension/subagents/agent/sandbox.js +1 -1
  1153. package/dist/src/self-modification/extension/subagents/agent/skills/trace_analysis.d.ts +3 -3
  1154. package/dist/src/self-modification/extension/subagents/agent/skills/trace_analysis.js +1 -1
  1155. package/dist/src/self-modification/extension/subagents/agent/tools/inspect_trace.d.ts +1 -1
  1156. package/dist/src/self-modification/extension/subagents/agent/tools/inspect_trace_spans.d.ts +1 -1
  1157. package/dist/src/self-modification/extension/subagents/agent/tools/registry_add.d.ts +1 -1
  1158. package/dist/src/self-modification/extension/subagents/agent/tools/search_traces.d.ts +1 -1
  1159. package/dist/src/self-modification/mode.d.ts +8 -0
  1160. package/dist/src/self-modification/mode.js +1 -1
  1161. package/dist/src/self-modification/remote/config.d.ts +3 -6
  1162. package/dist/src/self-modification/remote/extension.d.ts +1 -0
  1163. package/dist/src/self-modification/remote/production-registry-add.js +1 -1
  1164. package/dist/src/self-modification/remote/subagents/agent/agent.d.ts +6 -3
  1165. package/dist/src/self-modification/remote/subagents/agent/agent.js +1 -1
  1166. package/dist/src/self-modification/remote/subagents/agent/instructions.d.ts +1 -1
  1167. package/dist/src/self-modification/remote/subagents/agent/instructions.js +2 -2
  1168. package/dist/src/self-modification/remote/subagents/agent/tools/publish.d.ts +1 -3
  1169. package/dist/src/self-modification/remote/subagents/agent/tools/publish.js +1 -1
  1170. package/dist/src/self-modification/remote/subagents/agent/tools/registry_add.d.ts +1 -3
  1171. package/dist/src/self-modification/remote/subagents/agent/tools/registry_add.js +1 -1
  1172. package/dist/src/self-modification/scaffold.js +1 -1
  1173. package/dist/src/self-modification/setup.js +3 -6
  1174. package/dist/src/services/dev-client/client-options.js +1 -1
  1175. package/dist/src/services/dev-client.d.ts +4 -4
  1176. package/dist/src/services/dev-client.js +1 -1
  1177. package/dist/src/setup/integrations/self-modification/setup.d.ts +1 -4
  1178. package/dist/src/setup/integrations/self-modification/setup.js +1 -1
  1179. package/dist/src/setup/scaffold/create/project.js +1 -1
  1180. package/dist/src/setup/scaffold/create/web-template.d.ts +9 -18
  1181. package/dist/src/setup/scaffold/create/web-template.js +1015 -2537
  1182. package/dist/src/setup/verified-remote-agent.js +1 -1
  1183. package/dist/src/shared/action-label.d.ts +5 -3
  1184. package/dist/src/shared/action-label.js +1 -1
  1185. package/dist/src/shared/action-types.d.ts +5 -0
  1186. package/dist/src/shared/action-types.js +1 -1
  1187. package/dist/src/shared/agent-definition.d.ts +14 -9
  1188. package/dist/src/shared/answers-delivery-id.d.ts +1 -0
  1189. package/dist/src/shared/answers-delivery-id.js +1 -0
  1190. package/dist/src/shared/channel-context.d.ts +12 -0
  1191. package/dist/src/shared/channel-context.js +1 -0
  1192. package/dist/src/shared/channel-definition.d.ts +19 -26
  1193. package/dist/src/shared/channel-delivery.d.ts +16 -0
  1194. package/dist/src/shared/channel-delivery.js +1 -0
  1195. package/dist/src/shared/connection-events.d.ts +2 -2
  1196. package/dist/src/shared/connection-types.d.ts +12 -32
  1197. package/dist/src/shared/conversation-context.d.ts +4 -13
  1198. package/dist/src/shared/delivery.d.ts +38 -0
  1199. package/dist/src/shared/delivery.js +1 -0
  1200. package/dist/src/shared/history-message.d.ts +190 -0
  1201. package/dist/src/shared/history-message.js +1 -0
  1202. package/dist/src/shared/input.d.ts +23 -97
  1203. package/dist/src/shared/input.js +1 -1
  1204. package/dist/src/shared/instructions-definition.d.ts +2 -8
  1205. package/dist/src/shared/instrumentation-channel-kind.d.ts +1 -1
  1206. package/dist/src/shared/instrumentation-channel.d.ts +12 -0
  1207. package/dist/src/shared/instrumentation-channel.js +1 -0
  1208. package/dist/src/shared/json.d.ts +2 -18
  1209. package/dist/src/shared/memory-state.d.ts +4 -40
  1210. package/dist/src/shared/memory-state.js +1 -1
  1211. package/dist/src/shared/message-content.d.ts +19 -0
  1212. package/dist/src/shared/message-content.js +1 -0
  1213. package/dist/src/shared/network-address.d.ts +9 -0
  1214. package/dist/src/shared/network-address.js +1 -1
  1215. package/dist/src/shared/sandbox-environment.d.ts +2 -2
  1216. package/dist/src/shared/sandbox-provider.d.ts +1 -1
  1217. package/dist/src/shared/sandbox-session.d.ts +60 -85
  1218. package/dist/src/shared/schedule-definition.d.ts +5 -5
  1219. package/dist/src/shared/serialized-observability-state.d.ts +0 -2
  1220. package/dist/src/shared/serialized-observability-state.js +1 -1
  1221. package/dist/src/shared/session-history.d.ts +2 -2
  1222. package/dist/src/shared/session.d.ts +22 -0
  1223. package/dist/src/shared/session.js +1 -0
  1224. package/dist/src/shared/skill-definition.d.ts +1 -1
  1225. package/dist/src/shared/skill-package.d.ts +2 -2
  1226. package/dist/src/shared/skill-package.js +1 -1
  1227. package/dist/src/shared/token-usage-math.d.ts +5 -0
  1228. package/dist/src/shared/token-usage-math.js +1 -0
  1229. package/dist/src/shared/token-usage.d.ts +0 -2
  1230. package/dist/src/shared/token-usage.js +1 -1
  1231. package/dist/src/shared/validate-authorization.js +1 -1
  1232. package/dist/src/shared/wait-with-signal.d.ts +2 -0
  1233. package/dist/src/shared/wait-with-signal.js +1 -0
  1234. package/dist/src/subagents/adapter.d.ts +3 -5
  1235. package/dist/src/subagents/adapter.js +1 -1
  1236. package/dist/src/subagents/callback-route.js +1 -1
  1237. package/dist/src/subagents/event-proxy-step.d.ts +6 -9
  1238. package/dist/src/subagents/event-proxy-step.js +1 -1
  1239. package/dist/src/subagents/hitl-proxy.d.ts +11 -23
  1240. package/dist/src/subagents/hitl-proxy.js +1 -1
  1241. package/dist/src/subagents/invocation.d.ts +8 -8
  1242. package/dist/src/subagents/invocation.js +2 -2
  1243. package/dist/src/subagents/parent-notification.d.ts +5 -0
  1244. package/dist/src/subagents/parent-notification.js +1 -1
  1245. package/dist/src/subagents/protocol-two-callback.d.ts +27 -0
  1246. package/dist/src/subagents/protocol-two-callback.js +1 -0
  1247. package/dist/src/svelte/index.d.ts +3 -6
  1248. package/dist/src/svelte/index.js +2 -39
  1249. package/dist/src/svelte/use-eve-agent.d.ts +67 -56
  1250. package/dist/src/svelte/use-eve-agent.js +1 -1
  1251. package/dist/src/tool-stubs/rules.js +1 -1
  1252. package/dist/src/tools/approval/policies.d.ts +4 -16
  1253. package/dist/src/tools/approval/policies.js +1 -1
  1254. package/dist/src/tools/auth.d.ts +3 -3
  1255. package/dist/src/tools/definition.d.ts +13 -35
  1256. package/dist/src/tools/definition.js +1 -1
  1257. package/dist/src/tools/dynamic.d.ts +13 -72
  1258. package/dist/src/tools/dynamic.js +1 -1
  1259. package/dist/src/tools/framework/agent.js +1 -1
  1260. package/dist/src/tools/provided/ask-question-workflow.d.ts +3 -3
  1261. package/dist/src/tools/provided/ask-question-workflow.js +1 -1
  1262. package/dist/src/tools/provided/ask-question.d.ts +2 -2
  1263. package/dist/src/tools/provided/ask-question.js +1 -1
  1264. package/dist/src/tools/provided/grep.d.ts +2 -15
  1265. package/dist/src/tools/provided/grep.js +1 -2
  1266. package/dist/src/tools/provided/no-reply.d.ts +2 -2
  1267. package/dist/src/tools/provided/no-reply.js +1 -1
  1268. package/dist/src/tools/provided/sleep-workflow.js +1 -1
  1269. package/dist/src/tools/provided/sleep.d.ts +2 -2
  1270. package/dist/src/tools/provided/sleep.js +1 -1
  1271. package/dist/src/tools/provided/workflow.js +1 -1
  1272. package/dist/src/tools/schema.d.ts +2 -0
  1273. package/dist/src/tools/schema.js +1 -1
  1274. package/dist/src/tools/signature.js +1 -1
  1275. package/dist/src/tools/workflow-definition.d.ts +17 -15
  1276. package/dist/src/tracing/eve/agent-approval-instrumentation.d.ts +1 -1
  1277. package/dist/src/tracing/eve/agent-approval-instrumentation.js +1 -1
  1278. package/dist/src/tracing/eve/agent-channel-delivery-instrumentation.d.ts +2 -2
  1279. package/dist/src/tracing/eve/agent-channel-delivery-instrumentation.js +1 -1
  1280. package/dist/src/tracing/eve/agent-invocation-coordinator.d.ts +2 -2
  1281. package/dist/src/tracing/eve/agent-otel-provider.js +1 -1
  1282. package/dist/src/tracing/eve/agent-tool-instrumentation.d.ts +6 -7
  1283. package/dist/src/tracing/eve/agent-tool-instrumentation.js +1 -1
  1284. package/dist/src/tracing/eve/agent-trace-context-store.d.ts +3 -3
  1285. package/dist/src/tracing/eve/agent-trace-state.d.ts +1 -6
  1286. package/dist/src/tracing/eve/delegation.d.ts +4 -4
  1287. package/dist/src/tracing/eve/install-instrumentation-runtime.js +1 -1
  1288. package/dist/src/tracing/eve/invoke-tool-span.d.ts +3 -2
  1289. package/dist/src/tracing/eve/invoke-tool-span.js +1 -1
  1290. package/dist/src/tracing/eve/otel-declaration.d.ts +9 -10
  1291. package/dist/src/tracing/eve/otel-declaration.js +1 -1
  1292. package/dist/src/tracing/eve/policy.d.ts +2 -2
  1293. package/dist/src/tracing/eve/policy.js +1 -1
  1294. package/dist/src/tracing/eve/session.d.ts +4 -3
  1295. package/dist/src/tracing/eve/session.js +1 -1
  1296. package/dist/src/vue/index.d.ts +3 -6
  1297. package/dist/src/vue/index.js +2 -39
  1298. package/dist/src/vue/use-eve-agent.d.ts +70 -59
  1299. package/dist/src/vue/use-eve-agent.js +1 -1
  1300. package/docs/agent-config.md +40 -44
  1301. package/docs/channels/chat-sdk.mdx +19 -13
  1302. package/docs/channels/custom.mdx +106 -85
  1303. package/docs/channels/discord.mdx +12 -12
  1304. package/docs/channels/eve.mdx +48 -15
  1305. package/docs/channels/github.mdx +2 -2
  1306. package/docs/channels/linear.mdx +8 -8
  1307. package/docs/channels/linq.mdx +1 -1
  1308. package/docs/channels/mcp.mdx +2 -2
  1309. package/docs/channels/overview.mdx +11 -1
  1310. package/docs/channels/photon.mdx +1 -1
  1311. package/docs/channels/slack.mdx +65 -58
  1312. package/docs/channels/teams.mdx +4 -4
  1313. package/docs/channels/telegram.mdx +1 -1
  1314. package/docs/channels/twilio.mdx +2 -2
  1315. package/docs/code-extension.mdx +19 -7
  1316. package/docs/concepts/built-in-tools.md +21 -9
  1317. package/docs/concepts/context-control.md +5 -8
  1318. package/docs/concepts/default-harness.md +8 -9
  1319. package/docs/concepts/execution-model-and-durability.mdx +119 -12
  1320. package/docs/concepts/meta.json +1 -0
  1321. package/docs/concepts/sessions-runs-and-streaming.md +244 -138
  1322. package/docs/concepts/state.md +1 -1
  1323. package/docs/concepts/upgrade-to-v27-events.md +128 -0
  1324. package/docs/connections/mcp.mdx +38 -34
  1325. package/docs/connections/openapi.mdx +24 -3
  1326. package/docs/connections/overview.mdx +66 -57
  1327. package/docs/evals/assertions.mdx +30 -24
  1328. package/docs/evals/cases.mdx +19 -24
  1329. package/docs/evals/judge.mdx +2 -2
  1330. package/docs/evals/overview.mdx +7 -7
  1331. package/docs/evals/reporters.mdx +15 -11
  1332. package/docs/evals/targets.mdx +5 -3
  1333. package/docs/evals/tool-stubs.mdx +2 -2
  1334. package/docs/extensions.md +6 -3
  1335. package/docs/guides/auth-and-route-protection.md +4 -0
  1336. package/docs/guides/client/continuations.mdx +10 -10
  1337. package/docs/guides/client/messages.mdx +50 -48
  1338. package/docs/guides/client/output-schema.mdx +13 -13
  1339. package/docs/guides/client/overview.mdx +12 -12
  1340. package/docs/guides/client/streaming.mdx +160 -123
  1341. package/docs/guides/decide.md +15 -9
  1342. package/docs/guides/deployment/self-hosting.md +5 -40
  1343. package/docs/guides/dynamic-capabilities.md +151 -406
  1344. package/docs/guides/frontend/nextjs.mdx +1 -1
  1345. package/docs/guides/frontend/nuxt.mdx +2 -2
  1346. package/docs/guides/frontend/overview.mdx +257 -181
  1347. package/docs/guides/frontend/sveltekit.mdx +4 -4
  1348. package/docs/guides/frontend/tanstack.mdx +5 -5
  1349. package/docs/guides/frontend/use-eve-agent-svelte.mdx +30 -38
  1350. package/docs/guides/frontend/use-eve-agent-vue.mdx +35 -36
  1351. package/docs/guides/hooks.md +67 -55
  1352. package/docs/guides/instrumentation/instrumentation.mdx +33 -27
  1353. package/docs/guides/instrumentation/otel.mdx +4 -2
  1354. package/docs/guides/remote-agents.md +116 -50
  1355. package/docs/guides/self-modification.md +11 -7
  1356. package/docs/instructions.mdx +4 -6
  1357. package/docs/memory/custom-provider.md +63 -56
  1358. package/docs/memory/file.md +1 -1
  1359. package/docs/memory/overview.mdx +10 -18
  1360. package/docs/patterns/durable-cross-channel-notifications.md +4 -3
  1361. package/docs/patterns/multi-tenant-approvals.md +3 -3
  1362. package/docs/patterns/multi-tenant-auth.md +3 -3
  1363. package/docs/patterns/multi-tenant-memory.md +6 -7
  1364. package/docs/patterns/voice-notes.md +1 -1
  1365. package/docs/reference/cli.md +11 -25
  1366. package/docs/reference/typescript-api.md +88 -61
  1367. package/docs/sandbox/custom-providers.mdx +13 -14
  1368. package/docs/sandbox/default.mdx +1 -1
  1369. package/docs/sandbox/docker.mdx +10 -0
  1370. package/docs/sandbox/index.mdx +4 -0
  1371. package/docs/sandbox/vercel.mdx +6 -6
  1372. package/docs/schedules.mdx +4 -4
  1373. package/docs/skills.mdx +6 -6
  1374. package/docs/subagents/index.mdx +25 -34
  1375. package/docs/tools/human-in-the-loop.md +42 -34
  1376. package/docs/tools/overview.mdx +14 -12
  1377. package/docs/tools/tasks-upgrade.md +13 -1
  1378. package/docs/tools/tasks.md +58 -89
  1379. package/docs/tools/workflows.mdx +44 -33
  1380. package/docs/tutorial/guard-the-spend.mdx +1 -1
  1381. package/docs/tutorial/run-analysis.mdx +15 -12
  1382. package/docs/tutorial/team-playbooks.mdx +19 -23
  1383. package/package.json +148 -93
  1384. package/dist/src/chunks/use-eve-agent-DnbG9c7c.js +0 -4921
  1385. package/dist/src/chunks/use-eve-agent-ZY7NQ2VW.js +0 -4963
  1386. package/dist/src/cli/invoke/command.d.ts +0 -19
  1387. package/dist/src/cli/invoke/command.js +0 -1
  1388. package/dist/src/cli/invoke/invoke.d.ts +0 -27
  1389. package/dist/src/cli/invoke/invoke.js +0 -1
  1390. package/dist/src/cli/invoke/result.d.ts +0 -137
  1391. package/dist/src/cli/invoke/result.js +0 -1
  1392. package/dist/src/client/agent-host.d.ts +0 -4
  1393. package/dist/src/client/agent-host.js +0 -1
  1394. package/dist/src/client/authorization-message-parts.d.ts +0 -4
  1395. package/dist/src/client/authorization-message-parts.js +0 -1
  1396. package/dist/src/client/conversation-projection.d.ts +0 -4
  1397. package/dist/src/client/conversation-projection.js +0 -1
  1398. package/dist/src/client/conversation-reducer.d.ts +0 -29
  1399. package/dist/src/client/conversation-reducer.js +0 -1
  1400. package/dist/src/client/eve-agent-projection.d.ts +0 -28
  1401. package/dist/src/client/eve-agent-projection.js +0 -1
  1402. package/dist/src/client/eve-agent-store-helpers.d.ts +0 -34
  1403. package/dist/src/client/eve-agent-store-helpers.js +0 -2
  1404. package/dist/src/client/eve-agent-store-state.d.ts +0 -96
  1405. package/dist/src/client/eve-agent-store.d.ts +0 -45
  1406. package/dist/src/client/eve-agent-store.js +0 -1
  1407. package/dist/src/client/message-action-parts.d.ts +0 -37
  1408. package/dist/src/client/message-action-parts.js +0 -1
  1409. package/dist/src/client/message-reducer-primitives.d.ts +0 -6
  1410. package/dist/src/client/message-reducer-primitives.js +0 -1
  1411. package/dist/src/client/message-reducer-types.d.ts +0 -244
  1412. package/dist/src/client/message-reducer.d.ts +0 -14
  1413. package/dist/src/client/message-reducer.js +0 -1
  1414. package/dist/src/client/message-response.d.ts +0 -74
  1415. package/dist/src/client/message-response.js +0 -1
  1416. package/dist/src/client/message-run-parts.d.ts +0 -22
  1417. package/dist/src/client/message-run-parts.js +0 -1
  1418. package/dist/src/client/output-schema.d.ts +0 -5
  1419. package/dist/src/client/output-schema.js +0 -1
  1420. package/dist/src/client/reducer.d.ts +0 -67
  1421. package/dist/src/client/session-turn-dispatch.d.ts +0 -15
  1422. package/dist/src/client/session-turn-dispatch.js +0 -1
  1423. package/dist/src/client/tool-call-state.d.ts +0 -23
  1424. package/dist/src/client/tool-call-state.js +0 -1
  1425. package/dist/src/client/tool-part-state.d.ts +0 -7
  1426. package/dist/src/client/tool-part-state.js +0 -1
  1427. package/dist/src/client/transcript-reducer.d.ts +0 -49
  1428. package/dist/src/client/transcript-reducer.js +0 -2
  1429. package/dist/src/context/build-dynamic-tools.d.ts +0 -10
  1430. package/dist/src/context/build-dynamic-tools.js +0 -1
  1431. package/dist/src/context/dynamic-connection-lifecycle.d.ts +0 -15
  1432. package/dist/src/context/dynamic-connection-lifecycle.js +0 -1
  1433. package/dist/src/context/dynamic-instruction-lifecycle.d.ts +0 -31
  1434. package/dist/src/context/dynamic-instruction-lifecycle.js +0 -1
  1435. package/dist/src/context/dynamic-model-lifecycle.d.ts +0 -19
  1436. package/dist/src/context/dynamic-model-lifecycle.js +0 -1
  1437. package/dist/src/context/dynamic-resolve-context.d.ts +0 -12
  1438. package/dist/src/context/dynamic-resolve-context.js +0 -1
  1439. package/dist/src/context/dynamic-skill-lifecycle.d.ts +0 -15
  1440. package/dist/src/context/dynamic-skill-lifecycle.js +0 -1
  1441. package/dist/src/context/dynamic-subagent-lifecycle.d.ts +0 -27
  1442. package/dist/src/context/dynamic-subagent-lifecycle.js +0 -1
  1443. package/dist/src/context/dynamic-tool-lifecycle.d.ts +0 -46
  1444. package/dist/src/context/dynamic-tool-lifecycle.js +0 -1
  1445. package/dist/src/context/dynamic-tool-metadata.d.ts +0 -47
  1446. package/dist/src/context/dynamic-tool-metadata.js +0 -1
  1447. package/dist/src/context/effective-model.d.ts +0 -5
  1448. package/dist/src/context/effective-model.js +0 -1
  1449. package/dist/src/context/hook-lifecycle.d.ts +0 -15
  1450. package/dist/src/context/hook-lifecycle.js +0 -1
  1451. package/dist/src/context/memory-event-lifecycle.d.ts +0 -15
  1452. package/dist/src/context/memory-event-lifecycle.js +0 -1
  1453. package/dist/src/context/memory-lifecycle.d.ts +0 -47
  1454. package/dist/src/context/memory-lifecycle.js +0 -1
  1455. package/dist/src/context/serialized-dynamic-model-selection.d.ts +0 -2
  1456. package/dist/src/context/serialized-dynamic-model-selection.js +0 -1
  1457. package/dist/src/execution/cancel-descendant-turns-step.d.ts +0 -6
  1458. package/dist/src/execution/cancel-descendant-turns-step.js +0 -1
  1459. package/dist/src/execution/dynamic-connection-recovery.d.ts +0 -14
  1460. package/dist/src/execution/dynamic-connection-recovery.js +0 -1
  1461. package/dist/src/execution/dynamic-connections.d.ts +0 -12
  1462. package/dist/src/execution/dynamic-connections.js +0 -1
  1463. package/dist/src/execution/history-view.d.ts +0 -10
  1464. package/dist/src/execution/history-view.js +0 -1
  1465. package/dist/src/execution/legacy-remote-agent/protocol.d.ts +0 -49
  1466. package/dist/src/execution/legacy-remote-agent/protocol.js +0 -1
  1467. package/dist/src/execution/runtime-errors.d.ts +0 -13
  1468. package/dist/src/execution/runtime-errors.js +0 -1
  1469. package/dist/src/execution/sandbox/grep-tool.d.ts +0 -26
  1470. package/dist/src/execution/sandbox/grep-tool.js +0 -3
  1471. package/dist/src/execution/session/turn-waiting-step.d.ts +0 -4
  1472. package/dist/src/execution/session/turn-waiting-step.js +0 -1
  1473. package/dist/src/execution/tools/workflow/cancel.d.ts +0 -13
  1474. package/dist/src/execution/tools/workflow/cancel.js +0 -1
  1475. package/dist/src/execution/workflow-trace-context.d.ts +0 -8
  1476. package/dist/src/execution/workflow-trace-context.js +0 -1
  1477. package/dist/src/extensions/code/extension/instructions/github.d.ts +0 -3
  1478. package/dist/src/extensions/code/extension/instructions/github.js +0 -1
  1479. package/dist/src/extensions/code/extension/lib/github-compat.d.ts +0 -28
  1480. package/dist/src/extensions/code/extension/lib/github-compat.js +0 -1
  1481. package/dist/src/extensions/code/extension/lib/grep-search.js +0 -6
  1482. package/dist/src/extensions/code/extension/skills/pr.d.ts +0 -6
  1483. package/dist/src/extensions/code/extension/skills/pr.js +0 -1
  1484. package/dist/src/extensions/code/extension/tools/gh.d.ts +0 -28
  1485. package/dist/src/extensions/code/extension/tools/gh.js +0 -1
  1486. package/dist/src/harness/approval-recheck.d.ts +0 -7
  1487. package/dist/src/harness/approval-recheck.js +0 -1
  1488. package/dist/src/harness/authorization-event-fields.d.ts +0 -16
  1489. package/dist/src/harness/authorization-event-fields.js +0 -1
  1490. package/dist/src/harness/hitl/candidates.d.ts +0 -139
  1491. package/dist/src/harness/hitl/candidates.js +0 -1
  1492. package/dist/src/harness/hitl/coordinator.d.ts +0 -35
  1493. package/dist/src/harness/hitl/coordinator.js +0 -1
  1494. package/dist/src/harness/input-extraction.d.ts +0 -13
  1495. package/dist/src/harness/input-extraction.js +0 -1
  1496. package/dist/src/harness/input-request-class.d.ts +0 -3
  1497. package/dist/src/harness/input-request-class.js +0 -1
  1498. package/dist/src/harness/input-request-resolution.d.ts +0 -39
  1499. package/dist/src/harness/input-request-resolution.js +0 -1
  1500. package/dist/src/harness/open-input-request.d.ts +0 -8
  1501. package/dist/src/harness/open-input-request.js +0 -1
  1502. package/dist/src/harness/session-machine/events.d.ts +0 -6
  1503. package/dist/src/harness/session-machine/events.js +0 -1
  1504. package/dist/src/harness/session-machine/resolver-events.d.ts +0 -12
  1505. package/dist/src/harness/session-machine/resolver-events.js +0 -1
  1506. package/dist/src/harness/tool-call-action.d.ts +0 -9
  1507. package/dist/src/harness/tool-call-action.js +0 -1
  1508. package/dist/src/harness/tool-interrupts.d.ts +0 -22
  1509. package/dist/src/harness/tool-interrupts.js +0 -1
  1510. package/dist/src/harness/tool-presentation.d.ts +0 -5
  1511. package/dist/src/harness/tool-presentation.js +0 -1
  1512. package/dist/src/harness/turn-tag-state.d.ts +0 -115
  1513. package/dist/src/harness/turn-tag-state.js +0 -1
  1514. package/dist/src/internal/dynamic-tool-rebind.d.ts +0 -3
  1515. package/dist/src/internal/dynamic-tool-rebind.js +0 -1
  1516. package/dist/src/internal/nitro/host/extension-capability-requirements.d.ts +0 -14
  1517. package/dist/src/internal/nitro/host/extension-capability-requirements.js +0 -1
  1518. package/dist/src/internal/workflow-bundle/dynamic-capability-transform-plugin.d.ts +0 -12
  1519. package/dist/src/internal/workflow-bundle/dynamic-capability-transform-plugin.js +0 -1
  1520. package/dist/src/internal/workflow-bundle/dynamic-remote-agent-transform.d.ts +0 -7
  1521. package/dist/src/internal/workflow-bundle/dynamic-remote-agent-transform.js +0 -3
  1522. package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.d.ts +0 -79
  1523. package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.js +0 -1
  1524. package/dist/src/internal/workflow-bundle/dynamic-tool-transform.d.ts +0 -14
  1525. package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +0 -3
  1526. package/dist/src/protocol/event-dedupe.d.ts +0 -26
  1527. package/dist/src/protocol/event-dedupe.js +0 -1
  1528. package/dist/src/protocol/event-id.d.ts +0 -10
  1529. package/dist/src/protocol/event-id.js +0 -1
  1530. package/dist/src/protocol/message-version.d.ts +0 -53
  1531. package/dist/src/protocol/message-version.js +0 -1
  1532. package/dist/src/protocol/message.d.ts +0 -1198
  1533. package/dist/src/protocol/message.js +0 -2
  1534. package/dist/src/public/channels/chat-sdk/messageToUserContent.js +0 -1
  1535. package/dist/src/public/channels/slack/input-response.js +0 -1
  1536. package/dist/src/runtime/hooks/registry.d.ts +0 -34
  1537. package/dist/src/runtime/hooks/registry.js +0 -1
  1538. package/dist/src/runtime/resolve-dynamic-connection.d.ts +0 -5
  1539. package/dist/src/runtime/resolve-dynamic-connection.js +0 -1
  1540. package/dist/src/runtime/resolve-dynamic-instructions.d.ts +0 -4
  1541. package/dist/src/runtime/resolve-dynamic-instructions.js +0 -1
  1542. package/dist/src/runtime/resolve-dynamic-skill.d.ts +0 -8
  1543. package/dist/src/runtime/resolve-dynamic-skill.js +0 -1
  1544. package/dist/src/runtime/resolve-dynamic-subagent.d.ts +0 -9
  1545. package/dist/src/runtime/resolve-dynamic-subagent.js +0 -1
  1546. package/dist/src/runtime/resolve-dynamic-tool.d.ts +0 -12
  1547. package/dist/src/runtime/resolve-dynamic-tool.js +0 -1
  1548. package/dist/src/self-modification/migration.d.ts +0 -9
  1549. package/dist/src/self-modification/migration.js +0 -28
  1550. package/dist/src/shared/history-view.d.ts +0 -22
  1551. package/dist/src/shared/history-view.js +0 -1
  1552. package/dist/src/shared/package-version.d.ts +0 -2
  1553. package/dist/src/shared/package-version.js +0 -1
  1554. package/dist/src/tools/durable-callbacks.d.ts +0 -118
  1555. package/dist/src/tools/durable-callbacks.js +0 -1
  1556. package/dist/src/tools/durable-schema.d.ts +0 -16
  1557. package/dist/src/tools/durable-schema.js +0 -1
  1558. /package/dist/src/{client/eve-agent-store-state.js → ai/decision-types.js} +0 -0
  1559. /package/dist/src/client/{message-reducer-types.js → agent-info-types.js} +0 -0
  1560. /package/dist/src/client/{reducer.js → health-types.js} +0 -0
  1561. /package/dist/src/{shared → protocol/session-projection}/display-name.d.ts +0 -0
  1562. /package/dist/src/{shared → protocol/session-projection}/display-name.js +0 -0
@@ -1,4963 +0,0 @@
1
- import { onMount } from "svelte";
2
- import { createSubscriber } from "svelte/reactivity";
3
- import { z } from "#compiled/zod/index.js";
4
- import "ai";
5
- import { Validator } from "#compiled/@cfworker/json-schema/index.js";
6
-
7
- //#region src/client/abort-signal.ts
8
- function throwIfAborted(signal) {
9
- if (signal === void 0) return;
10
- const nativeThrowIfAborted = signal.throwIfAborted;
11
- if (typeof nativeThrowIfAborted === "function") {
12
- nativeThrowIfAborted.call(signal);
13
- return;
14
- }
15
- if (!signal.aborted) return;
16
- if (signal.reason !== void 0) throw signal.reason;
17
- const error = /* @__PURE__ */ new Error("The operation was aborted.");
18
- error.name = "AbortError";
19
- throw error;
20
- }
21
-
22
- //#endregion
23
- //#region src/protocol/routes.ts
24
- const EVE_ROUTE_PREFIX = "/eve/v1";
25
- const EVE_PRODUCTION_CRON_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/cron/:token`;
26
- const EVE_HEALTH_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/health`;
27
- const EVE_INFO_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/info`;
28
- const EVE_SESSION_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/session`;
29
- const EVE_SESSION_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId`;
30
- const EVE_SESSION_CANCEL_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/cancel`;
31
- const EVE_SESSION_COMPACT_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/compact`;
32
- const EVE_SESSION_CLEAR_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/clear`;
33
- const EVE_SESSION_RESET_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/reset`;
34
- const EVE_SESSION_STUBS_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/stubs`;
35
- const EVE_SESSION_STREAM_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:sessionId/stream`;
36
- const EVE_SUBAGENT_STREAM_ROUTE_PATTERN = `${EVE_SESSION_ROUTE_PATH}/:parentSessionId/subagents/:callId/:childSessionId/stream`;
37
- const EVE_DEV_DISPATCH_SCHEDULE_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/dev/schedules/:scheduleId`;
38
- const EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH = `${EVE_ROUTE_PREFIX}/dev/runtime-artifacts`;
39
- const EVE_DEV_RUNTIME_ARTIFACTS_REBUILD_ROUTE_PATH = `${EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}/rebuild`;
40
- const EVE_DEV_RUNTIME_ARTIFACTS_SUSPEND_ROUTE_PATH = `${EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}/suspend`;
41
- const EVE_DEV_RUNTIME_ARTIFACTS_RESUME_ROUTE_PATH = `${EVE_DEV_RUNTIME_ARTIFACTS_ROUTE_PATH}/resume`;
42
- const EVE_CONNECTION_CALLBACK_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/connections/:name/callback/:attemptId/:token`;
43
- const EVE_CALLBACK_ROUTE_PATTERN = `${EVE_ROUTE_PREFIX}/callback/:token`;
44
- function createEveSessionRoutePath(sessionId) {
45
- return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}`;
46
- }
47
- function createEveSessionCancelRoutePath(sessionId) {
48
- return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/cancel`;
49
- }
50
- function createEveSessionCompactRoutePath(sessionId) {
51
- return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/compact`;
52
- }
53
- function createEveSessionClearRoutePath(sessionId) {
54
- return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/clear`;
55
- }
56
- function createEveSessionResetRoutePath(sessionId) {
57
- return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/reset`;
58
- }
59
- function createEveSessionStreamRoutePath(sessionId) {
60
- return `${EVE_SESSION_ROUTE_PATH}/${encodeURIComponent(sessionId)}/stream`;
61
- }
62
-
63
- //#endregion
64
- //#region src/client/agent-info-error.ts
65
- var AgentInfoResponseError = class extends Error {
66
- issues;
67
- constructor(issues = []) {
68
- const detail = issues.length === 0 ? "" : ` (${issues.join("; ")})`;
69
- super(`The server returned an unrecognized response from the eve agent info route.${detail}`);
70
- this.name = "AgentInfoResponseError";
71
- this.issues = issues;
72
- }
73
- };
74
-
75
- //#endregion
76
- //#region src/client/health-response-error.ts
77
- var HealthResponseError = class extends Error {
78
- issues;
79
- constructor(issues = []) {
80
- const detail = issues.length === 0 ? "" : ` (${issues.join("; ")})`;
81
- super(`The server returned an unrecognized eve health response.${detail}`);
82
- this.name = "HealthResponseError";
83
- this.issues = issues;
84
- }
85
- };
86
-
87
- //#endregion
88
- //#region src/client/health-schema.ts
89
- const HealthResultSchema = z.object({
90
- ok: z.literal(true),
91
- status: z.literal("ready"),
92
- workflowId: z.string().min(1)
93
- }).strict();
94
-
95
- //#endregion
96
- //#region src/internal/http/basic-auth.ts
97
- function encodeBasicCredentials(username, password) {
98
- const bytes = new TextEncoder().encode(`${username}:${password}`);
99
- const binaryString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join("");
100
- return btoa(binaryString);
101
- }
102
-
103
- //#endregion
104
- //#region src/shared/extension-mount.ts
105
- const mountIdSchema = z.string().min(1);
106
-
107
- //#endregion
108
- //#region src/client/agent-info-schema.ts
109
- const owner = z.discriminatedUnion("kind", [
110
- z.object({ kind: z.literal("application") }).strict(),
111
- z.object({
112
- feature: z.string(),
113
- kind: z.literal("framework")
114
- }).strict(),
115
- z.object({
116
- kind: z.literal("extension"),
117
- mountId: mountIdSchema.optional(),
118
- namespace: z.string(),
119
- packageName: z.string()
120
- }).strict()
121
- ]);
122
- const moduleBacking = z.discriminatedUnion("kind", [z.object({
123
- externalDependencies: z.array(z.string()),
124
- extensionScope: z.object({
125
- namespace: z.string(),
126
- sourceRoot: z.string()
127
- }).strict().optional(),
128
- kind: z.literal("filesystem"),
129
- mountId: z.string().optional(),
130
- sourcePath: z.string()
131
- }).strict(), z.object({
132
- dependencies: z.record(z.string(), z.string()).optional(),
133
- kind: z.literal("programmatic"),
134
- mountId: z.string().optional(),
135
- moduleId: z.string(),
136
- parameters: z.record(z.string(), z.unknown()).optional(),
137
- registryId: z.string(),
138
- revision: z.string(),
139
- semanticRevision: z.string().optional()
140
- }).strict()]);
141
- const binding = z.object({
142
- backing: moduleBacking,
143
- logicalPath: z.string(),
144
- owner
145
- }).strict();
146
- const source = z.object({
147
- binding: binding.optional(),
148
- exportName: z.string().optional(),
149
- logicalPath: z.string(),
150
- owner,
151
- sourceId: z.string(),
152
- sourceKind: z.enum([
153
- "markdown",
154
- "module",
155
- "skill-package"
156
- ])
157
- }).strict();
158
- const entry = source.extend({ name: z.string() }).strict();
159
- const dynamicResolver = source.extend({
160
- eventNames: z.array(z.string()),
161
- slug: z.string()
162
- }).strict();
163
- const modelRouting = z.discriminatedUnion("kind", [z.object({
164
- kind: z.literal("gateway"),
165
- target: z.string(),
166
- byok: z.string().optional()
167
- }).strict(), z.object({
168
- kind: z.literal("external"),
169
- provider: z.string()
170
- }).strict()]);
171
- const modelEndpoint = z.union([
172
- z.object({
173
- kind: z.literal("external"),
174
- provider: z.string()
175
- }).strict(),
176
- z.object({
177
- kind: z.literal("chatgpt"),
178
- state: z.enum([
179
- "checking",
180
- "ready",
181
- "signed-out",
182
- "reauth-required",
183
- "unavailable"
184
- ]),
185
- accountLabel: z.string().optional()
186
- }).strict(),
187
- z.object({
188
- kind: z.literal("gateway"),
189
- connected: z.literal(true),
190
- credential: z.enum([
191
- "api-key",
192
- "oidc",
193
- "oauth"
194
- ]),
195
- team: z.optional(z.string())
196
- }).strict(),
197
- z.object({
198
- kind: z.literal("gateway"),
199
- connected: z.literal(false)
200
- }).strict()
201
- ]);
202
- const modelBaseFields = {
203
- contextWindowTokens: z.number().optional(),
204
- providerOptions: z.unknown().optional(),
205
- reasoning: z.enum([
206
- "provider-default",
207
- "none",
208
- "minimal",
209
- "low",
210
- "medium",
211
- "high",
212
- "xhigh"
213
- ]).optional().catch(void 0),
214
- source: source.optional()
215
- };
216
- const agentModel = z.union([z.object({
217
- ...modelBaseFields,
218
- endpoint: modelEndpoint.optional(),
219
- id: z.string(),
220
- routing: modelRouting
221
- }).strict(), z.object({
222
- ...modelBaseFields,
223
- endpoint: z.never().optional(),
224
- id: z.never().optional(),
225
- routing: z.object({
226
- kind: z.literal("dynamic"),
227
- resolver: dynamicResolver
228
- }).strict()
229
- }).strict()]);
230
- const tool = entry.extend({
231
- description: z.string(),
232
- hasAuth: z.boolean(),
233
- hasExecute: z.boolean(),
234
- hasModelOutputProjection: z.boolean(),
235
- hasOutputSchema: z.boolean(),
236
- inputSchema: z.unknown(),
237
- outputSchema: z.unknown().optional(),
238
- requiresApproval: z.boolean()
239
- }).strict();
240
- const skill = entry.extend({
241
- description: z.string(),
242
- license: z.string().optional(),
243
- markdown: z.string(),
244
- metadata: z.record(z.string(), z.string()).optional()
245
- }).strict();
246
- const instructions = entry.extend({
247
- content: z.string(),
248
- role: z.enum(["system", "user"])
249
- }).strict();
250
- const schedule = entry.extend({
251
- cron: z.string(),
252
- hasRun: z.boolean(),
253
- markdown: z.string().optional()
254
- }).strict();
255
- const channelMethod = z.enum([
256
- "GET",
257
- "HEAD",
258
- "POST",
259
- "PUT",
260
- "PATCH",
261
- "DELETE",
262
- "OPTIONS",
263
- "WEBSOCKET"
264
- ]);
265
- const channelRoute = entry.extend({
266
- adapterKind: z.string().optional(),
267
- method: channelMethod,
268
- urlPath: z.string()
269
- }).strict();
270
- const sourceDescriptor = z.object({
271
- backing: z.union([moduleBacking, z.object({
272
- kind: z.literal("resource"),
273
- sourcePath: z.string()
274
- }).strict()]),
275
- form: z.enum(["derived", "direct"]),
276
- layer: z.enum([
277
- "framework-default",
278
- "extension-package",
279
- "extension-override",
280
- "application"
281
- ]),
282
- logicalPath: z.string(),
283
- owner,
284
- sourceId: z.string()
285
- }).strict();
286
- const shadowedChannelRoute = z.object({
287
- method: channelMethod,
288
- source: sourceDescriptor,
289
- urlPath: z.string(),
290
- winnerSourceId: z.string()
291
- }).strict();
292
- const connection = source.extend({
293
- connectionName: z.string(),
294
- description: z.string(),
295
- hasApproval: z.boolean(),
296
- hasAuthorization: z.boolean(),
297
- hasHeaders: z.boolean(),
298
- protocol: z.string(),
299
- toolFilter: z.unknown().optional(),
300
- url: z.string()
301
- }).strict();
302
- const hook = source.extend({
303
- eventNames: z.array(z.string()),
304
- slug: z.string()
305
- }).strict();
306
- const memory = source.extend({
307
- description: z.string().optional(),
308
- slot: z.string(),
309
- visibility: z.enum(["scope", "session"])
310
- }).strict();
311
- const sandbox = source.extend({
312
- provider: z.string().optional(),
313
- environmentExportName: z.string().optional(),
314
- revisionHash: z.string()
315
- }).strict();
316
- const subagent = entry.extend({
317
- configResolver: dynamicResolver.optional(),
318
- description: z.string().optional(),
319
- entryPath: z.string(),
320
- nodeId: z.string(),
321
- parentNodeId: z.string(),
322
- rootPath: z.string(),
323
- summary: z.object({
324
- channels: z.number(),
325
- connections: z.number(),
326
- hooks: z.number(),
327
- instructions: z.number(),
328
- memories: z.number(),
329
- schedules: z.number(),
330
- skills: z.number(),
331
- tools: z.number()
332
- }).strict()
333
- }).strict();
334
- const remoteAgent = entry.extend({
335
- description: z.string(),
336
- nodeId: z.string(),
337
- parentNodeId: z.string(),
338
- url: z.string().optional()
339
- }).strict();
340
- const kernelEffect = z.object({
341
- action: z.union([z.enum(["subagent-call", "workflow-tool-call"]), z.literal("unrecognized")]).catch("unrecognized").optional(),
342
- audience: z.array(z.union([z.literal("root-session"), z.literal("unrecognized")]).catch("unrecognized")),
343
- kind: z.union([z.enum(["dispatch", "provider-tool"]), z.literal("unrecognized")]).catch("unrecognized"),
344
- sourceId: z.string()
345
- }).strict();
346
- const compositionDiagnostic = z.object({
347
- kind: z.enum(["disabled", "shadowed"]),
348
- logicalPath: z.string(),
349
- owner,
350
- sourceId: z.string(),
351
- winnerSourceId: z.string().optional()
352
- }).strict();
353
- const AgentInfoResultSchema = z.object({
354
- agent: z.object({
355
- agentRoot: z.string(),
356
- appRoot: z.string(),
357
- config: source.extend({ binding }).strict(),
358
- description: z.string().optional(),
359
- model: agentModel,
360
- name: z.string(),
361
- nodeId: z.string(),
362
- outputSchema: z.unknown().optional()
363
- }).strict(),
364
- capabilities: z.object({ devRoutes: z.boolean() }).strict(),
365
- channels: z.object({
366
- routes: z.array(channelRoute),
367
- shadowed: z.array(shadowedChannelRoute)
368
- }).strict(),
369
- composition: z.object({
370
- disabled: z.array(compositionDiagnostic),
371
- shadowed: z.array(compositionDiagnostic)
372
- }).strict(),
373
- connections: z.array(connection),
374
- diagnostics: z.object({
375
- discoveryErrors: z.number(),
376
- discoveryWarnings: z.number()
377
- }).strict(),
378
- hooks: z.array(hook),
379
- instructions: z.object({
380
- dynamic: z.array(dynamicResolver),
381
- static: z.array(instructions)
382
- }).strict(),
383
- instrumentation: source.optional(),
384
- kernelEffects: z.array(kernelEffect),
385
- kind: z.literal("eve-agent-info"),
386
- memories: z.array(memory),
387
- mode: z.enum(["development", "production"]),
388
- remoteAgents: z.object({
389
- entries: z.array(remoteAgent),
390
- total: z.number()
391
- }).strict(),
392
- sandbox,
393
- schedules: z.array(schedule),
394
- skills: z.object({
395
- dynamic: z.array(dynamicResolver),
396
- static: z.array(skill)
397
- }).strict(),
398
- subagents: z.object({
399
- local: z.array(subagent),
400
- total: z.number()
401
- }).strict(),
402
- tools: z.object({
403
- dynamic: z.array(dynamicResolver),
404
- static: z.array(tool)
405
- }).strict(),
406
- version: z.literal(5),
407
- workspace: z.object({
408
- resourceRoot: z.unknown(),
409
- rootEntries: z.array(z.string())
410
- }).strict()
411
- }).strict().superRefine((value, context) => {
412
- const assertUnique = (entries, identity, path) => {
413
- const seen = /* @__PURE__ */ new Set();
414
- entries.forEach((entry, index) => {
415
- const key = identity(entry);
416
- if (seen.has(key)) context.addIssue({
417
- code: "custom",
418
- message: `Duplicate public identity "${key}".`,
419
- path: [...path, index]
420
- });
421
- seen.add(key);
422
- });
423
- };
424
- const assertTotal = (total, entries, path) => {
425
- if (!Number.isSafeInteger(total) || total < 0 || total !== entries.length) context.addIssue({
426
- code: "custom",
427
- message: `Expected total ${entries.length}, received ${total}.`,
428
- path: [...path]
429
- });
430
- };
431
- assertUnique(value.tools.static, (entry) => entry.name, ["tools", "static"]);
432
- assertUnique(value.tools.dynamic, (entry) => entry.slug, ["tools", "dynamic"]);
433
- assertUnique(value.skills.static, (entry) => entry.name, ["skills", "static"]);
434
- assertUnique(value.skills.dynamic, (entry) => entry.slug, ["skills", "dynamic"]);
435
- assertUnique(value.instructions.static, (entry) => entry.name, ["instructions", "static"]);
436
- assertUnique(value.instructions.dynamic, (entry) => entry.slug, ["instructions", "dynamic"]);
437
- assertUnique(value.schedules, (entry) => entry.name, ["schedules"]);
438
- assertUnique(value.connections, (entry) => entry.connectionName, ["connections"]);
439
- assertUnique(value.hooks, (entry) => entry.slug, ["hooks"]);
440
- assertUnique(value.memories, (entry) => entry.slot, ["memories"]);
441
- assertUnique(value.channels.routes, (entry) => `${entry.method} ${normalizeRoutePattern(entry.urlPath)}`, ["channels", "routes"]);
442
- assertUnique(value.subagents.local, (entry) => entry.nodeId, ["subagents", "local"]);
443
- assertUnique(value.remoteAgents.entries, (entry) => entry.nodeId, ["remoteAgents", "entries"]);
444
- assertTotal(value.subagents.total, value.subagents.local, ["subagents", "total"]);
445
- assertTotal(value.remoteAgents.total, value.remoteAgents.entries, ["remoteAgents", "total"]);
446
- const boundSources = [
447
- [value.agent.config, ["agent", "config"]],
448
- ...value.agent.model.source === void 0 ? [] : [[value.agent.model.source, [
449
- "agent",
450
- "model",
451
- "source"
452
- ]]],
453
- ...value.agent.model.routing.kind === "dynamic" ? [[value.agent.model.routing.resolver, [
454
- "agent",
455
- "model",
456
- "routing",
457
- "resolver"
458
- ]]] : [],
459
- ...value.channels.routes.map((entry, index) => [entry, [
460
- "channels",
461
- "routes",
462
- index
463
- ]]),
464
- ...value.connections.map((entry, index) => [entry, ["connections", index]]),
465
- ...value.hooks.map((entry, index) => [entry, ["hooks", index]]),
466
- ...value.instructions.dynamic.map((entry, index) => [entry, [
467
- "instructions",
468
- "dynamic",
469
- index
470
- ]]),
471
- ...value.instructions.static.map((entry, index) => [entry, [
472
- "instructions",
473
- "static",
474
- index
475
- ]]),
476
- ...value.memories.map((entry, index) => [entry, ["memories", index]]),
477
- ...value.instrumentation === void 0 ? [] : [[value.instrumentation, ["instrumentation"]]],
478
- ...value.remoteAgents.entries.map((entry, index) => [entry, [
479
- "remoteAgents",
480
- "entries",
481
- index
482
- ]]),
483
- ...value.schedules.map((entry, index) => [entry, ["schedules", index]]),
484
- ...value.skills.dynamic.map((entry, index) => [entry, [
485
- "skills",
486
- "dynamic",
487
- index
488
- ]]),
489
- ...value.skills.static.map((entry, index) => [entry, [
490
- "skills",
491
- "static",
492
- index
493
- ]]),
494
- ...value.subagents.local.flatMap((entry, index) => entry.configResolver === void 0 ? [] : [[entry.configResolver, [
495
- "subagents",
496
- "local",
497
- index,
498
- "configResolver"
499
- ]]]),
500
- ...value.tools.dynamic.map((entry, index) => [entry, [
501
- "tools",
502
- "dynamic",
503
- index
504
- ]]),
505
- ...value.tools.static.map((entry, index) => [entry, [
506
- "tools",
507
- "static",
508
- index
509
- ]]),
510
- [value.sandbox, ["sandbox"]]
511
- ];
512
- for (const [entry, path] of boundSources) {
513
- if (entry.sourceKind === "module" && entry.binding === void 0) {
514
- context.addIssue({
515
- code: "custom",
516
- message: "Module source is missing its compiled binding.",
517
- path: [...path, "binding"]
518
- });
519
- continue;
520
- }
521
- if (entry.sourceKind !== "module" && entry.binding !== void 0) {
522
- context.addIssue({
523
- code: "custom",
524
- message: `${entry.sourceKind} source cannot carry a module binding.`,
525
- path: [...path, "binding"]
526
- });
527
- continue;
528
- }
529
- if (entry.binding === void 0) continue;
530
- if (entry.binding.logicalPath !== entry.logicalPath) context.addIssue({
531
- code: "custom",
532
- message: "Source and binding logical paths do not match.",
533
- path: [
534
- ...path,
535
- "binding",
536
- "logicalPath"
537
- ]
538
- });
539
- if (JSON.stringify(entry.binding.owner) !== JSON.stringify(entry.owner)) context.addIssue({
540
- code: "custom",
541
- message: "Source and binding owners do not match.",
542
- path: [
543
- ...path,
544
- "binding",
545
- "owner"
546
- ]
547
- });
548
- }
549
- });
550
- function normalizeRoutePattern(path) {
551
- return path.replace(/^\/+|\/+$/g, "").split("/").map((segment) => segment.startsWith(":") || /^\[[^\]]+\]$/.test(segment) ? ":" : segment).join("/");
552
- }
553
-
554
- //#endregion
555
- //#region src/shared/guards.ts
556
- function isObject(value) {
557
- return typeof value === "object" && value !== null && !Array.isArray(value);
558
- }
559
-
560
- //#endregion
561
- //#region src/client/client-error.ts
562
- var ClientError = class extends Error {
563
- code;
564
- status;
565
- body;
566
- headers;
567
- constructor(status, body, headers) {
568
- const normalizedHeaders = Object.freeze(Object.fromEntries(new Headers(headers).entries()));
569
- const contentType = normalizedHeaders["content-type"]?.toLowerCase();
570
- const parsed = parseJsonObject$1(body);
571
- let message = body || `Server returned ${status}.`;
572
- if (typeof parsed?.error === "string") message = parsed.error;
573
- else if (parsed === void 0 && contentType?.includes("text/html")) message = `Server returned ${status} with an HTML response. Check the eve route and development server configuration.`;
574
- super(message);
575
- this.name = "ClientError";
576
- this.code = typeof parsed?.code === "string" ? parsed.code : void 0;
577
- this.status = status;
578
- this.body = body;
579
- this.headers = normalizedHeaders;
580
- }
581
- };
582
- var ClientSessionStrandedError = class extends ClientError {
583
- eveVersion;
584
- constructor(status, body, headers, details) {
585
- super(status, body, headers);
586
- this.name = "ClientSessionStrandedError";
587
- this.eveVersion = details.eveVersion;
588
- }
589
- };
590
- function createClientError(status, body, headers) {
591
- const parsed = status === 409 ? parseJsonObject$1(body) : void 0;
592
- if (parsed?.code !== "session_stranded") return new ClientError(status, body, headers);
593
- return new ClientSessionStrandedError(status, body, headers, { eveVersion: typeof parsed.eveVersion === "string" ? parsed.eveVersion : void 0 });
594
- }
595
- function parseJsonObject$1(body) {
596
- try {
597
- const parsed = JSON.parse(body);
598
- return isObject(parsed) ? parsed : void 0;
599
- } catch {
600
- return;
601
- }
602
- }
603
-
604
- //#endregion
605
- //#region src/internal/attachments/media-metadata.ts
606
- const PDF_MEDIA_TYPE = "application/pdf";
607
- const INLINE_IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
608
- "image/gif",
609
- "image/jpeg",
610
- "image/png",
611
- "image/webp"
612
- ]);
613
- const VERIFIABLE_MEDIA_TYPES = /* @__PURE__ */ new Set([
614
- ...INLINE_IMAGE_MEDIA_TYPES,
615
- "image/jpg",
616
- PDF_MEDIA_TYPE
617
- ]);
618
-
619
- //#endregion
620
- //#region src/shared/ulid.ts
621
- const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
622
- const TIME_CHARS = 10;
623
- const TIME_MAX = 2 ** 48 - 1;
624
- const RANDOM_BYTES = 10;
625
- function createUlidFactory() {
626
- let lastTimeMs = -1;
627
- const lastRandom = new Uint8Array(RANDOM_BYTES);
628
- return function createUlidFromFactory() {
629
- const now = Date.now();
630
- if (!Number.isInteger(now) || now < 0 || now > TIME_MAX) throw new Error(`Cannot mint a ULID: timestamp must be an integer from 0 to ${TIME_MAX}.`);
631
- if (now > lastTimeMs) {
632
- lastTimeMs = now;
633
- randomFill(lastRandom);
634
- } else if (!incrementRandom(lastRandom)) {
635
- if (lastTimeMs === TIME_MAX) throw new Error("Cannot mint a ULID: random component overflowed at the maximum timestamp.");
636
- lastTimeMs += 1;
637
- randomFill(lastRandom);
638
- }
639
- return `${encodeTime(lastTimeMs)}${encodeRandom(lastRandom)}`;
640
- };
641
- }
642
- const createUlid = createUlidFactory();
643
- function randomFill(target) {
644
- const webCrypto = globalThis.crypto;
645
- if (typeof webCrypto?.getRandomValues !== "function") throw new Error("Cannot mint a ULID: globalThis.crypto.getRandomValues is unavailable.");
646
- webCrypto.getRandomValues(target);
647
- }
648
- function encodeTime(timeMs) {
649
- let remaining = timeMs;
650
- let encoded = "";
651
- for (let index = 0; index < TIME_CHARS; index += 1) {
652
- encoded = ENCODING[remaining % 32] + encoded;
653
- remaining = Math.floor(remaining / 32);
654
- }
655
- return encoded;
656
- }
657
- function encodeRandom(bytes) {
658
- let buffer = 0;
659
- let bufferedBits = 0;
660
- let encoded = "";
661
- for (const byte of bytes) {
662
- buffer = buffer << 8 | byte;
663
- bufferedBits += 8;
664
- while (bufferedBits >= 5) {
665
- bufferedBits -= 5;
666
- encoded += ENCODING[buffer >>> bufferedBits & 31];
667
- }
668
- buffer &= (1 << bufferedBits) - 1;
669
- }
670
- return encoded;
671
- }
672
- function incrementRandom(bytes) {
673
- for (let index = bytes.length - 1; index >= 0; index -= 1) {
674
- const byte = bytes[index] ?? 0;
675
- if (byte < 255) {
676
- bytes[index] = byte + 1;
677
- bytes.fill(0, index + 1);
678
- return true;
679
- }
680
- }
681
- return false;
682
- }
683
-
684
- //#endregion
685
- //#region src/protocol/message.ts
686
- const EVE_SESSION_ID_HEADER = "x-eve-session-id";
687
- const EVE_STREAM_TAIL_INDEX_HEADER = "x-eve-stream-tail-index";
688
- const EVE_STREAM_VERSION_HEADER = "x-eve-stream-version";
689
- const EVE_STREAM_CONTROL_VERSION_QUERY = "streamControlVersion";
690
- const EVE_STREAM_LEASE_ENDED_CONTROL = {
691
- $eve: "stream.lease-ended",
692
- version: 1
693
- };
694
- const textEncoder = new TextEncoder();
695
- function isCurrentTurnBoundaryEvent(event) {
696
- return event.type === "session.completed" || event.type === "session.failed" || event.type === "session.waiting";
697
- }
698
- function isTurnFailureEvent(event) {
699
- return event.type === "session.failed" || event.type === "step.failed" || event.type === "turn.failed";
700
- }
701
-
702
- //#endregion
703
- //#region src/protocol/session-projection.ts
704
- function initialSessionProjection() {
705
- return {
706
- authorizations: {},
707
- calls: {},
708
- candidates: {},
709
- inputs: {},
710
- nextSequence: 0,
711
- tasks: {},
712
- turns: {}
713
- };
714
- }
715
- function updateTurn(state, turnId, update) {
716
- const turn = state.turns[turnId];
717
- if (turn === void 0) return state;
718
- const next = update(turn);
719
- return next === turn ? state : {
720
- ...state,
721
- turns: {
722
- ...state.turns,
723
- [turnId]: next
724
- }
725
- };
726
- }
727
- function putTask(state, task) {
728
- return state.tasks[task.taskId] === task ? state : {
729
- ...state,
730
- tasks: {
731
- ...state.tasks,
732
- [task.taskId]: task
733
- }
734
- };
735
- }
736
- function putTaskCall(task, call) {
737
- return task.calls[call.callId] === call ? task : {
738
- ...task,
739
- calls: {
740
- ...task.calls,
741
- [call.callId]: call
742
- }
743
- };
744
- }
745
- function putCall(state, call) {
746
- return state.calls[call.callId] === call ? state : {
747
- ...state,
748
- calls: {
749
- ...state.calls,
750
- [call.callId]: call
751
- }
752
- };
753
- }
754
- function updateTask(state, taskId, update) {
755
- const task = state.tasks[taskId];
756
- if (task === void 0) return state;
757
- return putTask(state, update(task));
758
- }
759
- function updateCall(state, callId, update) {
760
- const call = state.calls[callId];
761
- if (call === void 0) return state;
762
- return putCall(state, update(call));
763
- }
764
- const SETTLED_CALL_STATUSES = /* @__PURE__ */ new Set([
765
- "completed",
766
- "failed",
767
- "rejected",
768
- "cancelled"
769
- ]);
770
- function isSettledCallStatus(status) {
771
- return SETTLED_CALL_STATUSES.has(status);
772
- }
773
- function settleCall(call, status, error) {
774
- if (call.taskId !== void 0 || isSettledCallStatus(call.status)) return call;
775
- const { requestId: _requestId, error: _error, ...rest } = call;
776
- const settled = {
777
- ...rest,
778
- status
779
- };
780
- if (call.requestId !== void 0) settled.requestId = call.requestId;
781
- if (error !== void 0) settled.error = error;
782
- return settled;
783
- }
784
- function actionName(action) {
785
- switch (action.kind) {
786
- case "load-skill": return action.name;
787
- case "subagent-call":
788
- case "remote-agent-call": return action.name;
789
- case "tool-call":
790
- case "workflow-tool-call": return action.toolName;
791
- }
792
- }
793
- function resultName(result) {
794
- switch (result.kind) {
795
- case "load-skill-result": return result.name;
796
- case "subagent-result": return result.subagentName;
797
- default: return result.toolName;
798
- }
799
- }
800
- function callStatusAfterApproval(outcome) {
801
- switch (outcome) {
802
- case "approved": return "running";
803
- case "denied": return "rejected";
804
- case "cancelled": return "cancelled";
805
- default: return;
806
- }
807
- }
808
- const TOOL_EXECUTION_DENIED = "TOOL_EXECUTION_DENIED";
809
- function foldSession(state, event) {
810
- const typed = event;
811
- switch (typed.type) {
812
- case "session.started": return state.started ? state : {
813
- ...state,
814
- started: true
815
- };
816
- case "turn.started": {
817
- const { sequence, turnId } = typed.data;
818
- const turn = {
819
- turnId,
820
- sequence,
821
- status: "active"
822
- };
823
- return {
824
- ...state,
825
- activeTurnId: turnId,
826
- nextSequence: Math.max(state.nextSequence, sequence + 1),
827
- turns: {
828
- ...state.turns,
829
- [turnId]: turn
830
- }
831
- };
832
- }
833
- case "step.started": return updateTurn(state, typed.data.turnId, (turn) => {
834
- if (!turn.waiting && turn.stepIndex === typed.data.stepIndex) return turn;
835
- const { waiting: _waiting, ...rest } = turn;
836
- return {
837
- ...rest,
838
- stepIndex: typed.data.stepIndex
839
- };
840
- });
841
- case "turn.waiting": return updateTurn(state, typed.data.turnId, (turn) => turn.status === "active" && !turn.waiting ? {
842
- ...turn,
843
- waiting: true
844
- } : turn);
845
- case "message.appended":
846
- case "message.completed":
847
- case "result.completed":
848
- if (!(typed.type === "message.appended" ? typed.data.messageDelta.length > 0 : typed.type === "message.completed" ? (typed.data.message?.length ?? 0) > 0 : true)) return state;
849
- return updateTurn(state, typed.data.turnId, (turn) => turn.outputStarted ? turn : {
850
- ...turn,
851
- outputStarted: true
852
- });
853
- case "turn.completed":
854
- case "turn.cancelled":
855
- case "turn.failed": {
856
- const { turnId } = typed.data;
857
- const status = typed.type === "turn.completed" ? "completed" : typed.type === "turn.failed" ? "failed" : "cancelled";
858
- const { waiting: _waiting, ...rest } = state.turns[turnId] ?? {
859
- turnId,
860
- sequence: typed.data.sequence
861
- };
862
- return {
863
- ...state,
864
- activeTurnId: state.activeTurnId === turnId ? void 0 : state.activeTurnId,
865
- turns: {
866
- ...state.turns,
867
- [turnId]: {
868
- ...rest,
869
- status
870
- }
871
- }
872
- };
873
- }
874
- case "context.cleared": return {
875
- ...state,
876
- calls: Object.fromEntries(Object.entries(state.calls).filter(([, call]) => call.taskId !== void 0))
877
- };
878
- case "session.waiting": return state.activeTurnId === void 0 ? state : {
879
- ...state,
880
- activeTurnId: void 0
881
- };
882
- case "session.completed":
883
- case "session.failed": {
884
- const { activeTurnId: _activeTurnId, ...rest } = state;
885
- return {
886
- ...rest,
887
- ended: true
888
- };
889
- }
890
- case "actions.requested": {
891
- let calls;
892
- for (const action of typed.data.actions) {
893
- if (state.calls[action.callId] !== void 0) continue;
894
- calls ??= { ...state.calls };
895
- calls[action.callId] = {
896
- callId: action.callId,
897
- name: actionName(action),
898
- turnId: typed.data.turnId,
899
- stepIndex: typed.data.stepIndex,
900
- status: "running"
901
- };
902
- }
903
- return calls === void 0 ? state : {
904
- ...state,
905
- calls
906
- };
907
- }
908
- case "action.result": {
909
- const { result, status, error } = typed.data;
910
- const call = state.calls[result.callId];
911
- if (call?.taskId !== void 0) return state;
912
- const settled = status === "rejected" || error?.code === TOOL_EXECUTION_DENIED ? "rejected" : status === "failed" || result.isError === true ? "failed" : "completed";
913
- if (call === void 0) {
914
- const unannounced = {
915
- callId: result.callId,
916
- name: resultName(result),
917
- turnId: typed.data.turnId,
918
- stepIndex: typed.data.stepIndex,
919
- status: settled
920
- };
921
- if (error !== void 0) unannounced.error = error;
922
- return putCall(state, unannounced);
923
- }
924
- return updateCall(state, result.callId, (current) => settleCall(current, settled, error));
925
- }
926
- case "task.started": {
927
- const { callId, kind, name, taskId, turnId } = typed.data;
928
- const task = state.tasks[taskId] ?? {
929
- taskId,
930
- name,
931
- kind,
932
- calls: {}
933
- };
934
- let next = state;
935
- if (task.calls[callId] === void 0) next = putTask(next, putTaskCall(task, {
936
- callId,
937
- turnId,
938
- status: "working"
939
- }));
940
- const call = next.calls[callId];
941
- if (call?.taskId === taskId) return next;
942
- const linked = {
943
- callId,
944
- name: call?.name ?? name,
945
- stepIndex: call?.stepIndex ?? 0,
946
- taskId,
947
- turnId: call?.turnId ?? turnId
948
- };
949
- if (call?.requestId !== void 0) linked.requestId = call.requestId;
950
- return putCall(next, linked);
951
- }
952
- case "task.settled": {
953
- const { callId, error, output, status, taskId } = typed.data;
954
- return updateTask(state, taskId, (task) => {
955
- const call = task.calls[callId];
956
- if (call === void 0 || call.status !== "working") return task;
957
- const settled = {
958
- callId,
959
- turnId: call.turnId,
960
- status
961
- };
962
- return putTaskCall(task, status === "completed" && output !== void 0 ? {
963
- ...settled,
964
- output
965
- } : status === "failed" && error !== void 0 ? {
966
- ...settled,
967
- error
968
- } : settled);
969
- });
970
- }
971
- case "input.requested": {
972
- const inputs = { ...state.inputs };
973
- let calls;
974
- for (const request of typed.data.requests) {
975
- if (inputs[request.requestId] !== void 0) continue;
976
- const input = {
977
- request,
978
- sequence: typed.data.sequence,
979
- turnId: typed.data.turnId,
980
- stepIndex: typed.data.stepIndex,
981
- status: "open"
982
- };
983
- if (typed.data.taskId !== void 0) input.taskId = typed.data.taskId;
984
- if (typed.data.callId !== void 0) input.callId = typed.data.callId;
985
- inputs[request.requestId] = input;
986
- if (request.kind !== "tool-approval" || isRelayed(typed.data)) continue;
987
- const { callId, toolName } = request.action;
988
- calls ??= { ...state.calls };
989
- const call = calls[callId];
990
- if (call?.taskId !== void 0) continue;
991
- if (call !== void 0 && isSettledCallStatus(call.status)) continue;
992
- calls[callId] = {
993
- ...call ?? {
994
- callId,
995
- name: toolName,
996
- turnId: typed.data.turnId,
997
- stepIndex: typed.data.stepIndex
998
- },
999
- requestId: request.requestId,
1000
- status: "awaiting-input"
1001
- };
1002
- }
1003
- return calls === void 0 ? {
1004
- ...state,
1005
- inputs
1006
- } : {
1007
- ...state,
1008
- calls,
1009
- inputs
1010
- };
1011
- }
1012
- case "approval.candidate": {
1013
- const { candidateId, outcome, requestId } = typed.data;
1014
- state = {
1015
- ...state,
1016
- candidates: {
1017
- ...state.candidates,
1018
- [candidateId]: {
1019
- candidateId,
1020
- outcome,
1021
- requestId
1022
- }
1023
- }
1024
- };
1025
- const current = state.inputs[typed.data.requestId];
1026
- if (current === void 0 || current.status === "settled") return state;
1027
- if (typed.data.outcome === "pending" || current.status === "open") return state;
1028
- const { response: _response, ...rest } = current;
1029
- return {
1030
- ...state,
1031
- inputs: {
1032
- ...state.inputs,
1033
- [typed.data.requestId]: {
1034
- ...rest,
1035
- status: "open"
1036
- }
1037
- }
1038
- };
1039
- }
1040
- case "approval.settled": {
1041
- const current = state.inputs[typed.data.requestId];
1042
- if (current === void 0 || current.status === "settled") return state;
1043
- const outcome = typed.data.outcome === "approved" ? "approved" : "denied";
1044
- return settleApprovalCall({
1045
- ...state,
1046
- inputs: {
1047
- ...state.inputs,
1048
- [typed.data.requestId]: {
1049
- ...current,
1050
- status: "settled",
1051
- outcome
1052
- }
1053
- }
1054
- }, current, outcome);
1055
- }
1056
- case "input.resolved": {
1057
- let next = state;
1058
- for (const resolution of typed.data.resolutions) {
1059
- const current = next.inputs[resolution.requestId];
1060
- if (current === void 0 || current.status === "settled") continue;
1061
- const response = resolution.response ?? current.response;
1062
- const settled = {
1063
- ...current,
1064
- status: "settled",
1065
- outcome: resolution.outcome
1066
- };
1067
- if (response !== void 0) settled.response = response;
1068
- next = {
1069
- ...next,
1070
- inputs: {
1071
- ...next.inputs,
1072
- [resolution.requestId]: settled
1073
- }
1074
- };
1075
- next = settleApprovalCall(next, current, resolution.outcome);
1076
- }
1077
- return next;
1078
- }
1079
- case "authorization.required": {
1080
- const attemptId = typed.data.attemptId ?? typed.data.name;
1081
- const authorization = {
1082
- attemptId,
1083
- name: typed.data.name,
1084
- sequence: typed.data.sequence,
1085
- turnId: typed.data.turnId,
1086
- stepIndex: typed.data.stepIndex,
1087
- status: "required"
1088
- };
1089
- if (typed.data.taskId !== void 0) authorization.taskId = typed.data.taskId;
1090
- if (typed.data.principalId !== void 0) authorization.principalId = typed.data.principalId;
1091
- if (typed.data.candidateId !== void 0) authorization.candidateId = typed.data.candidateId;
1092
- if (typed.data.grant !== void 0) authorization.grant = typed.data.grant;
1093
- if (typed.data.principal !== void 0) authorization.principal = typed.data.principal;
1094
- if (typed.data.webhookUrl !== void 0) authorization.awaitsCallback = true;
1095
- return {
1096
- ...state,
1097
- authorizations: {
1098
- ...state.authorizations,
1099
- [attemptId]: authorization
1100
- }
1101
- };
1102
- }
1103
- case "authorization.completed": {
1104
- const attemptId = typed.data.attemptId ?? typed.data.name;
1105
- const completed = {
1106
- ...state.authorizations[attemptId] ?? {
1107
- attemptId,
1108
- name: typed.data.name,
1109
- sequence: typed.data.sequence,
1110
- turnId: typed.data.turnId,
1111
- stepIndex: typed.data.stepIndex
1112
- },
1113
- status: typed.data.outcome
1114
- };
1115
- if (typed.data.grant !== void 0) completed.grant = typed.data.grant;
1116
- if (typed.data.principal !== void 0) completed.principal = typed.data.principal;
1117
- if (typed.data.retryable !== void 0) completed.retryable = typed.data.retryable;
1118
- if (typed.data.reason !== void 0) completed.reason = typed.data.reason;
1119
- return {
1120
- ...state,
1121
- authorizations: {
1122
- ...state.authorizations,
1123
- [attemptId]: completed
1124
- }
1125
- };
1126
- }
1127
- default: return state;
1128
- }
1129
- }
1130
- function isRelayed(request) {
1131
- return request.callId !== void 0 || request.taskId !== void 0;
1132
- }
1133
- function settleApprovalCall(state, input, outcome) {
1134
- if (input.request.kind !== "tool-approval" || isRelayed(input)) return state;
1135
- const status = callStatusAfterApproval(outcome);
1136
- if (status === void 0) return state;
1137
- return updateCall(state, input.request.action.callId, (call) => {
1138
- if (call.status !== "awaiting-input" || call.requestId !== input.request.requestId) return call;
1139
- return status === "running" ? {
1140
- ...call,
1141
- status
1142
- } : settleCall(call, status);
1143
- });
1144
- }
1145
- function openInputs(state) {
1146
- return Object.values(state.inputs).filter((input) => input.status !== "settled");
1147
- }
1148
- function openSignIns(state) {
1149
- return Object.values(state.authorizations).filter((attempt) => attempt.status === "required");
1150
- }
1151
- function callStatus(state, callId, options = {}) {
1152
- const call = state.calls[callId];
1153
- if (call === void 0) return void 0;
1154
- const status = reportedCallStatus(state, call);
1155
- if (status !== "running" || call.taskId !== void 0) return status;
1156
- const turn = state.turns[call.turnId];
1157
- if (options.streaming === false || turn !== void 0 && turn.status !== "active") return "interrupted";
1158
- return status;
1159
- }
1160
- function reportedCallStatus(state, call) {
1161
- if (call.taskId === void 0) return call.status;
1162
- const status = state.tasks[call.taskId]?.calls[call.callId]?.status;
1163
- return status === void 0 || status === "working" ? "running" : status;
1164
- }
1165
-
1166
- //#endregion
1167
- //#region src/client/session-utils.ts
1168
- function summarizeTurnEvents(events) {
1169
- const segment = new TurnSegment();
1170
- let boundary;
1171
- let failure;
1172
- let message;
1173
- for (const event of events) {
1174
- if (segment.observe(event)) boundary = event;
1175
- if (isTurnFailureEvent(event)) failure = event;
1176
- if (isFinalMessageCompleted(event)) message = event.data.message ?? void 0;
1177
- }
1178
- return {
1179
- boundary,
1180
- failure,
1181
- inputRequests: segment.inputRequests,
1182
- message,
1183
- pendingAuthorizations: segment.pendingAuthorizations,
1184
- status: summarizeBoundaryStatus(boundary)
1185
- };
1186
- }
1187
- function summarizeBoundaryStatus(boundary) {
1188
- if (boundary?.type === "session.waiting" || boundary?.type === "turn.waiting") return "waiting";
1189
- if (boundary?.type === "session.failed") return "failed";
1190
- return "completed";
1191
- }
1192
- function endsTurnSegment(event, open) {
1193
- if (event.type === "turn.waiting") return open.requests || event.data.on === "input" && !open.callbacks;
1194
- return isCurrentTurnBoundaryEvent(event) && (event.type !== "session.waiting" || !open.callbacks);
1195
- }
1196
- var TurnSegment = class {
1197
- #projection = initialSessionProjection();
1198
- #authorizations = /* @__PURE__ */ new Map();
1199
- #followCallbacks;
1200
- constructor(options = {}) {
1201
- this.#followCallbacks = options.followCallbacks === true;
1202
- }
1203
- get inputRequests() {
1204
- return openInputs(this.#projection).map((input) => input.request);
1205
- }
1206
- get pendingAuthorizations() {
1207
- return openSignIns(this.#projection).flatMap((attempt) => this.#authorizations.get(attempt.attemptId) ?? []);
1208
- }
1209
- observe(event) {
1210
- this.#projection = foldSession(this.#projection, event);
1211
- if (event.type === "authorization.required") this.#authorizations.set(event.data.attemptId ?? event.data.name, event.data);
1212
- return endsTurnSegment(event, {
1213
- callbacks: this.#followCallbacks && openSignIns(this.#projection).some((attempt) => attempt.awaitsCallback === true),
1214
- requests: openInputs(this.#projection).length > 0
1215
- });
1216
- }
1217
- };
1218
- function isFinalMessageCompleted(event) {
1219
- return event.type === "message.completed" && event.data.finishReason !== "tool-calls";
1220
- }
1221
-
1222
- //#endregion
1223
- //#region src/protocol/message-version.ts
1224
- function normalizeMessageStreamEvent(version, event) {
1225
- return nameSkillLoads(normalizeAppendEvent(version, event));
1226
- }
1227
- function normalizeAppendEvent(version, event) {
1228
- switch (version) {
1229
- case "21":
1230
- case "22":
1231
- case "23":
1232
- case "24": return normalizeLegacyMessageStreamEvent(version, event);
1233
- case "25":
1234
- case "26": return validateDeltaMessageStreamEvent(version, event);
1235
- default: return assertNever(version);
1236
- }
1237
- }
1238
- function normalizeLegacyMessageStreamEvent(version, event) {
1239
- if (event.type === "message.appended") {
1240
- assertLegacyAppendSnapshot(event.data.messageSoFar, event.data.messageDelta, "message", version);
1241
- return {
1242
- data: {
1243
- messageDelta: event.data.messageDelta,
1244
- sequence: event.data.sequence,
1245
- stepIndex: event.data.stepIndex,
1246
- turnId: event.data.turnId
1247
- },
1248
- meta: event.meta,
1249
- type: "message.appended"
1250
- };
1251
- }
1252
- if (event.type === "reasoning.appended") {
1253
- assertLegacyAppendSnapshot(event.data.reasoningSoFar, event.data.reasoningDelta, "reasoning", version);
1254
- return {
1255
- data: {
1256
- reasoningDelta: event.data.reasoningDelta,
1257
- sequence: event.data.sequence,
1258
- stepIndex: event.data.stepIndex,
1259
- turnId: event.data.turnId
1260
- },
1261
- meta: event.meta,
1262
- type: "reasoning.appended"
1263
- };
1264
- }
1265
- if (event.type === "action.input.appended") {
1266
- if (version !== void 0 && version !== "24") throw new TypeError(`Invalid action input append for stream version ${version}.`);
1267
- assertLegacyActionInputOffset(event.data.inputTextOffset, version);
1268
- return {
1269
- data: {
1270
- callId: event.data.callId,
1271
- inputTextDelta: event.data.inputTextDelta,
1272
- sequence: event.data.sequence,
1273
- stepIndex: event.data.stepIndex,
1274
- toolName: event.data.toolName,
1275
- turnId: event.data.turnId
1276
- },
1277
- meta: event.meta,
1278
- type: "action.input.appended"
1279
- };
1280
- }
1281
- return event;
1282
- }
1283
- function nameSkillLoads(event) {
1284
- if (event.type !== "actions.requested" || !event.data.actions.some(isUnnamedSkillLoad)) return event;
1285
- return {
1286
- ...event,
1287
- data: {
1288
- ...event.data,
1289
- actions: event.data.actions.map((action) => isUnnamedSkillLoad(action) ? {
1290
- ...action,
1291
- name: releasedSkillName(action)
1292
- } : action)
1293
- }
1294
- };
1295
- }
1296
- function isUnnamedSkillLoad(action) {
1297
- return action.kind === "load-skill" && typeof Reflect.get(action, "name") !== "string";
1298
- }
1299
- function releasedSkillName(action) {
1300
- const skill = action.input.skill;
1301
- return typeof skill === "string" ? skill : "load_skill";
1302
- }
1303
- function validateDeltaMessageStreamEvent(version, event) {
1304
- if (event.type === "message.appended") {
1305
- assertAppendDelta(event.data.messageDelta, "message", version);
1306
- assertUnsupportedAppendField(event.data, "messageOffset", "message", version);
1307
- assertUnsupportedAppendField(event.data, "messageSoFar", "message", version);
1308
- } else if (event.type === "reasoning.appended") {
1309
- assertAppendDelta(event.data.reasoningDelta, "reasoning", version);
1310
- assertUnsupportedAppendField(event.data, "reasoningOffset", "reasoning", version);
1311
- assertUnsupportedAppendField(event.data, "reasoningSoFar", "reasoning", version);
1312
- } else if (event.type === "action.input.appended") {
1313
- assertAppendDelta(event.data.inputTextDelta, "action input", version);
1314
- assertUnsupportedAppendField(event.data, "inputTextOffset", "action input", version);
1315
- }
1316
- return event;
1317
- }
1318
- function assertAppendDelta(delta, stream, version) {
1319
- if (typeof delta !== "string") throw new TypeError(`Invalid ${stream} append delta for stream version ${version}.`);
1320
- }
1321
- function assertUnsupportedAppendField(data, field, stream, version) {
1322
- if (field in data) throw new TypeError(`Invalid ${stream} append shape for stream version ${version}.`);
1323
- }
1324
- function assertNever(value) {
1325
- throw new TypeError(`Unsupported message stream version: ${String(value)}.`);
1326
- }
1327
- function assertLegacyActionInputOffset(offset, version) {
1328
- if (!Number.isSafeInteger(offset) || offset < 0) {
1329
- const source = version === void 0 ? "persisted stream" : `stream version ${version}`;
1330
- throw new TypeError(`Invalid action input append offset for ${source}.`);
1331
- }
1332
- }
1333
- function assertLegacyAppendSnapshot(snapshot, delta, stream, version) {
1334
- const offset = snapshot.length - delta.length;
1335
- if (offset < 0 || snapshot.slice(offset) !== delta) {
1336
- const source = version === void 0 ? "persisted stream" : `stream version ${version}`;
1337
- throw new TypeError(`Invalid cumulative ${stream} append for ${source}.`);
1338
- }
1339
- }
1340
-
1341
- //#endregion
1342
- //#region src/client/ndjson.ts
1343
- function isStreamDisconnectError(error) {
1344
- if (error instanceof DOMException) return error.name === "AbortError";
1345
- if (!(error instanceof Error)) return false;
1346
- const errorCode = "code" in error && typeof error.code === "string" ? error.code : void 0;
1347
- return error.name === "AbortError" || error.message === "terminated" || errorCode === "UND_ERR_SOCKET" || error instanceof TypeError && /^(?:failed to fetch|fetch failed|load failed|networkerror when attempting to fetch resource\.)$/i.test(error.message) || /abort|cancel|disconnect|premature close|socket|terminated/i.test(error.message);
1348
- }
1349
- async function* readNdjsonStream(body, options) {
1350
- const reader = body.getReader();
1351
- const decoder = new TextDecoder();
1352
- let buffer = "";
1353
- let reachedEof = false;
1354
- const abort = () => {
1355
- reader.cancel().catch(() => {});
1356
- };
1357
- options.signal?.addEventListener("abort", abort, { once: true });
1358
- try {
1359
- while (true) {
1360
- throwIfAborted(options.signal);
1361
- const result = await readWithIdleTimeout(reader, options?.idleTimeoutMs);
1362
- throwIfAborted(options.signal);
1363
- if (result.done) {
1364
- reachedEof = true;
1365
- buffer += decoder.decode();
1366
- break;
1367
- }
1368
- if (result.value) buffer += decoder.decode(result.value, { stream: true });
1369
- let newlineIndex = buffer.indexOf("\n");
1370
- while (newlineIndex !== -1) {
1371
- const line = buffer.slice(0, newlineIndex).trim();
1372
- buffer = buffer.slice(newlineIndex + 1);
1373
- if (line.length > 0) {
1374
- const value = JSON.parse(line);
1375
- if (options.controlVersion === "1" && isLeaseEndedControl(value)) options.onLeaseEnded?.();
1376
- else yield parseMessageStreamEvent(value, options.streamVersion);
1377
- }
1378
- newlineIndex = buffer.indexOf("\n");
1379
- }
1380
- }
1381
- const trailing = buffer.trim();
1382
- if (trailing.length > 0) {
1383
- const value = JSON.parse(trailing);
1384
- if (options.controlVersion === "1" && isLeaseEndedControl(value)) options.onLeaseEnded?.();
1385
- else yield parseMessageStreamEvent(value, options.streamVersion);
1386
- }
1387
- } finally {
1388
- options.signal?.removeEventListener("abort", abort);
1389
- if (!reachedEof) reader.cancel().catch(() => {});
1390
- reader.releaseLock();
1391
- }
1392
- }
1393
- function isLeaseEndedControl(value) {
1394
- if (value === null || typeof value !== "object") return false;
1395
- const record = value;
1396
- return record.$eve === EVE_STREAM_LEASE_ENDED_CONTROL.$eve && record.version === EVE_STREAM_LEASE_ENDED_CONTROL.version;
1397
- }
1398
- function parseMessageStreamEvent(value, version) {
1399
- return normalizeMessageStreamEvent(version, value);
1400
- }
1401
- async function readWithIdleTimeout(reader, idleTimeoutMs) {
1402
- let timeout;
1403
- try {
1404
- if (idleTimeoutMs === void 0) return await reader.read();
1405
- return await Promise.race([reader.read(), new Promise((_resolve, reject) => {
1406
- timeout = setTimeout(() => reject(new DOMException("Session stream was idle.", "AbortError")), idleTimeoutMs);
1407
- })]);
1408
- } catch (error) {
1409
- if (error instanceof TypeError) throw new Error("Session stream disconnected.", { cause: error });
1410
- throw error;
1411
- } finally {
1412
- if (timeout !== void 0) clearTimeout(timeout);
1413
- }
1414
- }
1415
-
1416
- //#endregion
1417
- //#region src/client/stream-version.ts
1418
- const supportedMessageStreamVersions = {
1419
- "21": true,
1420
- "22": true,
1421
- "23": true,
1422
- "24": true,
1423
- "25": true,
1424
- "26": true
1425
- };
1426
- function readMessageStreamVersion(headers) {
1427
- const version = headers.get(EVE_STREAM_VERSION_HEADER);
1428
- if (version !== null && Object.hasOwn(supportedMessageStreamVersions, version)) return version;
1429
- if (version === null) throw new TypeError(`Missing ${EVE_STREAM_VERSION_HEADER} response header.`);
1430
- throw new TypeError(`Unsupported message stream version: ${version}.`);
1431
- }
1432
-
1433
- //#endregion
1434
- //#region src/shared/eve-route-path.ts
1435
- const EVE_NAMED_AGENT_MOUNT_PATTERN = /^\/eve\/[a-z0-9][a-z0-9_-]*$/;
1436
- const EVE_NAMED_AGENT_PROTOCOL_PATTERN = /^\/eve\/[a-z0-9][a-z0-9_-]*\/v1$/;
1437
- function joinEveRoutePath(basePath, routePath) {
1438
- const base = trimTrailingSlash$1(basePath);
1439
- const route = routePath.startsWith("/") ? routePath : `/${routePath}`;
1440
- if (route === "/eve/v1" || route.startsWith(`${"/eve/v1"}/`)) {
1441
- if (EVE_NAMED_AGENT_MOUNT_PATTERN.test(base)) return `${base}${route.slice(4)}`;
1442
- if (EVE_NAMED_AGENT_PROTOCOL_PATTERN.test(base)) return `${base}${route.slice(EVE_ROUTE_PREFIX.length)}`;
1443
- }
1444
- return `${base}${route}`;
1445
- }
1446
- function trimTrailingSlash$1(value) {
1447
- if (value === "/") return "";
1448
- return value.endsWith("/") ? value.slice(0, -1) : value;
1449
- }
1450
-
1451
- //#endregion
1452
- //#region src/client/url.ts
1453
- function createClientUrl(host, routePath, searchParams) {
1454
- const queryIndex = routePath.indexOf("?");
1455
- const pathOnly = queryIndex === -1 ? routePath : routePath.slice(0, queryIndex);
1456
- const embeddedQuery = queryIndex === -1 ? "" : routePath.slice(queryIndex + 1);
1457
- const normalizedRoute = pathOnly.startsWith("/") ? pathOnly : `/${pathOnly}`;
1458
- if (isAbsoluteUrl(host)) {
1459
- const url = new URL(host);
1460
- const basePath = trimTrailingSlash(url.pathname);
1461
- url.pathname = joinEveRoutePath(basePath, normalizedRoute);
1462
- mergeEmbeddedQuery(url.searchParams, embeddedQuery);
1463
- mergeSearchParams(url.searchParams, searchParams);
1464
- url.hash = "";
1465
- return url.toString();
1466
- }
1467
- const url = new URL(host, "http://eve.local");
1468
- const basePath = trimTrailingSlash(url.pathname);
1469
- mergeEmbeddedQuery(url.searchParams, embeddedQuery);
1470
- mergeSearchParams(url.searchParams, searchParams);
1471
- return `${joinEveRoutePath(basePath, normalizedRoute)}${formatSearch(url.searchParams)}`;
1472
- }
1473
- function mergeEmbeddedQuery(target, embeddedQuery) {
1474
- if (embeddedQuery.length === 0) return;
1475
- for (const [name, value] of new URLSearchParams(embeddedQuery)) target.append(name, value);
1476
- }
1477
- function isAbsoluteUrl(value) {
1478
- return /^[a-z][a-z\d+\-.]*:/i.test(value);
1479
- }
1480
- function trimTrailingSlash(value) {
1481
- if (value === "/") return "";
1482
- return value.endsWith("/") ? value.slice(0, -1) : value;
1483
- }
1484
- function mergeSearchParams(target, searchParams) {
1485
- if (searchParams === void 0) return;
1486
- for (const [name, value] of Object.entries(searchParams)) target.set(name, value);
1487
- }
1488
- function formatSearch(searchParams) {
1489
- const value = searchParams.toString();
1490
- return value.length === 0 ? "" : `?${value}`;
1491
- }
1492
-
1493
- //#endregion
1494
- //#region src/client/open-stream.ts
1495
- const DEFAULT_STREAM_READ_IDLE_TIMEOUT_MS = 15e3;
1496
- const DEFAULT_STREAM_RECONNECT_POLICY = {
1497
- retryableErrorStatuses: /* @__PURE__ */ new Set([
1498
- 404,
1499
- 409,
1500
- 425,
1501
- 500,
1502
- 502,
1503
- 503,
1504
- 504
1505
- ]),
1506
- streamIdleReconnectPolicy: {
1507
- baseDelayMs: 250,
1508
- maxAttempts: 5,
1509
- maxDelayMs: 4e3
1510
- },
1511
- streamOpenReconnectPolicy: {
1512
- baseDelayMs: 250,
1513
- maxAttempts: 12,
1514
- maxDelayMs: 5e3
1515
- }
1516
- };
1517
- const NO_STREAM_RECONNECT_POLICY = {
1518
- ...DEFAULT_STREAM_RECONNECT_POLICY,
1519
- streamIdleReconnectPolicy: {
1520
- ...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,
1521
- maxAttempts: 0
1522
- },
1523
- streamOpenReconnectPolicy: {
1524
- ...DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy,
1525
- maxAttempts: 1
1526
- }
1527
- };
1528
- function resolveRetryPolicy(policy, defaults) {
1529
- return {
1530
- ...defaults,
1531
- ...policy
1532
- };
1533
- }
1534
- function resolveStreamReconnectPolicy(policy, keepAlive = false) {
1535
- if (policy && "reconnect" in policy && policy.reconnect === false) return NO_STREAM_RECONNECT_POLICY;
1536
- const configured = policy;
1537
- return {
1538
- retryableErrorStatuses: configured?.retryableErrorStatuses ? new Set(configured.retryableErrorStatuses) : DEFAULT_STREAM_RECONNECT_POLICY.retryableErrorStatuses,
1539
- streamIdleReconnectPolicy: resolveRetryPolicy(configured?.streamIdleReconnectPolicy, {
1540
- ...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,
1541
- maxAttempts: keepAlive ? Infinity : DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy.maxAttempts
1542
- }),
1543
- streamOpenReconnectPolicy: resolveRetryPolicy(configured?.streamOpenReconnectPolicy, DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy)
1544
- };
1545
- }
1546
- async function* followStreamIterable(input) {
1547
- if (input.follow === false && input.startIndex < 0) throw new Error("stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.");
1548
- const resolvePolicy = () => resolveStreamReconnectPolicy(input.resolveReconnectPolicy === void 0 ? input.streamReconnectPolicy : input.resolveReconnectPolicy(), input.keepAlive);
1549
- let retryPolicy = resolvePolicy();
1550
- let idleRetryPolicy = retryPolicy.streamIdleReconnectPolicy;
1551
- let startIndex = input.startIndex;
1552
- let reconnectDelayMs = idleRetryPolicy.baseDelayMs;
1553
- let idleReconnects = 0;
1554
- let initialConnection = true;
1555
- let tailIndex;
1556
- let caughtUp = false;
1557
- while (true) {
1558
- retryPolicy = resolvePolicy();
1559
- idleRetryPolicy = retryPolicy.streamIdleReconnectPolicy;
1560
- let connection;
1561
- try {
1562
- connection = await openStreamBody({
1563
- ...input,
1564
- retryPolicy,
1565
- startIndex,
1566
- requestTailIndex: (input.follow === false || input.onCaughtUp !== void 0) && tailIndex === void 0
1567
- });
1568
- } catch (error) {
1569
- if (input.signal?.aborted) return;
1570
- throw error;
1571
- }
1572
- if ((input.follow === false || input.onCaughtUp !== void 0) && tailIndex === void 0) {
1573
- tailIndex = connection.tailIndex;
1574
- if (tailIndex === void 0) {
1575
- connection.close();
1576
- throw new Error(`stream({ follow: false }) requires the server to report the ${EVE_STREAM_TAIL_INDEX_HEADER} header. The agent may be running an older eve version.`);
1577
- }
1578
- }
1579
- if (!caughtUp && tailIndex !== void 0 && startIndex > tailIndex) {
1580
- caughtUp = true;
1581
- input.onCaughtUp?.();
1582
- }
1583
- if (input.follow === false && tailIndex !== void 0 && startIndex > tailIndex) {
1584
- connection.close();
1585
- return;
1586
- }
1587
- let deliveredEvent = false;
1588
- let leaseEnded = false;
1589
- try {
1590
- for await (const event of readNdjsonStream(connection.body, {
1591
- signal: input.signal,
1592
- controlVersion: connection.controlVersion,
1593
- idleTimeoutMs: input.streamReadIdleTimeoutMs ?? DEFAULT_STREAM_READ_IDLE_TIMEOUT_MS,
1594
- onLeaseEnded: () => {
1595
- leaseEnded = true;
1596
- },
1597
- streamVersion: connection.streamVersion
1598
- })) {
1599
- startIndex += 1;
1600
- deliveredEvent = true;
1601
- reconnectDelayMs = idleRetryPolicy.baseDelayMs;
1602
- idleReconnects = 0;
1603
- yield event;
1604
- if (!caughtUp && tailIndex !== void 0 && startIndex > tailIndex) {
1605
- caughtUp = true;
1606
- input.onCaughtUp?.();
1607
- }
1608
- if (event.type === "session.failed" || event.type === "session.completed") return;
1609
- if (input.follow === false && tailIndex !== void 0 && startIndex > tailIndex) return;
1610
- }
1611
- } catch (error) {
1612
- if (!isStreamDisconnectError(error)) throw error;
1613
- } finally {
1614
- connection.close();
1615
- }
1616
- idleRetryPolicy = resolvePolicy().streamIdleReconnectPolicy;
1617
- if (input.signal?.aborted || input.startIndex < 0 || idleRetryPolicy.maxAttempts === 0) return;
1618
- if (leaseEnded) continue;
1619
- if (!deliveredEvent && !initialConnection && (idleReconnects += 1) >= idleRetryPolicy.maxAttempts) return;
1620
- initialConnection = false;
1621
- await sleep(reconnectDelayMs, input.signal);
1622
- if (input.signal?.aborted) return;
1623
- reconnectDelayMs = Math.min(reconnectDelayMs * 2, idleRetryPolicy.maxDelayMs);
1624
- }
1625
- }
1626
- async function openStreamBody(input) {
1627
- const retryPolicy = input.retryPolicy ?? resolveStreamReconnectPolicy(input.streamReconnectPolicy, input.keepAlive);
1628
- const openRetryPolicy = retryPolicy.streamOpenReconnectPolicy;
1629
- let lastStatus;
1630
- let lastBody;
1631
- let lastHeaders;
1632
- let retryDelayMs = openRetryPolicy.baseDelayMs;
1633
- const controlVersion = input.startIndex >= 0 && retryPolicy.streamIdleReconnectPolicy.maxAttempts > 0 ? "1" : void 0;
1634
- const searchParams = {};
1635
- if (controlVersion !== void 0) searchParams[EVE_STREAM_CONTROL_VERSION_QUERY] = controlVersion;
1636
- if (input.startIndex !== 0) searchParams.startIndex = String(input.startIndex);
1637
- if (input.requestTailIndex === true) searchParams.includeTailIndex = "1";
1638
- if (input.follow === false) searchParams.follow = "false";
1639
- for (let attempt = 0; attempt < openRetryPolicy.maxAttempts; attempt += 1) {
1640
- throwIfAborted(input.signal);
1641
- const url = createClientUrl(input.host, input.path, Object.keys(searchParams).length > 0 ? searchParams : void 0);
1642
- const headers = await input.resolveHeaders();
1643
- throwIfAborted(input.signal);
1644
- const connectionController = new AbortController();
1645
- const signal = input.signal ? AbortSignal.any([input.signal, connectionController.signal]) : connectionController.signal;
1646
- let response;
1647
- try {
1648
- response = await fetch(url, {
1649
- cache: "no-store",
1650
- headers,
1651
- redirect: input.redirect,
1652
- signal
1653
- });
1654
- } catch (error) {
1655
- if (input.signal?.aborted || !isStreamDisconnectError(error) || attempt === openRetryPolicy.maxAttempts - 1) throw error;
1656
- await sleep(retryDelayMs, input.signal);
1657
- retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
1658
- continue;
1659
- }
1660
- if (response.ok) {
1661
- if (!response.body) throw new ClientError(response.status, "Response body is null.", response.headers);
1662
- let closed = false;
1663
- return {
1664
- body: response.body,
1665
- close: () => {
1666
- if (closed) return;
1667
- closed = true;
1668
- response.body?.cancel().catch(() => {});
1669
- connectionController.abort();
1670
- },
1671
- controlVersion,
1672
- streamVersion: readMessageStreamVersion(response.headers),
1673
- tailIndex: parseTailIndexHeader(response.headers)
1674
- };
1675
- }
1676
- lastStatus = response.status;
1677
- lastBody = await response.text();
1678
- lastHeaders = response.headers;
1679
- const error = createClientError(response.status, lastBody, response.headers);
1680
- if (error instanceof ClientSessionStrandedError || !retryPolicy.retryableErrorStatuses.has(response.status)) throw error;
1681
- if (attempt < openRetryPolicy.maxAttempts - 1) {
1682
- await sleep(retryDelayMs, input.signal);
1683
- retryDelayMs = Math.min(retryDelayMs * 2, openRetryPolicy.maxDelayMs);
1684
- }
1685
- }
1686
- throw new ClientError(lastStatus ?? 0, lastBody ?? "Failed to open message stream.", lastHeaders);
1687
- }
1688
- function parseTailIndexHeader(headers) {
1689
- const raw = headers.get(EVE_STREAM_TAIL_INDEX_HEADER);
1690
- if (raw === null || !/^-?\d+$/.test(raw)) return;
1691
- const parsed = Number(raw);
1692
- return Number.isSafeInteger(parsed) ? parsed : void 0;
1693
- }
1694
- async function sleep(ms, signal) {
1695
- if (signal?.aborted) return;
1696
- await new Promise((resolve) => {
1697
- const onAbort = () => {
1698
- clearTimeout(timer);
1699
- resolve();
1700
- };
1701
- const timer = setTimeout(() => {
1702
- signal?.removeEventListener("abort", onAbort);
1703
- resolve();
1704
- }, ms);
1705
- signal?.addEventListener("abort", onAbort, { once: true });
1706
- });
1707
- }
1708
-
1709
- //#endregion
1710
- //#region src/client/agent-session.ts
1711
- var ClientAgentSession = class {
1712
- name;
1713
- sessionId;
1714
- taskId;
1715
- #context;
1716
- #streamPath;
1717
- constructor(context, started) {
1718
- this.#context = context;
1719
- this.#streamPath = started.data.streamPath;
1720
- this.name = started.data.name;
1721
- this.sessionId = started.data.sessionId;
1722
- this.taskId = started.data.taskId;
1723
- }
1724
- stream(options) {
1725
- const startIndex = options?.startIndex ?? 0;
1726
- if (options?.follow === false && startIndex < 0) throw new Error("agent(started).stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.");
1727
- return followStreamIterable({
1728
- follow: options?.follow,
1729
- host: this.#context.host,
1730
- path: this.#streamPath,
1731
- redirect: this.#context.redirect,
1732
- resolveHeaders: () => this.#context.resolveHeaders(),
1733
- signal: options?.signal,
1734
- startIndex,
1735
- streamReconnectPolicy: options?.streamReconnectPolicy
1736
- });
1737
- }
1738
- };
1739
-
1740
- //#endregion
1741
- //#region src/client/output-schema.ts
1742
- function extractCompletedResult(events) {
1743
- let result;
1744
- for (const event of events) if (isResultCompletedEvent(event)) result = event.data.result;
1745
- return result;
1746
- }
1747
- function isResultCompletedEvent(event) {
1748
- return event.type === "result.completed";
1749
- }
1750
-
1751
- //#endregion
1752
- //#region src/client/message-response.ts
1753
- const consumeResponse = Symbol("consumeMessageResponse");
1754
- const acceptedDeliveryId = Symbol("acceptedDeliveryId");
1755
- const sendReceipt = Symbol("sendReceipt");
1756
- var MessageResponse = class {
1757
- sessionId;
1758
- [acceptedDeliveryId];
1759
- [sendReceipt];
1760
- #cancelTurn;
1761
- #cancellation;
1762
- #consumed = false;
1763
- #createStream;
1764
- #resumesTurn;
1765
- #settled = false;
1766
- #turnId = Promise.withResolvers();
1767
- constructor(input) {
1768
- this.#cancelTurn = input.cancelTurn;
1769
- this.sessionId = input.sessionId;
1770
- this[acceptedDeliveryId] = input.deliveryId;
1771
- this[sendReceipt] = input.receipt;
1772
- this.#createStream = input.createStream;
1773
- this.#resumesTurn = input.resumesTurn ?? false;
1774
- }
1775
- cancel() {
1776
- if (this.#settled) return Promise.resolve({ status: "no_active_turn" });
1777
- if (this.#cancellation !== void 0) return this.#cancellation;
1778
- const cancellation = this.#turnId.promise.then((turnId) => turnId === void 0 ? { status: "no_active_turn" } : this.#cancelTurn(turnId));
1779
- this.#cancellation = cancellation;
1780
- cancellation.catch(() => {
1781
- if (!this.#settled && this.#cancellation === cancellation) this.#cancellation = void 0;
1782
- });
1783
- return cancellation;
1784
- }
1785
- async result() {
1786
- const events = [];
1787
- for await (const event of this) events.push(event);
1788
- const summary = summarizeTurnEvents(events);
1789
- return {
1790
- data: extractCompletedResult(events),
1791
- events,
1792
- inputRequests: summary.inputRequests,
1793
- message: summary.message,
1794
- sessionId: this.sessionId,
1795
- status: summary.status
1796
- };
1797
- }
1798
- [Symbol.asyncIterator]() {
1799
- return this[consumeResponse]();
1800
- }
1801
- [consumeResponse](source) {
1802
- if (this.#consumed) throw new Error("MessageResponse has already been consumed.");
1803
- this.#consumed = true;
1804
- return this.#observeStream(source);
1805
- }
1806
- async *#observeStream(source) {
1807
- try {
1808
- for await (const event of this.#createStream(source)) {
1809
- if (event.type === "turn.started" || this.#resumesTurn && event.type === "input.resolved") this.#turnId.resolve(event.data.turnId);
1810
- else if (isCurrentTurnBoundaryEvent(event)) {
1811
- this.#settled = true;
1812
- this.#turnId.resolve(void 0);
1813
- }
1814
- yield event;
1815
- }
1816
- } finally {
1817
- this.#turnId.resolve(void 0);
1818
- }
1819
- }
1820
- };
1821
- function getMessageResponseDeliveryId(response) {
1822
- return response[acceptedDeliveryId];
1823
- }
1824
- function consumeMessageResponse(response, source) {
1825
- return response[consumeResponse](source);
1826
- }
1827
-
1828
- //#endregion
1829
- //#region src/protocol/prewarm-session.ts
1830
- const PrewarmResponseSchema = z.object({
1831
- ok: z.literal(true),
1832
- status: z.enum([
1833
- "ready",
1834
- "accepted",
1835
- "unsupported",
1836
- "no_active_session"
1837
- ])
1838
- });
1839
-
1840
- //#endregion
1841
- //#region src/protocol/cancel-turn.ts
1842
- const CancelTurnResponseSchema = z.discriminatedUnion("status", [z.strictObject({
1843
- ok: z.literal(true),
1844
- sessionId: z.string().min(1),
1845
- status: z.literal("accepted")
1846
- }), z.strictObject({
1847
- ok: z.literal(true),
1848
- status: z.literal("no_active_turn")
1849
- })]);
1850
-
1851
- //#endregion
1852
- //#region src/protocol/clear-session.ts
1853
- const ClearResponseSchema = z.discriminatedUnion("status", [z.object({
1854
- ok: z.literal(true),
1855
- sessionId: z.string().min(1),
1856
- status: z.literal("accepted")
1857
- }), z.object({
1858
- ok: z.literal(true),
1859
- status: z.literal("no_active_session")
1860
- })]);
1861
-
1862
- //#endregion
1863
- //#region src/protocol/compact-session.ts
1864
- const CompactResponseSchema = z.discriminatedUnion("status", [z.object({
1865
- ok: z.literal(true),
1866
- sessionId: z.string().min(1),
1867
- status: z.literal("accepted")
1868
- }), z.object({
1869
- ok: z.literal(true),
1870
- status: z.literal("no_active_session")
1871
- })]);
1872
-
1873
- //#endregion
1874
- //#region src/protocol/reset-session.ts
1875
- const ResetResponseSchema = z.discriminatedUnion("status", [z.object({
1876
- ok: z.literal(true),
1877
- previousSessionId: z.string().min(1),
1878
- status: z.literal("reset")
1879
- }), z.object({
1880
- ok: z.literal(true),
1881
- status: z.literal("no_active_session")
1882
- })]);
1883
-
1884
- //#endregion
1885
- //#region src/client/session-controls.ts
1886
- async function prewarmClientSession(input) {
1887
- const { payload } = await postJson({
1888
- context: input.context,
1889
- operation: "Prewarm",
1890
- path: createEveSessionRoutePath(input.sessionId),
1891
- signal: input.signal
1892
- });
1893
- const result = PrewarmResponseSchema.safeParse(payload);
1894
- if (!result.success) throw new Error("Prewarm route returned an invalid response.");
1895
- return { status: result.data.status };
1896
- }
1897
- async function cancelClientSession(input) {
1898
- const { signal, ...body } = input.options ?? {};
1899
- const { payload, response } = await postJson({
1900
- body,
1901
- context: input.context,
1902
- operation: "Cancel",
1903
- path: createEveSessionCancelRoutePath(input.sessionId),
1904
- signal
1905
- });
1906
- const result = CancelTurnResponseSchema.safeParse(payload);
1907
- if (!result.success || result.data.status === "accepted" && result.data.sessionId !== input.sessionId) throw new Error(`Cancel route returned an invalid response (${response.status}).`);
1908
- return result.data.status === "accepted" ? {
1909
- sessionId: result.data.sessionId,
1910
- status: "accepted"
1911
- } : { status: "no_active_turn" };
1912
- }
1913
- async function clearClientSession(input) {
1914
- const { payload } = await postJson({
1915
- context: input.context,
1916
- operation: "Clear",
1917
- path: createEveSessionClearRoutePath(input.sessionId)
1918
- });
1919
- const result = ClearResponseSchema.safeParse(payload);
1920
- if (!result.success || result.data.status === "accepted" && result.data.sessionId !== input.sessionId) throw new Error("Clear route returned an invalid response.");
1921
- return result.data.status === "accepted" ? {
1922
- sessionId: result.data.sessionId,
1923
- status: "accepted"
1924
- } : { status: "no_active_session" };
1925
- }
1926
- async function compactClientSession(input) {
1927
- const { payload } = await postJson({
1928
- context: input.context,
1929
- operation: "Compact",
1930
- path: createEveSessionCompactRoutePath(input.sessionId)
1931
- });
1932
- const result = CompactResponseSchema.safeParse(payload);
1933
- if (!result.success || result.data.status === "accepted" && result.data.sessionId !== input.sessionId) throw new Error("Compact route returned an invalid response.");
1934
- return result.data.status === "accepted" ? {
1935
- sessionId: result.data.sessionId,
1936
- status: "accepted"
1937
- } : { status: "no_active_session" };
1938
- }
1939
- async function resetClientSession(input) {
1940
- const { signal, ...body } = input.options ?? {};
1941
- const { payload } = await postJson({
1942
- body,
1943
- context: input.context,
1944
- operation: "Reset",
1945
- path: createEveSessionResetRoutePath(input.sessionId),
1946
- signal
1947
- });
1948
- const result = ResetResponseSchema.safeParse(payload);
1949
- if (!result.success || result.data.status === "reset" && result.data.previousSessionId !== input.sessionId) throw new Error("Reset route returned an invalid response.");
1950
- return result.data.status === "reset" ? {
1951
- previousSessionId: result.data.previousSessionId,
1952
- status: "reset"
1953
- } : { status: "no_active_session" };
1954
- }
1955
- async function postJson(input) {
1956
- const headers = await input.context.resolveHeaders();
1957
- headers.set("content-type", "application/json");
1958
- const response = await fetch(createClientUrl(input.context.host, input.path), withRedirectPolicy$1({
1959
- body: input.body === void 0 ? void 0 : JSON.stringify(input.body),
1960
- headers,
1961
- method: "POST",
1962
- signal: input.signal
1963
- }, input.context.redirect));
1964
- const text = await response.text();
1965
- if (!response.ok) throw createClientError(response.status, text, response.headers);
1966
- try {
1967
- return {
1968
- payload: JSON.parse(text),
1969
- response
1970
- };
1971
- } catch {
1972
- throw new Error(`${input.operation} route returned invalid JSON (${response.status}).`);
1973
- }
1974
- }
1975
- function withRedirectPolicy$1(init, redirect) {
1976
- return redirect === void 0 ? init : {
1977
- ...init,
1978
- redirect
1979
- };
1980
- }
1981
-
1982
- //#endregion
1983
- //#region src/shared/errors.ts
1984
- function toErrorMessage(error) {
1985
- if (error instanceof Error) return error.message;
1986
- if (typeof error === "string") return error;
1987
- if (error === null || error === void 0) return String(error);
1988
- if (isObject(error)) {
1989
- if (typeof error.message === "string" && error.message.length > 0) return error.message;
1990
- return safeJsonStringify(error);
1991
- }
1992
- return String(error);
1993
- }
1994
- function toError(raw) {
1995
- if (raw instanceof Error) return raw;
1996
- const error = new Error(toErrorMessage(raw));
1997
- if (!isObject(raw)) return error;
1998
- if (typeof raw.name === "string" && raw.name.length > 0) error.name = raw.name;
1999
- if (typeof raw.stack === "string" && raw.stack.length > 0) error.stack = raw.stack;
2000
- if ("cause" in raw && raw.cause !== void 0 && raw.cause !== raw) error.cause = raw.cause;
2001
- return error;
2002
- }
2003
- function safeJsonStringify(value) {
2004
- try {
2005
- return JSON.stringify(value) ?? String(value);
2006
- } catch {
2007
- return String(value);
2008
- }
2009
- }
2010
-
2011
- //#endregion
2012
- //#region src/shared/json.ts
2013
- const INVALID_JSON_VALUE_CANDIDATE = Symbol("invalid-json-value-candidate");
2014
- const JSON_VALUE_ERROR_MESSAGE = "Expected a JSON-serializable value.";
2015
- const JSON_OBJECT_ERROR_MESSAGE = "Expected a JSON-serializable object.";
2016
- function parseJsonValue(value) {
2017
- const normalized = normalizeJsonValueCandidate(value);
2018
- if (normalized === INVALID_JSON_VALUE_CANDIDATE) throw new TypeError(JSON_VALUE_ERROR_MESSAGE);
2019
- return normalized;
2020
- }
2021
- function parseJsonObject(value) {
2022
- const normalized = parseJsonValue(value);
2023
- if (!isJsonObjectValue(normalized)) throw new TypeError(JSON_OBJECT_ERROR_MESSAGE);
2024
- return normalized;
2025
- }
2026
- function normalizeJsonValueCandidate(value, seen = /* @__PURE__ */ new WeakSet()) {
2027
- if (value === null || typeof value === "boolean" || typeof value === "string") return value;
2028
- if (typeof value === "number") return Number.isFinite(value) ? value : INVALID_JSON_VALUE_CANDIDATE;
2029
- if (Array.isArray(value)) {
2030
- const normalizedItems = [];
2031
- for (const item of value) {
2032
- const normalizedItem = normalizeJsonValueCandidate(item, seen);
2033
- if (normalizedItem === INVALID_JSON_VALUE_CANDIDATE) return INVALID_JSON_VALUE_CANDIDATE;
2034
- normalizedItems.push(normalizedItem);
2035
- }
2036
- return normalizedItems;
2037
- }
2038
- if (typeof value !== "object" || value === void 0) return INVALID_JSON_VALUE_CANDIDATE;
2039
- if (!isPlainObject(value)) return INVALID_JSON_VALUE_CANDIDATE;
2040
- if (seen.has(value)) return INVALID_JSON_VALUE_CANDIDATE;
2041
- seen.add(value);
2042
- const normalized = {};
2043
- for (const [key, entry] of Object.entries(value)) {
2044
- if (entry === void 0) continue;
2045
- const normalizedEntry = normalizeJsonValueCandidate(entry, seen);
2046
- if (normalizedEntry === INVALID_JSON_VALUE_CANDIDATE) return INVALID_JSON_VALUE_CANDIDATE;
2047
- normalized[key] = normalizedEntry;
2048
- }
2049
- seen.delete(value);
2050
- return normalized;
2051
- }
2052
- function isJsonObjectValue(value) {
2053
- return value !== null && !Array.isArray(value) && typeof value === "object";
2054
- }
2055
- function isPlainObject(value) {
2056
- const prototype = Object.getPrototypeOf(value);
2057
- return prototype === null || Object.getPrototypeOf(prototype) === null;
2058
- }
2059
-
2060
- //#endregion
2061
- //#region src/tools/schema-emission.ts
2062
- const JSON_SCHEMA_TARGET = "draft-07";
2063
- function serializeOutputSchema(source) {
2064
- if (source === null || source === void 0) return source;
2065
- return emitJsonSchema(source, "output");
2066
- }
2067
- function emitJsonSchema(source, direction) {
2068
- const standard = getStandardSchemaProperties(source);
2069
- if (standard === void 0) return withoutSchemaVersion(parseJsonObject(source));
2070
- const emit = readJsonSchemaEmitter(standard, direction);
2071
- if (emit === void 0) throw new Error(describeMissingEmitter(standard));
2072
- return withoutSchemaVersion(parseJsonObject(emit({ target: JSON_SCHEMA_TARGET })));
2073
- }
2074
- function readJsonSchemaEmitter(standard, direction) {
2075
- const jsonSchema = standard.jsonSchema;
2076
- if (typeof jsonSchema !== "object" || jsonSchema === null) return void 0;
2077
- const emit = jsonSchema[direction];
2078
- return typeof emit === "function" ? emit : void 0;
2079
- }
2080
- function getStandardSchemaProperties(value) {
2081
- if (typeof value !== "object" || value === null || !("~standard" in value)) return void 0;
2082
- const standard = value["~standard"];
2083
- return typeof standard === "object" && standard !== null ? standard : void 0;
2084
- }
2085
- function describeMissingEmitter(standard) {
2086
- const vendor = typeof standard.vendor === "string" ? standard.vendor : "unknown";
2087
- if (vendor === "zod") return "Zod 3 cannot emit an output JSON Schema. Upgrade to Zod 4 or provide a plain JSON Schema object.";
2088
- return `Standard Schema vendor "${vendor}" does not support JSON Schema conversion. Provide a Standard Schema implementation with JSON Schema conversion or a plain JSON Schema object.`;
2089
- }
2090
- function withoutSchemaVersion(schema) {
2091
- const { $schema: _schemaVersion, ...canonical } = schema;
2092
- return canonical;
2093
- }
2094
-
2095
- //#endregion
2096
- //#region src/tools/schema.ts
2097
- function defineJsonSchema(schema, check) {
2098
- const emit = () => structuredClone(schema);
2099
- const toolSchema = { "~standard": {
2100
- version: 1,
2101
- vendor: "eve",
2102
- validate: createJsonSchemaValidator(schema, check),
2103
- jsonSchema: {
2104
- input: emit,
2105
- output: emit
2106
- }
2107
- } };
2108
- plainJsonSchemas.add(toolSchema);
2109
- return toolSchema;
2110
- }
2111
- const plainJsonSchemas = /* @__PURE__ */ new WeakSet();
2112
- const UNSPECIFIED_INPUT_SCHEMA = defineJsonSchema({});
2113
- function createJsonSchemaValidator(schema, check) {
2114
- let validator;
2115
- let warned = false;
2116
- const passThrough = (value, reason) => {
2117
- if (!warned) {
2118
- warned = true;
2119
- console.warn(`[eve] Tool schema cannot validate values locally; passing them through unvalidated: ${reason}`);
2120
- }
2121
- return { value };
2122
- };
2123
- return (value) => {
2124
- if (validator === void 0) {
2125
- const built = buildValidator(schema);
2126
- if (typeof built === "string") {
2127
- validator = null;
2128
- return passThrough(value, built);
2129
- }
2130
- validator = built;
2131
- }
2132
- if (validator === null) return { value };
2133
- let result;
2134
- try {
2135
- result = validator.validate(value);
2136
- } catch (error) {
2137
- if (value === void 0) return { issues: [{ message: "Expected a JSON value." }] };
2138
- return passThrough(value, toErrorMessage(error));
2139
- }
2140
- if (!result.valid) return { issues: toIssues(result.errors) };
2141
- const filled = applyDefaults(schema, schema, value);
2142
- const message = check?.(filled);
2143
- return message === void 0 ? { value: filled } : { issues: [{ message }] };
2144
- };
2145
- }
2146
- function applyDefaults(root, schema, value) {
2147
- let result = value;
2148
- for (const node of followRefs(root, schema)) {
2149
- const { items, properties } = node;
2150
- if (isObject(result) && isObject(properties)) result = fillProperties(root, properties, result);
2151
- else if (Array.isArray(result) && isObject(items)) {
2152
- const list = result;
2153
- const next = list.map((item) => applyDefaults(root, items, item));
2154
- if (next.some((item, index) => item !== list[index])) result = next;
2155
- }
2156
- }
2157
- return result;
2158
- }
2159
- function fillProperties(root, properties, value) {
2160
- let result = value;
2161
- for (const [key, property] of Object.entries(properties)) {
2162
- const current = Object.hasOwn(value, key) ? value[key] : void 0;
2163
- const next = current === void 0 ? findDefault(root, property) : applyDefaults(root, property, current);
2164
- if (next === current) continue;
2165
- if (result === value) result = { ...value };
2166
- result[key] = next;
2167
- }
2168
- return result;
2169
- }
2170
- function findDefault(root, schema) {
2171
- for (const node of followRefs(root, schema)) if ("default" in node) return structuredClone(node.default);
2172
- }
2173
- function* followRefs(root, schema) {
2174
- const seen = /* @__PURE__ */ new Set();
2175
- let node = schema;
2176
- while (isObject(node) && !seen.has(node)) {
2177
- seen.add(node);
2178
- yield node;
2179
- node = resolveLocalRef(root, node.$ref);
2180
- }
2181
- }
2182
- function resolveLocalRef(root, ref) {
2183
- if (typeof ref !== "string" || ref !== "#" && !ref.startsWith("#/")) return void 0;
2184
- let node = root;
2185
- for (const segment of decodePointer(ref)) {
2186
- if (typeof node !== "object" || node === null || !Object.hasOwn(node, segment)) return;
2187
- node = node[segment];
2188
- }
2189
- return node;
2190
- }
2191
- function buildValidator(schema) {
2192
- try {
2193
- const copy = structuredClone(schema);
2194
- return prepareForValidation(copy) ?? new Validator(copy, "2020-12", false);
2195
- } catch (error) {
2196
- return toErrorMessage(error);
2197
- }
2198
- }
2199
- const JSON_TYPES = /* @__PURE__ */ new Set([
2200
- "array",
2201
- "boolean",
2202
- "integer",
2203
- "null",
2204
- "number",
2205
- "object",
2206
- "string"
2207
- ]);
2208
- const EXCLUSIVE_BOUNDS = [["exclusiveMinimum", "minimum"], ["exclusiveMaximum", "maximum"]];
2209
- const SUBSCHEMA_KEYWORDS = [
2210
- "additionalItems",
2211
- "additionalProperties",
2212
- "contains",
2213
- "else",
2214
- "if",
2215
- "not",
2216
- "propertyNames",
2217
- "then",
2218
- "unevaluatedItems",
2219
- "unevaluatedProperties"
2220
- ];
2221
- const SUBSCHEMA_LIST_KEYWORDS = [
2222
- "allOf",
2223
- "anyOf",
2224
- "oneOf",
2225
- "prefixItems"
2226
- ];
2227
- const SUBSCHEMA_MAP_KEYWORDS = [
2228
- "$defs",
2229
- "definitions",
2230
- "dependencies",
2231
- "dependentSchemas",
2232
- "patternProperties",
2233
- "properties"
2234
- ];
2235
- function prepareForValidation(schema) {
2236
- if (typeof schema === "boolean") return void 0;
2237
- if (typeof schema !== "object" || schema === null || Array.isArray(schema)) return "a subschema is neither an object nor a boolean";
2238
- const node = schema;
2239
- delete node.format;
2240
- for (const [flag, bound] of EXCLUSIVE_BOUNDS) {
2241
- if (typeof node[flag] !== "boolean") continue;
2242
- if (node[flag] && typeof node[bound] === "number") {
2243
- node[flag] = node[bound];
2244
- delete node[bound];
2245
- } else delete node[flag];
2246
- }
2247
- const { enum: values, pattern, required, type } = node;
2248
- if (type !== void 0 && !(Array.isArray(type) ? type.every(isJsonType) : isJsonType(type))) return `unsupported type ${JSON.stringify(type)}`;
2249
- if (values !== void 0 && !Array.isArray(values)) return "`enum` is not an array";
2250
- if (required !== void 0 && !(Array.isArray(required) && required.every((key) => typeof key === "string"))) return "`required` is not an array of strings";
2251
- if (pattern !== void 0 && !isRegExpSource(pattern)) return `invalid pattern ${JSON.stringify(pattern)}`;
2252
- for (const keyword of SUBSCHEMA_KEYWORDS) if (keyword in node) {
2253
- const problem = prepareForValidation(node[keyword]);
2254
- if (problem !== void 0) return problem;
2255
- }
2256
- const items = node.items;
2257
- for (const subschema of Array.isArray(items) ? items : items === void 0 ? [] : [items]) {
2258
- const problem = prepareForValidation(subschema);
2259
- if (problem !== void 0) return problem;
2260
- }
2261
- for (const keyword of SUBSCHEMA_LIST_KEYWORDS) {
2262
- const list = node[keyword];
2263
- if (list === void 0) continue;
2264
- if (!Array.isArray(list)) return `\`${keyword}\` is not an array`;
2265
- for (const subschema of list) {
2266
- const problem = prepareForValidation(subschema);
2267
- if (problem !== void 0) return problem;
2268
- }
2269
- }
2270
- for (const keyword of SUBSCHEMA_MAP_KEYWORDS) {
2271
- const map = node[keyword];
2272
- if (map === void 0) continue;
2273
- if (typeof map !== "object" || map === null || Array.isArray(map)) return `\`${keyword}\` is not an object`;
2274
- for (const [key, subschema] of Object.entries(map)) {
2275
- if (keyword === "patternProperties" && !isRegExpSource(key)) return `invalid pattern ${JSON.stringify(key)}`;
2276
- if (keyword === "dependencies" && Array.isArray(subschema)) continue;
2277
- const problem = prepareForValidation(subschema);
2278
- if (problem !== void 0) return problem;
2279
- }
2280
- }
2281
- }
2282
- function isJsonType(value) {
2283
- return typeof value === "string" && JSON_TYPES.has(value);
2284
- }
2285
- function isRegExpSource(value) {
2286
- if (typeof value !== "string") return false;
2287
- try {
2288
- new RegExp(value, "u");
2289
- return true;
2290
- } catch {
2291
- return false;
2292
- }
2293
- }
2294
- const CLOSED_OBJECT_KEYWORD = /\/(?:additional|unevaluated)Properties$/;
2295
- function toIssues(errors) {
2296
- const failures = [];
2297
- for (let index = 0; index < errors.length; index++) {
2298
- const unit = errors[index];
2299
- const rejected = errors[index + 1];
2300
- if (CLOSED_OBJECT_KEYWORD.test(unit.keywordLocation) && rejected?.keyword === "false") {
2301
- const key = decodePointer(rejected.instanceLocation).at(-1);
2302
- failures.push({
2303
- keyword: "false",
2304
- location: rejected.instanceLocation,
2305
- message: `Unrecognized key: ${JSON.stringify(key)}`,
2306
- object: unit.instanceLocation
2307
- });
2308
- index++;
2309
- } else failures.push({
2310
- keyword: unit.keyword,
2311
- location: unit.instanceLocation,
2312
- message: unit.error
2313
- });
2314
- }
2315
- const relevant = failures.filter((failure) => failure.object === void 0 || !failures.some((other) => other.object === void 0 && (other.location === failure.location || other.location.startsWith(`${failure.location}/`))));
2316
- return relevant.filter((failure, index) => {
2317
- const next = relevant[index + 1];
2318
- if (next === void 0) return true;
2319
- if (next.location.startsWith(`${failure.location}/`)) return false;
2320
- return !(failure.keyword === "$ref" && next.location === failure.location);
2321
- }).map(({ location, message, object }) => {
2322
- const path = decodePointer(object ?? location);
2323
- return path.length === 0 ? { message } : {
2324
- message,
2325
- path
2326
- };
2327
- });
2328
- }
2329
- function decodePointer(location) {
2330
- return location.split("/").slice(1).map((segment) => {
2331
- let decoded = segment;
2332
- try {
2333
- decoded = decodeURIComponent(segment);
2334
- } catch {}
2335
- return decoded.replaceAll("~1", "/").replaceAll("~0", "~");
2336
- });
2337
- }
2338
-
2339
- //#endregion
2340
- //#region src/client/session.ts
2341
- const SESSION_SEND_RETRY_BASE_DELAY_MS = 250;
2342
- const SESSION_SEND_RETRY_MAX_DELAY_MS = 2e3;
2343
- const SESSION_SEND_READY_TIMEOUT_MS = 2e4;
2344
- const followSession = Symbol("followClientSession");
2345
- var ClientSession = class ClientSession {
2346
- #context;
2347
- #state;
2348
- constructor(context, state) {
2349
- this.#context = context;
2350
- this.#state = state;
2351
- }
2352
- static async create(context, input) {
2353
- const startedAt = Date.now();
2354
- const response = await postTurn(context, EVE_SESSION_ROUTE_PATH, input, true, input.stubs);
2355
- const acceptedAt = Date.now();
2356
- const { sessionId, deliveryId } = await readAcceptedMessage(response);
2357
- const session = new ClientSession(context, {
2358
- sessionId,
2359
- streamIndex: 0
2360
- });
2361
- const receipt = {
2362
- deliveryId,
2363
- startedAt,
2364
- notReadyMs: 0,
2365
- acceptedAt
2366
- };
2367
- return {
2368
- response: session.#messageResponse(response, input, 0, void 0, receipt),
2369
- session
2370
- };
2371
- }
2372
- static async prewarm(context, options = {}) {
2373
- const { sessionId } = await readAcceptedMessage(await postCreateSession(context, options));
2374
- return new ClientSession(context, {
2375
- sessionId,
2376
- streamIndex: 0
2377
- });
2378
- }
2379
- get state() {
2380
- return this.#state;
2381
- }
2382
- async snapshot(options) {
2383
- throwIfAborted(options?.signal);
2384
- const events = [];
2385
- for await (const event of this.#readStream({
2386
- follow: false,
2387
- signal: options?.signal,
2388
- startIndex: 0
2389
- })) events.push(event);
2390
- throwIfAborted(options?.signal);
2391
- return {
2392
- events,
2393
- session: {
2394
- sessionId: this.#state.sessionId,
2395
- streamIndex: events.length
2396
- }
2397
- };
2398
- }
2399
- async send(message, options = {}) {
2400
- return await this.#send({
2401
- ...options,
2402
- message
2403
- }, true);
2404
- }
2405
- async respond(inputResponses, options = {}) {
2406
- if (inputResponses.length === 0) throw new Error("ClientSession.respond() requires at least one input response.");
2407
- return await this.#send({
2408
- ...options,
2409
- inputResponses
2410
- }, false);
2411
- }
2412
- async #send(input, retrySessionNotReady) {
2413
- const initialStreamIndex = this.#state.streamIndex;
2414
- const path = createEveSessionRoutePath(this.#state.sessionId);
2415
- const { response, timing } = await postSessionSend(this.#context, path, input, retrySessionNotReady);
2416
- const { sessionId: responseSessionId, deliveryId } = await readAcceptedMessage(response, this.#state.sessionId);
2417
- if (responseSessionId !== this.#state.sessionId) throw new Error("Message route returned a different session id.");
2418
- if (input.message !== void 0 && deliveryId === void 0) throw new Error("Message route did not return a delivery id. Update the server before sending with this client.");
2419
- return this.#messageResponse(response, input, initialStreamIndex, input.message === void 0 ? void 0 : deliveryId, {
2420
- ...timing,
2421
- deliveryId
2422
- });
2423
- }
2424
- async prewarm(options) {
2425
- return await prewarmClientSession({
2426
- context: this.#context,
2427
- sessionId: this.#state.sessionId,
2428
- signal: options?.signal
2429
- });
2430
- }
2431
- async cancel(options) {
2432
- return await cancelClientSession({
2433
- context: this.#context,
2434
- options,
2435
- sessionId: this.#state.sessionId
2436
- });
2437
- }
2438
- async clear() {
2439
- return await clearClientSession({
2440
- context: this.#context,
2441
- sessionId: this.#state.sessionId
2442
- });
2443
- }
2444
- async compact() {
2445
- return await compactClientSession({
2446
- context: this.#context,
2447
- sessionId: this.#state.sessionId
2448
- });
2449
- }
2450
- async reset(options) {
2451
- return await resetClientSession({
2452
- context: this.#context,
2453
- options,
2454
- sessionId: this.#state.sessionId
2455
- });
2456
- }
2457
- stream(options) {
2458
- if (options?.follow === false && (options.startIndex ?? this.#state.streamIndex) < 0) throw new Error("stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.");
2459
- return this.#streamAndAdvance(options);
2460
- }
2461
- agent(started) {
2462
- return new ClientAgentSession(this.#context, started);
2463
- }
2464
- [followSession](options) {
2465
- return this.#streamAndAdvance({
2466
- ...options,
2467
- keepAlive: true
2468
- });
2469
- }
2470
- #messageResponse(response, input, initialStreamIndex, deliveryId, receipt) {
2471
- response.body?.cancel().catch(() => {});
2472
- return new MessageResponse({
2473
- cancelTurn: async (turnId) => await this.cancel({ turnId }),
2474
- createStream: (source) => this.#createEventStream(initialStreamIndex, input, deliveryId, source),
2475
- deliveryId,
2476
- receipt,
2477
- resumesTurn: input.inputResponses !== void 0,
2478
- sessionId: this.#state.sessionId
2479
- });
2480
- }
2481
- async *#createEventStream(initialStreamIndex, input, deliveryId, source) {
2482
- let eventCount = 0;
2483
- let started = deliveryId === void 0;
2484
- let reachedBoundary = false;
2485
- const segment = new TurnSegment({ followCallbacks: true });
2486
- try {
2487
- for await (const event of source ?? this.#readStream({
2488
- headers: input.headers,
2489
- keepAlive: true,
2490
- signal: input.signal,
2491
- startIndex: initialStreamIndex,
2492
- streamReconnectPolicy: input.streamReconnectPolicy
2493
- })) {
2494
- eventCount += 1;
2495
- if (deliveryId !== void 0) {
2496
- const matches = event.meta?.deliveryIds?.includes(deliveryId) === true;
2497
- const terminal = event.type === "session.failed" || event.type === "session.completed";
2498
- if (!matches && terminal && (!started || event.type === "session.completed")) throw new Error("The session ended before the accepted message reached its turn boundary.");
2499
- if (!started && !matches) continue;
2500
- const attributed = event.meta?.deliveryIds !== void 0;
2501
- if (!terminal && attributed && !matches) continue;
2502
- started = true;
2503
- }
2504
- reachedBoundary = segment.observe(event);
2505
- yield event;
2506
- if (reachedBoundary) break;
2507
- }
2508
- if (deliveryId !== void 0 && !reachedBoundary && !input.signal?.aborted) throw new Error("The response stream ended before the accepted message reached its turn boundary.");
2509
- } finally {
2510
- this.#advanceStreamIndex(initialStreamIndex + eventCount);
2511
- }
2512
- }
2513
- async *#streamAndAdvance(options) {
2514
- const startIndex = options?.startIndex ?? this.#state.streamIndex;
2515
- let eventCount = 0;
2516
- for await (const event of this.#readStream({
2517
- follow: options?.follow,
2518
- headers: options?.headers,
2519
- keepAlive: options?.keepAlive,
2520
- onCaughtUp: options?.onCaughtUp,
2521
- resolveHeaders: options?.resolveHeaders,
2522
- resolveReconnectPolicy: options?.resolveReconnectPolicy,
2523
- signal: options?.signal,
2524
- startIndex,
2525
- streamReconnectPolicy: options?.streamReconnectPolicy
2526
- })) {
2527
- eventCount += 1;
2528
- if (startIndex >= 0) this.#advanceStreamIndex(startIndex + eventCount);
2529
- yield event;
2530
- }
2531
- }
2532
- #advanceStreamIndex(streamIndex) {
2533
- this.#state = {
2534
- sessionId: this.#state.sessionId,
2535
- streamIndex: Math.max(this.#state.streamIndex, streamIndex)
2536
- };
2537
- }
2538
- #readStream(input) {
2539
- return followStreamIterable({
2540
- onCaughtUp: input.onCaughtUp,
2541
- follow: input.follow,
2542
- host: this.#context.host,
2543
- keepAlive: input.keepAlive,
2544
- resolveHeaders: () => this.#context.resolveHeaders(input.resolveHeaders?.() ?? input.headers),
2545
- path: createEveSessionStreamRoutePath(this.#state.sessionId),
2546
- redirect: this.#context.redirect,
2547
- signal: input.signal,
2548
- startIndex: input.startIndex,
2549
- streamReconnectPolicy: input.streamReconnectPolicy,
2550
- resolveReconnectPolicy: input.resolveReconnectPolicy
2551
- });
2552
- }
2553
- };
2554
- function followClientSession(session, options) {
2555
- return session[followSession](options);
2556
- }
2557
- async function postSessionSend(context, path, input, retrySessionNotReady) {
2558
- const startedAt = Date.now();
2559
- const readyDeadline = startedAt + SESSION_SEND_READY_TIMEOUT_MS;
2560
- let retryDelayMs = SESSION_SEND_RETRY_BASE_DELAY_MS;
2561
- for (;;) {
2562
- const attemptAt = Date.now();
2563
- try {
2564
- return {
2565
- response: await postTurn(context, path, input, false),
2566
- timing: {
2567
- startedAt,
2568
- notReadyMs: attemptAt - startedAt,
2569
- acceptedAt: Date.now()
2570
- }
2571
- };
2572
- } catch (error) {
2573
- if (!retrySessionNotReady || !isSessionNotReady(error)) throw error;
2574
- const remainingMs = readyDeadline - Date.now();
2575
- if (remainingMs <= 0) throw error;
2576
- await sleep(Math.min(retryDelayMs, remainingMs), input.signal);
2577
- }
2578
- throwIfAborted(input.signal);
2579
- retryDelayMs = Math.min(retryDelayMs * 2, SESSION_SEND_RETRY_MAX_DELAY_MS);
2580
- }
2581
- }
2582
- async function postCreateSession(context, options) {
2583
- const headers = await context.resolveHeaders(options.headers);
2584
- const body = options.stubs === void 0 ? void 0 : JSON.stringify({ stubs: options.stubs });
2585
- if (body !== void 0) headers.set("content-type", "application/json");
2586
- const response = await fetch(createClientUrl(context.host, EVE_SESSION_ROUTE_PATH), {
2587
- body,
2588
- headers,
2589
- method: "POST",
2590
- redirect: context.redirect,
2591
- signal: options.signal ?? null
2592
- });
2593
- if (!response.ok) {
2594
- const responseBody = await response.text();
2595
- throw new ClientError(response.status, responseBody, response.headers);
2596
- }
2597
- return response;
2598
- }
2599
- function isSessionNotReady(error) {
2600
- return error instanceof ClientError && error.status === 409 && error.code === "session_not_ready";
2601
- }
2602
- async function postTurn(context, path, input, requireMessage, stubs) {
2603
- const body = createMessageBody(input, requireMessage);
2604
- if (body === null) throw new Error(requireMessage ? "Creating a session requires a non-empty message." : "A session turn requires a non-empty message or inputResponses.");
2605
- if (stubs !== void 0) body.stubs = stubs;
2606
- const headers = await context.resolveHeaders(input.headers);
2607
- headers.set("content-type", "application/json");
2608
- const response = await fetch(createClientUrl(context.host, path), {
2609
- body: JSON.stringify(body),
2610
- headers,
2611
- method: "POST",
2612
- redirect: context.redirect,
2613
- signal: input.signal ?? null
2614
- });
2615
- if (!response.ok) {
2616
- const responseBody = await response.text();
2617
- throw createClientError(response.status, responseBody, response.headers);
2618
- }
2619
- return response;
2620
- }
2621
- async function readAcceptedMessage(response, expected) {
2622
- const payload = await response.json();
2623
- const sessionId = (typeof payload.sessionId === "string" ? payload.sessionId : void 0) ?? response.headers.get("x-eve-session-id")?.trim() ?? expected;
2624
- if (!sessionId) throw new Error("Message route did not return a session id.");
2625
- return {
2626
- sessionId,
2627
- deliveryId: typeof payload.deliveryId === "string" && payload.deliveryId.length > 0 ? payload.deliveryId : void 0
2628
- };
2629
- }
2630
- function createMessageBody(input, requireMessage) {
2631
- const body = {};
2632
- if (input.message !== void 0) body.message = input.message;
2633
- if (input.inputResponses !== void 0 && input.inputResponses.length > 0) body.inputResponses = input.inputResponses;
2634
- if (!requireMessage && input.message !== void 0 && input.turnPolicy !== void 0) body.turnPolicy = input.turnPolicy;
2635
- if (input.clientContext !== void 0) body.clientContext = input.clientContext;
2636
- const outputSchema = serializeOutputSchema(input.outputSchema);
2637
- if (outputSchema !== void 0) body.outputSchema = outputSchema;
2638
- if (requireMessage && body.message === void 0) return null;
2639
- if (body.message === void 0 && body.inputResponses === void 0) return null;
2640
- return body;
2641
- }
2642
-
2643
- //#endregion
2644
- //#region src/client/sessions.ts
2645
- var ClientSessions = class {
2646
- #context;
2647
- constructor(context) {
2648
- this.#context = context;
2649
- }
2650
- async create(input = {}) {
2651
- if ("message" in input) return await ClientSession.create(this.#context, input);
2652
- return { session: await ClientSession.prewarm(this.#context, input) };
2653
- }
2654
- attach(sessionId, options) {
2655
- if (sessionId.length === 0) throw new Error("sessionId must be a non-empty string.");
2656
- return new ClientSession(this.#context, {
2657
- sessionId,
2658
- streamIndex: options?.streamIndex ?? 0
2659
- });
2660
- }
2661
- };
2662
-
2663
- //#endregion
2664
- //#region src/client/types.ts
2665
- const VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER = "x-vercel-trusted-oidc-idp-token";
2666
-
2667
- //#endregion
2668
- //#region src/client/client.ts
2669
- var Client = class {
2670
- #auth;
2671
- #headers;
2672
- #host;
2673
- #redirect;
2674
- sessions;
2675
- constructor(options) {
2676
- this.#host = options.host;
2677
- this.#auth = options.auth;
2678
- this.#headers = options.headers;
2679
- this.#redirect = options.redirect;
2680
- this.sessions = new ClientSessions({
2681
- host: this.#host,
2682
- redirect: this.#redirect,
2683
- resolveHeaders: (perRequest) => this.#resolveHeaders(perRequest)
2684
- });
2685
- }
2686
- async health() {
2687
- const url = createClientUrl(this.#host, EVE_HEALTH_ROUTE_PATH);
2688
- const headers = await this.#resolveHeaders();
2689
- const response = await fetch(url, withRedirectPolicy({ headers }, this.#redirect));
2690
- if (!response.ok) {
2691
- const body = await response.text();
2692
- throw new ClientError(response.status, body, response.headers);
2693
- }
2694
- let payload;
2695
- try {
2696
- payload = await response.json();
2697
- } catch {
2698
- throw new HealthResponseError();
2699
- }
2700
- const result = HealthResultSchema.safeParse(payload);
2701
- if (!result.success) throw new HealthResponseError(result.error.issues.slice(0, 5).map((issue) => {
2702
- const path = issue.path.join(".");
2703
- return path.length === 0 ? issue.message : `${path}: ${issue.message}`;
2704
- }));
2705
- return result.data;
2706
- }
2707
- async info(options = {}) {
2708
- const response = await this.fetch(EVE_INFO_ROUTE_PATH, options);
2709
- if (!response.ok) {
2710
- const body = await response.text();
2711
- throw new ClientError(response.status, body, response.headers);
2712
- }
2713
- let payload;
2714
- try {
2715
- payload = await response.json();
2716
- } catch {
2717
- throw new AgentInfoResponseError();
2718
- }
2719
- const result = AgentInfoResultSchema.safeParse(payload);
2720
- if (!result.success) throw new AgentInfoResponseError(result.error.issues.slice(0, 5).map((issue) => {
2721
- const path = issue.path.join(".");
2722
- return path.length === 0 ? issue.message : `${path}: ${issue.message}`;
2723
- }));
2724
- return result.data;
2725
- }
2726
- async fetch(path, init = {}) {
2727
- const url = createClientUrl(this.#host, path);
2728
- const headers = await this.#resolveHeaders(headersInitToRecord(init.headers));
2729
- return await fetch(url, withRedirectPolicy({
2730
- ...init,
2731
- headers
2732
- }, this.#redirect));
2733
- }
2734
- async #resolveHeaders(perRequest) {
2735
- const headers = new Headers();
2736
- const [baseHeaders, authHeaders] = await Promise.all([resolveHeadersValue(this.#headers), this.#resolveAuthHeaders()]);
2737
- for (const [key, value] of Object.entries(baseHeaders)) headers.set(key, value);
2738
- for (const [key, value] of Object.entries(authHeaders)) headers.set(key, value);
2739
- if (perRequest) for (const [key, value] of Object.entries(perRequest)) headers.set(key, value);
2740
- return headers;
2741
- }
2742
- async #resolveAuthHeaders() {
2743
- const auth = this.#auth;
2744
- if (!auth) return {};
2745
- if ("vercelOidc" in auth) {
2746
- const token = (await resolveTokenValue(auth.vercelOidc.token)).trim();
2747
- if (token.length === 0) return {};
2748
- return {
2749
- authorization: `Bearer ${token}`,
2750
- [VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER]: token
2751
- };
2752
- }
2753
- if ("bearer" in auth) {
2754
- const token = (await resolveTokenValue(auth.bearer)).trim();
2755
- return token.length === 0 ? {} : { authorization: `Bearer ${token}` };
2756
- }
2757
- if ("basic" in auth) {
2758
- const password = await resolveTokenValue(auth.basic.password);
2759
- return { authorization: `Basic ${encodeBasicCredentials(auth.basic.username, password)}` };
2760
- }
2761
- return {};
2762
- }
2763
- };
2764
- async function resolveTokenValue(value) {
2765
- return typeof value === "function" ? value() : value;
2766
- }
2767
- async function resolveHeadersValue(value) {
2768
- if (value === void 0) return {};
2769
- return typeof value === "function" ? await value() : value;
2770
- }
2771
- function headersInitToRecord(headers) {
2772
- if (headers === void 0) return {};
2773
- return Object.fromEntries(new Headers(headers).entries());
2774
- }
2775
- function withRedirectPolicy(init, redirect) {
2776
- return redirect === void 0 ? init : {
2777
- ...init,
2778
- redirect
2779
- };
2780
- }
2781
-
2782
- //#endregion
2783
- //#region src/client/eve-agent-projection.ts
2784
- var EveAgentProjection = class {
2785
- #reducer;
2786
- #events;
2787
- #data;
2788
- constructor(reducer, events) {
2789
- this.#reducer = reducer;
2790
- this.#events = [...events];
2791
- this.#data = this.#reduce();
2792
- }
2793
- get data() {
2794
- return this.#data;
2795
- }
2796
- get reducer() {
2797
- return this.#reducer;
2798
- }
2799
- reset() {
2800
- this.#events = [];
2801
- this.#data = this.#reducer.initial();
2802
- }
2803
- append(event) {
2804
- this.#events.push(event);
2805
- this.#data = this.#reducer.reduce(this.#data, event);
2806
- }
2807
- remove(predicate) {
2808
- this.#events = this.#events.filter((event) => !predicate(event));
2809
- this.#data = this.#reduce();
2810
- }
2811
- replace(predicate, replacement) {
2812
- const index = this.#events.findIndex(predicate);
2813
- if (index === -1) this.#events.push(replacement);
2814
- else this.#events[index] = replacement;
2815
- this.#data = this.#reduce();
2816
- }
2817
- #reduce() {
2818
- let data = this.#reducer.initial();
2819
- for (const event of this.#events) data = this.#reducer.reduce(data, event);
2820
- return data;
2821
- }
2822
- };
2823
-
2824
- //#endregion
2825
- //#region src/client/conversation-projection.ts
2826
- const projectionKey = Symbol("eve.conversationProjection");
2827
- function conversationProjection(state) {
2828
- return state[projectionKey] ?? initialSessionProjection();
2829
- }
2830
- function withConversationProjection(state, projection) {
2831
- if (state[projectionKey] === projection) return state;
2832
- return Object.defineProperty({ ...state }, projectionKey, { value: projection });
2833
- }
2834
-
2835
- //#endregion
2836
- //#region src/client/conversation-state.ts
2837
- function openConversationInputs(state) {
2838
- return Object.values(state.inputs).filter((input) => input.status === "open");
2839
- }
2840
- function hasPendingAuthorizations(state) {
2841
- return openSignIns(conversationProjection(state)).some((attempt) => attempt.awaitsCallback === true);
2842
- }
2843
- function agentToolTask(state, agent) {
2844
- const task = agent.taskId === void 0 ? void 0 : state.tasks[agent.taskId];
2845
- return task?.kind === "agent" ? task : void 0;
2846
- }
2847
- function isAgentSessionCaughtUp(state, agent) {
2848
- if (agent.observation.status !== "following" && agent.observation.status !== "idle") return false;
2849
- const task = agentToolTask(state, agent);
2850
- if (task === void 0) return false;
2851
- const calls = Object.values(task.calls);
2852
- if (calls.some((call) => call.status === "working")) return false;
2853
- const child = agent.observation.conversation;
2854
- if (child.activeTurnId !== void 0) return false;
2855
- if (Object.values(child.inputs).some((input) => input.status !== "settled")) return false;
2856
- if (hasPendingAuthorizations(child)) return false;
2857
- return child.messages.filter((message) => message.role === "user").length >= calls.filter((call) => call.status === "completed").length;
2858
- }
2859
-
2860
- //#endregion
2861
- //#region src/client/eve-agent-store-helpers.ts
2862
- function activeTurnForOptimisticFollowUp(events) {
2863
- const lastTurn = events.findLast((event) => event.type === "turn.started" || event.type === "turn.completed" || event.type === "turn.failed" || event.type === "turn.cancelled" || isCurrentTurnBoundaryEvent(event));
2864
- return lastTurn?.type === "turn.started" ? lastTurn.data.turnId : void 0;
2865
- }
2866
- function isResponseBoundary(event, conversation) {
2867
- return endsTurnSegment(event, {
2868
- callbacks: hasPendingAuthorizations(conversation),
2869
- requests: Object.values(conversation.inputs).some((input) => input.status !== "settled")
2870
- });
2871
- }
2872
- function settledStatus(error, conversation) {
2873
- if (error !== void 0) return "error";
2874
- return conversation.activeTurnId === void 0 ? "ready" : "streaming";
2875
- }
2876
- function isSettledSessionTail(events, conversation) {
2877
- const tail = events.at(-1);
2878
- return tail !== void 0 && isResponseBoundary(tail, conversation);
2879
- }
2880
- function assertAnswerable(input, conversation) {
2881
- for (const { requestId } of input.inputResponses ?? []) {
2882
- const status = conversation.inputs[requestId]?.status;
2883
- if (status !== void 0 && status !== "open") throw new Error(`Input request ${requestId} was already answered.`);
2884
- }
2885
- }
2886
- function assertInFlightFollowUp(input) {
2887
- if (input.inputResponses !== void 0) return;
2888
- if (input.message === void 0 || input.turnPolicy !== "steer") throw new Error("eve session is already processing a turn. Send a message with turnPolicy: \"steer\" to guide it at the next boundary, or answer an open input request.");
2889
- }
2890
- function validateFollowUp(input) {
2891
- assertExclusiveTurnInput(input);
2892
- assertInFlightFollowUp(input);
2893
- return input;
2894
- }
2895
- function assertExclusiveTurnInput(input) {
2896
- if (input.message !== void 0 === (input.inputResponses !== void 0)) throw new Error("A turn requires exactly one of message or inputResponses.");
2897
- }
2898
- let submissionSequence = 0;
2899
- function createSubmissionId() {
2900
- const randomUUID = globalThis.crypto?.randomUUID;
2901
- if (randomUUID !== void 0) return randomUUID.call(globalThis.crypto);
2902
- submissionSequence += 1;
2903
- return `submission_${submissionSequence.toString()}`;
2904
- }
2905
- function createAbortSignal(first, second) {
2906
- return first ? AbortSignal.any([first, second]) : second;
2907
- }
2908
- function summarizeUserContent(message) {
2909
- if (typeof message === "string") return message;
2910
- const parts = [];
2911
- for (const part of message) if (part.type === "text") parts.push(part.text);
2912
- else if (part.type === "file") parts.push(part.filename ? `[file: ${part.filename}]` : "[file]");
2913
- return parts.join("\n");
2914
- }
2915
- function isAbortError(error) {
2916
- return error instanceof Error && error.name === "AbortError";
2917
- }
2918
- function toTerminalStreamFailureError(event) {
2919
- if (event.type !== "session.failed") return void 0;
2920
- const error = new Error(event.data.message);
2921
- error.name = event.data.code;
2922
- return error;
2923
- }
2924
- function createActiveTurn(cancel) {
2925
- const response = Promise.withResolvers();
2926
- const completion = Promise.withResolvers();
2927
- const turn = {
2928
- abortController: new AbortController(),
2929
- acceptedFollowUps: 0,
2930
- cancel: () => cancel(turn),
2931
- completion: completion.promise,
2932
- followUpDispatches: /* @__PURE__ */ new Set(),
2933
- receivedFollowUps: 0,
2934
- receivedFollowUpEvents: /* @__PURE__ */ new Map(),
2935
- followUpSubmissionIds: /* @__PURE__ */ new Set(),
2936
- resolveCompletion: completion.resolve,
2937
- response: response.promise,
2938
- resolveResponse: response.resolve
2939
- };
2940
- return turn;
2941
- }
2942
- function countFollowUpDeliveries(turn, reconciliation) {
2943
- let followed = 0;
2944
- for (const id of reconciliation.ids) if (turn.followUpSubmissionIds.delete(id)) followed += 1;
2945
- if (followed === 0) return;
2946
- if (reconciliation.alreadyProjected) turn.receivedFollowUps += followed;
2947
- else {
2948
- const previous = turn.receivedFollowUpEvents.get(reconciliation.event) ?? 0;
2949
- turn.receivedFollowUpEvents.set(reconciliation.event, previous + followed);
2950
- }
2951
- }
2952
- async function followSteeredTurns(turn, events, isActive) {
2953
- while (turn.followUpDispatches.size > 0) await Promise.allSettled(turn.followUpDispatches);
2954
- if (turn.receivedFollowUps >= turn.acceptedFollowUps) return;
2955
- const segment = new TurnSegment({ followCallbacks: true });
2956
- for await (const event of events) {
2957
- if (!isActive()) return;
2958
- turn.receivedFollowUps += turn.receivedFollowUpEvents.get(event) ?? 0;
2959
- turn.receivedFollowUpEvents.delete(event);
2960
- if (segment.observe(event)) {
2961
- while (turn.followUpDispatches.size > 0) await Promise.allSettled(turn.followUpDispatches);
2962
- if (turn.receivedFollowUps >= turn.acceptedFollowUps) return;
2963
- }
2964
- }
2965
- }
2966
- async function waitWithSignal(promise, signal) {
2967
- if (signal === void 0) return await promise;
2968
- const aborted = Promise.withResolvers();
2969
- const onAbort = () => aborted.reject(signal.reason);
2970
- signal.addEventListener("abort", onAbort, { once: true });
2971
- if (signal.aborted) onAbort();
2972
- try {
2973
- return await Promise.race([aborted.promise, promise]);
2974
- } finally {
2975
- signal.removeEventListener("abort", onAbort);
2976
- }
2977
- }
2978
-
2979
- //#endregion
2980
- //#region src/client/optimistic-message-submissions.ts
2981
- var OptimisticMessageSubmissions = class {
2982
- #optimistic;
2983
- #projections;
2984
- #pending = [];
2985
- constructor(projections, optimistic) {
2986
- this.#projections = projections;
2987
- this.#optimistic = optimistic;
2988
- }
2989
- reset() {
2990
- this.#pending = [];
2991
- }
2992
- submit(input, eventStartIndex, turnId) {
2993
- if (input.message === void 0) return void 0;
2994
- const pending = {
2995
- createdAt: Date.now(),
2996
- eventStartIndex,
2997
- id: createSubmissionId(),
2998
- message: summarizeUserContent(input.message),
2999
- turnId,
3000
- requiresDeliveryId: true
3001
- };
3002
- this.#pending = [...this.#pending, pending];
3003
- if (this.#optimistic) for (const projection of this.#projections) projection.append({
3004
- data: {
3005
- createdAt: pending.createdAt,
3006
- message: pending.message,
3007
- submissionId: pending.id,
3008
- turnId
3009
- },
3010
- type: "client.message.submitted"
3011
- });
3012
- return pending.id;
3013
- }
3014
- resubmit(submissionId, input) {
3015
- const pending = this.#pending.find((candidate) => candidate.id === submissionId);
3016
- const message = input.message === void 0 ? void 0 : summarizeUserContent(input.message);
3017
- if (pending?.message === message) return submissionId;
3018
- if (pending !== void 0) this.#withdraw([pending.id]);
3019
- return this.submit(input, pending?.eventStartIndex ?? 0, pending?.turnId);
3020
- }
3021
- apply(event) {
3022
- if (event.type !== "message.received") {
3023
- for (const projection of this.#projections) projection.append(event);
3024
- return;
3025
- }
3026
- const matching = this.#matching(event);
3027
- if (matching.length === 0) {
3028
- for (const projection of this.#projections) projection.append(event);
3029
- return;
3030
- }
3031
- return this.#reconcile(matching, event, false);
3032
- }
3033
- correlate(submissionId, deliveryId, events) {
3034
- if (submissionId === void 0) return void 0;
3035
- this.#pending = this.#pending.map((pending) => pending.id === submissionId ? {
3036
- ...pending,
3037
- deliveryId,
3038
- requiresDeliveryId: deliveryId !== void 0
3039
- } : pending);
3040
- const pending = this.#pending.find((candidate) => candidate.id === submissionId);
3041
- if (pending === void 0) return void 0;
3042
- for (const event of events.slice(pending.eventStartIndex)) {
3043
- if (event.type !== "message.received") continue;
3044
- const matching = this.#matching(event);
3045
- if (matching.some((candidate) => candidate.id === submissionId)) return this.#reconcile(matching, event, true);
3046
- }
3047
- }
3048
- fail(error, submissionId) {
3049
- const pending = submissionId === void 0 ? this.#pending[0] : this.#pending.find((candidate) => candidate.id === submissionId);
3050
- if (pending === void 0) return;
3051
- this.#pending = this.#pending.filter((candidate) => candidate.id !== pending.id);
3052
- for (const projection of this.#projections) projection.replace((event) => event.type === "client.message.submitted" && event.data.submissionId === pending.id, {
3053
- data: {
3054
- createdAt: pending.createdAt,
3055
- error: { message: error.message },
3056
- message: pending.message,
3057
- submissionId: pending.id,
3058
- turnId: pending.turnId
3059
- },
3060
- type: "client.message.failed"
3061
- });
3062
- }
3063
- failAll(error) {
3064
- for (const pending of this.#pending) this.fail(error, pending.id);
3065
- }
3066
- #matching(event) {
3067
- return this.#pending.filter((pending) => pending.deliveryId === void 0 ? !pending.requiresDeliveryId : event.meta.deliveryIds?.includes(pending.deliveryId) === true);
3068
- }
3069
- #reconcile(submissions, event, alreadyProjected) {
3070
- const ids = submissions.map((pending) => pending.id);
3071
- this.#withdraw(ids);
3072
- if (!alreadyProjected) for (const projection of this.#projections) projection.append(event);
3073
- return {
3074
- alreadyProjected,
3075
- event,
3076
- ids
3077
- };
3078
- }
3079
- #withdraw(ids) {
3080
- const idSet = new Set(ids);
3081
- this.#pending = this.#pending.filter((pending) => !idSet.has(pending.id));
3082
- for (const projection of this.#projections) projection.remove((candidate) => candidate.type === "client.message.submitted" && idSet.has(candidate.data.submissionId));
3083
- }
3084
- };
3085
-
3086
- //#endregion
3087
- //#region src/client/agent-stream-follower.ts
3088
- const agentStreamReconnectPolicy = {
3089
- streamIdleReconnectPolicy: { maxAttempts: Infinity },
3090
- streamOpenReconnectPolicy: { maxAttempts: Infinity }
3091
- };
3092
- var AgentStreamFollower = class {
3093
- #options;
3094
- #started = /* @__PURE__ */ new Map();
3095
- #controllers = /* @__PURE__ */ new Map();
3096
- #failed = /* @__PURE__ */ new Set();
3097
- #disposed = false;
3098
- constructor(options) {
3099
- this.#options = options;
3100
- }
3101
- acceptParentEvent(event) {
3102
- if (event.type === "agent.started") this.#started.set(event.data.sessionId, event);
3103
- }
3104
- reconcile() {
3105
- if (this.#disposed) return;
3106
- const state = this.#options.getState();
3107
- for (const agent of Object.values(state.agents)) {
3108
- if (agentToolTask(state, agent) === void 0) continue;
3109
- const controller = this.#controllers.get(agent.sessionId);
3110
- const caughtUp = isAgentSessionCaughtUp(state, agent);
3111
- if (controller !== void 0 && caughtUp) {
3112
- this.#controllers.delete(agent.sessionId);
3113
- controller.abort();
3114
- this.#options.onIdle(agent.sessionId);
3115
- } else if (controller === void 0 && !caughtUp && !this.#failed.has(agent.sessionId)) this.#follow(agent.sessionId);
3116
- }
3117
- }
3118
- abortAll() {
3119
- this.#disposed = true;
3120
- for (const controller of this.#controllers.values()) controller.abort();
3121
- this.#controllers.clear();
3122
- }
3123
- #follow(sessionId) {
3124
- const started = this.#started.get(sessionId);
3125
- if (started === void 0) return;
3126
- const controller = new AbortController();
3127
- this.#controllers.set(sessionId, controller);
3128
- this.#options.onFollowing(sessionId);
3129
- const { cursors } = this.#options;
3130
- (async () => {
3131
- let cursor = cursors.get(sessionId) ?? 0;
3132
- try {
3133
- for await (const event of this.#options.session.agent(started).stream({
3134
- signal: controller.signal,
3135
- startIndex: cursor,
3136
- streamReconnectPolicy: agentStreamReconnectPolicy
3137
- })) {
3138
- if (controller.signal.aborted) return;
3139
- cursors.set(sessionId, ++cursor);
3140
- this.#options.onEvent(sessionId, event);
3141
- this.reconcile();
3142
- }
3143
- } catch {}
3144
- if (controller.signal.aborted || this.#controllers.get(sessionId) !== controller) return;
3145
- this.#controllers.delete(sessionId);
3146
- this.#failed.add(sessionId);
3147
- this.#options.onUnavailable(sessionId);
3148
- })();
3149
- }
3150
- };
3151
-
3152
- //#endregion
3153
- //#region src/client/authorization-message-parts.ts
3154
- function createAuthorizationRequiredPart(event) {
3155
- const displayName = event.data.authorization?.displayName ?? formatAuthorizationDisplayName(event.data.name);
3156
- const part = {
3157
- authorization: event.data.authorization,
3158
- description: normalizeAuthorizationDescription(event.data.description, event.data.name, displayName),
3159
- displayName,
3160
- name: event.data.name,
3161
- state: "required",
3162
- stepIndex: event.data.stepIndex,
3163
- turnId: event.data.turnId,
3164
- type: "authorization"
3165
- };
3166
- if (event.data.attemptId !== void 0) part.attemptId = event.data.attemptId;
3167
- if (event.data.webhookUrl !== void 0) part.awaitsCallback = true;
3168
- return part;
3169
- }
3170
- function createAuthorizationCompletedPart(event, existing) {
3171
- const displayName = event.data.authorization?.displayName ?? existing?.displayName ?? formatAuthorizationDisplayName(event.data.name);
3172
- const part = {
3173
- authorization: existing?.authorization || event.data.authorization ? {
3174
- ...existing?.authorization,
3175
- ...event.data.authorization
3176
- } : void 0,
3177
- description: existing?.description ?? buildCompletedAuthorizationDescription(displayName, event.data.outcome, event.data.reason),
3178
- displayName,
3179
- name: event.data.name,
3180
- outcome: event.data.outcome,
3181
- state: "completed",
3182
- stepIndex: existing?.stepIndex ?? event.data.stepIndex,
3183
- turnId: existing?.turnId ?? event.data.turnId,
3184
- type: "authorization"
3185
- };
3186
- const attemptId = event.data.attemptId ?? existing?.attemptId;
3187
- if (attemptId !== void 0) part.attemptId = attemptId;
3188
- if (existing?.awaitsCallback) part.awaitsCallback = true;
3189
- if (event.data.reason !== void 0) part.reason = event.data.reason;
3190
- return part;
3191
- }
3192
- function buildCompletedAuthorizationDescription(displayName, outcome, reason) {
3193
- if (outcome === "authorized") return `${displayName} connected.`;
3194
- return `${displayName} authorization ${outcome}${reason !== void 0 ? ` (${reason})` : ""}.`;
3195
- }
3196
- function normalizeAuthorizationDescription(description, name, displayName) {
3197
- if (description === `Authorization required for ${name}`) return `Authorization required for ${displayName}`;
3198
- return description;
3199
- }
3200
- function formatAuthorizationDisplayName(name) {
3201
- if (name.length === 0) return name;
3202
- return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
3203
- }
3204
-
3205
- //#endregion
3206
- //#region src/protocol/catalog-tools.ts
3207
- const SKILL_TOOL_NAME = "eve__skill";
3208
-
3209
- //#endregion
3210
- //#region src/shared/action-request-name.ts
3211
- function actionRequestName(action) {
3212
- switch (action.kind) {
3213
- case "load-skill": return action.name;
3214
- case "subagent-call": return action.subagentName;
3215
- case "remote-agent-call": return action.remoteAgentName;
3216
- case "tool-call":
3217
- case "workflow-tool-call": return action.toolName;
3218
- }
3219
- }
3220
-
3221
- //#endregion
3222
- //#region src/shared/display-name.ts
3223
- function displayName(identifier) {
3224
- const words = lastSegment(identifier).replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/gu, "$1 $2").split(SEPARATORS).filter((word) => word !== "").map((word) => word.length > 1 && word === word.toUpperCase() ? word : word.toLowerCase());
3225
- return words.length === 0 ? identifier : words.join(" ");
3226
- }
3227
- function displayTitle(identifier) {
3228
- return capitalize(displayName(identifier));
3229
- }
3230
- const SEPARATORS = /[\s_-]+/u;
3231
- function lastSegment(identifier) {
3232
- return identifier.split("__").findLast((segment) => segment !== "") ?? identifier;
3233
- }
3234
- function capitalize(text) {
3235
- return text.charAt(0).toUpperCase() + text.slice(1);
3236
- }
3237
-
3238
- //#endregion
3239
- //#region src/client/message-action-parts.ts
3240
- function toMessageInputRequest(request) {
3241
- return {
3242
- allowFreeform: request.allowFreeform,
3243
- display: request.display,
3244
- kind: request.kind,
3245
- options: request.options,
3246
- prompt: request.prompt,
3247
- requestId: request.requestId
3248
- };
3249
- }
3250
- function createToolMetadata(descriptor, extra) {
3251
- return { eve: {
3252
- inputRequest: extra?.inputRequest,
3253
- kind: descriptor.kind,
3254
- label: extra?.label,
3255
- name: descriptor.name
3256
- } };
3257
- }
3258
- function mergeToolMetadata(current, next) {
3259
- const kind = next.eve?.kind ?? current?.eve?.kind ?? "unknown";
3260
- const name = next.eve?.name ?? current?.eve?.name ?? "unknown";
3261
- return { eve: {
3262
- ...current?.eve,
3263
- ...next.eve,
3264
- inputRequest: next.eve?.inputRequest ?? current?.eve?.inputRequest,
3265
- inputResponse: next.eve?.inputResponse ?? current?.eve?.inputResponse,
3266
- kind,
3267
- label: next.eve?.label ?? current?.eve?.label,
3268
- name
3269
- } };
3270
- }
3271
- function normalizeActionRequest(action) {
3272
- const name = actionRequestName(action);
3273
- switch (action.kind) {
3274
- case "load-skill": return {
3275
- kind: "load-skill",
3276
- name,
3277
- toolName: SKILL_TOOL_NAME
3278
- };
3279
- case "tool-call":
3280
- case "workflow-tool-call": return {
3281
- kind: "tool-call",
3282
- name,
3283
- toolName: name
3284
- };
3285
- case "subagent-call":
3286
- case "remote-agent-call": return {
3287
- kind: "subagent-call",
3288
- name,
3289
- toolName: `eve:subagent:${name}`
3290
- };
3291
- }
3292
- }
3293
- function normalizeActionResult(result) {
3294
- switch (result.kind) {
3295
- case "load-skill-result": return {
3296
- kind: "load-skill",
3297
- name: result.name,
3298
- toolName: SKILL_TOOL_NAME
3299
- };
3300
- case "tool-result": return {
3301
- kind: "tool-call",
3302
- name: result.toolName,
3303
- toolName: result.toolName
3304
- };
3305
- case "subagent-result": return {
3306
- kind: "subagent-call",
3307
- name: result.subagentName,
3308
- toolName: `eve:subagent:${result.subagentName}`
3309
- };
3310
- }
3311
- }
3312
- function settledLabel(current, label, descriptor) {
3313
- return label ?? current?.eve?.label ?? displayTitle(descriptor.name);
3314
- }
3315
- function stringifyUnknown(value) {
3316
- if (typeof value === "string") return value;
3317
- try {
3318
- return JSON.stringify(value);
3319
- } catch {
3320
- return "Action failed.";
3321
- }
3322
- }
3323
-
3324
- //#endregion
3325
- //#region src/client/message-reducer-primitives.ts
3326
- function projectReceivedParts(parts, message) {
3327
- return parts?.map((part) => part.type === "text" ? {
3328
- state: "done",
3329
- text: part.text,
3330
- type: "text"
3331
- } : {
3332
- filename: part.filename,
3333
- mediaType: part.mediaType,
3334
- size: part.size,
3335
- type: "file",
3336
- url: part.url
3337
- }) ?? [{
3338
- state: "done",
3339
- text: message,
3340
- type: "text"
3341
- }];
3342
- }
3343
- function partKey(part) {
3344
- switch (part.type) {
3345
- case "text": return `text:${part.stepIndex ?? 0}`;
3346
- case "reasoning": return `reasoning:${part.stepIndex ?? 0}`;
3347
- case "file": return `file:${part.stepIndex ?? 0}:${part.filename ?? part.url ?? part.mediaType}`;
3348
- case "step-start": return "step-start";
3349
- case "authorization": return part.attemptId === void 0 ? `authorization:${part.turnId}:${part.stepIndex}:${part.name}` : `authorization:${part.attemptId}`;
3350
- case "dynamic-tool": return `dynamic-tool:${part.toolCallId}`;
3351
- }
3352
- }
3353
- function upsertMessage(data, next, beforeAssistantTurnId) {
3354
- const index = data.messages.findIndex((message) => message.id === next.id);
3355
- if (index !== -1) return {
3356
- ...data,
3357
- messages: [
3358
- ...data.messages.slice(0, index),
3359
- next,
3360
- ...data.messages.slice(index + 1)
3361
- ]
3362
- };
3363
- const before = beforeAssistantTurnId === void 0 ? -1 : data.messages.findIndex((message) => message.role === "assistant" && message.metadata?.turnId === beforeAssistantTurnId);
3364
- if (before === -1) return {
3365
- ...data,
3366
- messages: [...data.messages, next]
3367
- };
3368
- return {
3369
- ...data,
3370
- messages: [
3371
- ...data.messages.slice(0, before),
3372
- next,
3373
- ...data.messages.slice(before)
3374
- ]
3375
- };
3376
- }
3377
- function optimisticUserMessageId(submissionId) {
3378
- return `optimistic:${submissionId}:user`;
3379
- }
3380
-
3381
- //#endregion
3382
- //#region src/client/message-run-parts.ts
3383
- function transition(message, input) {
3384
- const index = message.parts.findLastIndex((part) => part.type === input.type && part.stepIndex === input.stepIndex);
3385
- const previous = index === -1 ? void 0 : message.parts[index];
3386
- if (input.kind === "append" && !input.delta) return message;
3387
- const current = previous?.state === "streaming" ? previous : void 0;
3388
- const part = {
3389
- id: current?.id ?? input.id ?? `${message.id}:${input.type}:${message.parts.length}`,
3390
- state: input.kind === "append" ? "streaming" : "done",
3391
- stepIndex: input.stepIndex,
3392
- text: input.kind === "append" ? (current?.text ?? "") + input.delta : input.text,
3393
- type: input.type
3394
- };
3395
- const parts = current ? [
3396
- ...message.parts.slice(0, index),
3397
- part,
3398
- ...message.parts.slice(index + 1)
3399
- ] : [...message.parts, part];
3400
- return {
3401
- ...message,
3402
- metadata: {
3403
- ...message.metadata,
3404
- status: input.type === "text" && part.state === "done" ? "complete" : "streaming"
3405
- },
3406
- parts
3407
- };
3408
- }
3409
- const messageRun = { transition };
3410
-
3411
- //#endregion
3412
- //#region src/shared/action-label.ts
3413
- function actionLabel(action, presentation) {
3414
- return presentation?.[action.callId]?.label ?? displayTitle(actionRequestName(action));
3415
- }
3416
-
3417
- //#endregion
3418
- //#region src/client/tool-part-state.ts
3419
- function toolPartState(data, part) {
3420
- const content = part;
3421
- const projection = conversationProjection(data);
3422
- const call = projection.calls[part.toolCallId];
3423
- const requestId = content.approval?.id;
3424
- const input = requestId === void 0 ? void 0 : projection.inputs[requestId];
3425
- const base = {
3426
- input: part.input,
3427
- stepIndex: part.stepIndex,
3428
- toolCallId: part.toolCallId,
3429
- toolMetadata: part.toolMetadata,
3430
- toolName: part.toolName,
3431
- type: "dynamic-tool"
3432
- };
3433
- const requested = requestId === void 0 ? void 0 : {
3434
- id: requestId,
3435
- ...content.approval?.isAutomatic !== void 0 && { isAutomatic: content.approval.isAutomatic }
3436
- };
3437
- const responded = (approved, reason) => ({
3438
- ...base,
3439
- approval: {
3440
- ...requested,
3441
- ...approved && { approved: true },
3442
- ...reason !== void 0 && { reason }
3443
- },
3444
- state: "approval-responded"
3445
- });
3446
- const approvedTrue = requested === void 0 ? void 0 : {
3447
- ...requested,
3448
- approved: true
3449
- };
3450
- if (requested !== void 0 && input !== void 0 && input.status !== "settled" && (call === void 0 || !isSettledCallStatus(reportedCallStatus(projection, call)))) return {
3451
- ...base,
3452
- approval: requested,
3453
- state: "approval-requested"
3454
- };
3455
- const task = call?.taskId === void 0 ? void 0 : projection.tasks[call.taskId]?.calls[part.toolCallId];
3456
- if (call === void 0) {
3457
- if (input === void 0) return part;
3458
- return input.response === void 0 ? {
3459
- ...base,
3460
- output: { status: input.outcome },
3461
- state: "output-available"
3462
- } : responded(input.outcome === "approved", input.response.text);
3463
- }
3464
- switch (reportedCallStatus(projection, call)) {
3465
- case "running":
3466
- case "awaiting-input":
3467
- if (content.partial === true) return {
3468
- ...base,
3469
- approval: approvedTrue,
3470
- output: content.output,
3471
- partial: true,
3472
- state: "output-available"
3473
- };
3474
- if (input !== void 0 && (input.outcome === "approved" || input.response !== void 0)) return responded(input.outcome === "approved", input.response?.text);
3475
- return {
3476
- ...base,
3477
- state: "input-available"
3478
- };
3479
- case "completed": return {
3480
- ...base,
3481
- approval: approvedTrue,
3482
- output: task?.output ?? content.output,
3483
- state: "output-available"
3484
- };
3485
- case "failed": return {
3486
- ...base,
3487
- approval: approvedTrue,
3488
- errorText: task?.error?.message ?? content.errorText ?? call.error?.message ?? (call.taskId === void 0 ? "Action failed." : "Task failed."),
3489
- state: "output-error"
3490
- };
3491
- case "rejected": return {
3492
- ...base,
3493
- approval: {
3494
- id: requestId ?? part.toolCallId,
3495
- approved: false,
3496
- reason: call.error?.message ?? content.errorText
3497
- },
3498
- state: "output-denied"
3499
- };
3500
- case "cancelled":
3501
- if (requestId !== void 0 && input?.outcome === "cancelled") return {
3502
- ...base,
3503
- approval: {
3504
- id: requestId,
3505
- approved: false,
3506
- reason: "Tool execution was cancelled."
3507
- },
3508
- state: "output-denied"
3509
- };
3510
- return {
3511
- ...base,
3512
- approval: approvedTrue,
3513
- errorText: call.taskId === void 0 ? content.errorText ?? call.error?.message ?? "Action was cancelled." : "Task was cancelled.",
3514
- state: "output-error"
3515
- };
3516
- }
3517
- }
3518
-
3519
- //#endregion
3520
- //#region src/client/message-reducer.ts
3521
- function receivedMessageEventId(event) {
3522
- return event.meta.id ?? `${event.data.turnId}:${event.data.sequence}`;
3523
- }
3524
- function defaultMessageReducer() {
3525
- return {
3526
- initial() {
3527
- return withConversationProjection({ messages: [] }, initialSessionProjection());
3528
- },
3529
- reduce(data, event) {
3530
- return reduceMessageData(data, event);
3531
- }
3532
- };
3533
- }
3534
- function reduceMessageData(data, event) {
3535
- const projection = foldSession(conversationProjection(data), event);
3536
- const content = withConversationProjection(reduceContent(data, event), projection);
3537
- const callIds = toolCallIds(content, event);
3538
- return withConversationProjection(callIds.length === 0 ? content : withToolPartStates(content, callIds), projection);
3539
- }
3540
- function reduceContent(data, event) {
3541
- switch (event.type) {
3542
- case "client.message.submitted":
3543
- case "client.message.failed": return upsertMessage(data, {
3544
- id: optimisticUserMessageId(event.data.submissionId),
3545
- metadata: {
3546
- optimistic: true,
3547
- status: event.type === "client.message.failed" ? "failed" : "submitted"
3548
- },
3549
- parts: [{
3550
- type: "text",
3551
- text: event.data.message
3552
- }],
3553
- role: "user"
3554
- }, event.data.turnId);
3555
- case "message.received": return upsertMessage(data, {
3556
- id: `${receivedMessageEventId(event)}:user`,
3557
- metadata: {
3558
- status: "complete",
3559
- turnId: event.data.turnId
3560
- },
3561
- parts: projectReceivedParts(event.data.parts, event.data.message),
3562
- role: "user"
3563
- }, event.data.turnId);
3564
- case "history.imported": return importHistory(data, event);
3565
- case "step.started": return updateAssistantMessage(data, event.data.turnId, (message) => ensureStepStartPart(message, event.data.stepIndex));
3566
- case "step.completed":
3567
- if (data.messages.find((message) => message.role === "assistant" && message.metadata?.turnId === event.data.turnId) === void 0) return data;
3568
- return updateAssistantMessage(data, event.data.turnId, (message) => ({
3569
- ...message,
3570
- parts: closeStreamingRuns(message.parts, event.data.stepIndex)
3571
- }));
3572
- case "reasoning.appended": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
3573
- kind: "append",
3574
- delta: event.data.reasoningDelta,
3575
- id: event.meta?.id,
3576
- stepIndex: event.data.stepIndex,
3577
- type: "reasoning"
3578
- }));
3579
- case "reasoning.completed": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
3580
- kind: "complete",
3581
- stepIndex: event.data.stepIndex,
3582
- text: event.data.reasoning,
3583
- id: event.meta?.id,
3584
- type: "reasoning"
3585
- }));
3586
- case "action.input.appended": {
3587
- const existing = findToolPart(data, event.data.callId);
3588
- if (existing !== void 0 && existing.state !== "input-streaming") return data;
3589
- const inputText = (existing?.state === "input-streaming" ? existing.inputText : "") + event.data.inputTextDelta;
3590
- return upsertToolPart(data, event.data.turnId, event.data.stepIndex, {
3591
- input: void 0,
3592
- inputText,
3593
- state: "input-streaming",
3594
- stepIndex: event.data.stepIndex,
3595
- toolCallId: event.data.callId,
3596
- toolMetadata: existing?.toolMetadata ?? { eve: {
3597
- kind: "unknown",
3598
- name: event.data.toolName
3599
- } },
3600
- toolName: event.data.toolName,
3601
- type: "dynamic-tool"
3602
- });
3603
- }
3604
- case "actions.requested": {
3605
- let next = data;
3606
- for (const action of event.data.actions) {
3607
- const existing = findToolPart(next, action.callId);
3608
- if (existing !== void 0 && existing.state !== "input-streaming") continue;
3609
- const descriptor = normalizeActionRequest(action);
3610
- next = updateAssistantMessage(next, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), {
3611
- input: "input" in action ? action.input : void 0,
3612
- state: "input-available",
3613
- stepIndex: event.data.stepIndex,
3614
- toolCallId: action.callId,
3615
- toolMetadata: createToolMetadata(descriptor, { label: actionLabel(action, event.data.presentation) }),
3616
- toolName: descriptor.toolName,
3617
- type: "dynamic-tool"
3618
- }));
3619
- }
3620
- return next;
3621
- }
3622
- case "input.requested": {
3623
- let next = data;
3624
- for (const request of event.data.requests) {
3625
- const existing = findToolPart(next, request.action.callId);
3626
- if (existing?.approval?.id === request.requestId || existing !== void 0 && isSettledToolPart(existing)) continue;
3627
- const descriptor = normalizeActionRequest(request.action);
3628
- next = updateAssistantMessage(next, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), {
3629
- ...existing,
3630
- approval: { id: request.requestId },
3631
- input: request.action.input,
3632
- state: "approval-requested",
3633
- stepIndex: existing?.stepIndex ?? event.data.stepIndex,
3634
- toolCallId: request.action.callId,
3635
- toolMetadata: createToolMetadata(descriptor, {
3636
- inputRequest: toMessageInputRequest(request),
3637
- label: existing?.toolMetadata?.eve?.label ?? actionLabel(request.action, void 0)
3638
- }),
3639
- toolName: descriptor.toolName,
3640
- type: "dynamic-tool"
3641
- }));
3642
- }
3643
- return next;
3644
- }
3645
- case "action.result": {
3646
- if (conversationProjection(data).calls[event.data.result.callId]?.taskId !== void 0) return data;
3647
- if (event.data.error?.code === "MODEL_CALL_ATTEMPT_RETRIED") return updateAssistantMessage(data, event.data.turnId, (message) => ({
3648
- ...message,
3649
- parts: message.parts.filter((part) => part.type !== "dynamic-tool" || part.toolCallId !== event.data.result.callId)
3650
- }));
3651
- const existing = findToolPart(data, event.data.result.callId);
3652
- const descriptor = normalizeActionResult(event.data.result);
3653
- const succeeded = event.data.status === void 0 || event.data.status === "completed" ? event.data.result.isError !== true && event.data.error === void 0 : false;
3654
- const part = {
3655
- ...existing,
3656
- input: existing?.input,
3657
- stepIndex: existing?.stepIndex ?? event.data.stepIndex,
3658
- toolCallId: event.data.result.callId,
3659
- toolMetadata: mergeToolMetadata(existing?.toolMetadata, createToolMetadata(descriptor, { label: settledLabel(existing?.toolMetadata, event.data.presentation?.[event.data.result.callId]?.label, descriptor) })),
3660
- toolName: existing?.toolName ?? descriptor.toolName,
3661
- type: "dynamic-tool"
3662
- };
3663
- const outcome = succeeded ? {
3664
- errorText: void 0,
3665
- output: event.data.result.output
3666
- } : {
3667
- errorText: event.data.error?.message ?? stringifyUnknown(event.data.result.output),
3668
- output: void 0
3669
- };
3670
- return upsertToolPart(data, event.data.turnId, event.data.stepIndex, {
3671
- ...part,
3672
- ...outcome,
3673
- partial: void 0
3674
- });
3675
- }
3676
- case "action.partial": {
3677
- const existing = findToolPart(data, event.data.result.callId);
3678
- if (existing !== void 0 && isSettledToolPart(existing)) return data;
3679
- const descriptor = normalizeActionResult(event.data.result);
3680
- return upsertToolPart(data, event.data.turnId, event.data.stepIndex, {
3681
- ...existing,
3682
- input: existing?.input,
3683
- output: event.data.result.output,
3684
- partial: true,
3685
- state: "output-available",
3686
- stepIndex: existing?.stepIndex ?? event.data.stepIndex,
3687
- toolCallId: event.data.result.callId,
3688
- toolMetadata: mergeToolMetadata(existing?.toolMetadata, createToolMetadata(descriptor, { label: settledLabel(existing?.toolMetadata, event.data.presentation?.[event.data.result.callId]?.label, descriptor) })),
3689
- toolName: existing?.toolName ?? descriptor.toolName,
3690
- type: "dynamic-tool"
3691
- });
3692
- }
3693
- case "input.resolved": {
3694
- let next = data;
3695
- for (const { requestId, response } of event.data.resolutions) {
3696
- const existing = response === void 0 ? void 0 : findToolPartByApprovalId(next, requestId);
3697
- if (existing === void 0) continue;
3698
- next = replaceToolPart(next, {
3699
- ...existing,
3700
- toolMetadata: mergeToolMetadata(existing.toolMetadata, { eve: {
3701
- inputResponse: response,
3702
- kind: existing.toolMetadata?.eve?.kind ?? "unknown",
3703
- name: existing.toolMetadata?.eve?.name ?? existing.toolName
3704
- } })
3705
- });
3706
- }
3707
- return next;
3708
- }
3709
- case "task.settled": {
3710
- const existing = findToolPart(data, event.data.callId);
3711
- if (existing === void 0) return data;
3712
- const { error, output, status } = event.data;
3713
- const outcome = status === "completed" ? { output } : { errorText: error?.message };
3714
- return replaceToolPart(data, {
3715
- ...existing,
3716
- ...outcome
3717
- });
3718
- }
3719
- case "authorization.required": return updateAssistantMessage(data, event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, event.data.stepIndex), createAuthorizationRequiredPart(event)));
3720
- case "authorization.completed": return completeAuthorization(data, event);
3721
- case "message.appended": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
3722
- kind: "append",
3723
- delta: event.data.messageDelta,
3724
- id: event.meta?.id,
3725
- stepIndex: event.data.stepIndex,
3726
- type: "text"
3727
- }));
3728
- case "message.completed": return updateAssistantMessage(data, event.data.turnId, (message) => messageRun.transition(ensureStepStartPart(message, event.data.stepIndex), {
3729
- kind: "complete",
3730
- stepIndex: event.data.stepIndex,
3731
- text: event.data.message,
3732
- id: event.meta?.id,
3733
- type: "text"
3734
- }));
3735
- case "result.completed": return updateAssistantMessage(data, event.data.turnId, (message) => ({
3736
- ...message,
3737
- metadata: {
3738
- ...message.metadata,
3739
- result: event.data.result
3740
- }
3741
- }));
3742
- case "turn.completed":
3743
- case "turn.cancelled":
3744
- case "turn.failed":
3745
- if (event.type === "turn.failed" && !data.messages.some((message) => message.role === "assistant" && message.metadata?.turnId === event.data.turnId)) return data;
3746
- return updateAssistantMessage(data, event.data.turnId, (message) => ({
3747
- ...message,
3748
- metadata: {
3749
- ...message.metadata,
3750
- status: "complete"
3751
- },
3752
- parts: removeUnsettledToolParts(closeStreamingRuns(message.parts), conversationProjection(data))
3753
- }));
3754
- default: return data;
3755
- }
3756
- }
3757
- function importHistory(data, event) {
3758
- const eventId = event.meta.id ?? `${event.data.turnId}:${event.data.sequence}`;
3759
- const imported = event.data.messages.map((message, index) => ({
3760
- id: `${eventId}:imported:${index}`,
3761
- metadata: message.id === void 0 ? {
3762
- imported: true,
3763
- status: "complete"
3764
- } : {
3765
- historyId: message.id,
3766
- imported: true,
3767
- status: "complete"
3768
- },
3769
- parts: [message.role === "assistant" ? {
3770
- state: "done",
3771
- text: message.text,
3772
- type: "text"
3773
- } : {
3774
- text: message.text,
3775
- type: "text"
3776
- }],
3777
- role: message.role
3778
- }));
3779
- const ids = new Set(imported.map((message) => message.id));
3780
- const messages = data.messages.filter((message) => !ids.has(message.id));
3781
- const before = messages.findIndex((message) => message.metadata?.optimistic === true || message.role === "assistant" && message.metadata?.turnId === event.data.turnId);
3782
- const at = before === -1 ? messages.length : before;
3783
- return {
3784
- ...data,
3785
- messages: [
3786
- ...messages.slice(0, at),
3787
- ...imported,
3788
- ...messages.slice(at)
3789
- ]
3790
- };
3791
- }
3792
- function toolCallIds(data, event) {
3793
- const byRequest = (requestId) => findToolPartByApprovalId(data, requestId)?.toolCallId ?? [];
3794
- switch (event.type) {
3795
- case "actions.requested": return event.data.actions.map((action) => action.callId);
3796
- case "input.requested": return event.data.requests.map((request) => request.action.callId);
3797
- case "action.result":
3798
- case "action.partial": return [event.data.result.callId];
3799
- case "task.started":
3800
- case "task.settled": return [event.data.callId];
3801
- case "input.resolved": return event.data.resolutions.flatMap((resolution) => byRequest(resolution.requestId));
3802
- case "approval.settled": return [byRequest(event.data.requestId)].flat();
3803
- default: return [];
3804
- }
3805
- }
3806
- function withToolPartStates(data, callIds) {
3807
- let next = data;
3808
- for (const callId of new Set(callIds)) {
3809
- const part = findToolPart(next, callId);
3810
- if (part === void 0) continue;
3811
- const derived = toolPartState(next, part);
3812
- if (derived !== part) next = withConversationProjection(replaceToolPart(next, derived), conversationProjection(data));
3813
- }
3814
- return next;
3815
- }
3816
- function closeStreamingRuns(parts, stepIndex) {
3817
- return parts.map((part) => (part.type === "text" || part.type === "reasoning") && part.state === "streaming" && (stepIndex === void 0 || part.stepIndex === stepIndex) ? {
3818
- ...part,
3819
- state: "done"
3820
- } : part);
3821
- }
3822
- function removeUnsettledToolParts(parts, projection) {
3823
- return parts.filter((part) => {
3824
- if (part.type !== "dynamic-tool") return true;
3825
- if (part.state === "input-streaming") return false;
3826
- if (part.state !== "input-available") return true;
3827
- const call = projection.calls[part.toolCallId];
3828
- return call === void 0 || call.taskId !== void 0 || reportedCallStatus(projection, call) !== "running";
3829
- });
3830
- }
3831
- function updateAssistantMessage(data, turnId, update) {
3832
- const message = data.messages.find((message) => message.role === "assistant" && message.metadata?.turnId === turnId) ?? createAssistantMessage(turnId);
3833
- return upsertMessage(data, update(message));
3834
- }
3835
- function createAssistantMessage(turnId) {
3836
- return {
3837
- id: `${turnId}:assistant`,
3838
- metadata: {
3839
- status: "streaming",
3840
- turnId
3841
- },
3842
- parts: [],
3843
- role: "assistant"
3844
- };
3845
- }
3846
- function ensureStepStartPart(message, stepIndex) {
3847
- const stepStartCount = message.parts.filter((part) => part.type === "step-start").length;
3848
- if (stepStartCount > stepIndex) return message;
3849
- const missingCount = stepIndex - stepStartCount + 1;
3850
- return {
3851
- ...message,
3852
- parts: [...message.parts, ...Array.from({ length: missingCount }, () => ({ type: "step-start" }))]
3853
- };
3854
- }
3855
- function upsertPart(message, next) {
3856
- const index = message.parts.findIndex((part) => partKey(part) === partKey(next));
3857
- const parts = index === -1 ? [...message.parts, next] : [
3858
- ...message.parts.slice(0, index),
3859
- next,
3860
- ...message.parts.slice(index + 1)
3861
- ];
3862
- return {
3863
- ...message,
3864
- metadata: {
3865
- ...message.metadata,
3866
- status: next.type === "text" && next.state === "done" ? "complete" : "streaming"
3867
- },
3868
- parts
3869
- };
3870
- }
3871
- function upsertToolPart(data, turnId, stepIndex, part) {
3872
- const updated = updateToolPart(data, part.toolCallId, part);
3873
- return updated !== data ? updated : updateAssistantMessage(data, turnId, (message) => upsertPart(ensureStepStartPart(message, stepIndex), part));
3874
- }
3875
- function updateToolPart(data, toolCallId, next) {
3876
- const message = data.messages.find((candidate) => candidate.role === "assistant" && candidate.parts.some((part) => part.type === "dynamic-tool" && part.toolCallId === toolCallId));
3877
- if (!message) return data;
3878
- return upsertMessage(data, upsertPart(message, next));
3879
- }
3880
- function replaceToolPart(data, next) {
3881
- const message = data.messages.find((candidate) => candidate.parts.some((part) => part.type === "dynamic-tool" && part.toolCallId === next.toolCallId));
3882
- if (message === void 0) return data;
3883
- return upsertMessage(data, {
3884
- ...message,
3885
- parts: message.parts.map((part) => partKey(part) === partKey(next) ? next : part)
3886
- });
3887
- }
3888
- function completeAuthorization(data, event) {
3889
- const existing = findPendingAuthorizationPart(data, event.data.name, event.data.attemptId);
3890
- const next = createAuthorizationCompletedPart(event, existing);
3891
- return updateAssistantMessage(data, existing?.turnId ?? event.data.turnId, (message) => upsertPart(ensureStepStartPart(message, next.stepIndex), next));
3892
- }
3893
- function findToolPart(data, toolCallId) {
3894
- for (const message of data.messages) for (const part of message.parts) if (part.type === "dynamic-tool" && part.toolCallId === toolCallId) return part;
3895
- }
3896
- function isSettledToolPart(part) {
3897
- return part.state === "output-denied" || part.state === "output-error" || part.state === "output-available" && part.partial !== true;
3898
- }
3899
- function findPendingAuthorizationPart(data, name, attemptId) {
3900
- for (let messageIndex = data.messages.length - 1; messageIndex >= 0; messageIndex -= 1) {
3901
- const message = data.messages[messageIndex];
3902
- if (message?.role !== "assistant") continue;
3903
- for (let partIndex = message.parts.length - 1; partIndex >= 0; partIndex -= 1) {
3904
- const part = message.parts[partIndex];
3905
- if (part?.type === "authorization" && part.state === "required" && (attemptId === void 0 ? part.attemptId === void 0 && part.name === name : part.attemptId === attemptId)) return part;
3906
- }
3907
- }
3908
- }
3909
- function findToolPartByApprovalId(data, approvalId) {
3910
- for (const message of data.messages) for (const part of message.parts) if (part.type === "dynamic-tool" && part.approval?.id === approvalId) return part;
3911
- }
3912
-
3913
- //#endregion
3914
- //#region src/client/conversation-reducer.ts
3915
- function initialConversationState() {
3916
- return withConversationProjection({
3917
- turns: {},
3918
- inputs: {},
3919
- tasks: {},
3920
- messages: [],
3921
- agents: {}
3922
- }, initialSessionProjection());
3923
- }
3924
- function updateObservation(state, sessionId, update) {
3925
- const agent = state.agents[sessionId];
3926
- if (agent === void 0) return state;
3927
- const observation = update(agent.observation);
3928
- if (observation === agent.observation) return state;
3929
- return {
3930
- ...state,
3931
- agents: {
3932
- ...state.agents,
3933
- [sessionId]: {
3934
- ...agent,
3935
- observation
3936
- }
3937
- }
3938
- };
3939
- }
3940
- function observedConversation(observation) {
3941
- return observation.status === "not-followed" ? void 0 : observation.conversation;
3942
- }
3943
- function reduceConversationLifecycle(state, event) {
3944
- switch (event.type) {
3945
- case "agent.started": {
3946
- const { callId, name, sessionId, taskId, turnId } = event.data;
3947
- if (state.agents[sessionId] !== void 0) return state;
3948
- const agent = {
3949
- sessionId,
3950
- name,
3951
- callId,
3952
- turnId,
3953
- observation: { status: "not-followed" }
3954
- };
3955
- if (taskId !== void 0) agent.taskId = taskId;
3956
- return withConversationProjection({
3957
- ...state,
3958
- agents: {
3959
- ...state.agents,
3960
- [sessionId]: agent
3961
- }
3962
- }, conversationProjection(state));
3963
- }
3964
- case "client.input.responded": {
3965
- const inputs = { ...state.inputs };
3966
- for (const response of event.data.responses) {
3967
- const current = inputs[response.requestId];
3968
- if (current?.status !== "open") continue;
3969
- inputs[response.requestId] = {
3970
- ...current,
3971
- response,
3972
- status: "responded"
3973
- };
3974
- }
3975
- const projection = conversationProjection(state);
3976
- const projectedInputs = { ...projection.inputs };
3977
- for (const response of event.data.responses) {
3978
- const current = projectedInputs[response.requestId];
3979
- if (current?.status === "open") projectedInputs[response.requestId] = {
3980
- ...current,
3981
- response,
3982
- status: "responded"
3983
- };
3984
- }
3985
- return withConversationProjection({
3986
- ...state,
3987
- inputs
3988
- }, {
3989
- ...projection,
3990
- inputs: projectedInputs
3991
- });
3992
- }
3993
- default: return state;
3994
- }
3995
- }
3996
- const messageReducer = defaultMessageReducer();
3997
- function reduceConversation(state, event) {
3998
- const next = reduceConversationEvent(state, event);
3999
- return event.type.startsWith("client.agent.") ? withConversationProjection(next, conversationProjection(state)) : next;
4000
- }
4001
- function reduceConversationEvent(state, event) {
4002
- switch (event.type) {
4003
- case "client.agent.following": return updateObservation(state, event.data.sessionId, (observation) => observation.status === "following" ? observation : {
4004
- status: "following",
4005
- conversation: observedConversation(observation) ?? initialConversationState()
4006
- });
4007
- case "client.agent.observed": return updateObservation(state, event.data.sessionId, (observation) => observation.status === "following" ? {
4008
- status: "following",
4009
- conversation: reduceConversation(observation.conversation, event.data.event)
4010
- } : observation);
4011
- case "client.agent.idle": return updateObservation(state, event.data.sessionId, (observation) => observation.status === "following" ? {
4012
- status: "idle",
4013
- conversation: observation.conversation
4014
- } : observation);
4015
- case "client.agent.unavailable": return updateObservation(state, event.data.sessionId, (observation) => {
4016
- const conversation = observedConversation(observation);
4017
- return conversation === void 0 ? { status: "unavailable" } : {
4018
- status: "unavailable",
4019
- conversation
4020
- };
4021
- });
4022
- default:
4023
- const messages = messageReducer.reduce(state, event);
4024
- const projection = conversationProjection(messages);
4025
- const { activeTurnId: _activeTurnId, ...rest } = state;
4026
- const { activeTurnId: _messageTurnId, ...messageData } = messages;
4027
- const conversation = {
4028
- ...rest,
4029
- ...messageData,
4030
- turns: Object.fromEntries(Object.entries(projection.turns).map(([id, turn]) => {
4031
- const { turnId, status, waiting } = turn;
4032
- const publicTurn = {
4033
- turnId,
4034
- status
4035
- };
4036
- if (waiting !== void 0) publicTurn.waiting = waiting;
4037
- return [id, publicTurn];
4038
- })),
4039
- inputs: Object.fromEntries(Object.entries(projection.inputs).map(([id, input]) => {
4040
- const { sequence: _sequence, callId: _callId, ...publicInput } = input;
4041
- return [id, publicInput];
4042
- })),
4043
- tasks: projection.tasks
4044
- };
4045
- if (projection.activeTurnId !== void 0) conversation.activeTurnId = projection.activeTurnId;
4046
- return reduceConversationLifecycle(withConversationProjection(conversation, projection), event);
4047
- }
4048
- }
4049
- const canonicalConversationReducer = {
4050
- initial: initialConversationState,
4051
- reduce: reduceConversation
4052
- };
4053
- const conversationReducer = canonicalConversationReducer;
4054
-
4055
- //#endregion
4056
- //#region src/protocol/event-dedupe.ts
4057
- function createEventDeduper() {
4058
- const seen = /* @__PURE__ */ new Set();
4059
- return {
4060
- admit(event) {
4061
- const id = event.meta?.id;
4062
- if (id === void 0) return true;
4063
- if (seen.has(id)) return false;
4064
- seen.add(id);
4065
- return true;
4066
- },
4067
- get size() {
4068
- return seen.size;
4069
- }
4070
- };
4071
- }
4072
-
4073
- //#endregion
4074
- //#region src/client/session-event-stream.ts
4075
- var SessionEventStream = class {
4076
- #controller = new AbortController();
4077
- #readers = /* @__PURE__ */ new Set();
4078
- #caughtUp = Promise.withResolvers();
4079
- caughtUp = this.#caughtUp.promise;
4080
- #ended = false;
4081
- #error;
4082
- #headers;
4083
- #reconnectPolicy;
4084
- constructor(session, options) {
4085
- this.setOptions(options);
4086
- this.caughtUp.catch(() => {});
4087
- if (!options.catchUp) this.#caughtUp.resolve();
4088
- (async () => {
4089
- try {
4090
- for await (const event of followClientSession(session, {
4091
- signal: this.#controller.signal,
4092
- resolveHeaders: () => this.#headers,
4093
- resolveReconnectPolicy: () => this.#reconnectPolicy,
4094
- startIndex: options.startIndex,
4095
- onCaughtUp: options.catchUp ? () => this.#caughtUp.resolve() : void 0
4096
- })) {
4097
- if (this.#controller.signal.aborted) return;
4098
- options.onEvent(event);
4099
- for (const reader of this.#readers) reader.push(event);
4100
- if (event.type === "session.completed" || event.type === "session.failed") break;
4101
- }
4102
- this.#caughtUp.resolve();
4103
- this.#finish();
4104
- } catch (error) {
4105
- this.#caughtUp.reject(error);
4106
- this.#finish(error);
4107
- if (!this.#controller.signal.aborted) options.onError(error);
4108
- }
4109
- })();
4110
- }
4111
- subscribe(signal) {
4112
- const reader = new SessionEventReader(() => this.#readers.delete(reader), signal);
4113
- if (this.#ended) reader.end(this.#error);
4114
- else this.#readers.add(reader);
4115
- return reader;
4116
- }
4117
- get ended() {
4118
- return this.#ended;
4119
- }
4120
- setOptions(options) {
4121
- if ("headers" in options) this.#headers = options.headers;
4122
- if ("streamReconnectPolicy" in options) this.#reconnectPolicy = options.streamReconnectPolicy;
4123
- }
4124
- close() {
4125
- const error = new DOMException("Session stream was detached.", "AbortError");
4126
- this.#controller.abort(error);
4127
- this.#caughtUp.reject(error);
4128
- this.#finish(error);
4129
- }
4130
- #finish(error) {
4131
- if (this.#ended) return;
4132
- this.#ended = true;
4133
- this.#error = error;
4134
- for (const reader of this.#readers) reader.end(error);
4135
- }
4136
- };
4137
- var SessionEventReader = class {
4138
- #events = [];
4139
- #wake = Promise.withResolvers();
4140
- #ended = false;
4141
- #error;
4142
- #dispose;
4143
- constructor(unsubscribe, signal) {
4144
- const abort = () => this.end(signal?.reason);
4145
- signal?.addEventListener("abort", abort, { once: true });
4146
- this.#dispose = () => {
4147
- signal?.removeEventListener("abort", abort);
4148
- unsubscribe();
4149
- };
4150
- if (signal?.aborted) abort();
4151
- }
4152
- push(event) {
4153
- if (this.#ended) return;
4154
- this.#events.push(event);
4155
- this.#wake.resolve();
4156
- }
4157
- end(error) {
4158
- if (this.#ended) return;
4159
- this.#ended = true;
4160
- this.#error = error;
4161
- this.#wake.resolve();
4162
- }
4163
- [Symbol.dispose]() {
4164
- this.end();
4165
- this.#events = [];
4166
- this.#dispose();
4167
- }
4168
- discard() {
4169
- this.#events = [];
4170
- }
4171
- async *[Symbol.asyncIterator]() {
4172
- for (;;) {
4173
- while (this.#events.length > 0) yield this.#events.shift();
4174
- if (this.#ended) {
4175
- if (this.#error !== void 0) throw this.#error;
4176
- return;
4177
- }
4178
- this.#wake = Promise.withResolvers();
4179
- await this.#wake.promise;
4180
- }
4181
- }
4182
- };
4183
-
4184
- //#endregion
4185
- //#region src/client/conversation-client.ts
4186
- var ConversationClient = class {
4187
- projection;
4188
- #conversation;
4189
- #cursors = /* @__PURE__ */ new Map();
4190
- #seenEvents = createEventDeduper();
4191
- #follower;
4192
- #stream;
4193
- #onChange;
4194
- #onConversationChange;
4195
- constructor(projection, onChange, onConversationChange) {
4196
- this.projection = projection;
4197
- this.#conversation = projection.reducer === conversationReducer ? projection : new EveAgentProjection(canonicalConversationReducer, []);
4198
- this.#onChange = onChange;
4199
- this.#onConversationChange = onConversationChange;
4200
- }
4201
- get data() {
4202
- return this.projection.data;
4203
- }
4204
- get conversation() {
4205
- return this.#conversation.data;
4206
- }
4207
- get projections() {
4208
- return this.#conversation === this.projection ? [this.projection] : [this.#conversation, this.projection];
4209
- }
4210
- get following() {
4211
- return this.#follower !== void 0;
4212
- }
4213
- append(event) {
4214
- const previous = this.data;
4215
- const previousConversation = this.conversation;
4216
- this.#appendRoot(event);
4217
- if (previous !== this.data) this.#onChange(this.data, previous);
4218
- else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
4219
- }
4220
- projectResponses(responses) {
4221
- if (!responses?.length) return void 0;
4222
- const event = {
4223
- data: {
4224
- createdAt: Date.now(),
4225
- responses
4226
- },
4227
- type: "client.input.responded"
4228
- };
4229
- this.append(event);
4230
- return () => this.#retract(event);
4231
- }
4232
- replaceResponses(retract, input) {
4233
- retract?.();
4234
- assertAnswerable(input, this.conversation);
4235
- return this.projectResponses(input.inputResponses);
4236
- }
4237
- #retract(event) {
4238
- const previous = this.data;
4239
- const previousConversation = this.conversation;
4240
- for (const projection of this.projections) projection.remove((entry) => entry === event);
4241
- if (previous !== this.data) this.#onChange(this.data, previous);
4242
- else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
4243
- }
4244
- observe(event, options = {}) {
4245
- if (!this.#seenEvents.admit(event)) return false;
4246
- options.onAccepted?.(event);
4247
- const previous = this.data;
4248
- const previousConversation = this.conversation;
4249
- if (options.project) options.project(event);
4250
- else this.#appendRoot(event);
4251
- if (options.notify !== false) {
4252
- if (previous !== this.data) this.#onChange(this.data, previous);
4253
- else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
4254
- }
4255
- this.#follower?.acceptParentEvent(event);
4256
- this.#follower?.reconcile();
4257
- return true;
4258
- }
4259
- hydrate(event) {
4260
- if (!this.#seenEvents.admit(event)) return false;
4261
- this.#appendRoot(event);
4262
- return true;
4263
- }
4264
- follow(session, events = []) {
4265
- this.#follower?.abortAll();
4266
- const follower = new AgentStreamFollower({
4267
- session,
4268
- cursors: this.#cursors,
4269
- getState: () => this.conversation,
4270
- onFollowing: (sessionId) => this.#appendChild({
4271
- type: "client.agent.following",
4272
- data: { sessionId }
4273
- }),
4274
- onEvent: (sessionId, event) => this.#appendChild({
4275
- type: "client.agent.observed",
4276
- data: {
4277
- sessionId,
4278
- event
4279
- }
4280
- }),
4281
- onIdle: (sessionId) => this.#appendChild({
4282
- type: "client.agent.idle",
4283
- data: { sessionId }
4284
- }),
4285
- onUnavailable: (sessionId) => this.#appendChild({
4286
- type: "client.agent.unavailable",
4287
- data: { sessionId }
4288
- })
4289
- });
4290
- this.#follower = follower;
4291
- for (const event of events) follower.acceptParentEvent(event);
4292
- follower.reconcile();
4293
- }
4294
- #appendRoot(event) {
4295
- for (const projection of this.projections) projection.append(event);
4296
- }
4297
- #appendChild(event) {
4298
- const previous = this.data;
4299
- const previousConversation = this.conversation;
4300
- this.#conversation.append(event);
4301
- if (previous !== this.data) this.#onChange(this.data, previous);
4302
- else if (previousConversation !== this.conversation) this.#onConversationChange?.(this.conversation, previousConversation);
4303
- }
4304
- stream(session, options) {
4305
- if (this.#stream !== void 0 && !this.#stream.ended) {
4306
- this.#stream.setOptions(options);
4307
- return this.#stream;
4308
- }
4309
- this.#stream = new SessionEventStream(session, options);
4310
- return this.#stream;
4311
- }
4312
- closeStream() {
4313
- this.#stream?.close();
4314
- this.#stream = void 0;
4315
- }
4316
- stop() {
4317
- this.#follower?.abortAll();
4318
- this.#follower = void 0;
4319
- this.closeStream();
4320
- }
4321
- reset() {
4322
- this.stop();
4323
- this.#cursors.clear();
4324
- this.#seenEvents = createEventDeduper();
4325
- for (const projection of this.projections) projection.reset();
4326
- }
4327
- };
4328
-
4329
- //#endregion
4330
- //#region src/client/session-turn-dispatch.ts
4331
- async function dispatchSessionTurn(input) {
4332
- const { client, session, turn, beforeSend } = input;
4333
- if (session === void 0) {
4334
- if (client === void 0) throw new Error("An external eve session is required before sending.");
4335
- if (turn.message === void 0) throw new Error("Cannot answer an input request before the session starts.");
4336
- const created = await client.sessions.create({
4337
- ...turn,
4338
- message: turn.message
4339
- });
4340
- throwIfAborted(turn.signal);
4341
- return {
4342
- ...created,
4343
- created: true
4344
- };
4345
- }
4346
- beforeSend?.();
4347
- if (turn.inputResponses === void 0) {
4348
- const { message, ...options } = turn;
4349
- return {
4350
- session,
4351
- response: await session.send(message, options),
4352
- created: false
4353
- };
4354
- }
4355
- const { inputResponses, ...options } = turn;
4356
- return {
4357
- session,
4358
- response: await session.respond(inputResponses, options),
4359
- created: false
4360
- };
4361
- }
4362
-
4363
- //#endregion
4364
- //#region src/client/eve-agent-store.ts
4365
- const detachStore = Symbol("detachEveAgentStore");
4366
- const attachStore = Symbol("attachEveAgentStore");
4367
- var EveAgentStore = class {
4368
- #client;
4369
- #autoPrewarm;
4370
- #attached = false;
4371
- #conversationClient;
4372
- #followChildStreams;
4373
- #followIdle;
4374
- #externalSession;
4375
- #subscribers = /* @__PURE__ */ new Set();
4376
- #activeTurn;
4377
- #callbacks = {};
4378
- #error;
4379
- #events;
4380
- #messageSubmissions;
4381
- #prewarmGeneration = 0;
4382
- #prewarmPromise;
4383
- #prewarmController;
4384
- #resumePromise;
4385
- #session;
4386
- #snapshot;
4387
- #status = "ready";
4388
- constructor(init) {
4389
- this.#autoPrewarm = init.prewarm ?? false;
4390
- this.#followChildStreams = init.followSubagents ?? false;
4391
- this.#followIdle = init.followIdle ?? true;
4392
- this.#externalSession = init.session !== void 0;
4393
- this.#client = this.#externalSession ? void 0 : init.client ?? new Client({
4394
- auth: init.auth,
4395
- headers: init.headers,
4396
- host: init.host ?? ""
4397
- });
4398
- this.#conversationClient = new ConversationClient(new EveAgentProjection(init.reducer, []), () => this.#publish(), () => this.#publish());
4399
- this.#events = (init.initialEvents ?? []).filter((event) => this.#conversationClient.hydrate(event));
4400
- this.#messageSubmissions = new OptimisticMessageSubmissions(this.#conversationClient.projections, init.optimistic ?? true);
4401
- this.#session = init.session ?? (init.initialSession === void 0 ? void 0 : this.#client?.sessions.attach(init.initialSession.sessionId, { streamIndex: init.initialSession.streamIndex }));
4402
- this.#snapshot = this.#createSnapshot();
4403
- }
4404
- get snapshot() {
4405
- return this.#snapshot;
4406
- }
4407
- setCallbacks(callbacks) {
4408
- this.#callbacks = callbacks;
4409
- }
4410
- subscribe(callback) {
4411
- this.#subscribers.add(callback);
4412
- return () => void this.#subscribers.delete(callback);
4413
- }
4414
- prewarm() {
4415
- if (this.#prewarmPromise !== void 0) return this.#prewarmPromise;
4416
- if (this.#session === void 0 && this.#externalSession) return Promise.resolve();
4417
- if (this.#activeTurn !== void 0 && this.#session === void 0) return this.#activeTurn.response.then((response) => {
4418
- if (response === void 0) throw this.#error ?? new DOMException("Session creation was aborted.", "AbortError");
4419
- });
4420
- const client = this.#client;
4421
- const session = this.#session;
4422
- if (client === void 0 && session === void 0) return Promise.reject(/* @__PURE__ */ new Error("This eve agent store does not own a session client."));
4423
- const generation = this.#prewarmGeneration;
4424
- const controller = new AbortController();
4425
- this.#prewarmController = controller;
4426
- const promise = (async () => {
4427
- try {
4428
- if (session !== void 0) {
4429
- await session.prewarm({ signal: controller.signal });
4430
- return;
4431
- }
4432
- const created = await client.sessions.create({ signal: controller.signal });
4433
- if (generation !== this.#prewarmGeneration) return;
4434
- this.#error = void 0;
4435
- if (this.#status === "error") this.#status = "ready";
4436
- this.#adoptSession(created.session);
4437
- if (this.#followIdle) this.#ensureStream();
4438
- } catch (error) {
4439
- if (session === void 0 && generation === this.#prewarmGeneration && this.#activeTurn === void 0 && this.#error === void 0) this.#fail(error);
4440
- throw error;
4441
- }
4442
- })();
4443
- this.#prewarmPromise = promise;
4444
- const clear = () => {
4445
- if (this.#prewarmPromise === promise) {
4446
- this.#prewarmPromise = void 0;
4447
- this.#prewarmController = void 0;
4448
- }
4449
- };
4450
- promise.then(clear, clear);
4451
- return promise;
4452
- }
4453
- async send(input) {
4454
- return await this.#submit(input, this.#callbacks.prepareSend);
4455
- }
4456
- async #submit(input, prepareSend) {
4457
- assertAnswerable(input, this.#conversationClient.conversation);
4458
- if (this.#activeTurn !== void 0) {
4459
- if (this.#status === "resuming") throw new Error("eve session is resuming.");
4460
- return await this.#sendFollowUp(this.#activeTurn, input, prepareSend);
4461
- }
4462
- const turn = createActiveTurn((turn) => turn.acceptedFollowUps > 0 && this.#session !== void 0 ? this.#session.cancel() : turn.response.then((response) => response === void 0 ? { status: "no_active_turn" } : response.cancel()));
4463
- this.#activeTurn = turn;
4464
- this.#error = void 0;
4465
- this.#status = "submitted";
4466
- let reader;
4467
- let submissionId;
4468
- let retractResponses;
4469
- try {
4470
- assertExclusiveTurnInput(input);
4471
- submissionId = this.#messageSubmissions.submit(input, this.#events.length);
4472
- retractResponses = this.#conversationClient.projectResponses(input.inputResponses);
4473
- this.#publish();
4474
- const preparedInput = await (prepareSend === void 0 ? input : waitWithSignal(Promise.resolve(prepareSend(input)), createAbortSignal(input.signal, turn.abortController.signal)));
4475
- assertExclusiveTurnInput(preparedInput);
4476
- if (!this.#isActiveTurn(turn)) return;
4477
- if (preparedInput !== input) {
4478
- submissionId = this.#messageSubmissions.resubmit(submissionId, preparedInput);
4479
- retractResponses = this.#conversationClient.replaceResponses(retractResponses, preparedInput);
4480
- this.#publish();
4481
- }
4482
- const turnInput = {
4483
- ...preparedInput,
4484
- signal: createAbortSignal(preparedInput.signal, turn.abortController.signal)
4485
- };
4486
- const dispatched = await this.#dispatchTurn(turnInput);
4487
- retractResponses = void 0;
4488
- const response = dispatched.response;
4489
- reader = dispatched.reader;
4490
- if (!this.#isActiveTurn(turn)) return;
4491
- turn.resolveResponse(response);
4492
- this.#correlate(submissionId, response);
4493
- for await (const event of consumeMessageResponse(response, reader)) {
4494
- if (!this.#isActiveTurn(turn)) return;
4495
- turn.receivedFollowUps += turn.receivedFollowUpEvents.get(event) ?? 0;
4496
- turn.receivedFollowUpEvents.delete(event);
4497
- }
4498
- if (!this.#isActiveTurn(turn)) return;
4499
- await followSteeredTurns(turn, reader, () => this.#isActiveTurn(turn));
4500
- if (!this.#isActiveTurn(turn)) return;
4501
- this.#status = settledStatus(this.#error, this.#conversationClient.conversation);
4502
- } catch (error) {
4503
- if (!this.#isActiveTurn(turn)) return;
4504
- retractResponses?.();
4505
- if (isAbortError(error)) {
4506
- this.#status = "ready";
4507
- this.#messageSubmissions.fail(toError(error), submissionId);
4508
- } else {
4509
- const reported = this.#error !== void 0;
4510
- this.#error ??= toError(error);
4511
- this.#status = "error";
4512
- this.#messageSubmissions.fail(this.#error, submissionId);
4513
- if (!reported) this.#callbacks.onError?.(this.#error);
4514
- }
4515
- } finally {
4516
- reader?.[Symbol.dispose]();
4517
- this.#finishTurn(turn);
4518
- }
4519
- }
4520
- resume() {
4521
- if (this.#resumePromise !== void 0) return this.#resumePromise;
4522
- const promise = this.#resume();
4523
- this.#resumePromise = promise;
4524
- const clear = () => {
4525
- if (this.#resumePromise === promise) this.#resumePromise = void 0;
4526
- };
4527
- promise.then(clear, clear);
4528
- return promise;
4529
- }
4530
- async #resume() {
4531
- if (this.#status !== "ready" && this.#status !== "error") throw new Error("eve session is already processing a turn.");
4532
- if (this.#session === void 0) throw new Error("An eve session is required before resuming.");
4533
- const session = this.#session;
4534
- const turn = createActiveTurn(() => session.cancel());
4535
- this.#activeTurn = turn;
4536
- turn.resolveResponse(void 0);
4537
- this.#error = void 0;
4538
- this.#status = "resuming";
4539
- this.#publish();
4540
- let reader;
4541
- try {
4542
- const stream = this.#ensureStream({
4543
- catchUp: true,
4544
- startIndex: this.#events.length === session.state.streamIndex ? session.state.streamIndex : 0
4545
- });
4546
- reader = stream.subscribe(turn.abortController.signal);
4547
- await stream.caughtUp;
4548
- if (!this.#isActiveTurn(turn)) return;
4549
- reader.discard();
4550
- const tail = this.#events.at(-1);
4551
- if (tail !== void 0) this.#applyTerminalStreamFailure(tail);
4552
- if (tail && !this.#error && !isSettledSessionTail(this.#events, this.#conversationClient.conversation)) {
4553
- this.#status = "streaming";
4554
- this.#publish();
4555
- for await (const event of reader) {
4556
- if (!this.#isActiveTurn(turn)) return;
4557
- turn.receivedFollowUps += turn.receivedFollowUpEvents.get(event) ?? 0;
4558
- turn.receivedFollowUpEvents.delete(event);
4559
- if (isResponseBoundary(event, this.#conversationClient.conversation)) break;
4560
- }
4561
- }
4562
- await followSteeredTurns(turn, reader, () => this.#isActiveTurn(turn));
4563
- if (this.#isActiveTurn(turn)) this.#status = settledStatus(this.#error, this.#conversationClient.conversation);
4564
- } catch (error) {
4565
- if (!this.#isActiveTurn(turn)) return;
4566
- if (isAbortError(error)) this.#status = "ready";
4567
- else {
4568
- this.#error = toError(error);
4569
- this.#status = "error";
4570
- this.#callbacks.onError?.(this.#error);
4571
- }
4572
- } finally {
4573
- reader?.[Symbol.dispose]();
4574
- this.#finishTurn(turn);
4575
- }
4576
- }
4577
- cancel() {
4578
- const turn = this.#activeTurn;
4579
- if (turn === void 0) return this.#status === "streaming" && this.#session !== void 0 ? this.#session.cancel() : Promise.resolve({ status: "no_active_turn" });
4580
- return turn.cancel();
4581
- }
4582
- async compact() {
4583
- return await this.#session?.compact() ?? { status: "no_active_session" };
4584
- }
4585
- async clear() {
4586
- return await this.#session?.clear() ?? { status: "no_active_session" };
4587
- }
4588
- async retire() {
4589
- if (this.#externalSession) throw new Error("retire() needs a store-owned session. Call reset() on the session you supplied, then create a new store for the next session.");
4590
- const result = await this.#session?.reset() ?? { status: "no_active_session" };
4591
- this.reset();
4592
- return result;
4593
- }
4594
- [attachStore]() {
4595
- this.#attached = true;
4596
- if (this.#followChildStreams && !this.#conversationClient.following) this.#followSubagents();
4597
- if (this.#autoPrewarm && this.#session === void 0) this.prewarm().catch(() => {});
4598
- }
4599
- [detachStore]() {
4600
- this.#attached = false;
4601
- this.#conversationClient.stop();
4602
- this.#activeTurn?.abortController.abort();
4603
- this.#resetPrewarm();
4604
- this.#resumePromise = void 0;
4605
- }
4606
- reset() {
4607
- this.#conversationClient.stop();
4608
- const turn = this.#activeTurn;
4609
- this.#activeTurn = void 0;
4610
- turn?.resolveResponse(void 0);
4611
- turn?.resolveCompletion();
4612
- turn?.abortController.abort();
4613
- this.#resetPrewarm();
4614
- this.#resumePromise = void 0;
4615
- if (!this.#externalSession) this.#session = void 0;
4616
- this.#events = [];
4617
- this.#conversationClient.reset();
4618
- this.#messageSubmissions.reset();
4619
- if (this.#followChildStreams && this.#attached) this.#followSubagents();
4620
- this.#error = void 0;
4621
- this.#status = "ready";
4622
- this.#callbacks.onSessionChange?.(this.#session?.state);
4623
- this.#publish();
4624
- if (this.#autoPrewarm && this.#attached) this.prewarm().catch(() => {});
4625
- }
4626
- async #sendFollowUp(turn, input, prepareSend) {
4627
- assertInFlightFollowUp(input);
4628
- const generation = this.#prewarmGeneration;
4629
- const signal = createAbortSignal(input.signal, turn.abortController.signal);
4630
- let retractResponses = this.#conversationClient.projectResponses(input.inputResponses);
4631
- const preparedInput = await waitWithSignal(Promise.resolve(prepareSend?.(input)), signal).then((prepared) => {
4632
- const next = validateFollowUp(prepared ?? input);
4633
- if (next === input) return next;
4634
- retractResponses = this.#conversationClient.replaceResponses(retractResponses, next);
4635
- return next;
4636
- }).catch((error) => {
4637
- retractResponses?.();
4638
- throw error;
4639
- });
4640
- if (generation !== this.#prewarmGeneration) return;
4641
- if (!this.#isActiveTurn(turn)) {
4642
- retractResponses?.();
4643
- return await this.#submit(preparedInput);
4644
- }
4645
- const submissionId = this.#messageSubmissions.submit(preparedInput, this.#events.length, activeTurnForOptimisticFollowUp(this.#events));
4646
- if (submissionId !== void 0) turn.followUpSubmissionIds.add(submissionId);
4647
- this.#publish();
4648
- let dispatch;
4649
- dispatch = (async () => {
4650
- try {
4651
- const signal = createAbortSignal(preparedInput.signal, turn.abortController.signal);
4652
- await waitWithSignal(turn.response, signal);
4653
- if (!this.#isActiveTurn(turn) || this.#session === void 0) throw new Error("The active eve turn ended before the follow-up could be sent.");
4654
- this.#ensureStream({
4655
- headers: preparedInput.headers,
4656
- streamReconnectPolicy: preparedInput.streamReconnectPolicy
4657
- });
4658
- const response = (await dispatchSessionTurn({
4659
- session: this.#session,
4660
- turn: {
4661
- ...preparedInput,
4662
- signal
4663
- }
4664
- })).response;
4665
- retractResponses = void 0;
4666
- if (preparedInput.message === void 0) return;
4667
- turn.acceptedFollowUps += 1;
4668
- this.#correlate(submissionId, response);
4669
- } catch (error) {
4670
- if (this.#isActiveTurn(turn)) {
4671
- this.#messageSubmissions.fail(toError(error), submissionId);
4672
- retractResponses?.();
4673
- this.#publish();
4674
- }
4675
- throw error;
4676
- } finally {
4677
- turn.followUpDispatches.delete(dispatch);
4678
- }
4679
- })();
4680
- turn.followUpDispatches.add(dispatch);
4681
- await dispatch;
4682
- await turn.completion;
4683
- }
4684
- async #dispatchTurn(input) {
4685
- const streamOptions = {
4686
- headers: input.headers,
4687
- streamReconnectPolicy: input.streamReconnectPolicy
4688
- };
4689
- if (this.#session === void 0 && this.#prewarmPromise !== void 0) {
4690
- await waitWithSignal(this.#prewarmPromise.catch((error) => {
4691
- if (this.#session !== void 0) throw error;
4692
- }), input.signal);
4693
- throwIfAborted(input.signal);
4694
- }
4695
- const session = this.#session;
4696
- let reader;
4697
- try {
4698
- const dispatched = await dispatchSessionTurn({
4699
- client: this.#client,
4700
- session,
4701
- turn: input,
4702
- beforeSend: () => {
4703
- reader = this.#ensureStream(streamOptions).subscribe(input.signal);
4704
- }
4705
- });
4706
- if (dispatched.created) {
4707
- this.#adoptSession(dispatched.session);
4708
- reader = this.#ensureStream(streamOptions).subscribe(input.signal);
4709
- }
4710
- return {
4711
- response: dispatched.response,
4712
- reader
4713
- };
4714
- } catch (error) {
4715
- reader?.[Symbol.dispose]();
4716
- throw error;
4717
- }
4718
- }
4719
- #ensureStream(options = {}) {
4720
- if (this.#session === void 0) throw new Error("A session is required before opening its stream.");
4721
- const generation = this.#prewarmGeneration;
4722
- if (this.#followChildStreams && !this.#conversationClient.following) this.#followSubagents();
4723
- return this.#conversationClient.stream(this.#session, {
4724
- ...options,
4725
- onEvent: (event) => {
4726
- if (generation === this.#prewarmGeneration) this.#acceptServerEvent(event);
4727
- },
4728
- onError: (error) => {
4729
- if (generation !== this.#prewarmGeneration || this.#activeTurn !== void 0) return;
4730
- this.#fail(error);
4731
- }
4732
- });
4733
- }
4734
- #adoptSession(session) {
4735
- this.#session = session;
4736
- if (this.#followChildStreams && this.#attached) this.#followSubagents();
4737
- this.#callbacks.onSessionChange?.(session.state);
4738
- this.#publish();
4739
- }
4740
- #fail(error) {
4741
- this.#error = toError(error);
4742
- this.#status = "error";
4743
- this.#callbacks.onError?.(this.#error);
4744
- this.#publish();
4745
- }
4746
- #followSubagents() {
4747
- if (this.#session) this.#conversationClient.follow(this.#session, this.#events);
4748
- }
4749
- #resetPrewarm() {
4750
- this.#prewarmGeneration += 1;
4751
- this.#prewarmController?.abort();
4752
- this.#prewarmController = void 0;
4753
- this.#prewarmPromise = void 0;
4754
- }
4755
- #finishTurn(turn) {
4756
- if (!this.#isActiveTurn(turn)) return;
4757
- turn.resolveResponse(void 0);
4758
- this.#activeTurn = void 0;
4759
- this.#closeStreamWhenIdle();
4760
- try {
4761
- this.#callbacks.onSessionChange?.(this.#session?.state);
4762
- this.#publish();
4763
- this.#callbacks.onFinish?.(this.#snapshot);
4764
- } finally {
4765
- turn.resolveCompletion();
4766
- }
4767
- }
4768
- #isActiveTurn(turn) {
4769
- return this.#activeTurn === turn;
4770
- }
4771
- #acceptServerEvent(event) {
4772
- const wasStreaming = this.#status === "streaming";
4773
- if (!this.#conversationClient.observe(event, {
4774
- onAccepted: () => {
4775
- this.#events = [...this.#events, event];
4776
- },
4777
- project: (accepted) => {
4778
- this.#handleReconciliation(this.#messageSubmissions.apply(accepted));
4779
- },
4780
- notify: false
4781
- })) return false;
4782
- this.#callbacks.onEvent?.(event);
4783
- this.#applyTerminalStreamFailure(event);
4784
- const { conversation } = this.#conversationClient;
4785
- const settled = isSettledSessionTail(this.#events, conversation) && conversation.activeTurnId === void 0;
4786
- if (this.#status !== "resuming" && this.#error === void 0) {
4787
- if ("data" in event && event.data !== void 0 && "turnId" in event.data) this.#status = "streaming";
4788
- if (this.#activeTurn === void 0 && settled) this.#status = "ready";
4789
- }
4790
- this.#callbacks.onSessionChange?.(this.#session?.state);
4791
- if (this.#status !== "resuming") this.#publish();
4792
- if (this.#activeTurn === void 0 && wasStreaming && settled) this.#callbacks.onFinish?.(this.#snapshot);
4793
- if (this.#activeTurn === void 0) this.#closeStreamWhenIdle();
4794
- return true;
4795
- }
4796
- #closeStreamWhenIdle() {
4797
- if (this.#followIdle) return;
4798
- const { conversation } = this.#conversationClient;
4799
- if (conversation.activeTurnId !== void 0) return;
4800
- if (this.#events.length > 0 && !isSettledSessionTail(this.#events, conversation)) return;
4801
- if (!Object.values(conversation.tasks).some((task) => Object.values(task.calls).some((call) => call.status === "working"))) this.#conversationClient.closeStream();
4802
- }
4803
- #correlate(submissionId, response) {
4804
- const deliveryId = getMessageResponseDeliveryId(response);
4805
- const reconciled = this.#messageSubmissions.correlate(submissionId, deliveryId, this.#events);
4806
- if (this.#handleReconciliation(reconciled)) this.#publish();
4807
- }
4808
- #handleReconciliation(reconciliation) {
4809
- if (reconciliation === void 0) return false;
4810
- if (this.#activeTurn !== void 0) countFollowUpDeliveries(this.#activeTurn, reconciliation);
4811
- return true;
4812
- }
4813
- #applyTerminalStreamFailure(event) {
4814
- const error = toTerminalStreamFailureError(event);
4815
- if (error === void 0) return;
4816
- this.#status = "error";
4817
- this.#messageSubmissions.failAll(error);
4818
- if (this.#error === void 0) {
4819
- this.#error = error;
4820
- this.#callbacks.onError?.(error);
4821
- }
4822
- }
4823
- #createSnapshot() {
4824
- return {
4825
- data: this.#conversationClient.data,
4826
- conversation: this.#conversationClient.conversation,
4827
- error: this.#error,
4828
- events: this.#events,
4829
- session: this.#session?.state,
4830
- status: this.#status
4831
- };
4832
- }
4833
- #publish() {
4834
- this.#snapshot = this.#createSnapshot();
4835
- for (const subscriber of this.#subscribers) subscriber();
4836
- }
4837
- };
4838
- function detachEveAgentStore(store) {
4839
- store[detachStore]();
4840
- }
4841
- function attachEveAgentStore(store) {
4842
- store[attachStore]();
4843
- }
4844
-
4845
- //#endregion
4846
- //#region src/client/agent-host.ts
4847
- const AGENT_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
4848
- const EVE_NAMED_AGENT_ROUTE_PREFIX = "/eve";
4849
- function resolveEveAgentHost(input) {
4850
- if (input.agent === void 0) return input.host ?? "";
4851
- if (input.host !== void 0) throw new Error("useEveAgent cannot combine agent and host. Use one target option.");
4852
- assertValidAgentName(input.agent);
4853
- return `${EVE_NAMED_AGENT_ROUTE_PREFIX}/${input.agent}`;
4854
- }
4855
- function assertValidAgentName(name) {
4856
- if (!AGENT_NAME_PATTERN.test(name)) throw new Error(`eve agent name ${JSON.stringify(name)} is invalid. Use lowercase letters, numbers, underscores, or hyphens, starting with a letter or number.`);
4857
- }
4858
-
4859
- //#endregion
4860
- //#region src/svelte/use-eve-agent.ts
4861
- var SvelteEveAgent = class {
4862
- #snapshot;
4863
- #store;
4864
- #subscribe;
4865
- constructor(store) {
4866
- this.#store = store;
4867
- this.#snapshot = store.snapshot;
4868
- this.#subscribe = createSubscriber((update) => {
4869
- if (!("window" in globalThis)) return;
4870
- const unsubscribe = store.subscribe(() => {
4871
- this.#snapshot = store.snapshot;
4872
- update();
4873
- });
4874
- return () => {
4875
- unsubscribe();
4876
- };
4877
- });
4878
- }
4879
- get data() {
4880
- this.#subscribe();
4881
- return this.#snapshot.data;
4882
- }
4883
- get conversation() {
4884
- this.#subscribe();
4885
- return this.#snapshot.conversation;
4886
- }
4887
- get error() {
4888
- this.#subscribe();
4889
- return this.#snapshot.error;
4890
- }
4891
- get events() {
4892
- this.#subscribe();
4893
- return this.#snapshot.events;
4894
- }
4895
- get session() {
4896
- this.#subscribe();
4897
- return this.#snapshot.session;
4898
- }
4899
- get status() {
4900
- this.#subscribe();
4901
- return this.#snapshot.status;
4902
- }
4903
- cancel = () => {
4904
- return this.#store.cancel();
4905
- };
4906
- reset = () => {
4907
- this.#store.reset();
4908
- };
4909
- prewarm = () => {
4910
- return this.#store.prewarm();
4911
- };
4912
- resume = () => {
4913
- return this.#store.resume();
4914
- };
4915
- respond = (inputResponses, options) => {
4916
- return this.#store.send({
4917
- ...options,
4918
- inputResponses
4919
- });
4920
- };
4921
- send = (message, options) => {
4922
- return this.#store.send({
4923
- ...options,
4924
- message
4925
- });
4926
- };
4927
- };
4928
- function useEveAgent(options = {}) {
4929
- if (options.resume && options.initialSession === void 0 && options.session === void 0) throw new Error("useEveAgent({ resume: true }) requires initialSession or session.");
4930
- const reducer = options.reducer ?? conversationReducer;
4931
- const store = new EveAgentStore({
4932
- auth: options.auth,
4933
- headers: options.headers,
4934
- host: resolveEveAgentHost({
4935
- agent: options.agent,
4936
- host: options.host
4937
- }),
4938
- initialEvents: options.initialEvents,
4939
- initialSession: options.initialSession,
4940
- optimistic: options.optimistic,
4941
- followSubagents: options.followSubagents,
4942
- followIdle: options.followIdle,
4943
- prewarm: options.prewarm,
4944
- reducer,
4945
- session: options.session
4946
- });
4947
- store.setCallbacks({
4948
- onError: options.onError,
4949
- onEvent: options.onEvent,
4950
- onFinish: options.onFinish,
4951
- onSessionChange: options.onSessionChange,
4952
- prepareSend: options.prepareSend
4953
- });
4954
- if ("window" in globalThis) onMount(() => {
4955
- attachEveAgentStore(store);
4956
- if (options.resume) store.resume();
4957
- return () => detachEveAgentStore(store);
4958
- });
4959
- return new SvelteEveAgent(store);
4960
- }
4961
-
4962
- //#endregion
4963
- export { conversationProjection as a, openConversationInputs as i, conversationReducer as n, callStatus as o, defaultMessageReducer as r, useEveAgent as t };