stitchkit 0.136.7 → 0.137.0
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 +68 -0
- package/dist/agent-runtime/stores/branch-observations.d.ts +19 -19
- package/dist/agent-runtime/stores/schedule-contract.d.ts.map +1 -1
- package/dist/agent-runtime/stores/schedule-records.d.ts.map +1 -1
- package/dist/agent-runtime/stores/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/stores/sql-rows.d.ts +36 -36
- package/dist/agent-runtime/terminal-commit.d.ts +5 -5
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +52 -52
- package/dist/agent-runtime/testing/store-conformance-support.d.ts +26 -26
- package/dist/browser/client-executors.d.ts +2 -3
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/realtime-client.d.ts +6 -1
- package/dist/browser/realtime-client.d.ts.map +1 -1
- package/dist/browser/socket-io-client.d.ts.map +1 -1
- package/dist/browser/socket-io-contract.d.ts +2 -0
- package/dist/browser/socket-io-contract.d.ts.map +1 -1
- package/dist/contract/define-validation.d.ts +6 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +1 -1
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/error-mapping.d.ts +71 -0
- package/dist/contract/error-mapping.d.ts.map +1 -0
- package/dist/contract/errors.d.ts +8 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/factory.d.ts +8 -0
- package/dist/contract/factory.d.ts.map +1 -1
- package/dist/contract/fragments.d.ts +45 -0
- package/dist/contract/fragments.d.ts.map +1 -0
- package/dist/contract/normalize.d.ts +6 -3
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/contract/operation-read.d.ts +38 -0
- package/dist/contract/operation-read.d.ts.map +1 -0
- package/dist/contract/stream.d.ts.map +1 -1
- package/dist/contract/time-zone.d.ts +31 -0
- package/dist/contract/time-zone.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +1 -1
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/device-relay/hub.d.ts +1 -1
- package/dist/device-relay/hub.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +9 -9
- package/dist/entrypoints/agent-executor/claude-sdk.js +11 -11
- package/dist/entrypoints/agent-executor/claude.js +8 -8
- package/dist/entrypoints/agent-executor/codex.js +15 -15
- package/dist/entrypoints/agent-executor/testing.js +11 -11
- package/dist/entrypoints/agent-executor.js +14 -13
- package/dist/entrypoints/agent-runtime/ai-sdk.js +5 -5
- package/dist/entrypoints/agent-runtime/anthropic.js +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +5 -5
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +14 -15
- package/dist/entrypoints/agent-runtime/openai.js +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +7 -7
- package/dist/entrypoints/agent-runtime/postgres.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +8 -8
- package/dist/entrypoints/agent-runtime/sandbox.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +33 -29
- package/dist/entrypoints/application/diagnostic-journal.js +3 -3
- package/dist/entrypoints/application/directory-inbox.js +1 -1
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application/opentelemetry.js +2 -2
- package/dist/entrypoints/application.js +10 -10
- package/dist/entrypoints/cli/publish.d.ts +4 -4
- package/dist/entrypoints/cli/publish.d.ts.map +1 -1
- package/dist/entrypoints/cli/publish.js +160 -52
- package/dist/entrypoints/cli.d.ts +3 -1
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +520 -59
- package/dist/entrypoints/contract.d.ts +5 -1
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +25 -7
- package/dist/entrypoints/device-relay.js +20 -10
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.js +10 -10
- package/dist/entrypoints/handler.d.ts +1 -1
- package/dist/entrypoints/handler.d.ts.map +1 -1
- package/dist/entrypoints/handler.js +12 -12
- package/dist/entrypoints/http.js +13 -12
- package/dist/entrypoints/index.js +36 -18
- package/dist/entrypoints/live.d.ts +2 -1
- package/dist/entrypoints/live.d.ts.map +1 -1
- package/dist/entrypoints/live.js +630 -1
- package/dist/entrypoints/node.d.ts +5 -0
- package/dist/entrypoints/node.d.ts.map +1 -1
- package/dist/entrypoints/node.js +36 -16
- package/dist/entrypoints/observability.js +25 -10
- package/dist/entrypoints/postgres.d.ts +4 -1
- package/dist/entrypoints/postgres.d.ts.map +1 -1
- package/dist/entrypoints/postgres.js +312 -0
- package/dist/entrypoints/primitives.js +11 -4
- package/dist/entrypoints/process.js +7 -7
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +6 -29
- package/dist/entrypoints/server.d.ts +6 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +93 -32
- package/dist/entrypoints/service-host/macos.js +6 -6
- package/dist/entrypoints/service-host/work.js +6 -6
- package/dist/entrypoints/service-host.js +10 -10
- package/dist/entrypoints/spend.js +2 -1
- package/dist/entrypoints/sync.js +5 -5
- package/dist/entrypoints/telegram.js +8 -8
- package/dist/entrypoints/testing.d.ts +1 -0
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +1501 -13
- package/dist/entrypoints/tools/agent.js +6 -7
- package/dist/entrypoints/tools/connections.js +9 -11
- package/dist/entrypoints/tools/contract.js +1 -2
- package/dist/entrypoints/tools/invoker.js +4 -5
- package/dist/entrypoints/tools/mcp.js +10 -11
- package/dist/entrypoints/tools/toolkit.d.ts +1 -1
- package/dist/entrypoints/tools/toolkit.d.ts.map +1 -1
- package/dist/entrypoints/tools/toolkit.js +29 -24
- package/dist/entrypoints/tools.js +28 -30
- package/dist/entrypoints/tracking/contract.js +2 -1
- package/dist/entrypoints/xlsx.js +5 -8
- package/dist/{index-033tyx59.js → index-0zw0hcyg.js} +4 -1
- package/dist/{index-zcq3dby3.js → index-1bjwfnnj.js} +1 -1
- package/dist/{index-f103md2v.js → index-1cfacbe2.js} +88 -23
- package/dist/{index-gj4wdts6.js → index-1ckh9qx1.js} +1 -1
- package/dist/index-1pvwmbxp.js +1435 -0
- package/dist/{index-0s75mjh7.js → index-2e4hdh32.js} +1 -1
- package/dist/{index-3shdhzt6.js → index-2j0pqxkn.js} +12 -6
- package/dist/index-3k8w02se.js +28 -0
- package/dist/{index-7fjbdga8.js → index-3pb4ccj2.js} +8 -0
- package/dist/{index-w7e402wx.js → index-48kb4gqq.js} +46 -7
- package/dist/{index-cv9b7fz2.js → index-6rws2xf5.js} +8 -0
- package/dist/{index-bbpygynk.js → index-77w5vx0g.js} +1 -1
- package/dist/index-7dz1ngaf.js +35 -0
- package/dist/{index-y68gavb5.js → index-7n4atsm4.js} +1 -1
- package/dist/index-8ef1bfea.js +71 -0
- package/dist/{index-0x4mnwg5.js → index-8k3y9nd4.js} +6 -9
- package/dist/{index-ezwsqyad.js → index-8rkdkefj.js} +40 -23
- package/dist/{index-3cwq5byx.js → index-9nax7tkn.js} +2 -2
- package/dist/{index-dz6tstcp.js → index-9r6emjwz.js} +1 -1
- package/dist/{index-32ew02z1.js → index-c4b7d6ej.js} +5 -5
- package/dist/index-ceshyndf.js +284 -0
- package/dist/{index-w161azza.js → index-d13rw31w.js} +6 -6
- package/dist/{index-1h0dtfz3.js → index-dmm7vs3f.js} +1 -1
- package/dist/{index-ypm85xwe.js → index-dp8j2e77.js} +1 -1
- package/dist/{index-qqd979f7.js → index-edycjvrv.js} +9 -9
- package/dist/{index-18qdpbcq.js → index-egpf9dv0.js} +200 -1479
- package/dist/{index-fatke81t.js → index-ezgvsj9w.js} +2 -2
- package/dist/{index-chapre0y.js → index-f3e7tj1g.js} +1 -1
- package/dist/{index-df5xr2f9.js → index-frsd2a94.js} +16 -1
- package/dist/index-fy9mmek1.js +95 -0
- package/dist/{index-2331y2tf.js → index-g0gvfzrx.js} +12 -12
- package/dist/index-gpe8d1ka.js +19 -0
- package/dist/{index-4p2zx593.js → index-gyw4qd0m.js} +1 -1
- package/dist/index-gzqy81tw.js +172 -0
- package/dist/{index-yrhw10ef.js → index-h34c510q.js} +8 -4
- package/dist/{index-rr94xcj6.js → index-h527p1yj.js} +10 -4
- package/dist/{index-qj0sq69b.js → index-hgf1tbgz.js} +76 -16
- package/dist/{index-smvmnz5y.js → index-hvpan32x.js} +1 -1
- package/dist/{index-4gbybjg6.js → index-hxawqrb6.js} +2 -2
- package/dist/{index-0k1ba0ss.js → index-j91jffhv.js} +1 -1
- package/dist/{index-d01akj5n.js → index-jr4kwetx.js} +8 -8
- package/dist/{index-xqppqn97.js → index-ka6z48zc.js} +315 -69
- package/dist/{index-by8w2461.js → index-kw0segzt.js} +104 -3
- package/dist/{index-6f4fjygr.js → index-m5t4dr7h.js} +29 -7
- package/dist/{index-afaq0nc4.js → index-n0egp1ke.js} +1 -1
- package/dist/{index-9fzjgg86.js → index-n74rb1dq.js} +2 -2
- package/dist/{index-dwq6a6sq.js → index-pt25vmhc.js} +33 -16
- package/dist/{index-vwg0n3e6.js → index-pyazb8q4.js} +23 -14
- package/dist/{index-5md04mwc.js → index-qpjjbkc5.js} +4 -4
- package/dist/{index-08a3qfr8.js → index-r1qt6zgj.js} +1 -1
- package/dist/{index-ctaxjpa4.js → index-r709pqed.js} +1 -1
- package/dist/{index-2zrx0nzv.js → index-rzc40z6e.js} +3 -5
- package/dist/{index-gq35s3bm.js → index-s5axtd56.js} +2 -2
- package/dist/{index-edpkm3k7.js → index-scpcps66.js} +669 -16
- package/dist/{index-ry8m2mhg.js → index-sf2mt6wj.js} +1 -1
- package/dist/{index-tjhhsnjv.js → index-t1213r0t.js} +1 -1
- package/dist/{index-gvgtmt7a.js → index-t7efje30.js} +2 -2
- package/dist/{index-w3s79kcb.js → index-tzyk36dy.js} +1 -1
- package/dist/{index-8tn10tp6.js → index-v64bvwjr.js} +1 -1
- package/dist/{index-1fhbe4e4.js → index-vksbsqpb.js} +1 -1
- package/dist/{index-dxft2mnm.js → index-wdg7bswj.js} +1 -1
- package/dist/{index-ppy23bd2.js → index-wjx1zs2r.js} +7 -578
- package/dist/{index-efbzm2se.js → index-x2r0ma9t.js} +1 -1
- package/dist/{index-kd48gk7d.js → index-x8py72a3.js} +1 -1
- package/dist/index-xvydbxmk.js +1404 -0
- package/dist/index-xwaphv0d.js +31 -0
- package/dist/{index-a09r9ff0.js → index-y44j39yk.js} +1 -1
- package/dist/{index-7mjsb7zv.js → index-ybrrxjhb.js} +1 -1
- package/dist/{index-xsrma0jd.js → index-ysthxsa8.js} +6 -6
- package/dist/{index-6p5pshcd.js → index-yyh3ey4b.js} +1 -1
- package/dist/{index-mr3njw67.js → index-z6hq9j8j.js} +1 -1
- package/dist/{index-67mzzkdv.js → index-z72agxdn.js} +2 -2
- package/dist/{index-e4w0sfm1.js → index-z78mtc16.js} +1 -1
- package/dist/{index-7csn6pva.js → index-ze94h4ph.js} +5 -0
- package/dist/internal/json-stringify.d.ts +12 -0
- package/dist/internal/json-stringify.d.ts.map +1 -1
- package/dist/internal/unix-client-error.d.ts +4 -0
- package/dist/internal/unix-client-error.d.ts.map +1 -1
- package/dist/live/watch-contract.d.ts +4 -0
- package/dist/live/watch-contract.d.ts.map +1 -1
- package/dist/live/watch-fanout-frame.d.ts +81 -0
- package/dist/live/watch-fanout-frame.d.ts.map +1 -0
- package/dist/live/watch-fanout.d.ts +57 -0
- package/dist/live/watch-fanout.d.ts.map +1 -0
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/spool-core.d.ts +1 -0
- package/dist/observability/spool-core.d.ts.map +1 -1
- package/dist/observability/spool-drain.d.ts +48 -0
- package/dist/observability/spool-drain.d.ts.map +1 -0
- package/dist/observability/spool.d.ts +12 -6
- package/dist/observability/spool.d.ts.map +1 -1
- package/dist/postgres/connection-config.d.ts +54 -0
- package/dist/postgres/connection-config.d.ts.map +1 -0
- package/dist/postgres/rollback-transaction.d.ts +61 -0
- package/dist/postgres/rollback-transaction.d.ts.map +1 -0
- package/dist/primitives/deadline.d.ts +4 -4
- package/dist/primitives/deadline.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +3 -32
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/local-consent-key.d.ts +104 -0
- package/dist/server/local-consent-key.d.ts.map +1 -0
- package/dist/server/local-control-journal.d.ts +51 -0
- package/dist/server/local-control-journal.d.ts.map +1 -0
- package/dist/server/local-control-reporter.d.ts +32 -0
- package/dist/server/local-control-reporter.d.ts.map +1 -0
- package/dist/server/local-control.d.ts +48 -0
- package/dist/server/local-control.d.ts.map +1 -0
- package/dist/server/local-host-clients.d.ts +105 -0
- package/dist/server/local-host-clients.d.ts.map +1 -0
- package/dist/server/middleware/trust-fence.d.ts +20 -0
- package/dist/server/middleware/trust-fence.d.ts.map +1 -1
- package/dist/spend/receipt-spool.d.ts +9 -4
- package/dist/spend/receipt-spool.d.ts.map +1 -1
- package/dist/testing/tool-surface-checks.d.ts +89 -0
- package/dist/testing/tool-surface-checks.d.ts.map +1 -0
- package/dist/testing/tool-surface-cli-callable.d.ts +63 -0
- package/dist/testing/tool-surface-cli-callable.d.ts.map +1 -0
- package/dist/testing/tool-surface-dead-refs.d.ts +32 -0
- package/dist/testing/tool-surface-dead-refs.d.ts.map +1 -0
- package/dist/testing/tool-surface-gates.d.ts +72 -0
- package/dist/testing/tool-surface-gates.d.ts.map +1 -0
- package/dist/testing/tool-surface-parity-drivers.d.ts +56 -0
- package/dist/testing/tool-surface-parity-drivers.d.ts.map +1 -0
- package/dist/testing/tool-surface-parity.d.ts +28 -0
- package/dist/testing/tool-surface-parity.d.ts.map +1 -0
- package/dist/testing/tool-surface-ratchet.d.ts +71 -0
- package/dist/testing/tool-surface-ratchet.d.ts.map +1 -0
- package/dist/tools/agent-tools.d.ts +3 -0
- package/dist/tools/agent-tools.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +3 -0
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/create-cli.d.ts.map +1 -1
- package/dist/tools/cli/distribution-config.d.ts +39 -1
- package/dist/tools/cli/distribution-config.d.ts.map +1 -1
- package/dist/tools/cli/distribution-routes.d.ts +4 -2
- package/dist/tools/cli/distribution-routes.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts +3 -6
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +4 -0
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/local-key-command.d.ts +53 -0
- package/dist/tools/cli/local-key-command.d.ts.map +1 -0
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/publication-contract.d.ts +9 -2
- package/dist/tools/cli/publication-contract.d.ts.map +1 -1
- package/dist/tools/cli/publication.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-stream.d.ts.map +1 -1
- package/dist/tools/cli/runner.d.ts +8 -3
- package/dist/tools/cli/runner.d.ts.map +1 -1
- package/dist/tools/cli/secret.d.ts +55 -0
- package/dist/tools/cli/secret.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +2 -2
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/signature.d.ts +23 -9
- package/dist/tools/cli/signature.d.ts.map +1 -1
- package/dist/tools/cli/stream.d.ts.map +1 -1
- package/dist/tools/cli/unix-outcome.d.ts +6 -0
- package/dist/tools/cli/unix-outcome.d.ts.map +1 -1
- package/dist/tools/cli/update.d.ts +6 -1
- package/dist/tools/cli/update.d.ts.map +1 -1
- package/dist/tools/execute-result.d.ts +20 -0
- package/dist/tools/execute-result.d.ts.map +1 -1
- package/dist/tools/execute.d.ts +3 -0
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/json-projection.d.ts +13 -9
- package/dist/tools/internal/json-projection.d.ts.map +1 -1
- package/dist/tools/internal/remote-error.d.ts +15 -0
- package/dist/tools/internal/remote-error.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +2 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +3 -0
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts +2 -0
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +5 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -0
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts +2 -0
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/mcp/stdio.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +3 -0
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/read-operation.d.ts +2 -6
- package/dist/tools/read-operation.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +10 -3
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/xlsx/schema.d.ts.map +1 -1
- package/llms/cli-publish.txt +4 -1
- package/llms/cli.2.txt +42 -51
- package/llms/cli.3.txt +34 -1
- package/llms/cli.txt +18 -3
- package/llms/contract.txt +47 -5
- package/llms/handler.txt +1 -1
- package/llms/live.txt +82 -0
- package/llms/node.txt +5 -0
- package/llms/observability.2.txt +1 -1
- package/llms/observability.txt +6 -0
- package/llms/postgres.txt +14 -3
- package/llms/server.2.txt +206 -240
- package/llms/server.3.txt +242 -202
- package/llms/server.4.txt +202 -1025
- package/llms/server.5.txt +1053 -255
- package/llms/server.6.txt +274 -0
- package/llms/server.txt +32 -116
- package/llms/spend.txt +8 -7
- package/llms/stitchkit.2.txt +13 -35
- package/llms/stitchkit.3.txt +27 -0
- package/llms/stitchkit.txt +82 -82
- package/llms/testing.txt +40 -0
- package/llms/tools-toolkit.txt +2 -2
- package/llms/tools.2.txt +29 -20
- package/llms/{upgrading-0.128.0-0.129.0.txt → upgrading-0.128.0-0.131.0.txt} +101 -3
- package/llms/{upgrading-0.130.0-0.136.0.txt → upgrading-0.132.0-0.137.0.txt} +62 -101
- package/llms/upgrading.txt +2 -2
- package/llms-full.txt +641 -189
- package/llms.txt +14 -14
- package/package.json +3 -3
- package/dist/index-9118dw8d.js +0 -603
- package/dist/index-9vj869rx.js +0 -19
- package/dist/index-a1rjr381.js +0 -114
- package/dist/index-dacxr7nf.js +0 -17
- package/dist/index-dm50x3by.js +0 -63
- package/dist/index-dmrx8xma.js +0 -163
- package/dist/index-ednf2cxs.js +0 -37
- package/dist/{index-e4zt2x70.js → index-3czppvrr.js} +3 -3
- package/dist/{index-42n9jycn.js → index-3f79t32b.js} +3 -3
- package/dist/{index-mfe9a266.js → index-84n49vam.js} +0 -0
- package/dist/{index-f16b7rze.js → index-er1tp8de.js} +3 -3
- package/dist/{index-k137ezb6.js → index-f5d0fdcf.js} +3 -3
- package/dist/{index-65p8v81y.js → index-psz8qrz0.js} +3 -3
- package/dist/{index-kadgaw1s.js → index-r8cq86h1.js} +0 -0
- package/dist/{index-1yky29qg.js → index-tyyvbarf.js} +0 -0
- package/dist/{index-tjakdpf2.js → index-wq71v08n.js} +3 -3
- package/dist/{index-7an2fs5h.js → index-wswcpbm4.js} +3 -3
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./index-
|
|
2
|
+
localVerdict
|
|
3
|
+
} from "./index-dsa676h8.js";
|
|
4
4
|
import {
|
|
5
5
|
toJsonSchema
|
|
6
6
|
} from "./index-d1pdv8qc.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
objectShapeKeys,
|
|
9
|
+
rebuildObject,
|
|
10
|
+
mergeSchemas,
|
|
11
|
+
coerceJsonArgs2
|
|
12
|
+
} from "./index-hgf1tbgz.js";
|
|
13
|
+
import {
|
|
14
|
+
isHttpOnlyEndpoint
|
|
15
|
+
} from "./index-yt1gg11x.js";
|
|
16
|
+
import {
|
|
17
|
+
assertInputRecursionDepth,
|
|
18
|
+
assertInputNestingDepth
|
|
19
|
+
} from "./index-kw0segzt.js";
|
|
20
|
+
import {
|
|
21
|
+
assertErrorCodeMapping,
|
|
22
|
+
resolveWireError,
|
|
23
|
+
rememberCanonicalError,
|
|
24
|
+
canonicalErrorCodeFor
|
|
25
|
+
} from "./index-fy9mmek1.js";
|
|
26
|
+
import {
|
|
27
|
+
runWithRequestContext2,
|
|
28
|
+
getRequestContext2
|
|
29
|
+
} from "./index-q4tr9vnf.js";
|
|
10
30
|
import {
|
|
31
|
+
normalizeError2,
|
|
11
32
|
validateDeclaredOutput
|
|
12
|
-
} from "./index-
|
|
33
|
+
} from "./index-pt25vmhc.js";
|
|
13
34
|
import {
|
|
35
|
+
projectedToolError,
|
|
14
36
|
withDraft2020Keywords,
|
|
15
37
|
stringValues,
|
|
16
38
|
mergePropertySchemas
|
|
17
|
-
} from "./index-
|
|
39
|
+
} from "./index-frsd2a94.js";
|
|
18
40
|
import {
|
|
19
41
|
assertNoLegacyTransports
|
|
20
42
|
} from "./index-akfgymyr.js";
|
|
@@ -24,12 +46,17 @@ import {
|
|
|
24
46
|
mapSubschemas
|
|
25
47
|
} from "./index-e413q2cj.js";
|
|
26
48
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
isUnsafeKey
|
|
50
|
+
} from "./index-zsarb5xp.js";
|
|
51
|
+
import {
|
|
52
|
+
formatZodError2
|
|
53
|
+
} from "./index-1eeqpadm.js";
|
|
30
54
|
import {
|
|
31
|
-
AppError2
|
|
32
|
-
|
|
55
|
+
AppError2,
|
|
56
|
+
STITCH_ERROR_STATUS2,
|
|
57
|
+
isRetryableStatus2,
|
|
58
|
+
isStitchErrorCode2
|
|
59
|
+
} from "./index-3pb4ccj2.js";
|
|
33
60
|
import {
|
|
34
61
|
setOwnMember
|
|
35
62
|
} from "./index-3tb82xr7.js";
|
|
@@ -37,6 +64,133 @@ import {
|
|
|
37
64
|
isRecord
|
|
38
65
|
} from "./index-ps3djm8d.js";
|
|
39
66
|
|
|
67
|
+
// src/tools/access.ts
|
|
68
|
+
var TOOL_OPEN_REASONS = ["public", "local-operator", "remote"];
|
|
69
|
+
var TOOL_OPEN_REASON_SET = new Set(TOOL_OPEN_REASONS);
|
|
70
|
+
var inspectOnlyLifecycles = new WeakMap;
|
|
71
|
+
function accessRequiredMessage(entryName) {
|
|
72
|
+
return `${entryName}: access is required — pass { gate } with the auth hook, { open }, or { inspect: true }`;
|
|
73
|
+
}
|
|
74
|
+
function legacyLifecycleMessage(entryName) {
|
|
75
|
+
return `${entryName}: access is required — pass { gate } with the auth hook, { open }, or { inspect: true } ("lifecycle" was replaced by "access")`;
|
|
76
|
+
}
|
|
77
|
+
function inspectForbiddenError(entryName) {
|
|
78
|
+
return new AppError2("FORBIDDEN", {
|
|
79
|
+
message: `${entryName}: mounted with access: { inspect: true } (read-only surface inspection); tool execution is forbidden`,
|
|
80
|
+
status: 403
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function isInspectOnlyLifecycle(lifecycle) {
|
|
84
|
+
return lifecycle !== undefined && inspectOnlyLifecycles.has(lifecycle);
|
|
85
|
+
}
|
|
86
|
+
function inspectOnlyError(lifecycle) {
|
|
87
|
+
if (lifecycle === undefined)
|
|
88
|
+
return;
|
|
89
|
+
const entryName = inspectOnlyLifecycles.get(lifecycle);
|
|
90
|
+
return entryName !== undefined ? inspectForbiddenError(entryName) : undefined;
|
|
91
|
+
}
|
|
92
|
+
function isBeforeHandleHook(value) {
|
|
93
|
+
return typeof value === "function";
|
|
94
|
+
}
|
|
95
|
+
function isAfterHandleHook(value) {
|
|
96
|
+
return typeof value === "function";
|
|
97
|
+
}
|
|
98
|
+
function isToolOpenReason(value) {
|
|
99
|
+
return typeof value === "string" && TOOL_OPEN_REASON_SET.has(value);
|
|
100
|
+
}
|
|
101
|
+
function resolveToolAccess(entryName, config) {
|
|
102
|
+
if (!isRecord(config)) {
|
|
103
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
104
|
+
}
|
|
105
|
+
if (Object.hasOwn(config, "lifecycle")) {
|
|
106
|
+
throw new TypeError(legacyLifecycleMessage(entryName));
|
|
107
|
+
}
|
|
108
|
+
if (!Object.hasOwn(config, "access")) {
|
|
109
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
110
|
+
}
|
|
111
|
+
const { access } = config;
|
|
112
|
+
if (!isRecord(access)) {
|
|
113
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
114
|
+
}
|
|
115
|
+
const hasGate = Object.hasOwn(access, "gate") && access.gate !== undefined;
|
|
116
|
+
const hasOpen = Object.hasOwn(access, "open") && access.open !== undefined;
|
|
117
|
+
const hasInspect = Object.hasOwn(access, "inspect") && access.inspect !== undefined;
|
|
118
|
+
if (Number(hasGate) + Number(hasOpen) + Number(hasInspect) !== 1) {
|
|
119
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
120
|
+
}
|
|
121
|
+
if (hasGate) {
|
|
122
|
+
for (const key of Object.keys(access)) {
|
|
123
|
+
if (key === "gate")
|
|
124
|
+
continue;
|
|
125
|
+
if ((key === "open" || key === "inspect" || key === "afterHandle") && access[key] === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
128
|
+
}
|
|
129
|
+
const { gate } = access;
|
|
130
|
+
if (!isRecord(gate)) {
|
|
131
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
132
|
+
}
|
|
133
|
+
const { beforeHandle, afterHandle } = gate;
|
|
134
|
+
if (!isBeforeHandleHook(beforeHandle)) {
|
|
135
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
136
|
+
}
|
|
137
|
+
if (afterHandle !== undefined && !isAfterHandleHook(afterHandle)) {
|
|
138
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
139
|
+
}
|
|
140
|
+
return afterHandle !== undefined ? { beforeHandle, afterHandle } : { beforeHandle };
|
|
141
|
+
}
|
|
142
|
+
if (hasInspect) {
|
|
143
|
+
for (const key of Object.keys(access)) {
|
|
144
|
+
if (key === "inspect")
|
|
145
|
+
continue;
|
|
146
|
+
if ((key === "gate" || key === "open" || key === "afterHandle") && access[key] === undefined)
|
|
147
|
+
continue;
|
|
148
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
149
|
+
}
|
|
150
|
+
if (access.inspect !== true) {
|
|
151
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
152
|
+
}
|
|
153
|
+
const lifecycle = {
|
|
154
|
+
beforeHandle() {
|
|
155
|
+
throw inspectForbiddenError(entryName);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
inspectOnlyLifecycles.set(lifecycle, entryName);
|
|
159
|
+
return lifecycle;
|
|
160
|
+
}
|
|
161
|
+
for (const key of Object.keys(access)) {
|
|
162
|
+
if (key === "open" || key === "afterHandle")
|
|
163
|
+
continue;
|
|
164
|
+
if ((key === "gate" || key === "inspect") && access[key] === undefined)
|
|
165
|
+
continue;
|
|
166
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
167
|
+
}
|
|
168
|
+
const { open, afterHandle } = access;
|
|
169
|
+
if (!isToolOpenReason(open)) {
|
|
170
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
171
|
+
}
|
|
172
|
+
if (afterHandle !== undefined && !isAfterHandleHook(afterHandle)) {
|
|
173
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
174
|
+
}
|
|
175
|
+
return afterHandle !== undefined ? { afterHandle } : {};
|
|
176
|
+
}
|
|
177
|
+
function resolveOptionalCliToolAccess(entryName, config) {
|
|
178
|
+
if (!isRecord(config)) {
|
|
179
|
+
throw new TypeError(accessRequiredMessage(entryName));
|
|
180
|
+
}
|
|
181
|
+
if (Object.hasOwn(config, "lifecycle")) {
|
|
182
|
+
throw new TypeError(legacyLifecycleMessage(entryName));
|
|
183
|
+
}
|
|
184
|
+
const hasManagedSurface = config.services !== undefined || config.runtimeTools !== undefined;
|
|
185
|
+
if (hasManagedSurface || Object.hasOwn(config, "access") && config.access !== undefined) {
|
|
186
|
+
return resolveToolAccess(entryName, config);
|
|
187
|
+
}
|
|
188
|
+
return {};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/tools/execute-args.ts
|
|
192
|
+
import { z } from "zod";
|
|
193
|
+
|
|
40
194
|
// src/tools/internal/tool-view.ts
|
|
41
195
|
function toolSurfaceOutputSchema(operation) {
|
|
42
196
|
if (!operation.outputSchema)
|
|
@@ -90,8 +244,421 @@ function projectToolView(options) {
|
|
|
90
244
|
return checked;
|
|
91
245
|
}
|
|
92
246
|
|
|
247
|
+
// src/tools/execute-args.ts
|
|
248
|
+
function parseToolCallArguments(method, callArgs, {
|
|
249
|
+
coerceJson = false,
|
|
250
|
+
toolSurface = false
|
|
251
|
+
} = {}) {
|
|
252
|
+
const paramKeys = new Set(objectShapeKeys(method.paramsSchema));
|
|
253
|
+
let paramArgs = {};
|
|
254
|
+
let inputArgs = {};
|
|
255
|
+
for (const [key, value] of Object.entries(callArgs)) {
|
|
256
|
+
if (isUnsafeKey(key))
|
|
257
|
+
continue;
|
|
258
|
+
if (paramKeys.has(key))
|
|
259
|
+
paramArgs[key] = value;
|
|
260
|
+
else
|
|
261
|
+
inputArgs[key] = value;
|
|
262
|
+
}
|
|
263
|
+
if (coerceJson) {
|
|
264
|
+
try {
|
|
265
|
+
paramArgs = coerceJsonArgs2(paramArgs, method.paramsSchema);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
if (err instanceof z.ZodError) {
|
|
268
|
+
return { ok: false, message: `Invalid params: ${formatZodError2(err)}` };
|
|
269
|
+
}
|
|
270
|
+
throw err;
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
inputArgs = coerceJsonArgs2(inputArgs, method.inputSchema);
|
|
274
|
+
} catch (err) {
|
|
275
|
+
if (err instanceof z.ZodError) {
|
|
276
|
+
return { ok: false, message: `Invalid input: ${formatZodError2(err)}` };
|
|
277
|
+
}
|
|
278
|
+
throw err;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (toolSurface)
|
|
282
|
+
inputArgs = applyToolViewDefaults(inputArgs, method.toolView?.defaults);
|
|
283
|
+
let params;
|
|
284
|
+
if (method.paramsSchema) {
|
|
285
|
+
let result;
|
|
286
|
+
try {
|
|
287
|
+
result = method.paramsSchema.safeParse(paramArgs);
|
|
288
|
+
} catch (err) {
|
|
289
|
+
return { ok: false, message: "Invalid params", thrown: err };
|
|
290
|
+
}
|
|
291
|
+
if (!result.success) {
|
|
292
|
+
return { ok: false, message: `Invalid params: ${formatZodError2(result.error)}` };
|
|
293
|
+
}
|
|
294
|
+
params = result.data;
|
|
295
|
+
}
|
|
296
|
+
let input;
|
|
297
|
+
if (method.inputSchema) {
|
|
298
|
+
let result;
|
|
299
|
+
try {
|
|
300
|
+
result = method.inputSchema.safeParse(inputArgs);
|
|
301
|
+
} catch (err) {
|
|
302
|
+
return { ok: false, message: "Invalid input", thrown: err };
|
|
303
|
+
}
|
|
304
|
+
if (result.success)
|
|
305
|
+
input = result.data;
|
|
306
|
+
else {
|
|
307
|
+
const refused = localVerdict(method.inputSchema, result.error);
|
|
308
|
+
if (refused)
|
|
309
|
+
return { ok: false, message: `Invalid input: ${formatZodError2(refused)}` };
|
|
310
|
+
input = inputArgs;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { ok: true, params, input };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/tools/execute-handler.ts
|
|
317
|
+
async function invokeToolHandler(method, ctx, input, source, {
|
|
318
|
+
lifecycle,
|
|
319
|
+
onOutputStrip,
|
|
320
|
+
finalizeOutput,
|
|
321
|
+
toolSurface
|
|
322
|
+
}) {
|
|
323
|
+
if (lifecycle?.beforeHandle) {
|
|
324
|
+
await lifecycle.beforeHandle(ctx, method);
|
|
325
|
+
}
|
|
326
|
+
let data = await method.handler(ctx);
|
|
327
|
+
if (method.stream !== undefined)
|
|
328
|
+
return { ok: true, data };
|
|
329
|
+
if (lifecycle?.afterHandle) {
|
|
330
|
+
const transformed = await lifecycle.afterHandle(ctx, data, method);
|
|
331
|
+
if (transformed !== undefined)
|
|
332
|
+
data = transformed;
|
|
333
|
+
}
|
|
334
|
+
const checked = validateDeclaredOutput(method.outputSchema, data, onOutputStrip);
|
|
335
|
+
if (checked.ok) {
|
|
336
|
+
data = checked.data;
|
|
337
|
+
} else {
|
|
338
|
+
const verdict = checked.error && method.outputSchema ? localVerdict(method.outputSchema, checked.error) : undefined;
|
|
339
|
+
if (verdict !== null) {
|
|
340
|
+
const message = verdict && verdict !== checked.error ? `Handler output does not match the contract: ${formatZodError2(verdict)}` : checked.message;
|
|
341
|
+
return {
|
|
342
|
+
ok: false,
|
|
343
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
344
|
+
details: { message }
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (toolSurface && method.toolView && method.outputSchema) {
|
|
349
|
+
const viewed = projectToolView({
|
|
350
|
+
view: method.toolView,
|
|
351
|
+
fullSchema: method.outputSchema,
|
|
352
|
+
full: data,
|
|
353
|
+
call: { input, source },
|
|
354
|
+
operation: `${method.serviceName}.${method.key}`,
|
|
355
|
+
onStripped: onOutputStrip
|
|
356
|
+
});
|
|
357
|
+
if (!viewed.ok) {
|
|
358
|
+
return {
|
|
359
|
+
ok: false,
|
|
360
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
361
|
+
details: { message: viewed.message }
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
data = viewed.data;
|
|
365
|
+
}
|
|
366
|
+
if (finalizeOutput)
|
|
367
|
+
data = await finalizeOutput(data);
|
|
368
|
+
const output = (data === undefined || data === null) && !method.outputSchema ? { status: "ok" } : data;
|
|
369
|
+
return { ok: true, data: output };
|
|
370
|
+
}
|
|
371
|
+
async function resolveToolExtension(extension, keys, rawArgs, context) {
|
|
372
|
+
const extensionArgs = Object.fromEntries(Object.entries(rawArgs).filter(([key]) => keys.has(key)));
|
|
373
|
+
let parsed;
|
|
374
|
+
try {
|
|
375
|
+
parsed = extension.schema.safeParse(extensionArgs);
|
|
376
|
+
} catch (err) {
|
|
377
|
+
return { thrown: err };
|
|
378
|
+
}
|
|
379
|
+
if (!parsed.success)
|
|
380
|
+
return { invalid: formatZodError2(parsed.error) };
|
|
381
|
+
try {
|
|
382
|
+
const resolved = await extension.resolve({ ...rawArgs, ...parsed.data });
|
|
383
|
+
return {
|
|
384
|
+
context: {
|
|
385
|
+
...context,
|
|
386
|
+
...resolved,
|
|
387
|
+
source: context.source,
|
|
388
|
+
...context.mcp !== undefined && { mcp: context.mcp },
|
|
389
|
+
...context.toolCallId !== undefined && { toolCallId: context.toolCallId }
|
|
390
|
+
},
|
|
391
|
+
args: Object.fromEntries(Object.entries(rawArgs).filter(([key]) => !keys.has(key)))
|
|
392
|
+
};
|
|
393
|
+
} catch (err) {
|
|
394
|
+
return { thrown: err };
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/tools/execute-result.ts
|
|
399
|
+
var normalizedToolErrors = new WeakMap;
|
|
400
|
+
function toolResultFromError(err) {
|
|
401
|
+
const appErr = normalizeError2(projectedToolError(err) ?? err, { logUnexpected: false });
|
|
402
|
+
const result = {
|
|
403
|
+
ok: false,
|
|
404
|
+
code: appErr.code,
|
|
405
|
+
details: appErr.details ?? { message: appErr.message },
|
|
406
|
+
...appErr.hint && { hint: appErr.hint },
|
|
407
|
+
retryable: appErr.retryable ?? isRetryableStatus2(appErr.status)
|
|
408
|
+
};
|
|
409
|
+
normalizedToolErrors.set(result, {
|
|
410
|
+
normalized: appErr,
|
|
411
|
+
canonical: appErr,
|
|
412
|
+
canonicalCode: appErr.code,
|
|
413
|
+
cause: err,
|
|
414
|
+
mapped: false
|
|
415
|
+
});
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
function applyToolErrorMapping(result, mapping) {
|
|
419
|
+
if (mapping === undefined)
|
|
420
|
+
return result;
|
|
421
|
+
const retained = normalizedToolErrors.get(result);
|
|
422
|
+
if (retained?.mapped)
|
|
423
|
+
return result;
|
|
424
|
+
const canonical = retained?.canonical ?? retained?.normalized ?? toolErrorFromResult(result);
|
|
425
|
+
const canonicalCode = retained?.canonicalCode ?? canonical.code;
|
|
426
|
+
const cause = retained?.cause;
|
|
427
|
+
const resolved = resolveWireError(canonical, mapping);
|
|
428
|
+
const retryable = result.retryable ?? canonical.retryable ?? isRetryableStatus2(canonical.status);
|
|
429
|
+
const wireError = resolved.redacted ? new AppError2(resolved.code, {
|
|
430
|
+
message: resolved.message,
|
|
431
|
+
status: resolved.status,
|
|
432
|
+
...canonical.traceId !== undefined && { traceId: canonical.traceId },
|
|
433
|
+
retryable
|
|
434
|
+
}) : resolved.code === canonical.code && retryable === canonical.retryable ? canonical : new AppError2(resolved.code, {
|
|
435
|
+
message: canonical.message,
|
|
436
|
+
status: canonical.status,
|
|
437
|
+
details: canonical.details,
|
|
438
|
+
hint: canonical.hint,
|
|
439
|
+
...canonical.traceId !== undefined && { traceId: canonical.traceId },
|
|
440
|
+
retryable
|
|
441
|
+
});
|
|
442
|
+
const mappedResult = resolved.redacted ? {
|
|
443
|
+
ok: false,
|
|
444
|
+
code: resolved.code,
|
|
445
|
+
details: { message: resolved.message },
|
|
446
|
+
retryable
|
|
447
|
+
} : {
|
|
448
|
+
...result,
|
|
449
|
+
code: resolved.code,
|
|
450
|
+
retryable
|
|
451
|
+
};
|
|
452
|
+
normalizedToolErrors.set(mappedResult, {
|
|
453
|
+
normalized: wireError,
|
|
454
|
+
canonical,
|
|
455
|
+
canonicalCode,
|
|
456
|
+
cause,
|
|
457
|
+
mapped: true
|
|
458
|
+
});
|
|
459
|
+
rememberCanonicalError(mappedResult, canonical);
|
|
460
|
+
return mappedResult;
|
|
461
|
+
}
|
|
462
|
+
function canonicalToolErrorCode(result) {
|
|
463
|
+
return normalizedToolErrors.get(result)?.canonicalCode ?? canonicalErrorCodeFor(result, result.code);
|
|
464
|
+
}
|
|
465
|
+
function toolErrorFromResult(result) {
|
|
466
|
+
const retained = normalizedToolErrors.get(result);
|
|
467
|
+
if (retained)
|
|
468
|
+
return retained.normalized;
|
|
469
|
+
const details = isRecord(result.details) ? result.details : undefined;
|
|
470
|
+
const message = typeof details?.message === "string" ? details.message : result.code;
|
|
471
|
+
const status = isStitchErrorCode2(result.code) ? STITCH_ERROR_STATUS2[result.code] : 500;
|
|
472
|
+
return new AppError2(result.code, {
|
|
473
|
+
message,
|
|
474
|
+
status,
|
|
475
|
+
details,
|
|
476
|
+
hint: result.hint,
|
|
477
|
+
retryable: result.retryable
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
function toolErrorMessageFromResult(result) {
|
|
481
|
+
const retained = normalizedToolErrors.get(result);
|
|
482
|
+
if (retained)
|
|
483
|
+
return retained.normalized.message;
|
|
484
|
+
return isRecord(result.details) && typeof result.details.message === "string" ? result.details.message : undefined;
|
|
485
|
+
}
|
|
486
|
+
function toolCauseFromResult(result) {
|
|
487
|
+
return normalizedToolErrors.get(result)?.cause;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/tools/internal/observe-hook.ts
|
|
491
|
+
async function observed(hook, call) {
|
|
492
|
+
try {
|
|
493
|
+
await call();
|
|
494
|
+
} catch (hookError) {
|
|
495
|
+
try {
|
|
496
|
+
console.error(`[stitchkit] ${hook} hook failed:`, hookError);
|
|
497
|
+
} catch {}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/tools/execute.ts
|
|
502
|
+
class ToolExecutionControlError2 extends Error {
|
|
503
|
+
reason;
|
|
504
|
+
constructor(reason) {
|
|
505
|
+
super(`Agent tool execution stopped: ${reason}`);
|
|
506
|
+
this.name = "ToolExecutionControlError";
|
|
507
|
+
this.reason = reason;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function isPlainObject(value) {
|
|
511
|
+
if (!isRecord(value))
|
|
512
|
+
return false;
|
|
513
|
+
const proto = Object.getPrototypeOf(value);
|
|
514
|
+
return proto === Object.prototype || proto === null;
|
|
515
|
+
}
|
|
516
|
+
function isToolExecutionControlError2(value) {
|
|
517
|
+
return value instanceof ToolExecutionControlError2;
|
|
518
|
+
}
|
|
519
|
+
var noProgress = async () => {
|
|
520
|
+
return;
|
|
521
|
+
};
|
|
522
|
+
async function executeToolMethod(method, call, options = {}) {
|
|
523
|
+
const inspectErr = inspectOnlyError(options.lifecycle);
|
|
524
|
+
if (inspectErr) {
|
|
525
|
+
return applyToolErrorMapping(toolResultFromError(inspectErr), options.errors);
|
|
526
|
+
}
|
|
527
|
+
const { toolName, context } = call;
|
|
528
|
+
return inToolCallContext({ source: context.source, toolName, method }, () => runToolMethod(method, call, options));
|
|
529
|
+
}
|
|
530
|
+
function inToolCallContext(call, body) {
|
|
531
|
+
const parent = getRequestContext2();
|
|
532
|
+
if (!parent)
|
|
533
|
+
return body();
|
|
534
|
+
return runWithRequestContext2({
|
|
535
|
+
...parent,
|
|
536
|
+
trace: parent.trace,
|
|
537
|
+
dimensions: parent.dimensions ? { ...parent.dimensions } : undefined,
|
|
538
|
+
error: undefined,
|
|
539
|
+
source: call.source,
|
|
540
|
+
method: "TOOL",
|
|
541
|
+
path: `/${call.source}/${call.toolName}`,
|
|
542
|
+
serviceName: call.method.serviceName,
|
|
543
|
+
action: call.method.key
|
|
544
|
+
}, body);
|
|
545
|
+
}
|
|
546
|
+
async function runToolMethod(method, { toolName, rawArgs, context }, {
|
|
547
|
+
hooks,
|
|
548
|
+
lifecycle,
|
|
549
|
+
coerceJson = false,
|
|
550
|
+
onOutputStrip,
|
|
551
|
+
extension,
|
|
552
|
+
finalizeOutput,
|
|
553
|
+
toolSurface = false,
|
|
554
|
+
errors
|
|
555
|
+
}) {
|
|
556
|
+
const startedAt = Date.now();
|
|
557
|
+
let hookContext = context;
|
|
558
|
+
const finish = async (result, thrown) => {
|
|
559
|
+
const mapped = result.ok ? result : applyToolErrorMapping(result, errors);
|
|
560
|
+
await observed("afterToolCall", () => hooks?.afterToolCall?.({
|
|
561
|
+
toolName,
|
|
562
|
+
args: rawArgs,
|
|
563
|
+
result: mapped,
|
|
564
|
+
durationMs: Date.now() - startedAt,
|
|
565
|
+
context: hookContext,
|
|
566
|
+
endpoint: method,
|
|
567
|
+
...thrown !== undefined && { error: thrown },
|
|
568
|
+
...rewrittenArgsApplied && rewrittenArgs !== undefined && { effectiveArgs: rewrittenArgs }
|
|
569
|
+
}));
|
|
570
|
+
return mapped;
|
|
571
|
+
};
|
|
572
|
+
let beforeRan = false;
|
|
573
|
+
let rewrittenArgs;
|
|
574
|
+
let rewrittenArgsApplied = false;
|
|
575
|
+
const runBefore = async () => {
|
|
576
|
+
if (beforeRan || !hooks?.beforeToolCall)
|
|
577
|
+
return null;
|
|
578
|
+
beforeRan = true;
|
|
579
|
+
let returned;
|
|
580
|
+
try {
|
|
581
|
+
returned = await hooks.beforeToolCall({
|
|
582
|
+
toolName,
|
|
583
|
+
args: rawArgs,
|
|
584
|
+
context: hookContext,
|
|
585
|
+
endpoint: method
|
|
586
|
+
});
|
|
587
|
+
} catch (err) {
|
|
588
|
+
return { kind: "failure", result: await finish(toolResultFromError(err)) };
|
|
589
|
+
}
|
|
590
|
+
if (!isPlainObject(returned))
|
|
591
|
+
return null;
|
|
592
|
+
rewrittenArgs = returned;
|
|
593
|
+
return { kind: "args" };
|
|
594
|
+
};
|
|
595
|
+
const finishThrown = async (err) => {
|
|
596
|
+
const before = await runBefore();
|
|
597
|
+
if (before?.kind === "failure")
|
|
598
|
+
return before.result;
|
|
599
|
+
await observed("onToolError", () => hooks?.onToolError?.({ toolName, error: err, context: hookContext, endpoint: method }));
|
|
600
|
+
return finish(toolResultFromError(err), err);
|
|
601
|
+
};
|
|
602
|
+
let callArgs = rawArgs;
|
|
603
|
+
let callContext = context;
|
|
604
|
+
let extensionKeys;
|
|
605
|
+
if (extension) {
|
|
606
|
+
extensionKeys = new Set(Object.keys(extension.schema.shape));
|
|
607
|
+
const resolved = await resolveToolExtension(extension, extensionKeys, rawArgs, context);
|
|
608
|
+
if ("thrown" in resolved)
|
|
609
|
+
return finishThrown(resolved.thrown);
|
|
610
|
+
if ("invalid" in resolved) {
|
|
611
|
+
const before = await runBefore();
|
|
612
|
+
if (before?.kind === "failure")
|
|
613
|
+
return before.result;
|
|
614
|
+
return finish({
|
|
615
|
+
ok: false,
|
|
616
|
+
code: "VALIDATION_ERROR",
|
|
617
|
+
details: { message: `Invalid tool extension: ${resolved.invalid}` }
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
callContext = resolved.context;
|
|
621
|
+
hookContext = callContext;
|
|
622
|
+
callArgs = resolved.args;
|
|
623
|
+
}
|
|
624
|
+
const before = await runBefore();
|
|
625
|
+
if (before?.kind === "failure")
|
|
626
|
+
return before.result;
|
|
627
|
+
if (before?.kind === "args" && rewrittenArgs) {
|
|
628
|
+
callArgs = extensionKeys ? Object.fromEntries(Object.entries(rewrittenArgs).filter(([key]) => !extensionKeys.has(key))) : rewrittenArgs;
|
|
629
|
+
rewrittenArgsApplied = true;
|
|
630
|
+
}
|
|
631
|
+
const parsed = parseToolCallArguments(method, callArgs, { coerceJson, toolSurface });
|
|
632
|
+
if (!parsed.ok) {
|
|
633
|
+
return parsed.thrown !== undefined ? finishThrown(parsed.thrown) : finish({ ok: false, code: "VALIDATION_ERROR", details: { message: parsed.message } });
|
|
634
|
+
}
|
|
635
|
+
const { params, input } = parsed;
|
|
636
|
+
try {
|
|
637
|
+
const ctx = {
|
|
638
|
+
reportProgress: noProgress,
|
|
639
|
+
...callContext,
|
|
640
|
+
params,
|
|
641
|
+
input,
|
|
642
|
+
source: context.source
|
|
643
|
+
};
|
|
644
|
+
return finish(await invokeToolHandler(method, ctx, input, context.source, {
|
|
645
|
+
lifecycle,
|
|
646
|
+
onOutputStrip,
|
|
647
|
+
finalizeOutput,
|
|
648
|
+
toolSurface
|
|
649
|
+
}));
|
|
650
|
+
} catch (err) {
|
|
651
|
+
if (isToolExecutionControlError2(err))
|
|
652
|
+
throw err;
|
|
653
|
+
return finishThrown(err);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/tools/mount.ts
|
|
658
|
+
import { z as z4 } from "zod";
|
|
659
|
+
|
|
93
660
|
// src/tools/internal/surface-projector.ts
|
|
94
|
-
import { z as
|
|
661
|
+
import { z as z3 } from "zod";
|
|
95
662
|
|
|
96
663
|
// src/tools/names.ts
|
|
97
664
|
var SINGULAR_EXCEPTIONS = new Set([
|
|
@@ -159,7 +726,7 @@ function assertUniqueToolName(name, taken, surface) {
|
|
|
159
726
|
}
|
|
160
727
|
|
|
161
728
|
// src/tools/schema/presentation.ts
|
|
162
|
-
import { z } from "zod";
|
|
729
|
+
import { z as z2 } from "zod";
|
|
163
730
|
|
|
164
731
|
// src/tools/schema/flatten.ts
|
|
165
732
|
function rebuild(value) {
|
|
@@ -741,7 +1308,7 @@ function buildToolPresentationSchema(config) {
|
|
|
741
1308
|
};
|
|
742
1309
|
}
|
|
743
1310
|
if (config.extendSchema) {
|
|
744
|
-
const extra = namespaceLocalReferences(schemaFromZod(
|
|
1311
|
+
const extra = namespaceLocalReferences(schemaFromZod(z2.object(config.extendSchema), steps), "extend");
|
|
745
1312
|
if (extra) {
|
|
746
1313
|
presentation = mergeObjectSchemas(withoutDialect(extra), withoutDialect(presentation), true);
|
|
747
1314
|
}
|
|
@@ -788,7 +1355,7 @@ function presentationMetadata(schema) {
|
|
|
788
1355
|
|
|
789
1356
|
// src/tools/internal/surface-projector.ts
|
|
790
1357
|
function assertToolExtensionCompatible(base, extra) {
|
|
791
|
-
if (!(base instanceof
|
|
1358
|
+
if (!(base instanceof z3.ZodObject))
|
|
792
1359
|
return;
|
|
793
1360
|
const conflicts = Object.keys(extra).filter((key) => (key in base.shape));
|
|
794
1361
|
if (conflicts.length > 0) {
|
|
@@ -910,4 +1477,90 @@ function projectToolSurface(surface, transport, config = {}) {
|
|
|
910
1477
|
return projected;
|
|
911
1478
|
}
|
|
912
1479
|
|
|
913
|
-
|
|
1480
|
+
// src/tools/mount.ts
|
|
1481
|
+
function applyExtend(base, extra) {
|
|
1482
|
+
if (base instanceof z4.ZodObject) {
|
|
1483
|
+
assertToolExtensionCompatible(base, extra);
|
|
1484
|
+
return rebuildObject(base, { ...extra, ...base.shape });
|
|
1485
|
+
}
|
|
1486
|
+
return z4.intersection(z4.object(extra), base);
|
|
1487
|
+
}
|
|
1488
|
+
function contractToolMountable(projected, extend) {
|
|
1489
|
+
const method = projected.source;
|
|
1490
|
+
const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
|
|
1491
|
+
const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
|
|
1492
|
+
return {
|
|
1493
|
+
method,
|
|
1494
|
+
name: projected.name,
|
|
1495
|
+
argumentSchema,
|
|
1496
|
+
presentationSchema: projected.presentationSchema,
|
|
1497
|
+
shouldExtend: projected.shouldExtend
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
function collectTools2(service, transport, config = {}) {
|
|
1501
|
+
const {
|
|
1502
|
+
extend,
|
|
1503
|
+
flattenUnionInput = false,
|
|
1504
|
+
inputRecursionDepth,
|
|
1505
|
+
inputNestingDepth,
|
|
1506
|
+
assertNames = true
|
|
1507
|
+
} = config;
|
|
1508
|
+
const tools = [];
|
|
1509
|
+
for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
|
|
1510
|
+
extend,
|
|
1511
|
+
flattenUnionInput,
|
|
1512
|
+
inputRecursionDepth,
|
|
1513
|
+
inputNestingDepth,
|
|
1514
|
+
assertNames,
|
|
1515
|
+
assertUniqueNames: false
|
|
1516
|
+
})) {
|
|
1517
|
+
if (projected.kind !== "contract")
|
|
1518
|
+
continue;
|
|
1519
|
+
tools.push(contractToolMountable(projected, extend));
|
|
1520
|
+
}
|
|
1521
|
+
return tools;
|
|
1522
|
+
}
|
|
1523
|
+
function createToolRunner(config) {
|
|
1524
|
+
assertErrorCodeMapping("createToolRunner", config.errors);
|
|
1525
|
+
const extension = config.extend ? {
|
|
1526
|
+
schema: z4.object(config.extend.schema),
|
|
1527
|
+
resolve: config.extend.resolve
|
|
1528
|
+
} : undefined;
|
|
1529
|
+
return async function runOneToolCall(tool, rawArgs, context, call) {
|
|
1530
|
+
return executeToolMethod(tool.method, {
|
|
1531
|
+
toolName: tool.name,
|
|
1532
|
+
rawArgs,
|
|
1533
|
+
context: { ...config.context, ...context, source: config.source }
|
|
1534
|
+
}, {
|
|
1535
|
+
hooks: config.hooks,
|
|
1536
|
+
lifecycle: config.lifecycle,
|
|
1537
|
+
coerceJson: config.coerceJsonArgs ?? true,
|
|
1538
|
+
onOutputStrip: config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined,
|
|
1539
|
+
extension: tool.shouldExtend ? extension : undefined,
|
|
1540
|
+
toolSurface: config.toolSurface ?? false,
|
|
1541
|
+
finalizeOutput: call?.finalizeOutput,
|
|
1542
|
+
errors: config.errors
|
|
1543
|
+
});
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
function formatToolError(result, toolName, errorHint) {
|
|
1547
|
+
const err = {
|
|
1548
|
+
error: result.code,
|
|
1549
|
+
retryable: result.retryable ?? isRetryableStatus2(toolErrorFromResult(result).status)
|
|
1550
|
+
};
|
|
1551
|
+
if (result.details)
|
|
1552
|
+
err.details = result.details;
|
|
1553
|
+
const hints = [];
|
|
1554
|
+
if (result.hint)
|
|
1555
|
+
hints.push(result.hint);
|
|
1556
|
+
if (errorHint && toolName) {
|
|
1557
|
+
const global = errorHint(toolName, result.code);
|
|
1558
|
+
if (global)
|
|
1559
|
+
hints.push(global);
|
|
1560
|
+
}
|
|
1561
|
+
if (hints.length > 0)
|
|
1562
|
+
err._hint = hints.join(" ");
|
|
1563
|
+
return err;
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
export { isInspectOnlyLifecycle, inspectOnlyError, resolveToolAccess, resolveOptionalCliToolAccess, toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, parseToolCallArguments, toolResultFromError, applyToolErrorMapping, canonicalToolErrorCode, toolErrorFromResult, toolErrorMessageFromResult, toolCauseFromResult, observed, ToolExecutionControlError2, isToolExecutionControlError2, assertToolName, toToolName, assertUniqueToolName, flattenToolJsonSchema2, buildToolPresentationSchema, isObjectPresentationSchema, presentationMetadata, projectedContractToolName, projectToolSurface, contractToolMountable, collectTools2, createToolRunner, formatToolError };
|