eve 0.75.1 → 0.76.2

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 (720) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/src/_virtual/_rolldown/runtime.js +1 -1
  3. package/dist/src/acp/adapter.js +1 -1
  4. package/dist/src/channel/channel-address.d.ts +3 -1
  5. package/dist/src/channel/channel-address.js +1 -1
  6. package/dist/src/channel/session-stranded-error.d.ts +25 -0
  7. package/dist/src/channel/session-stranded-error.js +1 -0
  8. package/dist/src/channel/session.d.ts +13 -6
  9. package/dist/src/channel/task-card.js +1 -1
  10. package/dist/src/channel/tool-eligibility.d.ts +1 -2
  11. package/dist/src/channel/types.d.ts +29 -1
  12. package/dist/src/chunks/{use-eve-agent-DK_T88EP.js → use-eve-agent-BtKWTEpm.js} +99 -24
  13. package/dist/src/chunks/{use-eve-agent-B2Kne9z6.js → use-eve-agent-jI6EsYAu.js} +99 -24
  14. package/dist/src/cli/commands/registry-project.d.ts +10 -3
  15. package/dist/src/cli/commands/registry-project.js +2 -2
  16. package/dist/src/cli/commands/registry.js +1 -1
  17. package/dist/src/cli/dev/environment.d.ts +0 -6
  18. package/dist/src/cli/dev/environment.js +1 -1
  19. package/dist/src/cli/dev/tui/conversation-view.js +1 -1
  20. package/dist/src/cli/dev/tui/runner.js +3 -3
  21. package/dist/src/cli/dev/tui/stranded-session.d.ts +9 -0
  22. package/dist/src/cli/dev/tui/stranded-session.js +1 -0
  23. package/dist/src/cli/dev/tui/tool-presentation.js +1 -1
  24. package/dist/src/cli/dev/tui/transcript.js +1 -1
  25. package/dist/src/client/client-error.d.ts +16 -0
  26. package/dist/src/client/client-error.js +1 -1
  27. package/dist/src/client/client.js +1 -1
  28. package/dist/src/client/index.d.ts +3 -2
  29. package/dist/src/client/index.js +1 -1
  30. package/dist/src/client/message-action-parts.d.ts +3 -0
  31. package/dist/src/client/message-action-parts.js +1 -1
  32. package/dist/src/client/message-reducer-types.d.ts +6 -1
  33. package/dist/src/client/message-reducer.js +1 -1
  34. package/dist/src/client/open-stream.d.ts +5 -3
  35. package/dist/src/client/open-stream.js +1 -1
  36. package/dist/src/client/session-controls.js +1 -1
  37. package/dist/src/client/session.js +1 -1
  38. package/dist/src/client/transcript-reducer.d.ts +46 -0
  39. package/dist/src/client/transcript-reducer.js +2 -0
  40. package/dist/src/compiled/.vendor-stamp.json +3 -2
  41. package/dist/src/compiled/@eve/catalog/index.js +1 -1
  42. package/dist/src/compiled/@vercel/queue/index.d.ts +1066 -0
  43. package/dist/src/compiled/@vercel/queue/index.js +47 -0
  44. package/dist/src/compiler/connection-ownership.d.ts +6 -0
  45. package/dist/src/compiler/connection-ownership.js +1 -0
  46. package/dist/src/compiler/default-tool-policy.d.ts +0 -3
  47. package/dist/src/compiler/default-tool-policy.js +1 -1
  48. package/dist/src/compiler/extension-compatibility.d.ts +23 -22
  49. package/dist/src/compiler/extension-compatibility.js +1 -1
  50. package/dist/src/compiler/manifest.d.ts +9 -6
  51. package/dist/src/compiler/manifest.js +1 -1
  52. package/dist/src/compiler/normalize-agent-config.js +1 -1
  53. package/dist/src/compiler/normalize-connection.js +1 -1
  54. package/dist/src/compiler/normalize-manifest.js +1 -1
  55. package/dist/src/compiler/normalize-skill.d.ts +5 -0
  56. package/dist/src/compiler/normalize-skill.js +1 -1
  57. package/dist/src/compiler/normalize-subagent.d.ts +2 -1
  58. package/dist/src/compiler/normalize-subagent.js +1 -1
  59. package/dist/src/compiler/normalize-tool.js +1 -1
  60. package/dist/src/compiler/remote-agent-node.d.ts +2 -1
  61. package/dist/src/compiler/remote-agent-node.js +1 -1
  62. package/dist/src/connections/ownership.d.ts +18 -0
  63. package/dist/src/connections/ownership.js +1 -0
  64. package/dist/src/context/accessors.d.ts +1 -1
  65. package/dist/src/context/build-callback-context.js +1 -1
  66. package/dist/src/context/build-dynamic-tools.d.ts +3 -9
  67. package/dist/src/context/build-dynamic-tools.js +1 -1
  68. package/dist/src/context/dynamic-connection-lifecycle.js +1 -1
  69. package/dist/src/context/dynamic-resolve-context.js +1 -1
  70. package/dist/src/context/dynamic-skill-lifecycle.d.ts +2 -11
  71. package/dist/src/context/dynamic-skill-lifecycle.js +1 -1
  72. package/dist/src/context/dynamic-subagent-lifecycle.js +1 -1
  73. package/dist/src/context/dynamic-tool-lifecycle.js +1 -1
  74. package/dist/src/context/dynamic-tool-metadata.d.ts +1 -0
  75. package/dist/src/context/keys.d.ts +10 -4
  76. package/dist/src/context/keys.js +1 -1
  77. package/dist/src/context/memory-tools.js +1 -1
  78. package/dist/src/context/providers/session.d.ts +1 -0
  79. package/dist/src/context/providers/session.js +1 -1
  80. package/dist/src/context/schedule-collection-tools.js +1 -1
  81. package/dist/src/context/session-context.d.ts +8 -2
  82. package/dist/src/discover/grammar.d.ts +11 -0
  83. package/dist/src/discover/grammar.js +1 -1
  84. package/dist/src/discover/manifest.d.ts +1 -0
  85. package/dist/src/discover/manifest.js +1 -1
  86. package/dist/src/discover/skills.d.ts +1 -0
  87. package/dist/src/discover/skills.js +1 -1
  88. package/dist/src/dynamic/definition.d.ts +14 -6
  89. package/dist/src/evals/assertions/collector.d.ts +4 -0
  90. package/dist/src/evals/assertions/collector.js +1 -1
  91. package/dist/src/evals/assertions/run.d.ts +2 -3
  92. package/dist/src/evals/assertions/run.js +2 -2
  93. package/dist/src/evals/assertions/scoped.js +1 -1
  94. package/dist/src/evals/index.d.ts +1 -1
  95. package/dist/src/evals/match.d.ts +9 -6
  96. package/dist/src/evals/reported-tool-name.d.ts +9 -0
  97. package/dist/src/evals/reported-tool-name.js +1 -0
  98. package/dist/src/evals/runner/derive-run-facts.d.ts +3 -3
  99. package/dist/src/evals/runner/derive-run-facts.js +1 -1
  100. package/dist/src/evals/runner/execute-task.js +1 -1
  101. package/dist/src/evals/runner/reporters/braintrust.js +1 -1
  102. package/dist/src/evals/runner/reporters/datadog-runtime-trace-links.d.ts +11 -0
  103. package/dist/src/evals/runner/reporters/datadog-runtime-trace-links.js +1 -0
  104. package/dist/src/evals/runner/reporters/datadog.js +2 -2
  105. package/dist/src/evals/session.js +2 -2
  106. package/dist/src/evals/target.d.ts +7 -0
  107. package/dist/src/evals/target.js +1 -1
  108. package/dist/src/evals/types.d.ts +19 -2
  109. package/dist/src/eve-channel/index.js +1 -1
  110. package/dist/src/eve-channel/request.js +2 -2
  111. package/dist/src/eve-channel/support.d.ts +2 -0
  112. package/dist/src/eve-channel/support.js +1 -1
  113. package/dist/src/execution/agent-sessions/remote.js +1 -1
  114. package/dist/src/execution/agent-sessions/steps.js +1 -1
  115. package/dist/src/execution/catalog/connection-auth.d.ts +41 -0
  116. package/dist/src/execution/catalog/connection-auth.js +1 -0
  117. package/dist/src/execution/catalog/connection-entry.d.ts +16 -0
  118. package/dist/src/execution/catalog/connection-entry.js +1 -0
  119. package/dist/src/execution/catalog/listing.d.ts +9 -0
  120. package/dist/src/execution/catalog/listing.js +3 -0
  121. package/dist/src/execution/catalog/rank.d.ts +44 -0
  122. package/dist/src/execution/catalog/rank.js +1 -0
  123. package/dist/src/execution/catalog/search.d.ts +28 -0
  124. package/dist/src/execution/catalog/search.js +1 -0
  125. package/dist/src/execution/catalog/signatures.d.ts +11 -0
  126. package/dist/src/execution/catalog/signatures.js +1 -0
  127. package/dist/src/execution/catalog/skills.d.ts +24 -0
  128. package/dist/src/execution/catalog/skills.js +1 -0
  129. package/dist/src/execution/catalog/step-catalog.d.ts +51 -0
  130. package/dist/src/execution/catalog/step-catalog.js +1 -0
  131. package/dist/src/execution/coordination-dispatch-shared.js +1 -1
  132. package/dist/src/execution/dynamic-connections.js +1 -1
  133. package/dist/src/execution/dynamic-workflow/tool.js +1 -1
  134. package/dist/src/execution/eve-workflow-attributes.d.ts +15 -0
  135. package/dist/src/execution/eve-workflow-attributes.js +1 -1
  136. package/dist/src/execution/install-workflow-world.d.ts +7 -0
  137. package/dist/src/execution/install-workflow-world.js +1 -0
  138. package/dist/src/execution/invoke-tool.js +1 -1
  139. package/dist/src/execution/legacy-session/authorization.js +1 -1
  140. package/dist/src/execution/legacy-session/inbox.js +1 -1
  141. package/dist/src/execution/legacy-session/turn-workflow.js +1 -1
  142. package/dist/src/execution/node-step.js +1 -1
  143. package/dist/src/execution/session/active-turn.d.ts +1 -1
  144. package/dist/src/execution/session/entry.js +1 -1
  145. package/dist/src/execution/session/handoff-steps.d.ts +11 -0
  146. package/dist/src/execution/session/handoff-steps.js +1 -1
  147. package/dist/src/execution/session/pending-turn-state.js +1 -1
  148. package/dist/src/execution/session/program.js +1 -1
  149. package/dist/src/execution/session/timeout-steps.js +1 -1
  150. package/dist/src/execution/session/turn-step.js +1 -1
  151. package/dist/src/execution/session/turn.d.ts +5 -5
  152. package/dist/src/execution/session/turn.js +1 -1
  153. package/dist/src/execution/session-event-stream.d.ts +6 -0
  154. package/dist/src/execution/session-event-stream.js +1 -1
  155. package/dist/src/execution/session-inbox/address.d.ts +4 -0
  156. package/dist/src/execution/session-inbox/address.js +1 -1
  157. package/dist/src/execution/session-inbox/end-stranded-session.d.ts +22 -0
  158. package/dist/src/execution/session-inbox/end-stranded-session.js +1 -0
  159. package/dist/src/execution/session-inbox/hook-release.d.ts +4 -0
  160. package/dist/src/execution/session-inbox/hook-release.js +1 -0
  161. package/dist/src/execution/session-inbox/owner.d.ts +48 -0
  162. package/dist/src/execution/session-inbox/owner.js +1 -0
  163. package/dist/src/execution/session-inbox/resume.d.ts +12 -0
  164. package/dist/src/execution/session-inbox/resume.js +1 -1
  165. package/dist/src/execution/session-inbox/runnable-owner.d.ts +13 -0
  166. package/dist/src/execution/session-inbox/runnable-owner.js +1 -0
  167. package/dist/src/execution/session-inbox/stranded-replay-guard.d.ts +16 -0
  168. package/dist/src/execution/session-inbox/stranded-replay-guard.js +1 -0
  169. package/dist/src/execution/session.js +1 -1
  170. package/dist/src/execution/skills/instructions.d.ts +20 -10
  171. package/dist/src/execution/skills/instructions.js +2 -2
  172. package/dist/src/execution/tasks/calls.d.ts +6 -5
  173. package/dist/src/execution/tasks/calls.js +1 -1
  174. package/dist/src/execution/tasks/model-step.d.ts +10 -10
  175. package/dist/src/execution/tasks/model-step.js +1 -1
  176. package/dist/src/execution/tasks/render.d.ts +3 -3
  177. package/dist/src/execution/tasks/render.js +3 -3
  178. package/dist/src/execution/tasks/session.d.ts +2 -1
  179. package/dist/src/execution/tasks/table.d.ts +1 -1
  180. package/dist/src/execution/tasks/tool-entry-point.d.ts +1 -1
  181. package/dist/src/execution/tool-auth.js +1 -1
  182. package/dist/src/execution/tools/agent-router-workflow.js +1 -1
  183. package/dist/src/execution/tools/workflow/harness-definition.js +1 -1
  184. package/dist/src/execution/workflow-runtime.d.ts +5 -1
  185. package/dist/src/execution/workflow-runtime.js +1 -1
  186. package/dist/src/extensions/code/extension/extension.d.ts +4 -18
  187. package/dist/src/extensions/code/extension/instructions/github.d.ts +3 -0
  188. package/dist/src/extensions/code/extension/instructions/github.js +1 -0
  189. package/dist/src/extensions/code/extension/instructions.md +1 -13
  190. package/dist/src/extensions/code/extension/lib/diagnostics.d.ts +4 -2
  191. package/dist/src/extensions/code/extension/lib/diagnostics.js +3 -3
  192. package/dist/src/extensions/code/extension/lib/github-compat.d.ts +28 -0
  193. package/dist/src/extensions/code/extension/lib/github-compat.js +1 -0
  194. package/dist/src/extensions/code/extension/lib/grep-search.d.ts +3 -13
  195. package/dist/src/extensions/code/extension/lib/grep-search.js +2 -2
  196. package/dist/src/extensions/code/extension/lib/patch.d.ts +8 -2
  197. package/dist/src/extensions/code/extension/lib/patch.js +4 -4
  198. package/dist/src/extensions/code/extension/lib/repository-root.d.ts +3 -4
  199. package/dist/src/extensions/code/extension/lib/repository-root.js +1 -1
  200. package/dist/src/extensions/code/extension/lib/sandbox.d.ts +2 -1
  201. package/dist/src/extensions/code/extension/lib/sandbox.js +1 -1
  202. package/dist/src/extensions/code/extension/lib/tooling.d.ts +4 -4
  203. package/dist/src/extensions/code/extension/lib/tooling.js +7 -7
  204. package/dist/src/extensions/code/extension/lib/workspace-root.d.ts +31 -0
  205. package/dist/src/extensions/code/extension/lib/workspace-root.js +1 -0
  206. package/dist/src/extensions/code/extension/skills/pr.d.ts +6 -0
  207. package/dist/src/extensions/code/extension/skills/pr.js +1 -0
  208. package/dist/src/extensions/code/extension/tools/apply_patch.d.ts +2 -2
  209. package/dist/src/extensions/code/extension/tools/apply_patch.js +2 -2
  210. package/dist/src/extensions/code/extension/tools/gh.d.ts +4 -3
  211. package/dist/src/extensions/code/extension/tools/gh.js +1 -1
  212. package/dist/src/extensions/code/extension/tools/grep.js +1 -1
  213. package/dist/src/extensions/code/tools.d.ts +2 -1
  214. package/dist/src/extensions/code/tools.js +1 -1
  215. package/dist/src/extensions/git/extension/extension.d.ts +12 -0
  216. package/dist/src/extensions/git/extension/extension.js +1 -0
  217. package/dist/src/extensions/git/extension/instructions/github.d.ts +2 -0
  218. package/dist/src/extensions/git/extension/instructions/github.js +1 -0
  219. package/dist/src/extensions/git/extension/lib/gh-tool.d.ts +29 -0
  220. package/dist/src/extensions/git/extension/lib/gh-tool.js +1 -0
  221. package/dist/src/extensions/git/extension/lib/github-guidance.d.ts +3 -0
  222. package/dist/src/extensions/git/extension/lib/github-guidance.js +49 -0
  223. package/dist/src/extensions/{code → git}/extension/lib/github-shell.d.ts +1 -1
  224. package/dist/src/extensions/git/extension/lib/github-shell.js +1 -0
  225. package/dist/src/extensions/git/extension/lib/repository-root.d.ts +5 -0
  226. package/dist/src/extensions/git/extension/lib/repository-root.js +1 -0
  227. package/dist/src/extensions/git/extension/lib/sandbox.d.ts +6 -0
  228. package/dist/src/extensions/git/extension/lib/sandbox.js +1 -0
  229. package/dist/src/extensions/git/extension/lib/shell.d.ts +1 -0
  230. package/dist/src/extensions/git/extension/lib/shell.js +1 -0
  231. package/dist/src/extensions/git/extension/lib/tooling.d.ts +4 -0
  232. package/dist/src/extensions/git/extension/lib/tooling.js +1 -0
  233. package/dist/src/extensions/git/extension/skills/pr.d.ts +5 -0
  234. package/dist/src/extensions/git/extension/skills/pr.js +1 -0
  235. package/dist/src/extensions/git/extension/tools/gh.d.ts +28 -0
  236. package/dist/src/extensions/git/extension/tools/gh.js +1 -0
  237. package/dist/src/extensions/git/tools.d.ts +27 -0
  238. package/dist/src/extensions/git/tools.js +1 -0
  239. package/dist/src/framework/sources/registry.js +1 -1
  240. package/dist/src/harness/action-presentation.d.ts +2 -2
  241. package/dist/src/harness/action-result-helpers.d.ts +10 -2
  242. package/dist/src/harness/action-result-helpers.js +1 -1
  243. package/dist/src/harness/announcements.d.ts +2 -8
  244. package/dist/src/harness/announcements.js +1 -1
  245. package/dist/src/harness/compaction/step.js +1 -1
  246. package/dist/src/harness/coordination.d.ts +11 -11
  247. package/dist/src/harness/coordination.js +1 -1
  248. package/dist/src/harness/current-messages.d.ts +1 -5
  249. package/dist/src/harness/current-messages.js +1 -1
  250. package/dist/src/harness/emission.d.ts +2 -2
  251. package/dist/src/harness/emission.js +1 -1
  252. package/dist/src/harness/execute-call.d.ts +48 -0
  253. package/dist/src/harness/execute-call.js +1 -0
  254. package/dist/src/harness/execute-tool.d.ts +3 -1
  255. package/dist/src/harness/final-output.d.ts +2 -6
  256. package/dist/src/harness/final-output.js +1 -1
  257. package/dist/src/harness/hitl/approvals.d.ts +5 -0
  258. package/dist/src/harness/hitl/approvals.js +1 -1
  259. package/dist/src/harness/hitl/approved-calls.d.ts +3 -2
  260. package/dist/src/harness/hitl/approved-calls.js +1 -1
  261. package/dist/src/harness/hitl/candidates.d.ts +13 -2
  262. package/dist/src/harness/hitl/candidates.js +1 -1
  263. package/dist/src/harness/hitl/coordinator.d.ts +3 -3
  264. package/dist/src/harness/hitl/coordinator.js +1 -1
  265. package/dist/src/harness/hitl/index.d.ts +6 -4
  266. package/dist/src/harness/hitl/index.js +1 -1
  267. package/dist/src/harness/hitl/intake.d.ts +3 -3
  268. package/dist/src/harness/hitl/intake.js +1 -1
  269. package/dist/src/harness/input-extraction.d.ts +4 -1
  270. package/dist/src/harness/input-extraction.js +1 -1
  271. package/dist/src/harness/input-request-resolution.d.ts +15 -0
  272. package/dist/src/harness/input-request-resolution.js +1 -1
  273. package/dist/src/harness/model-call/call.d.ts +4 -6
  274. package/dist/src/harness/model-call/call.js +1 -1
  275. package/dist/src/harness/model-call/errors.d.ts +5 -6
  276. package/dist/src/harness/model-call/errors.js +1 -1
  277. package/dist/src/harness/model-call/recovery.d.ts +4 -3
  278. package/dist/src/harness/model-call/request.d.ts +5 -3
  279. package/dist/src/harness/model-call/request.js +1 -1
  280. package/dist/src/harness/model-call/response.d.ts +2 -1
  281. package/dist/src/harness/model-call/response.js +1 -1
  282. package/dist/src/harness/model-call/run.d.ts +5 -3
  283. package/dist/src/harness/model-call/run.js +1 -1
  284. package/dist/src/harness/model-call/tools.d.ts +12 -21
  285. package/dist/src/harness/model-call/tools.js +1 -1
  286. package/dist/src/harness/model-profile.d.ts +15 -3
  287. package/dist/src/harness/model-profile.js +1 -1
  288. package/dist/src/harness/prompt-cache.d.ts +6 -3
  289. package/dist/src/harness/prompt-cache.js +1 -1
  290. package/dist/src/harness/provider-safety.d.ts +2 -1
  291. package/dist/src/harness/provider-safety.js +1 -1
  292. package/dist/src/harness/provider-tools.d.ts +7 -6
  293. package/dist/src/harness/provider-tools.js +1 -1
  294. package/dist/src/harness/session-machine/commit.js +1 -1
  295. package/dist/src/harness/session-machine/transitions.d.ts +8 -3
  296. package/dist/src/harness/session-machine/transitions.js +1 -1
  297. package/dist/src/harness/step/after-model.js +1 -1
  298. package/dist/src/harness/step/context.js +1 -1
  299. package/dist/src/harness/step-hooks.d.ts +4 -6
  300. package/dist/src/harness/step-hooks.js +1 -1
  301. package/dist/src/harness/tool-call-input-errors.d.ts +2 -2
  302. package/dist/src/harness/tool-call-io.d.ts +3 -0
  303. package/dist/src/harness/tool-call-io.js +1 -1
  304. package/dist/src/harness/tools.d.ts +22 -19
  305. package/dist/src/harness/tools.js +1 -1
  306. package/dist/src/harness/types.d.ts +14 -0
  307. package/dist/src/instrumentation/lifecycle.d.ts +0 -1
  308. package/dist/src/instrumentation/native-events.js +1 -1
  309. package/dist/src/instrumentation/runtime.d.ts +2 -1
  310. package/dist/src/internal/application/compiled-artifacts.js +4 -4
  311. package/dist/src/internal/application/package.d.ts +1 -1
  312. package/dist/src/internal/application/package.js +1 -1
  313. package/dist/src/internal/application/stamped-package-version.d.ts +5 -0
  314. package/dist/src/internal/application/stamped-package-version.js +1 -0
  315. package/dist/src/internal/authored-definition/core.d.ts +3 -0
  316. package/dist/src/internal/authored-definition/core.js +1 -1
  317. package/dist/src/internal/authored-definition/schedule-collection.js +1 -1
  318. package/dist/src/internal/authored-definition/schema-backed.d.ts +2 -2
  319. package/dist/src/internal/authored-definition/schema-backed.js +1 -1
  320. package/dist/src/internal/authored-module.d.ts +2 -1
  321. package/dist/src/internal/authored-module.js +1 -1
  322. package/dist/src/internal/helpers/markdown.js +1 -1
  323. package/dist/src/internal/mcp/skills.js +1 -1
  324. package/dist/src/internal/model-auth/available-models.js +1 -1
  325. package/dist/src/internal/nitro/host/create-application-nitro.js +1 -1
  326. package/dist/src/internal/nitro/host/dev-host-fingerprint.js +1 -1
  327. package/dist/src/internal/nitro/host/local-schedules-runtime-plugin.d.ts +5 -0
  328. package/dist/src/internal/nitro/host/local-schedules-runtime-plugin.js +1 -0
  329. package/dist/src/internal/nitro/routes/schedule-collection-consumer.d.ts +6 -0
  330. package/dist/src/internal/nitro/routes/schedule-collection-consumer.js +1 -1
  331. package/dist/src/internal/schedules/consumer-route.d.ts +2 -0
  332. package/dist/src/internal/schedules/consumer-route.js +1 -1
  333. package/dist/src/internal/schedules/dev-environment.d.ts +2 -0
  334. package/dist/src/internal/schedules/dev-environment.js +1 -0
  335. package/dist/src/internal/vercel-agent-summary.d.ts +2 -2
  336. package/dist/src/internal/workflow/development-run-unavailable-error.d.ts +15 -0
  337. package/dist/src/internal/workflow/development-run-unavailable-error.js +1 -0
  338. package/dist/src/internal/workflow/development-world-server.js +1 -1
  339. package/dist/src/internal/workflow/vercel-world-defaults.d.ts +1 -1
  340. package/dist/src/internal/workflow/vercel-world-defaults.js +1 -1
  341. package/dist/src/internal/workflow-bundle/workflow-builders.js +1 -1
  342. package/dist/src/protocol/catalog-tools.d.ts +12 -0
  343. package/dist/src/protocol/catalog-tools.js +1 -0
  344. package/dist/src/protocol/message-version.js +1 -1
  345. package/dist/src/protocol/message.d.ts +15 -1
  346. package/dist/src/protocol/message.js +1 -1
  347. package/dist/src/protocol/remote-agent-protocol.d.ts +2 -0
  348. package/dist/src/protocol/remote-agent-protocol.js +1 -1
  349. package/dist/src/protocol/reply-tool.d.ts +2 -0
  350. package/dist/src/protocol/reply-tool.js +1 -0
  351. package/dist/src/protocol/runtime-tools.d.ts +6 -0
  352. package/dist/src/protocol/runtime-tools.js +1 -0
  353. package/dist/src/protocol/session-projection.js +1 -1
  354. package/dist/src/protocol/task-tools.d.ts +4 -4
  355. package/dist/src/protocol/task-tools.js +1 -1
  356. package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +1 -1
  357. package/dist/src/public/channels/index.d.ts +1 -1
  358. package/dist/src/public/channels/index.js +1 -1
  359. package/dist/src/public/channels/linear/defaults.js +2 -2
  360. package/dist/src/public/channels/slack/action-status.d.ts +0 -9
  361. package/dist/src/public/channels/slack/action-status.js +1 -1
  362. package/dist/src/public/channels/slack/defaults.js +2 -2
  363. package/dist/src/public/channels/slack/task-card.d.ts +1 -1
  364. package/dist/src/public/context/index.d.ts +1 -1
  365. package/dist/src/public/definitions/callback-context.d.ts +1 -1
  366. package/dist/src/public/definitions/channel.d.ts +1 -0
  367. package/dist/src/public/definitions/channel.js +1 -1
  368. package/dist/src/public/definitions/connections/mcp.d.ts +4 -4
  369. package/dist/src/public/definitions/connections/openapi.d.ts +6 -7
  370. package/dist/src/public/definitions/remote-agent.d.ts +6 -3
  371. package/dist/src/public/definitions/workspace-agent.d.ts +6 -3
  372. package/dist/src/public/experimental/schedules/index.d.ts +1 -1
  373. package/dist/src/public/models/openai/chatgpt/model.js +1 -1
  374. package/dist/src/public/models/openai/chatgpt/transport.js +1 -1
  375. package/dist/src/public/schedules/providers/in-memory.js +1 -1
  376. package/dist/src/public/schedules/providers/vercel.js +1 -1
  377. package/dist/src/public/schedules/subscription.d.ts +36 -16
  378. package/dist/src/public/tanstack/index.d.ts +40 -0
  379. package/dist/src/public/tanstack/index.js +1 -0
  380. package/dist/src/public/tools/web-search.d.ts +1 -1
  381. package/dist/src/runtime/agent/bootstrap.d.ts +2 -1
  382. package/dist/src/runtime/agent/bootstrap.js +1 -1
  383. package/dist/src/runtime/agent/mock-model-adapter.js +2 -2
  384. package/dist/src/runtime/agent/mock-model-fixtures.js +2 -2
  385. package/dist/src/runtime/agent/mock-model-skill-selection.d.ts +2 -0
  386. package/dist/src/runtime/agent/mock-model-skill-selection.js +2 -2
  387. package/dist/src/runtime/agent/mock-structured-output.d.ts +1 -1
  388. package/dist/src/runtime/agent/resolve-model.js +1 -1
  389. package/dist/src/runtime/connections/mcp-client.js +1 -1
  390. package/dist/src/runtime/connections/registry.js +1 -1
  391. package/dist/src/runtime/connections/scoped-authorization.js +1 -1
  392. package/dist/src/runtime/connections/tool-result.d.ts +2 -2
  393. package/dist/src/runtime/resolve-agent-graph.js +1 -1
  394. package/dist/src/runtime/resolve-agent.js +1 -1
  395. package/dist/src/runtime/resolve-tool.js +1 -1
  396. package/dist/src/runtime/schedules/collection-client.d.ts +12 -3
  397. package/dist/src/runtime/schedules/collection-client.js +1 -1
  398. package/dist/src/runtime/subagents/dynamic-agent-config.d.ts +2 -2
  399. package/dist/src/runtime/subagents/dynamic-remote-agent-config.d.ts +2 -1
  400. package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
  401. package/dist/src/runtime/subagents/registry.d.ts +2 -1
  402. package/dist/src/runtime/subagents/registry.js +1 -1
  403. package/dist/src/runtime/tools/registry.d.ts +2 -0
  404. package/dist/src/runtime/tools/registry.js +1 -1
  405. package/dist/src/runtime/types.d.ts +3 -3
  406. package/dist/src/setup/connection-connector.js +1 -2
  407. package/dist/src/setup/flows/model-login.js +1 -1
  408. package/dist/src/setup/index.d.ts +1 -1
  409. package/dist/src/setup/index.js +1 -1
  410. package/dist/src/setup/integrations/slack/setup.d.ts +23 -3
  411. package/dist/src/setup/integrations/slack/setup.js +1 -1
  412. package/dist/src/setup/integrations/web/framework.d.ts +8 -0
  413. package/dist/src/setup/integrations/web/framework.js +1 -0
  414. package/dist/src/setup/integrations/web/hosting.d.ts +43 -0
  415. package/dist/src/setup/integrations/web/hosting.js +15 -0
  416. package/dist/src/setup/integrations/web/setup.d.ts +6 -10
  417. package/dist/src/setup/integrations/web/setup.js +23 -17
  418. package/dist/src/setup/primitives/process-output.d.ts +5 -0
  419. package/dist/src/setup/primitives/process-output.js +2 -1
  420. package/dist/src/setup/scaffold/create/project.js +1 -1
  421. package/dist/src/setup/scaffold/create/web-template.d.ts +7 -3
  422. package/dist/src/setup/scaffold/create/web-template.js +40 -3
  423. package/dist/src/setup/scaffold/update/channels.js +1 -1
  424. package/dist/src/setup/scaffold/update/update-slack-channel.d.ts +17 -0
  425. package/dist/src/setup/scaffold/update/update-slack-channel.js +1 -1
  426. package/dist/src/setup/slack-connect-create.d.ts +10 -2
  427. package/dist/src/setup/slack-connect-create.js +1 -1
  428. package/dist/src/setup/slack-connect-lifecycle.d.ts +92 -44
  429. package/dist/src/setup/slack-connect-lifecycle.js +1 -1
  430. package/dist/src/setup/slack-connect.d.ts +30 -11
  431. package/dist/src/setup/slack-connect.js +1 -1
  432. package/dist/src/setup/slack-setup-plan.d.ts +72 -0
  433. package/dist/src/setup/slack-setup-plan.js +1 -0
  434. package/dist/src/setup/slackbot.d.ts +75 -35
  435. package/dist/src/setup/slackbot.js +2 -1
  436. package/dist/src/setup/vercel-project-framework.js +1 -1
  437. package/dist/src/shared/action-label.d.ts +10 -0
  438. package/dist/src/shared/action-label.js +1 -0
  439. package/dist/src/shared/action-request-name.d.ts +3 -1
  440. package/dist/src/shared/action-request-name.js +1 -1
  441. package/dist/src/shared/action-types.d.ts +7 -8
  442. package/dist/src/shared/action-types.js +1 -1
  443. package/dist/src/shared/agent-definition.d.ts +36 -3
  444. package/dist/src/shared/agent-definition.js +1 -1
  445. package/dist/src/shared/chatgpt-model.d.ts +8 -0
  446. package/dist/src/shared/chatgpt-model.js +1 -1
  447. package/dist/src/shared/development-env-files.d.ts +4 -0
  448. package/dist/src/shared/development-env-files.js +1 -0
  449. package/dist/src/shared/input.d.ts +0 -1
  450. package/dist/src/shared/map-with-concurrency.d.ts +2 -0
  451. package/dist/src/shared/map-with-concurrency.js +1 -0
  452. package/dist/src/shared/skill-definition.d.ts +6 -0
  453. package/dist/src/shared/skill-package.d.ts +1 -0
  454. package/dist/src/shared/skill-package.js +1 -1
  455. package/dist/src/shared/web-search.d.ts +15 -2
  456. package/dist/src/shared/web-search.js +1 -1
  457. package/dist/src/subagents/callback-route.js +1 -1
  458. package/dist/src/svelte/index.js +1 -1
  459. package/dist/src/svelte/use-eve-agent.js +1 -1
  460. package/dist/src/tool-stubs/execute.d.ts +0 -3
  461. package/dist/src/tool-stubs/execute.js +1 -1
  462. package/dist/src/tool-stubs/rules.js +1 -1
  463. package/dist/src/tool-stubs/validate-targets.js +1 -1
  464. package/dist/src/tools/behavior.d.ts +3 -6
  465. package/dist/src/tools/definition.d.ts +5 -0
  466. package/dist/src/tools/dynamic.d.ts +5 -2
  467. package/dist/src/tools/provided/ask-question-workflow.js +1 -1
  468. package/dist/src/tools/provided/sleep-workflow.js +1 -1
  469. package/dist/src/tools/provided/task-cancel.d.ts +1 -1
  470. package/dist/src/tools/provided/task-wait.d.ts +1 -1
  471. package/dist/src/tools/provided/web-search.d.ts +20 -7
  472. package/dist/src/tools/provided/web-search.js +1 -1
  473. package/dist/src/tools/schema.d.ts +5 -0
  474. package/dist/src/tools/schema.js +1 -1
  475. package/dist/src/{runtime/connections/tool-signature.d.ts → tools/signature.d.ts} +2 -2
  476. package/dist/src/tools/workflow-definition.d.ts +1 -1
  477. package/dist/src/tracing/agent-approval-instrumentation.js +1 -1
  478. package/dist/src/tracing/agent-otel-provider.js +2 -2
  479. package/dist/src/tracing/agent-otel-runtime-context.d.ts +1 -0
  480. package/dist/src/tracing/agent-otel-runtime-context.js +1 -1
  481. package/dist/src/tracing/agent-otel-turn-state.d.ts +6 -0
  482. package/dist/src/tracing/agent-otel-turn-state.js +1 -0
  483. package/dist/src/tracing/agent-tool-instrumentation.js +1 -1
  484. package/dist/src/tracing/agent-trace-context-codec.js +1 -1
  485. package/dist/src/tracing/agent-trace-state.d.ts +4 -1
  486. package/dist/src/vue/index.js +1 -1
  487. package/dist/src/vue/use-eve-agent.js +1 -1
  488. package/docs/agent-config.md +39 -8
  489. package/docs/channels/chat-sdk.mdx +1 -1
  490. package/docs/channels/custom.mdx +26 -0
  491. package/docs/channels/eve.mdx +8 -5
  492. package/docs/channels/slack.mdx +32 -82
  493. package/docs/code-extension.mdx +28 -7
  494. package/docs/concepts/built-in-tools.md +60 -43
  495. package/docs/concepts/context-control.md +1 -1
  496. package/docs/concepts/execution-model-and-durability.mdx +101 -1
  497. package/docs/concepts/project-structure.mdx +2 -2
  498. package/docs/concepts/sessions-runs-and-streaming.md +40 -38
  499. package/docs/connections/mcp.mdx +5 -5
  500. package/docs/connections/openapi.mdx +1 -1
  501. package/docs/connections/overview.mdx +4 -2
  502. package/docs/evals/assertions.mdx +5 -3
  503. package/docs/evals/reporters.mdx +3 -1
  504. package/docs/evals/tool-stubs.mdx +3 -1
  505. package/docs/extensions.md +2 -0
  506. package/docs/guides/client/messages.mdx +10 -1
  507. package/docs/guides/deployment/overview.md +2 -2
  508. package/docs/guides/dev-tui.md +4 -2
  509. package/docs/guides/dynamic-capabilities.md +14 -4
  510. package/docs/guides/frontend/meta.json +9 -1
  511. package/docs/guides/frontend/nextjs.mdx +1 -1
  512. package/docs/guides/frontend/overview.mdx +10 -9
  513. package/docs/guides/frontend/tanstack.mdx +201 -0
  514. package/docs/guides/remote-agents.md +10 -3
  515. package/docs/guides/session-context.md +1 -0
  516. package/docs/install-integrations.mdx +1 -1
  517. package/docs/instructions.mdx +6 -6
  518. package/docs/reference/cli.md +2 -2
  519. package/docs/reference/typescript-api.md +4 -4
  520. package/docs/skills.mdx +19 -4
  521. package/docs/subagents/index.mdx +5 -3
  522. package/docs/tools/human-in-the-loop.md +2 -0
  523. package/docs/tools/overview.mdx +22 -1
  524. package/docs/tools/tasks-upgrade.md +1 -1
  525. package/docs/tools/tasks.md +32 -32
  526. package/docs/tools/workflows.mdx +6 -6
  527. package/docs/tutorial/ship-it.mdx +1 -1
  528. package/docs/tutorial/team-playbooks.mdx +2 -2
  529. package/package.json +28 -6
  530. package/dist/src/execution/connection-announcement.d.ts +0 -7
  531. package/dist/src/execution/connection-announcement.js +0 -4
  532. package/dist/src/execution/tools/connection-approval.d.ts +0 -25
  533. package/dist/src/execution/tools/connection-approval.js +0 -1
  534. package/dist/src/execution/tools/connection-search-rank.d.ts +0 -21
  535. package/dist/src/execution/tools/connection-search-rank.js +0 -1
  536. package/dist/src/execution/tools/connection-target.d.ts +0 -18
  537. package/dist/src/execution/tools/connection-target.js +0 -1
  538. package/dist/src/execution/tools/connection-tools.d.ts +0 -4
  539. package/dist/src/execution/tools/connection-tools.js +0 -2
  540. package/dist/src/execution/tools/load-skill.d.ts +0 -10
  541. package/dist/src/execution/tools/load-skill.js +0 -1
  542. package/dist/src/extensions/code/extension/lib/github-shell.js +0 -1
  543. package/dist/src/extensions/code/extension/skills/pr/SKILL.md +0 -53
  544. package/dist/src/extensions/code/extension/subagents/worker/tools/load_skill.d.ts +0 -2
  545. package/dist/src/extensions/code/extension/subagents/worker/tools/load_skill.js +0 -1
  546. package/dist/src/harness/advertised-tools.d.ts +0 -26
  547. package/dist/src/harness/advertised-tools.js +0 -1
  548. package/dist/src/harness/nested-actions.d.ts +0 -23
  549. package/dist/src/harness/nested-actions.js +0 -1
  550. package/dist/src/node_modules/.pnpm/@vercel_cli-config@0.2.0/node_modules/@vercel/cli-config/dist/cli-config.js +0 -1
  551. package/dist/src/node_modules/.pnpm/@vercel_cli-config@0.2.0/node_modules/@vercel/cli-config/dist/cred-storage.js +0 -1
  552. package/dist/src/node_modules/.pnpm/@vercel_cli-config@0.2.0/node_modules/@vercel/cli-config/dist/index.js +0 -1
  553. package/dist/src/node_modules/.pnpm/@vercel_cli-config@0.2.0/node_modules/@vercel/cli-config/dist/schema.js +0 -1
  554. package/dist/src/node_modules/.pnpm/@vercel_cli-config@0.2.0/node_modules/@vercel/cli-config/dist/schema.zod.js +0 -1
  555. package/dist/src/node_modules/.pnpm/@vercel_cli-config@0.2.0/node_modules/@vercel/cli-config/dist/types.js +0 -1
  556. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/envpath.js +0 -1
  557. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/errors.js +0 -2
  558. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/errutils.js +0 -1
  559. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/exec.js +0 -1
  560. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/fsutils.js +0 -1
  561. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/index.js +0 -1
  562. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/lookup.js +0 -1
  563. package/dist/src/node_modules/.pnpm/@vercel_cli-exec@1.0.0/node_modules/@vercel/cli-exec/dist/safety.js +0 -1
  564. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/auth-errors.js +0 -1
  565. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/exchange-vercel-oidc-token.js +0 -1
  566. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/get-context.js +0 -1
  567. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token-sync.js +0 -1
  568. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token-with-refresh.js +0 -2
  569. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/index.js +0 -1
  570. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/oauth.js +0 -1
  571. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/token-error.js +0 -1
  572. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/token-io.js +0 -1
  573. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/token-util.js +0 -2
  574. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/token.js +0 -1
  575. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/verify-vercel-oidc-token.js +0 -1
  576. package/dist/src/node_modules/.pnpm/@vercel_oidc@3.8.0/node_modules/@vercel/oidc/dist/version.js +0 -1
  577. package/dist/src/node_modules/.pnpm/@vercel_queue@0.5.1_@opentelemetry_api@1.9.1/node_modules/@vercel/queue/dist/index.js +0 -36
  578. package/dist/src/node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js +0 -1
  579. package/dist/src/node_modules/.pnpm/brace-expansion@5.0.12/node_modules/brace-expansion/dist/esm/index.js +0 -1
  580. package/dist/src/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js +0 -1
  581. package/dist/src/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js +0 -1
  582. package/dist/src/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js +0 -1
  583. package/dist/src/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js +0 -1
  584. package/dist/src/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js +0 -1
  585. package/dist/src/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js +0 -1
  586. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/index.js +0 -1
  587. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/command.js +0 -1
  588. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/error.js +0 -2
  589. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/kill.js +0 -1
  590. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/promise.js +0 -1
  591. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/stdio.js +0 -1
  592. package/dist/src/node_modules/.pnpm/execa@5.1.1/node_modules/execa/lib/stream.js +0 -1
  593. package/dist/src/node_modules/.pnpm/get-stream@6.0.1/node_modules/get-stream/buffer-stream.js +0 -1
  594. package/dist/src/node_modules/.pnpm/get-stream@6.0.1/node_modules/get-stream/index.js +0 -1
  595. package/dist/src/node_modules/.pnpm/human-signals@2.1.0/node_modules/human-signals/build/src/core.js +0 -1
  596. package/dist/src/node_modules/.pnpm/human-signals@2.1.0/node_modules/human-signals/build/src/main.js +0 -1
  597. package/dist/src/node_modules/.pnpm/human-signals@2.1.0/node_modules/human-signals/build/src/realtime.js +0 -1
  598. package/dist/src/node_modules/.pnpm/human-signals@2.1.0/node_modules/human-signals/build/src/signals.js +0 -1
  599. package/dist/src/node_modules/.pnpm/is-stream@2.0.1/node_modules/is-stream/index.js +0 -1
  600. package/dist/src/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js +0 -1
  601. package/dist/src/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js +0 -1
  602. package/dist/src/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js +0 -1
  603. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/index.js +0 -1
  604. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwe/compact/decrypt.js +0 -1
  605. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwe/compact/encrypt.js +0 -1
  606. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwe/flattened/decrypt.js +0 -1
  607. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwe/flattened/encrypt.js +0 -1
  608. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwe/general/decrypt.js +0 -1
  609. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwe/general/encrypt.js +0 -1
  610. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwk/embedded.js +0 -1
  611. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwk/thumbprint.js +0 -1
  612. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwks/local.js +0 -1
  613. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwks/remote.js +0 -1
  614. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jws/compact/sign.js +0 -1
  615. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jws/compact/verify.js +0 -1
  616. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jws/flattened/sign.js +0 -1
  617. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jws/flattened/verify.js +0 -1
  618. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jws/general/sign.js +0 -1
  619. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jws/general/verify.js +0 -1
  620. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwt/decrypt.js +0 -1
  621. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwt/encrypt.js +0 -1
  622. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwt/produce.js +0 -1
  623. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwt/sign.js +0 -1
  624. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwt/unsecured.js +0 -1
  625. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/jwt/verify.js +0 -1
  626. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/key/export.js +0 -1
  627. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/key/generate_key_pair.js +0 -1
  628. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/key/generate_secret.js +0 -1
  629. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/key/import.js +0 -1
  630. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/aesgcmkw.js +0 -1
  631. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/buffer_utils.js +0 -1
  632. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/cek.js +0 -1
  633. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/check_iv_length.js +0 -1
  634. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/check_key_type.js +0 -1
  635. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/check_p2s.js +0 -1
  636. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/crypto_key.js +0 -1
  637. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/decrypt_key_management.js +0 -1
  638. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/encrypt_key_management.js +0 -1
  639. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/epoch.js +0 -1
  640. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/invalid_key_input.js +0 -1
  641. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/is_disjoint.js +0 -1
  642. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/is_jwk.js +0 -1
  643. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/is_object.js +0 -1
  644. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/iv.js +0 -1
  645. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/jwt_claims_set.js +0 -1
  646. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/private_symbols.js +0 -1
  647. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/secs.js +0 -1
  648. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/validate_algorithms.js +0 -1
  649. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/lib/validate_crit.js +0 -1
  650. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/aeskw.js +0 -1
  651. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/asn1.js +0 -1
  652. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/base64url.js +0 -1
  653. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/cbc_tag.js +0 -1
  654. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/check_cek_length.js +0 -1
  655. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/check_key_length.js +0 -1
  656. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/ciphers.js +0 -1
  657. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/decrypt.js +0 -1
  658. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/digest.js +0 -1
  659. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/dsa_digest.js +0 -1
  660. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/ecdhes.js +0 -1
  661. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/encrypt.js +0 -1
  662. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/fetch_jwks.js +0 -1
  663. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/generate.js +0 -1
  664. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/get_named_curve.js +0 -1
  665. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/get_sign_verify_key.js +0 -1
  666. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/hmac_digest.js +0 -1
  667. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/is_key_like.js +0 -1
  668. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/is_key_object.js +0 -1
  669. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/jwk_to_key.js +0 -1
  670. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/key_to_jwk.js +0 -1
  671. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/node_key.js +0 -1
  672. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/normalize_key.js +0 -1
  673. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/pbes2kw.js +0 -1
  674. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/random.js +0 -1
  675. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/rsaes.js +0 -1
  676. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/runtime.js +0 -1
  677. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/sign.js +0 -1
  678. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/timing_safe_equal.js +0 -1
  679. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/verify.js +0 -1
  680. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/runtime/webcrypto.js +0 -1
  681. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/util/base64url.js +0 -1
  682. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/util/decode_jwt.js +0 -1
  683. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/util/decode_protected_header.js +0 -1
  684. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/util/errors.js +0 -1
  685. package/dist/src/node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/node/cjs/util/runtime.js +0 -1
  686. package/dist/src/node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.js +0 -1
  687. package/dist/src/node_modules/.pnpm/mimic-fn@2.1.0/node_modules/mimic-fn/index.js +0 -1
  688. package/dist/src/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/assert-valid-pattern.js +0 -1
  689. package/dist/src/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/ast.js +0 -1
  690. package/dist/src/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/brace-expressions.js +0 -1
  691. package/dist/src/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/escape.js +0 -1
  692. package/dist/src/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/index.js +0 -1
  693. package/dist/src/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/unescape.js +0 -1
  694. package/dist/src/node_modules/.pnpm/mixpart@0.0.6/node_modules/mixpart/dist/index.js +0 -7
  695. package/dist/src/node_modules/.pnpm/npm-run-path@4.0.1/node_modules/npm-run-path/index.js +0 -1
  696. package/dist/src/node_modules/.pnpm/onetime@5.1.2/node_modules/onetime/index.js +0 -1
  697. package/dist/src/node_modules/.pnpm/os-paths@4.4.0/node_modules/os-paths/src/lib/index.js +0 -1
  698. package/dist/src/node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js +0 -1
  699. package/dist/src/node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js +0 -1
  700. package/dist/src/node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js +0 -1
  701. package/dist/src/node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js +0 -1
  702. package/dist/src/node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/index.js +0 -1
  703. package/dist/src/node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/signals.js +0 -1
  704. package/dist/src/node_modules/.pnpm/strip-final-newline@2.0.0/node_modules/strip-final-newline/index.js +0 -2
  705. package/dist/src/node_modules/.pnpm/which@2.0.2/node_modules/which/which.js +0 -1
  706. package/dist/src/node_modules/.pnpm/xdg-app-paths@5.5.1/node_modules/xdg-app-paths/src/lib/index.js +0 -1
  707. package/dist/src/node_modules/.pnpm/xdg-portable@7.3.0/node_modules/xdg-portable/src/lib/index.js +0 -1
  708. package/dist/src/public/tools/load-skill.d.ts +0 -3
  709. package/dist/src/public/tools/load-skill.js +0 -1
  710. package/dist/src/runtime/skills/fragment-context.d.ts +0 -4
  711. package/dist/src/runtime/skills/fragment-context.js +0 -1
  712. package/dist/src/tools/framework/connection-tools.d.ts +0 -3
  713. package/dist/src/tools/framework/connection-tools.js +0 -1
  714. package/dist/src/tools/provided/load-skill.d.ts +0 -2
  715. package/dist/src/tools/provided/load-skill.js +0 -1
  716. /package/dist/src/extensions/{code → git}/extension/lib/github-shell-schema.d.ts +0 -0
  717. /package/dist/src/extensions/{code → git}/extension/lib/github-shell-schema.js +0 -0
  718. /package/dist/src/extensions/{code → git}/extension/lib/signed-commit.d.ts +0 -0
  719. /package/dist/src/extensions/{code → git}/extension/lib/signed-commit.js +0 -0
  720. /package/dist/src/{runtime/connections/tool-signature.js → tools/signature.js} +0 -0
