stitchkit 0.135.1 → 0.136.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -0
- package/README.md +37 -11
- package/dist/agent-executor/acp/v1-session-build.d.ts +51 -0
- package/dist/agent-executor/acp/v1-session-build.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-session.d.ts +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/claude/classify.d.ts +1 -1
- package/dist/agent-executor/claude/classify.d.ts.map +1 -1
- package/dist/agent-executor/claude/events-wire.d.ts +13 -0
- package/dist/agent-executor/claude/events-wire.d.ts.map +1 -0
- package/dist/agent-executor/claude/events.d.ts +1 -11
- package/dist/agent-executor/claude/events.d.ts.map +1 -1
- package/dist/agent-executor/codex/protocol.d.ts +0 -143
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
- package/dist/agent-executor/codex/server-requests.d.ts +150 -0
- package/dist/agent-executor/codex/server-requests.d.ts.map +1 -0
- package/dist/agent-executor/executor-contract.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +10 -3
- package/dist/agent-executor/image-input.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-scenarios.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -1
- package/dist/agent-executor/vocabulary.d.ts +80 -0
- package/dist/agent-executor/vocabulary.d.ts.map +1 -1
- package/dist/agent-parts/model.d.ts +94 -0
- package/dist/agent-parts/model.d.ts.map +1 -1
- package/dist/agent-parts/parts.d.ts +176 -0
- package/dist/agent-parts/parts.d.ts.map +1 -1
- package/dist/agent-runtime/browser/browser-control-contract.d.ts +444 -0
- package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -1
- package/dist/agent-runtime/browser/control-schema.d.ts +532 -0
- package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/browser/control-view.d.ts.map +1 -1
- package/dist/agent-runtime/event-schema.d.ts +720 -3
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/history/run-history-parts.d.ts.map +1 -1
- package/dist/agent-runtime/loop/deferred-tools.d.ts.map +1 -1
- package/dist/agent-runtime/loop/invocation-payload.d.ts.map +1 -1
- package/dist/agent-runtime/loop/invocation-stream.d.ts +9 -1
- package/dist/agent-runtime/loop/invocation-stream.d.ts.map +1 -1
- package/dist/agent-runtime/loop/provider-stream-parts.d.ts +6 -0
- package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/loop/provider-stream-segments.d.ts +1 -3
- package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-acquisition.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-approval-signature.d.ts +38 -0
- package/dist/agent-runtime/loop/run-approval-signature.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-approval.d.ts +0 -28
- package/dist/agent-runtime/loop/run-approval.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-complete-port.d.ts +24 -0
- package/dist/agent-runtime/loop/run-complete-port.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-complete-stream.d.ts +7 -2
- package/dist/agent-runtime/loop/run-complete-stream.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-complete-types.d.ts +14 -1
- package/dist/agent-runtime/loop/run-complete-types.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-complete.d.ts +2 -2
- package/dist/agent-runtime/loop/run-complete.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-execution-state.d.ts +8 -0
- package/dist/agent-runtime/loop/run-execution-state.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-loop-events.d.ts +6 -1
- package/dist/agent-runtime/loop/run-loop-events.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-model-call.d.ts +44 -0
- package/dist/agent-runtime/loop/run-model-call.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-model-step.d.ts +25 -28
- package/dist/agent-runtime/loop/run-model-step.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-model-steps.d.ts +6 -0
- package/dist/agent-runtime/loop/run-model-steps.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-model-stream.d.ts +3 -1
- package/dist/agent-runtime/loop/run-model-stream.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts +0 -2
- package/dist/agent-runtime/loop/run-operation-lifecycle.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-step-loop.d.ts +19 -0
- package/dist/agent-runtime/loop/run-step-loop.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-step-port.d.ts +175 -0
- package/dist/agent-runtime/loop/run-step-port.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-stream-recorded.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-stream-step-text.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts +2 -1
- package/dist/agent-runtime/loop/run-tool-approval-flow.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-tool-call-input.d.ts +39 -0
- package/dist/agent-runtime/loop/run-tool-call-input.d.ts.map +1 -0
- package/dist/agent-runtime/loop/run-tool-call.d.ts +13 -34
- package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-tool-errors.d.ts +5 -0
- package/dist/agent-runtime/loop/run-tool-errors.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-tool-executor.d.ts +1 -1
- package/dist/agent-runtime/loop/run-tool-executor.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-tool-slots.d.ts +2 -1
- package/dist/agent-runtime/loop/run-tool-slots.d.ts.map +1 -1
- package/dist/agent-runtime/loop/runtime-state.d.ts.map +1 -1
- package/dist/agent-runtime/loop/runtime.d.ts +0 -5
- package/dist/agent-runtime/loop/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/providers/ai-sdk-convert.d.ts +1 -5
- package/dist/agent-runtime/providers/ai-sdk-convert.d.ts.map +1 -1
- package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts +15 -0
- package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts.map +1 -0
- package/dist/agent-runtime/providers/ai-sdk-tools.d.ts +11 -0
- package/dist/agent-runtime/providers/ai-sdk-tools.d.ts.map +1 -0
- package/dist/agent-runtime/providers/ai-sdk.d.ts +1 -9
- package/dist/agent-runtime/providers/ai-sdk.d.ts.map +1 -1
- package/dist/agent-runtime/providers/anthropic-sse.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-admission.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-audio.d.ts +123 -81
- package/dist/agent-runtime/providers/openrouter-audio.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-catalog-cache.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-catalog-query.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-catalog.d.ts +2 -2
- package/dist/agent-runtime/providers/openrouter-catalog.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-client.d.ts +37 -0
- package/dist/agent-runtime/providers/openrouter-client.d.ts.map +1 -0
- package/dist/agent-runtime/providers/openrouter-http.d.ts +26 -6
- package/dist/agent-runtime/providers/openrouter-http.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-media.d.ts +91 -77
- package/dist/agent-runtime/providers/openrouter-media.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-models.d.ts +2 -23
- package/dist/agent-runtime/providers/openrouter-models.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-options.d.ts +2 -0
- package/dist/agent-runtime/providers/openrouter-options.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-request.d.ts +23 -0
- package/dist/agent-runtime/providers/openrouter-request.d.ts.map +1 -0
- package/dist/agent-runtime/providers/openrouter-retrieval.d.ts +86 -55
- package/dist/agent-runtime/providers/openrouter-retrieval.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-speech.d.ts +90 -0
- package/dist/agent-runtime/providers/openrouter-speech.d.ts.map +1 -0
- package/dist/agent-runtime/providers/openrouter-spend.d.ts +2 -2
- package/dist/agent-runtime/providers/openrouter-spend.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-stream.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-systemone.d.ts +87 -32
- package/dist/agent-runtime/providers/openrouter-systemone.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-url.d.ts +7 -1
- package/dist/agent-runtime/providers/openrouter-url.d.ts.map +1 -1
- package/dist/agent-runtime/providers/openrouter-wire.d.ts +45 -0
- package/dist/agent-runtime/providers/openrouter-wire.d.ts.map +1 -0
- package/dist/agent-runtime/providers/openrouter.d.ts +1 -3
- package/dist/agent-runtime/providers/openrouter.d.ts.map +1 -1
- package/dist/agent-runtime/providers/provider-http.d.ts +14 -2
- package/dist/agent-runtime/providers/provider-http.d.ts.map +1 -1
- package/dist/agent-runtime/providers/provider-json-schema-strip.d.ts.map +1 -1
- package/dist/agent-runtime/providers/provider-json-schema.d.ts.map +1 -1
- package/dist/agent-runtime/providers/provider-openai-chat-sse.d.ts.map +1 -1
- package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts +42 -0
- package/dist/agent-runtime/providers/provider-openai-chat-state.d.ts.map +1 -0
- package/dist/agent-runtime/providers/provider-usage.d.ts +9 -0
- package/dist/agent-runtime/providers/provider-usage.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-internals.d.ts +1 -3
- package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts +9 -0
- package/dist/agent-runtime/sandbox/sandbox-bubblewrap-args.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts +6 -0
- package/dist/agent-runtime/sandbox/sandbox-bubblewrap.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox/sandbox-contract.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox/sandbox-process-linux.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts +5 -1
- package/dist/agent-runtime/sandbox/sandbox-process-spec.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox/sandbox-process-wrapper.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-json-projection.d.ts +29 -0
- package/dist/agent-runtime/schemas-json-projection.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-message.d.ts +88 -0
- package/dist/agent-runtime/schemas-message.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-run.d.ts +88 -0
- package/dist/agent-runtime/schemas-run.d.ts.map +1 -1
- package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/stores/branch-observations.d.ts +42 -42
- package/dist/agent-runtime/stores/branch-replay.d.ts +264 -0
- package/dist/agent-runtime/stores/branch-replay.d.ts.map +1 -1
- package/dist/agent-runtime/stores/conversations.d.ts +88 -0
- package/dist/agent-runtime/stores/conversations.d.ts.map +1 -1
- package/dist/agent-runtime/stores/sql-rows.d.ts +74 -10
- package/dist/agent-runtime/stores/sql-rows.d.ts.map +1 -1
- package/dist/agent-runtime/stores/store-driver-contract.d.ts +616 -0
- package/dist/agent-runtime/stores/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/stores/store-events.d.ts +1056 -0
- package/dist/agent-runtime/stores/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/stores/store.d.ts +1232 -0
- package/dist/agent-runtime/stores/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +74 -10
- package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
- package/dist/agent-runtime/testing/fault-bench.d.ts +5 -1
- package/dist/agent-runtime/testing/fault-bench.d.ts.map +1 -1
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +158 -30
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts.map +1 -1
- package/dist/agent-runtime/testing/store-conformance-support.d.ts +79 -15
- package/dist/agent-runtime/testing/store-conformance-support.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-manager.d.ts +1 -1
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
- package/dist/application/notification-delivery.d.ts.map +1 -1
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/client-url.d.ts.map +1 -1
- package/dist/contract/define.d.ts +3 -7
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/normalize.d.ts +17 -5
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +9 -6
- package/dist/entrypoints/agent-executor/claude-sdk.js +26 -25
- package/dist/entrypoints/agent-executor/claude.js +13 -12
- package/dist/entrypoints/agent-executor/codex.d.ts +2 -1
- package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/codex.js +135 -40
- package/dist/entrypoints/agent-executor/testing/claude-sdk.js +5 -4
- package/dist/entrypoints/agent-executor/testing.js +23 -18
- package/dist/entrypoints/agent-executor.js +8 -8
- package/dist/entrypoints/agent-runtime/ai-sdk.d.ts +2 -1
- package/dist/entrypoints/agent-runtime/ai-sdk.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/ai-sdk.js +34 -30
- package/dist/entrypoints/agent-runtime/anthropic.js +15 -12
- package/dist/entrypoints/agent-runtime/browser.js +13 -8
- package/dist/entrypoints/agent-runtime/harness.js +26 -27
- package/dist/entrypoints/agent-runtime/openai.js +7 -7
- package/dist/entrypoints/agent-runtime/openrouter.d.ts +7 -5
- package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +1097 -856
- package/dist/entrypoints/agent-runtime/postgres.js +9 -9
- package/dist/entrypoints/agent-runtime/realtime.js +9 -8
- package/dist/entrypoints/agent-runtime/sandbox.js +167 -139
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +10 -10
- package/dist/entrypoints/agent-runtime/sqlite/node.js +10 -10
- package/dist/entrypoints/agent-runtime/testing.js +9 -9
- package/dist/entrypoints/agent-runtime.js +261 -375
- package/dist/entrypoints/application/diagnostic-journal.js +14 -10
- package/dist/entrypoints/application.js +18 -6
- package/dist/entrypoints/cli.js +36 -15
- package/dist/entrypoints/contract.js +12 -10
- package/dist/entrypoints/geo.js +1 -1
- package/dist/entrypoints/handler.js +5 -6
- package/dist/entrypoints/http.d.ts +2 -0
- package/dist/entrypoints/http.d.ts.map +1 -1
- package/dist/entrypoints/http.js +16 -4
- package/dist/entrypoints/index.js +26 -35
- package/dist/entrypoints/live.js +3 -3
- package/dist/entrypoints/node.js +7 -7
- package/dist/entrypoints/observability.js +9 -7
- package/dist/entrypoints/process.js +3 -3
- package/dist/entrypoints/remote.js +5 -5
- package/dist/entrypoints/server.js +29 -16
- package/dist/entrypoints/telegram/grammy.d.ts +1 -1
- package/dist/entrypoints/telegram/grammy.d.ts.map +1 -1
- package/dist/entrypoints/telegram/grammy.js +39 -5
- package/dist/entrypoints/telegram/screens.js +3 -0
- package/dist/entrypoints/telegram.d.ts +1 -1
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +19 -6
- package/dist/entrypoints/testing.js +10 -11
- package/dist/entrypoints/tools/agent.js +9 -10
- package/dist/entrypoints/tools/connections.js +27 -57
- package/dist/entrypoints/tools/contract.js +4 -4
- package/dist/entrypoints/tools/invoker.js +7 -8
- package/dist/entrypoints/tools/mcp.js +9 -10
- package/dist/entrypoints/tools/toolkit.js +11 -12
- package/dist/entrypoints/tools.js +24 -22
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/tracking/performance.js +1 -1
- package/dist/entrypoints/tracking.js +1 -1
- package/dist/{index-3czc3ykr.js → index-08a3qfr8.js} +1 -1
- package/dist/index-1psbyyhj.js +21 -0
- package/dist/{index-pdcbjd6a.js → index-1yky29qg.js} +6 -3
- package/dist/{index-b4c9dpzm.js → index-252den5a.js} +10 -11
- package/dist/{index-yhwx4fwk.js → index-26v8hjqm.js} +4 -4
- package/dist/{index-xtby8rj3.js → index-28kbdn63.js} +5 -47
- package/dist/{index-c24bj2r1.js → index-2wm9b9vs.js} +5 -5
- package/dist/{index-ht71v1ag.js → index-32ew02z1.js} +60 -45
- package/dist/{index-dm84tsd5.js → index-3kb8dw48.js} +1 -1
- package/dist/index-3tb82xr7.js +11 -0
- package/dist/{index-nr4fhfn4.js → index-4p2zx593.js} +2 -0
- package/dist/{index-grhhsrd5.js → index-4q9tmzea.js} +5 -4
- package/dist/{index-mcv7b2n0.js → index-63ctzjp4.js} +497 -495
- package/dist/{index-y0a4gt1s.js → index-65p8v81y.js} +3 -2
- package/dist/{index-z72vazf5.js → index-6y3eae97.js} +27 -83
- package/dist/{index-y0mwkgkf.js → index-8cnfgwg8.js} +1212 -1139
- package/dist/{index-mkmep637.js → index-9m1m92rg.js} +1 -1
- package/dist/{index-5awtbyns.js → index-9vj869rx.js} +1 -1
- package/dist/index-a1rjr381.js +114 -0
- package/dist/{index-6kwdfb9m.js → index-akesakvj.js} +23 -4
- package/dist/{index-5q0qpw3v.js → index-aqm7e864.js} +23 -8
- package/dist/{index-d4at0q09.js → index-b9mj31q7.js} +90 -88
- package/dist/{index-baba8ehy.js → index-bjrcbcn2.js} +2 -2
- package/dist/{index-fsw9wxk9.js → index-c9j8441q.js} +1 -103
- package/dist/{index-wdb5jhas.js → index-d1pdv8qc.js} +1 -1
- package/dist/{index-v0j22shs.js → index-d5mhgx72.js} +16 -11
- package/dist/{index-73wq9abg.js → index-df5xr2f9.js} +13 -59
- package/dist/{index-n9358ydy.js → index-dm50x3by.js} +1 -1
- package/dist/{index-zyyerdny.js → index-dmrx8xma.js} +3 -0
- package/dist/{index-78da4g74.js → index-dwq6a6sq.js} +17 -13
- package/dist/{index-9be3tf6r.js → index-e413q2cj.js} +49 -22
- package/dist/{index-57sbckhv.js → index-e4w0sfm1.js} +2 -2
- package/dist/{index-g4gstmp1.js → index-ednf2cxs.js} +1 -1
- package/dist/{index-84tp547a.js → index-edpkm3k7.js} +29 -97
- package/dist/{index-gs0jw0hy.js → index-efbzm2se.js} +3 -3
- package/dist/{index-asnd4h2k.js → index-f0dzyskg.js} +27 -4
- package/dist/{index-xbb8ysmq.js → index-fatke81t.js} +2 -2
- package/dist/{index-d3s070eh.js → index-gj4wdts6.js} +1 -1
- package/dist/{index-6nzzj7qr.js → index-gq35s3bm.js} +1 -1
- package/dist/index-gvgtmt7a.js +102 -0
- package/dist/{index-pd9e8rz4.js → index-gvv7y0s4.js} +1 -1
- package/dist/{index-m2b49tvc.js → index-h08xqfw9.js} +20 -21
- package/dist/{index-gk6dq9ay.js → index-ha1tv70k.js} +3 -26
- package/dist/{index-vebzvse6.js → index-jy907kcs.js} +24 -1
- package/dist/{index-q86qnzzf.js → index-k5azb3v3.js} +8 -25
- package/dist/{index-qcy8et93.js → index-kaq9nb7h.js} +6 -6
- package/dist/{index-vse7x1qt.js → index-knqye3gv.js} +1 -1
- package/dist/{index-tav72wz5.js → index-ks4rhtcc.js} +5 -0
- package/dist/{index-bvpevwt6.js → index-mtpcax6d.js} +210 -205
- package/dist/{index-7qza24g1.js → index-px9r6wv1.js} +1 -1
- package/dist/{index-x6sp5vpa.js → index-q4tr9vnf.js} +1 -1
- package/dist/{index-hce3hbdg.js → index-qj0sq69b.js} +6 -2
- package/dist/{index-de7b0kvz.js → index-r9w7wfgn.js} +2 -2
- package/dist/{index-8vzh5wpv.js → index-rw1caff2.js} +14 -26
- package/dist/index-s8af9jqw.js +6 -0
- package/dist/{index-bgj9hbm3.js → index-sdppfbrh.js} +30 -16
- package/dist/{index-aacwkve4.js → index-sjq4akrx.js} +3 -5
- package/dist/{index-fec05c9k.js → index-ta0e2daw.js} +9 -7
- package/dist/{index-5dxgx3yj.js → index-tcv71frn.js} +1 -1
- package/dist/{index-1zy31r3b.js → index-v92djygb.js} +1 -1
- package/dist/{index-c0yym4a0.js → index-w7e402wx.js} +11 -105
- package/dist/{index-9f60gnfn.js → index-xaa3603f.js} +4 -11
- package/dist/index-xrbrvn15.js +147 -0
- package/dist/{index-ac3rfec5.js → index-y6wzzk2e.js} +21 -1
- package/dist/{index-3d2c45jn.js → index-yjx5jna7.js} +2 -2
- package/dist/{index-j3r7r1mh.js → index-yv7d6tav.js} +1 -1
- package/dist/{index-wsv11dhg.js → index-zagc12j1.js} +5 -5
- package/dist/{index-npfdymav.js → index-zqc64g69.js} +3 -3
- package/dist/{index-rkphknhx.js → index-zthekmrt.js} +2 -2
- package/dist/internal/json-stringify.d.ts +37 -0
- package/dist/internal/json-stringify.d.ts.map +1 -0
- package/dist/internal/loopback-host.d.ts +8 -0
- package/dist/internal/loopback-host.d.ts.map +1 -0
- package/dist/internal/own-member.d.ts +7 -0
- package/dist/internal/own-member.d.ts.map +1 -0
- package/dist/internal/request.d.ts +17 -8
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/secret-shapes.d.ts +33 -4
- package/dist/internal/secret-shapes.d.ts.map +1 -1
- package/dist/json-schema/dialect.d.ts.map +1 -1
- package/dist/json-schema/keywords.d.ts +25 -6
- package/dist/json-schema/keywords.d.ts.map +1 -1
- package/dist/json-schema/string-format.d.ts.map +1 -1
- package/dist/live/events.d.ts.map +1 -1
- package/dist/live/watch-client.d.ts.map +1 -1
- package/dist/live/watch-delta.d.ts.map +1 -1
- package/dist/observability/context.d.ts +4 -3
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/sanitize.d.ts.map +1 -1
- package/dist/observability/secret-values.d.ts +0 -9
- package/dist/observability/secret-values.d.ts.map +1 -1
- package/dist/server/context.d.ts +3 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +4 -3
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/event-bus.d.ts.map +1 -1
- package/dist/server/file.d.ts +11 -3
- package/dist/server/file.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +2 -2
- package/dist/server/handler-state.d.ts.map +1 -1
- package/dist/server/middleware/jwt.d.ts +12 -1
- package/dist/server/middleware/jwt.d.ts.map +1 -1
- package/dist/server/middleware/trust-fence.d.ts +4 -0
- package/dist/server/middleware/trust-fence.d.ts.map +1 -1
- package/dist/server/multipart.d.ts +2 -3
- package/dist/server/multipart.d.ts.map +1 -1
- package/dist/server/raw.d.ts.map +1 -1
- package/dist/server/request-body.d.ts +12 -1
- package/dist/server/request-body.d.ts.map +1 -1
- package/dist/server/request-completion.d.ts.map +1 -1
- package/dist/server/types.d.ts +14 -9
- package/dist/server/types.d.ts.map +1 -1
- package/dist/telegram/crypto.d.ts.map +1 -1
- package/dist/telegram/init-data.d.ts +4 -4
- package/dist/telegram/init-data.d.ts.map +1 -1
- package/dist/telegram/outbound-cost.d.ts.map +1 -1
- package/dist/telegram/screens/test-chat.d.ts.map +1 -1
- package/dist/telegram/widget-api.d.ts +85 -13
- package/dist/telegram/widget-api.d.ts.map +1 -1
- package/dist/telegram/widget.d.ts +46 -2
- package/dist/telegram/widget.d.ts.map +1 -1
- package/dist/tools/cli/args-classify.d.ts +4 -74
- package/dist/tools/cli/args-classify.d.ts.map +1 -1
- package/dist/tools/cli/args-framework.d.ts +79 -0
- package/dist/tools/cli/args-framework.d.ts.map +1 -0
- package/dist/tools/cli/args-scan.d.ts.map +1 -1
- package/dist/tools/cli/args-tokens.d.ts.map +1 -1
- package/dist/tools/cli/checkpoint.d.ts +5 -0
- package/dist/tools/cli/checkpoint.d.ts.map +1 -1
- package/dist/tools/cli/stream.d.ts.map +1 -1
- package/dist/tools/connections/foreign-schema-join.d.ts.map +1 -1
- package/dist/tools/connections/openapi.d.ts.map +1 -1
- package/dist/tools/connections/runtime.d.ts.map +1 -1
- package/dist/tools/execute-handler.d.ts +24 -0
- package/dist/tools/execute-handler.d.ts.map +1 -0
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/mcp/round.d.ts.map +1 -1
- package/dist/tools/schema/coerce.d.ts.map +1 -1
- package/dist/tools/schema/flatten.d.ts.map +1 -1
- package/dist/tools/schema/inline-references.d.ts.map +1 -1
- package/dist/tools/schema/nesting-limit.d.ts.map +1 -1
- package/dist/tools/schema/presentation.d.ts.map +1 -1
- package/dist/tracking/privacy.d.ts.map +1 -1
- package/llms/agent-runtime-openrouter.txt +10 -9
- package/llms/agent-runtime-sandbox.txt +50 -11
- package/llms/agent-runtime-testing.txt +1 -1
- package/llms/agent-runtime.2.txt +9 -6
- package/llms/agent-runtime.3.txt +2 -2
- package/llms/agent-runtime.4.txt +11 -5
- package/llms/agent-runtime.5.txt +2 -2
- package/llms/agent-runtime.txt +297 -36
- package/llms/application.2.txt +6 -3
- package/llms/application.3.txt +2 -1
- package/llms/application.txt +7 -2
- package/llms/http.txt +1 -1
- package/llms/live.txt +3 -1
- package/llms/observability.txt +16 -9
- package/llms/server.2.txt +13 -8
- package/llms/server.4.txt +23 -11
- package/llms/server.5.txt +5 -5
- package/llms/server.txt +54 -1
- package/llms/spend.txt +1 -0
- package/llms/stitchkit.2.txt +4 -2
- package/llms/stitchkit.txt +113 -93
- package/llms/telegram-grammy.txt +3 -2
- package/llms/telegram.2.txt +3 -1
- package/llms/telegram.txt +35 -10
- package/llms/upgrading-0.128.0-0.129.0.txt +175 -0
- package/llms/{upgrading-0.128.0-0.135.0.txt → upgrading-0.130.0-0.136.0.txt} +353 -169
- package/llms/upgrading.txt +2 -1
- package/llms-full.txt +1021 -223
- package/llms.txt +14 -13
- package/package.json +6 -6
- package/dist/agent-runtime/loop/deferred-tools-internal.d.ts +0 -19
- package/dist/agent-runtime/loop/deferred-tools-internal.d.ts.map +0 -1
- package/dist/agent-runtime/loop/run-complete-retry.d.ts +0 -24
- package/dist/agent-runtime/loop/run-complete-retry.d.ts.map +0 -1
- package/dist/agent-runtime/loop/run-model-attempts.d.ts +0 -6
- package/dist/agent-runtime/loop/run-model-attempts.d.ts.map +0 -1
- package/dist/index-sznqf8fx.js +0 -20
- /package/dist/{index-fthw8dwa.js → index-4gbybjg6.js} +0 -0
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
AgentModelAssistantMessageSchema2,
|
|
14
14
|
AgentModelToolMessageSchema2,
|
|
15
15
|
AgentModelMessageSchema2
|
|
16
|
-
} from "../index-
|
|
16
|
+
} from "../index-jy907kcs.js";
|
|
17
17
|
import {
|
|
18
18
|
createBoundedSinkManager
|
|
19
19
|
} from "../index-7an2fs5h.js";
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
AgentUsageValueSchema2,
|
|
36
36
|
AgentCostValueSchema2,
|
|
37
37
|
AgentUsageSchema2
|
|
38
|
-
} from "../index-
|
|
38
|
+
} from "../index-yv7d6tav.js";
|
|
39
39
|
import {
|
|
40
40
|
AgentProviderEnvelopeSchema2,
|
|
41
41
|
AgentTextPartSchema2,
|
|
@@ -49,10 +49,10 @@ import {
|
|
|
49
49
|
AgentOpaquePartSchema2,
|
|
50
50
|
AgentControlPartSchema2,
|
|
51
51
|
AgentMessagePartSchema2
|
|
52
|
-
} from "../index-
|
|
52
|
+
} from "../index-ks4rhtcc.js";
|
|
53
53
|
import {
|
|
54
54
|
AgentProviderResponseSchema2
|
|
55
|
-
} from "../index-
|
|
55
|
+
} from "../index-px9r6wv1.js";
|
|
56
56
|
import {
|
|
57
57
|
AgentRunStateSchema2,
|
|
58
58
|
AgentRunQueuePrioritySchema2,
|
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
AgentRunSchema2,
|
|
65
65
|
AgentSnapshotSchema2,
|
|
66
66
|
AgentRunMetricsSchema2
|
|
67
|
-
} from "../index-
|
|
67
|
+
} from "../index-gvv7y0s4.js";
|
|
68
68
|
import {
|
|
69
69
|
AgentAdmissionEventSchema2,
|
|
70
70
|
AgentTransientDeltaEventSchema2,
|
|
@@ -82,14 +82,7 @@ import {
|
|
|
82
82
|
AgentRuntimeEventCursorSchema2,
|
|
83
83
|
advanceAgentRuntimeEventCursor2,
|
|
84
84
|
agentDurableEventId2
|
|
85
|
-
} from "../index-
|
|
86
|
-
import {
|
|
87
|
-
AgentRuntimeConflictError2,
|
|
88
|
-
AgentRunUnsettledError2,
|
|
89
|
-
parseOptionalAgentUsage,
|
|
90
|
-
addUsage,
|
|
91
|
-
createIdleDeadline
|
|
92
|
-
} from "../index-9f60gnfn.js";
|
|
85
|
+
} from "../index-4q9tmzea.js";
|
|
93
86
|
import {
|
|
94
87
|
PurgeInvocationPayloadsInputSchema2,
|
|
95
88
|
PurgeInvocationPayloadsResultSchema2,
|
|
@@ -131,18 +124,17 @@ import {
|
|
|
131
124
|
AgentSeedReceiptSchema2,
|
|
132
125
|
AgentHistoryMutationSchema2,
|
|
133
126
|
ACTIVE_AGENT_RUN_STATES2
|
|
134
|
-
} from "../index-
|
|
135
|
-
import"../index-
|
|
136
|
-
import"../index-
|
|
137
|
-
import"../index-78da4g74.js";
|
|
127
|
+
} from "../index-kaq9nb7h.js";
|
|
128
|
+
import"../index-ha1tv70k.js";
|
|
129
|
+
import"../index-d1pdv8qc.js";
|
|
138
130
|
import"../index-dsa676h8.js";
|
|
139
|
-
import"../index-
|
|
140
|
-
import"../index-
|
|
131
|
+
import"../index-dm50x3by.js";
|
|
132
|
+
import"../index-qj0sq69b.js";
|
|
141
133
|
import {
|
|
142
134
|
resolveToolAccess
|
|
143
|
-
} from "../index-
|
|
135
|
+
} from "../index-b9mj31q7.js";
|
|
144
136
|
import"../index-yt1gg11x.js";
|
|
145
|
-
import"../index-
|
|
137
|
+
import"../index-edpkm3k7.js";
|
|
146
138
|
import"../index-werjqesf.js";
|
|
147
139
|
import {
|
|
148
140
|
DeferredAgentToolSearchInputSchema2,
|
|
@@ -179,7 +171,7 @@ import {
|
|
|
179
171
|
createAgentEventSearchTools2,
|
|
180
172
|
AgentStoreUnsupportedCapabilityError2,
|
|
181
173
|
createAgentRuntimeStore2
|
|
182
|
-
} from "../index-
|
|
174
|
+
} from "../index-d5mhgx72.js";
|
|
183
175
|
import {
|
|
184
176
|
AgentContextOverflowError2,
|
|
185
177
|
unknownUsage,
|
|
@@ -187,17 +179,11 @@ import {
|
|
|
187
179
|
projectAgentHistoryDetailed2,
|
|
188
180
|
projectAgentHistory2,
|
|
189
181
|
createAgentSessionCoordinator2,
|
|
190
|
-
registerDeferredToolRepair,
|
|
191
|
-
deferredToolRepair,
|
|
192
|
-
markDeferredRepairWrapper,
|
|
193
|
-
chainRepairHooks,
|
|
194
|
-
registerDeferredToolCatalog,
|
|
195
|
-
deferredToolCatalog,
|
|
196
|
-
repairedSearchCall,
|
|
197
182
|
InvocationPayloadTooLargeError2,
|
|
198
183
|
markProviderOrigin,
|
|
199
184
|
hasProviderOrigin,
|
|
200
185
|
currentModelInvocationAttempt2,
|
|
186
|
+
providerToolActed,
|
|
201
187
|
consumeStandaloneDriverStream,
|
|
202
188
|
createModelInvocationLedger2,
|
|
203
189
|
createAgentToolFenceLifecycle2,
|
|
@@ -213,18 +199,15 @@ import {
|
|
|
213
199
|
AgentToolApprovalError2,
|
|
214
200
|
AgentInvalidToolApprovalSignatureError2,
|
|
215
201
|
AgentToolCallNotFoundForApprovalError2,
|
|
202
|
+
mergeStepCallSettings,
|
|
216
203
|
AgentStepBarrierError2,
|
|
217
204
|
assertStandaloneStepBarriers,
|
|
218
205
|
createToolDependencyResolver2,
|
|
219
|
-
buildActiveToolSpecs,
|
|
220
|
-
mergeStepCallSettings,
|
|
221
|
-
isStepUnsafeForClientTools,
|
|
222
|
-
buildStepTimings,
|
|
223
|
-
assembleStepResult,
|
|
224
206
|
AgentUnknownToolError2,
|
|
225
207
|
AgentInvalidToolInputError2,
|
|
226
|
-
|
|
227
|
-
|
|
208
|
+
runModelStepLoop,
|
|
209
|
+
initialStepLoopState,
|
|
210
|
+
resolveIdleTimeoutMs,
|
|
228
211
|
defineStateSlot2,
|
|
229
212
|
createAgentStateSlotStore2,
|
|
230
213
|
renderAgentStateSlots2,
|
|
@@ -234,9 +217,9 @@ import {
|
|
|
234
217
|
AgentTokenCountSchema2,
|
|
235
218
|
selectAgentHistory2,
|
|
236
219
|
composeAgentPrompt2
|
|
237
|
-
} from "../index-
|
|
220
|
+
} from "../index-8cnfgwg8.js";
|
|
238
221
|
import"../index-m38ej7e5.js";
|
|
239
|
-
import"../index-
|
|
222
|
+
import"../index-dmrx8xma.js";
|
|
240
223
|
import {
|
|
241
224
|
DURABILITY_STEP_EVENT_KIND2,
|
|
242
225
|
StepResultDecodeError2,
|
|
@@ -272,13 +255,20 @@ import {
|
|
|
272
255
|
AgentConversationSummarySchema2,
|
|
273
256
|
AgentConversationPageSchema2,
|
|
274
257
|
AgentConversationMessagePageSchema2
|
|
275
|
-
} from "../index-
|
|
258
|
+
} from "../index-v92djygb.js";
|
|
276
259
|
import"../index-6kec3b14.js";
|
|
277
260
|
import"../index-tgehj4bp.js";
|
|
278
261
|
import"../index-5c4m8zdf.js";
|
|
279
262
|
import {
|
|
280
263
|
createMemoryAgentRuntimeStore2
|
|
281
|
-
} from "../index-
|
|
264
|
+
} from "../index-zqc64g69.js";
|
|
265
|
+
import {
|
|
266
|
+
AgentRuntimeConflictError2,
|
|
267
|
+
AgentRunUnsettledError2,
|
|
268
|
+
parseOptionalAgentUsage,
|
|
269
|
+
addUsage,
|
|
270
|
+
createIdleDeadline
|
|
271
|
+
} from "../index-xaa3603f.js";
|
|
282
272
|
import {
|
|
283
273
|
isAssistantHistoryEvidence2,
|
|
284
274
|
isCompleteAgentHistoryTurn
|
|
@@ -286,43 +276,41 @@ import {
|
|
|
286
276
|
import"../index-p9cab61p.js";
|
|
287
277
|
import {
|
|
288
278
|
createAgentRuntimeEventSink2
|
|
289
|
-
} from "../index-
|
|
279
|
+
} from "../index-gj4wdts6.js";
|
|
290
280
|
import {
|
|
291
281
|
isObjectSchemaType,
|
|
292
282
|
stripStrictOptionalNulls
|
|
293
|
-
} from "../index-
|
|
283
|
+
} from "../index-6y3eae97.js";
|
|
294
284
|
import {
|
|
295
285
|
AgentProviderError2,
|
|
296
286
|
AgentProviderStreamCutError2,
|
|
297
287
|
isAgentProviderError2,
|
|
298
288
|
classifyProviderFailure2,
|
|
299
289
|
isToolResultFailure2
|
|
300
|
-
} from "../index-
|
|
290
|
+
} from "../index-knqye3gv.js";
|
|
301
291
|
import {
|
|
302
292
|
buildToolManifest2
|
|
303
|
-
} from "../index-
|
|
304
|
-
import"../index-
|
|
305
|
-
import"../index-
|
|
306
|
-
import"../index-
|
|
293
|
+
} from "../index-08a3qfr8.js";
|
|
294
|
+
import"../index-fatke81t.js";
|
|
295
|
+
import"../index-gq35s3bm.js";
|
|
296
|
+
import"../index-4gbybjg6.js";
|
|
307
297
|
import {
|
|
308
298
|
rankToolsByQuery
|
|
309
299
|
} from "../index-kne9g2c5.js";
|
|
310
300
|
import {
|
|
311
301
|
zodToAgentInputJsonSchema,
|
|
312
302
|
mountAgentTools2
|
|
313
|
-
} from "../index-
|
|
303
|
+
} from "../index-k5azb3v3.js";
|
|
314
304
|
import"../index-rjs94dny.js";
|
|
315
305
|
import"../index-xrgn784x.js";
|
|
316
|
-
import"../index-
|
|
306
|
+
import"../index-bjrcbcn2.js";
|
|
317
307
|
import {
|
|
318
308
|
defineRuntimeTool2,
|
|
319
309
|
executableAgentRuntimeTools
|
|
320
310
|
} from "../index-7csn6pva.js";
|
|
321
311
|
import {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
SCHEMA_MAP_KEYWORDS
|
|
325
|
-
} from "../index-9be3tf6r.js";
|
|
312
|
+
mapSubschemas
|
|
313
|
+
} from "../index-e413q2cj.js";
|
|
326
314
|
import {
|
|
327
315
|
createTraceContext2,
|
|
328
316
|
childSpan2
|
|
@@ -682,6 +670,13 @@ function createDeferredSearchTool(config, runContext, surface) {
|
|
|
682
670
|
}
|
|
683
671
|
|
|
684
672
|
// src/agent-runtime/loop/deferred-tools.ts
|
|
673
|
+
function repairedSearchCall(toolCall, searchName) {
|
|
674
|
+
return {
|
|
675
|
+
...toolCall,
|
|
676
|
+
toolName: searchName,
|
|
677
|
+
input: JSON.stringify({ query: toolCall.toolName, reason: "inactive_call" })
|
|
678
|
+
};
|
|
679
|
+
}
|
|
685
680
|
function configuredSurfaces(config) {
|
|
686
681
|
return "surfaces" in config ? config.surfaces : { default: config };
|
|
687
682
|
}
|
|
@@ -795,14 +790,15 @@ function createDeferredAgentToolSurface(config) {
|
|
|
795
790
|
const projection = surfaceProjection(config);
|
|
796
791
|
const surfaces = resolveAllSurfaces(config, projection);
|
|
797
792
|
assertConstructionBudgets(config, surfaces);
|
|
798
|
-
const
|
|
793
|
+
const catalog = new Set([...surfaces.values()].flatMap((surface) => [...surface.byName.keys()]));
|
|
794
|
+
const baseRepair = ({
|
|
799
795
|
toolCall,
|
|
800
796
|
activeTools,
|
|
801
797
|
tools,
|
|
802
798
|
error
|
|
803
799
|
}) => {
|
|
804
|
-
const
|
|
805
|
-
if (error.kind !== "unknown-tool" || !catalog
|
|
800
|
+
const name = toolCall.toolName;
|
|
801
|
+
if (error.kind !== "unknown-tool" || !catalog.has(name) || !Object.hasOwn(tools, name) || !Object.hasOwn(tools, config.search.name) || activeTools.includes(name)) {
|
|
806
802
|
return null;
|
|
807
803
|
}
|
|
808
804
|
return repairedSearchCall(toolCall, config.search.name);
|
|
@@ -816,14 +812,11 @@ function createDeferredAgentToolSurface(config) {
|
|
|
816
812
|
...executableAgentRuntimeTools(surface.definition.runtimeTools ?? []),
|
|
817
813
|
createDeferredSearchTool(config, runContext, surface)
|
|
818
814
|
];
|
|
819
|
-
|
|
815
|
+
return mountAgentTools2([...surface.definition.services ?? []], {
|
|
820
816
|
...mountConfig,
|
|
821
817
|
...projection,
|
|
822
818
|
runtimeTools
|
|
823
819
|
});
|
|
824
|
-
registerDeferredToolCatalog(tools, config.search.name, new Set(surface.byName.keys()));
|
|
825
|
-
registerDeferredToolRepair(tools, baseRepair, config.search.name);
|
|
826
|
-
return tools;
|
|
827
820
|
},
|
|
828
821
|
prepareStep(applicationPrepareStep) {
|
|
829
822
|
const prepared = async (input) => {
|
|
@@ -867,8 +860,7 @@ function createDeferredAgentToolSurface(config) {
|
|
|
867
860
|
repairToolCall(applicationRepairToolCall) {
|
|
868
861
|
if (!applicationRepairToolCall)
|
|
869
862
|
return baseRepair;
|
|
870
|
-
|
|
871
|
-
return markDeferredRepairWrapper(composed, baseRepair);
|
|
863
|
+
return async (input) => await applicationRepairToolCall(input) ?? baseRepair(input);
|
|
872
864
|
}
|
|
873
865
|
};
|
|
874
866
|
}
|
|
@@ -1003,9 +995,6 @@ function createAgentObservability(config) {
|
|
|
1003
995
|
close: (bound) => manager.close(bound)
|
|
1004
996
|
};
|
|
1005
997
|
}
|
|
1006
|
-
// src/agent-runtime/loop/run-complete-retry.ts
|
|
1007
|
-
import { setTimeout as delay } from "node:timers/promises";
|
|
1008
|
-
|
|
1009
998
|
// src/agent-runtime/loop/run-complete-types.ts
|
|
1010
999
|
class AgentStructuredOutputError extends Error {
|
|
1011
1000
|
reason;
|
|
@@ -1037,147 +1026,223 @@ class AgentRetryExhaustedError extends Error {
|
|
|
1037
1026
|
}
|
|
1038
1027
|
}
|
|
1039
1028
|
|
|
1040
|
-
// src/agent-runtime/loop/run-complete-
|
|
1041
|
-
|
|
1029
|
+
// src/agent-runtime/loop/run-complete-port.ts
|
|
1030
|
+
function buildCompleteStepRequest(params) {
|
|
1031
|
+
const { input, prepared } = params;
|
|
1032
|
+
const toolChoice = prepared?.toolChoice ?? input.toolChoice;
|
|
1033
|
+
const responseFormat = prepared?.responseFormat ?? input.responseFormat;
|
|
1034
|
+
const cacheControl = prepared?.cacheControl ?? input.cacheControl;
|
|
1035
|
+
const providerOptions = prepared?.providerOptions ?? input.providerOptions;
|
|
1036
|
+
const headers = prepared?.headers ?? input.headers;
|
|
1037
|
+
return {
|
|
1038
|
+
instructions: normalizeAgentInstructions(params.instructions),
|
|
1039
|
+
messages: params.messages,
|
|
1040
|
+
tools: params.specs,
|
|
1041
|
+
...toolChoice !== undefined && { toolChoice },
|
|
1042
|
+
...responseFormat !== undefined && { responseFormat },
|
|
1043
|
+
...cacheControl !== undefined && { cacheControl },
|
|
1044
|
+
settings: mergeStepCallSettings(input.settings, prepared),
|
|
1045
|
+
...providerOptions !== undefined && { providerOptions },
|
|
1046
|
+
...headers !== undefined && { headers },
|
|
1047
|
+
correlation: {
|
|
1048
|
+
conversationId: params.conversationId,
|
|
1049
|
+
...input.correlation?.runId !== undefined && { runId: input.correlation.runId },
|
|
1050
|
+
...input.correlation?.invocationId !== undefined && {
|
|
1051
|
+
invocationId: input.correlation.invocationId
|
|
1052
|
+
},
|
|
1053
|
+
attemptId: input.correlation?.attemptId ?? params.callId,
|
|
1054
|
+
step: params.stepNumber
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
function idleTimeoutError(driver, idleTimeoutMs, cause) {
|
|
1059
|
+
return markProviderOrigin(new AgentProviderError2(`Provider stream idle timeout after ${idleTimeoutMs}ms`, {
|
|
1060
|
+
provider: driver.provider,
|
|
1061
|
+
failureReason: "timeout",
|
|
1062
|
+
...cause !== undefined && { cause }
|
|
1063
|
+
}));
|
|
1064
|
+
}
|
|
1065
|
+
function consumerStallError(driver, idleTimeoutMs, cause) {
|
|
1066
|
+
return new AgentProviderError2(`Completion consumer held a part for ${idleTimeoutMs}ms; the provider stream was not read`, {
|
|
1067
|
+
provider: driver.provider,
|
|
1068
|
+
failureReason: "timeout",
|
|
1069
|
+
...cause !== undefined && { cause }
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
async function streamStandaloneCall(input) {
|
|
1042
1073
|
const stepAbort = new AbortController;
|
|
1043
|
-
const
|
|
1044
|
-
const idleDeadline = createIdleDeadline(baseSignal, input.idleTimeoutMs);
|
|
1074
|
+
const idleDeadline = createIdleDeadline(input.signal, input.idleTimeoutMs);
|
|
1045
1075
|
const link = linkAbortSignals(idleDeadline.signal, stepAbort.signal);
|
|
1046
1076
|
const stepStartedAt = performance.now();
|
|
1077
|
+
let holding = false;
|
|
1078
|
+
let firedWhileHolding = false;
|
|
1079
|
+
const onIdle = () => {
|
|
1080
|
+
firedWhileHolding = holding;
|
|
1081
|
+
};
|
|
1082
|
+
idleDeadline.signal.addEventListener("abort", onIdle, { once: true });
|
|
1083
|
+
const deadlineError = (cause) => firedWhileHolding ? consumerStallError(input.driver, input.idleTimeoutMs, cause) : idleTimeoutError(input.driver, input.idleTimeoutMs, cause);
|
|
1047
1084
|
try {
|
|
1048
1085
|
idleDeadline.start();
|
|
1049
1086
|
let modelStream;
|
|
1050
1087
|
try {
|
|
1051
1088
|
modelStream = await input.driver.stream(input.request, link.signal);
|
|
1052
1089
|
} catch (error) {
|
|
1053
|
-
throw !input.
|
|
1090
|
+
throw !input.callerSignal?.aborted ? markProviderOrigin(error) : error;
|
|
1054
1091
|
}
|
|
1092
|
+
const onPart = input.onPart;
|
|
1055
1093
|
const consumed = await consumeStandaloneDriverStream({
|
|
1056
1094
|
modelStream,
|
|
1057
1095
|
abortAttempt: () => stepAbort.abort(new Error("Completion released provider stream")),
|
|
1058
1096
|
onChunk: () => idleDeadline.touch(),
|
|
1059
|
-
|
|
1060
|
-
|
|
1097
|
+
onProviderPart: (part) => {
|
|
1098
|
+
if (providerToolActed(part))
|
|
1099
|
+
input.onToolPart();
|
|
1100
|
+
},
|
|
1101
|
+
...onPart !== undefined && {
|
|
1102
|
+
onPart: async (part) => {
|
|
1103
|
+
holding = true;
|
|
1104
|
+
try {
|
|
1105
|
+
await onPart(part, link.signal);
|
|
1106
|
+
} finally {
|
|
1107
|
+
holding = false;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1061
1110
|
},
|
|
1062
|
-
captureErrorUsage: input.captureErrorUsage
|
|
1111
|
+
captureErrorUsage: input.captureErrorUsage,
|
|
1112
|
+
signal: idleDeadline.signal
|
|
1063
1113
|
});
|
|
1064
1114
|
const responseFinishedAt = performance.now();
|
|
1065
|
-
if (idleDeadline.signal.aborted && !input.
|
|
1066
|
-
throw
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1115
|
+
if (idleDeadline.signal.aborted && !input.callerSignal?.aborted)
|
|
1116
|
+
throw deadlineError();
|
|
1117
|
+
if (consumed.errorPart !== undefined) {
|
|
1118
|
+
return {
|
|
1119
|
+
kind: "failed",
|
|
1120
|
+
error: markProviderOrigin(consumed.errorPart),
|
|
1121
|
+
...consumed.finishPart && { usage: statedUsage(consumed.finishPart.usage) }
|
|
1122
|
+
};
|
|
1070
1123
|
}
|
|
1071
|
-
return {
|
|
1072
|
-
consumed,
|
|
1073
|
-
...consumed.errorPart !== undefined && { errorPart: consumed.errorPart },
|
|
1074
|
-
stepStartedAt,
|
|
1075
|
-
responseFinishedAt
|
|
1076
|
-
};
|
|
1124
|
+
return { kind: "finished", consumed, stepStartedAt, responseFinishedAt };
|
|
1077
1125
|
} catch (error) {
|
|
1078
|
-
if (idleDeadline.signal.aborted && !input.
|
|
1079
|
-
throw
|
|
1080
|
-
provider: input.driver.provider,
|
|
1081
|
-
failureReason: "timeout",
|
|
1082
|
-
cause: error
|
|
1083
|
-
}));
|
|
1126
|
+
if (idleDeadline.signal.aborted && !input.callerSignal?.aborted && (hasProviderOrigin(error) || error === idleDeadline.signal.reason)) {
|
|
1127
|
+
throw deadlineError(error);
|
|
1084
1128
|
}
|
|
1085
1129
|
throw error;
|
|
1086
1130
|
} finally {
|
|
1131
|
+
idleDeadline.signal.removeEventListener("abort", onIdle);
|
|
1087
1132
|
idleDeadline.dispose();
|
|
1088
1133
|
link.release();
|
|
1089
1134
|
idleDeadline.release();
|
|
1090
1135
|
}
|
|
1091
1136
|
}
|
|
1092
|
-
|
|
1093
|
-
const
|
|
1094
|
-
const
|
|
1095
|
-
const
|
|
1096
|
-
let
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1137
|
+
function createStandaloneStepPort(params) {
|
|
1138
|
+
const { input, emitPart, callerSignal } = params;
|
|
1139
|
+
const signal = callerSignal ?? new AbortController().signal;
|
|
1140
|
+
const conversationId = input.correlation?.conversationId ?? crypto.randomUUID();
|
|
1141
|
+
let stoppedByPolicy;
|
|
1142
|
+
let callInvokedTool = false;
|
|
1143
|
+
const port = {
|
|
1144
|
+
tools: input.tools,
|
|
1145
|
+
baseDriver: input.driver,
|
|
1146
|
+
initialMessages: params.initialMessages,
|
|
1147
|
+
initialInstructions: input.instructions ?? "",
|
|
1148
|
+
signal,
|
|
1149
|
+
repairToolCall: input.repairToolCall,
|
|
1150
|
+
retry: input.retry,
|
|
1151
|
+
...input.onAttemptDiscarded !== undefined && {
|
|
1152
|
+
onAttemptDiscarded: input.onAttemptDiscarded
|
|
1153
|
+
},
|
|
1154
|
+
toolMode: {
|
|
1155
|
+
kind: "standalone",
|
|
1156
|
+
stepBarriers: input.stepBarriers,
|
|
1157
|
+
beforeStepToolCalls: input.beforeStepToolCalls,
|
|
1158
|
+
...emitPart !== undefined && { onPart: emitPart }
|
|
1159
|
+
},
|
|
1160
|
+
startStep: async () => {
|
|
1161
|
+
return;
|
|
1162
|
+
},
|
|
1163
|
+
prepareStep: async (prepareInput) => await input.prepareStep?.(prepareInput) ?? undefined,
|
|
1164
|
+
takeInjectedMessages: async () => [],
|
|
1165
|
+
stepModel: (driver) => ({ provider: driver.provider, modelId: driver.modelId }),
|
|
1166
|
+
newCallId: () => crypto.randomUUID(),
|
|
1167
|
+
openCall: async ({ driver }) => {
|
|
1168
|
+
callInvokedTool = false;
|
|
1169
|
+
return driver;
|
|
1170
|
+
},
|
|
1171
|
+
buildRequest: (request) => buildCompleteStepRequest({ input, conversationId, ...request }),
|
|
1172
|
+
streamCall: (call) => streamStandaloneCall({
|
|
1173
|
+
driver: call.driver,
|
|
1174
|
+
request: call.request,
|
|
1175
|
+
signal,
|
|
1176
|
+
callerSignal,
|
|
1177
|
+
idleTimeoutMs: params.idleTimeoutMs,
|
|
1178
|
+
captureErrorUsage: input.retry !== undefined,
|
|
1179
|
+
onPart: emitPart,
|
|
1180
|
+
onToolPart: () => {
|
|
1181
|
+
callInvokedTool = true;
|
|
1182
|
+
}
|
|
1183
|
+
}),
|
|
1184
|
+
callInvokedTool: () => callInvokedTool,
|
|
1185
|
+
missingFinish: async (_consumed, driver) => {
|
|
1186
|
+
callerSignal?.throwIfAborted();
|
|
1187
|
+
throw markProviderOrigin(new AgentProviderStreamCutError2("Provider stream ended without a finish event", {
|
|
1188
|
+
provider: driver.provider
|
|
1189
|
+
}));
|
|
1190
|
+
},
|
|
1191
|
+
decideRetry: async ({ attempt, failure, elapsedMs }) => input.retry ? resolveAgentRetryDecision({ attempt, failure, policy: input.retry, elapsedMs }) : { retry: false, delayMs: 0 },
|
|
1192
|
+
discardCall: async () => {
|
|
1193
|
+
return;
|
|
1194
|
+
},
|
|
1195
|
+
announceDiscard: async ({ attempt, failure, usage }) => {
|
|
1196
|
+
await emitPart?.({
|
|
1197
|
+
type: "attempt-reset",
|
|
1198
|
+
attempt,
|
|
1199
|
+
reason: failure.reason,
|
|
1200
|
+
...usage !== undefined && { usage }
|
|
1201
|
+
}, callerSignal);
|
|
1202
|
+
},
|
|
1203
|
+
announceRetry: async () => {
|
|
1204
|
+
return;
|
|
1205
|
+
},
|
|
1206
|
+
refuseRetry: ({ error, attempts, usage }) => {
|
|
1207
|
+
const failure = attempts.at(-1)?.failure ?? classifyProviderFailure2(error);
|
|
1208
|
+
if (!input.retry || attempts.length === 1 && (!failure.retryable || callInvokedTool)) {
|
|
1209
|
+
return error;
|
|
1210
|
+
}
|
|
1211
|
+
return new AgentRetryExhaustedError(`Completion failed after ${attempts.length} attempt(s) (${failure.reason})`, {
|
|
1212
|
+
attempts: attempts.map((attempt) => ({
|
|
1213
|
+
attempt: attempt.attempt,
|
|
1214
|
+
error: attempt.error,
|
|
1215
|
+
failure: attempt.failure,
|
|
1216
|
+
...attempt.usage !== undefined && { usage: attempt.usage }
|
|
1217
|
+
})),
|
|
1218
|
+
lastError: error,
|
|
1219
|
+
usage: statedUsage(usage ?? unknownUsage())
|
|
1109
1220
|
});
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1221
|
+
},
|
|
1222
|
+
stepTextOverrides: async () => {
|
|
1223
|
+
return;
|
|
1224
|
+
},
|
|
1225
|
+
finishStep: async ({ stepResult }) => {
|
|
1226
|
+
await emitPart?.({ type: "finish-step", step: stepResult }, callerSignal);
|
|
1227
|
+
await input.onStepFinish?.(stepResult);
|
|
1228
|
+
},
|
|
1229
|
+
shouldStop: async (steps) => {
|
|
1230
|
+
for (const policy of input.stopPolicies ?? []) {
|
|
1231
|
+
if (await policy.when({ steps })) {
|
|
1232
|
+
stoppedByPolicy = policy.name;
|
|
1233
|
+
return true;
|
|
1114
1234
|
}
|
|
1115
|
-
} else if (!outcome.consumed.finishPart) {
|
|
1116
|
-
input.signal?.throwIfAborted();
|
|
1117
|
-
attemptError = markProviderOrigin(new AgentProviderStreamCutError2("Provider stream ended without a finish event", {
|
|
1118
|
-
provider: input.driver.provider
|
|
1119
|
-
}));
|
|
1120
|
-
} else {
|
|
1121
|
-
return {
|
|
1122
|
-
consumed: outcome.consumed,
|
|
1123
|
-
stepStartedAt: outcome.stepStartedAt,
|
|
1124
|
-
responseFinishedAt: outcome.responseFinishedAt,
|
|
1125
|
-
discardedUsage
|
|
1126
|
-
};
|
|
1127
1235
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
if (!retryPolicy)
|
|
1134
|
-
throw attemptError;
|
|
1135
|
-
if (attemptUsage !== undefined) {
|
|
1136
|
-
discardedUsage = addUsage(discardedUsage, attemptUsage);
|
|
1137
|
-
}
|
|
1138
|
-
const failure = classifyProviderFailure2(attemptError);
|
|
1139
|
-
attempts.push({
|
|
1140
|
-
attempt,
|
|
1141
|
-
error: attemptError,
|
|
1142
|
-
failure,
|
|
1143
|
-
...attemptUsage !== undefined && { usage: attemptUsage }
|
|
1144
|
-
});
|
|
1145
|
-
const decision = resolveAgentRetryDecision({
|
|
1146
|
-
attempt,
|
|
1147
|
-
failure,
|
|
1148
|
-
policy: retryPolicy,
|
|
1149
|
-
elapsedMs: Math.max(0, performance.now() - retryWindowStart)
|
|
1150
|
-
});
|
|
1151
|
-
if (!decision.retry) {
|
|
1152
|
-
if (attempts.length === 1 && !failure.retryable)
|
|
1153
|
-
throw attemptError;
|
|
1154
|
-
const accumulated = discardedUsage !== undefined ? addUsage(input.priorUsage, discardedUsage) : input.priorUsage;
|
|
1155
|
-
throw new AgentRetryExhaustedError(`Completion failed after ${attempts.length} attempt(s) (${failure.reason})`, {
|
|
1156
|
-
attempts,
|
|
1157
|
-
lastError: attemptError,
|
|
1158
|
-
usage: statedUsage(accumulated ?? unknownUsage())
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
await input.onAttemptDiscarded?.({
|
|
1162
|
-
attempt,
|
|
1163
|
-
reason: failure.reason,
|
|
1164
|
-
...attemptUsage !== undefined && { usage: attemptUsage }
|
|
1165
|
-
});
|
|
1166
|
-
await input.onPart?.({
|
|
1167
|
-
type: "attempt-reset",
|
|
1168
|
-
attempt,
|
|
1169
|
-
reason: failure.reason,
|
|
1170
|
-
...attemptUsage !== undefined && { usage: attemptUsage }
|
|
1171
|
-
}, input.signal);
|
|
1172
|
-
if (decision.delayMs > 0) {
|
|
1173
|
-
await delay(decision.delayMs, undefined, { signal: input.signal });
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1236
|
+
return steps.length >= params.maxSteps;
|
|
1237
|
+
},
|
|
1238
|
+
afterLastStep: async () => ({ action: "stop" })
|
|
1239
|
+
};
|
|
1240
|
+
return { port, stoppedByPolicy: () => stoppedByPolicy };
|
|
1176
1241
|
}
|
|
1177
1242
|
|
|
1178
1243
|
// src/agent-runtime/loop/run-complete-stream.ts
|
|
1179
1244
|
var STREAM_COMPLETE_BUFFER_LIMIT = 64;
|
|
1180
|
-
var
|
|
1245
|
+
var PARTS_IGNORED_MESSAGE = "streamComplete().parts is not available with parts: 'ignore'; await result, or drop the option to iterate parts";
|
|
1181
1246
|
function discardUncommittedQueueParts(queue) {
|
|
1182
1247
|
let keepCount = 0;
|
|
1183
1248
|
for (let index = queue.length - 1;index >= 0; index -= 1) {
|
|
@@ -1229,7 +1294,7 @@ function createCompleteTextStream(input, runLoop) {
|
|
|
1229
1294
|
let hasFailure = false;
|
|
1230
1295
|
let consumerClosed = false;
|
|
1231
1296
|
let startedIterating = false;
|
|
1232
|
-
|
|
1297
|
+
const ignoreParts = input.parts === "ignore";
|
|
1233
1298
|
let pullWaiter;
|
|
1234
1299
|
const wakePull = () => {
|
|
1235
1300
|
const resolve = pullWaiter;
|
|
@@ -1268,18 +1333,8 @@ function createCompleteTextStream(input, runLoop) {
|
|
|
1268
1333
|
return;
|
|
1269
1334
|
if (waitSignal?.aborted)
|
|
1270
1335
|
throw abortReason(waitSignal);
|
|
1271
|
-
if (
|
|
1336
|
+
if (ignoreParts)
|
|
1272
1337
|
return;
|
|
1273
|
-
if (!startedIterating) {
|
|
1274
|
-
if (queue.length < STREAM_COMPLETE_BUFFER_LIMIT) {
|
|
1275
|
-
queue.push(part);
|
|
1276
|
-
wakePull();
|
|
1277
|
-
return;
|
|
1278
|
-
}
|
|
1279
|
-
queue.length = 0;
|
|
1280
|
-
partsOverflowed = true;
|
|
1281
|
-
return;
|
|
1282
|
-
}
|
|
1283
1338
|
while (queue.length >= STREAM_COMPLETE_BUFFER_LIMIT && !consumerClosed && !link.signal.aborted && !waitSignal?.aborted) {
|
|
1284
1339
|
await waitForQueueCapacity(pushWaiters, waitSignal);
|
|
1285
1340
|
}
|
|
@@ -1336,24 +1391,9 @@ function createCompleteTextStream(input, runLoop) {
|
|
|
1336
1391
|
if (startedIterating) {
|
|
1337
1392
|
throw new TypeError("streamComplete().parts can only be iterated once");
|
|
1338
1393
|
}
|
|
1394
|
+
if (ignoreParts)
|
|
1395
|
+
throw new TypeError(PARTS_IGNORED_MESSAGE);
|
|
1339
1396
|
startedIterating = true;
|
|
1340
|
-
if (partsOverflowed) {
|
|
1341
|
-
return {
|
|
1342
|
-
async next() {
|
|
1343
|
-
while (!done && !consumerClosed) {
|
|
1344
|
-
await new Promise((resolve) => {
|
|
1345
|
-
pullWaiter = resolve;
|
|
1346
|
-
});
|
|
1347
|
-
}
|
|
1348
|
-
if (consumerClosed)
|
|
1349
|
-
return { done: true, value: undefined };
|
|
1350
|
-
if (hasFailure)
|
|
1351
|
-
throw failure;
|
|
1352
|
-
throw new Error(PARTS_OVERFLOW_MESSAGE);
|
|
1353
|
-
},
|
|
1354
|
-
return: closeConsumer
|
|
1355
|
-
};
|
|
1356
|
-
}
|
|
1357
1397
|
return {
|
|
1358
1398
|
async next() {
|
|
1359
1399
|
for (;; ) {
|
|
@@ -1402,34 +1442,6 @@ function assertCompleteStopPolicies(policies) {
|
|
|
1402
1442
|
names.add(policy.name);
|
|
1403
1443
|
}
|
|
1404
1444
|
}
|
|
1405
|
-
function buildCompleteStepRequest(params) {
|
|
1406
|
-
const { input, prepared, stepInstructions, currentMessages, specs } = params;
|
|
1407
|
-
const toolChoice = prepared?.toolChoice ?? input.toolChoice;
|
|
1408
|
-
const responseFormat = prepared?.responseFormat ?? input.responseFormat;
|
|
1409
|
-
const cacheControl = prepared?.cacheControl ?? input.cacheControl;
|
|
1410
|
-
const providerOptions = prepared?.providerOptions ?? input.providerOptions;
|
|
1411
|
-
const headers = prepared?.headers ?? input.headers;
|
|
1412
|
-
return {
|
|
1413
|
-
instructions: normalizeAgentInstructions(stepInstructions),
|
|
1414
|
-
messages: currentMessages,
|
|
1415
|
-
tools: specs,
|
|
1416
|
-
...toolChoice !== undefined && { toolChoice },
|
|
1417
|
-
...responseFormat !== undefined && { responseFormat },
|
|
1418
|
-
...cacheControl !== undefined && { cacheControl },
|
|
1419
|
-
settings: mergeStepCallSettings(input.settings, prepared),
|
|
1420
|
-
...providerOptions !== undefined && { providerOptions },
|
|
1421
|
-
...headers !== undefined && { headers },
|
|
1422
|
-
correlation: {
|
|
1423
|
-
conversationId: params.defaultConversationId,
|
|
1424
|
-
...input.correlation?.runId !== undefined && { runId: input.correlation.runId },
|
|
1425
|
-
...input.correlation?.invocationId !== undefined && {
|
|
1426
|
-
invocationId: input.correlation.invocationId
|
|
1427
|
-
},
|
|
1428
|
-
attemptId: input.correlation?.attemptId ?? params.callId,
|
|
1429
|
-
step: params.stepNumber
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
1445
|
async function finalizeCompleteResult(params) {
|
|
1434
1446
|
const { steps, responseMessages, totalUsage, stoppedByPolicy, emitPart, effectiveSignal } = params;
|
|
1435
1447
|
const lastStep = steps.at(-1);
|
|
@@ -1467,140 +1479,31 @@ async function finalizeCompleteResult(params) {
|
|
|
1467
1479
|
};
|
|
1468
1480
|
}
|
|
1469
1481
|
async function runCompleteLoop(input, emitPart, effectiveSignal) {
|
|
1470
|
-
const
|
|
1471
|
-
const declaredTools = tools ? Object.keys(tools) : [];
|
|
1472
|
-
const repairToolCall = chainRepairHooks(input.repairToolCall, deferredToolRepair(tools));
|
|
1482
|
+
const declaredTools = input.tools ? Object.keys(input.tools) : [];
|
|
1473
1483
|
const maxSteps = input.maxSteps ?? (declaredTools.length > 0 ? 10 : 1);
|
|
1474
1484
|
assertPositiveSafeInteger("completeText.maxSteps", maxSteps, RangeError);
|
|
1475
|
-
|
|
1485
|
+
const idleTimeoutMs = resolveIdleTimeoutMs(input.idleTimeoutMs);
|
|
1486
|
+
assertTimerMs("completeText.idleTimeoutMs", idleTimeoutMs);
|
|
1476
1487
|
if (input.retry)
|
|
1477
1488
|
assertAgentRetryPolicy("completeText.retry", input.retry);
|
|
1478
1489
|
assertCompleteStopPolicies(input.stopPolicies);
|
|
1479
1490
|
assertStandaloneStepBarriers(input.stepBarriers);
|
|
1480
1491
|
const initialMessages = resolveInitialMessages(input);
|
|
1481
|
-
const
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
const prepared = await input.prepareStep?.({
|
|
1492
|
-
stepNumber,
|
|
1493
|
-
steps,
|
|
1494
|
-
messages: currentMessages,
|
|
1495
|
-
responseMessages,
|
|
1496
|
-
initialMessages,
|
|
1497
|
-
initialInstructions,
|
|
1498
|
-
instructions: carriedInstructions,
|
|
1499
|
-
driver: input.driver,
|
|
1500
|
-
activeTools: declaredTools
|
|
1501
|
-
}) ?? undefined;
|
|
1502
|
-
currentMessages = [...prepared?.messages ?? currentMessages];
|
|
1503
|
-
if (prepared?.instructions !== undefined) {
|
|
1504
|
-
carriedInstructions = prepared.instructions;
|
|
1505
|
-
}
|
|
1506
|
-
const stepInstructions = prepared?.instructions ?? carriedInstructions;
|
|
1507
|
-
const { activeNames, specs } = tools ? buildActiveToolSpecs(tools, prepared?.activeTools) : { activeNames: [], specs: [] };
|
|
1508
|
-
const effectiveDriver = prepared?.driver ?? input.driver;
|
|
1509
|
-
const callId = crypto.randomUUID();
|
|
1510
|
-
const request = buildCompleteStepRequest({
|
|
1511
|
-
input,
|
|
1512
|
-
prepared,
|
|
1513
|
-
stepInstructions,
|
|
1514
|
-
currentMessages,
|
|
1515
|
-
specs,
|
|
1516
|
-
defaultConversationId,
|
|
1517
|
-
callId,
|
|
1518
|
-
stepNumber
|
|
1519
|
-
});
|
|
1520
|
-
const callOutcome = await runStepModelCallWithRetry({
|
|
1521
|
-
driver: effectiveDriver,
|
|
1522
|
-
request,
|
|
1523
|
-
signal: effectiveSignal,
|
|
1524
|
-
idleTimeoutMs: input.idleTimeoutMs,
|
|
1525
|
-
retry: input.retry,
|
|
1526
|
-
onAttemptDiscarded: input.onAttemptDiscarded,
|
|
1527
|
-
onPart: emitPart,
|
|
1528
|
-
priorUsage: totalUsage
|
|
1529
|
-
});
|
|
1530
|
-
if (callOutcome.discardedUsage !== undefined) {
|
|
1531
|
-
totalUsage = addUsage(totalUsage, callOutcome.discardedUsage);
|
|
1532
|
-
}
|
|
1533
|
-
const { consumed, stepStartedAt, responseFinishedAt } = callOutcome;
|
|
1534
|
-
const finishPart = consumed.finishPart;
|
|
1535
|
-
if (!finishPart) {
|
|
1536
|
-
throw markProviderOrigin(new AgentProviderStreamCutError2("Provider stream ended without a finish event", {
|
|
1537
|
-
provider: effectiveDriver.provider
|
|
1538
|
-
}));
|
|
1539
|
-
}
|
|
1540
|
-
const unsafeForClientTools = isStepUnsafeForClientTools(finishPart.finishReason, consumed.sawErrorPart);
|
|
1541
|
-
const toolStartedAt = performance.now();
|
|
1542
|
-
const toolExecution = unsafeForClientTools || !tools ? emptyStepToolExecutionResult() : await executeStepToolCalls({
|
|
1543
|
-
stepNumber,
|
|
1544
|
-
rawCalls: consumed.rawToolCalls,
|
|
1545
|
-
tools,
|
|
1546
|
-
activeTools: activeNames,
|
|
1547
|
-
repairToolCall,
|
|
1548
|
-
instructions: request.instructions,
|
|
1549
|
-
messages: currentMessages,
|
|
1550
|
-
signal: effectiveSignal ?? new AbortController().signal,
|
|
1551
|
-
mode: {
|
|
1552
|
-
kind: "standalone",
|
|
1553
|
-
stepBarriers: input.stepBarriers,
|
|
1554
|
-
beforeStepToolCalls: input.beforeStepToolCalls,
|
|
1555
|
-
...emitPart !== undefined && { onPart: emitPart }
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1558
|
-
const stepFinishedAt = performance.now();
|
|
1559
|
-
const toolExecutionMs = unsafeForClientTools || !tools ? 0 : Math.max(0, stepFinishedAt - toolStartedAt);
|
|
1560
|
-
const timings = buildStepTimings({
|
|
1561
|
-
stepStartedAt,
|
|
1562
|
-
responseFinishedAt,
|
|
1563
|
-
stepFinishedAt,
|
|
1564
|
-
firstOutputAt: consumed.firstOutputAt,
|
|
1565
|
-
toolExecutionMs,
|
|
1566
|
-
outputChunkTimestamps: consumed.outputChunkTimestamps
|
|
1567
|
-
});
|
|
1568
|
-
const stepUsage = statedUsage(finishPart.usage);
|
|
1569
|
-
totalUsage = addUsage(totalUsage, stepUsage);
|
|
1570
|
-
const { stepResponseMessages, stepResult } = assembleStepResult({
|
|
1571
|
-
stepNumber,
|
|
1572
|
-
callId,
|
|
1573
|
-
model: { provider: effectiveDriver.provider, modelId: effectiveDriver.modelId },
|
|
1574
|
-
consumed,
|
|
1575
|
-
finishPart,
|
|
1576
|
-
toolExecution,
|
|
1577
|
-
timings,
|
|
1578
|
-
stepUsage
|
|
1579
|
-
});
|
|
1580
|
-
currentMessages = [...currentMessages, ...stepResponseMessages];
|
|
1581
|
-
responseMessages.push(...stepResponseMessages);
|
|
1582
|
-
steps.push(stepResult);
|
|
1583
|
-
await emitPart?.({ type: "finish-step", step: stepResult }, effectiveSignal);
|
|
1584
|
-
await input.onStepFinish?.(stepResult);
|
|
1585
|
-
const canContinue = !unsafeForClientTools && toolExecution.clientToolCallCount > 0 && toolExecution.settledClientToolCount === toolExecution.clientToolCallCount;
|
|
1586
|
-
if (!canContinue)
|
|
1587
|
-
break;
|
|
1588
|
-
let halted = false;
|
|
1589
|
-
for (const policy of input.stopPolicies ?? []) {
|
|
1590
|
-
if (await policy.when({ steps })) {
|
|
1591
|
-
stoppedByPolicy = policy.name;
|
|
1592
|
-
halted = true;
|
|
1593
|
-
break;
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
if (halted)
|
|
1597
|
-
break;
|
|
1598
|
-
}
|
|
1492
|
+
const { port, stoppedByPolicy } = createStandaloneStepPort({
|
|
1493
|
+
input,
|
|
1494
|
+
initialMessages,
|
|
1495
|
+
maxSteps,
|
|
1496
|
+
idleTimeoutMs,
|
|
1497
|
+
emitPart,
|
|
1498
|
+
callerSignal: effectiveSignal
|
|
1499
|
+
});
|
|
1500
|
+
const state = initialStepLoopState(initialMessages, port.initialInstructions);
|
|
1501
|
+
await runModelStepLoop(port, state);
|
|
1599
1502
|
return finalizeCompleteResult({
|
|
1600
|
-
steps,
|
|
1601
|
-
responseMessages,
|
|
1602
|
-
totalUsage,
|
|
1603
|
-
stoppedByPolicy,
|
|
1503
|
+
steps: state.steps,
|
|
1504
|
+
responseMessages: state.responseMessages,
|
|
1505
|
+
totalUsage: state.discardedUsage !== undefined ? addUsage(state.stepUsage, state.discardedUsage) : state.stepUsage,
|
|
1506
|
+
stoppedByPolicy: stoppedByPolicy(),
|
|
1604
1507
|
emitPart,
|
|
1605
1508
|
effectiveSignal
|
|
1606
1509
|
});
|
|
@@ -1612,25 +1515,8 @@ async function completeText(input) {
|
|
|
1612
1515
|
function streamComplete(input) {
|
|
1613
1516
|
return createCompleteTextStream(input, runCompleteLoop);
|
|
1614
1517
|
}
|
|
1615
|
-
function closeStrictObjectNodes(
|
|
1616
|
-
|
|
1617
|
-
return value;
|
|
1618
|
-
const out = {};
|
|
1619
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
1620
|
-
if (SCHEMA_KEYWORDS.includes(key)) {
|
|
1621
|
-
out[key] = Array.isArray(entry) ? entry.map(closeStrictObjectNodes) : closeStrictObjectNodes(entry);
|
|
1622
|
-
} else if (SCHEMA_LIST_KEYWORDS.includes(key) && Array.isArray(entry)) {
|
|
1623
|
-
out[key] = entry.map(closeStrictObjectNodes);
|
|
1624
|
-
} else if ((SCHEMA_MAP_KEYWORDS.includes(key) || key === "dependencies") && isRecord(entry)) {
|
|
1625
|
-
const mapped = {};
|
|
1626
|
-
for (const [subKey, subEntry] of Object.entries(entry)) {
|
|
1627
|
-
mapped[subKey] = isRecord(subEntry) ? closeStrictObjectNodes(subEntry) : subEntry;
|
|
1628
|
-
}
|
|
1629
|
-
out[key] = mapped;
|
|
1630
|
-
} else {
|
|
1631
|
-
out[key] = entry;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1518
|
+
function closeStrictObjectNodes(node) {
|
|
1519
|
+
const out = mapSubschemas(node, { schema: closeStrictObjectNodes });
|
|
1634
1520
|
if (isObjectSchemaType(out.type) && isRecord(out.properties) && out.additionalProperties === undefined) {
|
|
1635
1521
|
out.additionalProperties = false;
|
|
1636
1522
|
}
|
|
@@ -1644,7 +1530,7 @@ async function completeObject(input) {
|
|
|
1644
1530
|
const responseFormat = AgentModelResponseFormatSchema2.parse({
|
|
1645
1531
|
type: "json-schema",
|
|
1646
1532
|
name: schemaName ?? "output",
|
|
1647
|
-
schema:
|
|
1533
|
+
schema: wireSchema,
|
|
1648
1534
|
...schemaDescription !== undefined && { description: schemaDescription },
|
|
1649
1535
|
strict: effectiveStrict
|
|
1650
1536
|
});
|