eve 0.47.2 → 0.47.5

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 (289) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/bin/eve.js +4 -0
  3. package/dist/src/channel/activity-renderer.d.ts +21 -0
  4. package/dist/src/channel/activity-renderer.js +1 -0
  5. package/dist/src/channel/activity-sink.d.ts +2 -0
  6. package/dist/src/channel/activity-sink.js +1 -0
  7. package/dist/src/channel/auth/oidc.js +1 -1
  8. package/dist/src/channel/channel-address.js +1 -1
  9. package/dist/src/channel/compiled-channel.d.ts +2 -0
  10. package/dist/src/channel/compiled-channel.js +2 -2
  11. package/dist/src/channel/forwarded-principal.js +1 -1
  12. package/dist/src/channel/session.d.ts +3 -2
  13. package/dist/src/channel/session.js +1 -1
  14. package/dist/src/channel/types.d.ts +11 -0
  15. package/dist/src/chunks/{use-eve-agent-CacMaX4P.js → use-eve-agent-DjYwFJF7.js} +1 -0
  16. package/dist/src/chunks/{use-eve-agent-kmlFdOBB.js → use-eve-agent-DkUB0Ok4.js} +1 -0
  17. package/dist/src/cli/dev/tui/status-line.d.ts +6 -0
  18. package/dist/src/cli/dev/tui/status-line.js +1 -1
  19. package/dist/src/cli/dev/tui/terminal-renderer.js +12 -12
  20. package/dist/src/cli/dev/tui/traces/trace-conversation.js +1 -1
  21. package/dist/src/cli/dev/tui/tui.js +1 -1
  22. package/dist/src/compiled/.vendor-stamp.json +1 -1
  23. package/dist/src/compiled/@opentelemetry/api/index.d.ts +37 -0
  24. package/dist/src/compiled/@vercel/otel/index.d.ts +11 -0
  25. package/dist/src/compiler/extension-compatibility.d.ts +11 -9
  26. package/dist/src/compiler/extension-compatibility.js +1 -1
  27. package/dist/src/compiler/manifest.d.ts +14 -2
  28. package/dist/src/compiler/manifest.js +1 -1
  29. package/dist/src/compiler/normalize-connection.d.ts +9 -2
  30. package/dist/src/compiler/normalize-connection.js +1 -1
  31. package/dist/src/compiler/normalize-manifest.js +1 -1
  32. package/dist/src/compiler/normalize-subagent.js +1 -1
  33. package/dist/src/compiler/validate-artifact.js +1 -1
  34. package/dist/src/context/dynamic-connection-lifecycle.d.ts +9 -0
  35. package/dist/src/context/dynamic-connection-lifecycle.js +1 -0
  36. package/dist/src/context/keys.d.ts +5 -2
  37. package/dist/src/context/keys.js +1 -1
  38. package/dist/src/context/memory-tools.js +1 -1
  39. package/dist/src/context/providers/connection.js +1 -1
  40. package/dist/src/dynamic/definition.d.ts +6 -3
  41. package/dist/src/dynamic/definition.js +1 -1
  42. package/dist/src/eve-channel/activity-observer-request.d.ts +7 -0
  43. package/dist/src/eve-channel/activity-observer-request.js +1 -0
  44. package/dist/src/eve-channel/index.js +1 -1
  45. package/dist/src/eve-channel/request.d.ts +3 -1
  46. package/dist/src/eve-channel/request.js +1 -1
  47. package/dist/src/execution/activity-collector.d.ts +12 -0
  48. package/dist/src/execution/activity-collector.js +1 -0
  49. package/dist/src/execution/activity-events.d.ts +7 -0
  50. package/dist/src/execution/activity-events.js +1 -0
  51. package/dist/src/execution/activity-route.d.ts +2 -0
  52. package/dist/src/execution/activity-route.js +1 -0
  53. package/dist/src/execution/activity-text.d.ts +3 -0
  54. package/dist/src/execution/activity-text.js +1 -0
  55. package/dist/src/execution/activity-work-id.d.ts +9 -0
  56. package/dist/src/execution/activity-work-id.js +1 -0
  57. package/dist/src/execution/activity-work.d.ts +20 -0
  58. package/dist/src/execution/activity-work.js +1 -0
  59. package/dist/src/execution/agent-handle-dispatch.d.ts +3 -1
  60. package/dist/src/execution/agent-handle-dispatch.js +1 -1
  61. package/dist/src/execution/authorization-callback-match.js +1 -1
  62. package/dist/src/execution/cancelled-turn-message.d.ts +2 -0
  63. package/dist/src/execution/cancelled-turn-message.js +1 -0
  64. package/dist/src/execution/delegated-parent-notification.js +1 -1
  65. package/dist/src/execution/dispatch-runtime-actions-shared.d.ts +8 -0
  66. package/dist/src/execution/dispatch-runtime-actions-shared.js +1 -1
  67. package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
  68. package/dist/src/execution/dynamic-connections.d.ts +9 -0
  69. package/dist/src/execution/dynamic-connections.js +1 -0
  70. package/dist/src/execution/eve-workflow-attributes.js +1 -1
  71. package/dist/src/execution/node-step.d.ts +2 -0
  72. package/dist/src/execution/node-step.js +1 -1
  73. package/dist/src/execution/remote-agent-dispatch.d.ts +3 -1
  74. package/dist/src/execution/remote-agent-dispatch.js +1 -1
  75. package/dist/src/execution/runtime-context.js +1 -1
  76. package/dist/src/execution/sandbox/bindings/vercel-credentials.js +1 -1
  77. package/dist/src/execution/session-activity-projection.d.ts +14 -0
  78. package/dist/src/execution/session-activity-projection.js +1 -0
  79. package/dist/src/execution/session-activity-renderer-step.d.ts +15 -0
  80. package/dist/src/execution/session-activity-renderer-step.js +1 -0
  81. package/dist/src/execution/session-activity.d.ts +6 -0
  82. package/dist/src/execution/session-activity.js +1 -0
  83. package/dist/src/execution/session-callback-request.d.ts +1 -0
  84. package/dist/src/execution/session-callback-request.js +1 -1
  85. package/dist/src/execution/session-callback-route.js +1 -1
  86. package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
  87. package/dist/src/execution/subagent-start-local.d.ts +1 -0
  88. package/dist/src/execution/subagent-start-local.js +1 -1
  89. package/dist/src/execution/subagent-start-remote.d.ts +1 -0
  90. package/dist/src/execution/subagent-start-remote.js +1 -1
  91. package/dist/src/execution/subagent-tool.d.ts +2 -1
  92. package/dist/src/execution/subagent-tool.js +1 -1
  93. package/dist/src/execution/submit-activity.d.ts +7 -0
  94. package/dist/src/execution/submit-activity.js +1 -0
  95. package/dist/src/execution/tasks/child/steps.d.ts +8 -0
  96. package/dist/src/execution/tasks/child/steps.js +1 -1
  97. package/dist/src/execution/tasks/child/update.js +1 -1
  98. package/dist/src/execution/tasks/child/workflow.d.ts +3 -0
  99. package/dist/src/execution/tasks/child/workflow.js +1 -1
  100. package/dist/src/execution/tasks/parent/delegate.d.ts +3 -0
  101. package/dist/src/execution/tasks/parent/delegate.js +1 -1
  102. package/dist/src/execution/tasks/parent/dispatch-task-step.js +1 -1
  103. package/dist/src/execution/tasks/parent/hitl-proxy-steps.js +1 -1
  104. package/dist/src/execution/tasks/parent/tool-execution.js +1 -1
  105. package/dist/src/execution/terminate-child-sessions-step.js +1 -1
  106. package/dist/src/execution/tools/connection-search.js +2 -2
  107. package/dist/src/execution/tools/load-skill.js +1 -1
  108. package/dist/src/execution/tools/subagent/local.js +1 -1
  109. package/dist/src/execution/turn-control-receiver.js +1 -1
  110. package/dist/src/execution/turn-workflow.js +1 -1
  111. package/dist/src/execution/web-fetch/request.js +1 -1
  112. package/dist/src/execution/wire/session-inbox-contract.d.ts +2 -2
  113. package/dist/src/execution/wire/session-inbox-contract.js +1 -1
  114. package/dist/src/execution/wire/session-inbox-encoder.d.ts +6 -2
  115. package/dist/src/execution/wire/session-inbox-encoder.js +1 -1
  116. package/dist/src/execution/wire/session-inbox-wire.js +1 -1
  117. package/dist/src/execution/wire/session-inbox-wire.v2-migration.d.ts +4 -0
  118. package/dist/src/execution/wire/session-inbox-wire.v2-migration.js +1 -0
  119. package/dist/src/execution/wire/session-inbox-wire.v2.d.ts +478 -0
  120. package/dist/src/execution/wire/session-inbox-wire.v2.js +1 -0
  121. package/dist/src/execution/workflow-entry.js +1 -1
  122. package/dist/src/execution/workflow-runtime.d.ts +4 -0
  123. package/dist/src/execution/workflow-runtime.js +1 -1
  124. package/dist/src/execution/workflow-steps.js +1 -1
  125. package/dist/src/execution/workflow-trace-context.d.ts +3 -6
  126. package/dist/src/execution/workflow-trace-context.js +1 -1
  127. package/dist/src/harness/approval-delivery-coordinator.js +1 -1
  128. package/dist/src/harness/authorization.d.ts +11 -4
  129. package/dist/src/harness/authorization.js +1 -1
  130. package/dist/src/harness/inline-tool-authorization.d.ts +13 -1
  131. package/dist/src/harness/inline-tool-authorization.js +1 -1
  132. package/dist/src/harness/model-call-error.js +1 -1
  133. package/dist/src/harness/semantic-errors/rule.d.ts +5 -2
  134. package/dist/src/harness/semantic-errors/rules/gateway.js +1 -1
  135. package/dist/src/harness/tool-loop.js +2 -2
  136. package/dist/src/harness/tool-model-output.js +1 -1
  137. package/dist/src/harness/turn-tag-state.d.ts +1 -1
  138. package/dist/src/harness/types.d.ts +2 -2
  139. package/dist/src/{harness → instrumentation}/ai-sdk-hook-bridge.d.ts +1 -1
  140. package/dist/src/instrumentation/ai-sdk-hook-bridge.js +1 -0
  141. package/dist/src/{harness → instrumentation}/ai-sdk-telemetry.d.ts +5 -1
  142. package/dist/src/instrumentation/ai-sdk-telemetry.js +1 -0
  143. package/dist/src/{harness/channel-delivery-instrumentation.d.ts → instrumentation/channel-delivery.d.ts} +5 -7
  144. package/dist/src/instrumentation/channel-delivery.js +1 -0
  145. package/dist/src/{harness/instrumentation → instrumentation}/config.d.ts +0 -10
  146. package/dist/src/instrumentation/config.js +1 -0
  147. package/dist/src/instrumentation/content-policy.d.ts +5 -0
  148. package/dist/src/instrumentation/content-policy.js +1 -0
  149. package/dist/src/{harness/instrumentation → instrumentation}/content.d.ts +1 -1
  150. package/dist/src/{harness/instrumentation → instrumentation}/dispatch.d.ts +1 -1
  151. package/dist/src/instrumentation/dispatch.js +1 -0
  152. package/dist/src/{harness/instrumentation → instrumentation}/lifecycle.d.ts +34 -35
  153. package/dist/src/instrumentation/lifecycle.js +1 -0
  154. package/dist/src/{harness/instrumentation → instrumentation}/native-events.d.ts +1 -1
  155. package/dist/src/instrumentation/native-events.js +1 -0
  156. package/dist/src/{harness → instrumentation}/parent-lineage.d.ts +1 -1
  157. package/dist/src/instrumentation/prepare-trace-context.d.ts +24 -0
  158. package/dist/src/instrumentation/prepare-trace-context.js +1 -0
  159. package/dist/src/instrumentation/provider.d.ts +13 -9
  160. package/dist/src/{harness/instrumentation → instrumentation}/providers.d.ts +1 -1
  161. package/dist/src/instrumentation/providers.js +1 -0
  162. package/dist/src/{harness/instrumentation → instrumentation}/runtime-context.d.ts +13 -2
  163. package/dist/src/instrumentation/runtime-context.js +1 -0
  164. package/dist/src/instrumentation/runtime.d.ts +100 -0
  165. package/dist/src/instrumentation/runtime.js +1 -0
  166. package/dist/src/{harness/instrumentation → instrumentation}/state.d.ts +2 -11
  167. package/dist/src/internal/application/compiled-artifacts.js +4 -4
  168. package/dist/src/internal/application/package.js +1 -1
  169. package/dist/src/internal/authored-definition/connection.js +1 -1
  170. package/dist/src/internal/instrumentation.d.ts +1 -1
  171. package/dist/src/internal/nitro/routes/channel-request-instrumentation.d.ts +4 -6
  172. package/dist/src/internal/nitro/routes/channel-request-instrumentation.js +1 -1
  173. package/dist/src/internal/user-agent.d.ts +2 -0
  174. package/dist/src/internal/user-agent.js +1 -1
  175. package/dist/src/packages/eve-catalog/src/index.js +1 -1
  176. package/dist/src/protocol/activity.d.ts +105 -0
  177. package/dist/src/protocol/activity.js +1 -0
  178. package/dist/src/protocol/message.js +2 -2
  179. package/dist/src/protocol/routes.d.ts +4 -0
  180. package/dist/src/protocol/routes.js +1 -1
  181. package/dist/src/public/channels/auth.js +1 -1
  182. package/dist/src/public/channels/slack/defaults.js +6 -3
  183. package/dist/src/public/channels/slack/index.d.ts +1 -1
  184. package/dist/src/public/channels/slack/interactions.d.ts +8 -5
  185. package/dist/src/public/channels/slack/interactions.js +1 -1
  186. package/dist/src/public/channels/slack/slackChannel.d.ts +66 -1
  187. package/dist/src/public/channels/slack/slash-command.d.ts +9 -0
  188. package/dist/src/public/channels/slack/slash-command.js +1 -0
  189. package/dist/src/public/connections/index.d.ts +2 -0
  190. package/dist/src/public/connections/index.js +1 -1
  191. package/dist/src/public/definitions/connections/dynamic.d.ts +23 -0
  192. package/dist/src/public/definitions/connections/dynamic.js +1 -0
  193. package/dist/src/public/definitions/connections/mcp.d.ts +8 -0
  194. package/dist/src/public/definitions/connections/openapi.d.ts +8 -0
  195. package/dist/src/public/definitions/connections/protocol.d.ts +6 -0
  196. package/dist/src/public/definitions/connections/protocol.js +1 -1
  197. package/dist/src/runtime/channels/registry.js +1 -1
  198. package/dist/src/runtime/connections/authorization-tokens.d.ts +11 -10
  199. package/dist/src/runtime/connections/instance-identity.d.ts +12 -0
  200. package/dist/src/runtime/connections/instance-identity.js +1 -0
  201. package/dist/src/runtime/connections/mcp-client.js +1 -1
  202. package/dist/src/runtime/connections/openapi-client.js +1 -1
  203. package/dist/src/runtime/connections/registry.d.ts +2 -0
  204. package/dist/src/runtime/connections/registry.js +1 -1
  205. package/dist/src/runtime/connections/scoped-authorization.d.ts +10 -6
  206. package/dist/src/runtime/connections/scoped-authorization.js +1 -1
  207. package/dist/src/runtime/resolve-agent.js +1 -1
  208. package/dist/src/runtime/resolve-connection.d.ts +5 -0
  209. package/dist/src/runtime/resolve-connection.js +1 -1
  210. package/dist/src/runtime/resolve-dynamic-connection.d.ts +5 -0
  211. package/dist/src/runtime/resolve-dynamic-connection.js +1 -0
  212. package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
  213. package/dist/src/runtime/types.d.ts +11 -0
  214. package/dist/src/setup/flows/registry.js +1 -1
  215. package/dist/src/setup/gateway-models.js +1 -1
  216. package/dist/src/setup/scaffold/create/project.js +1 -1
  217. package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
  218. package/dist/src/setup/scaffold/create/web-template.js +9 -5
  219. package/dist/src/shared/trace-policy.d.ts +20 -0
  220. package/dist/src/shared/trace-policy.js +1 -0
  221. package/dist/src/svelte/index.js +1 -1
  222. package/dist/src/svelte/use-eve-agent.js +1 -1
  223. package/dist/src/tracing/agent-action-instrumentation.d.ts +1 -1
  224. package/dist/src/tracing/agent-action-instrumentation.js +1 -1
  225. package/dist/src/tracing/agent-approval-instrumentation.d.ts +1 -3
  226. package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
  227. package/dist/src/tracing/agent-channel-delivery-instrumentation.d.ts +1 -1
  228. package/dist/src/tracing/agent-channel-delivery-instrumentation.js +1 -1
  229. package/dist/src/tracing/agent-otel-provider.d.ts +4 -4
  230. package/dist/src/tracing/agent-otel-provider.js +2 -2
  231. package/dist/src/tracing/agent-otel-runtime-context.d.ts +5 -0
  232. package/dist/src/tracing/agent-otel-runtime-context.js +1 -0
  233. package/dist/src/tracing/agent-otel-session-context.d.ts +3 -3
  234. package/dist/src/tracing/agent-otel-session-context.js +1 -1
  235. package/dist/src/tracing/agent-otel-usage.d.ts +4 -2
  236. package/dist/src/tracing/agent-otel-usage.js +1 -1
  237. package/dist/src/tracing/agent-span-id-generator.d.ts +1 -1
  238. package/dist/src/tracing/agent-tool-instrumentation.d.ts +1 -1
  239. package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
  240. package/dist/src/tracing/agent-trace-context-store.d.ts +6 -0
  241. package/dist/src/tracing/agent-trace-context-store.js +1 -1
  242. package/dist/src/tracing/agent-trace-context.d.ts +3 -0
  243. package/dist/src/tracing/agent-trace-context.js +1 -0
  244. package/dist/src/tracing/agent-trace-state.d.ts +10 -1
  245. package/dist/src/tracing/agent-trace-state.js +1 -1
  246. package/dist/src/tracing/install-instrumentation-runtime.d.ts +3 -2
  247. package/dist/src/tracing/install-instrumentation-runtime.js +1 -1
  248. package/dist/src/tracing/local-instrumentation-runtime.d.ts +1 -1
  249. package/dist/src/tracing/local-instrumentation-runtime.js +1 -1
  250. package/dist/src/tracing/local-trace-reader.d.ts +1 -0
  251. package/dist/src/tracing/local-trace-reader.js +1 -1
  252. package/dist/src/tracing/otel-declaration.d.ts +20 -19
  253. package/dist/src/tracing/otel-declaration.js +1 -1
  254. package/dist/src/tracing/otel-registration.js +1 -1
  255. package/dist/src/tracing/sampled-trace.d.ts +1 -14
  256. package/dist/src/tracing/sampled-trace.js +1 -1
  257. package/dist/src/vue/index.js +1 -1
  258. package/dist/src/vue/use-eve-agent.js +1 -1
  259. package/docs/channels/slack.mdx +25 -5
  260. package/docs/connections/overview.mdx +46 -2
  261. package/docs/extensions.md +2 -2
  262. package/docs/getting-started.mdx +1 -1
  263. package/docs/guides/dynamic-capabilities.md +91 -5
  264. package/docs/memory.md +7 -4
  265. package/docs/reference/cli.md +8 -8
  266. package/docs/reference/typescript-api.md +32 -23
  267. package/package.json +1 -1
  268. package/dist/src/execution/subagent-usage-span.d.ts +0 -9
  269. package/dist/src/execution/subagent-usage-span.js +0 -1
  270. package/dist/src/harness/ai-sdk-hook-bridge.js +0 -1
  271. package/dist/src/harness/ai-sdk-telemetry.js +0 -1
  272. package/dist/src/harness/channel-delivery-instrumentation.js +0 -1
  273. package/dist/src/harness/instrumentation/config.js +0 -1
  274. package/dist/src/harness/instrumentation/content-policy.d.ts +0 -7
  275. package/dist/src/harness/instrumentation/content-policy.js +0 -1
  276. package/dist/src/harness/instrumentation/dispatch.js +0 -1
  277. package/dist/src/harness/instrumentation/lifecycle.js +0 -1
  278. package/dist/src/harness/instrumentation/native-events.js +0 -1
  279. package/dist/src/harness/instrumentation/providers.js +0 -1
  280. package/dist/src/harness/instrumentation/runtime-context.js +0 -1
  281. package/dist/src/harness/instrumentation/runtime.d.ts +0 -21
  282. package/dist/src/harness/instrumentation/runtime.js +0 -1
  283. package/dist/src/harness/prepare-trace-context.d.ts +0 -21
  284. package/dist/src/harness/prepare-trace-context.js +0 -1
  285. /package/dist/src/{harness/instrumentation → instrumentation}/content.js +0 -0
  286. /package/dist/src/{harness → instrumentation}/parent-lineage.js +0 -0
  287. /package/dist/src/{harness/instrumentation → instrumentation}/setup-context.d.ts +0 -0
  288. /package/dist/src/{harness/instrumentation → instrumentation}/setup-context.js +0 -0
  289. /package/dist/src/{harness/instrumentation → instrumentation}/state.js +0 -0