@@ -0,0 +1 @@
1
+ import{CALL_TOOL_NAME,SKILL_TOOL_NAME}from"#protocol/catalog-tools.js";import{isWorkflowTool}from"#execution/tasks/model-step.js";import{toolCallModelOutput}from"#harness/tool-call-io.js";function historyCallNames(e){let t=new Map;for(let n of e)if(n.role===`assistant`&&Array.isArray(n.content))for(let e of n.content)e.type===`tool-call`&&t.set(e.toolCallId,e.toolName);return t}const DISPATCHED=Object.freeze({dispatched:!0});function dispatchesAfterStep(e){return e!==void 0&&isWorkflowTool(e.definition)}function runEntryCall(e,t){if(dispatchesAfterStep(e))return DISPATCHED;let{call:n,definition:r}=e;if(r.execute===void 0)throw Error(`"${n.toolName}" cannot run.`);return r.execute(n.input,t)}function stubbedCall(e,t){return t===void 0?e:dispatchesAfterStep(t)?void 0:t.call}function entryModelOutput(e,t,n){return t===DISPATCHED?Promise.resolve({type:`json`,value:null}):toolCallModelOutput(e,t,n)}function toEntryStep(e,t,n){let r=new Set((e.toolResults??[]).filter(e=>e.output===DISPATCHED).map(e=>e.toolCallId)),kept=e=>e.type!==`tool-result`||!r.has(e.toolCallId);return[{content:(e.content??[]).filter(kept).map(e=>toEntryPart(e,n)),finishReason:e.finishReason,invalidInputToolCallIds:e.invalidInputToolCallIds,providerMetadata:e.providerMetadata,response:{...e.response,messages:withoutResults(e.response.messages,kept)},text:e.text,toolCalls:(e.toolCalls??[]).map(e=>entryCallOf(e,n)),toolResults:(e.toolResults??[]).filter(kept).map(e=>entryCallOf(e,n)),usage:e.usage},withoutResults(t,kept)]}async function*toEntryStream(e,t){let n=new Set;for await(let r of e){if(r.type===`tool-input-start`&&(r.toolName===CALL_TOOL_NAME||r.toolName===SKILL_TOOL_NAME)){n.add(r.id);continue}r.type===`tool-input-delta`&&n.has(r.id)||r.type===`tool-input-end`&&n.delete(r.id)||(r.type!==`tool-result`||r.output!==DISPATCHED)&&(yield toEntryPart(r,t))}}function toEntryTelemetry(e,t){let n=e?.integrations;if(n===void 0)return e;let r=Array.isArray(n)?n:[n],i=new Set;return{...e,integrations:r.map(e=>entryToolExecutions(e,t,i))}}function entryToolExecutions(e,t,n){let{executeTool:r,onToolExecutionEnd:i,onToolExecutionStart:a}=e;if(!r&&!i&&!a)return e;let reportAsEntry=r=>i=>{let a=t(i.toolCall);if(dispatchesAfterStep(a)){n.add(i.toolCall.toolCallId);return}return r?.call(e,{...i,toolCall:a?.call??i.toolCall})};return Object.create(e,{executeTool:{value(t){return n.has(t.toolCallId)||r===void 0?t.execute():r.call(e,t)}},onToolExecutionEnd:{value:reportAsEntry(i)},onToolExecutionStart:{value:reportAsEntry(a)}})}function entryCallOf(e,t){return t(e)?.call??e}function toEntryPart(e,t){switch(e.type){case`tool-call`:case`tool-result`:case`tool-error`:return entryCallOf(e,t);case`tool-approval-request`:{let n=e;return n.toolCall===void 0?e:{...n,toolCall:entryCallOf(n.toolCall,t)}}default:return e}}function withoutResults(e,t){return e.flatMap(e=>{if(e.role!==`tool`)return[e];let n=e.content.filter(t);return n.length===0?[]:[{...e,content:n}]})}export{dispatchesAfterStep,entryModelOutput,historyCallNames,runEntryCall,stubbedCall,toEntryStep,toEntryStream,toEntryTelemetry};
@@ -11,6 +11,8 @@ export interface HarnessToolDefinition {
11
11
  readonly label?: InternalToolLabelDefinition;
12
12
  readonly approvalKey?: (toolInput: Readonly<Record<string, unknown>>) => string;
13
13
  readonly behavior?: PreparedToolBehavior;
14
+ /** Kept out of the model's tool list; the model reaches it through `eve__search` and `eve__tool`. */
15
+ readonly deferred?: boolean;
14
16
  readonly description: string;
15
17
  /** A successful call ends the turn without a final reply; see `ToolDefinition.endsTurn`. */
16
18
  readonly endsTurn?: InternalToolDefinition["endsTurn"];
@@ -18,7 +20,7 @@ export interface HarnessToolDefinition {
18
20
  /** Optional JSON input substituted when this tool starts its workflow body. */
19
21
  readonly executeInput?: (input: unknown) => JsonValue;
20
22
  readonly frameworkTool?: boolean;
21
- readonly frameworkAction?: "load-skill" | "task-cancel" | "task-wait";
23
+ readonly frameworkAction?: "task-cancel" | "task-wait";
22
24
  readonly inputSchema: FlexibleSchema;
23
25
  readonly name: string;
24
26
  readonly approval?: Approval;
@@ -1,16 +1,12 @@
1
1
  import type { Tool } from "ai";
2
2
  import type { JsonObject } from "#shared/json.js";
3
- /**
4
- * Stable model-visible name for the kernel structured-output interception.
5
- */
6
- export declare const FINAL_OUTPUT_TOOL_NAME = "final_output";
7
3
  /**
8
4
  * What the model reads when it gives its final output beside calls whose results it hasn't seen:
9
5
  * the turn can't end on an answer written before them, so it answers again once they arrive.
10
6
  */
11
- export declare const FINAL_OUTPUT_BESIDE_PENDING_CALLS = "Your final output wasn't delivered because other calls in this response were still running. Use their results, then call final_output again.";
7
+ export declare const FINAL_OUTPUT_BESIDE_PENDING_CALLS = "Your reply wasn't delivered because other calls in this response were still running. Use their results, then call eve__reply again.";
12
8
  /**
13
- * Builds the model-facing `final_output` tool from a lowered output schema.
9
+ * Builds the model-facing `eve__reply` tool from a lowered output schema.
14
10
  *
15
11
  * The tool has no `execute`: calling it is the terminal signal the harness
16
12
  * intercepts to surface the structured result. Its input is provider-constrained
@@ -1 +1 @@
1
- import{defineJsonSchema,toModelSchema}from"#tools/schema.js";const FINAL_OUTPUT_TOOL_NAME=`final_output`,FINAL_OUTPUT_BESIDE_PENDING_CALLS=`Your final output wasn't delivered because other calls in this response were still running. Use their results, then call final_output again.`;function buildFinalOutputTool(e){let t=toModelSchema(defineJsonSchema(e),`input`);return{description:`Deliver your final answer in the required structure by calling this tool. Call it exactly once, when you are done; do not answer in prose.`,inputSchema:t,outputSchema:t}}export{FINAL_OUTPUT_BESIDE_PENDING_CALLS,FINAL_OUTPUT_TOOL_NAME,buildFinalOutputTool};
1
+ import{REPLY_TOOL_NAME}from"#protocol/reply-tool.js";import{defineJsonSchema,toModelSchema}from"#tools/schema.js";const FINAL_OUTPUT_BESIDE_PENDING_CALLS=`Your reply wasn't delivered because other calls in this response were still running. Use their results, then call ${REPLY_TOOL_NAME} again.`;function buildFinalOutputTool(e){let t=toModelSchema(defineJsonSchema(e),`input`);return{description:`Reply with your final answer in the required structure by calling this tool. Call it when you are done, as your final step; do not answer in prose.`,inputSchema:t,outputSchema:t}}export{FINAL_OUTPUT_BESIDE_PENDING_CALLS,buildFinalOutputTool};
@@ -76,6 +76,11 @@ export declare function answer(view: SessionView, input: {
76
76
  /** The delivery merged the queue in, so the queue empties. */
77
77
  readonly takeQueued: boolean;
78
78
  readonly approvalKey: (request: InputRequest) => string | undefined;
79
+ /**
80
+ * Whether the request's restored step has `eve__search`, which a call whose
81
+ * tool is gone can use to find another.
82
+ */
83
+ readonly searchable: (request: InputRequest) => boolean;
79
84
  }): Answered;
