eve 0.69.0 → 0.70.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/src/acp/adapter.js +1 -1
  3. package/dist/src/channel/task-card.d.ts +3 -3
  4. package/dist/src/channel/task-card.js +1 -1
  5. package/dist/src/channel/types.d.ts +18 -0
  6. package/dist/src/chunks/{use-eve-agent-Dab2MnT2.js → use-eve-agent-CJQeE7-t.js} +1873 -1236
  7. package/dist/src/chunks/{use-eve-agent-D_5129A9.js → use-eve-agent-DdemtY6C.js} +1874 -1234
  8. package/dist/src/cli/dev/command.js +1 -1
  9. package/dist/src/cli/dev/console-records-preload.d.ts +1 -0
  10. package/dist/src/cli/dev/console-records-preload.js +1 -0
  11. package/dist/src/cli/dev/console-records.d.ts +17 -0
  12. package/dist/src/cli/dev/console-records.js +3 -0
  13. package/dist/src/cli/dev/diagnostic-sink.d.ts +1 -0
  14. package/dist/src/cli/dev/local-server-process.js +1 -1
  15. package/dist/src/cli/dev/tui/blocks.d.ts +2 -1
  16. package/dist/src/cli/dev/tui/blocks.js +3 -3
  17. package/dist/src/cli/dev/tui/conversation-view.d.ts +54 -0
  18. package/dist/src/cli/dev/tui/conversation-view.js +1 -0
  19. package/dist/src/cli/dev/tui/flow-drawer.d.ts +5 -2
  20. package/dist/src/cli/dev/tui/flow-drawer.js +1 -1
  21. package/dist/src/cli/dev/tui/log-display-mode.d.ts +4 -10
  22. package/dist/src/cli/dev/tui/log-display-mode.js +1 -1
  23. package/dist/src/cli/dev/tui/message-queue.d.ts +7 -63
  24. package/dist/src/cli/dev/tui/message-queue.js +3 -1
  25. package/dist/src/cli/dev/tui/prompt-commands.d.ts +7 -7
  26. package/dist/src/cli/dev/tui/prompt-commands.js +1 -1
  27. package/dist/src/cli/dev/tui/question-panel.d.ts +3 -1
  28. package/dist/src/cli/dev/tui/question-panel.js +1 -1
  29. package/dist/src/cli/dev/tui/runner.d.ts +58 -195
  30. package/dist/src/cli/dev/tui/runner.js +3 -3
  31. package/dist/src/cli/dev/tui/task-activity.d.ts +11 -24
  32. package/dist/src/cli/dev/tui/task-activity.js +1 -1
  33. package/dist/src/cli/dev/tui/task-records.d.ts +17 -0
  34. package/dist/src/cli/dev/tui/task-records.js +1 -0
  35. package/dist/src/cli/dev/tui/terminal-renderer.d.ts +15 -37
  36. package/dist/src/cli/dev/tui/terminal-renderer.js +10 -13
  37. package/dist/src/cli/dev/tui/terminal-tool-part.d.ts +2 -0
  38. package/dist/src/cli/dev/tui/terminal-tool-part.js +1 -0
  39. package/dist/src/cli/dev/tui/test/fake-eve-server.d.ts +34 -0
  40. package/dist/src/cli/dev/tui/test/fake-eve-server.js +1 -0
  41. package/dist/src/cli/dev/tui/test/index.d.ts +1 -0
  42. package/dist/src/cli/dev/tui/test/index.js +1 -1
  43. package/dist/src/cli/dev/tui/tool-block-groups.js +1 -1
  44. package/dist/src/cli/dev/tui/tool-presentation.d.ts +1 -0
  45. package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
  46. package/dist/src/cli/dev/tui/tool-rows.d.ts +1 -0
  47. package/dist/src/cli/dev/tui/tool-rows.js +2 -2
  48. package/dist/src/cli/dev/tui/transcript-parts.d.ts +81 -0
  49. package/dist/src/cli/dev/tui/transcript-parts.js +3 -0
  50. package/dist/src/cli/dev/tui/transcript.d.ts +47 -0
  51. package/dist/src/cli/dev/tui/transcript.js +1 -0
  52. package/dist/src/cli/dev/tui/tui.js +1 -1
  53. package/dist/src/cli/dev/tui/turn-clock.d.ts +11 -26
  54. package/dist/src/cli/dev/tui/turn-clock.js +1 -1
  55. package/dist/src/cli/dev/tui/types.d.ts +2 -4
  56. package/dist/src/cli/dev/ui-options.js +1 -1
  57. package/dist/src/client/agent-stream-follower.d.ts +26 -0
  58. package/dist/src/client/agent-stream-follower.js +1 -0
  59. package/dist/src/client/authorization-message-parts.js +1 -1
  60. package/dist/src/client/conversation-client.d.ts +40 -0
  61. package/dist/src/client/conversation-client.js +1 -0
  62. package/dist/src/client/conversation-reducer.d.ts +29 -0
  63. package/dist/src/client/conversation-reducer.js +1 -0
  64. package/dist/src/client/conversation-state.d.ts +110 -0
  65. package/dist/src/client/conversation-state.js +1 -0
  66. package/dist/src/client/eve-agent-projection.d.ts +24 -7
  67. package/dist/src/client/eve-agent-projection.js +1 -1
  68. package/dist/src/client/eve-agent-store-helpers.d.ts +21 -2
  69. package/dist/src/client/eve-agent-store-helpers.js +2 -2
  70. package/dist/src/client/eve-agent-store-state.d.ts +15 -3
  71. package/dist/src/client/eve-agent-store.d.ts +10 -1
  72. package/dist/src/client/eve-agent-store.js +1 -1
  73. package/dist/src/client/index.d.ts +4 -1
  74. package/dist/src/client/index.js +1 -1
  75. package/dist/src/client/message-reducer-primitives.d.ts +1 -2
  76. package/dist/src/client/message-reducer-primitives.js +1 -1
  77. package/dist/src/client/message-reducer-types.d.ts +9 -2
  78. package/dist/src/client/message-reducer.js +1 -1
  79. package/dist/src/client/message-response.js +1 -1
  80. package/dist/src/client/message-run-parts.d.ts +10 -6
  81. package/dist/src/client/message-run-parts.js +1 -1
  82. package/dist/src/client/optimistic-message-submissions.d.ts +6 -4
  83. package/dist/src/client/optimistic-message-submissions.js +1 -1
  84. package/dist/src/client/reducer.d.ts +5 -1
  85. package/dist/src/client/session-turn-dispatch.d.ts +15 -0
  86. package/dist/src/client/session-turn-dispatch.js +1 -0
  87. package/dist/src/client/session-utils.d.ts +27 -10
  88. package/dist/src/client/session-utils.js +1 -1
  89. package/dist/src/client/session.js +1 -1
  90. package/dist/src/client/types.d.ts +2 -1
  91. package/dist/src/compiled/.vendor-stamp.json +2 -2
  92. package/dist/src/compiled/{gray-matter → js-yaml}/LICENSE +2 -2
  93. package/dist/src/compiled/js-yaml/index.d.ts +12 -0
  94. package/dist/src/compiled/js-yaml/index.js +34 -0
  95. package/dist/src/compiler/extension-compatibility.d.ts +18 -18
  96. package/dist/src/compiler/extension-compatibility.js +1 -1
  97. package/dist/src/compiler/load-binding-namespace.js +1 -1
  98. package/dist/src/context/keys.d.ts +5 -2
  99. package/dist/src/context/keys.js +1 -1
  100. package/dist/src/context/provider.d.ts +5 -9
  101. package/dist/src/context/run-step.d.ts +4 -4
  102. package/dist/src/context/run-step.js +1 -1
  103. package/dist/src/context/serialize.d.ts +5 -1
  104. package/dist/src/context/serialize.js +1 -1
  105. package/dist/src/evals/loaders/yaml.js +1 -1
  106. package/dist/src/evals/runner/derive-run-facts.js +1 -1
  107. package/dist/src/evals/runner/execute-task.js +1 -1
  108. package/dist/src/evals/session.js +2 -2
  109. package/dist/src/evals/types.d.ts +16 -0
  110. package/dist/src/eve-channel/index.js +1 -1
  111. package/dist/src/execution/agent-sessions/context.d.ts +4 -2
  112. package/dist/src/execution/agent-sessions/context.js +1 -1
  113. package/dist/src/execution/agent-sessions/steps.js +1 -1
  114. package/dist/src/execution/cancelled-model-call-batch.js +1 -1
  115. package/dist/src/execution/coordination-dispatch-shared.d.ts +6 -4
  116. package/dist/src/execution/coordination-dispatch-shared.js +1 -1
  117. package/dist/src/execution/create-session-step.d.ts +4 -2
  118. package/dist/src/execution/create-session-step.js +1 -1
  119. package/dist/src/execution/durable-session-store.d.ts +10 -4
  120. package/dist/src/execution/durable-session-store.js +1 -1
  121. package/dist/src/execution/dynamic-workflow/tool.js +1 -1
  122. package/dist/src/execution/legacy-remote-agent/protocol.d.ts +8 -0
  123. package/dist/src/execution/legacy-remote-agent/protocol.js +1 -1
  124. package/dist/src/execution/legacy-session/completion-step.d.ts +2 -0
  125. package/dist/src/execution/legacy-session/completion-step.js +1 -1
  126. package/dist/src/execution/legacy-session/interrupt-step.js +1 -1
  127. package/dist/src/execution/legacy-session/prepare-step.d.ts +1 -0
  128. package/dist/src/execution/legacy-session/prepare-step.js +1 -1
  129. package/dist/src/execution/legacy-session/snapshot.d.ts +8 -4
  130. package/dist/src/execution/legacy-session/snapshot.js +1 -1
  131. package/dist/src/execution/legacy-session/turn-workflow.js +1 -1
  132. package/dist/src/execution/proxied-deliver-step.js +1 -1
  133. package/dist/src/execution/publish-session-events.d.ts +27 -7
  134. package/dist/src/execution/publish-session-events.js +1 -1
  135. package/dist/src/execution/reconcile-session-continuation-token.d.ts +2 -2
  136. package/dist/src/execution/runtime-context.js +1 -1
  137. package/dist/src/execution/session/active-turn.d.ts +97 -0
  138. package/dist/src/execution/session/active-turn.js +1 -0
  139. package/dist/src/execution/session/checkpoint-migrations.d.ts +23 -0
  140. package/dist/src/execution/session/checkpoint-migrations.js +1 -0
  141. package/dist/src/execution/session/entry.js +1 -1
  142. package/dist/src/execution/session/finalization.js +1 -1
  143. package/dist/src/execution/session/handoff-steps.d.ts +24 -5
  144. package/dist/src/execution/session/handoff-steps.js +1 -1
  145. package/dist/src/execution/session/handoff.d.ts +10 -6
  146. package/dist/src/execution/session/handoff.js +1 -1
  147. package/dist/src/execution/session/input-queue.d.ts +19 -13
  148. package/dist/src/execution/session/input-queue.js +1 -1
  149. package/dist/src/execution/session/next-input.d.ts +2 -10
  150. package/dist/src/execution/session/next-input.js +1 -1
  151. package/dist/src/execution/session/pending-turn-state.d.ts +2 -0
  152. package/dist/src/execution/session/pending-turn-state.js +1 -1
  153. package/dist/src/execution/session/program.d.ts +2 -0
  154. package/dist/src/execution/session/program.js +1 -1
  155. package/dist/src/execution/session/state-cursor.d.ts +22 -16
  156. package/dist/src/execution/session/state-cursor.js +1 -1
  157. package/dist/src/execution/session/state-delta.d.ts +8 -1
  158. package/dist/src/execution/session/state-delta.js +1 -1
  159. package/dist/src/execution/session/turn-event-handler.js +1 -1
  160. package/dist/src/execution/session/turn-step-result.js +1 -1
  161. package/dist/src/execution/session/turn-step-types.d.ts +20 -4
  162. package/dist/src/execution/session/turn-step.js +1 -1
  163. package/dist/src/execution/session/turn-waiting-step.js +1 -1
  164. package/dist/src/execution/session/turn.d.ts +22 -3
  165. package/dist/src/execution/session/turn.js +1 -1
  166. package/dist/src/execution/session.d.ts +5 -5
  167. package/dist/src/execution/session.js +2 -2
  168. package/dist/src/execution/settle-cancelled-turn-step.d.ts +5 -4
  169. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  170. package/dist/src/execution/tasks/start.d.ts +2 -2
  171. package/dist/src/execution/tasks/task-id-input.d.ts +1 -1
  172. package/dist/src/execution/tasks/task-id-input.js +1 -1
  173. package/dist/src/execution/terminal-session-completion-step.d.ts +2 -0
  174. package/dist/src/execution/terminal-session-completion-step.js +1 -1
  175. package/dist/src/execution/terminal-session-failure-step.d.ts +2 -0
  176. package/dist/src/execution/terminal-session-failure-step.js +1 -1
  177. package/dist/src/execution/tools/agent-router-workflow.js +1 -1
  178. package/dist/src/execution/tools/connection-target.d.ts +5 -0
  179. package/dist/src/execution/tools/connection-target.js +1 -1
  180. package/dist/src/execution/tools/connection-tools.js +2 -2
  181. package/dist/src/execution/tools/workflow/start.d.ts +3 -3
  182. package/dist/src/harness/authorization.d.ts +15 -2
  183. package/dist/src/harness/authorization.js +1 -1
  184. package/dist/src/harness/cancelled-turn-emission.d.ts +2 -1
  185. package/dist/src/harness/cancelled-turn-emission.js +1 -1
  186. package/dist/src/harness/coordination.d.ts +5 -3
  187. package/dist/src/harness/emission.d.ts +5 -2
  188. package/dist/src/harness/emission.js +1 -1
  189. package/dist/src/harness/held-requests.d.ts +18 -0
  190. package/dist/src/harness/held-requests.js +1 -0
  191. package/dist/src/harness/hitl/approval-input-requests.d.ts +16 -0
  192. package/dist/src/harness/hitl/approval-input-requests.js +1 -1
  193. package/dist/src/harness/input-extraction.js +1 -1
  194. package/dist/src/harness/input-requests.d.ts +0 -4
  195. package/dist/src/harness/input-requests.js +1 -1
  196. package/dist/src/harness/model-call-error.js +1 -1
  197. package/dist/src/harness/proxy-input-requests.d.ts +4 -4
  198. package/dist/src/harness/session-limit-enforcement.js +1 -1
  199. package/dist/src/harness/stale-input-responses.js +1 -1
  200. package/dist/src/harness/tool-loop.js +2 -2
  201. package/dist/src/harness/turn-tag-state.d.ts +2 -0
  202. package/dist/src/harness/turn-tag-state.js +1 -1
  203. package/dist/src/harness/types.d.ts +23 -11
  204. package/dist/src/instrumentation/channel-delivery.d.ts +1 -0
  205. package/dist/src/instrumentation/channel-delivery.js +1 -1
  206. package/dist/src/instrumentation/lifecycle.d.ts +4 -0
  207. package/dist/src/instrumentation/memory.d.ts +2 -0
  208. package/dist/src/instrumentation/memory.js +1 -1
  209. package/dist/src/instrumentation/native-events.d.ts +1 -0
  210. package/dist/src/instrumentation/native-events.js +1 -1
  211. package/dist/src/instrumentation/runtime.d.ts +4 -3
  212. package/dist/src/instrumentation/runtime.js +1 -1
  213. package/dist/src/instrumentation/session-init.js +1 -1
  214. package/dist/src/internal/application/package.js +1 -1
  215. package/dist/src/internal/authored-module-loader.d.ts +14 -6
  216. package/dist/src/internal/authored-module-loader.js +1 -1
  217. package/dist/src/internal/authored-package-boundary.d.ts +1 -1
  218. package/dist/src/internal/authored-package-boundary.js +1 -1
  219. package/dist/src/internal/bundler/extension-mount-plugin.js +1 -1
  220. package/dist/src/internal/helpers/frontmatter.d.ts +24 -0
  221. package/dist/src/internal/helpers/frontmatter.js +1 -0
  222. package/dist/src/internal/helpers/markdown.js +1 -3
  223. package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
  224. package/dist/src/internal/nitro/host/nitro-bundler-config.js +1 -1
  225. package/dist/src/internal/node-esm-compat-banner.js +1 -1
  226. package/dist/src/internal/workflow-bundle/dynamic-remote-agent-transform.js +1 -1
  227. package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.d.ts +27 -1
  228. package/dist/src/internal/workflow-bundle/dynamic-tool-ast-references.js +1 -1
  229. package/dist/src/internal/workflow-bundle/dynamic-tool-transform.js +2 -2
  230. package/dist/src/protocol/message.d.ts +41 -3
  231. package/dist/src/protocol/message.js +2 -2
  232. package/dist/src/public/channels/slack/action-status.d.ts +2 -2
  233. package/dist/src/public/channels/slack/action-status.js +1 -1
  234. package/dist/src/public/channels/slack/approval-cards.d.ts +15 -0
  235. package/dist/src/public/channels/slack/approval-cards.js +2 -0
  236. package/dist/src/public/channels/slack/auth.d.ts +2 -0
  237. package/dist/src/public/channels/slack/auth.js +1 -1
  238. package/dist/src/public/channels/slack/connections.d.ts +15 -11
  239. package/dist/src/public/channels/slack/connections.js +1 -1
  240. package/dist/src/public/channels/slack/defaults.d.ts +1 -15
  241. package/dist/src/public/channels/slack/defaults.js +3 -4
  242. package/dist/src/public/channels/slack/hitl.js +1 -1
  243. package/dist/src/public/channels/slack/inbound.d.ts +10 -2
  244. package/dist/src/public/channels/slack/inbound.js +1 -1
  245. package/dist/src/public/channels/slack/index.d.ts +2 -0
  246. package/dist/src/public/channels/slack/index.js +1 -1
  247. package/dist/src/public/channels/slack/input-response.js +1 -1
  248. package/dist/src/public/channels/slack/interaction-cards.js +1 -1
  249. package/dist/src/public/channels/slack/interactions.js +1 -1
  250. package/dist/src/public/channels/slack/limits.d.ts +5 -3
  251. package/dist/src/public/channels/slack/private-approval-delivery.js +1 -1
  252. package/dist/src/public/channels/slack/renderers.d.ts +1 -1
  253. package/dist/src/public/channels/slack/renderers.js +1 -1
  254. package/dist/src/public/channels/slack/reply-delivery.d.ts +72 -0
  255. package/dist/src/public/channels/slack/reply-delivery.js +1 -0
  256. package/dist/src/public/channels/slack/sign-in-cancel.d.ts +20 -0
  257. package/dist/src/public/channels/slack/sign-in-cancel.js +1 -0
  258. package/dist/src/public/channels/slack/slackChannel.d.ts +15 -0
  259. package/dist/src/public/channels/slack/slackChannel.js +1 -1
  260. package/dist/src/public/channels/slack/task-card.js +1 -1
  261. package/dist/src/public/channels/teams/defaults.d.ts +1 -1
  262. package/dist/src/public/channels/teams/defaults.js +2 -2
  263. package/dist/src/public/definitions/channel.d.ts +1 -0
  264. package/dist/src/public/definitions/channel.js +1 -1
  265. package/dist/src/public/definitions/state.d.ts +2 -0
  266. package/dist/src/public/definitions/state.js +1 -1
  267. package/dist/src/public/next/index.js +1 -1
  268. package/dist/src/public/next/server.d.ts +2 -0
  269. package/dist/src/public/next/server.js +1 -2
  270. package/dist/src/public/nuxt/module.d.ts +6 -0
  271. package/dist/src/public/nuxt/module.js +1 -1
  272. package/dist/src/react/index.d.ts +3 -0
  273. package/dist/src/react/index.js +1 -1
  274. package/dist/src/react/use-eve-agent.d.ts +7 -5
  275. package/dist/src/react/use-eve-agent.js +1 -1
  276. package/dist/src/runtime/connections/openapi-spec.d.ts +1 -4
  277. package/dist/src/runtime/connections/openapi-spec.js +1 -1
  278. package/dist/src/runtime/connections/scoped-authorization.d.ts +2 -0
  279. package/dist/src/runtime/connections/scoped-authorization.js +1 -1
  280. package/dist/src/setup/boxes/deploy-project.js +1 -1
  281. package/dist/src/setup/integrations/web/setup.js +6 -2
  282. package/dist/src/setup/scaffold/create/project.js +1 -1
  283. package/dist/src/setup/scaffold/create/web-template.d.ts +5 -5
  284. package/dist/src/setup/scaffold/create/web-template.js +61 -35
  285. package/dist/src/setup/vercel-project-framework.js +1 -1
  286. package/dist/src/shared/display-name.d.ts +15 -0
  287. package/dist/src/shared/display-name.js +1 -0
  288. package/dist/src/shared/framework-eve-server.d.ts +43 -0
  289. package/dist/src/shared/framework-eve-server.js +2 -0
  290. package/dist/src/shared/token-usage.d.ts +2 -0
  291. package/dist/src/shared/token-usage.js +1 -1
  292. package/dist/src/shared/trace-root.d.ts +8 -0
  293. package/dist/src/shared/trace-root.js +1 -0
  294. package/dist/src/subagents/callback-route.js +1 -1
  295. package/dist/src/subagents/hitl-proxy.d.ts +3 -3
  296. package/dist/src/subagents/hitl-proxy.js +1 -1
  297. package/dist/src/subagents/invocation.d.ts +3 -1
  298. package/dist/src/subagents/parent-notification.d.ts +7 -7
  299. package/dist/src/subagents/parent-notification.js +1 -1
  300. package/dist/src/subagents/tool.js +1 -1
  301. package/dist/src/svelte/index.d.ts +3 -0
  302. package/dist/src/svelte/index.js +2 -2
  303. package/dist/src/svelte/use-eve-agent.d.ts +7 -4
  304. package/dist/src/svelte/use-eve-agent.js +1 -1
  305. package/dist/src/tools/provided/ask-question-workflow.js +1 -1
  306. package/dist/src/tools/provided/load-skill.js +1 -1
  307. package/dist/src/tools/provided/sleep-workflow.js +1 -1
  308. package/dist/src/tracing/agent-action-instrumentation.js +1 -1
  309. package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
  310. package/dist/src/tracing/agent-memory-instrumentation.js +1 -1
  311. package/dist/src/tracing/agent-otel-attributes.d.ts +6 -0
  312. package/dist/src/tracing/agent-otel-attributes.js +1 -1
  313. package/dist/src/tracing/agent-otel-provider.js +2 -2
  314. package/dist/src/tracing/agent-otel-runtime-context.d.ts +1 -1
  315. package/dist/src/tracing/agent-otel-runtime-context.js +1 -1
  316. package/dist/src/tracing/agent-otel-session-context.js +1 -1
  317. package/dist/src/tracing/agent-span-contract.js +1 -1
  318. package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
  319. package/dist/src/tracing/agent-trace-context-codec.d.ts +4 -0
  320. package/dist/src/tracing/agent-trace-context-codec.js +1 -1
  321. package/dist/src/tracing/agent-trace-span-processor.js +1 -1
  322. package/dist/src/tracing/agent-trace-state.d.ts +3 -0
  323. package/dist/src/tracing/conversation-context.d.ts +10 -0
  324. package/dist/src/tracing/conversation-context.js +1 -1
  325. package/dist/src/tracing/otel-registration.js +1 -1
  326. package/dist/src/vue/index.d.ts +3 -0
  327. package/dist/src/vue/index.js +2 -2
  328. package/dist/src/vue/use-eve-agent.d.ts +7 -3
  329. package/dist/src/vue/use-eve-agent.js +1 -1
  330. package/docs/channels/slack.mdx +60 -13
  331. package/docs/concepts/built-in-tools.md +3 -2
  332. package/docs/concepts/execution-model-and-durability.mdx +3 -1
  333. package/docs/concepts/sessions-runs-and-streaming.md +4 -4
  334. package/docs/connections/overview.mdx +9 -3
  335. package/docs/evals/reporters.mdx +4 -0
  336. package/docs/extensions.md +15 -3
  337. package/docs/guides/client/streaming.mdx +7 -6
  338. package/docs/guides/deployment/vercel.mdx +2 -1
  339. package/docs/guides/dev-tui.md +17 -17
  340. package/docs/guides/dynamic-capabilities.md +1 -1
  341. package/docs/guides/frontend/nuxt.mdx +24 -4
  342. package/docs/guides/frontend/overview.mdx +44 -38
  343. package/docs/guides/frontend/use-eve-agent-svelte.mdx +4 -10
  344. package/docs/guides/frontend/use-eve-agent-vue.mdx +4 -10
  345. package/docs/guides/instrumentation/otel.mdx +24 -6
  346. package/docs/guides/remote-agents.md +26 -8
  347. package/docs/reference/cli.md +4 -4
  348. package/docs/tools/human-in-the-loop.md +4 -4
  349. package/docs/tools/overview.mdx +1 -1
  350. package/docs/tools/tasks.md +8 -8
  351. package/package.json +2 -2
  352. package/dist/src/cli/dev/tui/steering-stream.d.ts +0 -15
  353. package/dist/src/cli/dev/tui/steering-stream.js +0 -1
  354. package/dist/src/cli/dev/tui/subagent-pump.d.ts +0 -134
  355. package/dist/src/cli/dev/tui/subagent-pump.js +0 -1
  356. package/dist/src/compiled/gray-matter/index.d.ts +0 -62
  357. package/dist/src/compiled/gray-matter/index.js +0 -48
  358. package/dist/src/internal/helpers/gray-matter.d.ts +0 -25
  359. package/dist/src/internal/helpers/gray-matter.js +0 -1
  360. package/dist/src/public/nuxt/dev-server.d.ts +0 -25
  361. package/dist/src/public/nuxt/dev-server.js +0 -1
