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
package/llms/agent-runtime.txt
CHANGED
|
@@ -75,32 +75,77 @@ bun add ai@^7
|
|
|
75
75
|
|
|
76
76
|
## Minimal composition
|
|
77
77
|
|
|
78
|
+
The whole loop in one file: a protocol, a model, a prompt, contract tools and one turn. It runs
|
|
79
|
+
as written — `createScriptedModelDriver` from `stitchkit/agent-runtime/testing` stands in for
|
|
80
|
+
the provider, so `bun run agent.ts` needs no key and no network:
|
|
81
|
+
|
|
78
82
|
```ts
|
|
83
|
+
// agent.ts
|
|
79
84
|
import { z } from 'zod'
|
|
85
|
+
import { defineContract } from 'stitchkit'
|
|
86
|
+
import { AppError, implement } from 'stitchkit/server'
|
|
80
87
|
import {
|
|
81
|
-
AgentContextOverflowError,
|
|
82
88
|
composeAgentPrompt,
|
|
83
89
|
createAgentRuntime,
|
|
84
90
|
createMemoryAgentRuntimeStore,
|
|
85
91
|
defineAgentProtocol,
|
|
86
92
|
defineModelRegistry,
|
|
87
93
|
} from 'stitchkit/agent-runtime'
|
|
88
|
-
import {
|
|
89
|
-
import { composeToolLifecycle, mountAgentTools } from 'stitchkit/tools'
|
|
94
|
+
import { createScriptedModelDriver } from 'stitchkit/agent-runtime/testing'
|
|
95
|
+
import { composeToolLifecycle, mountAgentTools, type ToolGate } from 'stitchkit/tools'
|
|
96
|
+
|
|
97
|
+
// The agent's tools are an ordinary contract; the endpoint `lookup` of `orders` is the tool `lookup_order`.
|
|
98
|
+
const orders = defineContract({ prefix: 'orders' }, {
|
|
99
|
+
lookup: {
|
|
100
|
+
method: 'GET',
|
|
101
|
+
path: '/:id',
|
|
102
|
+
desc: 'Look up an order by id',
|
|
103
|
+
params: z.object({ id: z.string() }),
|
|
104
|
+
output: z.object({ id: z.string(), status: z.string() }),
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
const service = implement(orders, {
|
|
108
|
+
lookup: (ctx) => ({ id: ctx.params.id, status: 'shipped' }),
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// Who may call them: your auth rule as a tool gate (`createAuthHook` builds one too).
|
|
112
|
+
const authLifecycle: ToolGate = {
|
|
113
|
+
beforeHandle: (ctx) => {
|
|
114
|
+
if (typeof ctx.userId !== 'string') throw new AppError('UNAUTHORIZED')
|
|
115
|
+
},
|
|
116
|
+
}
|
|
90
117
|
|
|
91
118
|
const protocol = defineAgentProtocol({
|
|
92
119
|
context: z.object({ userId: z.string() }),
|
|
93
120
|
inputMetadata: z.object({}),
|
|
94
121
|
})
|
|
95
122
|
|
|
123
|
+
// Two scripted model steps: call the tool, then answer.
|
|
124
|
+
const usage = (input: number, output: number) => ({
|
|
125
|
+
inputTokens: { value: input, provenance: 'provider-reported' as const },
|
|
126
|
+
outputTokens: { value: output, provenance: 'provider-reported' as const },
|
|
127
|
+
})
|
|
128
|
+
const scripted = createScriptedModelDriver({
|
|
129
|
+
steps: [
|
|
130
|
+
[
|
|
131
|
+
{ type: 'tool-call', toolCallId: 'call-1', toolName: 'lookup_order', input: '{"id":"42"}' },
|
|
132
|
+
{ type: 'finish', finishReason: 'tool-calls', usage: usage(20, 5) },
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
{ type: 'text-delta', id: 'text-1', delta: 'Order 42 has shipped.' },
|
|
136
|
+
{ type: 'finish', finishReason: 'stop', usage: usage(40, 6) },
|
|
137
|
+
],
|
|
138
|
+
],
|
|
139
|
+
})
|
|
140
|
+
|
|
96
141
|
const models = defineModelRegistry({
|
|
97
142
|
providers: {
|
|
98
|
-
|
|
143
|
+
scripted: { create: () => scripted },
|
|
99
144
|
},
|
|
100
145
|
models: {
|
|
101
146
|
fast: {
|
|
102
|
-
provider: '
|
|
103
|
-
modelId: '
|
|
147
|
+
provider: 'scripted',
|
|
148
|
+
modelId: 'scripted-model',
|
|
104
149
|
contextWindow: 128_000,
|
|
105
150
|
capabilities: ['tools'],
|
|
106
151
|
},
|
|
@@ -119,7 +164,9 @@ const runtime = createAgentRuntime({
|
|
|
119
164
|
protocol,
|
|
120
165
|
store: createMemoryAgentRuntimeStore(),
|
|
121
166
|
models: {
|
|
122
|
-
preflight: () =>
|
|
167
|
+
preflight: () => {
|
|
168
|
+
models.preflight('fast', ['tools']) // throws when the model cannot serve the turn
|
|
169
|
+
},
|
|
123
170
|
resolve: () => models.resolve('fast', ['tools']),
|
|
124
171
|
},
|
|
125
172
|
prompt: ({ context, signal, model }) =>
|
|
@@ -142,16 +189,14 @@ const runtime = createAgentRuntime({
|
|
|
142
189
|
runs: { inputPolicy: 'interrupt', coalescePending: true },
|
|
143
190
|
loop: {
|
|
144
191
|
idleTimeoutMs: 60_000,
|
|
145
|
-
prepareStep: ({ context
|
|
146
|
-
activeTools:
|
|
147
|
-
? ['lookup']
|
|
148
|
-
: ['lookup', 'discover'],
|
|
192
|
+
prepareStep: ({ context }) => ({
|
|
193
|
+
activeTools: ['lookup_order'],
|
|
149
194
|
instructions: `Current account: ${context.userId}`,
|
|
150
195
|
}),
|
|
151
196
|
stopPolicies: [
|
|
152
197
|
{
|
|
153
|
-
name: '
|
|
154
|
-
when: ({ steps }) =>
|
|
198
|
+
name: 'too-many-tool-steps',
|
|
199
|
+
when: ({ steps }) => steps.filter((step) => step.toolCalls.length > 0).length >= 5,
|
|
155
200
|
},
|
|
156
201
|
],
|
|
157
202
|
},
|
|
@@ -161,7 +206,7 @@ const ticket = runtime.submit({
|
|
|
161
206
|
conversationId: 'conversation-id',
|
|
162
207
|
idempotencyKey: 'request-id',
|
|
163
208
|
context: { userId: 'user-id' },
|
|
164
|
-
parts: [{ type: 'text', text: '
|
|
209
|
+
parts: [{ type: 'text', text: 'Where is order 42?' }],
|
|
165
210
|
recordIds: {
|
|
166
211
|
inputMessageId: 'user-message-id',
|
|
167
212
|
runId: 'run-id',
|
|
@@ -169,11 +214,36 @@ const ticket = runtime.submit({
|
|
|
169
214
|
},
|
|
170
215
|
})
|
|
171
216
|
|
|
172
|
-
const admission = await ticket.admission
|
|
173
217
|
await ticket.accepted
|
|
174
218
|
const terminal = await ticket.result
|
|
219
|
+
console.log(terminal.reason, terminal.message.parts) // 'success', the tool call, its result, the answer
|
|
220
|
+
await runtime.close()
|
|
175
221
|
```
|
|
176
222
|
|
|
223
|
+
For a real model, register its provider under the same key and keep everything else:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { defineModelRegistry } from 'stitchkit/agent-runtime'
|
|
227
|
+
import { openRouterProvider } from 'stitchkit/agent-runtime/openrouter'
|
|
228
|
+
|
|
229
|
+
const models = defineModelRegistry({
|
|
230
|
+
providers: {
|
|
231
|
+
openrouter: openRouterProvider({ apiKey: () => process.env.OPENROUTER_API_KEY ?? '' }),
|
|
232
|
+
},
|
|
233
|
+
models: {
|
|
234
|
+
fast: {
|
|
235
|
+
provider: 'openrouter',
|
|
236
|
+
modelId: 'provider/model', // a live tool-capable model id from the OpenRouter catalog
|
|
237
|
+
contextWindow: 128_000,
|
|
238
|
+
capabilities: ['tools'],
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
})
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Both blocks are type-checked, and the first one run, by
|
|
245
|
+
`packages/core/tests/guide-first-path-snippets.test.ts`.
|
|
246
|
+
|
|
177
247
|
A stop policy's `when` receives the completed `AgentStepResult[]` steps so far together with the
|
|
178
248
|
same run context `prepareStep` gets — `context`, `run`, `signal`, `toolFenceLifecycle` and
|
|
179
249
|
`contextUsage` — typed by the runtime's `CONTEXT`. A rule that depends on its own run (a receipt
|
|
@@ -181,6 +251,40 @@ bound to the run's request, a per-tenant limit) reads it there; it needs no map
|
|
|
181
251
|
by `runId`. The first policy to return `true` ends the run as `policy_stop` with its `name` as
|
|
182
252
|
`policyName`.
|
|
183
253
|
|
|
254
|
+
### When a run ends `runtime_failure`
|
|
255
|
+
|
|
256
|
+
A run ends `runtime_failure` when the composition fails it — `tools`, `prompt` or a hook throws, a
|
|
257
|
+
checkpoint cannot be written — and `provider_failure` when the model call does. The result a
|
|
258
|
+
caller awaits says which, never why: `terminal.reason` and the failed message travel to clients,
|
|
259
|
+
and a raw cause can carry a provider's response body, a path or another user's data. The cause goes
|
|
260
|
+
to the operator channel, `observe`, and only to a sink that asks for it with `includeInternalCause`:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import { createAgentObservability, createAgentRuntime } from 'stitchkit/agent-runtime'
|
|
264
|
+
|
|
265
|
+
const observe = createAgentObservability({
|
|
266
|
+
includeInternalCause: true, // operator-only: keep this sink's output away from clients
|
|
267
|
+
write: (event) => {
|
|
268
|
+
if (event.type === 'run-terminal' && event.internalCause !== undefined) {
|
|
269
|
+
console.error(`run ${event.runId} ended ${event.terminalReason}:`, event.internalCause)
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
const runtime = createAgentRuntime({
|
|
275
|
+
...composition, // protocol, store, models, prompt and tools, as in the minimal composition
|
|
276
|
+
observe,
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
const ticket = runtime.submit(input)
|
|
280
|
+
const terminal = await ticket.result
|
|
281
|
+
await observe.flush() // the sink is bounded and asynchronous; flush before reading it or exiting
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Without `observe`, nothing reports the cause. A composition missing `protocol`, `store`,
|
|
285
|
+
`models.resolve`, `prompt` or `tools` does not get that far: `createAgentRuntime` throws a
|
|
286
|
+
`TypeError` naming them. `packages/core/tests/agent-runtime-failure-cause.test.ts` holds both.
|
|
287
|
+
|
|
184
288
|
## Native model port, providers and driver composition
|
|
185
289
|
|
|
186
290
|
Every model call crosses one single-step port — `AgentModelDriver.stream(request, signal)` — with
|
|
@@ -216,6 +320,14 @@ freshly per stream call and reporting server `response.timestamp` alongside `mod
|
|
|
216
320
|
≤ 4 cache breakpoints with TTL-order checks, `output_config.format` JSON Schema (refusing
|
|
217
321
|
schemaless `json-object`), and retryable `529 overloaded_error` classification.
|
|
218
322
|
|
|
323
|
+
A Chat Completions stream is complete only when it says so: `data: [DONE]`, or a usage chunk
|
|
324
|
+
after `finish_reason` — the ending [OpenRouter's streaming reference](https://openrouter.ai/docs/api_reference/streaming)
|
|
325
|
+
describes. An OpenAI-compatible server behind `openRouterProvider({ baseUrl })` that closes the
|
|
326
|
+
connection after `finish_reason` with neither cannot be told apart from a cut that lost the usage
|
|
327
|
+
chunk, so the step fails with a retryable `AgentProviderStreamCutError` instead of finishing with
|
|
328
|
+
unreported usage. Such a server has to send `data: [DONE]` (or usage, e.g. on
|
|
329
|
+
`stream_options.include_usage`); there is no option to accept the bare close.
|
|
330
|
+
|
|
219
331
|
For an existing AI SDK (`LanguageModelV4` from `ai@7`) model or `ToolSet`, import `fromAiSdkModel` and `fromAiSdkTools` from
|
|
220
332
|
`stitchkit/agent-runtime/ai-sdk`. Both adapt directly onto `AgentModelDriver` and `AgentToolSet`
|
|
221
333
|
(driving `model.doStream()` without importing `streamText` or `generateText`) and normalize legacy
|
|
@@ -240,15 +352,20 @@ const guarded = composeModelDrivers(base, [admissionDecorator, telemetryDecorato
|
|
|
240
352
|
(`https://openrouter.ai/api/v1`), `OpenRouterFetch`, generic non-chat transport helpers
|
|
241
353
|
(`openRouterRequestJson` and `openRouterRequestStream`), and typed modality clients — all
|
|
242
354
|
peer-free, Web Fetch-clean, redirect-safe (`redirect: 'error'` plus response-level refusal), and
|
|
243
|
-
compatible with `gateway.fetchFor('openrouter')` and custom `baseUrl` overrides
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
355
|
+
compatible with `gateway.fetchFor('openrouter')` and custom `baseUrl` overrides. Chat, catalog,
|
|
356
|
+
spend and every non-chat client share one transport: one `baseUrl` rule (`https:`, or `http:` to a
|
|
357
|
+
loopback host only; no credentials, query or fragment; the API root, not an endpoint URL), one injected `fetch` option, and one error class,
|
|
358
|
+
`AgentProviderError` with `statusCode`, for every non-2xx answer:
|
|
359
|
+
|
|
360
|
+
- **Decision models (`POST /systemone`):** `openRouterSystemOne` sends `noul`, `choice`,
|
|
361
|
+
`score` and image `box` questions over text or structured `state` (with image `assets`,
|
|
362
|
+
`sessionId` and `user`) and returns calibrated probability answers, bounding boxes and
|
|
363
|
+
per-question refusals plus `generationId` and `costUsd`.
|
|
248
364
|
- **Audio (`POST /audio/transcriptions` and `POST /audio/speech`):** `openRouterAudioTranscription`
|
|
249
365
|
accepts `audio: { kind: 'base64' | 'url' | 'file' }` (JSON or automatic `FormData` multipart
|
|
250
366
|
without manual `Content-Type`), `verbose_json`, `timestampGranularities`, and `diarize`;
|
|
251
|
-
`openRouterAudioSpeech` streams synthesized audio bytes (`ReadableStream<Uint8Array>`)
|
|
367
|
+
`openRouterAudioSpeech` streams synthesized audio bytes (`ReadableStream<Uint8Array>`), takes
|
|
368
|
+
text or multi-speaker turns, and with `outputDelivery: 'url'` returns a signed download URL instead.
|
|
252
369
|
- **Images & Video (`POST /images` and `/videos`):** `openRouterGenerateImages` targets OpenRouter's
|
|
253
370
|
Unified Image API (`b64_json` or signed `url`), while `openRouterSubmitVideo`,
|
|
254
371
|
`openRouterGetVideo`, and `openRouterDownloadVideo` cover the async submit → poll → stream
|
|
@@ -260,6 +377,120 @@ compatible with `gateway.fetchFor('openrouter')` and custom `baseUrl` overrides:
|
|
|
260
377
|
management or future endpoints (`/credits`, `/key`, `/responses`, `/images/models`, `/videos/models`)
|
|
261
378
|
without custom wrappers.
|
|
262
379
|
|
|
380
|
+
`createOpenRouterClient` states the key, `baseUrl`, `fetch`, headers and attribution once and returns
|
|
381
|
+
every function above as a method of the same name (`audioTranscription`, `audioSpeech`, `systemOne`,
|
|
382
|
+
`generateImages`, `submitVideo`, `getVideo`, `downloadVideo`, `embeddings`, `rerank`, `requestJson`,
|
|
383
|
+
`requestStream`); a value passed to one call overrides the client's, except `headers` and
|
|
384
|
+
`providerApiKeys`, which merge key by key with the call's entries winning. An invalid `baseUrl` or
|
|
385
|
+
static `apiKey` is refused when the client is created. Every example below is
|
|
386
|
+
type-checked against the current exports by `packages/core/tests/openrouter-guide-snippets.test.ts`.
|
|
387
|
+
|
|
388
|
+
Speech to text — inline audio, or a URL the provider downloads:
|
|
389
|
+
|
|
390
|
+
```ts
|
|
391
|
+
import { createOpenRouterClient } from 'stitchkit/agent-runtime/openrouter';
|
|
392
|
+
|
|
393
|
+
const openRouter = createOpenRouterClient({
|
|
394
|
+
apiKey: () => process.env.OPENROUTER_API_KEY ?? '',
|
|
395
|
+
appName: 'Minutes',
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const fromBytes = await openRouter.audioTranscription({
|
|
399
|
+
model: 'openai/whisper-large-v3',
|
|
400
|
+
audio: { kind: 'base64', data: 'UklGRiQA...', format: 'wav' },
|
|
401
|
+
responseFormat: 'verbose_json',
|
|
402
|
+
diarize: true,
|
|
403
|
+
});
|
|
404
|
+
for (const word of fromBytes.words ?? []) console.log(word.speaker, word.speakerLabel, word.word);
|
|
405
|
+
|
|
406
|
+
const fromUrl = await openRouter.audioTranscription({
|
|
407
|
+
model: 'elevenlabs/scribe-v2',
|
|
408
|
+
audio: { kind: 'url', url: 'https://example.com/meeting.mp3' },
|
|
409
|
+
});
|
|
410
|
+
console.log(fromUrl.text, fromUrl.costUsd);
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Audio by URL depends on the model, and OpenRouter publishes which models accept it neither in the
|
|
414
|
+
endpoints API nor in its documentation. A model that cannot fetch a URL answers HTTP 400 "The
|
|
415
|
+
selected model does not support audio from a URL. Send the audio inline instead." before any charge;
|
|
416
|
+
the call rejects with `AgentProviderError` (`statusCode: 400`) carrying that message. Checked on
|
|
417
|
+
2026-11-30: `elevenlabs/scribe-v2` transcribed a URL, while `openai/whisper-large-v3-turbo`,
|
|
418
|
+
`deepgram/nova-3`, `mistralai/voxtral-mini-3b-2507` and `assemblyai/universal-3-5-pro` refused it —
|
|
419
|
+
send their audio as `base64` or `file`.
|
|
420
|
+
|
|
421
|
+
Text to speech — streamed bytes, or a signed URL OpenRouter keeps for 24 hours:
|
|
422
|
+
|
|
423
|
+
```ts
|
|
424
|
+
import { createOpenRouterClient } from 'stitchkit/agent-runtime/openrouter';
|
|
425
|
+
|
|
426
|
+
const openRouter = createOpenRouterClient({ apiKey: () => process.env.OPENROUTER_API_KEY ?? '' });
|
|
427
|
+
|
|
428
|
+
const streamed = await openRouter.audioSpeech({
|
|
429
|
+
model: 'mistralai/voxtral-mini-tts-2603',
|
|
430
|
+
input: 'Hello world',
|
|
431
|
+
voice: 'en_paul_neutral',
|
|
432
|
+
responseFormat: 'mp3',
|
|
433
|
+
});
|
|
434
|
+
const mp3 = new Uint8Array(await new Response(streamed.audio).arrayBuffer());
|
|
435
|
+
|
|
436
|
+
const stored = await openRouter.audioSpeech({
|
|
437
|
+
model: 'google/gemini-3.8-flash-lite-tts',
|
|
438
|
+
input: [
|
|
439
|
+
{ text: "How's it going today, Jane?", voice: 'Kore' },
|
|
440
|
+
{ text: 'Not too bad, how about you?', voice: 'Puck', instructions: 'tired, yawning' },
|
|
441
|
+
],
|
|
442
|
+
responseFormat: 'wav',
|
|
443
|
+
outputDelivery: 'url',
|
|
444
|
+
});
|
|
445
|
+
console.log(mp3.byteLength);
|
|
446
|
+
// Zero-data-retention makes OpenRouter stream even when a URL was asked for: read those bytes too.
|
|
447
|
+
if (stored.delivery === 'url') console.log(stored.url, new Date(stored.expiresAt * 1000));
|
|
448
|
+
else {
|
|
449
|
+
const wav = new Uint8Array(await new Response(stored.audio).arrayBuffer());
|
|
450
|
+
console.log(wav.byteLength, stored.contentType);
|
|
451
|
+
}
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Video — submit, poll, download:
|
|
455
|
+
|
|
456
|
+
```ts
|
|
457
|
+
import { createOpenRouterClient } from 'stitchkit/agent-runtime/openrouter';
|
|
458
|
+
|
|
459
|
+
const openRouter = createOpenRouterClient({ apiKey: () => process.env.OPENROUTER_API_KEY ?? '' });
|
|
460
|
+
|
|
461
|
+
const job = await openRouter.submitVideo({
|
|
462
|
+
model: 'google/veo-3.1',
|
|
463
|
+
prompt: 'A paper boat drifting down a rain gutter',
|
|
464
|
+
duration: 4,
|
|
465
|
+
});
|
|
466
|
+
let state = await openRouter.getVideo({ jobId: job.id });
|
|
467
|
+
while (state.jobStatus !== 'completed' && state.jobStatus !== 'failed') {
|
|
468
|
+
await new Promise((resolve) => setTimeout(resolve, 5_000));
|
|
469
|
+
state = await openRouter.getVideo({ jobId: job.id });
|
|
470
|
+
}
|
|
471
|
+
if (state.jobStatus === 'completed') {
|
|
472
|
+
const video = await openRouter.downloadVideo({ jobId: job.id });
|
|
473
|
+
console.log(video.contentType, state.costUsd);
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
Any other endpoint — `requestJson` with a Zod `schema` types and validates the answer:
|
|
478
|
+
|
|
479
|
+
```ts
|
|
480
|
+
import { createOpenRouterClient } from 'stitchkit/agent-runtime/openrouter';
|
|
481
|
+
import { z } from 'zod';
|
|
482
|
+
|
|
483
|
+
const openRouter = createOpenRouterClient({ apiKey: () => process.env.OPENROUTER_API_KEY ?? '' });
|
|
484
|
+
|
|
485
|
+
const credits = await openRouter.requestJson({
|
|
486
|
+
path: '/credits',
|
|
487
|
+
schema: z.object({
|
|
488
|
+
data: z.object({ total_credits: z.number(), total_usage: z.number() }),
|
|
489
|
+
}),
|
|
490
|
+
});
|
|
491
|
+
console.log(credits.data.data.total_credits - credits.data.data.total_usage);
|
|
492
|
+
```
|
|
493
|
+
|
|
263
494
|
### OpenRouter catalog snapshots, pricing ceilings, and cache
|
|
264
495
|
|
|
265
496
|
`stitchkit/agent-runtime/openrouter` also provides a peer-free, Web Fetch-clean catalog layer for
|
|
@@ -323,6 +554,20 @@ with `mountAgentTools` from `stitchkit/tools` (including the single-argument
|
|
|
323
554
|
`mountAgentTools({ runtimeTools, access })` form when no HTTP service contracts are mounted). Both
|
|
324
555
|
return `AgentTool` / `AgentToolSet` carrying JSON Schema 2020-12 `inputSchema`, Zod `parseInput`,
|
|
325
556
|
optional `needsApproval`, `onInputAvailable`, and `toModelOutput` returning `AgentToolModelOutput`.
|
|
557
|
+
Without `toModelOutput`, a tool's output reaches the model, and every later turn that reads the run
|
|
558
|
+
back, as `JSON.stringify` writes it: a field left `undefined` drops its key and a `Date` becomes its
|
|
559
|
+
ISO string; a `toModelOutput` JSON value is read the same way. An output `JSON.stringify` cannot
|
|
560
|
+
write (a BigInt, a cycle, a throwing `toJSON`) fails the call with an `AgentToolError` naming the
|
|
561
|
+
tool and the field and saying the tool ran, so the model does not take it for a call that never
|
|
562
|
+
happened. That holds with `toModelOutput` too: a branch presents the result again from the
|
|
563
|
+
recorded output.
|
|
564
|
+
|
|
565
|
+
What `toModelOutput` showed the model is recorded beside the result (`tool-result.modelOutput`),
|
|
566
|
+
and a later turn sends that again rather than calling `toModelOutput` a second time: history is
|
|
567
|
+
what the model read, and it does not change when the function does. Three records are presented
|
|
568
|
+
anew, from the JSON form of the output — where a `Date` is its ISO string: one written before the
|
|
569
|
+
field existed, one whose model output held a `file` part, and a branched one. To present recorded
|
|
570
|
+
results differently on purpose, pass `resolveToolModelOutput` to the history projection.
|
|
326
571
|
|
|
327
572
|
When an operation needs one or a few model steps without a durable conversation store — structured
|
|
328
573
|
extraction, classification, a bounded tool loop, or standalone streaming — call `completeText`,
|
|
@@ -332,13 +577,13 @@ extraction, classification, a bounded tool loop, or standalone streaming — cal
|
|
|
332
577
|
- Pass `onPart` on `completeText` / `completeObject` or use `streamComplete` to consume
|
|
333
578
|
`text-delta`, `reasoning-delta`, `tool-input-start`, `tool-call`, `tool-result` (preliminary and
|
|
334
579
|
final), `tool-error`, `attempt-reset`, `finish-step`, and `finish` events over a bounded async
|
|
335
|
-
iterable without a store. `streamComplete
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
580
|
+
iterable without a store. How `streamComplete` is read is stated, never guessed from when
|
|
581
|
+
`parts` is first touched. By default (`parts: 'iterate'`) `parts` is single-use with a 64-part
|
|
582
|
+
buffer that backpressures from the first part: iteration may start late — after other awaits —
|
|
583
|
+
and the run pauses at the full buffer until it does, losing nothing. Awaiting `result` alone in
|
|
584
|
+
this mode waits while the buffer is full, so a caller that wants only the result says so with
|
|
585
|
+
`parts: 'ignore'`: no buffer is kept, `result` (and `onPart`) carry the run, and iterating
|
|
586
|
+
`parts` throws a `TypeError`. `completeText` with `onPart` is the same result-only path.
|
|
342
587
|
- Standalone completions have no durable approval loop, so any tool with `needsApproval: true` (or
|
|
343
588
|
a `needsApproval` predicate returning `true`) is preflighted across every validated call in the
|
|
344
589
|
step and fails closed with `AgentToolApprovalError` (`reason: 'approval-unsupported'`) before any
|
|
@@ -347,11 +592,22 @@ extraction, classification, a bounded tool loop, or standalone streaming — cal
|
|
|
347
592
|
`toolDependencies`, `onPredecessorFailure`) on `completeText` / `streamComplete` /
|
|
348
593
|
`completeObject` to enforce the same batch-refusal, cap, and dependency-ordering policies as
|
|
349
594
|
`createAgentRuntime` (durable stream-only `stepBarriers` keys fail fast with a `TypeError`).
|
|
350
|
-
- Pass `retry` (`AgentRetryPolicy`) and optional `onAttemptDiscarded` for stateless retry
|
|
351
|
-
`
|
|
352
|
-
|
|
595
|
+
- Pass `retry` (`AgentRetryPolicy`) and optional `onAttemptDiscarded` for stateless retry. As in
|
|
596
|
+
`createAgentRuntime`, the unit of a retry is the model call of one step: earlier steps and the
|
|
597
|
+
tools they ran stand, and a call whose stream already carried a provider-executed tool call or
|
|
598
|
+
a tool result is not repeated. Exhausting retries throws `AgentRetryExhaustedError` carrying every failed attempt, `lastError`,
|
|
599
|
+
and accumulated billable `usage`. The wait before each retry is exactly what `delayMs` returns:
|
|
600
|
+
the runtime reads no `Retry-After` itself, so a policy that should honour one returns
|
|
601
|
+
`failure.retryAfterMs` (the provider's `Retry-After` or `retry-after-ms`, in milliseconds) and
|
|
602
|
+
bounds the total with `maxRetryDurationMs` — a retry whose wait would cross it is not scheduled.
|
|
603
|
+
The same policy serves `loop.retry`. Example:
|
|
604
|
+
[`packages/core/examples/agent-runtime/retry-after-policy.ts`](../../packages/core/examples/agent-runtime/retry-after-policy.ts).
|
|
353
605
|
- Pass `stopPolicies` (`AgentCompleteStopPolicy[]`) and `idleTimeoutMs` to bound multi-step loops
|
|
354
|
-
and stalled streams (suspending the idle timer during local tool execution).
|
|
606
|
+
and stalled streams (suspending the idle timer during local tool execution). A deadline that
|
|
607
|
+
fires while your consumer holds a part — a full `streamComplete().parts` buffer nobody reads, a
|
|
608
|
+
slow `onPart` — still ends the call with a `timeout` `AgentProviderError`, but one without
|
|
609
|
+
provider origin: `retry` never calls the provider again for it. `idleTimeoutMs`
|
|
610
|
+
defaults to 60 000, the runtime's default; `null` disables it.
|
|
355
611
|
|
|
356
612
|
```ts
|
|
357
613
|
import { z } from 'zod'
|
|
@@ -449,7 +705,10 @@ const runtime = createAgentRuntime({
|
|
|
449
705
|
context: runContext.context,
|
|
450
706
|
access: { gate: composeToolLifecycle(authLifecycle, runContext.toolFenceLifecycle) },
|
|
451
707
|
}),
|
|
452
|
-
loop: {
|
|
708
|
+
loop: {
|
|
709
|
+
prepareStep: deferred.prepareStep(applicationPrepareStep),
|
|
710
|
+
repairToolCall: deferred.repairToolCall(applicationRepairToolCall),
|
|
711
|
+
},
|
|
453
712
|
})
|
|
454
713
|
```
|
|
455
714
|
|
|
@@ -468,9 +727,11 @@ The latest valid same-run search replaces the earlier selection; parallel
|
|
|
468
727
|
searches in one step merge in call order. Recovery reconstructs it, while a
|
|
469
728
|
different run or finite surface cannot inherit it. Known inactive calls take a
|
|
470
729
|
recoverable `SEARCH_REQUIRED` search round; unknown names still fail. Inactive-call
|
|
471
|
-
repair
|
|
472
|
-
`
|
|
473
|
-
|
|
730
|
+
repair is the hook `deferred.repairToolCall(applicationRepairToolCall?)` returns, passed as
|
|
731
|
+
`loop.repairToolCall` (runtime) or `repairToolCall` (`completeText` / `streamComplete`); the
|
|
732
|
+
application's hook runs first. Nothing is attached to the mounted tools, so spreading them or a
|
|
733
|
+
tool, or merging two surfaces' mounts, keeps repair exact: two surfaces compose as
|
|
734
|
+
`first.repairToolCall(second.repairToolCall())`, each repairing only its own catalog. The
|
|
474
735
|
runtime marks that round with `reason: 'inactive_call'` beside the exact tool
|
|
475
736
|
name. The field is the runtime's to write; a model that sets it anyway gets
|
|
476
737
|
the same `SEARCH_REQUIRED` answer with an exact name, and with a query in words
|
package/llms/application.2.txt
CHANGED
|
@@ -255,9 +255,12 @@ Opt into `delivery: { version, actions, project }` on `createNotificationOutbox`
|
|
|
255
255
|
The pure `actions(payload)` selector runs at enqueue; the versioned plan remains
|
|
256
256
|
fixed throughout retry. Each `send` receives its action and a stable idempotency
|
|
257
257
|
key; return a small JSON receipt such as a remote message or uploaded object ID.
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
The receipt is kept as `JSON.stringify` writes it: a field left `undefined` drops,
|
|
259
|
+
a `Date` becomes its ISO string. An action that returned is confirmed and is never
|
|
260
|
+
sent again: a result JSON cannot carry (a BigInt, a cycle), or one that does not fit
|
|
261
|
+
the state's byte budget, is kept as `receipt: null` with
|
|
262
|
+
`unrecorded: 'not-json' | 'too-large'` and reported to `onError`, naming the field
|
|
263
|
+
for `not-json`.
|
|
261
264
|
`project(notification, receipts)` applies all confirmed results locally and must
|
|
262
265
|
be idempotent. Checkpoints and the final projection timestamp live in the existing
|
|
263
266
|
atomic StateStore; completed receipts retain them within retention/byte limits.
|
package/llms/application.3.txt
CHANGED
|
@@ -299,7 +299,8 @@ never trust a client-supplied owner ID as that scope.
|
|
|
299
299
|
immutable executor `version`, pure `actions(payload)` plan selector (1–128 unique
|
|
300
300
|
names, each at most 128 characters), and idempotent `project(notification, receipts)`.
|
|
301
301
|
`send` receives optional `action` and stable `idempotencyKey`, and returns a JSON
|
|
302
|
-
remote receipt (void becomes null)
|
|
302
|
+
remote receipt (void becomes null), kept as `JSON.stringify` writes it. A result JSON
|
|
303
|
+
cannot carry (a BigInt, a cycle; `onError` names the field) or that does not fit the
|
|
303
304
|
byte budget is kept as `receipt: null` with `unrecorded: 'not-json' | 'too-large'`;
|
|
304
305
|
the action stays confirmed and is not sent again. `retiredVersions` maps earlier
|
|
305
306
|
plan versions to their `NotificationProjection` so queued items drain after an
|
package/llms/application.txt
CHANGED
|
@@ -642,7 +642,10 @@ if (result.outcome === 'refused') internalCounter.add(1, { reason: result.reason
|
|
|
642
642
|
await journal.close({ timeoutMs: 5_000 })
|
|
643
643
|
```
|
|
644
644
|
|
|
645
|
-
The owner schema and JSON serialization run synchronously before admission.
|
|
645
|
+
The owner schema and JSON serialization run synchronously before admission. An event is kept as
|
|
646
|
+
`JSON.stringify` writes it, and only if the schema reads that form back: an optional field left
|
|
647
|
+
`undefined` is accepted, while a cycle, a BigInt or a `Date` in a `z.date()` field is `invalid`.
|
|
648
|
+
Accepted frames carry
|
|
646
649
|
a process epoch and contiguous sequence and retain their complete bytes inside both pending limits
|
|
647
650
|
until their append attempt settles. Capacity, invalid, oversized, closed and terminal-failure
|
|
648
651
|
refusals are explicit; accepted ordered frames are never evicted.
|
|
@@ -872,7 +875,9 @@ bot.catch(({ error }) => logger.error('Telegram handler failed', { error }))
|
|
|
872
875
|
const telegram = grammyBotResources({
|
|
873
876
|
bot,
|
|
874
877
|
dependsOn: [database, http], // what handlers need before the first update
|
|
875
|
-
configure: () =>
|
|
878
|
+
configure: async () => {
|
|
879
|
+
await bot.api.setMyCommands([{ command: 'start', description: 'Start' }])
|
|
880
|
+
},
|
|
876
881
|
onEnded: ({ error }) => stopProcess(error), // see below
|
|
877
882
|
})
|
|
878
883
|
|
package/llms/http.txt
CHANGED
|
@@ -14,7 +14,7 @@ Also read:
|
|
|
14
14
|
|
|
15
15
|
## `stitchkit/http`
|
|
16
16
|
|
|
17
|
-
An HTTP-only entrypoint for browsers, React Native/Hermes and servers. It exports the same `createClient`, `createClients`, `createHttpClient`, URL builders, client configuration types and `
|
|
17
|
+
An HTTP-only entrypoint for browsers, React Native/Hermes and servers. It exports the same `createClient`, `createClients`, `createHttpClient`, URL builders, client configuration types, `ApiError`, `readContractIdentity` (with its `ContractIdentity` result) and the stream line errors `StreamLineLimitError` / `StreamTruncatedLineError` as the root, without loading its optional Socket.IO graph, plus the `postMessage` bridge `ClientFetch` adapter and envelope schemas. Import shared contracts from `stitchkit/contract`.
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import { createClients, createHttpClient } from 'stitchkit/http';
|
package/llms/live.txt
CHANGED
|
@@ -432,7 +432,9 @@ never runs.
|
|
|
432
432
|
- **It does not gate operations.** "Only from this machine" is a property of an
|
|
433
433
|
operation, and an operation is known after routing, not before it. Write it as
|
|
434
434
|
an auth rule over `ctx.ipAddress` — `isLoopbackAddress` is exported for
|
|
435
|
-
exactly that — where it composes with your other rules.
|
|
435
|
+
exactly that — where it composes with your other rules. Behind a proxy on the
|
|
436
|
+
same host every peer is loopback: resolve the visitor with `trustProxy` first
|
|
437
|
+
([server guide](./server.md#client-ip-behind-a-proxy)).
|
|
436
438
|
- **It does not re-check an open connection.** Both lanes check at admission.
|
|
437
439
|
- **It does not see an `OPTIONS` preflight** when `cors` is configured; that is
|
|
438
440
|
answered earlier. The preflight carries no operation and no body, and the
|
package/llms/observability.txt
CHANGED
|
@@ -601,18 +601,25 @@ each request.
|
|
|
601
601
|
A payload goes into an audit row only after `sanitizePayload`:
|
|
602
602
|
|
|
603
603
|
- **secret-named keys are masked** — a key whose words include a secret term is
|
|
604
|
-
redacted (`password`, `sessionToken`, `X-Api-Key`, `
|
|
605
|
-
…),
|
|
606
|
-
`
|
|
604
|
+
redacted (`password`, `passphrase`, `sessionToken`, `X-Api-Key`, `accessKey`,
|
|
605
|
+
`authorization`, `cookie`, …), a key written as one lowercase run that ends in
|
|
606
|
+
one (`newpassword`, `accesstoken`), and a key that ENDS in `auth`, `signature`,
|
|
607
|
+
`jwt`, `otp`, `pin` or `dsn` (`basicAuth`, `webhookSignature`, `SENTRY_DSN`),
|
|
608
|
+
while identifiers that merely contain one (`authorId`, `sessionCount`,
|
|
609
|
+
`tokenizer`, `pinned`) or only describe it (`signatureVersion`, `auth_date`,
|
|
610
|
+
a model token count such as `maxTokens` or `usage.total_tokens`)
|
|
611
|
+
survive. This applies wherever a key exists — an object field and
|
|
607
612
|
a `Map` entry alike, at any depth. A `Set` member has no key, so nothing there
|
|
608
613
|
is masked by name;
|
|
609
614
|
- **secrets are masked by their shape** in every string, whatever key holds
|
|
610
615
|
it — the secret half of a Telegram bot token (`123456:[redacted]`: the bot's
|
|
611
616
|
id stays, it tells two bots apart), the password in
|
|
612
|
-
`postgresql://user:password@host` (user, host and path stay),
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
617
|
+
`postgresql://user:password@host` (user, host and path stay), the user of an
|
|
618
|
+
`http(s)` / `ws(s)` address with no password (a Sentry DSN's key — a database
|
|
619
|
+
or SSH user stays), the credential after `Bearer`, a provider key (`sk-…`, `or-v1-…`, `AIza…`), a
|
|
620
|
+
JSON Web Token (`eyJ….eyJ….…`), and the value of a query parameter named as a
|
|
621
|
+
secret (`?access_token=`, `?api-key=`, `?key=`, `?sig=`). A URL in an error
|
|
622
|
+
message or a request log line is the usual way a token reaches a journal;
|
|
616
623
|
- **an error keeps what it says about itself** — its own fields (`error_code`,
|
|
617
624
|
`parameters`, a provider's `status`) are written beside `name`, `message`,
|
|
618
625
|
`stack` and `cause`, masked by the same rules; a field holding a class
|
|
@@ -791,8 +798,8 @@ use; future optional fields do not change callback arity.
|
|
|
791
798
|
|
|
792
799
|
`createObservability({ tools })` uses it already. Where the envelope was scrubbed to
|
|
793
800
|
`INTERNAL_SERVER_ERROR`, the row's `errorMessage` becomes the real message
|
|
794
|
-
instead of the placeholder
|
|
795
|
-
`
|
|
801
|
+
instead of the placeholder (a `ZodError` from handler code is one of these); a
|
|
802
|
+
truthful envelope (a thrown `AppError`, invalid input) is left alone, `errorCode` and `errorDetail` are untouched, and the
|
|
796
803
|
stack is not written — that is `onToolError`'s job, for a tracker that wants it.
|
|
797
804
|
The caller still receives the scrubbed envelope in every case: the raw text
|
|
798
805
|
reaches your server-side record, never the response. → ADR 0042
|
package/llms/server.2.txt
CHANGED
|
@@ -103,7 +103,7 @@ Runtime requirements and boundaries:
|
|
|
103
103
|
- **Origin trust and navigation lock-down.** A `postMessage` bridge has no loopback `Host` header,
|
|
104
104
|
so `createLocalHostGuard` does not apply. `serveBridge` validates the native container-reported
|
|
105
105
|
`origin` against the exact `origins` allow-list, strips `host`, `origin`, `x-forwarded-for`,
|
|
106
|
-
`x-real-ip` and `forwarded` from every frame, refuses a handler with `trustProxy
|
|
106
|
+
`x-real-ip` and `forwarded` from every frame, refuses a handler configured with `trustProxy`, and
|
|
107
107
|
optionally verifies a per-start `secret` in constant time. Refusal reasons are logged on the host
|
|
108
108
|
and never disclosed to the window. Because any page a WebView navigates to receives
|
|
109
109
|
`window.ReactNativeWebView`, always lock navigation down in the WebView itself
|
|
@@ -147,8 +147,8 @@ This endpoint is HTTP-only and cannot be multipart or exposed as a tool. The
|
|
|
147
147
|
router sets `ctx.rawBody` before JSON/Zod validation, so `onError` can inspect it
|
|
148
148
|
after malformed JSON or a schema failure. Endpoints without `rawBody: true` do
|
|
149
149
|
not retain the text. `maxJsonBodyBytes` may also be set once on `createServer` /
|
|
150
|
-
`createHandler`; a route value wins.
|
|
151
|
-
oversized stream before it is fully buffered. → ADR 0051
|
|
150
|
+
`createHandler`; a route value wins. Without either the ceiling is 1 MiB; every
|
|
151
|
+
limit aborts an oversized stream before it is fully buffered. → ADR 0051, ADR 0340
|
|
152
152
|
|
|
153
153
|
## Safelisted request bodies (beacons)
|
|
154
154
|
|
|
@@ -452,11 +452,16 @@ contract route does.
|
|
|
452
452
|
|
|
453
453
|
### Serving files & Range requests
|
|
454
454
|
|
|
455
|
-
`staticRoute(prefix, dir, { cacheControl })` serves a directory:
|
|
456
|
-
containment, then answers the file through `serveFile`, so a static
|
|
457
|
-
video carries `ETag`, `Last-Modified` and `Accept-Ranges`, revalidates
|
|
458
|
-
and seeks with `206`. `cacheControl` sets `Cache-Control` on every
|
|
459
|
-
default none is sent.
|
|
455
|
+
`staticRoute(prefix, dir, { cacheControl, allowedDotNames })` serves a directory:
|
|
456
|
+
it checks containment, then answers the file through `serveFile`, so a static
|
|
457
|
+
image or video carries `ETag`, `Last-Modified` and `Accept-Ranges`, revalidates
|
|
458
|
+
to `304` and seeks with `206`. `cacheControl` sets `Cache-Control` on every
|
|
459
|
+
answer; by default none is sent.
|
|
460
|
+
|
|
461
|
+
A path with a segment that starts with a dot — `/.env`, `/.git/config`,
|
|
462
|
+
`/assets/.npmrc` — answers `404`, so a hidden file that ends up in the served
|
|
463
|
+
directory never leaves it. Name the ones you mean to publish:
|
|
464
|
+
`allowedDotNames: ['.well-known']`.
|
|
460
465
|
|
|
461
466
|
```ts
|
|
462
467
|
import { createServer, staticRoute } from 'stitchkit/server'
|