80
85
  /** Queued input that can run now, rather than wait for more answers. */
81
86
  export declare function hasRunnableQueue(view: SessionView): boolean;
@@ -1 +1 @@
1
- import{canonicalize,compactInput,hasInput,isEmptyInput,resolveTextInput,withoutResponses,withoutTurnInput}from"./delivery.js";import{openInputs,turnCoordinates}from"#protocol/session-projection.js";import{readClientContext}from"#internal/client-context.js";import{createActionResultEvent,createApprovalCandidateEvent,createApprovalSettledEvent,createAuthorizationCompletedEvent,createAuthorizationRequiredEvent,createInputRequestedEvent,createInputResolvedEvent,createMessageCompletedEvent}from"#protocol/message.js";import{coalesceTurnInputs,createFrameworkUserMessage}from"#harness/messages.js";import{turnPosition}from"#harness/session-machine/view.js";import{renderPendingApprovalsSnippet}from"#harness/hitl/approval-prompt.js";import{finishTurn,hold,ownOpenRequestIds,settle,stepCallIds,suspend,withResult,withoutApproved}from"#harness/session-machine/transitions.js";import{supersededChallenges,withSignIns}from"#harness/authorization.js";import{withoutCalls}from"#harness/inline-tool-authorization.js";import{isApprovalRequest}from"#harness/input-request-class.js";import{authorizationEventFields}from"#harness/authorization-event-fields.js";import{TOOL_EXECUTION_DENIED_MESSAGE,resolveApprovalOutcome,resolveInputOutcome}from"#harness/input-request-resolution.js";import{resolveSessionLimitContinuation}from"#harness/hitl/budget-request.js";import{signInWithdrawn}from"#harness/session-machine/events.js";function parkOnApprovals(e,t){let n=t.requester?.principalType===`anonymous`?null:t.requester,r=t.messages.findIndex(e=>e.role!==`tool`),i=r===-1?t.messages:t.messages.slice(0,r),a=renderPendingApprovalsSnippet(t.requests),o=suspend(e.turn,{event:t.event,messages:t.messages.slice(i.length),requester:n,requests:t.requests,responseAuthRequiredRequestIds:t.responseAuthRequiredRequestIds,tasks:t.tasks});return{commit:[...i,...a===void 0?[]:[createFrameworkUserMessage(`context.state`,a)]],events:t.tasks.length>0?[]:[createInputRequestedEvent({requests:t.requests,...t.event})],turn:o}}function dispatch(e,t){let n=e.turn.suspended.map(e=>{let n=stepCallIds(e),r=t.tasks.filter(e=>n.has(e.callId));if(r.length===0)return e;let i=withoutApproved(e,new Set(r.map(e=>e.callId))),a={...e.approvers};for(let{callId:e}of r){let n=t.approvers[e];n!==void 0&&(a[e]=n)}return{...i,tasks:[...e.tasks,...r],...Object.keys(a).length>0&&{approvers:a}}});return{events:[],turn:{...e.turn,suspended:n}}}function deferInput(e,t){return{events:[],turn:withQueued(e.turn,t)}}function withQueued(e,t){return t===void 0||isEmptyInput(t)?e:{...e,queued:e.queued===void 0?t:coalesceTurnInputs(e.queued,t)}}function answer(e,t){let{policy:n}=t,{projection:r}=e,i=turnPosition(r),a=[...n.feedback.map(e=>createMessageCompletedEvent({message:e,sequence:i.sequence,stepIndex:i.stepIndex,turnId:i.turnId})),...reportApprovalProgress(r,n.audit,n.challengesAtStart)],o=t.takeQueued?{...e.turn,queued:void 0}:e.turn,done=e=>({events:a,resolved:[],turn:o,...e}),queue=e=>{o=withQueued(o,e)};if(n.kind===`park`)return done({next:`park`});if(n.kind===`continue-coordination`)return queue(n.stepInput),done({next:`repeat`});if(n.challenges.length>0)return done({next:`sign-in`});let s=t.delivery,c=openInputs(r).find(t=>t.request.kind===`session-limit`&&ownOpenRequestIds(e).has(t.request.requestId)),l=o.suspended.filter(e=>e.requests.length>0);if(c===void 0&&l.length===0)return done({input:s,next:`continue`});let u=c===void 0?s:resolveTextInput({requests:[c.request]},s),d=canonicalize(u?.inputResponses??[]),f=new Map(d.map(e=>[e.requestId,e])),p=l.filter(e=>e.requests.every(e=>f.has(e.requestId))),leftoverFor=e=>d.filter(t=>e.some(e=>e.requests.some(e=>e.requestId===t.requestId))),park=()=>(queue(compactInput(u)),done({next:`park`}));if(d.length===0&&u?.message===void 0)return park();if(c!==void 0){let e=f.get(c.request.requestId);if(e===void 0)return hasInput(s)?(queue(withoutTurnInput(u)),done({input:u,next:`defer-message`})):(queue(compactInput(u)),done({next:`park`}));let t={event:{sequence:c.sequence,stepIndex:c.stepIndex,turnId:c.turnId},inputs:[{outcome:resolveInputOutcome(c.request.kind,e),request:c.request,response:e}]};a.push(resolvedEvent(t));let n=leftoverFor(l);return n.length>0&&queue({inputResponses:n}),done({consumedMessage:u?.messageConsumed,input:withoutResponses(u),limit:resolveSessionLimitContinuation({requests:[c.request],responses:d}),next:`continue`,resolved:[t]})}if(p.length===0&&u?.message===void 0)return park();p.length===0&&p.push(l[0]);let m=leftoverFor(l.filter(e=>!p.includes(e)));m.length>0&&queue({inputResponses:m});let h=new Set(o.grants),g=[],_=[],v=o.suspended.map(e=>{if(!p.includes(e))return e;let n=e.messages,r=[];for(let i of e.requests){let{approved:a,reason:o,status:s}=resolveApprovalOutcome(f.get(i.requestId));if(a){h.add(t.approvalKey(i)??i.action.toolName),r.push(i);continue}n=withResult(n,{output:{reason:o,type:`execution-denied`},toolCallId:i.action.callId,toolName:i.action.toolName,type:`tool-result`}),_.push(createActionResultEvent({rejected:!0,result:{callId:i.action.callId,isError:!0,kind:`tool-result`,output:{approval:{requestId:i.requestId,status:s},code:`TOOL_EXECUTION_DENIED`,message:o??TOOL_EXECUTION_DENIED_MESSAGE,tool:{result:`not_run`}},toolName:i.action.toolName},...e.event}))}g.push({event:e.event,inputs:e.requests.map(e=>{let t=f.get(e.requestId);return{outcome:resolveInputOutcome(e.kind,t),request:e,response:t}})});let i=[...e.approved??[],...r];return{...e,messages:n,requests:[],...i.length>0&&{approved:i}}});return a.push(...g.map(resolvedEvent),..._),o={...o,grants:[...h],suspended:v},done({consumedMessage:u?.messageConsumed,input:withoutResponses(u),next:`continue`,resolved:g})}function resolvedEvent(e){return createInputResolvedEvent({resolutions:e.inputs.map(e=>{let t={kind:e.request.kind,outcome:e.outcome,requestId:e.request.requestId};return e.response===void 0?t:{...t,response:e.response}}),...e.event})}function reportApprovalProgress(e,t,n){let r=turnCoordinates(e),isOpen=t=>{let n=e.inputs[t];return n!==void 0&&n.status!==`settled`},i=[];for(let a of n){let n=t.candidateHistory.some(e=>e.candidateId===a.candidateId&&e.status===`timed-out`),o=e.authorizations[a.attemptId??a.name];n&&o?.status===`required`&&i.push(createAuthorizationCompletedEvent({...authorizationEventFields(a),outcome:`failed`,reason:`The approval response expired. Please submit a new response.`,...r}))}for(let n of t.activeCandidates)e.candidates[n.candidateId]===void 0&&isOpen(n.requestId)&&i.push(createApprovalCandidateEvent({candidateId:n.candidateId,outcome:`pending`,requestId:n.requestId,responderPrincipalId:n.responder.principalId,...r}));for(let n of t.candidateHistory)n.status!==`allowed`&&n.status!==`authorization-required`&&e.inputs[n.requestId]!==void 0&&e.candidates[n.candidateId]?.outcome!==n.status&&i.push(createApprovalCandidateEvent({candidateId:n.candidateId,outcome:n.status,requestId:n.requestId,responderPrincipalId:n.responder.principalId,reason:n.reason,...r}));for(let e of t.settlements)isOpen(e.requestId)&&i.push(createApprovalSettledEvent({outcome:e.outcome===`allowed`?`approved`:`cancelled`,requestId:e.requestId,responderPrincipalId:e.actor.principalId,...r}));return i}function hasRunnableQueue(e){let t=e.turn.queued;if(t===void 0)return!1;if(t.message!==void 0||(t.context?.length??0)>0||readClientContext(t)!==void 0||t.outputSchema!==void 0||(t.runtimeActionResults?.length??0)>0)return!0;let n=[...t.inputResponses??[],...(t.attributedInputResponses??[]).map(({response:e})=>e)];if(n.length===0)return!1;let r=new Set(n.map(e=>e.requestId)),i=openInputs(e.projection).find(e=>e.request.kind===`session-limit`);return i===void 0?e.turn.suspended.some(e=>e.requests.length>0&&e.requests.every(e=>r.has(e.requestId))):r.has(i.request.requestId)}function grantedApprovalKeys(e,t){let n=new Set(e.turn.grants);for(let r of e.turn.suspended)for(let e of r.requests)isApprovalRequest(e)&&n.delete(t(e)??e.action.toolName);return n}function approvingSteps(e,t){let n=e.turn.suspended.filter(e=>e.requests.length>0),r=new Map((t?.inputResponses??[]).map(e=>[e.requestId,e.optionId]));return n.filter(e=>e.requests.every(e=>r.has(e.requestId))&&e.requests.some(e=>isApprovalRequest(e)&&r.get(e.requestId)===`approve`))}function stepForRequest(e,t){return e.turn.suspended.find(e=>e.requests.some(e=>e.requestId===t))}function withdrawSignIns(e,t){return{events:e.signIns.flatMap(n=>{let r=e.projection.authorizations[n.attemptId??n.name];return r?.status===`required`?[signInWithdrawn(r,t)]:[]}),signIns:[],turn:e.turn}}function requestLimit(e,t){let n=turnPosition(e.projection);return{events:[createInputRequestedEvent({requests:[t.request],sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId}),...finishTurn(e).events],turn:e.turn}}function requireSignIn(e,t){let n=turnPosition(e.projection),r={sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId},i=[...supersededChallenges(e.signIns,t.challenges).map(e=>createAuthorizationCompletedEvent({...authorizationEventFields(e),outcome:`failed`,reason:`Superseded by a newer authorization attempt.`,...r})),...t.challenges.map(e=>createAuthorizationRequiredEvent({...authorizationEventFields(e),description:e.challenge.instructions??`Authorization required for ${e.name}`,webhookUrl:e.hookUrl,...r}))];i.push(...hold(e,{on:`input`}).events);let a=t.queued===void 0?e.turn.queued:e.turn.queued===void 0?t.queued:coalesceTurnInputs(e.turn.queued,t.queued),o=withSignIns(e.signIns,t.challenges),s=new Set([...t.callIdsByName?.values()??[]].flat()),c=e.turn.suspended.map(e=>[...stepCallIds(e)].some(e=>s.has(e))?{...e,messages:withoutCalls(e.messages,s)}:e);if(c.every((t,n)=>t===e.turn.suspended[n]))return{events:i,signIns:o,turn:{...e.turn,queued:a}};let l=settle({...e,turn:{...e.turn,queued:a,suspended:c}},{results:[]});return{commit:l.commit,events:i,signIns:o,turn:l.turn}}export{answer,approvingSteps,deferInput,dispatch,grantedApprovalKeys,hasRunnableQueue,parkOnApprovals,requestLimit,requireSignIn,stepForRequest,withdrawSignIns};
1
+ import{canonicalize,compactInput,hasInput,isEmptyInput,resolveTextInput,withoutResponses,withoutTurnInput}from"./delivery.js";import{openInputs,turnCoordinates}from"#protocol/session-projection.js";import{readClientContext}from"#internal/client-context.js";import{createActionResultEvent,createApprovalCandidateEvent,createApprovalSettledEvent,createAuthorizationCompletedEvent,createAuthorizationRequiredEvent,createInputRequestedEvent,createInputResolvedEvent,createMessageCompletedEvent}from"#protocol/message.js";import{coalesceTurnInputs,createFrameworkUserMessage}from"#harness/messages.js";import{turnPosition}from"#harness/session-machine/view.js";import{renderPendingApprovalsSnippet}from"#harness/hitl/approval-prompt.js";import{supersededChallenges,withSignIns}from"#harness/authorization.js";import{finishTurn,hold,ownOpenRequestIds,settle,stepCallIds,suspend,withResult,withoutApproved}from"#harness/session-machine/transitions.js";import{withoutCalls}from"#harness/inline-tool-authorization.js";import{isApprovalRequest}from"#harness/input-request-class.js";import{authorizationEventFields}from"#harness/authorization-event-fields.js";import{TOOL_EXECUTION_DENIED_MESSAGE,failedCall,resolveApprovalOutcome,resolveInputOutcome,unavailableToolMessage}from"#harness/input-request-resolution.js";import{resolveSessionLimitContinuation}from"#harness/hitl/budget-request.js";import{signInWithdrawn}from"#harness/session-machine/events.js";function parkOnApprovals(e,t){let n=t.requester?.principalType===`anonymous`?null:t.requester,r=t.messages.findIndex(e=>e.role!==`tool`),i=r===-1?t.messages:t.messages.slice(0,r),a=renderPendingApprovalsSnippet(t.requests),o=suspend(e.turn,{event:t.event,messages:t.messages.slice(i.length),requester:n,requests:t.requests,responseAuthRequiredRequestIds:t.responseAuthRequiredRequestIds,tasks:t.tasks});return{commit:[...i,...a===void 0?[]:[createFrameworkUserMessage(`context.state`,a)]],events:t.tasks.length>0?[]:[createInputRequestedEvent({requests:t.requests,...t.event})],turn:o}}function dispatch(e,t){let n=e.turn.suspended.map(e=>{let n=stepCallIds(e),r=t.tasks.filter(e=>n.has(e.callId));if(r.length===0)return e;let i=withoutApproved(e,new Set(r.map(e=>e.callId))),a={...e.approvers};for(let{callId:e}of r){let n=t.approvers[e];n!==void 0&&(a[e]=n)}return{...i,tasks:[...e.tasks,...r],...Object.keys(a).length>0&&{approvers:a}}});return{events:[],turn:{...e.turn,suspended:n}}}function deferInput(e,t){return{events:[],turn:withQueued(e.turn,t)}}function withQueued(e,t){return t===void 0||isEmptyInput(t)?e:{...e,queued:e.queued===void 0?t:coalesceTurnInputs(e.queued,t)}}function answer(e,t){let{policy:n}=t,{projection:r}=e,i=turnPosition(r),a=[...n.feedback.map(e=>createMessageCompletedEvent({message:e,sequence:i.sequence,stepIndex:i.stepIndex,turnId:i.turnId})),...reportApprovalProgress(r,n.audit,n.challengesAtStart)],o=t.takeQueued?{...e.turn,queued:void 0}:e.turn,done=e=>({events:a,resolved:[],turn:o,...e}),queue=e=>{o=withQueued(o,e)};if(n.kind===`park`)return done({next:`park`});if(n.kind===`continue-coordination`)return queue(n.stepInput),done({next:`repeat`});if(n.challenges.length>0)return done({next:`sign-in`});let s=t.delivery,c=openInputs(r).find(t=>t.request.kind===`session-limit`&&ownOpenRequestIds(e).has(t.request.requestId)),l=o.suspended.filter(e=>e.requests.length>0);if(c===void 0&&l.length===0)return done({input:s,next:`continue`});let u=c===void 0?s:resolveTextInput({requests:[c.request]},s),d=canonicalize(u?.inputResponses??[]),f=new Map(d.map(e=>[e.requestId,e])),p=l.filter(e=>e.requests.every(e=>f.has(e.requestId))),leftoverFor=e=>d.filter(t=>e.some(e=>e.requests.some(e=>e.requestId===t.requestId))),park=()=>(queue(compactInput(u)),done({next:`park`}));if(d.length===0&&u?.message===void 0)return park();if(c!==void 0){let e=f.get(c.request.requestId);if(e===void 0)return hasInput(s)?(queue(withoutTurnInput(u)),done({input:u,next:`defer-message`})):(queue(compactInput(u)),done({next:`park`}));let t={event:{sequence:c.sequence,stepIndex:c.stepIndex,turnId:c.turnId},inputs:[{outcome:resolveInputOutcome(c.request.kind,e),request:c.request,response:e}]};a.push(resolvedEvent(t));let n=leftoverFor(l);return n.length>0&&queue({inputResponses:n}),done({consumedMessage:u?.messageConsumed,input:withoutResponses(u),limit:resolveSessionLimitContinuation({requests:[c.request],responses:d}),next:`continue`,resolved:[t]})}if(p.length===0&&u?.message===void 0)return park();p.length===0&&p.push(l[0]);let m=leftoverFor(l.filter(e=>!p.includes(e)));m.length>0&&queue({inputResponses:m});let h=new Set(o.grants),g=[],_=[],v=new Set(n.audit.settlements.filter(e=>e.outcome===`unavailable`).map(e=>e.requestId)),y=o.suspended.map(e=>{if(!p.includes(e))return e;let n=e.messages,r=[];for(let i of e.requests){let{callId:a,toolName:o}=i.action;if(v.has(i.requestId)){let r=failedCall({callId:a,message:unavailableToolMessage(o,t.searchable(i)),toolName:o});n=withResult(n,r.part),_.push(createActionResultEvent({result:r.result,...e.event}));continue}let{approved:s,reason:c,status:l}=resolveApprovalOutcome(f.get(i.requestId));if(s){h.add(t.approvalKey(i)??o),r.push(i);continue}n=withResult(n,{output:{reason:c,type:`execution-denied`},toolCallId:a,toolName:o,type:`tool-result`}),_.push(createActionResultEvent({rejected:!0,result:{callId:a,isError:!0,kind:`tool-result`,output:{approval:{requestId:i.requestId,status:l},code:`TOOL_EXECUTION_DENIED`,message:c??TOOL_EXECUTION_DENIED_MESSAGE,tool:{result:`not_run`}},toolName:o},...e.event}))}g.push({event:e.event,inputs:e.requests.map(e=>{let t=f.get(e.requestId);return{outcome:resolveInputOutcome(e.kind,t),request:e,response:t}})});let i=[...e.approved??[],...r];return{...e,messages:n,requests:[],...i.length>0&&{approved:i}}});return a.push(...g.map(resolvedEvent),..._),o={...o,grants:[...h],suspended:y},done({consumedMessage:u?.messageConsumed,input:withoutResponses(u),next:`continue`,resolved:g})}function resolvedEvent(e){return createInputResolvedEvent({resolutions:e.inputs.map(e=>{let t={kind:e.request.kind,outcome:e.outcome,requestId:e.request.requestId};return e.response===void 0?t:{...t,response:e.response}}),...e.event})}function reportApprovalProgress(e,t,n){let r=turnCoordinates(e),isOpen=t=>{let n=e.inputs[t];return n!==void 0&&n.status!==`settled`},i=[];for(let a of n){let n=t.candidateHistory.some(e=>e.candidateId===a.candidateId&&e.status===`timed-out`),o=e.authorizations[a.attemptId??a.name];n&&o?.status===`required`&&i.push(createAuthorizationCompletedEvent({...authorizationEventFields(a),outcome:`failed`,reason:`The approval response expired. Please submit a new response.`,...r}))}for(let n of t.activeCandidates)e.candidates[n.candidateId]===void 0&&isOpen(n.requestId)&&i.push(createApprovalCandidateEvent({candidateId:n.candidateId,outcome:`pending`,requestId:n.requestId,responderPrincipalId:n.responder.principalId,...r}));for(let n of t.candidateHistory)n.status!==`allowed`&&n.status!==`authorization-required`&&e.inputs[n.requestId]!==void 0&&e.candidates[n.candidateId]?.outcome!==n.status&&i.push(createApprovalCandidateEvent({candidateId:n.candidateId,outcome:n.status,requestId:n.requestId,responderPrincipalId:n.responder.principalId,reason:n.reason,...r}));for(let e of t.settlements)isOpen(e.requestId)&&e.outcome!==`unavailable`&&i.push(createApprovalSettledEvent({outcome:e.outcome===`allowed`?`approved`:`cancelled`,requestId:e.requestId,responderPrincipalId:e.actor.principalId,...r}));return i}function hasRunnableQueue(e){let t=e.turn.queued;if(t===void 0)return!1;if(t.message!==void 0||(t.context?.length??0)>0||readClientContext(t)!==void 0||t.outputSchema!==void 0||(t.runtimeActionResults?.length??0)>0)return!0;let n=[...t.inputResponses??[],...(t.attributedInputResponses??[]).map(({response:e})=>e)];if(n.length===0)return!1;let r=new Set(n.map(e=>e.requestId)),i=openInputs(e.projection).find(e=>e.request.kind===`session-limit`);return i===void 0?e.turn.suspended.some(e=>e.requests.length>0&&e.requests.every(e=>r.has(e.requestId))):r.has(i.request.requestId)}function grantedApprovalKeys(e,t){let n=new Set(e.turn.grants);for(let r of e.turn.suspended)for(let e of r.requests)isApprovalRequest(e)&&n.delete(t(e)??e.action.toolName);return n}function approvingSteps(e,t){let n=e.turn.suspended.filter(e=>e.requests.length>0),r=new Map((t?.inputResponses??[]).map(e=>[e.requestId,e.optionId]));return n.filter(e=>e.requests.every(e=>r.has(e.requestId))&&e.requests.some(e=>isApprovalRequest(e)&&r.get(e.requestId)===`approve`))}function stepForRequest(e,t){return e.turn.suspended.find(e=>e.requests.some(e=>e.requestId===t))}function withdrawSignIns(e,t){return{events:e.signIns.flatMap(n=>{let r=e.projection.authorizations[n.attemptId??n.name];return r?.status===`required`?[signInWithdrawn(r,t)]:[]}),signIns:[],turn:e.turn}}function requestLimit(e,t){let n=turnPosition(e.projection);return{events:[createInputRequestedEvent({requests:[t.request],sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId}),...finishTurn(e).events],turn:e.turn}}function requireSignIn(e,t){let n=turnPosition(e.projection),r={sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId},i=[...supersededChallenges(e.signIns,t.challenges).map(e=>createAuthorizationCompletedEvent({...authorizationEventFields(e),outcome:`failed`,reason:`Superseded by a newer authorization attempt.`,...r})),...t.challenges.map(e=>createAuthorizationRequiredEvent({...authorizationEventFields(e),description:e.challenge.instructions??`Authorization required for ${e.name}`,webhookUrl:e.hookUrl,...r}))];i.push(...hold(e,{on:`input`}).events);let a=t.queued===void 0?e.turn.queued:e.turn.queued===void 0?t.queued:coalesceTurnInputs(e.turn.queued,t.queued),o=withSignIns(e.signIns,t.challenges),s=new Set([...t.callIdsByName?.values()??[]].flat()),c=e.turn.suspended.map(e=>[...stepCallIds(e)].some(e=>s.has(e))?{...e,messages:withoutCalls(e.messages,s)}:e);if(c.every((t,n)=>t===e.turn.suspended[n]))return{events:i,signIns:o,turn:{...e.turn,queued:a}};let l=settle({...e,turn:{...e.turn,queued:a,suspended:c}},{results:[]});return{commit:l.commit,events:i,signIns:o,turn:l.turn}}export{answer,approvingSteps,deferInput,dispatch,grantedApprovalKeys,hasRunnableQueue,parkOnApprovals,requestLimit,requireSignIn,stepForRequest,withdrawSignIns};
@@ -1,5 +1,5 @@
1
1
  import { type ModelMessage, type TelemetryOptions, type ToolSet, type TypedToolResult } from "ai";