@@ -1,9 +1,9 @@
1
1
  ---
2
2
  title: "Dynamic Capabilities"
3
- description: "Resolve models, subagents, tools, skills, and instructions at runtime with defineDynamic resolver events."
3
+ description: "Resolve models, subagents, connections, tools, skills, and instructions at runtime with defineDynamic resolver events."
4
4
  ---
5
5
 
6
- `defineDynamic` resolves the model, subagents, tools, skills, and instructions at runtime from a session event instead of declaring them up front. Reach for it when the right capability isn't known until the session starts, because it hinges on who the caller is, what tenant they belong to, feature flags, or external data. The [subagents](../subagents), [tools](../tools), [skills](../skills), and [instructions](../instructions) guides each point here for their dynamic form.
6
+ `defineDynamic` resolves the model, subagents, connections, tools, skills, and instructions at runtime from a session event instead of declaring them up front. Reach for it when the right capability isn't known until the session starts, because it hinges on who the caller is, what tenant they belong to, feature flags, or external data. The [subagents](../subagents), [connections](../connections), [tools](../tools), [skills](../skills), and [instructions](../instructions) guides each point here for their dynamic form.
7
7
 
8
8
  eve evaluates a dynamic definition module once during compilation to classify and validate it, then retains that module as a runtime entry so its event handlers can run. Its top-level code therefore runs in both phases; keep caller-specific work inside the handlers. See [Authored module lifecycle](../reference/typescript-api#authored-module-lifecycle).
9
9
 
@@ -20,8 +20,8 @@ full contract.
20
20
 
21
21
  Dynamic models do not compile a default model or model metadata. When a
22
22
  resolver first selects a model, eve normalizes the selection and resolves any
23
- omitted context-window metadata from the AI Gateway catalog. Dynamic tools,
24
- skills, instructions, and subagents may return `null` to omit a capability.
23
+ omitted context-window metadata from the AI Gateway catalog. Dynamic connections,
24
+ tools, skills, instructions, and subagents may return `null` to omit a capability.
25
25
 
26
26
  ### Route image inputs to a vision model
27
27
 
@@ -132,6 +132,91 @@ availability as capability composition, not as the only authorization
132
132
  boundary: sensitive child tools still need their own authorization and
133
133
  approval checks.
134
134
 
135
+ ## Dynamic connections
136
+
137
+ Use a dynamic connection when the available MCP servers or OpenAPI services
138
+ depend on the authenticated caller. A handler returns one
139
+ `defineMcpClientConnection(...)` or `defineOpenAPIConnection(...)`, a map of
140
+ connection definitions, or `null`. Wrap every returned connection in its
141
+ protocol helper. Connection resolvers receive `ctx.session` and
142
+ `ctx.channel.kind`; they do not receive conversation messages, delivery
143
+ payloads, tool inputs, model outputs, continuation tokens, or free-form channel
144
+ metadata. Select accounts and endpoints from authenticated session identity or
145
+ application-owned data.
146
+
147
+ This example exposes one MCP connection for each cloud account enabled for the
148
+ current user:
149
+
150
+ ```ts title="agent/connections/accounts.ts"
151
+ import { defineDynamic, defineMcpClientConnection } from "eve/connections";
152
+ import { listEnabledAccounts, mintAccountToken } from "../lib/accounts";
153
+
154
+ export default defineDynamic({
155
+ events: {
156
+ "session.started": async (_event, ctx) => {
157
+ const principal = ctx.session.auth.current;
158
+ if (principal?.principalType !== "user") return null;
159
+
160
+ const accounts = await listEnabledAccounts(principal);
161
+ return Object.fromEntries(
162
+ accounts.map((account) => [
163
+ account.slug,
164
+ defineMcpClientConnection({
165
+ url: "https://mcp.cloud.example.com",
166
+ description: `${account.label} (${account.accountId})`,
167
+ instanceKey: account.accountId,
168
+ auth: {
169
+ principalType: "user",
170
+ getToken: ({ principal }) => mintAccountToken(principal, account),
171
+ },
172
+ }),
173
+ ]),
174
+ );
175
+ },
176
+ },
177
+ });
178
+ ```
179
+
180
+ The returned definitions use the same auth, headers, filtering, provided
181
+ arguments, and approval options as static [MCP](../connections/mcp) and
182
+ [OpenAPI](../connections/openapi) connections. Each resolved connection joins
183
+ the per-step connection registry, appears in `connection_search`, and exposes
184
+ discovered tools as `<connection>__<tool>`.
185
+
186
+ Set `instanceKey` on every authenticated dynamic connection. Use a stable,
187
+ non-secret account or tenant identifier, and change it whenever the endpoint,
188
+ account, or auth provider changes. eve hashes the value before storing the
189
+ resolved instance identity in durable authorization state. If a parked sign-in
190
+ callback resumes after the resolver selects a different instance, eve rejects
191
+ the callback instead of passing it to the new connection or reusing its token.
192
+
193
+ ### Naming and conflicts
194
+
195
+ | Return shape | File | Connection name(s) |
196
+ | ----------------------------- | ------------------------------- | ----------------------- |
197
+ | single connection definition | `agent/connections/accounts.ts` | `accounts` |
198
+ | map `{ production, staging }` | `agent/connections/accounts.ts` | `production`, `staging` |
199
+
200
+ A map key must be a legal connection name: lowercase ASCII letters, digits,
201
+ and dashes, starting with a letter, up to 64 characters. Map keys are bare;
202
+ eve does not prefix them with the file slug. A dynamic connection overrides a
203
+ same-named static connection. Two effective dynamic resolvers cannot emit the
204
+ same name; namespace one map key to remove the ambiguity.
205
+
206
+ ### Events and recovery
207
+
208
+ Dynamic connections support `session.started` and `turn.started`. A turn result
209
+ replaces that file's session result for the turn, including when the turn
210
+ handler returns `null`. A throwing or invalid handler fails the lifecycle
211
+ without rebuilding the registry, so a static connection shadowed by the
212
+ dynamic result cannot reappear as a fallback.
213
+
214
+ eve may run the active session and turn handlers again when a parked turn
215
+ resumes or a durable step retries. This rebuilds live auth, header, approval,
216
+ and provided-argument callbacks without serializing them into workflow state.
217
+ Keep connection resolvers idempotent, and keep external side effects outside
218
+ the handler.
219
+
135
220
  ## Dynamic tools
136
221
 
137
222
  Pass `defineDynamic` an `events` object whose handlers return either a single `defineTool(...)`, a `Record<string, defineTool(...)>`, or `null` for no tools. Wrap every entry in `defineTool()`. eve records durable descriptors for `execute`, approval request and response policies, and `toModelOutput`, so a parked call can reconstruct the same callbacks in a fresh process.
@@ -189,7 +274,7 @@ A single return produces one tool named after the file slug, identical to a stat
189
274
 
190
275
  ### Conflicts
191
276
 
192
- A dynamic tool or skill whose name matches an **authored** one **overrides** it — a per-caller resolver can replace a built-in by name. Two **dynamic** resolvers emitting the same name is a genuine ambiguity and throws; namespace one of the keys manually to resolve it.
277
+ A dynamic connection, tool, or skill whose name matches an **authored** one **overrides** it — a per-caller resolver can replace a static capability by name. Two **dynamic** resolvers of the same capability type emitting the same name is a genuine ambiguity and throws; namespace one of the keys manually to resolve it.
193
278
 
194
279
  ### Events
195
280
 
@@ -310,6 +395,7 @@ Dynamic system content that changes frequently can reduce provider prompt-cache
310
395
  ## What to read next
311
396
 
312
397
  - Conditionally expose a specialist → [Subagents](../subagents)
398
+ - Resolve caller-specific external services → [Connections](../connections)
313
399
  - The static tool basics this builds on → [Tools](../tools)
314
400
  - The built-in tools and how to override them → [Built-in tools](../concepts/built-in-tools)
315
401
  - Authenticate a tool or connection to an external service → [Auth & route protection](./auth-and-route-protection)
package/docs/memory.md CHANGED
@@ -29,12 +29,15 @@ recall and maintain memory:
29
29
  | Provider | Status | Use it for |
30
30
  | --------------- | -------------- | ------------------------------------------------------------------------- |
31
31
  | `fileMemory()` | Built into eve | A bounded, model-maintained list of durable facts and preferences |
32
- | Supermemory | Coming soon | The first third-party implementation of the eve provider contract |
32
+ | Supermemory | Third-party | Semantic recall, automatic capture, source extraction, and memory tools |
33
33
  | Custom provider | Supported | Application-specific retrieval, capture, retention, or model-facing tools |
34
34
 
35
- Supermemory is building the first third-party provider for eve. It is not
36
- available yet; until it is released, use `fileMemory()` or implement the
37
- provider contract described below.
35
+ [Supermemory](https://github.com/supermemoryai/eve-supermemory#readme) is a
36
+ third-party provider that recalls relevant context before each turn, captures
37
+ completed turns, and supplies search, memory-management, and source-extraction
38
+ tools. Add it with `eve add memory/supermemory`. It requires a Supermemory API
39
+ key and a memory scope you choose; review its retention and data handling before
40
+ sending sensitive content to the service.
38
41
 
39
42
  ## Use file memory
40
43
 
@@ -52,11 +52,11 @@ Coding-agent launches and non-interactive terminals cannot answer the location p
52
52
 
53
53
  After scaffolding, a human terminal usually continues into `eve dev`. If a coding-agent REPL is on `PATH`, the handoff menu can open it instead or exit without starting either process. Coding-agent launches print the next steps instead of opening the TUI, so the session does not get stuck. Fresh projects use the parent workspace's package manager when there is one; otherwise they use the manager that launched `eve init`.
54
54
 
55
- | Flag | Type | Default | Description |
56
- | ---------------------- | ------ | ---------------- | ------------------------------------------------------------------------------------------------------------------------ |
55
+ | Flag | Type | Default | Description |
56
+ | ---------------------- | ------ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
57
57
  | `--model <model>` | string | `openai/gpt-5.6-luna-fast` | Set the root agent's AI Gateway model ID. |
58
- | `--reasoning <effort>` | enum | provider default | Set reasoning to `none`, `minimal`, `low`, `medium`, `high`, or `xhigh`. `provider-default` leaves the field unauthored. |
59
- | `--channel-web-nextjs` | flag | off | Add the Web Chat app (Next.js). Not for existing projects — run `eve add channel/web` there instead. |
58
+ | `--reasoning <effort>` | enum | provider default | Set reasoning to `none`, `minimal`, `low`, `medium`, `high`, or `xhigh`. `provider-default` leaves the field unauthored. |
59
+ | `--channel-web-nextjs` | flag | off | Add the Web Chat app (Next.js). Not for existing projects — run `eve add channel/web` there instead. |
60
60
 
61
61
  ## `eve extension`
62
62
 
@@ -294,15 +294,15 @@ eve traces --json # dump the full trace as JSON
294
294
 
295
295
  Reads the immutable OTLP/JSON segments under `.eve/traces/v1`, so `eve dev` need not be running. Accepts a full trace id, an `agent.session.id`, or an unambiguous prefix of either. Malformed segments are skipped without hiding valid spans from the same trace.
296
296
 
297
- Span rows carry inline metrics when the span recorded them — `↑input`/`↓output` token counts, gateway cost, and the tool name for `ai.toolCall` spans — and the header aggregates models, token totals, cost, and error count across the trace's step spans. `--verbose` expands each span under its tree row: status (with the error message on failures), timing, ids, every attribute (prompts, responses, and tool payloads as transcripts or pretty-printed JSON), and every span event with its offset from span start. `--json` prints the same records as JSON, one object per selected trace.
297
+ Span rows carry inline metrics when the span recorded them — `↑input`/`↓output` token counts, gateway cost, and the tool name for `execute_tool` spans — and the header aggregates models, token totals, cost, and error count across the trace's step spans. `--verbose` expands each span under its tree row: status (with the error message on failures), timing, ids, every attribute (prompts, responses, and tool payloads as transcripts or pretty-printed JSON), and every span event with its offset from span start. `--json` prints the same records as JSON, one object per selected trace.
298
298
 
299
- A local subagent keeps its own session id but records into the parent trace. Its turn is parented to the `agent.action` span that dispatched it, so the span tree carries the relationship without duplicate lineage attributes; `agent.subagent.name` remains on the child turn as a standalone label. Either session id resolves to that trace. Remote agents propagate the parent trace context over `traceparent`.
299
+ A local subagent keeps its own session id but records into the parent trace. Its `invoke_agent` span is parented to the `agent.action` span that dispatched it, so the span tree carries the relationship without duplicate lineage attributes; `agent.subagent.name` remains on the child invocation as a standalone label. Either session id resolves to that trace. Remote agents propagate the parent trace context over `traceparent`.
300
300
 
301
301
  A durable session keeps one persisted trace context across turns and worker resumptions. Independently replayed attempts can still produce another trace; passing the session id shows every trace it produced, oldest first.
302
302
 
303
- Every span carries a real duration except `agent.session`: an idle session never closes, so it is recorded as a zero-duration marker and the span tree shows its descendant extent instead. A turn's span is written when the turn settles, so a running turn shows only its steps.
303
+ Every span carries a real duration except `agent.session`: an idle session never closes, so it is recorded as a zero-duration marker and the span tree shows its descendant extent instead. A turn's `invoke_agent` span is written when the turn settles, so a running turn shows only its steps.
304
304
 
305
- Model and tool-call spans omit their inputs and outputs by default. Set `EVE_TRACES_CONTENT=on` to capture system prompts, prompt messages, and response text for models, plus call arguments and results for tools. Each captured value is capped at 32 KB.
305
+ Model and `execute_tool` spans omit their inputs and outputs by default. Set `EVE_TRACES_CONTENT=on` to capture system prompts, prompt messages, and response text for models, plus call arguments and results for tools. Each captured value is capped at 32 KB.
306
306
 
307
307
  Step spans carry token counts, and cost when Vercel AI Gateway served the call. Both follow the [OTel GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai) (`gen_ai.usage.*`), so a third-party backend reads them without mapping.
308
308
 
@@ -30,28 +30,28 @@ export default defineTool({
30
30
 
31
31
  ## The define\* helpers
32
32
 
33
- | Helper | Import from | Authored at | Guide |
34
- | ----------------------------------------------------- | ---------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------ |
35
- | `defineAgent` | `eve` | `agent/agent.ts` | [agent.ts](../agent-config) |
36
- | `defineTool` | `eve/tools` | `agent/tools/<name>.ts` | [Tools](../tools) |
37
- | `defineDynamic` | `eve`, `eve/tools`, `eve/skills`, `eve/instructions` | dynamic model or subagent `agent.ts`; `agent/{tools,skills,instructions}/` | [Dynamic capabilities](../guides/dynamic-capabilities) |
38
- | `defineMcpClientConnection` | `eve/connections` | `agent/connections/<name>.ts` | [MCP connections](../connections/mcp) |
39
- | `defineOpenAPIConnection` | `eve/connections` | `agent/connections/<name>.ts` | [OpenAPI connections](../connections/openapi) |
40
- | `defineChannel` | `eve/channels` | `agent/channels/<name>.ts` | [Custom channels](../channels/custom) |
41
- | `eveChannel`, `slackChannel`, and the other platforms | `eve/channels/<platform>` | `agent/channels/<platform>.ts` | [Channels](../channels/overview) |
42
- | `defineSkill` | `eve/skills` | `agent/skills/<name>.ts` | [Skills](../skills) |
43
- | `defineInstructions` | `eve/instructions` | `agent/instructions.ts` | [Instructions](../instructions) |
44
- | `defineMemory`, `defineMemoryProvider` | `eve/memory` | `agent/memory.ts` or `agent/memory/<slot>.ts` | [Memory](../memory) |
45
- | `defineHook` | `eve/hooks` | `agent/hooks/<slug>.ts` | [Hooks](../guides/hooks) |
46
- | `defineSchedule` | `eve/schedules` | `agent/schedules/<name>.ts` | [Schedules](../schedules) |
47
- | `defineState` | `eve/context` | tools, hooks, lifecycle | [Session context](../guides/session-context) |
48
- | `defineSandbox` | `eve/sandbox` | `agent/sandbox.ts` | [Sandbox](../sandbox) |
49
- | `defineInstrumentation` | `eve/instrumentation` | `agent/instrumentation.ts` | [instrumentation.ts](../guides/instrumentation) |
50
- | `defineRemoteAgent` | `eve` | `agent/subagents/<id>/agent.ts` | [Remote agents](../guides/remote-agents) |
51
- | `defineEval` | `eve/evals` | `evals/*.eval.ts` | [Evals](../evals/overview) |
52
- | `defineEvalConfig` | `eve/evals` | `evals/evals.config.ts` | [Evals](../evals/overview) |
53
- | `mockModel` | `eve/evals` | Deterministic fixture agent models | [Evals](../evals/overview) |
54
- | `useEveAgent` | `eve/react`, `eve/vue`, `eve/svelte` | frontend | [Frontend](../guides/frontend/overview) |
33
+ | Helper | Import from | Authored at | Guide |
34
+ | ----------------------------------------------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ------------------------------------------------------ |
35
+ | `defineAgent` | `eve` | `agent/agent.ts` | [agent.ts](../agent-config) |
36
+ | `defineTool` | `eve/tools` | `agent/tools/<name>.ts` | [Tools](../tools) |
37
+ | `defineDynamic` | `eve`, `eve/tools`, `eve/skills`, `eve/instructions`, `eve/connections` | dynamic model or subagent `agent.ts`; `agent/{tools,skills,instructions,connections}/` | [Dynamic capabilities](../guides/dynamic-capabilities) |
38
+ | `defineMcpClientConnection` | `eve/connections` | `agent/connections/<name>.ts` | [MCP connections](../connections/mcp) |
39
+ | `defineOpenAPIConnection` | `eve/connections` | `agent/connections/<name>.ts` | [OpenAPI connections](../connections/openapi) |
40
+ | `defineChannel` | `eve/channels` | `agent/channels/<name>.ts` | [Custom channels](../channels/custom) |
41
+ | `eveChannel`, `slackChannel`, and the other platforms | `eve/channels/<platform>` | `agent/channels/<platform>.ts` | [Channels](../channels/overview) |
42
+ | `defineSkill` | `eve/skills` | `agent/skills/<name>.ts` | [Skills](../skills) |
43
+ | `defineInstructions` | `eve/instructions` | `agent/instructions.ts` | [Instructions](../instructions) |
44
+ | `defineMemory`, `defineMemoryProvider` | `eve/memory` | `agent/memory.ts` or `agent/memory/<slot>.ts` | [Memory](../memory) |
45
+ | `defineHook` | `eve/hooks` | `agent/hooks/<slug>.ts` | [Hooks](../guides/hooks) |
46
+ | `defineSchedule` | `eve/schedules` | `agent/schedules/<name>.ts` | [Schedules](../schedules) |
47
+ | `defineState` | `eve/context` | tools, hooks, lifecycle | [Session context](../guides/session-context) |
48
+ | `defineSandbox` | `eve/sandbox` | `agent/sandbox.ts` | [Sandbox](../sandbox) |
49
+ | `defineInstrumentation` | `eve/instrumentation` | `agent/instrumentation.ts` | [instrumentation.ts](../guides/instrumentation) |
50
+ | `defineRemoteAgent` | `eve` | `agent/subagents/<id>/agent.ts` | [Remote agents](../guides/remote-agents) |
51
+ | `defineEval` | `eve/evals` | `evals/*.eval.ts` | [Evals](../evals/overview) |
52
+ | `defineEvalConfig` | `eve/evals` | `evals/evals.config.ts` | [Evals](../evals/overview) |
53
+ | `mockModel` | `eve/evals` | Deterministic fixture agent models | [Evals](../evals/overview) |
54
+ | `useEveAgent` | `eve/react`, `eve/vue`, `eve/svelte` | frontend | [Frontend](../guides/frontend/overview) |
55
55
 
56
56
  Tool-wide authoring helpers such as `defineTool`, `defineDynamic`, and `disableTool` come from `eve/tools`. Capability-specific definitions and helpers use their own subpaths (see [Built-in tools](../concepts/built-in-tools)): reusable definitions such as `bash` and `glob` come from `eve/tools/<name>`, `webSearch` comes from `eve/tools/web_search`, `experimental_workflow` comes from `eve/tools/workflow`, `sleep` comes from `eve/tools/sleep`, and approval policies and types come from `eve/tools/approval`. The route verbs `GET`/`HEAD`/`POST`/`PUT`/`PATCH`/`DELETE`/`OPTIONS`/`WS` plus `disableRoute` come from `eve/channels`, and the channel auth helpers `localDev`/`vercelOidc`/`placeholderAuth` come from `eve/channels/auth`.
57
57
 
@@ -59,6 +59,15 @@ Tool-wide authoring helpers such as `defineTool`, `defineDynamic`, and `disableT
59
59
 
60
60
  `defineInstructions` accepts `{ content: string, role?: "system" | "user" }`; omitted `role` means `"system"`. Its `eve/instructions` version of `defineDynamic` accepts only `session.started` and `turn.started` handlers returning `defineInstructions(...)` or `null`. The legacy `{ markdown: string }` definition remains available as a deprecated system-role form.
61
61
 
62
+ The `eve/connections` version of `defineDynamic` accepts `session.started` and
63
+ `turn.started` handlers returning one MCP or OpenAPI connection definition, a
64
+ map of connection definitions, or `null`. Its resolver context exposes
65
+ authenticated session identity and `channel.kind`, but not conversation history,
66
+ delivery payloads, tool inputs, model outputs, or free-form channel metadata. An
67
+ authenticated returned definition must set `instanceKey` to a stable,
68
+ non-secret account or tenant identifier so durable authorization resumes cannot
69
+ cross resolved instances.
70
+
62
71
  ## Authored module lifecycle
63
72
 
64
73
  eve evaluates TypeScript definition modules during compilation so it can validate and normalize the agent. Within one agent node, each module namespace loads at most once during that compile. The resolved definition then determines whether the module is also an entry in the runtime bundle:
@@ -107,7 +116,7 @@ import template from "../../prompts/template.txt?raw";
107
116
  | `eve/tools/web_search` | Provider-managed `webSearch` configuration |
108
117
  | `eve/tools/workflow` | Experimental `Workflow` tool definition |
109
118
  | `eve/tools/sleep` | Opt-in durable `sleep` tool |
110
- | `eve/connections` | `defineMcpClientConnection`, `defineOpenAPIConnection` |
119
+ | `eve/connections` | `defineMcpClientConnection`, `defineOpenAPIConnection`, `defineDynamic` |
111
120
  | `eve/channels` | `defineChannel`, `disableRoute`, route verbs |
112
121
  | `eve/channels/eve` | `eveChannel` |
113
122
  | `eve/channels/auth` | `localDev`, `vercelOidc`, `placeholderAuth` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve",
3
- "version": "0.47.2",
3
+ "version": "0.47.5",
4
4
  "private": false,
5
5
  "description": "Filesystem-first framework for durable backend AI agents that run anywhere.",
6
6
  "keywords": [
@@ -1,9 +0,0 @@
1
- import type { RuntimeActionResult } from "#shared/action-types.js";
2
- /**
3
- * Emits one caller-side `invoke_agent` span per successful delegated
4
- * subagent result that reports token usage, so the parent session's
5
- * observability can attribute a child agent's tokens. Runs in the
6
- * parent's turn step, so the span lands in the caller's trace.
7
- * Best-effort: a tracer failure never blocks the turn.
8
- */
9
- export declare function recordSubagentUsageSpans(results: readonly RuntimeActionResult[]): void;
@@ -1 +0,0 @@
1
- import{createLogger}from"#internal/logging.js";import{trace}from"#compiled/@opentelemetry/api/index.js";const log=createLogger(`execution.subagent-usage-span`);function recordSubagentUsageSpans(e){for(let t of e){if(t.kind!==`subagent-result`||t.isError===!0)continue;let e=t.usage;if(e!==void 0)try{trace.getTracer(`eve`).startSpan(`invoke_agent ${t.subagentName}`,{attributes:{"gen_ai.operation.name":`invoke_agent`,"gen_ai.agent.name":t.subagentName,"gen_ai.usage.input_tokens":e.inputTokens,"gen_ai.usage.output_tokens":e.outputTokens,"gen_ai.usage.cache_read.input_tokens":e.cacheReadTokens,"gen_ai.usage.cache_creation.input_tokens":e.cacheWriteTokens}}).end()}catch(e){log.warn(`failed to emit subagent usage span`,{error:e})}}}export{recordSubagentUsageSpans};
@@ -1 +0,0 @@
1
- import{attemptIdempotencyKey,modelCallIdempotencyKey,toolCallIdempotencyKey}from"#harness/instrumentation/lifecycle.js";import{structuralProviderMetadata}from"#harness/instrumentation/content.js";function createAiSdkHookBridge(i,a,o=directRunInContext,s){let c={capturesContent:a.capturesContent,modelKeys:new Map,runtimeContext:s!==void 0&&Object.keys(s).length>0?Object.freeze({...s}):void 0,scope:i,toolKeys:new Map};return{onStart(e){c.operation=Object.freeze({modelId:e.modelId,operationId:e.operationId,provider:e.provider})},async onStepStart(e){c.stepNumber=e.stepNumber;let t=toStepAttemptStarted(c);t!==void 0&&await a.publish(t)},async onLanguageModelCallStart(e){let n=modelCallIdempotencyKey(c.scope,c.stepNumber??0);c.modelKeys.set(e.callId,n);let r=toModelCallStarted(c,n,e);await a.publish(r)},executeLanguageModelCall({callId:e,execute:t}){let n=c.modelKeys.get(e);return n===void 0?t():o({idempotencyKey:n,scope:i,type:`model.call`},t)},async onLanguageModelCallEnd(e){let t=c.modelKeys.get(e.callId);if(t===void 0)return;c.modelKeys.delete(e.callId);let n=toModelCallCompleted(c,t,e);await a.publish(n)},async onStepEnd(t){if(t.providerMetadata===void 0)return;let n=c.capturesContent?t.providerMetadata:structuralProviderMetadata(t.providerMetadata);await a.publish(Object.freeze({idempotencyKey:attemptIdempotencyKey(c.scope),providerMetadata:n,scope:c.scope,type:`step.attempt.metadata`}))},async onToolExecutionStart(e){let t=toolCallIdempotencyKey(c.scope,e.toolCall.toolCallId,c.stepNumber??0);c.toolKeys.set(e.toolCall.toolCallId,t);let r=toToolCallStarted(c,t,e);await a.publish(r)},executeTool({toolCallId:e,execute:t}){let n=c.toolKeys.get(e);return n===void 0?t():o({idempotencyKey:n,scope:i,type:`tool.call`},t)},async onToolExecutionEnd(e){let t=e.toolCall.toolCallId,n=c.toolKeys.get(t);if(n===void 0)return;c.toolKeys.delete(t);let r=toToolCallCompleted(c,n,e);await a.publish(r)},async onAbort(e){await failOpenOperations(e.reason)},async onError(e){await failOpenOperations(e.error)}};async function failOpenOperations(e){let t=[];for(let n of c.modelKeys.values())t.push(a.publish(Object.freeze({error:e,idempotencyKey:n,scope:i,type:`model.call.failed`})));for(let n of c.toolKeys.values())t.push(a.publish(Object.freeze({error:e,idempotencyKey:n,scope:i,type:`tool.call.failed`})));c.modelKeys.clear(),c.toolKeys.clear(),await Promise.all(t)}}const directRunInContext=(e,t)=>t();function toStepAttemptStarted(t){if(!(t.operation===void 0||t.stepNumber===void 0))return Object.freeze({idempotencyKey:attemptIdempotencyKey(t.scope),operation:t.operation,runtimeContext:t.runtimeContext,scope:t.scope,type:`step.attempt.started`})}function toModelCallStarted(e,t,n){return Object.freeze({idempotencyKey:t,input:e.capturesContent?Object.freeze({instructions:n.instructions,messages:Object.freeze([...n.messages])}):void 0,model:Object.freeze({modelId:n.modelId,provider:n.provider}),runtimeContext:e.runtimeContext,scope:e.scope,type:`model.call.started`})}function toModelCallCompleted(e,t,n){return Object.freeze({content:e.capturesContent?toContentParts(n.content):void 0,finishReason:n.finishReason,idempotencyKey:t,scope:e.scope,type:`model.call.completed`,usage:toUsage(n.usage)})}function toUsage(e){return Object.freeze({inputTokenDetails:Object.freeze({cacheReadTokens:e.inputTokenDetails?.cacheReadTokens,cacheWriteTokens:e.inputTokenDetails?.cacheWriteTokens}),inputTokens:e.inputTokens,outputTokens:e.outputTokens})}function toContentParts(e){let t=[];for(let n of e)switch(n.type){case`text`:case`reasoning`:t.push(Object.freeze({text:n.text,type:n.type}));break;case`tool-call`:t.push(Object.freeze({callId:n.toolCallId,input:n.input,toolName:n.toolName,type:`tool-call`}));break;case`tool-result`:t.push(Object.freeze({callId:n.toolCallId,input:n.input,output:n.output,toolName:n.toolName,type:`tool-result`}));break;case`tool-error`:t.push(Object.freeze({callId:n.toolCallId,error:n.error,input:n.input,toolName:n.toolName,type:`tool-error`}));break;default:break}return Object.freeze(t)}function toToolCallStarted(e,t,n){return Object.freeze({callId:n.toolCall.toolCallId,idempotencyKey:t,input:e.capturesContent?n.toolCall.input:void 0,scope:e.scope,toolName:n.toolCall.toolName,type:`tool.call.started`})}function toToolCallCompleted(e,t,n){return Object.freeze({idempotencyKey:t,output:toToolOutput(n.toolOutput,e.capturesContent),scope:e.scope,type:`tool.call.completed`})}function toToolOutput(e,t){return e.type===`tool-result`?Object.freeze(t?{output:e.output,type:`result`}:{type:`result`}):Object.freeze(t?{error:e.error,type:`error`}:{type:`error`})}export{createAiSdkHookBridge};
@@ -1 +0,0 @@
1
- import{registerTelemetry}from"ai";import{OpenTelemetry}from"#compiled/@ai-sdk/otel/index.js";let registered=!1;function ensureOtelIntegration(){registered||(registered=!0,registerTelemetry(new OpenTelemetry({runtimeContext:!0})))}function getRegisteredTelemetryIntegrations(){return globalThis.AI_SDK_TELEMETRY_INTEGRATIONS??[]}export{ensureOtelIntegration,getRegisteredTelemetryIntegrations};
@@ -1 +0,0 @@
1
- import{normalizeChannelAudience}from"#shared/channel-audience.js";import{ActiveChannelDeliveriesKey,ChannelInstrumentationKey,ParentTraceContextKey,SessionTraceSeedKey}from"#context/keys.js";import{instrumentationHooksForAudience,instrumentationHooksForDecision}from"#harness/instrumentation/content-policy.js";import{channelDeliveryIdempotencyKey}from"#harness/instrumentation/lifecycle.js";async function instrumentChannelDelivery(i){if(!(`delivery`in i)){let n=i.ctx.get(ActiveChannelDeliveriesKey);if(n===void 0||i.hooks===void 0)return;let r=`channel.delivery.${i.outcome}`;for(let t of n)await hooksForContext(i.ctx,i.hooks,normalizeChannelAudience(t.delivery.channelAudience))?.publish({agentName:t.agentName,delivery:t.delivery,error:i.error,errorCode:i.errorCode,idempotencyKey:channelDeliveryIdempotencyKey(t.sessionId,t.delivery.deliveryId),outcome:i.outcome,rootSessionId:t.rootSessionId,sequence:i.includeTurn?t.sequence:void 0,sessionId:t.sessionId,turnId:i.includeTurn?t.turnId:void 0,type:r});i.ctx.delete(ActiveChannelDeliveriesKey);return}if(i.hooks===void 0||i.delivery.deliveryMetadata===void 0)return;let a=[],o=normalizeChannelAudience(i.ctx.get(ChannelInstrumentationKey)?.metadata.audience),s=hooksForContext(i.ctx,i.hooks,o);for(let e of i.delivery.deliveryMetadata){let t=i.delivery.payloads[e.payloadIndex],n={channelAudience:o,channelKind:e.channelKind,channelName:e.channelName,deliveryId:e.deliveryId,requestId:e.requestId,requestTraceContext:e.requestTraceContext},c=!s?.capturesContent||t===void 0?void 0:projectDeliveryInput(t),l={agentName:i.agentName,delivery:n,rootSessionId:i.rootSessionId,sequence:i.sequence,sessionId:i.sessionId,turnId:i.turnId};a.push(l),await s?.publish({agentName:l.agentName,delivery:n,idempotencyKey:channelDeliveryIdempotencyKey(i.sessionId,n.deliveryId),input:c,parentTraceContext:i.ctx.get(ParentTraceContextKey),rootSessionId:i.rootSessionId,sessionId:i.sessionId,traceSeed:i.ctx.get(SessionTraceSeedKey),type:`channel.delivery.started`})}a.length>0&&i.ctx.set(ActiveChannelDeliveriesKey,a)}function hooksForContext(e,t,n){let r=e.get(SessionTraceSeedKey)?.decision;return r===void 0?instrumentationHooksForAudience(t,n):instrumentationHooksForDecision(t,r,n)}function projectDeliveryInput(e){let t={};return e.context!==void 0&&(t.context=e.context),e.message!==void 0&&(t.message=e.message),e.outputSchema!==void 0&&(t.outputSchema=e.outputSchema),e.inputResponses!==void 0&&(t.inputResponses=e.inputResponses.map(e=>{let t={};return e.optionId!==void 0&&(t.optionId=e.optionId),e.text!==void 0&&(t.text=e.text),t})),t}function channelDeliveryErrorCode(e){if(typeof e==`object`&&e&&`code`in e){let t=e.code;if(typeof t==`string`&&t.length>0)return t}return`CHANNEL_DELIVERY_FAILED`}export{channelDeliveryErrorCode,instrumentChannelDelivery};
@@ -1 +0,0 @@
1
- import{registerInstrumentationRuntime}from"#harness/instrumentation/runtime.js";import{createInstrumentationHooks}from"#harness/instrumentation/lifecycle.js";import{createInstrumentationSetupContext}from"#harness/instrumentation/setup-context.js";const INSTRUMENTATION_CONFIG_GLOBAL_KEY=Symbol.for(`eve.harness-instrumentation-config`),globalContainer=globalThis;async function registerInstrumentationConfig(n,r){globalContainer[INSTRUMENTATION_CONFIG_GLOBAL_KEY]=n,registerInstrumentationRuntime({forceFlush:async()=>void 0,hooks:createInstrumentationHooks([]),otelSettings:{functionId:n.functionId,recordInputs:n.recordInputs===!0,recordOutputs:n.recordOutputs===!0,traceChannelRequests:n.traceChannelRequests===!0},runInContext:(e,t)=>t(),shutdown:async()=>void 0}),await n.setup?.(createInstrumentationSetupContext(r.agentName))}function getInstrumentationConfig(){return globalContainer[INSTRUMENTATION_CONFIG_GLOBAL_KEY]}export{getInstrumentationConfig,registerInstrumentationConfig};
@@ -1,7 +0,0 @@
1
- import type { InstrumentationHooks } from "#harness/instrumentation/lifecycle.js";
2
- import type { ChannelAudience } from "#shared/channel-audience.js";
3
- import type { InstrumentationDecision } from "#shared/instrumentation-decision.js";
4
- export { shouldCaptureInstrumentationContent } from "#shared/instrumentation-content.js";
5
- export declare function instrumentationHooksForDecision(hooks: InstrumentationHooks | undefined, decision: InstrumentationDecision, audience: ChannelAudience): InstrumentationHooks | undefined;
6
- /** Applies the audience ceiling before any content-capable provider sees an event. */
7
- export declare function instrumentationHooksForAudience(hooks: InstrumentationHooks | undefined, audience: ChannelAudience): InstrumentationHooks | undefined;
@@ -1 +0,0 @@
1
- import{withInstrumentationDecision,withoutInstrumentationContent}from"#harness/instrumentation/content.js";import{applyAudienceCeiling,shouldCaptureInstrumentationContent,shouldCaptureInstrumentationContent as shouldCaptureInstrumentationContent$1}from"#shared/instrumentation-content.js";function instrumentationHooksForDecision(t,r,i){if(r.action===`drop`)return instrumentationHooksForAudience(t,i);let a=applyAudienceCeiling(r,i);return a.action===`drop`||t===void 0||!t.capturesContent||a.recordInputs&&a.recordOutputs?t:{capturesContent:a.recordInputs||a.recordOutputs,publish:n=>t.publish(withInstrumentationDecision(n,a))}}function instrumentationHooksForAudience(e,n){return e===void 0||!e.capturesContent||shouldCaptureInstrumentationContent$1(n)?e:{capturesContent:!1,publish:n=>e.publish(withoutInstrumentationContent(n))}}export{instrumentationHooksForAudience,instrumentationHooksForDecision,shouldCaptureInstrumentationContent};
@@ -1 +0,0 @@
1
- import{createLogger,formatError}from"#internal/logging.js";import{abandonInstrumentationState,instrumentationStateSlot,isInstrumentationStateAbandoned,releaseAllInstrumentationAttemptState,releaseAllInstrumentationState,releaseAllInstrumentationTurnState,takeInstrumentationActionScopes}from"#harness/instrumentation/state.js";import{withoutInstrumentationContent}from"#harness/instrumentation/content.js";const log=createLogger(`harness.instrumentation-dispatch`);function createInstrumentationDispatcher(e,t){let n=t.handlerTimeoutMs??5e3,r=normalizeDispatchGroups(e),i=new WeakMap,a=[...r.serialBefore,...r.parallel,...r.serialAfter].some(e=>e.capture===`content`),publish=async e=>{let t=snapshotInstrumentationEvent(e,i),a=t.type===`session.completed`||t.type===`session.failed`,o=t.type===`turn.cancelled`||t.type===`turn.failed`;if(a||o){let e=takeInstrumentationActionScopes(t.sessionId,o?t.turnId:void 0),n=terminalActionFailure(t);for(let t of e)await publish({...n,idempotencyKey:t.idempotencyKey,scope:t.scope,type:`action.failed`})}let s,visibleEvent=e=>e.capture===`content`?t:(s??=withoutInstrumentationContent(t),s);try{try{for(let e of r.serialBefore)await dispatchToProvider(e,t,n,()=>visibleEvent(e));if(r.parallel.length===1){let e=r.parallel[0];await dispatchToProvider(e,t,n,()=>visibleEvent(e))}else if(r.parallel.length>1){let e=(await Promise.allSettled(r.parallel.map(e=>dispatchToProvider(e,t,n,()=>visibleEvent(e))))).find(e=>e.status===`rejected`);if(e!==void 0)throw e.reason}}finally{for(let e of r.serialAfter)await dispatchToProvider(e,t,n,()=>visibleEvent(e))}}finally{releaseTerminalState(t)}};return{capturesContent:a,publish}}function snapshotInstrumentationEvent(e,t){return snapshotPlainValue(e,t)}function snapshotPlainValue(e,t){if(Array.isArray(e)){let n=t.get(e);if(n!==void 0)return n;let r=[];t.set(e,r);for(let n of e)r.push(snapshotPlainValue(n,t));return Object.freeze(r)}if(typeof e!=`object`||!e)return e;let n;try{n=Object.getPrototypeOf(e)}catch{return e}if(n!==Object.prototype&&n!==null)return e;let r=t.get(e);if(r!==void 0)return r;let i={};t.set(e,i);for(let[n,r]of Object.entries(e))i[n]=snapshotPlainValue(r,t);return Object.freeze(i)}function normalizeDispatchGroups(e){if(!Array.isArray(e)){let t=e;return{parallel:t.parallel??[],serialAfter:t.serialAfter??[],serialBefore:t.serialBefore??[]}}return{parallel:[],serialAfter:[],serialBefore:e.map((e,t)=>({...e,name:e.name??`provider-${String(t)}`}))}}async function dispatchToProvider(e,a,o,s){let c=a.type.endsWith(`.started`)||a.type===`input.requested`,l=stateOwner(a),u=e.name,d=e.stateNamespace??u;if(isInstrumentationStateAbandoned(d,a.idempotencyKey))return;let f=e.events?.[a.type];if(f===void 0)return;let p=instrumentationStateSlot(d,a.idempotencyKey,l);try{await withTimeout(()=>f(s(),{state:p}),o,()=>{p.revoke(),c&&abandonInstrumentationState(d,a.idempotencyKey,l)})||log.warn(`instrumentation provider timed out`,{boundary:a.type,provider:u,timeoutMs:o})}catch(e){log.warn(`instrumentation provider failed`,{boundary:a.type,error:formatError(e),provider:u})}finally{p.revoke()}}async function withTimeout(e,t,n){let r;try{return await Promise.race([Promise.resolve(e()).then(()=>!0),new Promise(e=>{r=setTimeout(()=>{n(),e(!1)},t)})])}finally{clearTimeout(r)}}function stateOwner(e){return e.type===`channel.delivery.started`||e.type===`channel.delivery.cancelled`||e.type===`channel.delivery.completed`||e.type===`channel.delivery.failed`?{sessionId:e.sessionId,turnId:e.turnId}:`scope`in e?e.type.startsWith(`action.`)||e.type.startsWith(`input.`)?{sessionId:e.scope.sessionId,turnId:e.scope.turnId}:e.type.startsWith(`model.call.`)||e.type.startsWith(`tool.call.`)||e.type.startsWith(`step.attempt.`)?{attemptId:e.scope.attemptId}:{}:{}}function releaseTerminalState(e){isTerminal(e.type)&&releaseAllInstrumentationState(e.idempotencyKey),(e.type===`step.attempt.completed`||e.type===`step.attempt.failed`)&&releaseAllInstrumentationAttemptState(e.scope.attemptId),(e.type===`session.completed`||e.type===`session.failed`)&&releaseAllInstrumentationTurnState(e.sessionId),(e.type===`turn.cancelled`||e.type===`turn.failed`)&&releaseAllInstrumentationTurnState(e.sessionId,e.turnId)}function terminalActionFailure(e){return e.type===`session.failed`||e.type===`turn.failed`?{error:e.error,outcome:`failed`}:e.type===`turn.cancelled`?{error:Error(`The action was cancelled with its turn.`),errorCode:`ACTION_CANCELLED`,outcome:`cancelled`}:{error:Error(`The session completed before the action settled.`),errorCode:`ACTION_ABANDONED`,outcome:`abandoned`}}function isTerminal(e){return e.endsWith(`.completed`)||e.endsWith(`.failed`)||e.endsWith(`.cancelled`)||e===`input.resolved`}export{createInstrumentationDispatcher};
@@ -1 +0,0 @@
1
- import{createInstrumentationDispatcher}from"#harness/instrumentation/dispatch.js";function sessionIdempotencyKey(e){return`session:${e}`}function turnIdempotencyKey(e,t){return`turn:${e}:${t}`}function attemptIdempotencyKey(e){return`step:${e.attemptId}`}function modelCallIdempotencyKey(e,t){return`model:${e.attemptId}:${String(t)}`}function toolCallIdempotencyKey(e,t,n){return`tool:${e.attemptId}:${t}:${String(n)}`}function inputIdempotencyKey(e,t,n){return`input:${e}:${t}:${n}`}function channelDeliveryIdempotencyKey(e,t){return`channel-delivery:${e}:${t}`}function actionIdempotencyKey(e,t,n){return`action:${e}:${t}:${n}`}function createInstrumentationHooks(t,n={}){return createInstrumentationDispatcher(t,n)}export{actionIdempotencyKey,attemptIdempotencyKey,channelDeliveryIdempotencyKey,createInstrumentationHooks,inputIdempotencyKey,modelCallIdempotencyKey,sessionIdempotencyKey,toolCallIdempotencyKey,turnIdempotencyKey};
@@ -1 +0,0 @@
1
- import{contextStorage}from"#context/container.js";import{instrumentChannelDelivery}from"#harness/channel-delivery-instrumentation.js";import{rememberInstrumentationActionScope,rememberInstrumentationInputScope,takeInstrumentationActionScopeForCall,takeInstrumentationInputScope}from"#harness/instrumentation/state.js";import{RuntimeActionSettlementTimesKey}from"#harness/runtime-action-settlement-state.js";import{actionIdempotencyKey,inputIdempotencyKey,sessionIdempotencyKey,turnIdempotencyKey}from"#harness/instrumentation/lifecycle.js";function createInstrumentationHandleEvent(n){if(n.hooks===void 0)return n.handleEvent;if(n.handleEvent===void 0)return;let r=n.handleEvent,i=n.hooks,a=new Set,o=new Set,s=n.turnId;return async(c,l)=>{await r(c,l);let u=toLifecycleEvent(c,n,s);if(c.type===`turn.started`&&(s=c.data.turnId),c.type===`turn.cancelled`||c.type===`turn.completed`||c.type===`turn.failed`||c.type===`session.completed`||c.type===`session.failed`){let n=contextStorage.getStore();n!==void 0&&await instrumentChannelDelivery({ctx:n,error:c.type===`turn.failed`||c.type===`session.failed`?Error(c.data.message):void 0,errorCode:c.type===`turn.failed`||c.type===`session.failed`?c.data.code:void 0,hooks:i,includeTurn:c.type===`turn.cancelled`||c.type===`turn.completed`||c.type===`turn.failed`,outcome:c.type===`turn.failed`||c.type===`session.failed`?`failed`:c.type===`turn.cancelled`?`cancelled`:`completed`})}u!==void 0&&await i.publish(u),c.type===`actions.requested`?await publishActionStarts(c,n,i,a):c.type===`action.result`?await publishActionTerminal(c,n,i):c.type===`input.requested`&&await publishInputStarts(c,n,i,o)}}async function publishInputStarts(e,t,n,i){let a=t.getAttemptScope?.();if(a!==void 0)for(let o of e.data.requests){let s=inputIdempotencyKey(t.sessionId,e.data.turnId,o.requestId);i.has(s)||(i.add(s),rememberInstrumentationInputScope(s,a),await n.publish(Object.freeze({action:Object.freeze({callId:o.action.callId,name:o.action.toolName}),idempotencyKey:s,kind:o.kind,request:n.capturesContent?Object.freeze({allowFreeform:o.allowFreeform,display:o.display,options:o.options,prompt:o.prompt}):void 0,requestId:o.requestId,scope:a,type:`input.requested`})))}}async function publishInputResolutions(e){for(let t of e.batch.inputs){let n=inputIdempotencyKey(e.sessionId,e.batch.event.turnId,t.request.requestId),r=takeInstrumentationInputScope(n);r!==void 0&&await e.hooks.publish(Object.freeze({idempotencyKey:n,kind:t.request.kind,outcome:t.outcome,requestId:t.request.requestId,response:!e.hooks.capturesContent||t.response===void 0?void 0:Object.freeze({optionId:t.response.optionId,text:t.response.text}),scope:r,type:`input.resolved`}))}}async function publishActionStarts(e,t,r,i){let a=t.getAttemptScope?.();if(a!==void 0)for(let o of e.data.actions){let c=actionIdempotencyKey(t.sessionId,e.data.turnId,o.callId);i.has(c)||(i.add(c),rememberInstrumentationActionScope(c,a),await r.publish(Object.freeze({callId:o.callId,idempotencyKey:c,input:r.capturesContent?o.input:void 0,kind:o.kind,name:actionName(o),scope:a,type:`action.started`})))}}async function publishActionTerminal(t,n,r){let a=takeInstrumentationActionScopeForCall(n.sessionId,t.data.result.callId);if(a===void 0)return;let{idempotencyKey:s,scope:c}=a;if(t.data.status===`completed`){await r.publish(Object.freeze({acceptedAtMs:contextStorage.getStore()?.get(RuntimeActionSettlementTimesKey)?.[t.data.result.callId],idempotencyKey:s,outcome:`completed`,output:Object.freeze(r.capturesContent?{output:t.data.result.output,type:`result`}:{type:`result`}),scope:c,type:`action.completed`,usage:actionUsage(t.data.result)}));return}let l=t.data.error===void 0?t.data.result.output:Object.assign(Error(t.data.error.message),{code:t.data.error.code});await r.publish(Object.freeze({acceptedAtMs:contextStorage.getStore()?.get(RuntimeActionSettlementTimesKey)?.[t.data.result.callId],error:l,errorCode:t.data.error?.code,idempotencyKey:s,outcome:t.data.status,scope:c,type:`action.failed`}))}function actionUsage(e){if(!(e.kind!==`subagent-result`||e.origin!==`child`||e.usage===void 0))return{inputTokenDetails:{cacheReadTokens:e.usage.cacheReadTokens,cacheWriteTokens:e.usage.cacheWriteTokens},inputTokens:e.usage.inputTokens,outputTokens:e.usage.outputTokens}}function actionName(e){return e.kind===`tool-call`?e.toolName:e.kind===`load-skill`?`load_skill`:e.name}function toLifecycleEvent(e,t,n){switch(e.type){case`session.started`:return{agentName:t.agentName,channelAudience:t.channelAudience,channelKind:t.channelKind,idempotencyKey:sessionIdempotencyKey(t.sessionId),parentTraceContext:t.parentTraceContext,rootSessionId:t.rootSessionId??t.sessionId,sessionId:t.sessionId,type:`session.started`};case`session.completed`:case`session.waiting`:return{idempotencyKey:sessionIdempotencyKey(t.sessionId),sessionId:t.sessionId,turnId:n,type:e.type};case`session.failed`:return{error:Error(e.data.message),idempotencyKey:sessionIdempotencyKey(t.sessionId),sessionId:t.sessionId,turnId:n,type:`session.failed`};case`turn.started`:return{idempotencyKey:turnIdempotencyKey(t.sessionId,e.data.turnId),parentLineage:t.parentLineage,parentTraceContext:t.parentTraceContext,rootSessionId:t.rootSessionId??t.sessionId,sequence:e.data.sequence,sessionId:t.sessionId,turnId:e.data.turnId,type:`turn.started`};case`turn.completed`:case`turn.cancelled`:return{idempotencyKey:turnIdempotencyKey(t.sessionId,e.data.turnId),sessionId:t.sessionId,turnId:e.data.turnId,type:e.type};case`turn.failed`:return{error:Error(e.data.message),idempotencyKey:turnIdempotencyKey(t.sessionId,e.data.turnId),sessionId:t.sessionId,turnId:e.data.turnId,type:`turn.failed`};default:return}}export{createInstrumentationHandleEvent,publishInputResolutions};
@@ -1 +0,0 @@
1
- import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{getInstrumentationRuntime}from"#harness/instrumentation/runtime.js";import{DEVELOPMENT_WORKER_APP_ROOT_ENV}from"#internal/workflow/development-world-protocol.js";import{createInstrumentationSetupContext}from"#harness/instrumentation/setup-context.js";import{agentRuns,localTraces}from"#public/instrumentation/otel.js";import{installInstrumentationRuntime}from"#tracing/install-instrumentation-runtime.js";import{collectOtelPipeline}from"#tracing/otel-declaration.js";import{isInstrumentationDisabled,isInstrumentationProvider}from"#public/instrumentation/provider.js";const INSTRUMENTATION_PROVIDERS_GLOBAL_KEY=Symbol.for(`eve.harness-instrumentation-providers`),globalContainer=globalThis;function providerRegistry(){let e=globalContainer[INSTRUMENTATION_PROVIDERS_GLOBAL_KEY];if(e!==void 0)return e;let t=new Map;return globalContainer[INSTRUMENTATION_PROVIDERS_GLOBAL_KEY]=t,t}function seedInstrumentationProviders(){let e=providerRegistry();process.env.VERCEL_ENV===`production`&&e.set(`agent-runs`,agentRuns()),process.env[DEVELOPMENT_WORKER_APP_ROOT_ENV]!==void 0&&e.set(`local`,localTraces())}async function registerInstrumentationProvider(e){if(isInstrumentationDisabled(e.value)){providerRegistry().delete(e.slot);return}if(!isInstrumentationProvider(e.value))throw Error(`The default export of "instrumentation/${e.slot}" is not an instrumentation provider. Return the result of \`defineInstrumentation\` or \`disableInstrumentation\` from it.`);providerRegistry().set(e.slot,e.value),await e.value.setup?.(createInstrumentationSetupContext(e.agentName))}function getInstrumentationProviders(){return[...providerRegistry()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({provider:t,slot:e}))}function finalizeInstrumentationProviders(t){let n=getInstrumentationProviders(),r=n.map(toProviderDefinition),i=collectOtelPipeline(n.map(e=>e.provider));return installInstrumentationRuntime({collected:i,frameworkVersion:resolveInstalledPackageInfo().version,providers:r,runtimeContextResolvers:i.runtimeContextResolvers,serviceName:t.serviceName})}async function shutdownInstrumentationProviders(){await getInstrumentationRuntime()?.shutdown()}function toProviderDefinition(e){return{capture:e.provider.capture,events:e.provider.events,flush:e.provider.flush,name:e.slot,shutdown:e.provider.shutdown,stateNamespace:`authored:${e.slot}`}}export{finalizeInstrumentationProviders,getInstrumentationProviders,registerInstrumentationProvider,seedInstrumentationProviders,shutdownInstrumentationProviders};
@@ -1 +0,0 @@
1
- import{createLogger,formatError}from"#internal/logging.js";import{normalizeInstrumentationChannelKind,resolveInstrumentationProjection}from"#internal/instrumentation.js";import{normalizeChannelAudience}from"#shared/channel-audience.js";import{contextStorage}from"#context/container.js";import{AuthKey,ChannelInstrumentationKey,InitiatorAuthKey,ParentSessionKey}from"#context/keys.js";import{parseJsonObject,parseJsonValue}from"#shared/json.js";import{shouldCaptureInstrumentationContent}from"#harness/instrumentation/content-policy.js";const log=createLogger(`harness.instrumentation-runtime-context`);function buildTelemetryRuntimeContext(e){let t=e.authored!==void 0,r=e.providerResolvers!==void 0&&e.providerResolvers.length>0;if(!t&&!r)return;let i=resolveStepStartedRuntimeContext(e),o=resolveProviderRuntimeContext(e),c=contextStorage.getStore()?.get(ChannelInstrumentationKey);return{...i,...o,"eve.channel.kind":normalizeInstrumentationChannelKind(c?.kind),"eve.environment":e.environment,"eve.session.id":e.session.sessionId,"eve.step.index":String(e.emissionState.stepIndex),"eve.turn.id":e.emissionState.turnId,"eve.turn.sequence":String(e.emissionState.sequence),"eve.version":e.eveVersion}}function buildInstrumentationStepStartedInput(e){let t=contextStorage.getStore(),r=t?.get(ChannelInstrumentationKey),o=shouldCaptureInstrumentationContent(normalizeChannelAudience(r?.metadata.audience));return{channel:{kind:normalizeInstrumentationChannelKind(r?.kind),metadata:snapshotForInstrumentation(r?.metadata,`channel.metadata`)??{}},modelInput:o?snapshotForInstrumentation(e.modelInput,`modelInput`)??{instructions:void 0,messages:[]}:{instructions:void 0,messages:[]},session:{auth:projectSessionAuth(t),id:e.session.sessionId,parent:snapshotForInstrumentation(t?.get(ParentSessionKey),`session.parent`)},step:{index:e.emissionState.stepIndex},turn:{id:e.emissionState.turnId,sequence:e.emissionState.sequence}}}function filterAuthoredRuntimeContext(e,t){let n={};for(let[r,i]of Object.entries(e)){if(r.startsWith(`eve.`)){log.warn(`ignoring reserved instrumentation runtime context key`,{key:r,source:t});continue}n[r]=i}return Object.keys(n).length>0?n:void 0}function resolveStepStartedRuntimeContext(e){let n=e.authored?.events?.[`step.started`];if(n===void 0)return;let i=`events["step.started"]`,a=resolveInstrumentationProjection({invoke:()=>{let t=buildInstrumentationStepStartedInput(e);return n(t)},log,source:i});if(a===void 0)return;if(!(`runtimeContext`in a)){log.warn(`ignoring instrumentation event result because runtimeContext is missing`,{source:i});return}let o;try{o=parseJsonObject(a.runtimeContext)}catch(e){log.warn(`ignoring instrumentation event result because runtimeContext is invalid`,{error:formatError(e),source:i});return}return filterAuthoredRuntimeContext(o,i)}function resolveProviderRuntimeContext(e){let t=e.providerResolvers;if(t===void 0||t.length===0)return;let n={},i=!1;for(let a of t){let t=`provider.runtimeContext`,o=resolveInstrumentationProjection({invoke:()=>{let t=buildInstrumentationStepStartedInput(e);return a(t)},log,source:t});if(o===void 0)continue;let s=filterAuthoredRuntimeContext(o,t);s!==void 0&&(Object.assign(n,s),i=!0)}return i?n:void 0}function projectSessionAuth(e){let t=e?.get(AuthKey)??null,n=e?.get(InitiatorAuthKey)??t;return{current:snapshotForInstrumentation(t,`session.auth.current`)??null,initiator:snapshotForInstrumentation(n,`session.auth.initiator`)??null}}function snapshotForInstrumentation(e,n){if(e!==void 0)try{return parseJsonValue(e)}catch(e){log.warn(`dropping non-serializable instrumentation snapshot`,{error:formatError(e),source:n});return}}export{buildTelemetryRuntimeContext};
@@ -1,21 +0,0 @@
1
- import type { InstrumentationContextRunner, InstrumentationHooks, InstrumentationSessionStartedEvent, InstrumentationTraceContext, InstrumentationTurnStartedEvent } from "#harness/instrumentation/lifecycle.js";
2
- import type { AgentSpanIdGenerator } from "#tracing/agent-span-id-generator.js";
3
- import type { OtelHarnessSettings, RuntimeContextResolver } from "#tracing/otel-declaration.js";
4
- /** Process-wide runtime consumed by every harness execution surface. */
5
- export interface InstrumentationRuntime {
6
- readonly forceFlush: () => Promise<void>;
7
- readonly hooks: InstrumentationHooks;
8
- readonly idGenerator?: AgentSpanIdGenerator;
9
- readonly prepareSessionTrace?: (event: InstrumentationSessionStartedEvent) => Promise<InstrumentationTraceContext>;
10
- readonly prepareTurnTrace?: (event: InstrumentationTurnStartedEvent) => Promise<InstrumentationTraceContext>;
11
- otelSettings: OtelHarnessSettings | undefined;
12
- readonly runtimeContextResolvers?: readonly RuntimeContextResolver[];
13
- readonly runInContext: InstrumentationContextRunner;
14
- readonly shutdown: () => Promise<void>;
15
- }
16
- /** Instrumentation capabilities consumed inside one harness execution. */
17
- export type HarnessInstrumentation = Pick<InstrumentationRuntime, "hooks" | "prepareSessionTrace" | "prepareTurnTrace" | "runInContext">;
18
- /** Registers the process instrumentation runtime before agent execution begins. */
19
- export declare function registerInstrumentationRuntime(runtime: InstrumentationRuntime): InstrumentationRuntime;
20
- /** Returns the process instrumentation runtime, when one was installed. */
21
- export declare function getInstrumentationRuntime(): InstrumentationRuntime | undefined;
@@ -1 +0,0 @@
1
- const INSTRUMENTATION_RUNTIME_KEY=Symbol.for(`eve.instrumentation-runtime`),globalRuntime=globalThis;function registerInstrumentationRuntime(e){let t=globalRuntime[INSTRUMENTATION_RUNTIME_KEY];return t===void 0?(globalRuntime[INSTRUMENTATION_RUNTIME_KEY]=e,e):(t.otelSettings=e.otelSettings,t)}function getInstrumentationRuntime(){return globalRuntime[INSTRUMENTATION_RUNTIME_KEY]}export{getInstrumentationRuntime,registerInstrumentationRuntime};
@@ -1,21 +0,0 @@
1
- import type { RuntimeTraceContext } from "#protocol/message.js";
2
- import type { InstrumentationParentLineage, InstrumentationTraceContext } from "#harness/instrumentation/lifecycle.js";
3
- import type { HarnessInstrumentation } from "#harness/instrumentation/runtime.js";
4
- import type { ChannelAudience } from "#shared/channel-audience.js";
5
- import type { SessionTraceSeed } from "#context/keys.js";
6
- /** Prepares native session/turn tracing before their durable stream events. */
7
- export declare function prepareTurnTraceContext(input: {
8
- readonly agentName?: string;
9
- readonly channelAudience?: ChannelAudience;
10
- readonly channelType?: string;
11
- readonly instrumentation?: HarnessInstrumentation;
12
- readonly parentLineage?: InstrumentationParentLineage;
13
- readonly parentTraceContext?: InstrumentationTraceContext;
14
- readonly rootSessionId: string;
15
- readonly sequence: number;
16
- readonly sessionId: string;
17
- readonly sessionStarted: boolean;
18
- readonly traceContext?: RuntimeTraceContext;
19
- readonly traceSeed?: SessionTraceSeed;
20
- readonly turnId: string;
21
- }): Promise<RuntimeTraceContext | undefined>;
@@ -1 +0,0 @@
1
- import{createLogger,formatError}from"#internal/logging.js";import{sessionIdempotencyKey,turnIdempotencyKey}from"#harness/instrumentation/lifecycle.js";const log=createLogger(`harness.prepare-trace-context`);async function prepareTurnTraceContext(e){let t;if(!e.sessionStarted&&e.instrumentation?.prepareSessionTrace!==void 0)try{t=await e.instrumentation.prepareSessionTrace({agentName:e.agentName,channelAudience:e.channelAudience,channelType:e.channelType,idempotencyKey:sessionIdempotencyKey(e.sessionId),parentTraceContext:e.parentTraceContext,rootSessionId:e.rootSessionId,sessionId:e.sessionId,traceSeed:e.traceSeed,type:`session.started`})}catch(e){warn(`session.started`,e)}if(e.instrumentation?.prepareTurnTrace!==void 0)try{t=await e.instrumentation.prepareTurnTrace({idempotencyKey:turnIdempotencyKey(e.sessionId,e.turnId),parentLineage:e.parentLineage,parentTraceContext:e.parentTraceContext,rootSessionId:e.rootSessionId,sequence:e.sequence,sessionId:e.sessionId,turnId:e.turnId,type:`turn.started`})}catch(e){warn(`turn.started`,e)}return e.traceContext??t}function warn(e,n){log.warn(`instrumentation trace preparation failed`,{boundary:e,error:formatError(n)})}export{prepareTurnTraceContext};