@@ -1,2 +1,2 @@
1
- import{isTurnSegmentBoundary,updatePendingAuthorizations,updatePendingInputRequests}from"#client/session-utils.js";function isSettledSessionTail(e){let t=e.at(-1);if(t===void 0)return!1;let n=new Set,r=new Set;for(let t of e)updatePendingAuthorizations(n,t),updatePendingInputRequests(r,t);return isTurnSegmentBoundary(t,r)&&(t.type!==`session.waiting`||n.size===0)}function assertExclusiveTurnInput(e){if(e.message!==void 0==(e.inputResponses!==void 0))throw Error(`A turn requires exactly one of message or inputResponses.`)}let submissionSequence=0;function createSubmissionId(){let e=globalThis.crypto?.randomUUID;return e===void 0?(submissionSequence+=1,`submission_${submissionSequence.toString()}`):e.call(globalThis.crypto)}function createAbortSignal(e,t){return e?AbortSignal.any([e,t]):t}function summarizeUserContent(e){if(typeof e==`string`)return e;let t=[];for(let n of e)n.type===`text`?t.push(n.text):n.type===`file`&&t.push(n.filename?`[file: ${n.filename}]`:`[file]`);return t.join(`
2
- `)}function isAbortError(e){return e instanceof Error&&e.name===`AbortError`}function toTerminalStreamFailureError(e){if(e.type!==`session.failed`)return;let t=Error(e.data.message);return t.name=e.data.code,t}function createActiveTurn(e){let t=Promise.withResolvers(),n=Promise.withResolvers(),r={abortController:new AbortController,acceptedFollowUps:0,cancel:()=>e(r),completion:n.promise,followUpDispatches:new Set,receivedFollowUps:0,receivedFollowUpEvents:new Map,followUpSubmissionIds:new Set,resolveCompletion:n.resolve,response:t.promise,resolveResponse:t.resolve};return r}async function followSteeredTurns(e,t,n){for(;e.followUpDispatches.size>0;)await Promise.allSettled(e.followUpDispatches);if(e.receivedFollowUps>=e.acceptedFollowUps)return;let r=new Set;for await(let i of t){if(!n())return;if(e.receivedFollowUps+=e.receivedFollowUpEvents.get(i)??0,e.receivedFollowUpEvents.delete(i),updatePendingInputRequests(r,i),isTurnSegmentBoundary(i,r)){for(;e.followUpDispatches.size>0;)await Promise.allSettled(e.followUpDispatches);if(e.receivedFollowUps>=e.acceptedFollowUps)return}}}async function waitWithSignal(e,t){if(t===void 0)return await e;let n=Promise.withResolvers(),onAbort=()=>n.reject(t.reason);t.addEventListener(`abort`,onAbort,{once:!0}),t.aborted&&onAbort();try{return await Promise.race([n.promise,e])}finally{t.removeEventListener(`abort`,onAbort)}}export{assertExclusiveTurnInput,createAbortSignal,createActiveTurn,createSubmissionId,followSteeredTurns,isAbortError,isSettledSessionTail,summarizeUserContent,toTerminalStreamFailureError,waitWithSignal};
1
+ import{hasPendingAuthorizations}from"#client/conversation-state.js";import{TurnSegment,endsTurnSegment}from"#client/session-utils.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";function activeTurnForOptimisticFollowUp(e){let t=e.findLast(e=>e.type===`turn.started`||e.type===`turn.completed`||e.type===`turn.failed`||e.type===`turn.cancelled`||isCurrentTurnBoundaryEvent(e));return t?.type===`turn.started`?t.data.turnId:void 0}function isResponseBoundary(e,t){return endsTurnSegment(e,{callbacks:hasPendingAuthorizations(t),requests:Object.values(t.inputs).some(e=>e.status!==`settled`)})}function settledStatus(e,t){return e===void 0?t.activeTurnId===void 0?`ready`:`streaming`:`error`}function isSettledSessionTail(e,t){let n=e.at(-1);return n!==void 0&&isResponseBoundary(n,t)}function assertAnswerable(e,t){for(let{requestId:n}of e.inputResponses??[]){let e=t.inputs[n]?.status;if(e!==void 0&&e!==`open`)throw Error(`Input request ${n} was already answered.`)}}function assertInFlightFollowUp(e){if(e.inputResponses===void 0&&(e.message===void 0||e.turnPolicy!==`steer`))throw 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.`)}function validateFollowUp(e){return assertExclusiveTurnInput(e),assertInFlightFollowUp(e),e}function assertExclusiveTurnInput(e){if(e.message!==void 0==(e.inputResponses!==void 0))throw Error(`A turn requires exactly one of message or inputResponses.`)}let submissionSequence=0;function createSubmissionId(){let e=globalThis.crypto?.randomUUID;return e===void 0?(submissionSequence+=1,`submission_${submissionSequence.toString()}`):e.call(globalThis.crypto)}function createAbortSignal(e,t){return e?AbortSignal.any([e,t]):t}function summarizeUserContent(e){if(typeof e==`string`)return e;let t=[];for(let n of e)n.type===`text`?t.push(n.text):n.type===`file`&&t.push(n.filename?`[file: ${n.filename}]`:`[file]`);return t.join(`
2
+ `)}function isAbortError(e){return e instanceof Error&&e.name===`AbortError`}function toTerminalStreamFailureError(e){if(e.type!==`session.failed`)return;let t=Error(e.data.message);return t.name=e.data.code,t}function createActiveTurn(e){let t=Promise.withResolvers(),n=Promise.withResolvers(),r={abortController:new AbortController,acceptedFollowUps:0,cancel:()=>e(r),completion:n.promise,followUpDispatches:new Set,receivedFollowUps:0,receivedFollowUpEvents:new Map,followUpSubmissionIds:new Set,resolveCompletion:n.resolve,response:t.promise,resolveResponse:t.resolve};return r}function countFollowUpDeliveries(e,t){let n=0;for(let r of t.ids)e.followUpSubmissionIds.delete(r)&&(n+=1);if(n!==0){if(t.alreadyProjected)e.receivedFollowUps+=n;else{let r=e.receivedFollowUpEvents.get(t.event)??0;e.receivedFollowUpEvents.set(t.event,r+n)}}}async function followSteeredTurns(e,t,n){for(;e.followUpDispatches.size>0;)await Promise.allSettled(e.followUpDispatches);if(e.receivedFollowUps>=e.acceptedFollowUps)return;let r=new TurnSegment({followCallbacks:!0});for await(let i of t){if(!n())return;if(e.receivedFollowUps+=e.receivedFollowUpEvents.get(i)??0,e.receivedFollowUpEvents.delete(i),r.observe(i)){for(;e.followUpDispatches.size>0;)await Promise.allSettled(e.followUpDispatches);if(e.receivedFollowUps>=e.acceptedFollowUps)return}}}async function waitWithSignal(e,t){if(t===void 0)return await e;let n=Promise.withResolvers(),onAbort=()=>n.reject(t.reason);t.addEventListener(`abort`,onAbort,{once:!0}),t.aborted&&onAbort();try{return await Promise.race([n.promise,e])}finally{t.removeEventListener(`abort`,onAbort)}}export{activeTurnForOptimisticFollowUp,assertAnswerable,assertExclusiveTurnInput,assertInFlightFollowUp,countFollowUpDeliveries,createAbortSignal,createActiveTurn,createSubmissionId,followSteeredTurns,isAbortError,isResponseBoundary,isSettledSessionTail,settledStatus,summarizeUserContent,toTerminalStreamFailureError,validateFollowUp,waitWithSignal};
@@ -1,5 +1,7 @@
1
+ import type { Client } from "#client/client.js";
1
2
  import type { MessageResponse } from "#client/message-response.js";
2
3
  import type { EveAgentReducer } from "#client/reducer.js";
4
+ import type { ConversationState } from "#client/conversation-state.js";
3
5
  import type { ClientSession } from "#client/session.js";
4
6
  import type { MessageStreamEvent } from "#protocol/message.js";
5
7
  import type { CancelSessionResult, ClientAuth, ClientSessionState, HeadersValue, SendTurnPayload } from "#client/types.js";
@@ -18,6 +20,8 @@ export type PrepareSend = (input: SendTurnPayload) => SendTurnPayload | Promise<
18
20
  /** Immutable projected state of an eve frontend session store. */
19
21
  export interface EveAgentStoreSnapshot<TData> {
20
22
  readonly data: TData;
23
+ /** Canonical session facts, independent of the caller's data projection. */
24
+ readonly conversation: ConversationState;
21
25
  /** The latest session creation, stream, resume, or turn failure. */
22
26
  readonly error: Error | undefined;
23
27
  readonly events: readonly MessageStreamEvent[];
@@ -36,12 +40,14 @@ export interface EveAgentStoreCallbacks<TData> {
36
40
  readonly prepareSend?: PrepareSend;
37
41
  }
38
42
  /**
39
- * Configuration for constructing an eve frontend session store. Pass either
40
- * connection options for a store-owned session or an existing `ClientSession`.
41
- * Saved events must be an ordered prefix of the same session stream.
43
+ * Configuration for constructing an eve frontend session store. Pass connection
44
+ * options or a configured `Client` for store-owned sessions, or an existing
45
+ * `ClientSession`. Saved events must be an ordered prefix of the same session stream.
42
46
  */
43
47
  export interface EveAgentStoreInit<TData> {
44
48
  readonly prewarm?: boolean;
49
+ /** Configured client for store-owned sessions; replaces `host`, `auth`, and `headers`. */
50
+ readonly client?: Client;
45
51
  readonly auth?: ClientAuth;
46
52
  readonly headers?: HeadersValue;
47
53
  readonly host?: string;
@@ -49,6 +55,11 @@ export interface EveAgentStoreInit<TData> {
49
55
  readonly initialEvents?: readonly MessageStreamEvent[];
50
56
  readonly initialSession?: ClientSessionState;
51
57
  readonly optimistic?: boolean;
58
+ /**
59
+ * Follow each agent tool's session into `conversation.agents`, regardless of the data reducer,
60
+ * while the store streams its session or a framework binding has it mounted.
61
+ */
62
+ readonly followSubagents?: boolean;
52
63
  readonly reducer: EveAgentReducer<TData>;
53
64
  readonly session?: ClientSession;
54
65
  }
@@ -57,6 +68,7 @@ export interface PendingMessageSubmission {
57
68
  readonly eventStartIndex: number;
58
69
  readonly id: string;
59
70
  readonly message: string;
71
+ readonly turnId?: string;
60
72
  readonly requiresDeliveryId: boolean;
61
73
  readonly deliveryId?: string;
62
74
  }
@@ -1,5 +1,5 @@
1
1
  import type { EveAgentStoreCallbacks, EveAgentStoreInit, EveAgentStoreSnapshot } from "#client/eve-agent-store-state.js";
2
- import type { CancelSessionResult, SendTurnPayload } from "#client/types.js";
2
+ import type { CancelSessionResult, ClearResult, CompactResult, ResetResult, SendTurnPayload } from "#client/types.js";
3
3
  export type { EveAgentStoreCallbacks, EveAgentStoreInit, EveAgentStoreSnapshot, EveAgentStoreStatus, PrepareSend, } from "#client/eve-agent-store-state.js";
4
4
  declare const detachStore: unique symbol;
5
5
  declare const attachStore: unique symbol;
@@ -26,6 +26,15 @@ export declare class EveAgentStore<TData> {
26
26
  * that turn ID. The event stream stays attached until the turn settles.
27
27
  */
28
28
  cancel(): Promise<CancelSessionResult>;
29
+ /** Queues server-side compaction of the current session's context. */
30
+ compact(): Promise<CompactResult>;
31
+ /** Clears the current session's model-message history on the server. */
32
+ clear(): Promise<ClearResult>;
33
+ /**
34
+ * Terminally retires the store-owned server session, then resets local state so the next
35
+ * send starts a fresh session. A failed request leaves both intact.
36
+ */
37
+ retire(): Promise<ResetResult>;
29
38
  [attachStore](): void;
30
39
  [detachStore](): void;
31
40
  reset(): void;
@@ -1 +1 @@
1
- import{toError}from"#shared/errors.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{isTurnSegmentBoundary,updatePendingAuthorizations,updatePendingInputRequests}from"#client/session-utils.js";import{Client}from"#client/client.js";import{consumeMessageResponse,getMessageResponseDeliveryId}from"#client/message-response.js";import{SessionEventStream}from"#client/session-event-stream.js";import{EveAgentProjection}from"#client/eve-agent-projection.js";import{OptimisticMessageSubmissions}from"#client/optimistic-message-submissions.js";import{assertExclusiveTurnInput,createAbortSignal,createActiveTurn,followSteeredTurns,isAbortError,isSettledSessionTail,toTerminalStreamFailureError,waitWithSignal}from"#client/eve-agent-store-helpers.js";const detachStore=Symbol(`detachEveAgentStore`),attachStore=Symbol(`attachEveAgentStore`);var EveAgentStore=class{#e;#t;#n=!1;#r;#i=new Set;#a=new Set;#o;#s;#c;#l=new Set;#u=createEventDeduper();#d;#f={};#p;#m;#h;#g=0;#_;#v;#y;#b;#x;#S=`ready`;constructor(e){this.#t=e.prewarm??!1,this.#o=e.session!==void 0,this.#e=this.#o?void 0:new Client({auth:e.auth,headers:e.headers,host:e.host??``});let t=[];for(let n of e.initialEvents??[])this.#u.admit(n)&&t.push(n),this.#N(n);this.#m=t,this.#c=new EveAgentProjection(e.reducer,this.#m),this.#s=e.optimistic??!0,this.#h=new OptimisticMessageSubmissions(this.#c,this.#s),this.#b=e.session??(e.initialSession===void 0?void 0:this.#e?.sessions.attach(e.initialSession.sessionId,{streamIndex:e.initialSession.streamIndex})),this.#x=this.#L()}get snapshot(){return this.#x}setCallbacks(e){this.#f=e}subscribe(e){return this.#l.add(e),()=>{this.#l.delete(e)}}prewarm(){if(this.#_!==void 0)return this.#_;if(this.#b!==void 0||this.#o)return Promise.resolve();if(this.#d!==void 0)return this.#d.response.then(e=>{if(e===void 0)throw this.#p??new DOMException(`Session creation was aborted.`,`AbortError`)});let e=this.#e;if(e===void 0)return Promise.reject(Error(`This eve agent store does not own a session client.`));let t=this.#g,n=new AbortController;this.#v=n;let r=(async()=>{try{let r=await e.sessions.create({signal:n.signal});if(t!==this.#g)return;this.#b=r.session,this.#p=void 0,this.#S===`error`&&(this.#S=`ready`),this.#f.onSessionChange?.(r.session.state),this.#R(),this.#D()}catch(e){throw t===this.#g&&this.#d===void 0&&this.#p===void 0&&(this.#p=toError(e),this.#S=`error`,this.#f.onError?.(this.#p),this.#R()),e}})();this.#_=r;let clear=()=>{this.#_===r&&(this.#_=void 0,this.#v=void 0)};return r.then(clear,clear),r}async send(e){return await this.#C(e,this.#f.prepareSend)}async#C(e,t){if(this.#d!==void 0){if(this.#S===`resuming`)throw Error(`eve session is resuming.`);return await this.#T(this.#d,e,t)}let n=createActiveTurn(e=>e.acceptedFollowUps>0&&this.#b!==void 0?this.#b.cancel():e.response.then(e=>e===void 0?{status:`no_active_turn`}:e.cancel()));this.#d=n,this.#p=void 0,this.#S=`submitted`,this.#R();let r;try{let i=await(t===void 0?e:waitWithSignal(Promise.resolve(t(e)),createAbortSignal(e.signal,n.abortController.signal)));if(assertExclusiveTurnInput(i),!this.#A(n))return;let a=this.#h.submit(i,this.#m.length);this.#j(i),this.#R();let o={...i,signal:createAbortSignal(i.signal,n.abortController.signal)},s=await this.#E(o),c=s.response;if(r=s.reader,!this.#A(n))return;n.resolveResponse(c),this.#F(this.#h.correlate(a,getMessageResponseDeliveryId(c),this.#m))&&this.#R();for await(let e of consumeMessageResponse(c,r)){if(!this.#A(n))return;n.receivedFollowUps+=n.receivedFollowUpEvents.get(e)??0,n.receivedFollowUpEvents.delete(e)}if(!this.#A(n)||(await followSteeredTurns(n,r,()=>this.#A(n)),!this.#A(n)))return;this.#S=this.#p===void 0?`ready`:`error`}catch(e){if(!this.#A(n))return;if(isAbortError(e))this.#S=`ready`,this.#h.fail(toError(e));else{let t=this.#p!==void 0;this.#p??=toError(e),this.#S=`error`,this.#h.fail(this.#p),t||this.#f.onError?.(this.#p)}}finally{r?.[Symbol.dispose](),this.#k(n)}}resume(){if(this.#y!==void 0)return this.#y;let e=this.#w();this.#y=e;let clear=()=>{this.#y===e&&(this.#y=void 0)};return e.then(clear,clear),e}async#w(){if(this.#S===`resuming`||this.#S===`streaming`||this.#S===`submitted`)throw Error(`eve session is already processing a turn.`);if(this.#b===void 0)throw Error(`An eve session is required before resuming.`);let e=this.#b,t=createActiveTurn(()=>e.cancel());this.#d=t,t.resolveResponse(void 0),this.#p=void 0,this.#S=`resuming`,this.#R();let n;try{let r=this.#D({catchUp:!0,startIndex:this.#m.length===e.state.streamIndex?e.state.streamIndex:0});if(n=r.subscribe(t.abortController.signal),await r.caughtUp,!this.#A(t))return;n.discard();let i=this.#m.at(-1);if(i!==void 0&&this.#I(i),i!==void 0&&this.#p===void 0&&!isSettledSessionTail(this.#m)){this.#S=`streaming`,this.#R();for await(let e of n){if(!this.#A(t))return;if(t.receivedFollowUps+=t.receivedFollowUpEvents.get(e)??0,t.receivedFollowUpEvents.delete(e),this.#P(e))break}}await followSteeredTurns(t,n,()=>this.#A(t)),this.#A(t)&&(this.#S=this.#p===void 0?`ready`:`error`)}catch(e){if(!this.#A(t))return;isAbortError(e)?this.#S=`ready`:(this.#p=toError(e),this.#S=`error`,this.#f.onError?.(this.#p))}finally{n?.[Symbol.dispose](),this.#k(t)}}cancel(){let e=this.#d;return e===void 0?this.#S===`streaming`&&this.#b!==void 0?this.#b.cancel():Promise.resolve({status:`no_active_turn`}):e.cancel()}[attachStore](){this.#n=!0,this.#t&&this.#b===void 0&&this.prewarm().catch(()=>{})}[detachStore](){this.#n=!1,this.#r?.close(),this.#r=void 0,this.#d?.abortController.abort(),this.#O(),this.#y=void 0}reset(){this.#r?.close(),this.#r=void 0,this.#i.clear(),this.#a.clear();let e=this.#d;this.#d=void 0,e?.resolveResponse(void 0),e?.resolveCompletion(),e?.abortController.abort(),this.#O(),this.#y=void 0,this.#o||(this.#b=void 0),this.#m=[],this.#u=createEventDeduper(),this.#h.reset(),this.#c.reset(),this.#p=void 0,this.#S=`ready`,this.#f.onSessionChange?.(this.#b?.state),this.#R(),this.#t&&this.#n&&this.prewarm().catch(()=>{})}async#T(e,t,n){if(t.message===void 0||t.turnPolicy!==`steer`)throw Error(`eve session is already processing a turn. Send a message with turnPolicy: "steer" to guide it at the next boundary.`);let r=this.#g,i=createAbortSignal(t.signal,e.abortController.signal),a=await waitWithSignal(Promise.resolve(n?.(t)),i)??t;if(r!==this.#g)return;if(assertExclusiveTurnInput(a),a.message===void 0||a.turnPolicy!==`steer`)throw Error(`An in-flight follow-up requires a message with turnPolicy: "steer".`);if(!this.#A(e))return await this.#C(a);let o=this.#h.submit(a,this.#m.length);o!==void 0&&e.followUpSubmissionIds.add(o),this.#R(),this.#D({headers:a.headers,streamReconnectPolicy:a.streamReconnectPolicy});let s;s=(async()=>{try{let t=createAbortSignal(a.signal,e.abortController.signal);if(await waitWithSignal(e.response,t),!this.#A(e)||this.#b===void 0)throw Error(`The active eve turn ended before the follow-up could be sent.`);let{message:n,...r}=a,i=await this.#b.send(n,{...r,signal:t});e.acceptedFollowUps+=1,this.#F(this.#h.correlate(o,getMessageResponseDeliveryId(i),this.#m))&&this.#R()}catch(t){throw this.#A(e)&&(this.#h.fail(toError(t),o),this.#R()),t}finally{e.followUpDispatches.delete(s)}})(),e.followUpDispatches.add(s),await s,await e.completion}async#E(e){let t={headers:e.headers,streamReconnectPolicy:e.streamReconnectPolicy};if(this.#_!==void 0&&(await waitWithSignal(this.#_.catch(e=>{if(this.#b!==void 0)throw e}),e.signal),e.signal?.throwIfAborted()),this.#b===void 0){if(this.#e===void 0)throw Error(`An external eve session is required before sending.`);if(e.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let n=await this.#e.sessions.create({...e,message:e.message});return e.signal?.throwIfAborted(),this.#b=n.session,this.#f.onSessionChange?.(n.session.state),this.#R(),{response:n.response,reader:this.#D(t).subscribe(e.signal)}}let n=this.#D(t).subscribe(e.signal);try{if(e.inputResponses===void 0){let{message:t,...r}=e;return{response:await this.#b.send(t,r),reader:n}}let{inputResponses:t,...r}=e;return{response:await this.#b.respond(t,r),reader:n}}catch(e){throw n[Symbol.dispose](),e}}#D(e={}){if(this.#r!==void 0&&!this.#r.ended)return this.#r.setOptions(e),this.#r;if(this.#b===void 0)throw Error(`A session is required before opening its stream.`);let t=this.#b,n=this.#g;return this.#r=new SessionEventStream(t,{...e,onEvent:e=>{n===this.#g&&this.#M(e)},onError:e=>{n===this.#g&&(this.#r=void 0,this.#d===void 0&&(this.#p=toError(e),this.#S=`error`,this.#f.onError?.(this.#p),this.#R()))}}),this.#r}#O(){this.#g+=1,this.#v?.abort(),this.#v=void 0,this.#_=void 0}#k(e){if(this.#A(e)){e.resolveResponse(void 0),this.#d=void 0;try{this.#f.onSessionChange?.(this.#b?.state),this.#R(),this.#f.onFinish?.(this.#x)}finally{e.resolveCompletion()}}}#A(e){return this.#d===e}#j(e){e.inputResponses!==void 0&&e.inputResponses.length!==0&&this.#c.append({data:{createdAt:Date.now(),responses:e.inputResponses},type:`client.input.responded`})}#M(e){if(!this.#u.admit(e))return;let t=this.#S===`streaming`;this.#N(e),this.#m=[...this.#m,e],this.#F(this.#h.apply(e)),this.#f.onEvent?.(e),this.#I(e);let n=this.#P(e);this.#S!==`resuming`&&this.#p===void 0&&(`data`in e&&`turnId`in e.data&&(this.#S=`streaming`),this.#d===void 0&&n&&(this.#S=`ready`)),this.#f.onSessionChange?.(this.#b?.state),this.#S!==`resuming`&&this.#R(),this.#d===void 0&&t&&n&&this.#f.onFinish?.(this.#x)}#N(e){updatePendingAuthorizations(this.#i,e),updatePendingInputRequests(this.#a,e)}#P(e){return isTurnSegmentBoundary(e,this.#a)&&this.#i.size===0}#F(e){if(e===void 0)return!1;let t=0;for(let n of e.ids)this.#d?.followUpSubmissionIds.delete(n)&&(t+=1);if(t>0&&this.#d!==void 0){if(e.alreadyProjected)this.#d.receivedFollowUps+=t;else{let n=this.#d.receivedFollowUpEvents.get(e.event)??0;this.#d.receivedFollowUpEvents.set(e.event,n+t)}}return!0}#I(e){let t=toTerminalStreamFailureError(e);t!==void 0&&(this.#S=`error`,this.#h.failAll(t),this.#p===void 0&&(this.#p=t,this.#f.onError?.(t)))}#L(){return{data:this.#c.data,error:this.#p,events:this.#m,session:this.#b?.state,status:this.#S}}#R(){this.#x=this.#L();for(let e of this.#l)e()}};function detachEveAgentStore(e){e[detachStore]()}function attachEveAgentStore(e){e[attachStore]()}export{EveAgentStore,attachEveAgentStore,detachEveAgentStore};
1
+ import{toError}from"#shared/errors.js";import{activeTurnForOptimisticFollowUp,assertAnswerable,assertExclusiveTurnInput,assertInFlightFollowUp,countFollowUpDeliveries,createAbortSignal,createActiveTurn,followSteeredTurns,isAbortError,isResponseBoundary,isSettledSessionTail,settledStatus,toTerminalStreamFailureError,validateFollowUp,waitWithSignal}from"#client/eve-agent-store-helpers.js";import{EveAgentProjection}from"#client/eve-agent-projection.js";import{Client}from"#client/client.js";import{consumeMessageResponse,getMessageResponseDeliveryId}from"#client/message-response.js";import{OptimisticMessageSubmissions}from"#client/optimistic-message-submissions.js";import{ConversationClient}from"#client/conversation-client.js";import{dispatchSessionTurn}from"#client/session-turn-dispatch.js";const detachStore=Symbol(`detachEveAgentStore`),attachStore=Symbol(`attachEveAgentStore`);var EveAgentStore=class{#e;#t;#n=!1;#r;#i;#a;#o=new Set;#s;#c={};#l;#u;#d;#f=0;#p;#m;#h;#g;#_;#v=`ready`;constructor(e){this.#t=e.prewarm??!1,this.#i=e.followSubagents??!1,this.#a=e.session!==void 0,this.#e=this.#a?void 0:e.client??new Client({auth:e.auth,headers:e.headers,host:e.host??``}),this.#r=new ConversationClient(new EveAgentProjection(e.reducer,[]),()=>this.#F(),()=>this.#F()),this.#u=(e.initialEvents??[]).filter(e=>this.#r.hydrate(e)),this.#d=new OptimisticMessageSubmissions(this.#r.projections,e.optimistic??!0),this.#g=e.session??(e.initialSession===void 0?void 0:this.#e?.sessions.attach(e.initialSession.sessionId,{streamIndex:e.initialSession.streamIndex})),this.#_=this.#P()}get snapshot(){return this.#_}setCallbacks(e){this.#c=e}subscribe(e){return this.#o.add(e),()=>void this.#o.delete(e)}prewarm(){if(this.#p!==void 0)return this.#p;if(this.#g!==void 0||this.#a)return Promise.resolve();if(this.#s!==void 0)return this.#s.response.then(e=>{if(e===void 0)throw this.#l??new DOMException(`Session creation was aborted.`,`AbortError`)});let e=this.#e;if(e===void 0)return Promise.reject(Error(`This eve agent store does not own a session client.`));let t=this.#f,n=new AbortController;this.#m=n;let r=(async()=>{try{let r=await e.sessions.create({signal:n.signal});if(t!==this.#f)return;this.#l=void 0,this.#v===`error`&&(this.#v=`ready`),this.#w(r.session),this.#C()}catch(e){throw t===this.#f&&this.#s===void 0&&this.#l===void 0&&this.#T(e),e}})();this.#p=r;let clear=()=>{this.#p===r&&(this.#p=void 0,this.#m=void 0)};return r.then(clear,clear),r}async send(e){return await this.#y(e,this.#c.prepareSend)}async#y(e,t){if(assertAnswerable(e,this.#r.conversation),this.#s!==void 0){if(this.#v===`resuming`)throw Error(`eve session is resuming.`);return await this.#x(this.#s,e,t)}let n=createActiveTurn(e=>e.acceptedFollowUps>0&&this.#g!==void 0?this.#g.cancel():e.response.then(e=>e===void 0?{status:`no_active_turn`}:e.cancel()));this.#s=n,this.#l=void 0,this.#v=`submitted`;let r,i,a;try{assertExclusiveTurnInput(e),i=this.#d.submit(e,this.#u.length),a=this.#r.projectResponses(e.inputResponses),this.#F();let o=await(t===void 0?e:waitWithSignal(Promise.resolve(t(e)),createAbortSignal(e.signal,n.abortController.signal)));if(assertExclusiveTurnInput(o),!this.#k(n))return;o!==e&&(i=this.#d.resubmit(i,o),a=this.#r.replaceResponses(a,o),this.#F());let s={...o,signal:createAbortSignal(o.signal,n.abortController.signal)},c=await this.#S(s);a=void 0;let l=c.response;if(r=c.reader,!this.#k(n))return;n.resolveResponse(l),this.#j(i,l);for await(let e of consumeMessageResponse(l,r)){if(!this.#k(n))return;n.receivedFollowUps+=n.receivedFollowUpEvents.get(e)??0,n.receivedFollowUpEvents.delete(e)}if(!this.#k(n)||(await followSteeredTurns(n,r,()=>this.#k(n)),!this.#k(n)))return;this.#v=settledStatus(this.#l,this.#r.conversation)}catch(e){if(!this.#k(n))return;if(a?.(),isAbortError(e))this.#v=`ready`,this.#d.fail(toError(e),i);else{let t=this.#l!==void 0;this.#l??=toError(e),this.#v=`error`,this.#d.fail(this.#l,i),t||this.#c.onError?.(this.#l)}}finally{r?.[Symbol.dispose](),this.#O(n)}}resume(){if(this.#h!==void 0)return this.#h;let e=this.#b();this.#h=e;let clear=()=>{this.#h===e&&(this.#h=void 0)};return e.then(clear,clear),e}async#b(){if(this.#v!==`ready`&&this.#v!==`error`)throw Error(`eve session is already processing a turn.`);if(this.#g===void 0)throw Error(`An eve session is required before resuming.`);let e=this.#g,t=createActiveTurn(()=>e.cancel());this.#s=t,t.resolveResponse(void 0),this.#l=void 0,this.#v=`resuming`,this.#F();let n;try{let r=this.#C({catchUp:!0,startIndex:this.#u.length===e.state.streamIndex?e.state.streamIndex:0});if(n=r.subscribe(t.abortController.signal),await r.caughtUp,!this.#k(t))return;n.discard();let i=this.#u.at(-1);if(i!==void 0&&this.#N(i),i&&!this.#l&&!isSettledSessionTail(this.#u,this.#r.conversation)){this.#v=`streaming`,this.#F();for await(let e of n){if(!this.#k(t))return;if(t.receivedFollowUps+=t.receivedFollowUpEvents.get(e)??0,t.receivedFollowUpEvents.delete(e),isResponseBoundary(e,this.#r.conversation))break}}await followSteeredTurns(t,n,()=>this.#k(t)),this.#k(t)&&(this.#v=settledStatus(this.#l,this.#r.conversation))}catch(e){if(!this.#k(t))return;isAbortError(e)?this.#v=`ready`:(this.#l=toError(e),this.#v=`error`,this.#c.onError?.(this.#l))}finally{n?.[Symbol.dispose](),this.#O(t)}}cancel(){let e=this.#s;return e===void 0?this.#v===`streaming`&&this.#g!==void 0?this.#g.cancel():Promise.resolve({status:`no_active_turn`}):e.cancel()}async compact(){return await this.#g?.compact()??{status:`no_active_session`}}async clear(){return await this.#g?.clear()??{status:`no_active_session`}}async retire(){if(this.#a)throw Error(`retire() needs a store-owned session. Call reset() on the session you supplied, then create a new store for the next session.`);let e=await this.#g?.reset()??{status:`no_active_session`};return this.reset(),e}[attachStore](){this.#n=!0,this.#i&&!this.#r.following&&this.#E(),this.#t&&this.#g===void 0&&this.prewarm().catch(()=>{})}[detachStore](){this.#n=!1,this.#r.stop(),this.#s?.abortController.abort(),this.#D(),this.#h=void 0}reset(){this.#r.stop();let e=this.#s;this.#s=void 0,e?.resolveResponse(void 0),e?.resolveCompletion(),e?.abortController.abort(),this.#D(),this.#h=void 0,this.#a||(this.#g=void 0),this.#u=[],this.#r.reset(),this.#d.reset(),this.#i&&this.#n&&this.#E(),this.#l=void 0,this.#v=`ready`,this.#c.onSessionChange?.(this.#g?.state),this.#F(),this.#t&&this.#n&&this.prewarm().catch(()=>{})}async#x(e,t,n){assertInFlightFollowUp(t);let r=this.#f,i=createAbortSignal(t.signal,e.abortController.signal),a=this.#r.projectResponses(t.inputResponses),o=await waitWithSignal(Promise.resolve(n?.(t)),i).then(e=>{let n=validateFollowUp(e??t);return n===t||(a=this.#r.replaceResponses(a,n)),n}).catch(e=>{throw a?.(),e});if(r!==this.#f)return;if(!this.#k(e))return a?.(),await this.#y(o);let s=this.#d.submit(o,this.#u.length,activeTurnForOptimisticFollowUp(this.#u));s!==void 0&&e.followUpSubmissionIds.add(s),this.#F();let c;c=(async()=>{try{let t=createAbortSignal(o.signal,e.abortController.signal);if(await waitWithSignal(e.response,t),!this.#k(e)||this.#g===void 0)throw Error(`The active eve turn ended before the follow-up could be sent.`);this.#C({headers:o.headers,streamReconnectPolicy:o.streamReconnectPolicy});let n=(await dispatchSessionTurn({session:this.#g,turn:{...o,signal:t}})).response;if(a=void 0,o.message===void 0)return;e.acceptedFollowUps+=1,this.#j(s,n)}catch(t){throw this.#k(e)&&(this.#d.fail(toError(t),s),a?.(),this.#F()),t}finally{e.followUpDispatches.delete(c)}})(),e.followUpDispatches.add(c),await c,await e.completion}async#S(e){let t={headers:e.headers,streamReconnectPolicy:e.streamReconnectPolicy};this.#p!==void 0&&(await waitWithSignal(this.#p.catch(e=>{if(this.#g!==void 0)throw e}),e.signal),e.signal?.throwIfAborted());let n=this.#g,r;try{let i=await dispatchSessionTurn({client:this.#e,session:n,turn:e,beforeSend:()=>{r=this.#C(t).subscribe(e.signal)}});return i.created&&(this.#w(i.session),r=this.#C(t).subscribe(e.signal)),{response:i.response,reader:r}}catch(e){throw r?.[Symbol.dispose](),e}}#C(e={}){if(this.#g===void 0)throw Error(`A session is required before opening its stream.`);let t=this.#f;return this.#i&&!this.#r.following&&this.#E(),this.#r.stream(this.#g,{...e,onEvent:e=>{t===this.#f&&this.#A(e)},onError:e=>{t===this.#f&&this.#s===void 0&&this.#T(e)}})}#w(e){this.#g=e,this.#i&&this.#n&&this.#E(),this.#c.onSessionChange?.(e.state),this.#F()}#T(e){this.#l=toError(e),this.#v=`error`,this.#c.onError?.(this.#l),this.#F()}#E(){this.#g&&this.#r.follow(this.#g,this.#u)}#D(){this.#f+=1,this.#m?.abort(),this.#m=void 0,this.#p=void 0}#O(e){if(this.#k(e)){e.resolveResponse(void 0),this.#s=void 0;try{this.#c.onSessionChange?.(this.#g?.state),this.#F(),this.#c.onFinish?.(this.#_)}finally{e.resolveCompletion()}}}#k(e){return this.#s===e}#A(e){let t=this.#v===`streaming`;if(!this.#r.observe(e,{onAccepted:()=>{this.#u=[...this.#u,e]},project:e=>{this.#M(this.#d.apply(e))},notify:!1}))return!1;this.#c.onEvent?.(e),this.#N(e);let{conversation:n}=this.#r,r=isSettledSessionTail(this.#u,n)&&n.activeTurnId===void 0;return this.#v!==`resuming`&&this.#l===void 0&&(`data`in e&&e.data!==void 0&&`turnId`in e.data&&(this.#v=`streaming`),this.#s===void 0&&r&&(this.#v=`ready`)),this.#c.onSessionChange?.(this.#g?.state),this.#v!==`resuming`&&this.#F(),this.#s===void 0&&t&&r&&this.#c.onFinish?.(this.#_),!0}#j(e,t){let n=getMessageResponseDeliveryId(t),r=this.#d.correlate(e,n,this.#u);this.#M(r)&&this.#F()}#M(e){return e!==void 0&&(this.#s!==void 0&&countFollowUpDeliveries(this.#s,e),!0)}#N(e){let t=toTerminalStreamFailureError(e);t!==void 0&&(this.#v=`error`,this.#d.failAll(t),this.#l===void 0&&(this.#l=t,this.#c.onError?.(t)))}#P(){return{data:this.#r.data,conversation:this.#r.conversation,error:this.#l,events:this.#u,session:this.#g?.state,status:this.#v}}#F(){this.#_=this.#P();for(let e of this.#o)e()}};function detachEveAgentStore(e){e[detachStore]()}function attachEveAgentStore(e){e[attachStore]()}export{EveAgentStore,attachEveAgentStore,detachEveAgentStore};
@@ -4,6 +4,9 @@ export { AgentInfoResponseError } from "#client/agent-info-error.js";
4
4
  export { HealthResponseError } from "#client/health-response-error.js";
5
5
  export { ClientError } from "#client/client-error.js";
6
6
  export { defaultMessageReducer } from "#client/message-reducer.js";
7
+ export { conversationReducer } from "#client/conversation-reducer.js";
8
+ export { openConversationInputs } from "#client/conversation-state.js";
9
+ export type { AgentObservation, ConversationAgentSession, ConversationInput, ConversationState, ConversationTask, ConversationTaskCall, ConversationTurn, } from "#client/conversation-state.js";
7
10
  export { createDataUrlFilePart, createTextWithFileContent } from "#client/file-parts.js";
8
11
  export { MessageResponse } from "#client/message-response.js";
9
12
  export { ClientAgentSession } from "#client/agent-session.js";
@@ -13,7 +16,7 @@ export type { EveAgentStoreCallbacks, EveAgentStoreInit, EveAgentStoreSnapshot,
13
16
  export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoRemoteAgentEntry, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClearResult, CompactResult, ClientAuth, ClientOptions, ClientRedirectPolicy, CreateSessionOptions, HeadersValue, HealthResult, MessageResult, RespondTurnOptions, ResetResult, ResolvedStreamReconnectPolicy, SendTurnInput, SendTurnOptions, SessionSnapshot, ClientSessionState, StreamOptions, StreamReconnectPolicy, StreamReconnectRetryPolicy, TokenValue, } from "#client/types.js";
14
17
  export type { EveAgentReducer, EveAgentReducerEvent, ClientInputRespondedEvent, ClientMessageFailedEvent, ClientMessageSubmittedEvent, } from "#client/reducer.js";
15
18
  export type { EveAuthorizationChallenge, EveAuthorizationOutcome, EveAuthorizationPart, EveMessageData, EveDynamicToolPart, EveMessageInputRequest, EveMessage, EveMessageMetadata, EveMessagePart, EveMessageToolMetadata, } from "#client/message-reducer.js";
16
- export type { ActionPartialStreamEvent, ActionResultStreamEvent, ActionsRequestedStreamEvent, AgentStartedStreamEvent, AssistantStepFinishReason, AuthorizationOutcome, CompactionCompletedStreamEvent, CompactionRequestedStreamEvent, AuthorizationCompletedStreamEvent, ConnectionAuthorizationOutcome, AuthorizationRequiredStreamEvent, HandleMessageStreamEvent, MessageStreamEventMeta, InputResolution, InputResolutionOutcome, InputResolvedStreamEvent, InputRequestedStreamEvent, MessageAppendedStreamEvent, MessageCompletedStreamEvent, MessageReceivedPart, MessageReceivedStreamEvent, ReasoningAppendedStreamEvent, ReasoningCompletedStreamEvent, ResultCompletedStreamEvent, RuntimeTraceContext, SessionCompletedStreamEvent, SessionFailedStreamEvent, SessionStartedStreamEvent, SessionWaitingStreamEvent, MessageStreamEvent, StepCompletedStreamEvent, StepFailedStreamEvent, StepStartedStreamEvent, TaskSettledStreamEvent, TaskStartedStreamEvent, TurnCancelledStreamEvent, TurnCompletedStreamEvent, TurnFailedStreamEvent, TurnStartedStreamEvent, TurnFailureStreamEvent, TurnWaitingStreamEvent, } from "#protocol/message.js";
19
+ export type { ActionPartialStreamEvent, ActionResultStreamEvent, ActionsRequestedStreamEvent, AgentStartedStreamEvent, AssistantStepFinishReason, AuthorizationOutcome, CompactionCompletedStreamEvent, CompactionRequestedStreamEvent, AuthorizationCompletedStreamEvent, ConnectionAuthorizationOutcome, AuthorizationRequiredStreamEvent, HandleMessageStreamEvent, MessageStreamEventMeta, InputResolution, InputResolutionOutcome, InputResolvedStreamEvent, InputRequestedStreamEvent, MessageAppendedStreamEvent, MessageCompletedStreamEvent, MessageReceivedPart, MessageReceivedStreamEvent, ReasoningAppendedStreamEvent, ReasoningCompletedStreamEvent, ResultCompletedStreamEvent, RuntimeTraceContext, SessionCompletedStreamEvent, SessionFailedStreamEvent, SessionStartedStreamEvent, SessionWaitingStreamEvent, MessageStreamEvent, StepCompletedStreamEvent, StepFailedStreamEvent, StepStartedStreamEvent, TaskSettledStreamEvent, TaskStartedStreamEvent, TurnCancelledStreamEvent, TurnCompletedStreamEvent, TurnFailedStreamEvent, TurnStartedStreamEvent, TurnFailureStreamEvent, TurnWaitingOn, TurnWaitingStreamEvent, } from "#protocol/message.js";
17
20
  export { isCurrentTurnBoundaryEvent, isTurnFailureEvent } from "#protocol/message.js";
18
21
  export type { InputOption, InputRequest, InputRequestKind, InputResponse } from "#shared/input.js";
19
22
  export { isInputRequest, isInputResponse, parseInputResponse, parseInputResponses, } from "#shared/input.js";
@@ -1 +1 @@
1
- import{isInputRequest,isInputResponse,parseInputResponse,parseInputResponses}from"#shared/input.js";import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";import{AgentInfoResponseError}from"#client/agent-info-error.js";import{HealthResponseError}from"#client/health-response-error.js";import{ClientError}from"#client/client-error.js";import{ClientSessions}from"#client/sessions.js";import{Client}from"#client/client.js";import{MessageResponse}from"#client/message-response.js";import{EveAgentStore}from"#client/eve-agent-store.js";import{defaultMessageReducer}from"#client/message-reducer.js";import{createDataUrlFilePart,createTextWithFileContent}from"#client/file-parts.js";import{ClientAgentSession}from"#client/agent-session.js";import{ClientSession}from"#client/session.js";import{resolveTextToResponse,resolveTextToResponses}from"#channel/resolve-text.js";export{AgentInfoResponseError,Client,ClientAgentSession,ClientError,ClientSession,ClientSessions,EveAgentStore,HealthResponseError,MessageResponse,createDataUrlFilePart,createTextWithFileContent,defaultMessageReducer,isCurrentTurnBoundaryEvent,isInputRequest,isInputResponse,isTurnFailureEvent,parseInputResponse,parseInputResponses,resolveTextToResponse,resolveTextToResponses};
1
+ import{isInputRequest,isInputResponse,parseInputResponse,parseInputResponses}from"#shared/input.js";import{openConversationInputs}from"#client/conversation-state.js";import{EveAgentStore}from"#client/eve-agent-store.js";import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";import{AgentInfoResponseError}from"#client/agent-info-error.js";import{HealthResponseError}from"#client/health-response-error.js";import{ClientError}from"#client/client-error.js";import{ClientSessions}from"#client/sessions.js";import{conversationReducer}from"#client/conversation-reducer.js";import{defaultMessageReducer}from"#client/message-reducer.js";import{Client}from"#client/client.js";import{MessageResponse}from"#client/message-response.js";import{createDataUrlFilePart,createTextWithFileContent}from"#client/file-parts.js";import{ClientAgentSession}from"#client/agent-session.js";import{ClientSession}from"#client/session.js";import{resolveTextToResponse,resolveTextToResponses}from"#channel/resolve-text.js";export{AgentInfoResponseError,Client,ClientAgentSession,ClientError,ClientSession,ClientSessions,EveAgentStore,HealthResponseError,MessageResponse,conversationReducer,createDataUrlFilePart,createTextWithFileContent,defaultMessageReducer,isCurrentTurnBoundaryEvent,isInputRequest,isInputResponse,isTurnFailureEvent,openConversationInputs,parseInputResponse,parseInputResponses,resolveTextToResponse,resolveTextToResponses};
@@ -2,6 +2,5 @@ import type { EveMessage, EveMessageData, EveMessagePart } from "#client/message
2
2
  import type { MessageReceivedPart } from "#protocol/message.js";
3
3
  export declare function projectReceivedParts(parts: readonly MessageReceivedPart[] | undefined, message: string): readonly EveMessagePart[];
4
4
  export declare function partKey(part: EveMessagePart): string;
5
- export declare function upsertMessage(data: EveMessageData, next: EveMessage): EveMessageData;
6
- export declare function removeStreamingToolPartsForTurn(data: EveMessageData, turnId: string): EveMessageData;
5
+ export declare function upsertMessage(data: EveMessageData, next: EveMessage, beforeAssistantTurnId?: string): EveMessageData;
7
6
  export declare function optimisticUserMessageId(submissionId: string): string;
@@ -1 +1 @@
1
- function projectReceivedParts(e,t){return e?.map(e=>e.type===`text`?{state:`done`,text:e.text,type:`text`}:{filename:e.filename,mediaType:e.mediaType,size:e.size,type:`file`,url:e.url})??[{state:`done`,text:t,type:`text`}]}function partKey(e){switch(e.type){case`text`:return`text:${e.stepIndex??0}`;case`reasoning`:return`reasoning:${e.stepIndex??0}`;case`file`:return`file:${e.stepIndex??0}:${e.filename??e.url??e.mediaType}`;case`step-start`:return`step-start`;case`authorization`:return`authorization:${e.turnId}:${e.stepIndex}:${e.name}`;case`dynamic-tool`:return`dynamic-tool:${e.toolCallId}`}}function upsertMessage(e,t){let n=e.messages.findIndex(e=>e.id===t.id);return n===-1?{messages:[...e.messages,t]}:{messages:[...e.messages.slice(0,n),t,...e.messages.slice(n+1)]}}function removeStreamingToolPartsForTurn(e,t){let n=e.messages.findIndex(e=>e.role===`assistant`&&e.metadata?.turnId===t),r=e.messages[n];return r===void 0?e:upsertMessage(e,{...r,parts:r.parts.filter(e=>e.type!==`dynamic-tool`||e.state!==`input-streaming`)})}function optimisticUserMessageId(e){return`optimistic:${e}:user`}export{optimisticUserMessageId,partKey,projectReceivedParts,removeStreamingToolPartsForTurn,upsertMessage};
1
+ function projectReceivedParts(e,t){return e?.map(e=>e.type===`text`?{state:`done`,text:e.text,type:`text`}:{filename:e.filename,mediaType:e.mediaType,size:e.size,type:`file`,url:e.url})??[{state:`done`,text:t,type:`text`}]}function partKey(e){switch(e.type){case`text`:return`text:${e.stepIndex??0}`;case`reasoning`:return`reasoning:${e.stepIndex??0}`;case`file`:return`file:${e.stepIndex??0}:${e.filename??e.url??e.mediaType}`;case`step-start`:return`step-start`;case`authorization`:return e.attemptId===void 0?`authorization:${e.turnId}:${e.stepIndex}:${e.name}`:`authorization:${e.attemptId}`;case`dynamic-tool`:return`dynamic-tool:${e.toolCallId}`}}function upsertMessage(e,t,n){let r=e.messages.findIndex(e=>e.id===t.id);if(r!==-1)return{...e,messages:[...e.messages.slice(0,r),t,...e.messages.slice(r+1)]};let i=n===void 0?-1:e.messages.findIndex(e=>e.role===`assistant`&&e.metadata?.turnId===n);return i===-1?{...e,messages:[...e.messages,t]}:{...e,messages:[...e.messages.slice(0,i),t,...e.messages.slice(i)]}}function optimisticUserMessageId(e){return`optimistic:${e}:user`}export{optimisticUserMessageId,partKey,projectReceivedParts,upsertMessage};
@@ -38,15 +38,19 @@ export interface EveMessageMetadata {
38
38
  * or `"done"`; `file` carries user-attachment metadata; `step-start` marks the
39
39
  * boundary of an agent step; and `dynamic-tool` ({@link EveDynamicToolPart})
40
40
  * holds the tool call and its lifecycle state. `stepIndex` ties a part to the
41
- * agent step that produced it.
41
+ * agent step that produced it. Assistant text and reasoning parts carry an
42
+ * `id` from the event that created the run. It survives appends and completion;
43
+ * a null completion removes the part. User text may not have an `id`.
42
44
  */
43
45
  export type EveMessagePart = {
46
+ readonly id?: string;
44
47
  readonly providerMetadata?: Record<string, unknown>;
45
48
  readonly state?: "done" | "streaming";
46
49
  readonly stepIndex?: number;
47
50
  readonly text: string;
48
51
  readonly type: "text";
49
52
  } | {
53
+ readonly id?: string;
50
54
  readonly providerMetadata?: Record<string, unknown>;
51
55
  readonly state?: "done" | "streaming";
52
56
  readonly stepIndex?: number;
@@ -80,7 +84,7 @@ export interface EveAuthorizationChallenge {
80
84
  export type EveAuthorizationOutcome = AuthorizationOutcome;
81
85
  /**
82
86
  * An authorization prompt or result. The default reducer projects
83
- * `authorization.required` into a pending part so browser chat UIs can render a
87
+ * `authorization.required` into a `required` part so browser chat UIs can render a
84
88
  * sign-in affordance, then updates it when `authorization.completed` arrives.
85
89
  */
86
90
  export type EveAuthorizationPart = {
@@ -88,6 +92,9 @@ export type EveAuthorizationPart = {
88
92
  readonly description: string;
89
93
  readonly displayName: string;
90
94
  readonly name: string;
95
+ readonly attemptId?: string;
96
+ /** The sign-in's callback settles this attempt and resumes the parked turn. */
97
+ readonly awaitsCallback?: boolean;
91
98
  readonly stepIndex: number;
92
99
  readonly turnId: string;
93
100
  readonly type: "authorization";
@@ -1 +1 @@
1
- import{createAuthorizationCompletedPart,createAuthorizationRequiredPart}from"#client/authorization-message-parts.js";import{approvedApproval,createToolMetadata,mergeToolMetadata,normalizeActionRequest,normalizeActionResult,stringifyUnknown,toMessageInputRequest}from"#client/message-action-parts.js";import{optimisticUserMessageId,partKey,projectReceivedParts,removeStreamingToolPartsForTurn,upsertMessage}from"#client/message-reducer-primitives.js";import{messageRun}from"#client/message-run-parts.js";import{createSettledTaskPart}from"#client/message-task-parts.js";function receivedMessageEventId(e){return e.meta.id??`${e.data.turnId}:${e.data.sequence}`}function defaultMessageReducer(){return{initial(){return{messages:[]}},reduce(e,t){return reduceMessageData(e,t)}}}function reduceMessageData(e,t){switch(t.type){case`client.message.submitted`:return upsertMessage(e,{id:optimisticUserMessageId(t.data.submissionId),metadata:{optimistic:!0,status:`submitted`},parts:[{type:`text`,text:t.data.message}],role:`user`});case`client.message.failed`:return upsertMessage(e,{id:optimisticUserMessageId(t.data.submissionId),metadata:{optimistic:!0,status:`failed`},parts:[{type:`text`,text:t.data.message}],role:`user`});case`input.resolved`:{let n=e;for(let e of t.data.resolutions)n=resolveInputRequest(n,e);return n}case`message.received`:return upsertMessage(e,{id:`${receivedMessageEventId(t)}:user`,metadata:{status:`complete`,turnId:t.data.turnId},parts:projectReceivedParts(t.data.parts,t.data.message),role:`user`});case`step.started`:return updateAssistantMessage(e,t.data.turnId,e=>ensureStepStartPart(e,t.data.stepIndex));case`reasoning.appended`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.append(ensureStepStartPart(e,t.data.stepIndex),{delta:t.data.reasoningDelta,stepIndex:t.data.stepIndex,type:`reasoning`}));case`reasoning.completed`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.upsert(ensureStepStartPart(e,t.data.stepIndex),{state:`done`,stepIndex:t.data.stepIndex,text:t.data.reasoning,type:`reasoning`}));case`action.input.appended`:{let n=findToolPart(e,t.data.callId);if(n!==void 0&&n.state!==`input-streaming`)return e;let r={input:void 0,inputText:(n?.state===`input-streaming`?n.inputText:``)+t.data.inputTextDelta,state:`input-streaming`,stepIndex:t.data.stepIndex,toolCallId:t.data.callId,toolMetadata:n?.toolMetadata??{eve:{kind:`unknown`,name:t.data.toolName}},toolName:t.data.toolName,type:`dynamic-tool`};return n===void 0?updateAssistantMessage(e,t.data.turnId,e=>upsertPart(ensureStepStartPart(e,t.data.stepIndex),r)):updateToolPart(e,t.data.callId,r)}case`actions.requested`:{let n=e;for(let e of t.data.actions){let r=normalizeActionRequest(e);n=updateAssistantMessage(n,t.data.turnId,n=>upsertPart(ensureStepStartPart(n,t.data.stepIndex),{input:`input`in e?e.input:void 0,state:`input-available`,stepIndex:t.data.stepIndex,toolCallId:e.callId,toolMetadata:createToolMetadata(r),toolName:r.toolName,type:`dynamic-tool`}))}return n}case`input.requested`:{let n=e;for(let e of t.data.requests){let r=normalizeActionRequest(e.action);n=updateAssistantMessage(n,t.data.turnId,n=>upsertPart(ensureStepStartPart(n,t.data.stepIndex),{approval:{id:e.requestId},input:e.action.input,state:`approval-requested`,stepIndex:t.data.stepIndex,toolCallId:e.action.callId,toolMetadata:createToolMetadata(r,{inputRequest:toMessageInputRequest(e)}),toolName:r.toolName,type:`dynamic-tool`}))}return n}case`approval.candidate`:return e;case`approval.settled`:{let n=findToolPartByApprovalId(e,t.data.requestId);return n===void 0?e:t.data.outcome===`approved`?updateToolPart(e,n.toolCallId,{approval:{approved:!0,id:t.data.requestId,reason:void 0},input:n.input,state:`approval-responded`,stepIndex:n.stepIndex,toolCallId:n.toolCallId,toolMetadata:n.toolMetadata,toolName:n.toolName,type:`dynamic-tool`}):updateToolPart(e,n.toolCallId,{approval:{approved:!1,id:t.data.requestId,reason:`Tool execution was cancelled.`},input:n.input,state:`output-denied`,stepIndex:n.stepIndex,toolCallId:n.toolCallId,toolMetadata:n.toolMetadata,toolName:n.toolName,type:`dynamic-tool`})}case`action.result`:{let n=normalizeActionResult(t.data.result),r=findToolPart(e,t.data.result.callId),i=t.data.error?.code===`TOOL_EXECUTION_DENIED`,a=t.data.status===`failed`&&!i,o=r?.approval?.id??t.data.result.callId,s=mergeToolMetadata(r?.toolMetadata,createToolMetadata(n)),c={input:r?.input,stepIndex:t.data.stepIndex,toolCallId:t.data.result.callId,toolMetadata:s,toolName:r?.toolName??n.toolName,type:`dynamic-tool`},l;return l=i?{...c,approval:{approved:!1,id:o,reason:t.data.error?.message},state:`output-denied`}:a?{...c,approval:approvedApproval(r),errorText:t.data.error?.message??stringifyUnknown(t.data.result.output),state:`output-error`}:{...c,approval:approvedApproval(r),output:t.data.result.output,state:`output-available`},r===void 0?updateAssistantMessage(e,t.data.turnId,e=>upsertPart(ensureStepStartPart(e,t.data.stepIndex),l)):updateToolPart(e,t.data.result.callId,l)}case`action.partial`:{let n=findToolPart(e,t.data.result.callId);if(n!==void 0&&isSettledToolPart(n))return e;let r=normalizeActionResult(t.data.result),i={approval:approvedApproval(n),input:n?.input,output:t.data.result.output,partial:!0,state:`output-available`,stepIndex:t.data.stepIndex,toolCallId:t.data.result.callId,toolMetadata:mergeToolMetadata(n?.toolMetadata,createToolMetadata(r)),toolName:n?.toolName??r.toolName,type:`dynamic-tool`};return n===void 0?updateAssistantMessage(e,t.data.turnId,e=>upsertPart(ensureStepStartPart(e,t.data.stepIndex),i)):updateToolPart(e,t.data.result.callId,i)}case`task.settled`:{let n=findToolPart(e,t.data.callId);return n===void 0?e:replaceToolPart(e,createSettledTaskPart(n,t))}case`authorization.required`:return updateAssistantMessage(e,t.data.turnId,e=>upsertPart(ensureStepStartPart(e,t.data.stepIndex),createAuthorizationRequiredPart(t)));case`authorization.completed`:return completeAuthorization(e,t);case`message.appended`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.append(ensureStepStartPart(e,t.data.stepIndex),{delta:t.data.messageDelta,stepIndex:t.data.stepIndex,type:`text`}));case`message.completed`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.upsert(ensureStepStartPart(e,t.data.stepIndex),{state:`done`,stepIndex:t.data.stepIndex,text:t.data.message,type:`text`}));case`result.completed`:return updateAssistantMetadata(e,t.data.turnId,{result:t.data.result});case`turn.completed`:return updateAssistantMessage(e,t.data.turnId,e=>({...e,metadata:{...e.metadata,status:`complete`},parts:removeStreamingToolParts(e.parts)}));case`turn.cancelled`:return updateAssistantMessage(e,t.data.turnId,e=>({...e,metadata:{...e.metadata,status:`complete`},parts:removeStreamingToolParts(e.parts.map(e=>(e.type===`text`||e.type===`reasoning`)&&e.state===`streaming`?{...e,state:`done`}:e))}));case`turn.failed`:return removeStreamingToolPartsForTurn(e,t.data.turnId);case`session.failed`:return e;default:return e}}function removeStreamingToolParts(e){return e.filter(e=>e.type!==`dynamic-tool`||e.state!==`input-streaming`)}function respondToInputRequest(e,t){let n=findToolPartByApprovalId(e,t.requestId);if(!n)return e;let r={id:t.requestId};return t.text!==void 0&&(r.reason=t.text),updateToolPart(e,n.toolCallId,{approval:r,input:n.input,state:`approval-responded`,stepIndex:n.stepIndex,toolCallId:n.toolCallId,toolMetadata:mergeToolMetadata(n.toolMetadata,{eve:{inputResponse:t,kind:n.toolMetadata?.eve?.kind??`unknown`,name:n.toolMetadata?.eve?.name??n.toolName}}),toolName:n.toolName,type:`dynamic-tool`})}function resolveInputRequest(e,t){if(t.response!==void 0)return respondToInputRequest(e,t.response);let n=findToolPartByApprovalId(e,t.requestId);return n?updateToolPart(e,n.toolCallId,{input:n.input,output:{status:t.outcome},state:`output-available`,stepIndex:n.stepIndex,toolCallId:n.toolCallId,toolMetadata:n.toolMetadata,toolName:n.toolName,type:`dynamic-tool`}):e}function updateAssistantMessage(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.metadata?.turnId===t)??createAssistantMessage(t);return upsertMessage(e,n(r))}function updateAssistantMetadata(e,t,n){return updateAssistantMessage(e,t,e=>({...e,metadata:{...e.metadata,...n}}))}function createAssistantMessage(e){return{id:`${e}:assistant`,metadata:{status:`streaming`,turnId:e},parts:[],role:`assistant`}}function ensureStepStartPart(e,t){let n=e.parts.filter(e=>e.type===`step-start`).length;if(n>t)return e;let r=t-n+1;return{...e,parts:[...e.parts,...Array.from({length:r},()=>({type:`step-start`}))]}}function upsertPart(e,t){let n=e.parts.findIndex(e=>partKey(e)===partKey(t)),r=n===-1?[...e.parts,t]:[...e.parts.slice(0,n),t,...e.parts.slice(n+1)];return{...e,metadata:{...e.metadata,status:t.type===`text`&&t.state===`done`?`complete`:`streaming`},parts:r}}function updateToolPart(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.parts.some(e=>e.type===`dynamic-tool`&&e.toolCallId===t));return r?upsertMessage(e,upsertPart(r,n)):e}function replaceToolPart(e,t){let n=e.messages.find(e=>e.parts.some(e=>e.type===`dynamic-tool`&&e.toolCallId===t.toolCallId));return n===void 0?e:upsertMessage(e,{...n,parts:n.parts.map(e=>partKey(e)===partKey(t)?t:e)})}function completeAuthorization(e,t){let n=findLatestPendingAuthorizationPart(e,t.data.name),r=createAuthorizationCompletedPart(t,n);return n===void 0?updateAssistantMessage(e,t.data.turnId,e=>upsertPart(ensureStepStartPart(e,t.data.stepIndex),r)):updateAuthorizationPart(e,n,r)}function updateAuthorizationPart(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.parts.some(e=>e===t));return r?upsertMessage(e,upsertPart(r,n)):e}function findToolPart(e,t){for(let n of e.messages)for(let e of n.parts)if(e.type===`dynamic-tool`&&e.toolCallId===t)return e}function isSettledToolPart(e){return e.state===`output-denied`||e.state===`output-error`||e.state===`output-available`&&e.partial!==!0}function findLatestPendingAuthorizationPart(e,t){for(let n=e.messages.length-1;n>=0;--n){let r=e.messages[n];if(r?.role===`assistant`)for(let e=r.parts.length-1;e>=0;--e){let n=r.parts[e];if(n?.type===`authorization`&&n.state===`required`&&n.name===t)return n}}}function findToolPartByApprovalId(e,t){for(let n of e.messages)for(let e of n.parts)if(e.type===`dynamic-tool`&&e.approval?.id===t)return e}export{defaultMessageReducer};
1
+ import{approvedApproval,createToolMetadata,mergeToolMetadata,normalizeActionRequest,normalizeActionResult,stringifyUnknown,toMessageInputRequest}from"#client/message-action-parts.js";import{createAuthorizationCompletedPart,createAuthorizationRequiredPart}from"#client/authorization-message-parts.js";import{optimisticUserMessageId,partKey,projectReceivedParts,upsertMessage}from"#client/message-reducer-primitives.js";import{messageRun}from"#client/message-run-parts.js";import{createSettledTaskPart}from"#client/message-task-parts.js";function receivedMessageEventId(e){return e.meta.id??`${e.data.turnId}:${e.data.sequence}`}function defaultMessageReducer(){return{initial(){return{messages:[]}},reduce(e,t){return reduceMessageData(e,t)}}}function reduceMessageData(e,t){switch(t.type){case`client.message.submitted`:case`client.message.failed`:return upsertMessage(e,{id:optimisticUserMessageId(t.data.submissionId),metadata:{optimistic:!0,status:t.type===`client.message.failed`?`failed`:`submitted`},parts:[{type:`text`,text:t.data.message}],role:`user`},t.data.turnId);case`input.resolved`:{let n=e;for(let e of t.data.resolutions)n=resolveInputRequest(n,e);return n}case`message.received`:return upsertMessage(e,{id:`${receivedMessageEventId(t)}:user`,metadata:{status:`complete`,turnId:t.data.turnId},parts:projectReceivedParts(t.data.parts,t.data.message),role:`user`},t.data.turnId);case`step.started`:return updateAssistantMessage(e,t.data.turnId,e=>ensureStepStartPart(e,t.data.stepIndex));case`step.completed`:return e.messages.find(e=>e.role===`assistant`&&e.metadata?.turnId===t.data.turnId)===void 0?e:updateAssistantMessage(e,t.data.turnId,e=>({...e,parts:closeStreamingRuns(e.parts,t.data.stepIndex)}));case`reasoning.appended`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.transition(ensureStepStartPart(e,t.data.stepIndex),{kind:`append`,delta:t.data.reasoningDelta,id:t.meta?.id,stepIndex:t.data.stepIndex,type:`reasoning`}));case`reasoning.completed`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.transition(ensureStepStartPart(e,t.data.stepIndex),{kind:`complete`,stepIndex:t.data.stepIndex,text:t.data.reasoning,id:t.meta?.id,type:`reasoning`}));case`action.input.appended`:{let n=findToolPart(e,t.data.callId);if(n!==void 0&&n.state!==`input-streaming`)return e;let r={input:void 0,inputText:(n?.state===`input-streaming`?n.inputText:``)+t.data.inputTextDelta,state:`input-streaming`,stepIndex:t.data.stepIndex,toolCallId:t.data.callId,toolMetadata:n?.toolMetadata??{eve:{kind:`unknown`,name:t.data.toolName}},toolName:t.data.toolName,type:`dynamic-tool`};return upsertToolPart(e,t.data.turnId,t.data.stepIndex,r)}case`actions.requested`:{let n=e;for(let e of t.data.actions){let r=findToolPart(n,e.callId);if(r!==void 0&&r.state!==`input-streaming`)continue;let i=normalizeActionRequest(e);n=updateAssistantMessage(n,t.data.turnId,n=>upsertPart(ensureStepStartPart(n,t.data.stepIndex),{input:`input`in e?e.input:void 0,state:`input-available`,stepIndex:t.data.stepIndex,toolCallId:e.callId,toolMetadata:createToolMetadata(i),toolName:i.toolName,type:`dynamic-tool`}))}return n}case`input.requested`:{let n=e;for(let e of t.data.requests){let r=findToolPart(n,e.action.callId);if(r?.approval?.id===e.requestId||r!==void 0&&isSettledToolPart(r))continue;let i=normalizeActionRequest(e.action);n=updateAssistantMessage(n,t.data.turnId,n=>upsertPart(ensureStepStartPart(n,t.data.stepIndex),{approval:{id:e.requestId},input:e.action.input,state:`approval-requested`,stepIndex:t.data.stepIndex,toolCallId:e.action.callId,toolMetadata:createToolMetadata(i,{inputRequest:toMessageInputRequest(e)}),toolName:i.toolName,type:`dynamic-tool`}))}return n}case`approval.candidate`:return e;case`approval.settled`:{let n=findToolPartByApprovalId(e,t.data.requestId);if(n===void 0)return e;if(t.data.outcome===`approved`){let r={approved:!0,id:t.data.requestId,reason:void 0};return updateToolPart(e,n.toolCallId,n.state===`output-available`?{...n,approval:r}:{...toolPartIdentity(n),approval:r,state:`approval-responded`})}return n.state===`output-available`?e:updateToolPart(e,n.toolCallId,{...toolPartIdentity(n),approval:{approved:!1,id:t.data.requestId,reason:`Tool execution was cancelled.`},state:`output-denied`})}case`action.result`:{let n=normalizeActionResult(t.data.result),r=findToolPart(e,t.data.result.callId),i=t.data.status===`rejected`||t.data.error?.code===`TOOL_EXECUTION_DENIED`,a=t.data.status===`failed`&&!i,o=r?.approval?.id??t.data.result.callId,s=mergeToolMetadata(r?.toolMetadata,createToolMetadata(n)),c={input:r?.input,stepIndex:t.data.stepIndex,toolCallId:t.data.result.callId,toolMetadata:s,toolName:r?.toolName??n.toolName,type:`dynamic-tool`},l;return l=i?{...c,approval:{approved:!1,id:o,reason:t.data.error?.message},state:`output-denied`}:a?{...c,approval:approvedApproval(r),errorText:t.data.error?.message??stringifyUnknown(t.data.result.output),state:`output-error`}:{...c,approval:approvedApproval(r),output:t.data.result.output,state:`output-available`},upsertToolPart(e,t.data.turnId,t.data.stepIndex,l)}case`action.partial`:{let n=findToolPart(e,t.data.result.callId);if(n!==void 0&&isSettledToolPart(n))return e;let r=normalizeActionResult(t.data.result),i={approval:approvedApproval(n),input:n?.input,output:t.data.result.output,partial:!0,state:`output-available`,stepIndex:t.data.stepIndex,toolCallId:t.data.result.callId,toolMetadata:mergeToolMetadata(n?.toolMetadata,createToolMetadata(r)),toolName:n?.toolName??r.toolName,type:`dynamic-tool`};return upsertToolPart(e,t.data.turnId,t.data.stepIndex,i)}case`task.settled`:{let n=findToolPart(e,t.data.callId);return n===void 0?e:replaceToolPart(e,createSettledTaskPart(n,t))}case`authorization.required`:return updateAssistantMessage(e,t.data.turnId,e=>upsertPart(ensureStepStartPart(e,t.data.stepIndex),createAuthorizationRequiredPart(t)));case`authorization.completed`:return completeAuthorization(e,t);case`message.appended`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.transition(ensureStepStartPart(e,t.data.stepIndex),{kind:`append`,delta:t.data.messageDelta,id:t.meta?.id,stepIndex:t.data.stepIndex,type:`text`}));case`message.completed`:return updateAssistantMessage(e,t.data.turnId,e=>messageRun.transition(ensureStepStartPart(e,t.data.stepIndex),{kind:`complete`,stepIndex:t.data.stepIndex,text:t.data.message,id:t.meta?.id,type:`text`}));case`result.completed`:return updateAssistantMessage(e,t.data.turnId,e=>({...e,metadata:{...e.metadata,result:t.data.result}}));case`turn.completed`:return updateAssistantMessage(e,t.data.turnId,e=>({...e,metadata:{...e.metadata,status:`complete`},parts:removeStreamingToolParts(closeStreamingRuns(e.parts))}));case`turn.cancelled`:return updateAssistantMessage(e,t.data.turnId,e=>({...e,metadata:{...e.metadata,status:`complete`},parts:removeStreamingToolParts(closeStreamingRuns(e.parts))}));case`turn.failed`:return e.messages.find(e=>e.role===`assistant`&&e.metadata?.turnId===t.data.turnId)===void 0?e:updateAssistantMessage(e,t.data.turnId,e=>({...e,metadata:{...e.metadata,status:`complete`},parts:removeStreamingToolParts(closeStreamingRuns(e.parts))}));case`session.failed`:return e;default:return e}}function closeStreamingRuns(e,t){return e.map(e=>(e.type===`text`||e.type===`reasoning`)&&e.state===`streaming`&&(t===void 0||e.stepIndex===t)?{...e,state:`done`}:e)}function removeStreamingToolParts(e){return e.filter(e=>e.type!==`dynamic-tool`||e.state!==`input-streaming`)}function respondToInputRequest(e,t){let n=findToolPartByApprovalId(e,t.requestId);if(!n)return e;let r={id:t.requestId};t.text!==void 0&&(r.reason=t.text);let i=mergeToolMetadata(n.toolMetadata,{eve:{inputResponse:t,kind:n.toolMetadata?.eve?.kind??`unknown`,name:n.toolMetadata?.eve?.name??n.toolName}});return updateToolPart(e,n.toolCallId,n.state===`output-available`?{...n,approval:{...r,approved:!0},toolMetadata:i}:{...toolPartIdentity(n),approval:r,state:`approval-responded`,toolMetadata:i})}function resolveInputRequest(e,t){if(t.response!==void 0)return findToolPartByApprovalId(e,t.requestId)?.approval?.approved===void 0?respondToInputRequest(e,t.response):e;let n=findToolPartByApprovalId(e,t.requestId);return n?updateToolPart(e,n.toolCallId,{...toolPartIdentity(n),output:{status:t.outcome},state:`output-available`}):e}function toolPartIdentity(e){return{input:e.input,stepIndex:e.stepIndex,toolCallId:e.toolCallId,toolMetadata:e.toolMetadata,toolName:e.toolName,type:e.type}}function updateAssistantMessage(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.metadata?.turnId===t)??createAssistantMessage(t);return upsertMessage(e,n(r))}function createAssistantMessage(e){return{id:`${e}:assistant`,metadata:{status:`streaming`,turnId:e},parts:[],role:`assistant`}}function ensureStepStartPart(e,t){let n=e.parts.filter(e=>e.type===`step-start`).length;if(n>t)return e;let r=t-n+1;return{...e,parts:[...e.parts,...Array.from({length:r},()=>({type:`step-start`}))]}}function upsertPart(e,t){let n=e.parts.findIndex(e=>partKey(e)===partKey(t)),r=n===-1?[...e.parts,t]:[...e.parts.slice(0,n),t,...e.parts.slice(n+1)];return{...e,metadata:{...e.metadata,status:t.type===`text`&&t.state===`done`?`complete`:`streaming`},parts:r}}function upsertToolPart(e,t,n,r){let i=updateToolPart(e,r.toolCallId,r);return i===e?updateAssistantMessage(e,t,e=>upsertPart(ensureStepStartPart(e,n),r)):i}function updateToolPart(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.parts.some(e=>e.type===`dynamic-tool`&&e.toolCallId===t));return r?upsertMessage(e,upsertPart(r,n)):e}function replaceToolPart(e,t){let n=e.messages.find(e=>e.parts.some(e=>e.type===`dynamic-tool`&&e.toolCallId===t.toolCallId));return n===void 0?e:upsertMessage(e,{...n,parts:n.parts.map(e=>partKey(e)===partKey(t)?t:e)})}function completeAuthorization(e,t){let n=findPendingAuthorizationPart(e,t.data.name,t.data.attemptId),r=createAuthorizationCompletedPart(t,n);return updateAssistantMessage(e,n?.turnId??t.data.turnId,e=>upsertPart(ensureStepStartPart(e,r.stepIndex),r))}function findToolPart(e,t){for(let n of e.messages)for(let e of n.parts)if(e.type===`dynamic-tool`&&e.toolCallId===t)return e}function isSettledToolPart(e){return e.state===`output-denied`||e.state===`output-error`||e.state===`output-available`&&e.partial!==!0}function findPendingAuthorizationPart(e,t,n){for(let r=e.messages.length-1;r>=0;--r){let i=e.messages[r];if(i?.role===`assistant`)for(let e=i.parts.length-1;e>=0;--e){let r=i.parts[e];if(r?.type===`authorization`&&r.state===`required`&&(n===void 0?r.attemptId===void 0&&r.name===t:r.attemptId===n))return r}}}function findToolPartByApprovalId(e,t){for(let n of e.messages)for(let e of n.parts)if(e.type===`dynamic-tool`&&e.approval?.id===t)return e}export{defaultMessageReducer};
@@ -1 +1 @@
1
- import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{summarizeTurnEvents}from"#client/session-utils.js";import{extractCompletedResult}from"#client/output-schema.js";const consumeResponse=Symbol(`consumeMessageResponse`),acceptedDeliveryId=Symbol(`acceptedDeliveryId`);var MessageResponse=class{sessionId;[acceptedDeliveryId];#e;#t;#n=!1;#r;#i=!1;#a=Promise.withResolvers();constructor(e){this.#e=e.cancelTurn,this.sessionId=e.sessionId,this[acceptedDeliveryId]=e.deliveryId,this.#r=e.createStream}cancel(){if(this.#i)return Promise.resolve({status:`no_active_turn`});if(this.#t!==void 0)return this.#t;let e=this.#a.promise.then(e=>e===void 0?{status:`no_active_turn`}:this.#e(e));return this.#t=e,e.catch(()=>{!this.#i&&this.#t===e&&(this.#t=void 0)}),e}async result(){let e=[];for await(let t of this)e.push(t);let t=summarizeTurnEvents(e);return{data:extractCompletedResult(e),events:e,inputRequests:t.inputRequests,message:t.message,sessionId:this.sessionId,status:t.status}}[Symbol.asyncIterator](){return this[consumeResponse]()}[consumeResponse](e){if(this.#n)throw Error(`MessageResponse has already been consumed.`);return this.#n=!0,this.#o(e)}async*#o(e){try{for await(let t of this.#r(e))t.type===`turn.started`?this.#a.resolve(t.data.turnId):isCurrentTurnBoundaryEvent(t)&&(this.#i=!0,this.#a.resolve(void 0)),yield t}finally{this.#a.resolve(void 0)}}};function getMessageResponseDeliveryId(e){return e[acceptedDeliveryId]}function consumeMessageResponse(e,t){return e[consumeResponse](t)}export{MessageResponse,consumeMessageResponse,getMessageResponseDeliveryId};
1
+ import{summarizeTurnEvents}from"#client/session-utils.js";import{isCurrentTurnBoundaryEvent}from"#protocol/message.js";import{extractCompletedResult}from"#client/output-schema.js";const consumeResponse=Symbol(`consumeMessageResponse`),acceptedDeliveryId=Symbol(`acceptedDeliveryId`);var MessageResponse=class{sessionId;[acceptedDeliveryId];#e;#t;#n=!1;#r;#i=!1;#a=Promise.withResolvers();constructor(e){this.#e=e.cancelTurn,this.sessionId=e.sessionId,this[acceptedDeliveryId]=e.deliveryId,this.#r=e.createStream}cancel(){if(this.#i)return Promise.resolve({status:`no_active_turn`});if(this.#t!==void 0)return this.#t;let e=this.#a.promise.then(e=>e===void 0?{status:`no_active_turn`}:this.#e(e));return this.#t=e,e.catch(()=>{!this.#i&&this.#t===e&&(this.#t=void 0)}),e}async result(){let e=[];for await(let t of this)e.push(t);let t=summarizeTurnEvents(e);return{data:extractCompletedResult(e),events:e,inputRequests:t.inputRequests,message:t.message,sessionId:this.sessionId,status:t.status}}[Symbol.asyncIterator](){return this[consumeResponse]()}[consumeResponse](e){if(this.#n)throw Error(`MessageResponse has already been consumed.`);return this.#n=!0,this.#o(e)}async*#o(e){try{for await(let t of this.#r(e))t.type===`turn.started`?this.#a.resolve(t.data.turnId):isCurrentTurnBoundaryEvent(t)&&(this.#i=!0,this.#a.resolve(void 0)),yield t}finally{this.#a.resolve(void 0)}}};function getMessageResponseDeliveryId(e){return e[acceptedDeliveryId]}function consumeMessageResponse(e,t){return e[consumeResponse](t)}export{MessageResponse,consumeMessageResponse,getMessageResponseDeliveryId};
@@ -5,14 +5,18 @@ type EveAssistantMessage = EveMessage & {
5
5
  type EveRunPart = Extract<EveMessagePart, {
6
6
  readonly type: "text" | "reasoning";
7
7
  }>;
8
- declare function append(message: EveAssistantMessage, append: {
9
- readonly delta: string;
8
+ declare function transition(message: EveAssistantMessage, input: {
10
9
  readonly stepIndex: number;
11
10
  readonly type: EveRunPart["type"];
12
- }): EveAssistantMessage;
13
- declare function upsert(message: EveAssistantMessage, next: EveRunPart): EveAssistantMessage;
11
+ readonly id?: string;
12
+ } & ({
13
+ readonly kind: "append";
14
+ readonly delta: string;
15
+ } | {
16
+ readonly kind: "complete";
17
+ readonly text: string;
18
+ })): EveAssistantMessage;
14
19
  export declare const messageRun: {
15
- readonly append: typeof append;
16
- readonly upsert: typeof upsert;
20
+ readonly transition: typeof transition;
17
21
  };
18
22
  export {};
@@ -1 +1 @@
1
- function append(e,t){let n=latestStreamingRun(e,t.type,t.stepIndex);return upsert(e,{state:`streaming`,stepIndex:t.stepIndex,text:(n?.text??``)+t.delta,type:t.type})}function latestStreamingRun(e,t,n){for(let r=e.parts.length-1;r>=0;--r){let i=e.parts[r];if(i?.type===t&&i.stepIndex===n)return i.state===`streaming`?i:void 0}}function upsert(e,t){let n=-1;for(let r=e.parts.length-1;r>=0;--r){let i=e.parts[r];if(i?.type===t.type&&i.stepIndex===t.stepIndex){n=r;break}}let r=n!==-1&&e.parts[n].state===`streaming`?[...e.parts.slice(0,n),t,...e.parts.slice(n+1)]:[...e.parts,t];return{...e,metadata:{...e.metadata,status:t.type===`text`&&t.state===`done`?`complete`:`streaming`},parts:r}}const messageRun={append,upsert};export{messageRun};
1
+ function transition(e,t){let n=e.parts.findLastIndex(e=>e.type===t.type&&e.stepIndex===t.stepIndex),r=n===-1?void 0:e.parts[n];if(t.kind===`append`&&!t.delta)return e;let i=r?.state===`streaming`?r:void 0,a={id:i?.id??t.id??`${e.id}:${t.type}:${e.parts.length}`,state:t.kind===`append`?`streaming`:`done`,stepIndex:t.stepIndex,text:t.kind===`append`?(i?.text??``)+t.delta:t.text,type:t.type},o=i?[...e.parts.slice(0,n),a,...e.parts.slice(n+1)]:[...e.parts,a];return{...e,metadata:{...e.metadata,status:t.type===`text`&&a.state===`done`?`complete`:`streaming`},parts:o}}const messageRun={transition};export{messageRun};
@@ -1,4 +1,4 @@
1
- import { EveAgentProjection } from "#client/eve-agent-projection.js";
1
+ import type { EveAgentEventLog } from "#client/eve-agent-projection.js";
2
2
  import type { MessageStreamEvent } from "#protocol/message.js";
3
3
  import type { SendTurnPayload } from "#client/types.js";
4
4
  interface ReconciledSubmissions {
@@ -9,11 +9,13 @@ interface ReconciledSubmissions {
9
9
  readonly ids: readonly string[];
10
10
  }
11
11
  /** Owns optimistic message projection and server-delivery reconciliation. */
12
- export declare class OptimisticMessageSubmissions<TData> {
12
+ export declare class OptimisticMessageSubmissions {
13
13
  #private;
14
- constructor(projection: EveAgentProjection<TData>, optimistic: boolean);
14
+ constructor(projections: readonly EveAgentEventLog[], optimistic: boolean);
15
15
  reset(): void;
16
- submit(input: SendTurnPayload, eventStartIndex: number): string | undefined;
16
+ submit(input: SendTurnPayload, eventStartIndex: number, turnId?: string): string | undefined;
17
+ /** Re-echoes a submission whose payload `prepareSend` replaced, keeping its place in the stream. */
18
+ resubmit(submissionId: string | undefined, input: SendTurnPayload): string | undefined;
17
19
  apply(event: MessageStreamEvent): ReconciledSubmissions | undefined;
18
20
  correlate(submissionId: string | undefined, deliveryId: string | undefined, events: readonly MessageStreamEvent[]): ReconciledSubmissions | undefined;
19
21
  fail(error: Error, submissionId?: string): void;
@@ -1 +1 @@
1
- import"#client/eve-agent-projection.js";import{createSubmissionId,summarizeUserContent}from"#client/eve-agent-store-helpers.js";var OptimisticMessageSubmissions=class{#e;#t;#n=[];constructor(e,t){this.#t=e,this.#e=t}reset(){this.#n=[]}submit(e,t){if(e.message===void 0)return;let n={createdAt:Date.now(),eventStartIndex:t,id:createSubmissionId(),message:summarizeUserContent(e.message),requiresDeliveryId:!0};return this.#n=[...this.#n,n],this.#e&&this.#t.append({data:{createdAt:n.createdAt,message:n.message,submissionId:n.id},type:`client.message.submitted`}),n.id}apply(e){if(e.type!==`message.received`){this.#t.append(e);return}let t=this.#r(e);if(t.length===0){this.#t.append(e);return}return this.#i(t,e,!1)}correlate(e,t,n){if(e===void 0)return;this.#n=this.#n.map(n=>n.id===e?{...n,deliveryId:t,requiresDeliveryId:t!==void 0}:n);let r=this.#n.find(t=>t.id===e);if(r!==void 0)for(let t of n.slice(r.eventStartIndex)){if(t.type!==`message.received`)continue;let n=this.#r(t);if(n.some(t=>t.id===e))return this.#i(n,t,!0)}}fail(e,t){let n=t===void 0?this.#n[0]:this.#n.find(e=>e.id===t);n!==void 0&&(this.#n=this.#n.filter(e=>e.id!==n.id),this.#t.replace(e=>e.type===`client.message.submitted`&&e.data.submissionId===n.id,{data:{createdAt:n.createdAt,error:{message:e.message},message:n.message,submissionId:n.id},type:`client.message.failed`}))}failAll(e){for(let t of this.#n)this.fail(e,t.id)}#r(e){return this.#n.filter(t=>t.deliveryId===void 0?!t.requiresDeliveryId:e.meta.deliveryIds?.includes(t.deliveryId)===!0)}#i(e,t,n){let r=e.map(e=>e.id),i=new Set(r);return this.#n=this.#n.filter(e=>!i.has(e.id)),n||this.#t.replace(e=>e.type===`client.message.submitted`&&e.data.submissionId===r[0],t),this.#t.remove(e=>e.type===`client.message.submitted`&&i.has(e.data.submissionId)),{alreadyProjected:n,event:t,ids:r}}};export{OptimisticMessageSubmissions};
1
+ import{createSubmissionId,summarizeUserContent}from"#client/eve-agent-store-helpers.js";var OptimisticMessageSubmissions=class{#e;#t;#n=[];constructor(e,t){this.#t=e,this.#e=t}reset(){this.#n=[]}submit(e,t,n){if(e.message===void 0)return;let r={createdAt:Date.now(),eventStartIndex:t,id:createSubmissionId(),message:summarizeUserContent(e.message),turnId:n,requiresDeliveryId:!0};if(this.#n=[...this.#n,r],this.#e)for(let e of this.#t)e.append({data:{createdAt:r.createdAt,message:r.message,submissionId:r.id,turnId:n},type:`client.message.submitted`});return r.id}resubmit(e,t){let n=this.#n.find(t=>t.id===e),r=t.message===void 0?void 0:summarizeUserContent(t.message);return n?.message===r?e:(n!==void 0&&this.#a([n.id]),this.submit(t,n?.eventStartIndex??0,n?.turnId))}apply(e){if(e.type!==`message.received`){for(let t of this.#t)t.append(e);return}let t=this.#r(e);if(t.length===0){for(let t of this.#t)t.append(e);return}return this.#i(t,e,!1)}correlate(e,t,n){if(e===void 0)return;this.#n=this.#n.map(n=>n.id===e?{...n,deliveryId:t,requiresDeliveryId:t!==void 0}:n);let r=this.#n.find(t=>t.id===e);if(r!==void 0)for(let t of n.slice(r.eventStartIndex)){if(t.type!==`message.received`)continue;let n=this.#r(t);if(n.some(t=>t.id===e))return this.#i(n,t,!0)}}fail(e,t){let n=t===void 0?this.#n[0]:this.#n.find(e=>e.id===t);if(n!==void 0){this.#n=this.#n.filter(e=>e.id!==n.id);for(let t of this.#t)t.replace(e=>e.type===`client.message.submitted`&&e.data.submissionId===n.id,{data:{createdAt:n.createdAt,error:{message:e.message},message:n.message,submissionId:n.id,turnId:n.turnId},type:`client.message.failed`})}}failAll(e){for(let t of this.#n)this.fail(e,t.id)}#r(e){return this.#n.filter(t=>t.deliveryId===void 0?!t.requiresDeliveryId:e.meta.deliveryIds?.includes(t.deliveryId)===!0)}#i(e,t,n){let r=e.map(e=>e.id);if(this.#a(r),!n)for(let e of this.#t)e.append(t);return{alreadyProjected:n,event:t,ids:r}}#a(e){let t=new Set(e);this.#n=this.#n.filter(e=>!t.has(e.id));for(let e of this.#t)e.remove(e=>e.type===`client.message.submitted`&&t.has(e.data.submissionId))}};export{OptimisticMessageSubmissions};
@@ -9,6 +9,8 @@ export interface ClientMessageSubmittedEvent {
9
9
  readonly createdAt: number;
10
10
  readonly message: string;
11
11
  readonly submissionId: string;
12
+ /** Active turn receiving a steered follow-up, when known. */
13
+ readonly turnId?: string;
12
14
  };
13
15
  readonly type: "client.message.submitted";
14
16
  }
@@ -24,6 +26,8 @@ export interface ClientMessageFailedEvent {
24
26
  };
25
27
  readonly message: string;
26
28
  readonly submissionId: string;
29
+ /** Active turn receiving a steered follow-up, when known. */
30
+ readonly turnId?: string;
27
31
  };
28
32
  readonly type: "client.message.failed";
29
33
  }
@@ -43,7 +47,7 @@ export interface ClientInputRespondedEvent {
43
47
  *
44
48
  * Server events are authoritative eve stream events. They include text,
45
49
  * reasoning, tool/action requests and results, HITL input requests, connection
46
- * authorization events, subagent events, and session lifecycle events. Client
50
+ * authorization events, task and agent-session events, and session lifecycle events. Client
47
51
  * events are projection-only events created by client state machines for local
48
52
  * UI state such as optimistic user messages and submitted HITL responses.
49
53
  */
@@ -0,0 +1,15 @@
1
+ import type { Client } from "#client/client.js";
2
+ import type { MessageResponse } from "#client/message-response.js";
3
+ import type { ClientSession } from "#client/session.js";
4
+ import type { SendTurnPayload } from "#client/types.js";
5
+ /** Send one turn through an owned or attached session, without choosing how to consume its stream. */
6
+ export declare function dispatchSessionTurn<TOutput>(input: {
7
+ client?: Client;
8
+ session?: ClientSession;
9
+ turn: SendTurnPayload<TOutput>;
10
+ beforeSend?: () => void;
11
+ }): Promise<{
12
+ session: ClientSession;
13
+ response: MessageResponse<TOutput>;
14
+ created: boolean;
15
+ }>;
@@ -0,0 +1 @@
1
+ async function dispatchSessionTurn(e){let{client:t,session:n,turn:r,beforeSend:i}=e;if(n===void 0){if(t===void 0)throw Error(`An external eve session is required before sending.`);if(r.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let e=await t.sessions.create({...r,message:r.message});return r.signal?.throwIfAborted(),{...e,created:!0}}if(i?.(),r.inputResponses===void 0){let{message:e,...t}=r;return{session:n,response:await n.send(e,t),created:!1}}let{inputResponses:a,...o}=r;return{session:n,response:await n.respond(a,o),created:!1}}export{dispatchSessionTurn};
@@ -1,10 +1,11 @@
1
- import type { AuthorizationRequiredStreamEvent, MessageStreamEvent, TurnFailureStreamEvent, UnstampedMessageStreamEvent } from "#protocol/message.js";
1
+ import type { AuthorizationRequiredStreamEvent, TurnFailureStreamEvent, UnstampedMessageStreamEvent } from "#protocol/message.js";
2
2
  import type { InputRequest } from "#shared/input.js";
3
3
  /** A connection authorization challenge that remains unresolved at a turn boundary. */
4
4
  interface PendingAuthorization {
5
5
  readonly authorization?: AuthorizationRequiredStreamEvent["data"]["authorization"];
6
6
  readonly description: string;
7
7
  readonly name: string;
8
+ readonly attemptId?: string;
8
9
  readonly webhookUrl?: string;
9
10
  }
10
11
  /** Canonical projection of the lifecycle state represented by one turn's events. */
@@ -21,14 +22,30 @@ export declare function summarizeTurnEvents(events: readonly UnstampedMessageStr
21
22
  /** Collects one segment of an event stream through its current-turn boundary. */
22
23
  export declare function collectTurnEvents(stream: AsyncIterable<UnstampedMessageStreamEvent>): Promise<readonly UnstampedMessageStreamEvent[]>;
23
24
  /**
24
- * Returns true when one segment of a turn's events ends at `event`: at a
25
- * current-turn boundary, or at `turn.waiting` while an input request read in
26
- * the segment is unanswered. The turn stays open there until a person answers;
27
- * without a pending request, `turn.waiting` is informational and reading goes
28
- * on to the turn's real end.
25
+ * Returns true when a read of a session's events ends at `event`: at a current-turn boundary, or
26
+ * at a `turn.waiting` on `"input"` (or while a request read in the segment is unanswered). The
27
+ * turn stays open there until a person acts; a `turn.waiting` on `"tasks"` is informational and
28
+ * reading goes on to the turn's real end.
29
+ * A reader that follows sign-in callbacks reads past a sign-in's `turn.waiting` or
30
+ * `session.waiting` while its callback is outstanding, because the callback resumes the same turn.
29
31
  */
30
- export declare function isTurnSegmentBoundary(event: UnstampedMessageStreamEvent, pendingInputRequests: ReadonlySet<string>): boolean;
31
- /** Tracks the input requests read in a segment that no `input.resolved` has answered yet. */
32
- export declare function updatePendingInputRequests(pending: Set<string>, event: UnstampedMessageStreamEvent): void;
33
- export declare function updatePendingAuthorizations(pending: Set<string>, event: MessageStreamEvent): void;
32
+ export declare function endsTurnSegment(event: UnstampedMessageStreamEvent, open: {
33
+ readonly callbacks: boolean;
34
+ readonly requests: boolean;
35
+ }): boolean;
36
+ /** The requests and sign-ins one segment of a session's events leaves open. */
37
+ export declare class TurnSegment {
38
+ #private;
39
+ constructor(options?: {
40
+ readonly followCallbacks?: boolean;
41
+ });
42
+ get inputRequests(): readonly InputRequest[];
43
+ get pendingAuthorizations(): readonly PendingAuthorization[];
44
+ /** Records `event` and returns true when it ends the segment. */
45
+ observe(event: UnstampedMessageStreamEvent): boolean;
46
+ }
47
+ export declare function authorizationKey(data: {
48
+ readonly name: string;
49
+ readonly attemptId?: string;
50
+ }): string;
34
51
  export {};
@@ -1 +1 @@
1
- import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";function summarizeTurnEvents(e){let t,n,r,i=[],a=new Set,o=new Map;for(let s of e)updatePendingInputRequests(a,s),isTurnSegmentBoundary(s,a)&&(t=s),isTurnFailureEvent(s)&&(n=s),isFinalMessageCompleted(s)&&(r=s.data.message??void 0),s.type===`turn.waiting`&&(r=void 0),s.type===`input.requested`&&i.push(...s.data.requests),s.type===`authorization.required`&&o.set(s.data.name,s.data),s.type===`authorization.completed`&&o.delete(s.data.name);return{boundary:t,failure:n,inputRequests:i,message:r,pendingAuthorizations:[...o.values()],status:summarizeBoundaryStatus(t)}}function summarizeBoundaryStatus(e){return e?.type===`session.waiting`||e?.type===`turn.waiting`?`waiting`:e?.type===`session.failed`?`failed`:`completed`}async function collectTurnEvents(e){let t=[],n=new Set;for await(let r of e)if(t.push(r),updatePendingInputRequests(n,r),isTurnSegmentBoundary(r,n))break;return t}function isTurnSegmentBoundary(e,t){return e.type===`turn.waiting`?t.size>0:isCurrentTurnBoundaryEvent(e)}function updatePendingInputRequests(e,t){if(t.type===`input.requested`)for(let n of t.data.requests)e.add(n.requestId);else if(t.type===`input.resolved`)for(let n of t.data.resolutions)e.delete(n.requestId)}function isFinalMessageCompleted(e){return e.type===`message.completed`&&e.data.finishReason!==`tool-calls`}function updatePendingAuthorizations(e,t){t.type===`authorization.required`&&t.data.webhookUrl!==void 0?e.add(t.data.name):t.type===`authorization.completed`&&e.delete(t.data.name)}export{collectTurnEvents,isTurnSegmentBoundary,summarizeTurnEvents,updatePendingAuthorizations,updatePendingInputRequests};
1
+ import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";function summarizeTurnEvents(e){let t=new TurnSegment,n,r,i;for(let a of e)t.observe(a)&&(n=a),isTurnFailureEvent(a)&&(r=a),isFinalMessageCompleted(a)&&(i=a.data.message??void 0),a.type===`turn.waiting`&&(i=void 0);return{boundary:n,failure:r,inputRequests:t.inputRequests,message:i,pendingAuthorizations:t.pendingAuthorizations,status:summarizeBoundaryStatus(n)}}function summarizeBoundaryStatus(e){return e?.type===`session.waiting`||e?.type===`turn.waiting`?`waiting`:e?.type===`session.failed`?`failed`:`completed`}async function collectTurnEvents(e){let t=[],n=new TurnSegment;for await(let r of e)if(t.push(r),n.observe(r))break;return t}function endsTurnSegment(e,t){return e.type===`turn.waiting`?t.requests||e.data.on===`input`&&!t.callbacks:isCurrentTurnBoundaryEvent(e)&&(e.type!==`session.waiting`||!t.callbacks)}var TurnSegment=class{#e=new Map;#t;#n=new Map;constructor(e={}){this.#t=e.followCallbacks===!0}get inputRequests(){return[...this.#n.values()]}get pendingAuthorizations(){return[...this.#e.values()]}observe(e){switch(e.type){case`input.requested`:for(let t of e.data.requests)this.#n.set(t.requestId,t);break;case`approval.settled`:this.#n.delete(e.data.requestId);break;case`input.resolved`:for(let t of e.data.resolutions)this.#n.delete(t.requestId);break;case`authorization.required`:this.#e.set(authorizationKey(e.data),e.data);break;case`authorization.completed`:this.#e.delete(authorizationKey(e.data))}return endsTurnSegment(e,{callbacks:this.#t&&[...this.#e.values()].some(e=>e.webhookUrl!==void 0),requests:this.#n.size>0})}};function isFinalMessageCompleted(e){return e.type===`message.completed`&&e.data.finishReason!==`tool-calls`}function authorizationKey(e){return e.attemptId===void 0?`name:${e.name}`:`attempt:${e.attemptId}`}export{TurnSegment,authorizationKey,collectTurnEvents,endsTurnSegment,summarizeTurnEvents};
@@ -1 +1 @@
1
- import{EVE_SESSION_ROUTE_PATH,createEveSessionRoutePath,createEveSessionStreamRoutePath}from"#protocol/routes.js";import{EVE_SESSION_ID_HEADER}from"#protocol/message.js";import{isTurnSegmentBoundary,updatePendingAuthorizations,updatePendingInputRequests}from"#client/session-utils.js";import{followStreamIterable,sleep}from"#client/open-stream.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{ClientAgentSession}from"#client/agent-session.js";import{cancelClientSession,clearClientSession,compactClientSession,resetClientSession}from"#client/session-controls.js";import{serializeOutputSchema}from"#tools/schema.js";const followSession=Symbol(`followClientSession`);var ClientSession=class ClientSession{#e;#t;constructor(e,t){this.#e=e,this.#t=t}static async create(e,t){let n=await postTurn(e,EVE_SESSION_ROUTE_PATH,t,!0),{sessionId:r}=await readAcceptedMessage(n),i=new ClientSession(e,{sessionId:r,streamIndex:0});return{response:i.#r(n,t,0),session:i}}static async prewarm(e,t={}){let{sessionId:n}=await readAcceptedMessage(await postCreateSession(e,t));return new ClientSession(e,{sessionId:n,streamIndex:0})}get state(){return this.#t}async snapshot(e){e?.signal?.throwIfAborted();let t=[];for await(let n of this.#s({follow:!1,signal:e?.signal,startIndex:0}))t.push(n);return e?.signal?.throwIfAborted(),{events:t,session:{sessionId:this.#t.sessionId,streamIndex:t.length}}}async send(e,t={}){return await this.#n({...t,message:e},!0)}async respond(e,t={}){if(e.length===0)throw Error(`ClientSession.respond() requires at least one input response.`);return await this.#n({...t,inputResponses:e},!1)}async#n(e,t){let n=this.#t.streamIndex,r=createEveSessionRoutePath(this.#t.sessionId),i=t?await postSessionSend(this.#e,r,e):await postTurn(this.#e,r,e,!1),{sessionId:a,deliveryId:o}=await readAcceptedMessage(i,this.#t.sessionId);if(a!==this.#t.sessionId)throw Error(`Message route returned a different session id.`);if(e.message!==void 0&&o===void 0)throw Error(`Message route did not return a delivery id. Update the server before sending with this client.`);return this.#r(i,e,n,e.message===void 0?void 0:o)}async cancel(e){return await cancelClientSession({context:this.#e,options:e,sessionId:this.#t.sessionId})}async clear(){return await clearClientSession({context:this.#e,sessionId:this.#t.sessionId})}async compact(){return await compactClientSession({context:this.#e,sessionId:this.#t.sessionId})}async reset(e){return await resetClientSession({context:this.#e,options:e,sessionId:this.#t.sessionId})}stream(e){if(e?.follow===!1&&(e.startIndex??this.#t.streamIndex)<0)throw Error(`stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.`);return this.#a(e)}agent(e){return new ClientAgentSession(this.#e,e)}[followSession](e){return this.#a({...e,keepAlive:!0})}#r(e,t,n,r){return e.body?.cancel().catch(()=>{}),new MessageResponse({cancelTurn:async e=>await this.cancel({turnId:e}),createStream:e=>this.#i(n,t,r,e),deliveryId:r,sessionId:this.#t.sessionId})}async*#i(e,t,n,r){let i=0,a=n===void 0,o=!1,s=new Set,c=new Set;try{for await(let l of r??this.#s({headers:t.headers,keepAlive:!0,signal:t.signal,startIndex:e,streamReconnectPolicy:t.streamReconnectPolicy})){if(i+=1,n!==void 0){let e=l.meta?.deliveryIds?.includes(n)===!0,t=l.type===`session.failed`||l.type===`session.completed`;if(!e&&t&&(!a||l.type===`session.completed`))throw Error(`The session ended before the accepted message reached its turn boundary.`);if(!a&&!e||!t&&l.meta?.deliveryIds!==void 0&&!e)continue;a=!0}if(updatePendingAuthorizations(s,l),updatePendingInputRequests(c,l),o=isTurnSegmentBoundary(l,c)&&(l.type!==`session.waiting`||s.size===0),yield l,o)break}if(n!==void 0&&!o&&!t.signal?.aborted)throw Error(`The response stream ended before the accepted message reached its turn boundary.`)}finally{this.#o(e+i)}}async*#a(e){let t=e?.startIndex??this.#t.streamIndex,n=0;for await(let r of this.#s({follow:e?.follow,headers:e?.headers,keepAlive:e?.keepAlive,onCaughtUp:e?.onCaughtUp,resolveHeaders:e?.resolveHeaders,resolveReconnectPolicy:e?.resolveReconnectPolicy,signal:e?.signal,startIndex:t,streamReconnectPolicy:e?.streamReconnectPolicy}))n+=1,t>=0&&this.#o(t+n),yield r}#o(e){this.#t={sessionId:this.#t.sessionId,streamIndex:Math.max(this.#t.streamIndex,e)}}#s(e){return followStreamIterable({onCaughtUp:e.onCaughtUp,follow:e.follow,host:this.#e.host,keepAlive:e.keepAlive,resolveHeaders:()=>this.#e.resolveHeaders(e.resolveHeaders?.()??e.headers),path:createEveSessionStreamRoutePath(this.#t.sessionId),redirect:this.#e.redirect,signal:e.signal,startIndex:e.startIndex,streamReconnectPolicy:e.streamReconnectPolicy,resolveReconnectPolicy:e.resolveReconnectPolicy})}};function followClientSession(e,t){return e[followSession](t)}async function postSessionSend(e,t,n){let r=Date.now()+2e4,i=250;for(;;){try{return await postTurn(e,t,n,!1)}catch(e){if(!isSessionNotReady(e))throw e;let t=r-Date.now();if(t<=0)throw e;await sleep(Math.min(i,t),n.signal)}n.signal?.throwIfAborted(),i=Math.min(i*2,2e3)}}async function postCreateSession(e,t){let n=await e.resolveHeaders(t.headers),r=await fetch(createClientUrl(e.host,EVE_SESSION_ROUTE_PATH),{headers:n,method:`POST`,redirect:e.redirect,signal:t.signal??null});if(!r.ok){let e=await r.text();throw new ClientError(r.status,e,r.headers)}return r}function isSessionNotReady(e){return e instanceof ClientError&&e.status===409&&e.code===`session_not_ready`}async function postTurn(e,t,n,r){let i=createMessageBody(n,r);if(i===null)throw Error(r?`Creating a session requires a non-empty message.`:`A session turn requires a non-empty message or inputResponses.`);let a=await e.resolveHeaders(n.headers);a.set(`content-type`,`application/json`);let o=await fetch(createClientUrl(e.host,t),{body:JSON.stringify(i),headers:a,method:`POST`,redirect:e.redirect,signal:n.signal??null});if(!o.ok){let e=await o.text();throw new ClientError(o.status,e,o.headers)}return o}async function readAcceptedMessage(e,t){let n=await e.json(),r=(typeof n.sessionId==`string`?n.sessionId:void 0)??e.headers.get(EVE_SESSION_ID_HEADER)?.trim()??t;if(!r)throw Error(`Message route did not return a session id.`);return{sessionId:r,deliveryId:typeof n.deliveryId==`string`&&n.deliveryId.length>0?n.deliveryId:void 0}}function createMessageBody(e,t){let n={};e.message!==void 0&&(n.message=e.message),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses),!t&&e.message!==void 0&&e.turnPolicy!==void 0&&(n.turnPolicy=e.turnPolicy),e.clientContext!==void 0&&(n.clientContext=e.clientContext);let r=serializeOutputSchema(e.outputSchema);return r!==void 0&&(n.outputSchema=r),t&&n.message===void 0||n.message===void 0&&n.inputResponses===void 0?null:n}export{ClientSession,followClientSession};
1
+ import{EVE_SESSION_ROUTE_PATH,createEveSessionRoutePath,createEveSessionStreamRoutePath}from"#protocol/routes.js";import{TurnSegment}from"#client/session-utils.js";import{EVE_SESSION_ID_HEADER}from"#protocol/message.js";import{followStreamIterable,sleep}from"#client/open-stream.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{MessageResponse}from"#client/message-response.js";import{ClientAgentSession}from"#client/agent-session.js";import{cancelClientSession,clearClientSession,compactClientSession,resetClientSession}from"#client/session-controls.js";import{serializeOutputSchema}from"#tools/schema.js";const followSession=Symbol(`followClientSession`);var ClientSession=class ClientSession{#e;#t;constructor(e,t){this.#e=e,this.#t=t}static async create(e,t){let n=await postTurn(e,EVE_SESSION_ROUTE_PATH,t,!0),{sessionId:r}=await readAcceptedMessage(n),i=new ClientSession(e,{sessionId:r,streamIndex:0});return{response:i.#r(n,t,0),session:i}}static async prewarm(e,t={}){let{sessionId:n}=await readAcceptedMessage(await postCreateSession(e,t));return new ClientSession(e,{sessionId:n,streamIndex:0})}get state(){return this.#t}async snapshot(e){e?.signal?.throwIfAborted();let t=[];for await(let n of this.#s({follow:!1,signal:e?.signal,startIndex:0}))t.push(n);return e?.signal?.throwIfAborted(),{events:t,session:{sessionId:this.#t.sessionId,streamIndex:t.length}}}async send(e,t={}){return await this.#n({...t,message:e},!0)}async respond(e,t={}){if(e.length===0)throw Error(`ClientSession.respond() requires at least one input response.`);return await this.#n({...t,inputResponses:e},!1)}async#n(e,t){let n=this.#t.streamIndex,r=createEveSessionRoutePath(this.#t.sessionId),i=t?await postSessionSend(this.#e,r,e):await postTurn(this.#e,r,e,!1),{sessionId:a,deliveryId:o}=await readAcceptedMessage(i,this.#t.sessionId);if(a!==this.#t.sessionId)throw Error(`Message route returned a different session id.`);if(e.message!==void 0&&o===void 0)throw Error(`Message route did not return a delivery id. Update the server before sending with this client.`);return this.#r(i,e,n,e.message===void 0?void 0:o)}async cancel(e){return await cancelClientSession({context:this.#e,options:e,sessionId:this.#t.sessionId})}async clear(){return await clearClientSession({context:this.#e,sessionId:this.#t.sessionId})}async compact(){return await compactClientSession({context:this.#e,sessionId:this.#t.sessionId})}async reset(e){return await resetClientSession({context:this.#e,options:e,sessionId:this.#t.sessionId})}stream(e){if(e?.follow===!1&&(e.startIndex??this.#t.streamIndex)<0)throw Error(`stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.`);return this.#a(e)}agent(e){return new ClientAgentSession(this.#e,e)}[followSession](e){return this.#a({...e,keepAlive:!0})}#r(e,t,n,r){return e.body?.cancel().catch(()=>{}),new MessageResponse({cancelTurn:async e=>await this.cancel({turnId:e}),createStream:e=>this.#i(n,t,r,e),deliveryId:r,sessionId:this.#t.sessionId})}async*#i(e,t,n,r){let i=0,a=n===void 0,o=!1,s=new TurnSegment({followCallbacks:!0});try{for await(let c of r??this.#s({headers:t.headers,keepAlive:!0,signal:t.signal,startIndex:e,streamReconnectPolicy:t.streamReconnectPolicy})){if(i+=1,n!==void 0){let e=c.meta?.deliveryIds?.includes(n)===!0,t=c.type===`session.failed`||c.type===`session.completed`;if(!e&&t&&(!a||c.type===`session.completed`))throw Error(`The session ended before the accepted message reached its turn boundary.`);if(!a&&!e||!t&&c.meta?.deliveryIds!==void 0&&!e)continue;a=!0}if(o=s.observe(c),yield c,o)break}if(n!==void 0&&!o&&!t.signal?.aborted)throw Error(`The response stream ended before the accepted message reached its turn boundary.`)}finally{this.#o(e+i)}}async*#a(e){let t=e?.startIndex??this.#t.streamIndex,n=0;for await(let r of this.#s({follow:e?.follow,headers:e?.headers,keepAlive:e?.keepAlive,onCaughtUp:e?.onCaughtUp,resolveHeaders:e?.resolveHeaders,resolveReconnectPolicy:e?.resolveReconnectPolicy,signal:e?.signal,startIndex:t,streamReconnectPolicy:e?.streamReconnectPolicy}))n+=1,t>=0&&this.#o(t+n),yield r}#o(e){this.#t={sessionId:this.#t.sessionId,streamIndex:Math.max(this.#t.streamIndex,e)}}#s(e){return followStreamIterable({onCaughtUp:e.onCaughtUp,follow:e.follow,host:this.#e.host,keepAlive:e.keepAlive,resolveHeaders:()=>this.#e.resolveHeaders(e.resolveHeaders?.()??e.headers),path:createEveSessionStreamRoutePath(this.#t.sessionId),redirect:this.#e.redirect,signal:e.signal,startIndex:e.startIndex,streamReconnectPolicy:e.streamReconnectPolicy,resolveReconnectPolicy:e.resolveReconnectPolicy})}};function followClientSession(e,t){return e[followSession](t)}async function postSessionSend(e,t,n){let r=Date.now()+2e4,i=250;for(;;){try{return await postTurn(e,t,n,!1)}catch(e){if(!isSessionNotReady(e))throw e;let t=r-Date.now();if(t<=0)throw e;await sleep(Math.min(i,t),n.signal)}n.signal?.throwIfAborted(),i=Math.min(i*2,2e3)}}async function postCreateSession(e,t){let n=await e.resolveHeaders(t.headers),r=await fetch(createClientUrl(e.host,EVE_SESSION_ROUTE_PATH),{headers:n,method:`POST`,redirect:e.redirect,signal:t.signal??null});if(!r.ok){let e=await r.text();throw new ClientError(r.status,e,r.headers)}return r}function isSessionNotReady(e){return e instanceof ClientError&&e.status===409&&e.code===`session_not_ready`}async function postTurn(e,t,n,r){let i=createMessageBody(n,r);if(i===null)throw Error(r?`Creating a session requires a non-empty message.`:`A session turn requires a non-empty message or inputResponses.`);let a=await e.resolveHeaders(n.headers);a.set(`content-type`,`application/json`);let o=await fetch(createClientUrl(e.host,t),{body:JSON.stringify(i),headers:a,method:`POST`,redirect:e.redirect,signal:n.signal??null});if(!o.ok){let e=await o.text();throw new ClientError(o.status,e,o.headers)}return o}async function readAcceptedMessage(e,t){let n=await e.json(),r=(typeof n.sessionId==`string`?n.sessionId:void 0)??e.headers.get(EVE_SESSION_ID_HEADER)?.trim()??t;if(!r)throw Error(`Message route did not return a session id.`);return{sessionId:r,deliveryId:typeof n.deliveryId==`string`&&n.deliveryId.length>0?n.deliveryId:void 0}}function createMessageBody(e,t){let n={};e.message!==void 0&&(n.message=e.message),e.inputResponses!==void 0&&e.inputResponses.length>0&&(n.inputResponses=e.inputResponses),!t&&e.message!==void 0&&e.turnPolicy!==void 0&&(n.turnPolicy=e.turnPolicy),e.clientContext!==void 0&&(n.clientContext=e.clientContext);let r=serializeOutputSchema(e.outputSchema);return r!==void 0&&(n.outputSchema=r),t&&n.message===void 0||n.message===void 0&&n.inputResponses===void 0?null:n}export{ClientSession,followClientSession};
@@ -232,7 +232,8 @@ export interface MessageResult<TOutput = unknown> {
232
232
  */
233
233
  readonly events: MessageStreamEvent[];
234
234
  /**
235
- * HITL input requests emitted during this turn.
235
+ * HITL input requests emitted in this response and still open at its boundary.
236
+ * Earlier requests may remain open in the same session.
236
237
  */
237
238
  readonly inputRequests: readonly InputRequest[];
238
239
  /**
@@ -20,8 +20,8 @@
20
20
  "env-runner": "0.1.16",
21
21
  "@eve/catalog": "0.0.1",
22
22
  "@ai-sdk/google": "4.0.74",
23
- "gray-matter": "4.0.3",
24
23
  "jose": "6.2.3",
24
+ "js-yaml": "4.3.2",
25
25
  "jsonc-parser": "3.3.1",
26
26
  "@types/json-schema": "7.0.15",
27
27
  "just-secrets": "0.0.2",
@@ -57,7 +57,7 @@
57
57
  "zod": "4.5.4",
58
58
  "zod-validation-error": "5.0.0"
59
59
  },
60
- "scriptHash": "3fdc6b497a398094f58f45f9430c9df5b90b43e07ec6f24725a31a02a78135d4",
60
+ "scriptHash": "0a49e17debf66c6cf63f7daea4e4e81cd1f060b1b23585bc85165e9a82d1fad1",
61
61
  "toolVersions": {
62
62
  "rolldown": "1.2.9",
63
63
  "typescript": "7.0.2"
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ (The MIT License)
2
2
 
3
- Copyright (c) 2014-2018, Jon Schlinkert.
3
+ Copyright (C) 2011-2015 by Vitaly Puzrin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,12 @@
1
+ // Hand-authored declaration for the vendored slice of `js-yaml` v4, which
2
+ // ships no types. Only `load` is vendored.
3
+
4
+ export interface LoadOptions {
5
+ /** File name used in error messages. */
6
+ filename?: string;
7
+ /** Allows duplicate mapping keys, keeping the last value. Defaults to `false`. */
8
+ json?: boolean;
9
+ }
10
+
11
+ /** Parses one YAML document with the default (data-only) schema. */
12
+ export function load(source: string, options?: LoadOptions): unknown;