2
- import type { HarnessToolMap } from "#harness/types.js";
2
+ import type { HarnessToolLookup } from "#harness/types.js";
3
3
  import type { InputRequest } from "#shared/input.js";
4
4
  import type { HandleEventFn } from "#harness/types.js";
5
5
  type ToolResponsePart = Extract<ModelMessage, {
@@ -19,7 +19,8 @@ export declare const APPROVED_CALL_INTERRUPTED_MESSAGE = "The turn was cancelled
19
19
  */
20
20
  export declare function runApprovedCalls(input: {
21
21
  readonly requests: readonly InputRequest[];
22
- readonly tools: HarnessToolMap;
22
+ /** The entries of the step that asked, which the approved calls run. */
23
+ readonly tools: HarnessToolLookup;
23
24
  readonly approvedTools?: ReadonlySet<string>;
24
25
  /** The conversation the tools read as `ctx.messages`. */
25
26
  readonly messages: readonly ModelMessage[];
@@ -1 +1 @@
1
- import{asSchema}from"ai";import{createLogger,logError}from"#internal/logging.js";import{toError}from"#shared/errors.js";import{createActionPartialEvent,createActionResultEvent}from"#protocol/message.js";import{parseJsonObject}from"#shared/json.js";import{isAsyncIterable}from"#shared/async-iterable.js";import{throwIfTurnAborted}from"#harness/turn-cancellation.js";import{createRuntimeToolResultFromValue}from"#harness/action-result-helpers.js";import{emitNestedToolActions}from"#harness/nested-actions.js";import{projectDeltaPresentation,projectResultPresentation}from"#harness/tool-presentation.js";import{isInlineAuthorizationToolResult}from"#harness/inline-tool-authorization.js";import{TOOL_EXECUTION_DENIED_MESSAGE}from"#harness/input-request-resolution.js";import{buildToolSet,recheckApprovedCall}from"#harness/tools.js";const log=createLogger(`harness.tool-loop`),APPROVED_CALL_INTERRUPTED_MESSAGE=`The turn was cancelled while this approved tool call was running. It may have partially run; it was not retried.`;async function runApprovedCalls(e){let t=buildToolSet({tools:e.tools,approvedTools:e.approvedTools}),n=e.requests.map(n=>{let r=e.tools.get(n.action.toolName),i=t[n.action.toolName];if(r?.execute===void 0||i?.execute===void 0||i.toModelOutput===void 0)throw Error(`The approved tool is no longer available. Request a new tool call and approval.`);return{request:n,definition:r,tool:i}}),r={sequence:e.position.sequence,stepIndex:e.position.stepIndex,turnId:e.position.turnId},i=await Promise.allSettled(n.map(async({request:t,definition:n,tool:i})=>{let a=[],o=[],{callId:s,toolName:c,input:l}=t.action,u=!1,d;try{if(throwIfTurnAborted(e.abortSignal),(await asSchema(i.inputSchema).validate?.(l))?.success===!1){let t=`The approved input is no longer valid for tool "${c}". Request a new tool call and approval.`;return await e.publish(createActionResultEvent({...r,result:createRuntimeToolResultFromValue({callId:s,isError:!0,output:t,toolName:c})})),{settled:[{part:{type:`tool-result`,toolCallId:s,toolName:c,output:{type:`error-text`,value:t}}}],toolResults:o}}let t=await recheckApprovedCall(n,{abortSignal:e.abortSignal,callId:s,input:l,approvedTools:e.approvedTools});if(t.denied)return await e.publish(createActionResultEvent({...r,rejected:!0,result:{callId:s,isError:!0,kind:`tool-result`,output:{code:`TOOL_EXECUTION_DENIED`,message:t.reason??TOOL_EXECUTION_DENIED_MESSAGE,tool:{result:`not_run`}},toolName:c}})),a.push({part:{output:{reason:t.reason,type:`execution-denied`},toolCallId:s,toolName:c,type:`tool-result`}}),{settled:a,toolResults:o};let f,p=!1,m=toolTelemetry(e.telemetry,{messages:[...e.messages],toolCall:{input:l,toolCallId:s,toolName:c,type:`tool-call`}});await m.started();let h=0;try{await m.execute(async()=>{let t=performance.now();try{u=!0;let t=i.execute(l,{abortSignal:e.abortSignal,context:void 0,messages:[...e.messages],toolCallId:s});if(isAsyncIterable(t))for await(let i of t)f=i,await e.publish(createActionPartialEvent({...r,presentation:projectDeltaPresentation(n,s,parseJsonObject(l),i),result:createRuntimeToolResultFromValue({callId:s,output:i,toolName:c})}));else f=await t}finally{h=performance.now()-t}})}catch(t){await m.ended({error:t,input:l,toolCallId:s,toolName:c,type:`tool-error`},h),throwIfTurnAborted(e.abortSignal),logError(log,`tool execution failed`,t,{toolName:c,toolCallId:s}),p=!0,f=toError(t).message}p||await m.ended({input:l,output:f,toolCallId:s,toolName:c,type:`tool-result`},h);let g={input:l,output:f,toolCallId:s,toolName:c,type:`tool-result`};return o.push(g),isInlineAuthorizationToolResult(g)?{settled:a,toolResults:o}:(await emitNestedToolActions(e.publish,e.position,s),d={part:{output:p?{type:`error-text`,value:String(f)}:await i.toModelOutput({input:l,output:f,toolCallId:s}),toolCallId:s,toolName:c,type:`tool-result`}},a.push(d),await e.publish(createActionResultEvent({...r,presentation:p?void 0:projectResultPresentation(n,s,parseJsonObject(l),f),result:createRuntimeToolResultFromValue({callId:s,isError:p,output:f,toolName:c})})),{settled:a,toolResults:o})}catch(t){if(e.abortSignal?.aborted===!0)return u||throwIfTurnAborted(e.abortSignal),d===void 0?{settled:[interruptedResult(s,c)],toolResults:o}:{settled:[d],toolResults:o};let n=toError(t).message;return logError(log,`approved tool failed`,t,{toolName:c,toolCallId:s}),await e.publish(createActionResultEvent({...r,result:createRuntimeToolResultFromValue({callId:s,isError:!0,output:n,toolName:c})})),{settled:[{part:{type:`tool-result`,toolCallId:s,toolName:c,output:{type:`error-text`,value:n}}}],toolResults:o}}})),a=i.find(e=>e.status===`rejected`);if(a?.status===`rejected`&&e.abortSignal?.aborted!==!0)throw a.reason;let o=i.flatMap(e=>e.status===`fulfilled`?[e.value]:[]);return{settled:o.flatMap(e=>e.settled),toolResults:o.flatMap(e=>e.toolResults)}}function interruptedResult(e,t){return{part:{output:{type:`error-text`,value:APPROVED_CALL_INTERRUPTED_MESSAGE},toolCallId:e,toolName:t,type:`tool-result`}}}function toolTelemetry(e,t){let n=e===void 0||e.isEnabled===!1?[]:[e.integrations??[]].flat(),r={...t,callId:`approved:${t.toolCall.toolCallId}`,functionId:e?.functionId,recordInputs:e?.recordInputs,recordOutputs:e?.recordOutputs,toolContext:void 0},notify=async e=>{await Promise.allSettled(n.map(async t=>await e(t)))};return{started:()=>notify(e=>e.onToolExecutionStart?.(r)),execute:async e=>{let wrapped=e;for(let e of n){if(e.executeTool===void 0)continue;let n=wrapped;wrapped=()=>e.executeTool({...r,execute:n,toolCallId:t.toolCall.toolCallId})}await wrapped()},ended:(e,t)=>notify(n=>n.onToolExecutionEnd?.({...r,toolExecutionMs:t,toolOutput:e}))}}export{APPROVED_CALL_INTERRUPTED_MESSAGE,runApprovedCalls};
1
+ import{asSchema}from"ai";import{createLogger,logError}from"#internal/logging.js";import{toError}from"#shared/errors.js";import{createActionPartialEvent,createActionResultEvent}from"#protocol/message.js";import{SEARCH_TOOL_NAME}from"#protocol/catalog-tools.js";import{toModelSchema}from"#tools/schema.js";import{parseJsonObject}from"#shared/json.js";import{toolCallModelOutput}from"#harness/tool-call-io.js";import{isAsyncIterable}from"#shared/async-iterable.js";import{throwIfTurnAborted}from"#harness/turn-cancellation.js";import{createRuntimeToolResultFromValue}from"#harness/action-result-helpers.js";import{projectDeltaPresentation,projectResultPresentation}from"#harness/tool-presentation.js";import{isInlineAuthorizationToolResult}from"#harness/inline-tool-authorization.js";import{TOOL_EXECUTION_DENIED_MESSAGE,failedCall,unavailableToolMessage}from"#harness/input-request-resolution.js";import{recheckApprovedCall,wrapToolExecute}from"#harness/tools.js";const log=createLogger(`harness.tool-loop`),APPROVED_CALL_INTERRUPTED_MESSAGE=`The turn was cancelled while this approved tool call was running. It may have partially run; it was not retried.`;async function runApprovedCalls(e){let t={sequence:e.position.sequence,stepIndex:e.position.stepIndex,turnId:e.position.turnId},settleFailure=async(n,r,i)=>{let a=failedCall({callId:n,message:i,toolName:r});return await e.publish(createActionResultEvent({...t,result:a.result})),{part:a.part}},n=await Promise.allSettled(e.requests.map(async n=>{let r=[],i=[],{callId:a,toolName:o,input:s}=n.action,c=e.tools.get(o),l=c===void 0?void 0:wrapToolExecute(c),u=!1,d;try{if(throwIfTurnAborted(e.abortSignal),c===void 0||l===void 0)return{settled:[await settleFailure(a,o,unavailableToolMessage(o,e.tools.get(SEARCH_TOOL_NAME)!==void 0))],toolResults:i};if((await asSchema(toModelSchema(c.inputSchema,`input`)).validate?.(s))?.success===!1){let e=`The approved input is no longer valid for tool "${o}". Request a new tool call and approval.`;return{settled:[await settleFailure(a,o,e)],toolResults:i}}let n=await recheckApprovedCall(c,{abortSignal:e.abortSignal,callId:a,input:s,approvedTools:e.approvedTools});if(n.denied)return await e.publish(createActionResultEvent({...t,rejected:!0,result:{callId:a,isError:!0,kind:`tool-result`,output:{code:`TOOL_EXECUTION_DENIED`,message:n.reason??TOOL_EXECUTION_DENIED_MESSAGE,tool:{result:`not_run`}},toolName:o}})),r.push({part:{output:{reason:n.reason,type:`execution-denied`},toolCallId:a,toolName:o,type:`tool-result`}}),{settled:r,toolResults:i};let f,p=!1,m=toolTelemetry(e.telemetry,{messages:[...e.messages],toolCall:{input:s,toolCallId:a,toolName:o,type:`tool-call`}});await m.started();let h=0;try{await m.execute(async()=>{let n=performance.now();try{u=!0;let n=l(s,{abortSignal:e.abortSignal,messages:[...e.messages],toolCallId:a});if(isAsyncIterable(n))for await(let r of n)f=r,await e.publish(createActionPartialEvent({...t,presentation:projectDeltaPresentation(c,a,parseJsonObject(s),r),result:createRuntimeToolResultFromValue({callId:a,output:r,toolName:o})}));else f=await n}finally{h=performance.now()-n}})}catch(t){await m.ended({error:t,input:s,toolCallId:a,toolName:o,type:`tool-error`},h),throwIfTurnAborted(e.abortSignal),logError(log,`tool execution failed`,t,{toolName:o,toolCallId:a}),p=!0,f=toError(t).message}p||await m.ended({input:s,output:f,toolCallId:a,toolName:o,type:`tool-result`},h);let g={input:s,output:f,toolCallId:a,toolName:o,type:`tool-result`};return i.push(g),isInlineAuthorizationToolResult(g)?{settled:r,toolResults:i}:(d={part:{output:p?{type:`error-text`,value:String(f)}:await toolCallModelOutput(c,f,a),toolCallId:a,toolName:o,type:`tool-result`}},r.push(d),await e.publish(createActionResultEvent({...t,presentation:p?void 0:projectResultPresentation(c,a,parseJsonObject(s),f),result:createRuntimeToolResultFromValue({callId:a,isError:p,output:f,toolName:o})})),{settled:r,toolResults:i})}catch(t){return e.abortSignal?.aborted===!0?(u||throwIfTurnAborted(e.abortSignal),d===void 0?{settled:[interruptedResult(a,o)],toolResults:i}:{settled:[d],toolResults:i}):(logError(log,`approved tool failed`,t,{toolName:o,toolCallId:a}),{settled:[await settleFailure(a,o,toError(t).message)],toolResults:i})}})),r=n.find(e=>e.status===`rejected`);if(r?.status===`rejected`&&e.abortSignal?.aborted!==!0)throw r.reason;let i=n.flatMap(e=>e.status===`fulfilled`?[e.value]:[]);return{settled:i.flatMap(e=>e.settled),toolResults:i.flatMap(e=>e.toolResults)}}function interruptedResult(e,t){return{part:{output:{type:`error-text`,value:APPROVED_CALL_INTERRUPTED_MESSAGE},toolCallId:e,toolName:t,type:`tool-result`}}}function toolTelemetry(e,t){let n=e===void 0||e.isEnabled===!1?[]:[e.integrations??[]].flat(),r={...t,callId:`approved:${t.toolCall.toolCallId}`,functionId:e?.functionId,recordInputs:e?.recordInputs,recordOutputs:e?.recordOutputs,toolContext:void 0},notify=async e=>{await Promise.allSettled(n.map(async t=>await e(t)))};return{started:()=>notify(e=>e.onToolExecutionStart?.(r)),execute:async e=>{let wrapped=e;for(let e of n){if(e.executeTool===void 0)continue;let n=wrapped;wrapped=()=>e.executeTool({...r,execute:n,toolCallId:t.toolCall.toolCallId})}await wrapped()},ended:(e,t)=>notify(n=>n.onToolExecutionEnd?.({...r,toolExecutionMs:t,toolOutput:e}))}}export{APPROVED_CALL_INTERRUPTED_MESSAGE,runApprovedCalls};
@@ -23,9 +23,10 @@ export interface ApprovalResponderIdentity {
23
23
  }
24
24
  export interface ApprovalSettlementAuditRecord {
25
25
  readonly actor: ApprovalResponderIdentity;
26
- /** The approver's full auth, which the approved call runs as. Absent for cancellations. */
26
+ /** The approver's full auth, which the approved call runs as. Present only when allowed. */
27
27
  readonly approver?: SessionAuthContext;
28
- readonly outcome: "allowed" | "cancelled";
28
+ /** `unavailable`: the request's entry was gone, so its call is reported unavailable, never run. */
29
+ readonly outcome: "allowed" | "cancelled" | "unavailable";
29
30
  readonly requestId: string;
30
31
  readonly settledAt: number;
31
32
  readonly candidateId?: string;
@@ -83,6 +84,16 @@ export declare function settleAllowedCandidate(input: {
83
84
  readonly settledAt: number;
84
85
  readonly state: SessionStateMap | undefined;
85
86
  }): ApprovalStateTransition;
87
+ /**
88
+ * Settles a request whose entry is gone, which no response can approve and no call can run: the
89
+ * candidate fails with `reason`, its competitors go stale, and the call is reported unavailable.
90
+ */
91
+ export declare function settleUnavailableCandidate(input: {
92
+ readonly candidateId: string;
93
+ readonly reason: string;
94
+ readonly settledAt: number;
95
+ readonly state: SessionStateMap | undefined;
96
+ }): ApprovalStateTransition;
86
97
  /** Atomically settles a direct authenticated approval response. */
87
98
  export declare function settleDirectApprovalResponse(input: {
88
99
  readonly actor: SessionAuthContext;
@@ -1 +1 @@
1
- const APPROVAL_STATE_KEY=`eve.runtime.hitl.approvalState`;function createApprovalCandidate(e){let t=expireApprovalCandidates({now:e.createdAt,state:e.state}),n=readApprovalState(t);if(n.settlements[e.requestId]!==void 0)return{changed:!1,state:t};let r=e.responder;if(Object.values(n.activeCandidates).find(t=>t.requestId===e.requestId&&t.decision===e.decision&&sameResponder(t.responder,r))!==void 0)return{changed:!1,state:t};let i=n.activeCandidates[e.candidateIdPrefix]!==void 0||n.candidateHistory.some(t=>t.candidateId===e.candidateIdPrefix)?`${e.candidateIdPrefix}.${n.nextCandidateSequence.toString(36)}`:e.candidateIdPrefix;if(n.activeCandidates[i]!==void 0||n.candidateHistory.some(e=>e.candidateId===i))throw Error(`Approval candidate id collision: "${i}".`);let a={candidateId:i,createdAt:e.createdAt,decision:e.decision,expiresAt:e.expiresAt,requestId:e.requestId,responder:r,status:`pending`};return{changed:!0,state:writeApprovalState(t,{...n,activeCandidates:{...n.activeCandidates,[a.candidateId]:a},nextCandidateSequence:n.nextCandidateSequence+1})}}function markApprovalCandidateAuthorizationRequired(e){let t=readApprovalState(e.state),n=t.activeCandidates[e.candidateId];if(n===void 0)return e.state;let r={...n,authorizationChallenges:e.authorizationChallenges,expiresAt:e.expiresAt??n.expiresAt,status:`authorization-required`};return writeApprovalState(e.state,{...t,activeCandidates:{...t.activeCandidates,[e.candidateId]:r}})}function finishApprovalCandidate(e){let t=readApprovalState(e.state),n=t.activeCandidates[e.candidateId];if(n===void 0)return e.state;let r={...t.activeCandidates};return delete r[e.candidateId],writeApprovalState(e.state,{...t,activeCandidates:r,candidateHistory:[...t.candidateHistory,toCandidateAuditRecord({candidate:n,completedAt:e.completedAt,reason:e.reason,status:e.status})]})}function expireApprovalCandidates(e){let t=e.state,n=Object.values(readApprovalState(t).activeCandidates);for(let r of n)r.expiresAt>e.now||(t=finishApprovalCandidate({candidateId:r.candidateId,completedAt:e.now,state:t,status:`timed-out`}));return t}function settleAllowedCandidate(e){let t=expireApprovalCandidates({now:e.settledAt,state:e.state}),n=readApprovalState(t),r=n.activeCandidates[e.candidateId];if(r===void 0){let r=n.candidateHistory.find(t=>t.candidateId===e.candidateId);if((r&&n.settlements[r.requestId])!==void 0)return{changed:!1,state:t};throw Error(`Unknown approval candidate "${e.candidateId}".`)}return settleRequest({candidateId:r.candidateId,outcome:r.decision===`cancel`?`cancelled`:`allowed`,requestId:r.requestId,responder:r.responder,settledAt:e.settledAt,state:t})}function settleDirectApprovalResponse(e){let t=expireApprovalCandidates({now:e.settledAt,state:e.state});return settleRequest({outcome:e.outcome,requestId:e.requestId,responder:e.actor,settledAt:e.settledAt,state:t})}function getActiveApprovalCandidate(e,t){return readApprovalState(e).activeCandidates[t]}function getApprovalAuditState(e){let t=readApprovalState(e);return{activeCandidates:Object.values(t.activeCandidates),candidateHistory:t.candidateHistory,settlements:Object.values(t.settlements)}}function settleRequest(e){let t=readApprovalState(e.state);if(t.settlements[e.requestId]!==void 0)return{changed:!1,state:e.state};let n={actor:projectResponder(e.responder),...e.outcome===`allowed`&&{approver:e.responder},candidateId:e.candidateId,outcome:e.outcome,requestId:e.requestId,settledAt:e.settledAt},r={},i=[...t.candidateHistory];for(let n of Object.values(t.activeCandidates)){if(n.requestId!==e.requestId){r[n.candidateId]=n;continue}i.push(toCandidateAuditRecord({candidate:n,completedAt:e.settledAt,status:n.candidateId===e.candidateId?`allowed`:`stale`}))}let a={activeCandidates:r,candidateHistory:i,nextCandidateSequence:t.nextCandidateSequence,settlements:{...t.settlements,[e.requestId]:n}};return{changed:!0,state:writeApprovalState(e.state,a)}}function toCandidateAuditRecord(e){let{authorizationChallenges:t,responder:n,...r}=e.candidate;return{...r,completedAt:e.completedAt,responder:projectResponder(n),reason:e.reason,status:e.status}}function projectResponder(e){return{authenticator:e.authenticator,issuer:e.issuer,principalId:e.principalId,principalType:e.principalType}}function sameResponder(e,t){return e.authenticator===t.authenticator&&e.issuer===t.issuer&&e.principalId===t.principalId&&e.principalType===t.principalType}function readActiveCandidates(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t,decision:t.decision===`cancel`?`cancel`:`approve`}]))}function readApprovalState(e){let t=e?.[APPROVAL_STATE_KEY];if(typeof t!=`object`||!t)return{activeCandidates:{},candidateHistory:[],nextCandidateSequence:0,settlements:{}};let n=t;return{activeCandidates:typeof n.activeCandidates==`object`&&n.activeCandidates!==null?readActiveCandidates(n.activeCandidates):{},candidateHistory:Array.isArray(n.candidateHistory)?n.candidateHistory:[],nextCandidateSequence:typeof n.nextCandidateSequence==`number`&&Number.isSafeInteger(n.nextCandidateSequence)&&n.nextCandidateSequence>=0?n.nextCandidateSequence:deriveNextCandidateSequence(n),settlements:typeof n.settlements==`object`&&n.settlements!==null?n.settlements:{}}}function deriveNextCandidateSequence(e){return Object.keys(e.activeCandidates??{}).length+(Array.isArray(e.candidateHistory)?e.candidateHistory.length:0)}function writeApprovalState(e,t){return{...e,[APPROVAL_STATE_KEY]:t}}function retireActiveCandidates(e,t){let n=e;for(let e of getApprovalAuditState(n).activeCandidates)n=finishApprovalCandidate({candidateId:e.candidateId,completedAt:t.completedAt,reason:t.reason,state:n,status:`stale`});return n}function approverOfRequest(e,t){return readApprovalState(e).settlements[t]?.approver}export{approverOfRequest,createApprovalCandidate,expireApprovalCandidates,finishApprovalCandidate,getActiveApprovalCandidate,getApprovalAuditState,markApprovalCandidateAuthorizationRequired,retireActiveCandidates,sameResponder,settleAllowedCandidate,settleDirectApprovalResponse};
1
+ const APPROVAL_STATE_KEY=`eve.runtime.hitl.approvalState`;function createApprovalCandidate(e){let t=expireApprovalCandidates({now:e.createdAt,state:e.state}),n=readApprovalState(t);if(n.settlements[e.requestId]!==void 0)return{changed:!1,state:t};let r=e.responder;if(Object.values(n.activeCandidates).find(t=>t.requestId===e.requestId&&t.decision===e.decision&&sameResponder(t.responder,r))!==void 0)return{changed:!1,state:t};let i=n.activeCandidates[e.candidateIdPrefix]!==void 0||n.candidateHistory.some(t=>t.candidateId===e.candidateIdPrefix)?`${e.candidateIdPrefix}.${n.nextCandidateSequence.toString(36)}`:e.candidateIdPrefix;if(n.activeCandidates[i]!==void 0||n.candidateHistory.some(e=>e.candidateId===i))throw Error(`Approval candidate id collision: "${i}".`);let a={candidateId:i,createdAt:e.createdAt,decision:e.decision,expiresAt:e.expiresAt,requestId:e.requestId,responder:r,status:`pending`};return{changed:!0,state:writeApprovalState(t,{...n,activeCandidates:{...n.activeCandidates,[a.candidateId]:a},nextCandidateSequence:n.nextCandidateSequence+1})}}function markApprovalCandidateAuthorizationRequired(e){let t=readApprovalState(e.state),n=t.activeCandidates[e.candidateId];if(n===void 0)return e.state;let r={...n,authorizationChallenges:e.authorizationChallenges,expiresAt:e.expiresAt??n.expiresAt,status:`authorization-required`};return writeApprovalState(e.state,{...t,activeCandidates:{...t.activeCandidates,[e.candidateId]:r}})}function finishApprovalCandidate(e){let t=readApprovalState(e.state),n=t.activeCandidates[e.candidateId];if(n===void 0)return e.state;let r={...t.activeCandidates};return delete r[e.candidateId],writeApprovalState(e.state,{...t,activeCandidates:r,candidateHistory:[...t.candidateHistory,toCandidateAuditRecord({candidate:n,completedAt:e.completedAt,reason:e.reason,status:e.status})]})}function expireApprovalCandidates(e){let t=e.state,n=Object.values(readApprovalState(t).activeCandidates);for(let r of n)r.expiresAt>e.now||(t=finishApprovalCandidate({candidateId:r.candidateId,completedAt:e.now,state:t,status:`timed-out`}));return t}function settleAllowedCandidate(e){let t=expireApprovalCandidates({now:e.settledAt,state:e.state}),n=readApprovalState(t),r=n.activeCandidates[e.candidateId];if(r===void 0){let r=n.candidateHistory.find(t=>t.candidateId===e.candidateId);if((r&&n.settlements[r.requestId])!==void 0)return{changed:!1,state:t};throw Error(`Unknown approval candidate "${e.candidateId}".`)}return settleRequest({candidateId:r.candidateId,outcome:r.decision===`cancel`?`cancelled`:`allowed`,requestId:r.requestId,responder:r.responder,settledAt:e.settledAt,state:t})}function settleUnavailableCandidate(e){let t=expireApprovalCandidates({now:e.settledAt,state:e.state}),n=readApprovalState(t).activeCandidates[e.candidateId];return n===void 0?{changed:!1,state:t}:settleRequest({candidateId:n.candidateId,outcome:`unavailable`,reason:e.reason,requestId:n.requestId,responder:n.responder,settledAt:e.settledAt,state:t})}function settleDirectApprovalResponse(e){let t=expireApprovalCandidates({now:e.settledAt,state:e.state});return settleRequest({outcome:e.outcome,requestId:e.requestId,responder:e.actor,settledAt:e.settledAt,state:t})}function getActiveApprovalCandidate(e,t){return readApprovalState(e).activeCandidates[t]}function getApprovalAuditState(e){let t=readApprovalState(e);return{activeCandidates:Object.values(t.activeCandidates),candidateHistory:t.candidateHistory,settlements:Object.values(t.settlements)}}function settleRequest(e){let t=readApprovalState(e.state);if(t.settlements[e.requestId]!==void 0)return{changed:!1,state:e.state};let n={actor:projectResponder(e.responder),...e.outcome===`allowed`&&{approver:e.responder},candidateId:e.candidateId,outcome:e.outcome,requestId:e.requestId,settledAt:e.settledAt},r={},i=[...t.candidateHistory];for(let n of Object.values(t.activeCandidates)){if(n.requestId!==e.requestId){r[n.candidateId]=n;continue}let t=n.candidateId===e.candidateId;i.push(toCandidateAuditRecord({candidate:n,completedAt:e.settledAt,reason:t?e.reason:void 0,status:t?e.outcome===`unavailable`?`failed`:`allowed`:`stale`}))}let a={activeCandidates:r,candidateHistory:i,nextCandidateSequence:t.nextCandidateSequence,settlements:{...t.settlements,[e.requestId]:n}};return{changed:!0,state:writeApprovalState(e.state,a)}}function toCandidateAuditRecord(e){let{authorizationChallenges:t,responder:n,...r}=e.candidate;return{...r,completedAt:e.completedAt,responder:projectResponder(n),reason:e.reason,status:e.status}}function projectResponder(e){return{authenticator:e.authenticator,issuer:e.issuer,principalId:e.principalId,principalType:e.principalType}}function sameResponder(e,t){return e.authenticator===t.authenticator&&e.issuer===t.issuer&&e.principalId===t.principalId&&e.principalType===t.principalType}function readActiveCandidates(e){return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{...t,decision:t.decision===`cancel`?`cancel`:`approve`}]))}function readApprovalState(e){let t=e?.[APPROVAL_STATE_KEY];if(typeof t!=`object`||!t)return{activeCandidates:{},candidateHistory:[],nextCandidateSequence:0,settlements:{}};let n=t;return{activeCandidates:typeof n.activeCandidates==`object`&&n.activeCandidates!==null?readActiveCandidates(n.activeCandidates):{},candidateHistory:Array.isArray(n.candidateHistory)?n.candidateHistory:[],nextCandidateSequence:typeof n.nextCandidateSequence==`number`&&Number.isSafeInteger(n.nextCandidateSequence)&&n.nextCandidateSequence>=0?n.nextCandidateSequence:deriveNextCandidateSequence(n),settlements:typeof n.settlements==`object`&&n.settlements!==null?n.settlements:{}}}function deriveNextCandidateSequence(e){return Object.keys(e.activeCandidates??{}).length+(Array.isArray(e.candidateHistory)?e.candidateHistory.length:0)}function writeApprovalState(e,t){return{...e,[APPROVAL_STATE_KEY]:t}}function retireActiveCandidates(e,t){let n=e;for(let e of getApprovalAuditState(n).activeCandidates)n=finishApprovalCandidate({candidateId:e.candidateId,completedAt:t.completedAt,reason:t.reason,state:n,status:`stale`});return n}function approverOfRequest(e,t){return readApprovalState(e).settlements[t]?.approver}export{approverOfRequest,createApprovalCandidate,expireApprovalCandidates,finishApprovalCandidate,getActiveApprovalCandidate,getApprovalAuditState,markApprovalCandidateAuthorizationRequired,retireActiveCandidates,sameResponder,settleAllowedCandidate,settleDirectApprovalResponse,settleUnavailableCandidate};
@@ -1,5 +1,5 @@
1
1
  import { type AuthorizationChallenge } from "#harness/authorization.js";
2
- import type { HarnessSession, HarnessToolMap, StepInput } from "#harness/types.js";
2
+ import type { HarnessSession, HarnessToolLookup, StepInput } from "#harness/types.js";
3
3
  import type { InputRequest } from "#shared/input.js";
4
4
  interface ApprovalDeliveryResult {
5
5
  readonly challenges: readonly AuthorizationChallenge[];
@@ -29,7 +29,7 @@ export declare function coordinateApprovalDelivery(input: {
29
29
  readonly now?: number;
30
30
  readonly session: HarnessSession;
31
31
  readonly stepInput?: StepInput;
32
- readonly tools: HarnessToolMap;
33
- readonly prepareTools?: (request: InputRequest) => Promise<HarnessToolMap>;
32
+ readonly tools: HarnessToolLookup;
33
+ readonly prepareTools?: (request: InputRequest) => Promise<HarnessToolLookup>;
34
34
  }): Promise<ApprovalDeliveryResult>;
35
35
  export {};
@@ -1 +1 @@
1
- import{contextStorage}from"#context/container.js";import{AuthKey,SessionKey}from"#context/keys.js";import{buildCallbackContext}from"#context/build-callback-context.js";import{buildApprovalResponseAuth,handleApprovalResponsePolicyError}from"#execution/tool-auth.js";import{suspendedSteps}from"#harness/session-machine/view.js";import{clearPendingAuthorization,getAuthorizationResult,getPendingAuthorization,isAuthorizationSignal}from"#harness/authorization.js";import{isApprovalRequest}from"#harness/input-request-class.js";import{createApprovalCandidate,expireApprovalCandidates,finishApprovalCandidate,getActiveApprovalCandidate,getApprovalAuditState,markApprovalCandidateAuthorizationRequired,sameResponder,settleAllowedCandidate,settleDirectApprovalResponse}from"#harness/hitl/candidates.js";async function coordinateApprovalDelivery(e){let t=e.now??Date.now(),n=getApprovalAuditState(e.session.state).activeCandidates.filter(e=>e.expiresAt<=t),r=n.flatMap(e=>e.authorizationChallenges?.map(e=>e.attemptId??e.candidateId??e.name)??[]),i=expireApprovalCandidates({now:t,state:e.session.state}),a={...e.session,state:clearPendingAuthorization(i,r)},o=getApprovalAuditState(a.state),s=suspendedSteps(a.state).filter(e=>e.requests.length>0),c=new Set(s.flatMap(e=>e.requests.map(e=>e.requestId))),l=o.settlements.filter(e=>c.has(e.requestId)),u=new Set(o.settlements.map(e=>e.requestId)),d=new Set([...u].filter(e=>!c.has(e))),f=hasResponseForRequest(e.stepInput,d),p=f?removeConsumedResponses(e.stepInput,d):e.stepInput;if(f&&l.length===0&&!hasMeaningfulInput(p))return deliveryResult(a,p,`park`);if(s.length===0)return deliveryResult(a,p);let m=p,h=new Set(s.flatMap(e=>e.responseAuthRequiredRequestIds??[])),g=s.flatMap(e=>e.requests),_=new Map(g.map(e=>[e.requestId,e])),v=[],y=[],b=new Set,x=!1,S=getApprovalAuditState(a.state).activeCandidates,C=[...m?.attributedInputResponses??[],...(m?.inputResponses??[]).map(e=>({auth:void 0,response:e}))];for(let{auth:e,response:n}of C){let r=_.get(n.requestId);if(r===void 0||!isApprovalRequest(r))continue;if(!h.has(n.requestId)){let r=contextStorage.getStore(),i=e===void 0?r?.get(AuthKey)??r?.get(SessionKey)?.auth.current??null:e,o=toCandidateDecision(n.optionId),s=suspendedSteps(a.state).find(e=>e.requests.some(e=>e.requestId===n.requestId))?.requester??null;if(i!==null&&o!==void 0&&s!==null&&!sameResponder(s,i)){b.add(n.requestId),y.push(`Only the person who requested this action can respond to this approval.`);continue}if(i!==null&&o!==void 0){let e=settleDirectApprovalResponse({actor:i,outcome:o===`approve`?`allowed`:`cancelled`,requestId:n.requestId,settledAt:t,state:a.state});a={...a,state:e.state},x||=e.changed}continue}b.add(n.requestId);let i=toCandidateDecision(n.optionId);if(i===void 0)continue;let o=e===void 0?buildCallbackContext().session.auth.current:e;if(o===null){y.push(`Authentication is required to respond to this approval.`);continue}let s=createApprovalCandidate({candidateIdPrefix:approvalCandidateIdPrefix(r.requestId,o,i),createdAt:t,decision:i,expiresAt:t+6e5,requestId:r.requestId,responder:o,state:a.state});a={...a,state:s.state},x||=s.changed}let w=removeConsumedResponses(m,b);if(b.size>0)return deliveryResult(a,w,x?`continue-coordination`:`continue`,[],y);if(x)return deliveryResult(a,w,`continue`,[],y);let T=new Set(getPendingAuthorization(a.state)?.challenges.map(e=>e.name)??[]);for(let n of S){if(n.status===`authorization-required`){let e=n.authorizationChallenges??[];if(!e.some(e=>getAuthorizationResult(e.name)!==void 0)){v.push(...e.filter(e=>!T.has(e.name)));continue}}let r=_.get(n.requestId);if(r===void 0||getActiveApprovalCandidate(a.state,n.candidateId)===void 0)continue;let i=await authorizeCandidate({candidateId:n.candidateId,decision:n.decision,now:t,request:r,responder:n.responder,session:a,tools:await e.prepareTools?.(r)??e.tools});a=i.session,x||=i.didCommit,v.push(...i.challenges);let o=getApprovalAuditState(a.state).settlements.find(e=>e.requestId===n.requestId);o!==void 0&&l.push(o)}let E=appendSettledResponses(w,l);return(x||n.length>0)&&getApprovalAuditState(a.state).activeCandidates.length===0?deliveryResult(a,E,`responses-completed`):l.length>0?deliveryResult(a,E,`continue`):x?deliveryResult(a,E,`continue-coordination`):deliveryResult(a,E,v.length>0?`authorization-required`:`continue`,v)}async function authorizeCandidate(e){let t={...e.session,state:expireApprovalCandidates({now:e.now,state:e.session.state})};if(getActiveApprovalCandidate(t.state,e.candidateId)===void 0)return{challenges:[],didCommit:!1,session:t};let n=e.tools.get(e.request.action.toolName)?.approval,r=n!==void 0&&typeof n!=`function`?n.response:void 0;if(r===void 0)return failCandidate({...e,reason:`Approval authorization is temporarily unavailable. Please try again.`,session:t});try{let n=buildCallbackContext(),i=await withAuthorizerTimeout(r({auth:buildApprovalResponseAuth({responder:e.responder,scope:e.candidateId}),request:{callId:e.request.action.callId,requestId:e.request.requestId,principal:suspendedSteps(t.state).find(t=>t.requests.some(t=>t.requestId===e.request.requestId))?.requester??null,toolInput:e.request.action.input,toolName:e.request.action.toolName},response:{decision:e.decision,principal:e.responder},session:{id:n.session.id,initiator:n.session.auth.initiator,parent:n.session.parent,turn:n.session.turn}}));if(i.status===`rejected`)return t={...t,state:finishApprovalCandidate({candidateId:e.candidateId,completedAt:e.now,reason:i.reason,state:t.state,status:`rejected`})},{challenges:[],didCommit:!0,session:t};if(i.status!==`allowed`)return failCandidate({...e,session:t});let a=settleAllowedCandidate({candidateId:e.candidateId,settledAt:e.now,state:t.state});return{challenges:[],didCommit:a.changed,session:{...t,state:a.state}}}catch(n){let r=await handleApprovalResponsePolicyError(n).catch(()=>void 0);if(isAuthorizationSignal(r)){let n=r.challenges.map(e=>Date.parse(e.challenge.expiresAt??``)).filter(Number.isFinite).sort((e,t)=>e-t)[0];return t={...t,state:markApprovalCandidateAuthorizationRequired({authorizationChallenges:r.challenges.map(t=>({...t,candidateId:e.candidateId})),candidateId:e.candidateId,expiresAt:n,state:t.state})},{challenges:r.challenges.map(t=>({...t,candidateId:e.candidateId})),didCommit:!0,session:t}}return failCandidate({...e,session:t})}}function failCandidate(e){let t=e.reason??`We couldn’t verify your response. Please try again.`;return{challenges:[],didCommit:!0,session:{...e.session,state:finishApprovalCandidate({candidateId:e.candidateId,completedAt:e.now,reason:t,state:e.session.state,status:`failed`})}}}function hasResponseForRequest(e,t){return e?.attributedInputResponses?.some(({response:e})=>t.has(e.requestId))===!0||e?.inputResponses?.some(e=>t.has(e.requestId))===!0}function hasMeaningfulInput(e){return e?.message!==void 0||(e?.attributedInputResponses?.length??0)>0||(e?.inputResponses?.length??0)>0||(e?.runtimeActionResults?.length??0)>0}function appendSettledResponses(e,t){if(t.length===0)return e;let n=new Set([...(e?.inputResponses??[]).map(e=>e.requestId),...(e?.attributedInputResponses??[]).map(({response:e})=>e.requestId)]),r=t.filter(e=>!n.has(e.requestId));return r.length===0?e:{...e,inputResponses:[...e?.inputResponses??[],...r.map(e=>({optionId:e.outcome===`allowed`?`approve`:`cancel`,requestId:e.requestId}))]}}function removeConsumedResponses(e,t){if(e===void 0)return;let n=(e.attributedInputResponses??[]).filter(({response:e})=>!t.has(e.requestId)),r=[...(e.inputResponses??[]).filter(e=>!t.has(e.requestId)),...n.map(({response:e})=>e)];return{...e,attributedInputResponses:void 0,inputResponses:r}}function deliveryResult(e,t,n=`continue`,r=[],i=[]){return{challenges:r,feedback:i,kind:n,session:e,stepInput:t}}function toCandidateDecision(e){if(e===`approve`)return`approve`;if(e===`cancel`||e===`deny`)return`cancel`}function approvalCandidateIdPrefix(e,t,n){let r=[t.authenticator,t.issuer??``,t.principalType,t.principalId].join(`:`),i=`${encodeCandidateIdPart(e)}.${encodeCandidateIdPart(r)}`;return n===`approve`?i:`${i}.${encodeCandidateIdPart(n)}`}function encodeCandidateIdPart(e){return Array.from(e,e=>e.codePointAt(0).toString(36)).join(`-`)}async function withAuthorizerTimeout(e){let t;try{return await Promise.race([Promise.resolve(e),new Promise((e,n)=>{t=setTimeout(()=>n(Error(`Approval response authorizer timed out.`)),1e4)})])}finally{t!==void 0&&clearTimeout(t)}}export{coordinateApprovalDelivery};
1
+ import{createLogger,logError}from"#internal/logging.js";import{contextStorage}from"#context/container.js";import{AuthKey,SessionKey}from"#context/keys.js";import{buildCallbackContext}from"#context/build-callback-context.js";import{buildApprovalResponseAuth,handleApprovalResponsePolicyError}from"#execution/tool-auth.js";import{suspendedSteps}from"#harness/session-machine/view.js";import{clearPendingAuthorization,getAuthorizationResult,getPendingAuthorization,isAuthorizationSignal}from"#harness/authorization.js";import{isApprovalRequest}from"#harness/input-request-class.js";import{createApprovalCandidate,expireApprovalCandidates,finishApprovalCandidate,getActiveApprovalCandidate,getApprovalAuditState,markApprovalCandidateAuthorizationRequired,sameResponder,settleAllowedCandidate,settleDirectApprovalResponse,settleUnavailableCandidate}from"#harness/hitl/candidates.js";const TEMPORARILY_UNAVAILABLE_APPROVAL_REASON=`Approval authorization is temporarily unavailable. Please try again.`,log=createLogger(`harness.hitl`);async function coordinateApprovalDelivery(e){let t=e.now??Date.now(),n=getApprovalAuditState(e.session.state).activeCandidates.filter(e=>e.expiresAt<=t),r=n.flatMap(e=>e.authorizationChallenges?.map(e=>e.attemptId??e.candidateId??e.name)??[]),i=expireApprovalCandidates({now:t,state:e.session.state}),a={...e.session,state:clearPendingAuthorization(i,r)},o=getApprovalAuditState(a.state),s=suspendedSteps(a.state).filter(e=>e.requests.length>0),c=new Set(s.flatMap(e=>e.requests.map(e=>e.requestId))),l=o.settlements.filter(e=>c.has(e.requestId)),u=new Set(o.settlements.map(e=>e.requestId)),d=new Set([...u].filter(e=>!c.has(e))),f=hasResponseForRequest(e.stepInput,d),p=f?removeConsumedResponses(e.stepInput,d):e.stepInput;if(f&&l.length===0&&!hasMeaningfulInput(p))return deliveryResult(a,p,`park`);if(s.length===0)return deliveryResult(a,p);let m=p,h=new Set(s.flatMap(e=>e.responseAuthRequiredRequestIds??[])),g=s.flatMap(e=>e.requests),_=new Map(g.map(e=>[e.requestId,e])),v=[],y=[],b=new Set,x=!1,S=getApprovalAuditState(a.state).activeCandidates,C=[...m?.attributedInputResponses??[],...(m?.inputResponses??[]).map(e=>({auth:void 0,response:e}))];for(let{auth:e,response:n}of C){let r=_.get(n.requestId);if(r===void 0||!isApprovalRequest(r))continue;if(!h.has(n.requestId)){let r=contextStorage.getStore(),i=e===void 0?r?.get(AuthKey)??r?.get(SessionKey)?.auth.current??null:e,o=toCandidateDecision(n.optionId),s=suspendedSteps(a.state).find(e=>e.requests.some(e=>e.requestId===n.requestId))?.requester??null;if(i!==null&&o!==void 0&&s!==null&&!sameResponder(s,i)){b.add(n.requestId),y.push(`Only the person who requested this action can respond to this approval.`);continue}if(i!==null&&o!==void 0){let e=settleDirectApprovalResponse({actor:i,outcome:o===`approve`?`allowed`:`cancelled`,requestId:n.requestId,settledAt:t,state:a.state});a={...a,state:e.state},x||=e.changed}continue}b.add(n.requestId);let i=toCandidateDecision(n.optionId);if(i===void 0)continue;let o=e===void 0?buildCallbackContext().session.auth.current:e;if(o===null){y.push(`Authentication is required to respond to this approval.`);continue}let s=createApprovalCandidate({candidateIdPrefix:approvalCandidateIdPrefix(r.requestId,o,i),createdAt:t,decision:i,expiresAt:t+6e5,requestId:r.requestId,responder:o,state:a.state});a={...a,state:s.state},x||=s.changed}let w=removeConsumedResponses(m,b);if(b.size>0)return deliveryResult(a,w,x?`continue-coordination`:`continue`,[],y);if(x)return deliveryResult(a,w,`continue`,[],y);let T=new Set(getPendingAuthorization(a.state)?.challenges.map(e=>e.name)??[]);for(let n of S){if(n.status===`authorization-required`){let e=n.authorizationChallenges??[];if(!e.some(e=>getAuthorizationResult(e.name)!==void 0)){v.push(...e.filter(e=>!T.has(e.name)));continue}}let r=_.get(n.requestId);if(r===void 0||getActiveApprovalCandidate(a.state,n.candidateId)===void 0)continue;let i=await authorizeCandidate({candidateId:n.candidateId,decision:n.decision,now:t,request:r,responder:n.responder,restoreTools:async()=>await e.prepareTools?.(r)??e.tools,session:a});a=i.session,x||=i.didCommit,v.push(...i.challenges);let o=getApprovalAuditState(a.state).settlements.find(e=>e.requestId===n.requestId);o!==void 0&&l.push(o)}let E=appendSettledResponses(w,l);return(x||n.length>0)&&getApprovalAuditState(a.state).activeCandidates.length===0?deliveryResult(a,E,`responses-completed`):l.length>0?deliveryResult(a,E,`continue`):x?deliveryResult(a,E,`continue-coordination`):deliveryResult(a,E,v.length>0?`authorization-required`:`continue`,v)}async function authorizeCandidate(e){let t={...e.session,state:expireApprovalCandidates({now:e.now,state:e.session.state})};if(getActiveApprovalCandidate(t.state,e.candidateId)===void 0)return{challenges:[],didCommit:!1,session:t};let n;try{n=await e.restoreTools()}catch(n){return logError(log,`approval tools could not be restored`,n,{requestId:e.request.requestId}),failCandidate({...e,reason:TEMPORARILY_UNAVAILABLE_APPROVAL_REASON,session:t})}let r=n.get(e.request.action.toolName);if(r===void 0){let n=settleUnavailableCandidate({candidateId:e.candidateId,reason:`The tool this approval was for is no longer available, so the call won't run.`,settledAt:e.now,state:t.state});return{challenges:[],didCommit:n.changed,session:{...t,state:n.state}}}let{approval:i}=r,a=i!==void 0&&typeof i!=`function`?i.response:void 0;if(a===void 0)return failCandidate({...e,reason:TEMPORARILY_UNAVAILABLE_APPROVAL_REASON,session:t});try{let n=buildCallbackContext(),r=await withAuthorizerTimeout(a({auth:buildApprovalResponseAuth({responder:e.responder,scope:e.candidateId}),request:{callId:e.request.action.callId,requestId:e.request.requestId,principal:suspendedSteps(t.state).find(t=>t.requests.some(t=>t.requestId===e.request.requestId))?.requester??null,toolInput:e.request.action.input,toolName:e.request.action.toolName},response:{decision:e.decision,principal:e.responder},session:{id:n.session.id,initiator:n.session.auth.initiator,parent:n.session.parent,turn:n.session.turn}}));if(r.status===`rejected`)return t={...t,state:finishApprovalCandidate({candidateId:e.candidateId,completedAt:e.now,reason:r.reason,state:t.state,status:`rejected`})},{challenges:[],didCommit:!0,session:t};if(r.status!==`allowed`)return failCandidate({...e,session:t});let i=settleAllowedCandidate({candidateId:e.candidateId,settledAt:e.now,state:t.state});return{challenges:[],didCommit:i.changed,session:{...t,state:i.state}}}catch(n){let r=await handleApprovalResponsePolicyError(n).catch(()=>void 0);if(isAuthorizationSignal(r)){let n=r.challenges.map(e=>Date.parse(e.challenge.expiresAt??``)).filter(Number.isFinite).sort((e,t)=>e-t)[0];return t={...t,state:markApprovalCandidateAuthorizationRequired({authorizationChallenges:r.challenges.map(t=>({...t,candidateId:e.candidateId})),candidateId:e.candidateId,expiresAt:n,state:t.state})},{challenges:r.challenges.map(t=>({...t,candidateId:e.candidateId})),didCommit:!0,session:t}}return failCandidate({...e,session:t})}}function failCandidate(e){let t=e.reason??`We couldn’t verify your response. Please try again.`;return{challenges:[],didCommit:!0,session:{...e.session,state:finishApprovalCandidate({candidateId:e.candidateId,completedAt:e.now,reason:t,state:e.session.state,status:`failed`})}}}function hasResponseForRequest(e,t){return e?.attributedInputResponses?.some(({response:e})=>t.has(e.requestId))===!0||e?.inputResponses?.some(e=>t.has(e.requestId))===!0}function hasMeaningfulInput(e){return e?.message!==void 0||(e?.attributedInputResponses?.length??0)>0||(e?.inputResponses?.length??0)>0||(e?.runtimeActionResults?.length??0)>0}function appendSettledResponses(e,t){if(t.length===0)return e;let n=new Set([...(e?.inputResponses??[]).map(e=>e.requestId),...(e?.attributedInputResponses??[]).map(({response:e})=>e.requestId)]),r=t.filter(e=>!n.has(e.requestId));return r.length===0?e:{...e,inputResponses:[...e?.inputResponses??[],...r.map(e=>({optionId:e.outcome===`allowed`?`approve`:`cancel`,requestId:e.requestId}))]}}function removeConsumedResponses(e,t){if(e===void 0)return;let n=(e.attributedInputResponses??[]).filter(({response:e})=>!t.has(e.requestId)),r=[...(e.inputResponses??[]).filter(e=>!t.has(e.requestId)),...n.map(({response:e})=>e)];return{...e,attributedInputResponses:void 0,inputResponses:r}}function deliveryResult(e,t,n=`continue`,r=[],i=[]){return{challenges:r,feedback:i,kind:n,session:e,stepInput:t}}function toCandidateDecision(e){if(e===`approve`)return`approve`;if(e===`cancel`||e===`deny`)return`cancel`}function approvalCandidateIdPrefix(e,t,n){let r=[t.authenticator,t.issuer??``,t.principalType,t.principalId].join(`:`),i=`${encodeCandidateIdPart(e)}.${encodeCandidateIdPart(r)}`;return n===`approve`?i:`${i}.${encodeCandidateIdPart(n)}`}function encodeCandidateIdPart(e){return Array.from(e,e=>e.codePointAt(0).toString(36)).join(`-`)}async function withAuthorizerTimeout(e){let t;try{return await Promise.race([Promise.resolve(e),new Promise((e,n)=>{t=setTimeout(()=>n(Error(`Approval response authorizer timed out.`)),1e4)})])}finally{t!==void 0&&clearTimeout(t)}}export{coordinateApprovalDelivery};
@@ -2,7 +2,7 @@ import type { ModelMessage } from "ai";
2
2
  import type { resolveInlineAuthorizationInterrupt } from "#harness/inline-tool-authorization.js";
3
3
  import type { StepCoordinates } from "#harness/session-machine/view.js";
4
4
  import type { Step } from "#harness/step/context.js";
5
- import type { HarnessSessionBase, StepInput, StepResult } from "#harness/types.js";
5
+ import type { HarnessSessionBase, HarnessToolLookup, StepInput, StepResult } from "#harness/types.js";
6
6
  import type { RuntimeWorkflowTaskRequest } from "#shared/action-types.js";
7
7
  import type { InputRequest } from "#shared/input.js";
8
8
  export { acceptHumanInput, admitApprovedWork, dispatchApprovedWorkflows, hasApprovedWork, runApprovedLocalCalls, type ApprovedWork, type HumanInputIntake, } from "./intake.js";
@@ -18,6 +18,8 @@ export declare function parkOnApprovals(step: Step, input: {
18
18
  readonly messages: readonly ModelMessage[];
19
19
  readonly requests: readonly InputRequest[];
20
20
  readonly tasks: readonly RuntimeWorkflowTaskRequest[];
21
+ /** The entries the step's calls ran, whose approvals the requests ask for. */
22
+ readonly tools: HarnessToolLookup;
21
23
  /** The step made calls the runtime runs, so the turn waits on them instead. */
22
24
  readonly waitsOnRuntime: boolean;
23
25
  }): Promise<StepResult>;
@@ -33,10 +35,10 @@ export declare function stopForToolSignIn(step: Step, interrupt: NonNullable<Ret
33
35
  */
34
36
  export declare function enforceBudget(step: Step, messages: readonly ModelMessage[]): Promise<StepResult | undefined>;
35
37
  /**
36
- * What a model call needs from the approvals: the keys `once()` approvals granted, and a note on
37
- * the calls still awaiting approval, which a message may revise.
38
+ * What a model call needs from the approvals: the keys `once()` approvals of `tools` granted, and
39
+ * a note on the calls still awaiting approval, which a message may revise.
38
40
  */
39
- export declare function humanInputContext(step: Step): {
41
+ export declare function humanInputContext(step: Step, tools: HarnessToolLookup): {
40
42
  readonly approvedTools: ReadonlySet<string>;
41
43
  readonly pendingApprovalsNote?: string;
42
44
  };
@@ -1 +1 @@
1
- import{renderPendingApprovalsInstruction}from"./approval-prompt.js";import{isEmptyInput}from"./delivery.js";import{grantedApprovalKeys,hasRunnableQueue,parkOnApprovals as parkOnApprovals$1,requestLimit,requireSignIn}from"./approvals.js";import{retireActiveCandidates}from"./candidates.js";import{checkSessionUsageLimit}from"./budget.js";import{acceptHumanInput,admitApprovedWork,dispatchApprovedWorkflows,hasApprovedWork,holdForInput,runApprovedLocalCalls}from"./intake.js";import{AuthKey,SessionKey}from"#context/keys.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{fail}from"#harness/session-machine/transitions.js";import{clearPendingAuthorization}from"#harness/authorization.js";import{buildResponseAuthorizationTools}from"#context/build-dynamic-tools.js";import{readTurnState,writeTurnState}from"#harness/session-machine/state.js";import{extractToolApprovalInputRequests}from"#harness/input-extraction.js";async function parkOnApprovals(e,t){let n=parkOnApprovals$1(e.view(),{event:t.event,messages:t.messages,requests:t.requests,tasks:t.tasks,requester:currentRequester(e),responseAuthRequiredRequestIds:responsePolicyRequestIds(e,t.requests)});return await e.apply(n,[...e.session.history,...n.commit??[]]),t.waitsOnRuntime?{next:null,session:e.session}:hasRunnableQueue(e.view())?{next:e.runStep,session:e.session}:holdForInput(e)}async function stopForToolSignIn(e,t){return e.session={...e.session,history:validateHarnessModelMessages(t.history)},await e.apply(requireSignIn(e.view(),{callIdsByName:t.callIdsByName,challenges:t.challenges}),e.session.history),{held:{kind:`request`},next:null,session:e.session}}async function enforceBudget(e,t){let n=checkSessionUsageLimit({canAsk:e.emit!==void 0&&e.config.capabilities?.requestInput===!0,session:e.session,turnSequence:e.position().sequence});if(n.kind!==`within`)return n.kind===`ask`?(e.session={...e.session,history:validateHarnessModelMessages([...t])},await e.apply(requestLimit(e.view(),{request:n.request}),e.session.history),{next:null,session:e.session}):(await e.apply(fail(e.view(),{code:n.code,details:n.details,message:n.message,terminal:{sessionId:e.session.sessionId}})),{next:{done:!0,output:``},session:e.session})}function humanInputContext(e){let t=e.view(),n=responseTools(e);return{approvedTools:grantedApprovalKeys(t,e=>n.get(e.action.toolName)?.approvalKey?.(e.action.input)),pendingApprovalsNote:renderPendingApprovalsInstruction(t.turn.suspended.flatMap(e=>e.requests))}}function discardClearedHumanInput(e){let{"eve.runtime.hitl.approvalState":t,...n}=clearPendingAuthorization(e.state)??{};return{...e,state:Object.keys(n).length>0?n:void 0}}function responseTools(e){return buildResponseAuthorizationTools({authoredTools:e.config.tools,context:e.ctx})}function responsePolicyRequestIds(e,t){let n=responseTools(e);return t.filter(e=>{let t=n.get(e.action.toolName)?.approval;return t!==void 0&&typeof t!=`function`&&t.response!==void 0}).map(e=>e.requestId)}function currentRequester(e){return e.ctx?.get(AuthKey)??e.ctx?.get(SessionKey)?.auth.current??null}function retireCancelledCandidates(e){return{...e,state:retireActiveCandidates(e.state,{completedAt:Date.now(),reason:`Cancelled.`})}}function takeDeferredMessage(e){let{queued:t,...n}=readTurnState(e.state);if(t?.message===void 0)return{session:e};let{message:r,...i}=t;return{message:r,session:writeTurnState(e,isEmptyInput(i)?n:{...n,queued:i})}}export{acceptHumanInput,admitApprovedWork,discardClearedHumanInput,dispatchApprovedWorkflows,enforceBudget,extractToolApprovalInputRequests,hasApprovedWork,hasRunnableQueue,humanInputContext,parkOnApprovals,retireCancelledCandidates,runApprovedLocalCalls,stopForToolSignIn,takeDeferredMessage};
1
+ import{renderPendingApprovalsInstruction}from"./approval-prompt.js";import{isEmptyInput}from"./delivery.js";import{grantedApprovalKeys,hasRunnableQueue,parkOnApprovals as parkOnApprovals$1,requestLimit,requireSignIn}from"./approvals.js";import{retireActiveCandidates}from"./candidates.js";import{checkSessionUsageLimit}from"./budget.js";import{acceptHumanInput,admitApprovedWork,dispatchApprovedWorkflows,hasApprovedWork,holdForInput,runApprovedLocalCalls}from"./intake.js";import{AuthKey,SessionKey}from"#context/keys.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{clearPendingAuthorization}from"#harness/authorization.js";import{fail}from"#harness/session-machine/transitions.js";import{readTurnState,writeTurnState}from"#harness/session-machine/state.js";import{extractToolApprovalInputRequests}from"#harness/input-extraction.js";async function parkOnApprovals(e,t){let n=parkOnApprovals$1(e.view(),{event:t.event,messages:t.messages,requests:t.requests,tasks:t.tasks,requester:currentRequester(e),responseAuthRequiredRequestIds:responsePolicyRequestIds(t.tools,t.requests)});return await e.apply(n,[...e.session.history,...n.commit??[]]),t.waitsOnRuntime?{next:null,session:e.session}:hasRunnableQueue(e.view())?{next:e.runStep,session:e.session}:holdForInput(e)}async function stopForToolSignIn(e,t){return e.session={...e.session,history:validateHarnessModelMessages(t.history)},await e.apply(requireSignIn(e.view(),{callIdsByName:t.callIdsByName,challenges:t.challenges}),e.session.history),{held:{kind:`request`},next:null,session:e.session}}async function enforceBudget(e,t){let n=checkSessionUsageLimit({canAsk:e.emit!==void 0&&e.config.capabilities?.requestInput===!0,session:e.session,turnSequence:e.position().sequence});if(n.kind!==`within`)return n.kind===`ask`?(e.session={...e.session,history:validateHarnessModelMessages([...t])},await e.apply(requestLimit(e.view(),{request:n.request}),e.session.history),{next:null,session:e.session}):(await e.apply(fail(e.view(),{code:n.code,details:n.details,message:n.message,terminal:{sessionId:e.session.sessionId}})),{next:{done:!0,output:``},session:e.session})}function humanInputContext(e,t){let n=e.view();return{approvedTools:grantedApprovalKeys(n,e=>t.get(e.action.toolName)?.approvalKey?.(e.action.input)),pendingApprovalsNote:renderPendingApprovalsInstruction(n.turn.suspended.flatMap(e=>e.requests))}}function discardClearedHumanInput(e){let{"eve.runtime.hitl.approvalState":t,...n}=clearPendingAuthorization(e.state)??{};return{...e,state:Object.keys(n).length>0?n:void 0}}function responsePolicyRequestIds(e,t){return t.filter(t=>{let n=e.get(t.action.toolName)?.approval;return n!==void 0&&typeof n!=`function`&&n.response!==void 0}).map(e=>e.requestId)}function currentRequester(e){return e.ctx?.get(AuthKey)??e.ctx?.get(SessionKey)?.auth.current??null}function retireCancelledCandidates(e){return{...e,state:retireActiveCandidates(e.state,{completedAt:Date.now(),reason:`Cancelled.`})}}function takeDeferredMessage(e){let{queued:t,...n}=readTurnState(e.state);if(t?.message===void 0)return{session:e};let{message:r,...i}=t;return{message:r,session:writeTurnState(e,isEmptyInput(i)?n:{...n,queued:i})}}export{acceptHumanInput,admitApprovedWork,discardClearedHumanInput,dispatchApprovedWorkflows,enforceBudget,extractToolApprovalInputRequests,hasApprovedWork,hasRunnableQueue,humanInputContext,parkOnApprovals,retireCancelledCandidates,runApprovedLocalCalls,stopForToolSignIn,takeDeferredMessage};
@@ -1,6 +1,6 @@
1
1
  import type { SuspendedStep } from "#harness/session-machine/view.js";
2
2
  import { type Step } from "#harness/step/context.js";
3
- import type { HarnessToolMap, StepInput, StepResult } from "#harness/types.js";
3
+ import type { HarnessToolLookup, StepInput, StepResult } from "#harness/types.js";
4
4
  import type { InstrumentationAttempt } from "#instrumentation/runtime.js";
5
5
  /**
6
6
  * What a delivery does before its turn runs. `stop` ends the step: the answers left nothing to
@@ -29,8 +29,8 @@ export interface ApprovedWork {
29
29
  readonly limit?: {
30
30
  readonly granted: boolean;
31
31
  };
32
- /** The tools a parked step's calls run with: those of the step that asked. */
33
- readonly toolsOf: (step: SuspendedStep | undefined) => HarnessToolMap;
32
+ /** The entries a parked step's calls run with: those of the step that asked. */
33
+ readonly toolsOf: (step: SuspendedStep | undefined) => HarnessToolLookup;
34
34
  }
35
35
  /**
36
36
  * Answers what the session asked: approval answers pass the response policies, and the session
@@ -1 +1 @@
1
- import{deliver,resolveTypedApproval,turnInputOnly,withoutTurnInput}from"./delivery.js";import{answer,approvingSteps,deferInput,dispatch,grantedApprovalKeys,requireSignIn,stepForRequest,withdrawSignIns}from"./approvals.js";import{getApprovalAuditState,retireActiveCandidates}from"./candidates.js";import{approversOf,setApprovedCallCallers}from"./approved-call-callers.js";import{runApprovedCalls}from"./approved-calls.js";import{coordinateApprovalDelivery}from"./coordinator.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{activeTurnId}from"#harness/session-machine/view.js";import{bumpSessionRuntimeUsageLimits}from"#harness/turn-tag-state.js";import{collectDeferredCalls}from"#harness/coordination.js";import{approvedCalls,completeSignIn,hold,settle}from"#harness/session-machine/transitions.js";import{stepStartedForResolvers}from"#harness/session-machine/resolver-events.js";import{SessionLimitDeclinedError,throwIfTurnAborted}from"#harness/turn-cancellation.js";import{resolveInlineAuthorizationInterrupt}from"#harness/inline-tool-authorization.js";import{buildResponseAuthorizationTools}from"#context/build-dynamic-tools.js";import{openTurn}from"#harness/step/context.js";import{prepareTurnInput}from"#harness/step/intake.js";import{placeTurnInput}from"#harness/step/prompt.js";async function acceptHumanInput(e,t,n){let{config:r,ctx:i}=e,a=r.signInCompletions??[];a.length>0&&await e.apply(completeSignIn(e.view(),{completions:a}));let o=deliver(e.view(),t,n),s=resolveTypedApproval(e.view(),o.input),c=t?.message!==void 0&&s?.message!==void 0||o.displayMessage!==void 0?await withdrawSteeredSignIns(e,s):s,l=new Map,u,restoreTools=async t=>{let n=t?.event??e.position(),a=`${n.turnId}:${n.stepIndex}`,o=l.get(a);if(o!==void 0&&u===a)return o;t!==void 0&&await r.prepareApprovalTurn?.(t.event),i!==void 0&&await r.resolveStepDynamicTools?.({ctx:i,event:stepStartedForResolvers({modelId:e.session.agent.modelReference?.id??`dynamic`,sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId}),messages:e.projectHistory(e.session.history)});let s=buildResponseAuthorizationTools({authoredTools:r.tools,context:i});return l.set(a,s),u=a,s},toolsOf=e=>(e&&l.get(`${e.event.turnId}:${e.event.stepIndex}`))??r.tools,d=e.view().signIns,f=await coordinateApprovalDelivery({session:e.session,stepInput:c,tools:r.tools,prepareTools:t=>restoreTools(stepForRequest(e.view(),t.requestId))});e.session=f.session;for(let t of approvingSteps(e.view(),f.stepInput))await restoreTools(t);let p=answer(e.view(),{approvalKey:t=>toolsOf(stepForRequest(e.view(),t.requestId)).get(t.action.toolName)?.approvalKey?.(t.action.input),delivery:f.stepInput,policy:{...f,audit:getApprovalAuditState(e.session.state),challengesAtStart:d},takeQueued:o.takeQueued});for(let t of p.resolved)await e.instrumentation?.publishInputResolutions({batch:t,sessionId:e.session.sessionId});await e.apply(p);let stop=e=>({kind:`stop`,result:e});switch(p.next){case`park`:return e.view().projection.activeTurnId===void 0?stop({next:null,session:e.session}):stop(await holdForInput(e));case`repeat`:return stop({next:e.runStep,session:e.session});case`sign-in`:return await e.apply(requireSignIn(e.view(),{challenges:f.challenges,queued:f.stepInput})),stop(held(e));case`defer-message`:{if(approvedCalls(e.view().turn).length>0){let t=turnInputOnly(p.input);return t!==void 0&&await e.apply(deferInput(e.view(),t)),stop({next:null,session:e.session})}let t=await prepareTurnInput(e,p.input,{consumedMessage:!1}),n=await openTurn(e,{input:[...t.ephemeral,...t.messages],message:o.displayMessage??p.input?.message});return n===void 0?(e.session={...e.session,history:validateHarnessModelMessages(placeTurnInput(e,e.session.history,t))},stop(await holdForInput(e))):stop(n)}}for(let t of e.view().turn.suspended)(t.approved?.length??0)>0&&await restoreTools(t);let m=p.resolved.some(e=>e.inputs.some(e=>e.request.kind===`tool-approval`)&&e.inputs.every(e=>e.response!==void 0))||approvedCalls(e.view().turn).length>0?turnInputOnly(p.input):void 0;return m!==void 0&&await e.apply(deferInput(e.view(),m)),{approved:{limit:p.limit,toolsOf},consumedMessage:p.consumedMessage===!0,input:m===void 0?p.input:withoutTurnInput(p.input),message:p.consumedMessage===!0||m!==void 0?void 0:o.displayMessage??o.input?.message,kind:`run`,opensTurn:hasTurnInput(o.input)||hasTurnInput(f.stepInput)}}async function admitApprovedWork(e,t){if(t.limit!==void 0){if(!t.limit.granted)throw new SessionLimitDeclinedError;e.session=bumpSessionRuntimeUsageLimits(e.session)}await e.apply(settle(e.view(),{results:[]}))}function hasApprovedWork(e){return approvedCalls(e.view().turn).length>0}async function dispatchApprovedWorkflows(e,t){let n=[],r=[];for(let i of e.view().turn.suspended){let a=t.toolsOf(i),o=(i.approved??[]).filter(e=>a.get(e.action.toolName)?.workflowId!==void 0);if(o.length===0)continue;r.push(...o);let s=collectDeferredCalls({session:e.session,toolCalls:o.map(({action:e})=>({input:e.input,toolCallId:e.callId,toolName:e.toolName})),tools:a,turnId:i.event.turnId});e.session=s.session,n.push(...s.workflowRequests)}return n.length!==0&&(await e.apply(dispatch(e.view(),{approvers:approversOf(r,e.session.state),tasks:n})),!0)}async function runApprovedLocalCalls(e,t,n){let r=e.view().turn.suspended.map(e=>{let n=t.toolsOf(e);return{requests:(e.approved??[]).filter(e=>n.get(e.action.toolName)?.workflowId===void 0),tools:n}}),i=r.flatMap(({requests:e})=>e);e.frameworkToolNames=new Set(r.flatMap(({tools:e})=>[...e].filter(([,e])=>e.frameworkTool===!0).map(([e])=>e))),setApprovedCallCallers(i,e.session.state);let a=e.position(),o=i.length===0?void 0:e.instrumentation?.prepareAttempt({isFrameworkTool:t=>e.frameworkToolNames.has(t),attemptIndex:0,stepIndex:a.stepIndex,turnId:activeTurnId(a)});o!==void 0&&n(o.scope);let s=await Promise.all(r.map(async({requests:t,tools:n})=>t.length===0?{settled:[],toolResults:[]}:await runApprovedCalls({abortSignal:e.config.abortSignal,approvedTools:grantedApprovalKeys(e.view(),e=>n.get(e.action.toolName)?.approvalKey?.(e.action.input)),messages:e.projectHistory(e.session.history),position:e.position(),publish:e.publish,requests:t,telemetry:o?.telemetry,tools:n})));await e.apply(settle(e.view(),{results:s.flatMap(e=>e.settled)})),throwIfTurnAborted(e.config.abortSignal);let c=resolveInlineAuthorizationInterrupt({messages:[],toolResults:s.flatMap(e=>e.toolResults)});if(c!==void 0)return await e.apply(requireSignIn(e.view(),{callIdsByName:c.callIdsByName,challenges:c.challenges}),e.session.history),held(e)}const STEERED_SIGN_IN_REASON=`Cancelled because a new message arrived.`;async function holdForInput(e){return await e.apply(hold(e.view(),{on:`input`})),held(e)}function held(e){return{held:{kind:`request`},next:null,session:e.session}}async function withdrawSteeredSignIns(e,t){let n=[...new Set(e.view().signIns.map(e=>e.name))];return e.session={...e.session,state:retireActiveCandidates(e.session.state,{completedAt:Date.now(),reason:STEERED_SIGN_IN_REASON})},n.length===0?t:(await e.apply(withdrawSignIns(e.view(),STEERED_SIGN_IN_REASON)),{...t,context:[...t?.context??[],`Sign-in to ${n.join(`, `)} was cancelled because the user sent a new message instead. Ask to sign in again only if the new message still needs it.`]})}function hasTurnInput(e){return e===void 0?!1:e.message!==void 0||(e.inputResponses?.length??0)>0}export{acceptHumanInput,admitApprovedWork,dispatchApprovedWorkflows,hasApprovedWork,holdForInput,runApprovedLocalCalls};
1
+ import{deliver,resolveTypedApproval,turnInputOnly,withoutTurnInput}from"./delivery.js";import{answer,approvingSteps,deferInput,dispatch,grantedApprovalKeys,requireSignIn,stepForRequest,withdrawSignIns}from"./approvals.js";import{getApprovalAuditState,retireActiveCandidates}from"./candidates.js";import{approversOf,setApprovedCallCallers}from"./approved-call-callers.js";import{runApprovedCalls}from"./approved-calls.js";import{coordinateApprovalDelivery}from"./coordinator.js";import{SEARCH_TOOL_NAME}from"#protocol/catalog-tools.js";import{validateHarnessModelMessages}from"#harness/messages.js";import{activeTurnId}from"#harness/session-machine/view.js";import{bumpSessionRuntimeUsageLimits}from"#harness/turn-tag-state.js";import{collectWorkflowCalls}from"#harness/coordination.js";import{approvedCalls,completeSignIn,hold,settle}from"#harness/session-machine/transitions.js";import{stepStartedForResolvers}from"#harness/session-machine/resolver-events.js";import{SessionLimitDeclinedError,throwIfTurnAborted}from"#harness/turn-cancellation.js";import{resolveInlineAuthorizationInterrupt}from"#harness/inline-tool-authorization.js";import{buildStepCatalog}from"#execution/catalog/step-catalog.js";import{openTurn}from"#harness/step/context.js";import{prepareTurnInput}from"#harness/step/intake.js";import{placeTurnInput}from"#harness/step/prompt.js";async function acceptHumanInput(e,t,n){let{config:r,ctx:i}=e,a=r.signInCompletions??[];a.length>0&&await e.apply(completeSignIn(e.view(),{completions:a}));let o=deliver(e.view(),t,n),s=resolveTypedApproval(e.view(),o.input),c=t?.message!==void 0&&s?.message!==void 0||o.displayMessage!==void 0?await withdrawSteeredSignIns(e,s):s,l=new Map,u,restoreTools=async t=>{let n=t?.event??e.position(),a=`${n.turnId}:${n.stepIndex}`,o=l.get(a);if(o!==void 0&&u===a)return o;t!==void 0&&await r.prepareApprovalTurn?.(t.event),i!==void 0&&await r.resolveStepDynamicTools?.({ctx:i,event:stepStartedForResolvers({modelId:e.session.agent.modelReference?.id??`dynamic`,sequence:n.sequence,stepIndex:n.stepIndex,turnId:n.turnId}),messages:e.projectHistory(e.session.history)});let s=buildStepCatalog({agentTools:r.tools,ctx:i,endsTurn:!1,session:e.session});return l.set(a,s),u=a,s},toolsOf=e=>(e&&l.get(`${e.event.turnId}:${e.event.stepIndex}`))??r.tools,d=e.view().signIns,f=await coordinateApprovalDelivery({session:e.session,stepInput:c,tools:r.tools,prepareTools:t=>restoreTools(stepForRequest(e.view(),t.requestId))});e.session=f.session;for(let t of approvingSteps(e.view(),f.stepInput))await restoreTools(t);let p=answer(e.view(),{approvalKey:t=>toolsOf(stepForRequest(e.view(),t.requestId)).get(t.action.toolName)?.approvalKey?.(t.action.input),delivery:f.stepInput,searchable:t=>toolsOf(stepForRequest(e.view(),t.requestId)).get(SEARCH_TOOL_NAME)!==void 0,policy:{...f,audit:getApprovalAuditState(e.session.state),challengesAtStart:d},takeQueued:o.takeQueued});for(let t of p.resolved)await e.instrumentation?.publishInputResolutions({batch:t,sessionId:e.session.sessionId});await e.apply(p);let stop=e=>({kind:`stop`,result:e});switch(p.next){case`park`:return e.view().projection.activeTurnId===void 0?stop({next:null,session:e.session}):stop(await holdForInput(e));case`repeat`:return stop({next:e.runStep,session:e.session});case`sign-in`:return await e.apply(requireSignIn(e.view(),{challenges:f.challenges,queued:f.stepInput})),stop(held(e));case`defer-message`:{if(approvedCalls(e.view().turn).length>0){let t=turnInputOnly(p.input);return t!==void 0&&await e.apply(deferInput(e.view(),t)),stop({next:null,session:e.session})}let t=await prepareTurnInput(e,p.input,{consumedMessage:!1}),n=await openTurn(e,{input:[...t.ephemeral,...t.messages],message:o.displayMessage??p.input?.message});return n===void 0?(e.session={...e.session,history:validateHarnessModelMessages(placeTurnInput(e,e.session.history,t))},stop(await holdForInput(e))):stop(n)}}for(let t of e.view().turn.suspended)(t.approved?.length??0)>0&&await restoreTools(t);let m=p.resolved.some(e=>e.inputs.some(e=>e.request.kind===`tool-approval`)&&e.inputs.every(e=>e.response!==void 0))||approvedCalls(e.view().turn).length>0?turnInputOnly(p.input):void 0;return m!==void 0&&await e.apply(deferInput(e.view(),m)),{approved:{limit:p.limit,toolsOf},consumedMessage:p.consumedMessage===!0,input:m===void 0?p.input:withoutTurnInput(p.input),message:p.consumedMessage===!0||m!==void 0?void 0:o.displayMessage??o.input?.message,kind:`run`,opensTurn:hasTurnInput(o.input)||hasTurnInput(f.stepInput)}}async function admitApprovedWork(e,t){if(t.limit!==void 0){if(!t.limit.granted)throw new SessionLimitDeclinedError;e.session=bumpSessionRuntimeUsageLimits(e.session)}await e.apply(settle(e.view(),{results:[]}))}function hasApprovedWork(e){return approvedCalls(e.view().turn).length>0}async function dispatchApprovedWorkflows(e,t){let n=[],r=[];for(let i of e.view().turn.suspended){let a=t.toolsOf(i),o=(i.approved??[]).filter(e=>a.get(e.action.toolName)?.workflowId!==void 0);if(o.length===0)continue;r.push(...o);let s=collectWorkflowCalls({session:e.session,toolCalls:o.map(({action:e})=>({input:e.input,toolCallId:e.callId,toolName:e.toolName})),tools:a,turnId:i.event.turnId});e.session=s.session,n.push(...s.workflowRequests)}return n.length!==0&&(await e.apply(dispatch(e.view(),{approvers:approversOf(r,e.session.state),tasks:n})),!0)}async function runApprovedLocalCalls(e,t,n){let r=e.view().turn.suspended.map(e=>{let n=t.toolsOf(e);return{requests:(e.approved??[]).filter(e=>n.get(e.action.toolName)?.workflowId===void 0),tools:n}}),i=r.flatMap(({requests:e})=>e);e.frameworkToolNames=new Set(r.flatMap(({requests:e,tools:t})=>e.map(e=>e.action.toolName).filter(e=>t.get(e)?.frameworkTool===!0))),setApprovedCallCallers(i,e.session.state);let a=e.position(),o=i.length===0?void 0:e.instrumentation?.prepareAttempt({isFrameworkTool:t=>e.frameworkToolNames.has(t),attemptIndex:0,stepIndex:a.stepIndex,turnId:activeTurnId(a)});o!==void 0&&n(o.scope);let s=await Promise.all(r.map(async({requests:t,tools:n})=>t.length===0?{settled:[],toolResults:[]}:await runApprovedCalls({abortSignal:e.config.abortSignal,approvedTools:grantedApprovalKeys(e.view(),e=>n.get(e.action.toolName)?.approvalKey?.(e.action.input)),messages:e.projectHistory(e.session.history),position:e.position(),publish:e.publish,requests:t,telemetry:o?.telemetry,tools:n})));await e.apply(settle(e.view(),{results:s.flatMap(e=>e.settled)})),throwIfTurnAborted(e.config.abortSignal);let c=resolveInlineAuthorizationInterrupt({messages:[],toolResults:s.flatMap(e=>e.toolResults)});if(c!==void 0)return await e.apply(requireSignIn(e.view(),{callIdsByName:c.callIdsByName,challenges:c.challenges}),e.session.history),held(e)}const STEERED_SIGN_IN_REASON=`Cancelled because a new message arrived.`;async function holdForInput(e){return await e.apply(hold(e.view(),{on:`input`})),held(e)}function held(e){return{held:{kind:`request`},next:null,session:e.session}}async function withdrawSteeredSignIns(e,t){let n=[...new Set(e.view().signIns.map(e=>e.name))];return e.session={...e.session,state:retireActiveCandidates(e.session.state,{completedAt:Date.now(),reason:STEERED_SIGN_IN_REASON})},n.length===0?t:(await e.apply(withdrawSignIns(e.view(),STEERED_SIGN_IN_REASON)),{...t,context:[...t?.context??[],`Sign-in to ${n.join(`, `)} was cancelled because the user sent a new message instead. Ask to sign in again only if the new message still needs it.`]})}function hasTurnInput(e){return e===void 0?!1:e.message!==void 0||(e.inputResponses?.length??0)>0}export{acceptHumanInput,admitApprovedWork,dispatchApprovedWorkflows,hasApprovedWork,holdForInput,runApprovedLocalCalls};
@@ -1,10 +1,13 @@
1
1
  import type { ContentPart, ToolSet } from "ai";
2
2
  import type { InputRequest } from "#shared/input.js";
3
+ import type { HarnessToolLookup } from "#harness/types.js";
3
4
  /**
4
5
  * Extracts tool approval input requests from AI SDK content parts that
5
- * contain `tool-approval-request` entries.
6
+ * contain `tool-approval-request` entries. Each prompt names the call by the
7
+ * label its entry in `tools` gives it.
6
8
  */
7
9
  export declare function extractToolApprovalInputRequests(input: {
8
10
  readonly content: readonly ContentPart<ToolSet>[];
9
11
  readonly excludedCallIds?: ReadonlySet<string>;
12
+ readonly tools: HarnessToolLookup;
10
13
  }): InputRequest[];
@@ -1 +1 @@
1
- import{z}from"#compiled/zod/index.js";import{toolCallDisplayName}from"#execution/tools/connection-target.js";import{createRuntimeToolCallActionFromToolCall}from"#harness/tool-call-action.js";const ToolCallDescriptorSchema=z.object({input:z.unknown(),toolCallId:z.string(),toolName:z.string()}),PersistedToolCallSchema=ToolCallDescriptorSchema.extend({type:z.literal(`tool-call`)}),ToolApprovalRequestSchema=z.object({approvalId:z.string(),isAutomatic:z.boolean().optional().catch(void 0),toolCall:ToolCallDescriptorSchema.optional().catch(void 0),toolCallId:z.string().optional().catch(void 0),type:z.literal(`tool-approval-request`)});function extractToolApprovalInputRequests(e){return extractApprovalRequests(e)}function extractApprovalRequests(e){let t=[],n=new Map;for(let t of e.content){let e=PersistedToolCallSchema.safeParse(t);e.success&&n.set(e.data.toolCallId,e.data)}for(let r of e.content){let i=ToolApprovalRequestSchema.safeParse(r);if(!i.success)continue;let a=i.data;if(a.isAutomatic===!0)continue;let o=a.toolCall??(a.toolCallId===void 0?void 0:n.get(a.toolCallId));o!==void 0&&(e.excludedCallIds?.has(o.toolCallId)||t.push({action:createRuntimeToolCallActionFromToolCall({toolCall:o}),allowFreeform:!1,display:`confirmation`,kind:`tool-approval`,options:[{id:`approve`,label:`Approve`},{id:`cancel`,label:`Cancel`}],prompt:`Approve ${toolCallDisplayName(o.toolName,o.input)}?`,requestId:a.approvalId}))}return t}export{extractToolApprovalInputRequests};
1
+ import{z}from"#compiled/zod/index.js";import{displayTitle}from"#shared/display-name.js";import{projectToolStartLabel}from"#harness/action-presentation.js";import{createRuntimeToolCallActionFromToolCall}from"#harness/tool-call-action.js";const ToolCallDescriptorSchema=z.object({input:z.unknown(),toolCallId:z.string(),toolName:z.string()}),PersistedToolCallSchema=ToolCallDescriptorSchema.extend({type:z.literal(`tool-call`)}),ToolApprovalRequestSchema=z.object({approvalId:z.string(),isAutomatic:z.boolean().optional().catch(void 0),toolCall:ToolCallDescriptorSchema.optional().catch(void 0),toolCallId:z.string().optional().catch(void 0),type:z.literal(`tool-approval-request`)});function extractToolApprovalInputRequests(e){return extractApprovalRequests(e)}function extractApprovalRequests(e){let t=[],n=new Map;for(let t of e.content){let e=PersistedToolCallSchema.safeParse(t);e.success&&n.set(e.data.toolCallId,e.data)}for(let r of e.content){let i=ToolApprovalRequestSchema.safeParse(r);if(!i.success)continue;let a=i.data;if(a.isAutomatic===!0)continue;let o=a.toolCall??(a.toolCallId===void 0?void 0:n.get(a.toolCallId));if(o===void 0||e.excludedCallIds?.has(o.toolCallId))continue;let s=createRuntimeToolCallActionFromToolCall({toolCall:o}),c=projectToolStartLabel(e.tools.get(s.toolName),s.input)??displayTitle(s.toolName);t.push({action:s,allowFreeform:!1,display:`confirmation`,kind:`tool-approval`,options:[{id:`approve`,label:`Approve`},{id:`cancel`,label:`Cancel`}],prompt:`Approve ${c}?`,requestId:a.approvalId})}return t}export{extractToolApprovalInputRequests};
@@ -1,3 +1,4 @@
1
+ import type { SettledCall } from "#harness/session-machine/transitions.js";
1
2
  import type { StepCoordinates as PendingInputBatchEvent } from "#harness/session-machine/view.js";
2
3
  import type { InputRequest, InputResponse } from "#shared/input.js";
3
4
  export declare const TOOL_EXECUTION_DENIED_MESSAGE = "Tool execution was denied.";
@@ -20,4 +21,18 @@ export declare function resolveApprovalOutcome(response: InputResponse | undefin
20
21
  readonly reason: string | undefined;
21
22
  readonly status: ApprovalTerminalStatus;
22
23
  };
24
+ /**
25
+ * What the model reads when a call's tool went away before the call could run.
26
+ * `searchable` says whether the agent has `eve__search` to find another.
27
+ */
28
+ export declare function unavailableToolMessage(toolName: string, searchable: boolean): string;
29
+ /**
30
+ * A call that ends without running: its failed runtime result, which the lifecycle reports at the
31
+ * step's coordinates, and the `error-text` result the model reads.
32
+ */
33
+ export declare function failedCall(call: {
34
+ readonly callId: string;
35
+ readonly message: string;
36
+ readonly toolName: string;
37
+ }): Required<SettledCall>;
23
38
  export {};
@@ -1 +1 @@
1
- const TOOL_EXECUTION_DENIED_MESSAGE=`Tool execution was denied.`;function resolveInputOutcome(e,t){return e===`tool-approval`?resolveApprovalOutcome(t).status:t===void 0?`ignored`:`answered`}function resolveApprovalOutcome(e){return e===void 0?{approved:!1,reason:`Ignored because the user continued without responding.`,status:`ignored`}:e.optionId===`approve`?{approved:!0,reason:void 0,status:`approved`}:e.optionId===`cancel`||e.optionId===`deny`?{approved:!1,reason:TOOL_EXECUTION_DENIED_MESSAGE,status:`denied`}:{approved:!1,reason:`Invalid approval response.`,status:`invalid`}}export{TOOL_EXECUTION_DENIED_MESSAGE,resolveApprovalOutcome,resolveInputOutcome};
1
+ import{SEARCH_TOOL_NAME}from"#protocol/catalog-tools.js";import{createRuntimeToolResultFromValue}from"#harness/action-result-helpers.js";const TOOL_EXECUTION_DENIED_MESSAGE=`Tool execution was denied.`;function resolveInputOutcome(e,t){return e===`tool-approval`?resolveApprovalOutcome(t).status:t===void 0?`ignored`:`answered`}function resolveApprovalOutcome(e){if(e===void 0)return{approved:!1,reason:`Ignored because the user continued without responding.`,status:`ignored`};if(e.optionId===`approve`)return{approved:!0,reason:void 0,status:`approved`};if(e.optionId===`cancel`||e.optionId===`deny`){let t=e.text?.trim();return{approved:!1,reason:t?`${TOOL_EXECUTION_DENIED_MESSAGE} The person who denied it wrote: ${JSON.stringify(t)}`:TOOL_EXECUTION_DENIED_MESSAGE,status:`denied`}}return{approved:!1,reason:`Invalid approval response.`,status:`invalid`}}function unavailableToolMessage(e,t){return`The tool "${e}" is no longer available, so the call didn't run. If the task still needs it, ${t?`find an available tool with ${SEARCH_TOOL_NAME} and make a new call`:`make a new call with an available tool`}.`}function failedCall(e){let{callId:t,message:n,toolName:r}=e;return{part:{output:{type:`error-text`,value:n},toolCallId:t,toolName:r,type:`tool-result`},result:createRuntimeToolResultFromValue({callId:t,isError:!0,output:n,toolName:r})}}export{TOOL_EXECUTION_DENIED_MESSAGE,failedCall,resolveApprovalOutcome,resolveInputOutcome,unavailableToolMessage};
@@ -1,14 +1,14 @@
1
1
  import { type LanguageModel, type ModelMessage } from "ai";
2
+ import type { StepCatalog } from "#execution/catalog/step-catalog.js";
2
3
  import type { GenerationSteering } from "#harness/generation-steering.js";
3
4
  import type { HarnessModelMessage, UserModelMessage } from "#harness/messages.js";
4
5
  import { type ModelProfile } from "#harness/model-profile.js";
5
6
  import type { Step } from "#harness/step/context.js";
6
7
  import { type Prompt } from "#harness/step/prompt.js";
7
8
  import { type HarnessStepResult } from "#harness/step-hooks.js";
8
- import type { StepResult } from "#harness/types.js";
9
+ import { type StepResult } from "#harness/types.js";
9
10
  import type { InstrumentationAttempt } from "#instrumentation/runtime.js";
10
11
  import { type RequestMessages } from "./request.js";
11
- import { type ModelTools } from "./tools.js";
12
12
  /** How one attempt differs from the step's first: what recovery and retries change. */
13
13
  export interface ModelCallOptions {
14
14
  readonly disabledProviderTools?: ReadonlySet<string>;
@@ -19,6 +19,8 @@ export interface ModelCallOptions {
19
19
  }
20
20
  /** What a model step's caller needs from the step. */
21
21
  interface ModelCallerInput {
22
+ /** The step's catalog: what the model can call, and what each call runs. */
23
+ readonly catalog: StepCatalog;
22
24
  readonly model: LanguageModel;
23
25
  readonly generation: GenerationSteering;
24
26
  readonly hidesHeldText: boolean;
@@ -42,8 +44,6 @@ export declare class ModelCaller {
42
44
  private projectedMessages;
43
45
  /** The latest attempt's request; its history is what the step commits. */
44
46
  request: RequestMessages;
45
- /** The latest attempt's tools, which decide how the step's calls defer and end the turn. */
46
- tools: ModelTools | undefined;
47
47
  /** The messages the latest attempt sent, after attachments were hydrated. */
48
48
  modelMessages: ModelMessage[];
49
49
  requestEnvelopeTokens: number;
@@ -76,7 +76,5 @@ export declare class ModelCaller {
76
76
  private attempt;
77
77
  /** Streams the call, publishing its content as it arrives. */
78
78
  private stream;
79
- /** Runs the call without a listener: nothing streams. */
80
- private generate;
81
79
  }
82
80
  export {};
@@ -1 +1 @@
1
- import{buildGatewayAttributionHeaders}from"./model.js";import{isEmptyModelResponse,rethrowNoOutputAsEmptyResponse}from"./recovery.js";import{modelInstructions,requestMessages,withTrailingUserNote}from"./request.js";import{answerSkippedToolCalls,appendMissingToolResultMessages,extractToolResultCallIds,withAccumulatedResponseMessages}from"./response.js";import{runModelCallWithRetries}from"./retry.js";import{logToolExecutionError,prepareModelTools}from"./tools.js";import{extractGatewayCostUsd,extractTokenUsageDelta}from"./usage.js";import{ToolLoopAgent,isStepCount}from"ai";import{createLogger,logError}from"#internal/logging.js";import{AuthKey,HistoryStateKey}from"#context/keys.js";import{createStepCompletedEvent}from"#protocol/message.js";import{activeTurnId}from"#harness/session-machine/view.js";import{addTurnUsage}from"#harness/turn-tag-state.js";import{hydrateSandboxAttachments,moveToolResultFilesToUserMessages}from"#harness/attachment-staging.js";import{discardAttempt}from"#harness/session-machine/transitions.js";import{throwIfTurnAborted}from"#harness/turn-cancellation.js";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{estimateTokens}from"#harness/token-estimate.js";import{ContentFilteredModelResponseError,EmptyModelResponseError}from"#harness/model-call/errors.js";import{resolveModelProfile}from"#harness/model-profile.js";import{estimateRequestEnvelope}from"#harness/request-envelope.js";import{workingTaskIds}from"#execution/tasks/model-step.js";import{interruptStreamOnFailure}from"#harness/interruptible-stream.js";import{buildToolApproval}from"#harness/tools.js";import{compactPrompt,projectPrompt,withClientContext}from"#harness/step/prompt.js";import{emitStreamContent}from"#harness/emission.js";import{FINAL_OUTPUT_TOOL_NAME}from"#harness/final-output.js";import{buildStepHooks,emitStepActions,readGatewayGenerationId}from"#harness/step-hooks.js";import{maybeCompact}from"#harness/compaction/step.js";const environment=process.env.NODE_ENV??`unknown`,log=createLogger(`harness.tool-loop`);var ModelCaller=class{profile;attributionHeaders;projectedMessages;request;tools;modelMessages=[];requestEnvelopeTokens=0;interruptedUsage;compactionFailure;attemptIndex=0;step;prompt;input;constructor(e,t,n){this.step=e,this.prompt=t,this.input=n,this.profile=resolveModelProfile(n.model),this.attributionHeaders=buildGatewayAttributionHeaders(this.profile,e.config.runtimeIdentity),this.projectedMessages=n.projectedMessages,this.request=this.buildRequest(e.config.tools)}async call(e){let t=new Map;return await runModelCallWithRetries(async n=>(n>1&&(await this.settleRetriedActions(t),t=new Map),await this.attempt({...e,suppressStepStartedEmission:n!==1||e.suppressStepStartedEmission},t)),{canRetry:()=>this.compactionFailure===void 0,sessionId:this.step.session.sessionId,turnId:this.step.position().turnId},this.input.generation.signal)}async settleRetriedActions(e){for(let[t,n]of e)await this.step.apply(discardAttempt(this.step.view(),{calls:[{callId:t,toolName:n}]})),e.delete(t)}throwIfCompactionFailed(){if(this.compactionFailure!==void 0)throw this.compactionFailure.error}async steered(){let{step:e}=this;return throwIfTurnAborted(e.config.abortSignal),e.ctx?.set(HistoryStateKey,this.request.historyState),this.interruptedUsage!==void 0&&(e.session=addTurnUsage(e.session,e.position().turnId,this.interruptedUsage)),await e.emit?.(createStepCompletedEvent({...e.position(),finishReason:`other`,usage:this.interruptedUsage})),{next:e.runStep,session:{...e.session,history:[...this.request.history]},steered:!0}}clearInterruptedUsage(){this.interruptedUsage=void 0}buildRequest(e){return requestMessages(this.step,{coordinationTools:e,hidesHeldText:this.input.hidesHeldText,messages:this.prompt.messages,pendingApprovalsNote:this.input.pendingApprovalsNote,projectedMessages:this.projectedMessages,turnMessages:this.input.turnMessages})}instructions(e){return modelInstructions({anthropicCache:this.profile.anthropicCache,extraSystemNote:e,session:this.step.session,systemMessages:this.request.systemMessages})}async prepare(e){let t=await prepareModelTools(this.step,{approvedTools:this.input.approvedTools,disabledProviderTools:e.disabledProviderTools,generation:this.input.generation,profile:this.profile});return this.tools=t,this.request=this.buildRequest(t.coordinationTools),this.requestEnvelopeTokens=await estimateRequestEnvelope({history:this.projectedMessages,instructions:this.instructions(e.extraSystemNote),messages:withTrailingUserNote(this.request.nonSystemMessages,e.trailingUserNote),tools:t.effectiveTools}),t}async compact(e,t){let{step:n,prompt:r}=this,{config:i}=n,a;try{if(a=await maybeCompact({abortSignal:i.abortSignal,auth:n.ctx?.get(AuthKey)??null,emissionState:n.position(),historyProjector:i.historyProjector,messages:[...r.messages],model:this.input.model,promptMessages:withClientContext(r),publish:n.publish,requestEnvelopeTokens:this.requestEnvelopeTokens,resolveModel:i.resolveModel,runtimeIdentity:i.runtimeIdentity,session:n.session,telemetry:n.instrumentation?.telemetry()}),a.failure!==void 0)throw a.failure.error}catch(e){throw this.compactionFailure={error:e},e}if(n.session=a.session,!a.compacted)return t;compactPrompt(n,r,a.messages);let{compaction:o}=n.session;return n.session={...n.session,compaction:{recentWindowSize:o.recentWindowSize,threshold:o.threshold,thresholdPercent:o.thresholdPercent}},this.projectedMessages=projectPrompt(n,r),await this.prepare(e)}async attempt(e,t){let{step:n}=this,{generation:r,model:i}=this.input,a=await this.compact(e,await this.prepare(e));this.requestEnvelopeTokens=Math.max(0,this.requestEnvelopeTokens-(estimateTokens(this.request.history)-estimateTokens(this.prompt.messages))),r.begin(),this.modelMessages=await hydrateSandboxAttachments(this.request.nonSystemMessages),this.profile.filesOutsideToolResults&&(this.modelMessages=moveToolResultFilesToUserMessages(this.modelMessages));let o=this.instructions(e.extraSystemNote),s=n.instrumentation?.resolveRuntimeContext({emissionState:n.position(),environment,modelInput:{instructions:o,messages:this.modelMessages},session:n.session})??{};e.retryReason&&(s[`eve.retry.reason`]=e.retryReason);let c=withTrailingUserNote(this.modelMessages,e.trailingUserNote),l=n.position(),u=n.instrumentation?.prepareAttempt({isFrameworkTool:e=>n.frameworkToolNames.has(e),attemptIndex:this.attemptIndex++,runtimeContext:s,stepIndex:l.stepIndex,turnId:activeTurnId(l)});this.input.setAttemptScope(u?.scope);let d=buildStepHooks({auth:n.ctx?.get(AuthKey)??null,profile:this.profile,session:n.session,startStep:e.suppressStepStartedEmission===!0?void 0:this.input.startStep}),f={headers:this.attributionHeaders,instructions:o,model:i,onLanguageModelCallEnd:e=>{r.interrupted||(this.interruptedUsage=extractTokenUsageDelta({costUsd:extractGatewayCostUsd(e.providerMetadata),usage:e.usage}))},onToolExecutionEnd:logToolExecutionError,onError(e){r.interrupted||summarizeKnownError(e.error)?.tags.includes(`config`)!==!0&&logError(log,`tool-loop stream error`,e.error)},onStepEnd:d.onStepEnd,onStepStart:d.onStepStart,prepareStep:d.prepareStep,reasoning:n.session.agent.modelReference?.reasoning??n.session.agent.reasoning,runtimeContext:s,stopWhen:isStepCount(1),telemetry:u?.telemetry,toolApproval:buildToolApproval(a.modelTools,r.signal),tools:a.effectiveTools},p=new ToolLoopAgent(f);try{let e=n.emit===void 0?await this.generate(p,c,d.stepResult):await this.stream(p,c,d.stepResult,a,t);return await u?.complete(),e}catch(e){return r.interrupted?await u?.complete():await u?.fail(e),r.check(),rethrowNoOutputAsEmptyResponse(e)}}async stream(e,t,n,r,i){let{step:a}=this,{generation:o}=this.input,s=new Set([FINAL_OUTPUT_TOOL_NAME]),c=await e.stream({abortSignal:o.signal,messages:t}),{emittedActionCallIds:l,handledInlineToolResultCallIds:u,invalidInputToolCallIds:d,inlineAuthorizationResults:f,trailingInlineToolResultParts:p}=await emitStreamContent(a.publish,a.position(),interruptStreamOnFailure(c.fullStream,o.signal),{excludedActionToolNames:s,hidesHeldText:this.input.hidesHeldText&&workingTaskIds(a.session).length>0,tools:r.presentationTools,unsettledActionToolNames:i});throwIfTurnAborted(a.config.abortSignal),o.check();let[m,h]=await Promise.all([n,c.responseMessages]);assertUsableResponse(m,h,f.length>0||p.length>0);let g=answerSkippedToolCalls(m,r.effectiveTools);await emitStepActions(a.publish,a.position(),g.length===0?m:withAccumulatedResponseMessages({stepResult:m,responseMessages:appendMissingToolResultMessages({append:g,responseMessages:m.response.messages})}),{emittedActionCallIds:l,excludedActionCallIds:d,excludedActionToolNames:s,handledInlineToolResultCallIds:u,tools:r.presentationTools});let _=new Map(m.toolResults.map(e=>[e.toolCallId,e]));for(let e of f)_.set(e.toolCallId,e);return withAccumulatedResponseMessages({invalidInputToolCallIds:d,responseMessages:appendMissingToolResultMessages({append:[...p,...answerSkippedToolCalls(m,r.effectiveTools)],responseMessages:h}),stepResult:m,toolResults:[..._.values()]})}async generate(e,t,n){let{generation:r}=this.input,i=await e.generate({abortSignal:r.signal,messages:t});throwIfTurnAborted(this.step.config.abortSignal),r.check();let a=await n;return assertUsableResponse(a,i.responseMessages,!1),withAccumulatedResponseMessages({responseMessages:appendMissingToolResultMessages({append:answerSkippedToolCalls(a,this.tools.effectiveTools),responseMessages:i.responseMessages}),stepResult:a})}};function assertUsableResponse(e,t,n){if(e.finishReason===`content-filter`)throw new ContentFilteredModelResponseError(readGatewayGenerationId(e.providerMetadata));if(isEmptyModelResponse(e)&&extractToolResultCallIds(t).size===0&&!n)throw new EmptyModelResponseError}export{ModelCaller};
1
+ import{buildGatewayAttributionHeaders}from"./model.js";import{isEmptyModelResponse,rethrowNoOutputAsEmptyResponse}from"./recovery.js";import{modelInstructions,requestMessages,withTrailingUserNote}from"./request.js";import{answerSkippedToolCalls,appendMissingToolResultMessages,extractToolResultCallIds,withAccumulatedResponseMessages}from"./response.js";import{runModelCallWithRetries}from"./retry.js";import{logToolExecutionError,prepareModelTools}from"./tools.js";import{extractGatewayCostUsd,extractTokenUsageDelta}from"./usage.js";import{ToolLoopAgent,isStepCount}from"ai";import{createLogger,logError}from"#internal/logging.js";import{AuthKey,HistoryStateKey}from"#context/keys.js";import{REPLY_TOOL_NAME}from"#protocol/reply-tool.js";import{createStepCompletedEvent}from"#protocol/message.js";import{activeTurnId}from"#harness/session-machine/view.js";import{addTurnUsage}from"#harness/turn-tag-state.js";import{hydrateSandboxAttachments,moveToolResultFilesToUserMessages}from"#harness/attachment-staging.js";import{workingTaskIds}from"#execution/tasks/model-step.js";import{toEntryStep,toEntryStream,toEntryTelemetry}from"#harness/execute-call.js";import{discardAttempt}from"#harness/session-machine/transitions.js";import{throwIfTurnAborted}from"#harness/turn-cancellation.js";import{summarizeKnownError}from"#harness/semantic-errors/index.js";import{estimateTokens}from"#harness/token-estimate.js";import{requireSessionModelReference}from"#harness/types.js";import{ContentFilteredModelResponseError,EmptyModelResponseError}from"#harness/model-call/errors.js";import{resolveModelProfile}from"#harness/model-profile.js";import{estimateRequestEnvelope}from"#harness/request-envelope.js";import{interruptStreamOnFailure}from"#harness/interruptible-stream.js";import{buildToolApproval}from"#harness/tools.js";import{compactPrompt,projectPrompt,withClientContext}from"#harness/step/prompt.js";import{emitStreamContent}from"#harness/emission.js";import{buildStepHooks,emitStepActions,readGatewayGenerationId}from"#harness/step-hooks.js";import{maybeCompact}from"#harness/compaction/step.js";const environment=process.env.NODE_ENV??`unknown`,log=createLogger(`harness.tool-loop`);var ModelCaller=class{profile;attributionHeaders;projectedMessages;request;modelMessages=[];requestEnvelopeTokens=0;interruptedUsage;compactionFailure;attemptIndex=0;step;prompt;input;constructor(e,t,n){this.step=e,this.prompt=t,this.input=n,this.profile=resolveModelProfile(n.model,requireSessionModelReference(e.session).promptCache),this.attributionHeaders=buildGatewayAttributionHeaders(this.profile,e.config.runtimeIdentity),this.projectedMessages=n.projectedMessages,this.request=this.buildRequest()}async call(e){let t=new Map;return await runModelCallWithRetries(async n=>(n>1&&(await this.settleRetriedActions(t),t=new Map),await this.attempt({...e,suppressStepStartedEmission:n!==1||e.suppressStepStartedEmission},t)),{canRetry:()=>this.compactionFailure===void 0,sessionId:this.step.session.sessionId,turnId:this.step.position().turnId},this.input.generation.signal)}async settleRetriedActions(e){for(let[t,n]of e)await this.step.apply(discardAttempt(this.step.view(),{calls:[{callId:t,toolName:n}]})),e.delete(t)}throwIfCompactionFailed(){if(this.compactionFailure!==void 0)throw this.compactionFailure.error}async steered(){let{step:e}=this;return throwIfTurnAborted(e.config.abortSignal),e.ctx?.set(HistoryStateKey,this.request.historyState),this.interruptedUsage!==void 0&&(e.session=addTurnUsage(e.session,e.position().turnId,this.interruptedUsage)),await e.emit?.(createStepCompletedEvent({...e.position(),finishReason:`other`,usage:this.interruptedUsage})),{next:e.runStep,session:{...e.session,history:[...this.request.history]},steered:!0}}clearInterruptedUsage(){this.interruptedUsage=void 0}buildRequest(){return requestMessages(this.step,{catalog:this.input.catalog,hidesHeldText:this.input.hidesHeldText,messages:this.prompt.messages,pendingApprovalsNote:this.input.pendingApprovalsNote,projectedMessages:this.projectedMessages,turnMessages:this.input.turnMessages})}instructions(e){return modelInstructions({anthropicCache:this.profile.anthropicCache,extraSystemNote:e,session:this.step.session,systemMessages:this.request.systemMessages})}async prepare(e){let t=await prepareModelTools(this.step,{catalog:this.input.catalog,disabledProviderTools:e.disabledProviderTools,generation:this.input.generation,profile:this.profile});return this.request=this.buildRequest(),this.requestEnvelopeTokens=await estimateRequestEnvelope({history:this.projectedMessages,instructions:this.instructions(e.extraSystemNote),messages:withTrailingUserNote(this.request.nonSystemMessages,e.trailingUserNote),tools:t}),t}async compact(e,t){let{step:n,prompt:r}=this,{config:i}=n,a;try{if(a=await maybeCompact({abortSignal:i.abortSignal,auth:n.ctx?.get(AuthKey)??null,emissionState:n.position(),historyProjector:i.historyProjector,messages:[...r.messages],model:this.input.model,promptMessages:withClientContext(r),publish:n.publish,requestEnvelopeTokens:this.requestEnvelopeTokens,resolveModel:i.resolveModel,runtimeIdentity:i.runtimeIdentity,session:n.session,telemetry:n.instrumentation?.telemetry()}),a.failure!==void 0)throw a.failure.error}catch(e){throw this.compactionFailure={error:e},e}if(n.session=a.session,!a.compacted)return t;compactPrompt(n,r,a.messages);let{compaction:o}=n.session;return n.session={...n.session,compaction:{recentWindowSize:o.recentWindowSize,threshold:o.threshold,thresholdPercent:o.thresholdPercent}},this.projectedMessages=projectPrompt(n,r),await this.prepare(e)}async attempt(e,t){let{step:n}=this,{catalog:r,generation:i,model:a}=this.input,o=await this.compact(e,await this.prepare(e));this.requestEnvelopeTokens=Math.max(0,this.requestEnvelopeTokens-(estimateTokens(this.request.history)-estimateTokens(this.prompt.messages))),i.begin(),this.modelMessages=await hydrateSandboxAttachments(this.request.nonSystemMessages),this.profile.filesOutsideToolResults&&(this.modelMessages=moveToolResultFilesToUserMessages(this.modelMessages));let s=this.instructions(e.extraSystemNote),c=n.instrumentation?.resolveRuntimeContext({emissionState:n.position(),environment,modelInput:{instructions:s,messages:this.modelMessages},session:n.session})??{};e.retryReason&&(c[`eve.retry.reason`]=e.retryReason);let l=withTrailingUserNote(this.modelMessages,e.trailingUserNote),u=n.position(),d=n.instrumentation?.prepareAttempt({isFrameworkTool:e=>n.frameworkToolNames.has(e),attemptIndex:this.attemptIndex++,runtimeContext:c,stepIndex:u.stepIndex,turnId:activeTurnId(u)});this.input.setAttemptScope(d?.scope);let f=buildStepHooks({auth:n.ctx?.get(AuthKey)??null,profile:this.profile,session:n.session,startStep:e.suppressStepStartedEmission===!0?void 0:this.input.startStep}),p={headers:this.attributionHeaders,instructions:s,model:a,onLanguageModelCallEnd:e=>{i.interrupted||(this.interruptedUsage=extractTokenUsageDelta({costUsd:extractGatewayCostUsd(e.providerMetadata),usage:e.usage}))},onToolExecutionEnd:e=>logToolExecutionError(e,r.resolve),onError(e){i.interrupted||summarizeKnownError(e.error)?.tags.includes(`config`)!==!0&&logError(log,`tool-loop stream error`,e.error)},onStepEnd:f.onStepEnd,onStepStart:f.onStepStart,prepareStep:f.prepareStep,reasoning:n.session.agent.modelReference?.reasoning??n.session.agent.reasoning,runtimeContext:c,stopWhen:isStepCount(1),telemetry:toEntryTelemetry(d?.telemetry,r.resolve),toolApproval:buildToolApproval({abortSignal:i.signal,approvedTools:this.input.approvedTools,resolve:r.resolve}),tools:o},m=new ToolLoopAgent(p);try{let e=await this.stream(m,l,f.stepResult,t);return await d?.complete(),e}catch(e){return i.interrupted?await d?.complete():await d?.fail(e),i.check(),rethrowNoOutputAsEmptyResponse(e)}}async stream(e,t,n,r){let{step:i}=this,{catalog:a,generation:o}=this.input,s=new Set([REPLY_TOOL_NAME]),c=await e.stream({abortSignal:o.signal,messages:t}),{emittedActionCallIds:l,handledInlineToolResultCallIds:u,invalidInputToolCallIds:d,inlineAuthorizationResults:f,trailingInlineToolResultParts:p}=await emitStreamContent(i.publish,i.position(),toEntryStream(interruptStreamOnFailure(c.fullStream,o.signal),a.resolve),{excludedActionToolNames:s,hidesHeldText:this.input.hidesHeldText&&workingTaskIds(i.session).length>0,tools:a,unsettledActionToolNames:r});throwIfTurnAborted(i.config.abortSignal),o.check();let[m,h]=toEntryStep(...await Promise.all([n,c.responseMessages]),a.resolve);assertUsableResponse(m,h,f.length>0||p.length>0);let g=answerSkippedToolCalls(m,a);await emitStepActions(i.publish,i.position(),g.length===0?m:withAccumulatedResponseMessages({stepResult:m,responseMessages:appendMissingToolResultMessages({append:g,responseMessages:m.response.messages})}),{emittedActionCallIds:l,excludedActionCallIds:d,excludedActionToolNames:s,handledInlineToolResultCallIds:u,tools:a});let _=new Map(m.toolResults.map(e=>[e.toolCallId,e]));for(let e of f)_.set(e.toolCallId,e);return withAccumulatedResponseMessages({invalidInputToolCallIds:d,responseMessages:appendMissingToolResultMessages({append:[...p,...answerSkippedToolCalls(m,a)],responseMessages:h}),stepResult:m,toolResults:[..._.values()]})}};function assertUsableResponse(e,t,n){if(e.finishReason===`content-filter`)throw new ContentFilteredModelResponseError(readGatewayGenerationId(e.providerMetadata));if(isEmptyModelResponse(e)&&extractToolResultCallIds(t).size===0&&!n)throw new EmptyModelResponseError}export{ModelCaller};
@@ -18,13 +18,12 @@ export interface UpstreamRejectionSummary {
18
18
  */
19
19
  export declare function extractUpstreamRejectionMessage(error: unknown): UpstreamRejectionSummary | null;
20
20
  /**
21
- * Returns the distinct upstream tool types referenced by any
22
- * "tool type 'X' is not supported" rejection in an AI Gateway error's
23
- * provider attempt list.
21
+ * Returns the distinct upstream identifiers named by any unsupported provider tool rejection
22
+ * (see {@link UNSUPPORTED_PROVIDER_TOOL_MATCHERS}) in a model-call error.
24
23
  *
25
- * Walks the cause chain to find the gateway error and inspects both the
26
- * structured `data` field and the raw `responseBody` JSON. Returns an
27
- * empty array for errors that are not of this shape.
24
+ * Walks the cause chain and inspects both the structured `data` field and
25
+ * the raw `responseBody` JSON. Returns an empty array for errors that are
26
+ * not of this shape.
28
27
  *
29
28
  * Used by the harness recovery path to identify which framework tools
30
29
  * to drop before retrying the failing step. Detection is by string