stitchkit 0.93.0 → 0.94.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 +134 -0
- package/README.md +5 -2
- package/dist/agent-runtime/children-control.d.ts +6 -0
- package/dist/agent-runtime/children-control.d.ts.map +1 -0
- package/dist/agent-runtime/children-spawn.d.ts +6 -0
- package/dist/agent-runtime/children-spawn.d.ts.map +1 -0
- package/dist/agent-runtime/children-state.d.ts +46 -0
- package/dist/agent-runtime/children-state.d.ts.map +1 -0
- package/dist/agent-runtime/children-usage.d.ts +8 -0
- package/dist/agent-runtime/children-usage.d.ts.map +1 -0
- package/dist/agent-runtime/children.d.ts +11 -14
- package/dist/agent-runtime/children.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts +2 -1
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +2 -2
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/events.d.ts +1 -1
- package/dist/agent-runtime/events.d.ts.map +1 -1
- package/dist/agent-runtime/managed-tools.d.ts +1 -1
- package/dist/agent-runtime/managed-tools.d.ts.map +1 -1
- package/dist/agent-runtime/observability.d.ts +1 -1
- package/dist/agent-runtime/observability.d.ts.map +1 -1
- package/dist/{agent-runtime-openrouter.d.ts → agent-runtime/openrouter.d.ts} +3 -3
- package/dist/agent-runtime/openrouter.d.ts.map +1 -0
- package/dist/agent-runtime/projections.d.ts +1 -1
- package/dist/agent-runtime/projections.d.ts.map +1 -1
- package/dist/agent-runtime/run-acquisition.d.ts +17 -0
- package/dist/agent-runtime/run-acquisition.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution-state.d.ts +133 -0
- package/dist/agent-runtime/run-execution-state.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution.d.ts +17 -33
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/run-failure.d.ts +18 -0
- package/dist/agent-runtime/run-failure.d.ts.map +1 -0
- package/dist/agent-runtime/run-model-attempts.d.ts +6 -0
- package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -0
- package/dist/agent-runtime/run-prompt-history.d.ts +58 -0
- package/dist/agent-runtime/run-prompt-history.d.ts.map +1 -0
- package/dist/agent-runtime/run-provider-ledger.d.ts +26 -0
- package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -0
- package/dist/agent-runtime/run-stream-parts.d.ts +17 -0
- package/dist/agent-runtime/run-stream-parts.d.ts.map +1 -0
- package/dist/agent-runtime/run-terminal.d.ts +11 -0
- package/dist/agent-runtime/run-terminal.d.ts.map +1 -0
- package/dist/agent-runtime/run-turn-preparation.d.ts +22 -0
- package/dist/agent-runtime/run-turn-preparation.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-admission-gate.d.ts +29 -0
- package/dist/agent-runtime/runtime-admission-gate.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-control.d.ts +9 -0
- package/dist/agent-runtime/runtime-control.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-recovery.d.ts +10 -0
- package/dist/agent-runtime/runtime-recovery.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-state.d.ts +36 -0
- package/dist/agent-runtime/runtime-state.d.ts.map +1 -0
- package/dist/agent-runtime/runtime-submit.d.ts +5 -0
- package/dist/agent-runtime/runtime-submit.d.ts.map +1 -0
- package/dist/agent-runtime/runtime.d.ts +9 -4
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/{agent-runtime-sqlite-bun.d.ts → agent-runtime/sqlite-bun.d.ts} +5 -4
- package/dist/agent-runtime/sqlite-bun.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-events.d.ts +5 -0
- package/dist/agent-runtime/sqlite-events.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-history.d.ts +7 -0
- package/dist/agent-runtime/sqlite-history.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-ledger.d.ts +7 -0
- package/dist/agent-runtime/sqlite-ledger.d.ts.map +1 -0
- package/dist/{agent-runtime-sqlite-node.d.ts → agent-runtime/sqlite-node.d.ts} +5 -4
- package/dist/agent-runtime/sqlite-node.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-reads.d.ts +14 -0
- package/dist/agent-runtime/sqlite-reads.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-rows.d.ts +178 -0
- package/dist/agent-runtime/sqlite-rows.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-schema.d.ts +7 -0
- package/dist/agent-runtime/sqlite-schema.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-transactions.d.ts +25 -0
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite.d.ts +10 -6
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/store-archive.d.ts +16 -0
- package/dist/agent-runtime/store-archive.d.ts.map +1 -0
- package/dist/{testing/agent-store-conformance.d.ts → agent-runtime/store-conformance.d.ts} +2 -2
- package/dist/agent-runtime/store-conformance.d.ts.map +1 -0
- package/dist/agent-runtime/store-create.d.ts +11 -0
- package/dist/agent-runtime/store-create.d.ts.map +1 -0
- package/dist/agent-runtime/{store-driver.d.ts → store-driver-contract.d.ts} +7 -7
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -0
- package/dist/agent-runtime/store-events.d.ts +7 -89
- package/dist/agent-runtime/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory.d.ts +4 -0
- package/dist/agent-runtime/store-memory.d.ts.map +1 -0
- package/dist/agent-runtime/store-mutate.d.ts +13 -0
- package/dist/agent-runtime/store-mutate.d.ts.map +1 -0
- package/dist/agent-runtime/store-purge.d.ts +1 -1
- package/dist/agent-runtime/store-purge.d.ts.map +1 -1
- package/dist/agent-runtime/store-reads.d.ts +29 -0
- package/dist/agent-runtime/store-reads.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-history.d.ts +10 -0
- package/dist/agent-runtime/store-reduce-history.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-run.d.ts +14 -0
- package/dist/agent-runtime/store-reduce-run.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-shared.d.ts +76 -0
- package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -0
- package/dist/agent-runtime/store-reduce-terminal.d.ts +6 -0
- package/dist/agent-runtime/store-reduce-terminal.d.ts.map +1 -0
- package/dist/agent-runtime/store-reducer.d.ts +24 -0
- package/dist/agent-runtime/store-reducer.d.ts.map +1 -0
- package/dist/agent-runtime/store-snapshot.d.ts +19 -0
- package/dist/agent-runtime/store-snapshot.d.ts.map +1 -0
- package/dist/agent-runtime/store.d.ts +1 -1
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/application/admission.d.ts +1 -1
- package/dist/application/admission.d.ts.map +1 -1
- package/dist/application/events.d.ts +1 -1
- package/dist/application/events.d.ts.map +1 -1
- package/dist/{server → application}/file-state-store.d.ts +1 -1
- package/dist/application/file-state-store.d.ts.map +1 -0
- package/dist/application/health.d.ts +1 -1
- package/dist/application/health.d.ts.map +1 -1
- package/dist/application/kernel-admission.d.ts +8 -0
- package/dist/application/kernel-admission.d.ts.map +1 -0
- package/dist/application/kernel-contract.d.ts +142 -0
- package/dist/application/kernel-contract.d.ts.map +1 -0
- package/dist/application/kernel-resource-context.d.ts +24 -0
- package/dist/application/kernel-resource-context.d.ts.map +1 -0
- package/dist/application/kernel-restart.d.ts +5 -0
- package/dist/application/kernel-restart.d.ts.map +1 -0
- package/dist/application/kernel-rollback.d.ts +4 -0
- package/dist/application/kernel-rollback.d.ts.map +1 -0
- package/dist/application/kernel-shutdown.d.ts +6 -0
- package/dist/application/kernel-shutdown.d.ts.map +1 -0
- package/dist/application/kernel-start.d.ts +20 -0
- package/dist/application/kernel-start.d.ts.map +1 -0
- package/dist/application/kernel-state.d.ts +116 -0
- package/dist/application/kernel-state.d.ts.map +1 -0
- package/dist/application/kernel.d.ts +9 -140
- package/dist/application/kernel.d.ts.map +1 -1
- package/dist/application/latest-sink.d.ts +1 -1
- package/dist/application/latest-sink.d.ts.map +1 -1
- package/dist/application/opentelemetry.d.ts +1 -1
- package/dist/application/opentelemetry.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts +2 -2
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/browser/client-multipart.d.ts +1 -1
- package/dist/browser/client-multipart.d.ts.map +1 -1
- package/dist/browser/client-url.d.ts +1 -1
- package/dist/browser/client-url.d.ts.map +1 -1
- package/dist/browser/client.d.ts +1 -1
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/contract-stream.d.ts +1 -1
- package/dist/browser/contract-stream.d.ts.map +1 -1
- package/dist/browser/http.d.ts +1 -1
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/resumable.d.ts +1 -28
- package/dist/browser/resumable.d.ts.map +1 -1
- package/dist/browser/retained.d.ts.map +1 -0
- package/dist/browser/socket-io.d.ts +23 -1
- package/dist/browser/socket-io.d.ts.map +1 -1
- package/dist/browser/stream.d.ts +14 -2
- package/dist/browser/stream.d.ts.map +1 -1
- package/dist/contract/define.d.ts +72 -65
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/{internal/errors.d.ts → contract/normalize.d.ts} +3 -39
- package/dist/contract/normalize.d.ts.map +1 -0
- package/dist/contract/tool-view.d.ts +135 -0
- package/dist/contract/tool-view.d.ts.map +1 -0
- package/dist/declaration/declaration.d.ts.map +1 -0
- package/dist/{agent-runtime/durability-contract.d.ts → durability/contract.d.ts} +2 -2
- package/dist/durability/contract.d.ts.map +1 -0
- package/dist/{agent-runtime/durability.d.ts → durability/engine.d.ts} +4 -4
- package/dist/durability/engine.d.ts.map +1 -0
- package/dist/durability/events.d.ts +101 -0
- package/dist/durability/events.d.ts.map +1 -0
- package/dist/{agent-runtime/durability-json.d.ts → durability/json.d.ts} +1 -1
- package/dist/durability/json.d.ts.map +1 -0
- package/dist/{agent-runtime/durability-ledger.d.ts → durability/ledger.d.ts} +2 -2
- package/dist/durability/ledger.d.ts.map +1 -0
- package/dist/{agent-runtime/durability-scheduler.d.ts → durability/scheduler.d.ts} +2 -2
- package/dist/durability/scheduler.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts +5 -0
- package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -0
- package/dist/{agent-runtime-browser.js → entrypoints/agent-runtime/browser.js} +3 -3
- package/dist/{agent-runtime-coding-tools.d.ts → entrypoints/agent-runtime/coding-tools.d.ts} +2 -2
- package/dist/entrypoints/agent-runtime/coding-tools.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/coding-tools.js +22 -0
- package/dist/{agent-runtime-harness.d.ts → entrypoints/agent-runtime/harness.d.ts} +2 -2
- package/dist/entrypoints/agent-runtime/harness.d.ts.map +1 -0
- package/dist/{agent-runtime-harness.js → entrypoints/agent-runtime/harness.js} +24 -25
- package/dist/entrypoints/agent-runtime/openrouter.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/openrouter.d.ts.map +1 -0
- package/dist/{agent-runtime-openrouter.js → entrypoints/agent-runtime/openrouter.js} +3 -3
- package/dist/{agent-runtime-sandbox.d.ts → entrypoints/agent-runtime/sandbox.d.ts} +5 -5
- package/dist/entrypoints/agent-runtime/sandbox.d.ts.map +1 -0
- package/dist/{agent-runtime-sandbox.js → entrypoints/agent-runtime/sandbox.js} +11 -12
- package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/sqlite/bun.d.ts.map +1 -0
- package/dist/{agent-runtime-sqlite-bun.js → entrypoints/agent-runtime/sqlite/bun.js} +8 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.d.ts +2 -0
- package/dist/entrypoints/agent-runtime/sqlite/node.d.ts.map +1 -0
- package/dist/{agent-runtime-sqlite-node.js → entrypoints/agent-runtime/sqlite/node.js} +8 -6
- package/dist/entrypoints/agent-runtime/testing.d.ts +4 -0
- package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -0
- package/dist/entrypoints/agent-runtime/testing.js +1084 -0
- package/dist/{agent-runtime.d.ts → entrypoints/agent-runtime.d.ts} +41 -37
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -0
- package/dist/{agent-runtime.js → entrypoints/agent-runtime.js} +408 -366
- package/dist/{application-diagnostic-journal.d.ts → entrypoints/application/diagnostic-journal.d.ts} +2 -2
- package/dist/entrypoints/application/diagnostic-journal.d.ts.map +1 -0
- package/dist/{application-diagnostic-journal.js → entrypoints/application/diagnostic-journal.js} +3 -3
- package/dist/{application-grammy.d.ts → entrypoints/application/grammy.d.ts} +2 -2
- package/dist/entrypoints/application/grammy.d.ts.map +1 -0
- package/dist/{application-grammy.js → entrypoints/application/grammy.js} +2 -2
- package/dist/{application-opentelemetry.d.ts → entrypoints/application/opentelemetry.d.ts} +2 -2
- package/dist/entrypoints/application/opentelemetry.d.ts.map +1 -0
- package/dist/{application-opentelemetry.js → entrypoints/application/opentelemetry.js} +4 -4
- package/dist/{application-schemas.d.ts → entrypoints/application/schemas.d.ts} +2 -2
- package/dist/entrypoints/application/schemas.d.ts.map +1 -0
- package/dist/{application-schemas.js → entrypoints/application/schemas.js} +2 -2
- package/dist/{application.d.ts → entrypoints/application.d.ts} +22 -21
- package/dist/entrypoints/application.d.ts.map +1 -0
- package/dist/{application.js → entrypoints/application.js} +24 -22
- package/dist/entrypoints/bin/upgrade-cli.d.ts.map +1 -0
- package/dist/{upgrade-cli.js → entrypoints/bin/upgrade-cli.js} +3 -3
- package/dist/{cli.d.ts → entrypoints/cli.d.ts} +15 -15
- package/dist/entrypoints/cli.d.ts.map +1 -0
- package/dist/{cli.js → entrypoints/cli.js} +30 -32
- package/dist/entrypoints/contract.d.ts +9 -0
- package/dist/entrypoints/contract.d.ts.map +1 -0
- package/dist/{contract/index.js → entrypoints/contract.js} +14 -6
- package/dist/entrypoints/declaration.d.ts +2 -0
- package/dist/entrypoints/declaration.d.ts.map +1 -0
- package/dist/{declaration.js → entrypoints/declaration.js} +1 -1
- package/dist/{files.d.ts → entrypoints/files.d.ts} +2 -2
- package/dist/entrypoints/files.d.ts.map +1 -0
- package/dist/{files.js → entrypoints/files.js} +3 -3
- package/dist/{geo.d.ts → entrypoints/geo.d.ts} +1 -1
- package/dist/entrypoints/geo.d.ts.map +1 -0
- package/dist/{geo.js → entrypoints/geo.js} +4 -4
- package/dist/entrypoints/google.d.ts +2 -0
- package/dist/entrypoints/google.d.ts.map +1 -0
- package/dist/{google.js → entrypoints/google.js} +1 -1
- package/dist/{index.d.ts → entrypoints/index.d.ts} +14 -13
- package/dist/entrypoints/index.d.ts.map +1 -0
- package/dist/{index.js → entrypoints/index.js} +99 -33
- package/dist/{live.d.ts → entrypoints/live.d.ts} +4 -4
- package/dist/entrypoints/live.d.ts.map +1 -0
- package/dist/{live.js → entrypoints/live.js} +6 -4
- package/dist/{node.d.ts → entrypoints/node.d.ts} +11 -11
- package/dist/entrypoints/node.d.ts.map +1 -0
- package/dist/{node.js → entrypoints/node.js} +20 -16
- package/dist/entrypoints/oauth.d.ts +2 -0
- package/dist/entrypoints/oauth.d.ts.map +1 -0
- package/dist/{oauth.js → entrypoints/oauth.js} +3 -3
- package/dist/{observability/index.d.ts → entrypoints/observability.d.ts} +11 -11
- package/dist/entrypoints/observability.d.ts.map +1 -0
- package/dist/{observability/index.js → entrypoints/observability.js} +9 -11
- package/dist/entrypoints/primitives.d.ts +3 -0
- package/dist/entrypoints/primitives.d.ts.map +1 -0
- package/dist/{primitives.js → entrypoints/primitives.js} +1 -6
- package/dist/{react.d.ts → entrypoints/react.d.ts} +4 -4
- package/dist/entrypoints/react.d.ts.map +1 -0
- package/dist/{react.js → entrypoints/react.js} +3 -3
- package/dist/{release.d.ts → entrypoints/release.d.ts} +4 -4
- package/dist/entrypoints/release.d.ts.map +1 -0
- package/dist/{release.js → entrypoints/release.js} +1 -1
- package/dist/{remote.d.ts → entrypoints/remote.d.ts} +1 -1
- package/dist/entrypoints/remote.d.ts.map +1 -0
- package/dist/entrypoints/remote.js +66 -0
- package/dist/{server/index.d.ts → entrypoints/server.d.ts} +35 -34
- package/dist/entrypoints/server.d.ts.map +1 -0
- package/dist/{server/index.js → entrypoints/server.js} +294 -244
- package/dist/{telegram.d.ts → entrypoints/telegram.d.ts} +2 -2
- package/dist/entrypoints/telegram.d.ts.map +1 -0
- package/dist/{telegram.js → entrypoints/telegram.js} +1 -1
- package/dist/entrypoints/testing.d.ts +9 -0
- package/dist/entrypoints/testing.d.ts.map +1 -0
- package/dist/{testing.js → entrypoints/testing.js} +80 -919
- package/dist/{tools/connections/index.d.ts → entrypoints/tools/connections.d.ts} +6 -7
- package/dist/entrypoints/tools/connections.d.ts.map +1 -0
- package/dist/{tools/connections/index.js → entrypoints/tools/connections.js} +7 -4
- package/dist/{tools-contract.d.ts → entrypoints/tools/contract.d.ts} +5 -5
- package/dist/entrypoints/tools/contract.d.ts.map +1 -0
- package/dist/{tools-contract.js → entrypoints/tools/contract.js} +4 -4
- package/dist/{tool-invoker.d.ts → entrypoints/tools/invoker.d.ts} +2 -2
- package/dist/entrypoints/tools/invoker.d.ts.map +1 -0
- package/dist/entrypoints/tools/invoker.js +20 -0
- package/dist/entrypoints/tools.d.ts +51 -0
- package/dist/entrypoints/tools.d.ts.map +1 -0
- package/dist/{tools.js → entrypoints/tools.js} +1787 -1751
- package/dist/{tracking-server.d.ts → entrypoints/tracking/server.d.ts} +8 -8
- package/dist/entrypoints/tracking/server.d.ts.map +1 -0
- package/dist/{tracking.d.ts → entrypoints/tracking.d.ts} +15 -15
- package/dist/entrypoints/tracking.d.ts.map +1 -0
- package/dist/{tracking.js → entrypoints/tracking.js} +5 -8
- package/dist/google/google.d.ts.map +1 -0
- package/dist/{index-a916km3r.js → index-0b1ess5e.js} +6 -13
- package/dist/{index-zwkgfq1s.js → index-1nd48tm9.js} +113 -118
- package/dist/{index-7zbps32p.js → index-1zbbzgfh.js} +2 -2
- package/dist/{index-mzvgxp0n.js → index-2cr1cqhn.js} +16 -4
- package/dist/{index-f9mb610r.js → index-35mh5bhj.js} +2 -2
- package/dist/index-48ffdxgk.js +6 -0
- package/dist/index-58k4fp34.js +1023 -0
- package/dist/{index-p13mwz16.js → index-83bdg97s.js} +1 -1
- package/dist/index-97ac4gph.js +3618 -0
- package/dist/{index-kw9t5ayn.js → index-cq4qfycf.js} +5 -5
- package/dist/{index-7gnkny4z.js → index-d9pk3td4.js} +1 -1
- package/dist/{index-e42wzzz5.js → index-dcpdvjsc.js} +7 -7
- package/dist/{index-h9etkkyk.js → index-dydjcp8z.js} +102 -25
- package/dist/{index-sr93cwf9.js → index-e2z3ahw9.js} +2 -2
- package/dist/{index-yewwh1w4.js → index-e87kakm4.js} +96 -11
- package/dist/{index-cby4ar3v.js → index-eqqvgdb3.js} +1 -1
- package/dist/index-fdp6hdxn.js +942 -0
- package/dist/{index-0a349c33.js → index-gyr48nzg.js} +125 -198
- package/dist/{index-wnfk50r0.js → index-h6eeys1v.js} +1 -1
- package/dist/{index-77fekveh.js → index-hffjpmq9.js} +1 -15
- package/dist/{index-yn8remb1.js → index-j05z5gn4.js} +50 -14
- package/dist/index-k5hsfc3j.js +31 -0
- package/dist/{index-fq77yfzc.js → index-kj2wbeta.js} +1 -1
- package/dist/index-kvj7f4hq.js +39 -0
- package/dist/{index-4fpa9dy2.js → index-m9zn6cpq.js} +2 -2
- package/dist/{index-2na0qrfn.js → index-mdzh02yc.js} +7 -7
- package/dist/{index-ywd0y6m1.js → index-mkm15s49.js} +1 -1
- package/dist/index-mp5sn43f.js +1084 -0
- package/dist/{index-3bmnp41g.js → index-n6hxg8as.js} +507 -419
- package/dist/index-ngfhvfpd.js +30 -0
- package/dist/{index-e0znv5gn.js → index-p5r7qpdd.js} +2 -93
- package/dist/{index-n0f51dfn.js → index-p81267c2.js} +608 -549
- package/dist/{index-wc4x00bn.js → index-qwhynv6x.js} +1 -1
- package/dist/index-r7nmqpsg.js +154 -0
- package/dist/{index-bx75zwt7.js → index-rewkc2hj.js} +5 -4
- package/dist/{index-9f8ztey6.js → index-sees8yf8.js} +2 -2
- package/dist/{index-vjpvjqpn.js → index-v38qyerb.js} +16 -2
- package/dist/{index-2c2bjw3s.js → index-vcvkq30w.js} +3 -3
- package/dist/index-wqgjfstn.js +18 -0
- package/dist/{index-f477k430.js → index-x4799c19.js} +1 -1
- package/dist/{index-cxqhvq21.js → index-xnj9bgxe.js} +142 -129
- package/dist/index-xsqjkha9.js +281 -0
- package/dist/{index-6kyksz9y.js → index-yw4fzmdz.js} +1 -1
- package/dist/{index-3xwxfj4z.js → index-zeemqhqx.js} +1 -1
- package/dist/{index-tmwcrptx.js → index-zfrhfn82.js} +1 -1
- package/dist/index-znfs20ss.js +98 -0
- package/dist/internal/backoff.d.ts +29 -0
- package/dist/internal/backoff.d.ts.map +1 -0
- package/dist/internal/canonical-json.d.ts +21 -11
- package/dist/internal/canonical-json.d.ts.map +1 -1
- package/dist/internal/channel.d.ts.map +1 -0
- package/dist/internal/logger.d.ts.map +1 -0
- package/dist/internal/request.d.ts.map +1 -0
- package/dist/internal/stable-digest.d.ts +0 -43
- package/dist/internal/stable-digest.d.ts.map +1 -1
- package/dist/internal/typed.d.ts +0 -8
- package/dist/internal/typed.d.ts.map +1 -1
- package/dist/internal/zod-issues.d.ts +38 -0
- package/dist/internal/zod-issues.d.ts.map +1 -0
- package/dist/{tools/json-schema-dialect.d.ts → json-schema/dialect.d.ts} +1 -1
- package/dist/json-schema/dialect.d.ts.map +1 -0
- package/dist/json-schema/json-schema.d.ts.map +1 -0
- package/dist/live/watch-delta.d.ts.map +1 -1
- package/dist/{oauth.d.ts → oauth/authorization-code.d.ts} +1 -1
- package/dist/oauth/authorization-code.d.ts.map +1 -0
- package/dist/observability/audit.d.ts +2 -2
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/bounded-logger.d.ts +1 -1
- package/dist/observability/bounded-logger.d.ts.map +1 -1
- package/dist/{internal/observability-sink.d.ts → observability/bounded-sink.d.ts} +2 -2
- package/dist/observability/bounded-sink.d.ts.map +1 -0
- package/dist/observability/context.d.ts +1 -1
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/event.d.ts +1 -1
- package/dist/observability/event.d.ts.map +1 -1
- package/dist/observability/work.d.ts +1 -1
- package/dist/observability/work.d.ts.map +1 -1
- package/dist/primitives/audit.d.ts +1 -1
- package/dist/primitives/audit.d.ts.map +1 -1
- package/dist/primitives/export-operation.d.ts +4 -2
- package/dist/primitives/export-operation.d.ts.map +1 -1
- package/dist/realtime/socket.d.ts +1 -1
- package/dist/realtime/socket.d.ts.map +1 -1
- package/dist/server/context-contribution.d.ts +1 -1
- package/dist/server/context-contribution.d.ts.map +1 -1
- package/dist/server/context.d.ts +2 -2
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts +15 -0
- package/dist/server/contract-method.d.ts.map +1 -0
- package/dist/server/contract-stream.d.ts +1 -1
- package/dist/server/contract-stream.d.ts.map +1 -1
- package/dist/server/create.d.ts +8 -0
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/endpoint-dispatch.d.ts +10 -0
- package/dist/server/endpoint-dispatch.d.ts.map +1 -0
- package/dist/server/endpoint-response.d.ts +18 -0
- package/dist/server/endpoint-response.d.ts.map +1 -0
- package/dist/server/error-dispatch.d.ts +17 -1
- package/dist/server/error-dispatch.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +2 -2
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/handler-state.d.ts +44 -0
- package/dist/server/handler-state.d.ts.map +1 -0
- package/dist/server/implement.d.ts +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/middleware/auth.d.ts +1 -1
- package/dist/server/middleware/auth.d.ts.map +1 -1
- package/dist/server/middleware/cors.d.ts +17 -0
- package/dist/server/middleware/cors.d.ts.map +1 -1
- package/dist/server/middleware/trust-fence.d.ts +1 -1
- package/dist/server/middleware/trust-fence.d.ts.map +1 -1
- package/dist/server/multipart.d.ts +1 -1
- package/dist/server/multipart.d.ts.map +1 -1
- package/dist/{tools/oauth-metadata.d.ts → server/oauth/metadata.d.ts} +2 -2
- package/dist/server/oauth/metadata.d.ts.map +1 -0
- package/dist/{tools/oauth-provider.d.ts → server/oauth/provider.d.ts} +2 -2
- package/dist/server/oauth/provider.d.ts.map +1 -0
- package/dist/server/realtime.d.ts +1 -1
- package/dist/server/realtime.d.ts.map +1 -1
- package/dist/server/request-completion.d.ts +16 -0
- package/dist/server/request-completion.d.ts.map +1 -0
- package/dist/server/response-metadata.d.ts +1 -1
- package/dist/server/response-metadata.d.ts.map +1 -1
- package/dist/server/route-table.d.ts +9 -0
- package/dist/server/route-table.d.ts.map +1 -0
- package/dist/server/stream.d.ts +0 -13
- package/dist/server/stream.d.ts.map +1 -1
- package/dist/server/types.d.ts +7 -4
- package/dist/server/types.d.ts.map +1 -1
- package/dist/testing/handler-clients.d.ts +31 -0
- package/dist/testing/handler-clients.d.ts.map +1 -0
- package/dist/testing/managed-resource-conformance-scenarios.d.ts.map +1 -1
- package/dist/testing/surface-conformance.d.ts +2 -1
- package/dist/testing/surface-conformance.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +30 -4
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/{cli-args.d.ts → cli/args.d.ts} +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -0
- package/dist/tools/{cli-checkpoint.d.ts → cli/checkpoint.d.ts} +1 -1
- package/dist/tools/cli/checkpoint.d.ts.map +1 -0
- package/dist/tools/{cli-command.d.ts → cli/command.d.ts} +4 -4
- package/dist/tools/cli/command.d.ts.map +1 -0
- package/dist/tools/{cli.d.ts → cli/config.d.ts} +5 -9
- package/dist/tools/cli/config.d.ts.map +1 -0
- package/dist/tools/cli/create-cli.d.ts +36 -0
- package/dist/tools/cli/create-cli.d.ts.map +1 -0
- package/dist/tools/cli/download.d.ts +8 -0
- package/dist/tools/cli/download.d.ts.map +1 -0
- package/dist/tools/{cli-format.d.ts → cli/format.d.ts} +2 -2
- package/dist/tools/cli/format.d.ts.map +1 -0
- package/dist/tools/cli/help.d.ts +24 -0
- package/dist/tools/cli/help.d.ts.map +1 -0
- package/dist/tools/{cli-installer.d.ts → cli/installer.d.ts} +2 -2
- package/dist/tools/cli/installer.d.ts.map +1 -0
- package/dist/tools/{cli-invoke.d.ts → cli/invoke.d.ts} +8 -8
- package/dist/tools/cli/invoke.d.ts.map +1 -0
- package/dist/tools/cli/io.d.ts +10 -0
- package/dist/tools/cli/io.d.ts.map +1 -0
- package/dist/tools/cli/managed-surface.d.ts +30 -0
- package/dist/tools/cli/managed-surface.d.ts.map +1 -0
- package/dist/tools/{cli-manifest.d.ts → cli/manifest.d.ts} +1 -1
- package/dist/tools/cli/manifest.d.ts.map +1 -0
- package/dist/tools/{cli-policy.d.ts → cli/policy.d.ts} +2 -2
- package/dist/tools/cli/policy.d.ts.map +1 -0
- package/dist/tools/cli/prepare.d.ts +14 -0
- package/dist/tools/cli/prepare.d.ts.map +1 -0
- package/dist/tools/{cli-profile.d.ts → cli/profile.d.ts} +2 -2
- package/dist/tools/cli/profile.d.ts.map +1 -0
- package/dist/tools/cli/run-managed.d.ts +5 -0
- package/dist/tools/cli/run-managed.d.ts.map +1 -0
- package/dist/tools/cli/run-native.d.ts +9 -0
- package/dist/tools/cli/run-native.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +40 -0
- package/dist/tools/cli/session.d.ts.map +1 -0
- package/dist/tools/{cli-signature.d.ts → cli/signature.d.ts} +2 -2
- package/dist/tools/cli/signature.d.ts.map +1 -0
- package/dist/tools/{cli-stream.d.ts → cli/stream.d.ts} +4 -4
- package/dist/tools/cli/stream.d.ts.map +1 -0
- package/dist/tools/{cli-update.d.ts → cli/update.d.ts} +3 -3
- package/dist/tools/cli/update.d.ts.map +1 -0
- package/dist/tools/{cli-view.d.ts → cli/view.d.ts} +2 -2
- package/dist/tools/cli/view.d.ts.map +1 -0
- package/dist/tools/{cli-wait.d.ts → cli/wait.d.ts} +2 -2
- package/dist/tools/cli/wait.d.ts.map +1 -0
- package/dist/tools/connections/runtime.d.ts +1 -1
- package/dist/tools/connections/runtime.d.ts.map +1 -1
- package/dist/tools/connections/types.d.ts +3 -3
- package/dist/tools/connections/types.d.ts.map +1 -1
- package/dist/tools/durability-context.d.ts +1 -1
- package/dist/tools/durability-context.d.ts.map +1 -1
- package/dist/tools/execute.d.ts +30 -3
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/surface-projector.d.ts +8 -6
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/internal/tool-view.d.ts +41 -0
- package/dist/tools/internal/tool-view.d.ts.map +1 -0
- package/dist/tools/invoker.d.ts +11 -3
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +3 -3
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -2
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/{mcp-app.d.ts → mcp/app.d.ts} +1 -1
- package/dist/tools/mcp/app.d.ts.map +1 -0
- package/dist/tools/{mcp-catalog.d.ts → mcp/catalog.d.ts} +2 -2
- package/dist/tools/mcp/catalog.d.ts.map +1 -0
- package/dist/tools/{mcp-handler.d.ts → mcp/handler.d.ts} +5 -5
- package/dist/tools/mcp/handler.d.ts.map +1 -0
- package/dist/tools/{mcp.d.ts → mcp/mount.d.ts} +9 -9
- package/dist/tools/mcp/mount.d.ts.map +1 -0
- package/dist/tools/{mcp-prepare.d.ts → mcp/prepare.d.ts} +9 -9
- package/dist/tools/mcp/prepare.d.ts.map +1 -0
- package/dist/tools/{mcp-progress.d.ts → mcp/progress.d.ts} +2 -2
- package/dist/tools/mcp/progress.d.ts.map +1 -0
- package/dist/tools/mcp/register.d.ts +35 -0
- package/dist/tools/mcp/register.d.ts.map +1 -0
- package/dist/tools/{mcp-round-policy.d.ts → mcp/round-policy.d.ts} +2 -2
- package/dist/tools/mcp/round-policy.d.ts.map +1 -0
- package/dist/tools/{mcp-round.d.ts → mcp/round.d.ts} +4 -4
- package/dist/tools/mcp/round.d.ts.map +1 -0
- package/dist/tools/mcp/runtime-tools.d.ts +24 -0
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -0
- package/dist/tools/{mcp-stdio-signals.d.ts → mcp/stdio-signals.d.ts} +3 -3
- package/dist/tools/mcp/stdio-signals.d.ts.map +1 -0
- package/dist/tools/{mcp-stdio.d.ts → mcp/stdio.d.ts} +4 -4
- package/dist/tools/mcp/stdio.d.ts.map +1 -0
- package/dist/tools/{mcp-trace.d.ts → mcp/trace.d.ts} +1 -1
- package/dist/tools/mcp/trace.d.ts.map +1 -0
- package/dist/tools/mount.d.ts +12 -7
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/native-definition.d.ts +3 -3
- package/dist/tools/native-definition.d.ts.map +1 -1
- package/dist/tools/operations/async-operation-binding-types.d.ts +127 -0
- package/dist/tools/operations/async-operation-binding-types.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-binding.d.ts +28 -0
- package/dist/tools/operations/async-operation-binding.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-canonical-types.d.ts +110 -0
- package/dist/tools/operations/async-operation-canonical-types.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-canonical.d.ts +7 -0
- package/dist/tools/operations/async-operation-canonical.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-contract.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-id.d.ts +23 -0
- package/dist/tools/operations/async-operation-id.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-runtime-tools.d.ts +40 -0
- package/dist/tools/operations/async-operation-runtime-tools.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-runtime-types.d.ts +68 -0
- package/dist/tools/operations/async-operation-runtime-types.d.ts.map +1 -0
- package/dist/tools/operations/async-operation-runtime.d.ts +5 -0
- package/dist/tools/operations/async-operation-runtime.d.ts.map +1 -0
- package/dist/tools/{define-wait-tool.d.ts → operations/define-wait-tool.d.ts} +2 -2
- package/dist/tools/operations/define-wait-tool.d.ts.map +1 -0
- package/dist/tools/operations/mount-wait.d.ts.map +1 -0
- package/dist/tools/operations/wait-core.d.ts.map +1 -0
- package/dist/tools/remote.d.ts +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts +11 -4
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/schema/coerce.d.ts.map +1 -0
- package/dist/tools/schema/flatten-join.d.ts.map +1 -0
- package/dist/tools/schema/flatten.d.ts.map +1 -0
- package/dist/tools/schema/portable-formats.d.ts.map +1 -0
- package/dist/tools/{presentation.d.ts → schema/presentation.d.ts} +2 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -0
- package/dist/tools/schema/schema.d.ts.map +1 -0
- package/dist/tools/schema/untyped-properties.d.ts.map +1 -0
- package/dist/tools/surface.d.ts +2 -3
- package/dist/tools/surface.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +4 -4
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/tools/{define-download-tool.d.ts → transfer/define-download-tool.d.ts} +4 -4
- package/dist/tools/transfer/define-download-tool.d.ts.map +1 -0
- package/dist/tools/{define-upload-tool.d.ts → transfer/define-upload-tool.d.ts} +3 -3
- package/dist/tools/transfer/define-upload-tool.d.ts.map +1 -0
- package/dist/tools/{define-view-file-tool.d.ts → transfer/define-view-file-tool.d.ts} +2 -2
- package/dist/tools/transfer/define-view-file-tool.d.ts.map +1 -0
- package/dist/tools/{download-core.d.ts → transfer/download-core.d.ts} +2 -2
- package/dist/tools/transfer/download-core.d.ts.map +1 -0
- package/dist/tools/{managed-file-error.d.ts → transfer/managed-file-error.d.ts} +1 -1
- package/dist/tools/transfer/managed-file-error.d.ts.map +1 -0
- package/dist/tools/{mount-download.d.ts → transfer/mount-download.d.ts} +1 -1
- package/dist/tools/transfer/mount-download.d.ts.map +1 -0
- package/dist/tools/{mount-upload.d.ts → transfer/mount-upload.d.ts} +1 -1
- package/dist/tools/transfer/mount-upload.d.ts.map +1 -0
- package/dist/tools/transfer/native-result.d.ts.map +1 -0
- package/dist/tools/{upload-core.d.ts → transfer/upload-core.d.ts} +1 -1
- package/dist/tools/transfer/upload-core.d.ts.map +1 -0
- package/dist/tools/transfer/view-file-contract.d.ts.map +1 -0
- package/dist/tools/{view-file.d.ts → transfer/view-file.d.ts} +1 -1
- package/dist/tools/transfer/view-file.d.ts.map +1 -0
- package/dist/tools/transports.d.ts +1 -1
- package/dist/tools/transports.d.ts.map +1 -1
- package/dist/tracking/contract.d.ts +1 -1
- package/dist/tracking/contract.d.ts.map +1 -1
- package/llms/agent-runtime-browser.txt +33 -0
- package/llms/agent-runtime-coding-tools.txt +58 -0
- package/llms/agent-runtime-harness.txt +45 -0
- package/llms/agent-runtime-openrouter.txt +22 -0
- package/llms/agent-runtime-sandbox.txt +159 -0
- package/llms/agent-runtime-sqlite-bun.txt +29 -0
- package/llms/agent-runtime-sqlite-node.txt +26 -0
- package/llms/agent-runtime-testing.txt +30 -0
- package/llms/agent-runtime.2.txt +550 -0
- package/llms/agent-runtime.3.txt +311 -0
- package/llms/agent-runtime.txt +893 -0
- package/llms/application-diagnostic-journal.txt +30 -0
- package/llms/application-grammy.txt +27 -0
- package/llms/application-opentelemetry.txt +27 -0
- package/llms/application-schemas.txt +42 -0
- package/llms/application.2.txt +223 -0
- package/llms/application.txt +1144 -0
- package/llms/cli.txt +977 -0
- package/llms/contract.txt +606 -0
- package/llms/declaration.txt +286 -0
- package/llms/files.txt +30 -0
- package/llms/geo.txt +114 -0
- package/llms/google.txt +27 -0
- package/llms/live.txt +471 -0
- package/llms/node.txt +43 -0
- package/llms/oauth.txt +136 -0
- package/llms/observability.txt +893 -0
- package/llms/primitives.txt +158 -0
- package/llms/react.txt +184 -0
- package/llms/release.txt +176 -0
- package/llms/remote.txt +25 -0
- package/llms/server.2.txt +361 -0
- package/llms/server.3.txt +1031 -0
- package/llms/server.4.txt +905 -0
- package/llms/server.5.txt +250 -0
- package/llms/server.txt +996 -0
- package/llms/stitchkit.2.txt +836 -0
- package/llms/stitchkit.3.txt +147 -0
- package/llms/stitchkit.txt +260 -0
- package/llms/telegram.txt +30 -0
- package/llms/testing.txt +676 -0
- package/llms/tools-connections.txt +45 -0
- package/llms/tools-contract.txt +9 -0
- package/llms/tools-invoker.txt +9 -0
- package/llms/tools.2.txt +838 -0
- package/llms/tools.txt +1004 -0
- package/llms/tracking-server.txt +32 -0
- package/llms/tracking.txt +263 -0
- package/llms/upgrading-0.37.0-0.50.0.txt +947 -0
- package/llms/upgrading-0.53.0-0.67.0.txt +1174 -0
- package/llms/upgrading-0.68.0-0.94.0.txt +1159 -0
- package/llms/upgrading.txt +215 -0
- package/llms-full.txt +214 -75
- package/llms.txt +54 -5
- package/package.json +84 -83
- package/dist/agent-runtime/durability-contract.d.ts.map +0 -1
- package/dist/agent-runtime/durability-json.d.ts.map +0 -1
- package/dist/agent-runtime/durability-ledger.d.ts.map +0 -1
- package/dist/agent-runtime/durability-scheduler.d.ts.map +0 -1
- package/dist/agent-runtime/durability.d.ts.map +0 -1
- package/dist/agent-runtime/store-driver.d.ts.map +0 -1
- package/dist/agent-runtime-browser.d.ts +0 -5
- package/dist/agent-runtime-browser.d.ts.map +0 -1
- package/dist/agent-runtime-coding-tools.d.ts.map +0 -1
- package/dist/agent-runtime-coding-tools.js +0 -23
- package/dist/agent-runtime-harness.d.ts.map +0 -1
- package/dist/agent-runtime-openrouter.d.ts.map +0 -1
- package/dist/agent-runtime-sandbox.d.ts.map +0 -1
- package/dist/agent-runtime-sqlite-bun.d.ts.map +0 -1
- package/dist/agent-runtime-sqlite-node.d.ts.map +0 -1
- package/dist/agent-runtime-testing.d.ts +0 -3
- package/dist/agent-runtime-testing.d.ts.map +0 -1
- package/dist/agent-runtime-testing.js +0 -156
- package/dist/agent-runtime.d.ts.map +0 -1
- package/dist/application/channel.d.ts.map +0 -1
- package/dist/application-diagnostic-journal.d.ts.map +0 -1
- package/dist/application-grammy.d.ts.map +0 -1
- package/dist/application-opentelemetry.d.ts.map +0 -1
- package/dist/application-schemas.d.ts.map +0 -1
- package/dist/application.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/contract/index.d.ts +0 -8
- package/dist/contract/index.d.ts.map +0 -1
- package/dist/declaration.d.ts.map +0 -1
- package/dist/files.d.ts.map +0 -1
- package/dist/geo.d.ts.map +0 -1
- package/dist/google.d.ts.map +0 -1
- package/dist/index-0j3vcp5m.js +0 -28
- package/dist/index-a11g2kry.js +0 -866
- package/dist/index-cnyk6te3.js +0 -77
- package/dist/index-fadnxwna.js +0 -1046
- package/dist/index-hrbajay7.js +0 -1196
- package/dist/index-s8cnx02s.js +0 -90
- package/dist/index-v5573g1k.js +0 -142
- package/dist/index-vk3kq9sb.js +0 -3344
- package/dist/index.d.ts.map +0 -1
- package/dist/internal/errors.d.ts.map +0 -1
- package/dist/internal/observability-sink.d.ts.map +0 -1
- package/dist/live.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/node.d.ts.map +0 -1
- package/dist/oauth.d.ts.map +0 -1
- package/dist/observability/index.d.ts.map +0 -1
- package/dist/primitives.d.ts +0 -3
- package/dist/primitives.d.ts.map +0 -1
- package/dist/react.d.ts.map +0 -1
- package/dist/release.d.ts.map +0 -1
- package/dist/remote.d.ts.map +0 -1
- package/dist/remote.js +0 -88
- package/dist/retained.d.ts.map +0 -1
- package/dist/server/file-state-store.d.ts.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/request.d.ts.map +0 -1
- package/dist/telegram.d.ts.map +0 -1
- package/dist/testing/agent-store-conformance.d.ts.map +0 -1
- package/dist/testing.d.ts +0 -39
- package/dist/testing.d.ts.map +0 -1
- package/dist/tool-invoker.d.ts.map +0 -1
- package/dist/tool-invoker.js +0 -21
- package/dist/tools/async-operation-contract.d.ts.map +0 -1
- package/dist/tools/async-operation.d.ts +0 -332
- package/dist/tools/async-operation.d.ts.map +0 -1
- package/dist/tools/cli-args.d.ts.map +0 -1
- package/dist/tools/cli-checkpoint.d.ts.map +0 -1
- package/dist/tools/cli-command.d.ts.map +0 -1
- package/dist/tools/cli-format.d.ts.map +0 -1
- package/dist/tools/cli-installer.d.ts.map +0 -1
- package/dist/tools/cli-invoke.d.ts.map +0 -1
- package/dist/tools/cli-manifest.d.ts.map +0 -1
- package/dist/tools/cli-policy.d.ts.map +0 -1
- package/dist/tools/cli-profile.d.ts.map +0 -1
- package/dist/tools/cli-signature.d.ts.map +0 -1
- package/dist/tools/cli-stream.d.ts.map +0 -1
- package/dist/tools/cli-update.d.ts.map +0 -1
- package/dist/tools/cli-view.d.ts.map +0 -1
- package/dist/tools/cli-wait.d.ts.map +0 -1
- package/dist/tools/cli.d.ts.map +0 -1
- package/dist/tools/coerce.d.ts.map +0 -1
- package/dist/tools/connections/index.d.ts.map +0 -1
- package/dist/tools/define-download-tool.d.ts.map +0 -1
- package/dist/tools/define-upload-tool.d.ts.map +0 -1
- package/dist/tools/define-view-file-tool.d.ts.map +0 -1
- package/dist/tools/define-wait-tool.d.ts.map +0 -1
- package/dist/tools/download-core.d.ts.map +0 -1
- package/dist/tools/flatten-join.d.ts.map +0 -1
- package/dist/tools/flatten.d.ts.map +0 -1
- package/dist/tools/json-schema-dialect.d.ts.map +0 -1
- package/dist/tools/json-schema.d.ts.map +0 -1
- package/dist/tools/managed-file-error.d.ts.map +0 -1
- package/dist/tools/mcp-app.d.ts.map +0 -1
- package/dist/tools/mcp-catalog.d.ts.map +0 -1
- package/dist/tools/mcp-handler.d.ts.map +0 -1
- package/dist/tools/mcp-prepare.d.ts.map +0 -1
- package/dist/tools/mcp-progress.d.ts.map +0 -1
- package/dist/tools/mcp-round-policy.d.ts.map +0 -1
- package/dist/tools/mcp-round.d.ts.map +0 -1
- package/dist/tools/mcp-stdio-signals.d.ts.map +0 -1
- package/dist/tools/mcp-stdio.d.ts.map +0 -1
- package/dist/tools/mcp-trace.d.ts.map +0 -1
- package/dist/tools/mcp.d.ts.map +0 -1
- package/dist/tools/mount-download.d.ts.map +0 -1
- package/dist/tools/mount-upload.d.ts.map +0 -1
- package/dist/tools/mount-wait.d.ts.map +0 -1
- package/dist/tools/native-mcp.d.ts +0 -20
- package/dist/tools/native-mcp.d.ts.map +0 -1
- package/dist/tools/native-result.d.ts.map +0 -1
- package/dist/tools/oauth-metadata.d.ts.map +0 -1
- package/dist/tools/oauth-provider.d.ts.map +0 -1
- package/dist/tools/portable-formats.d.ts.map +0 -1
- package/dist/tools/presentation.d.ts.map +0 -1
- package/dist/tools/schema.d.ts.map +0 -1
- package/dist/tools/untyped-properties.d.ts.map +0 -1
- package/dist/tools/upload-core.d.ts.map +0 -1
- package/dist/tools/view-file-contract.d.ts.map +0 -1
- package/dist/tools/view-file.d.ts.map +0 -1
- package/dist/tools/wait-core.d.ts.map +0 -1
- package/dist/tools-contract.d.ts.map +0 -1
- package/dist/tools.d.ts +0 -50
- package/dist/tools.d.ts.map +0 -1
- package/dist/tracking-server.d.ts.map +0 -1
- package/dist/tracking.d.ts.map +0 -1
- package/dist/upgrade-cli.d.ts.map +0 -1
- package/dist/{retained.d.ts → browser/retained.d.ts} +0 -0
- package/dist/{declaration.d.ts → declaration/declaration.d.ts} +0 -0
- package/dist/{upgrade-cli.d.ts → entrypoints/bin/upgrade-cli.d.ts} +0 -0
- package/dist/{tracking-server.js → entrypoints/tracking/server.js} +0 -0
- package/dist/{google.d.ts → google/google.d.ts} +0 -0
- package/dist/{index-pq95qkbf.js → index-5jm36zv1.js} +0 -0
- package/dist/{index-actkayzn.js → index-70yj2ebz.js} +3 -3
- /package/dist/{application → internal}/channel.d.ts +0 -0
- /package/dist/{logger.d.ts → internal/logger.d.ts} +0 -0
- /package/dist/{server → internal}/request.d.ts +0 -0
- /package/dist/{tools → json-schema}/json-schema.d.ts +0 -0
- /package/dist/tools/{async-operation-contract.d.ts → operations/async-operation-contract.d.ts} +0 -0
- /package/dist/tools/{mount-wait.d.ts → operations/mount-wait.d.ts} +0 -0
- /package/dist/tools/{wait-core.d.ts → operations/wait-core.d.ts} +0 -0
- /package/dist/tools/{coerce.d.ts → schema/coerce.d.ts} +0 -0
- /package/dist/tools/{flatten-join.d.ts → schema/flatten-join.d.ts} +0 -0
- /package/dist/tools/{flatten.d.ts → schema/flatten.d.ts} +0 -0
- /package/dist/tools/{portable-formats.d.ts → schema/portable-formats.d.ts} +0 -0
- /package/dist/tools/{schema.d.ts → schema/schema.d.ts} +0 -0
- /package/dist/tools/{untyped-properties.d.ts → schema/untyped-properties.d.ts} +0 -0
- /package/dist/tools/{native-result.d.ts → transfer/native-result.d.ts} +0 -0
- /package/dist/tools/{view-file-contract.d.ts → transfer/view-file-contract.d.ts} +0 -0
|
@@ -10,46 +10,49 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
createValidatedRealtimeSocket,
|
|
12
12
|
isModuleNotFound
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-x4799c19.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_CONTRACT_STREAM_FRAME_BYTES
|
|
16
|
+
} from "./index-wqgjfstn.js";
|
|
14
17
|
import {
|
|
15
18
|
DEFAULT_PROCESS_SIGNALS,
|
|
16
19
|
RUNTIME_CONTEXT_RESERVED_KEYS,
|
|
20
|
+
applyCors,
|
|
17
21
|
assertCorsConfig,
|
|
18
|
-
corsHeaders,
|
|
19
22
|
corsPreflightResponse,
|
|
20
23
|
defaultSignalSource,
|
|
21
24
|
guardSignalCallback,
|
|
22
25
|
isOriginAllowed,
|
|
23
26
|
mediaTypeEssence,
|
|
24
|
-
reportSignalError
|
|
25
|
-
|
|
27
|
+
reportSignalError,
|
|
28
|
+
requestCorsHeaders
|
|
29
|
+
} from "./index-xnj9bgxe.js";
|
|
30
|
+
import {
|
|
31
|
+
joinRoutePath,
|
|
32
|
+
parseTrailingWildcard
|
|
33
|
+
} from "./index-gyr48nzg.js";
|
|
26
34
|
import {
|
|
27
35
|
getRequestContext,
|
|
28
36
|
runWithRequestContext,
|
|
29
37
|
setRequestEndpoint,
|
|
30
38
|
setRequestError
|
|
31
|
-
} from "./index-
|
|
39
|
+
} from "./index-zfrhfn82.js";
|
|
32
40
|
import {
|
|
33
41
|
extractIp,
|
|
34
42
|
getClientInfo,
|
|
35
43
|
parseQueryParams,
|
|
36
44
|
resolveSocketIp,
|
|
37
45
|
resolveTraceId
|
|
38
|
-
} from "./index-
|
|
46
|
+
} from "./index-35mh5bhj.js";
|
|
47
|
+
import {
|
|
48
|
+
resolveTraceContext
|
|
49
|
+
} from "./index-zcgf3gqf.js";
|
|
39
50
|
import {
|
|
40
51
|
errorCode,
|
|
41
52
|
normalizeError,
|
|
42
53
|
recordedErrorMessage,
|
|
43
54
|
validateDeclaredOutput
|
|
44
|
-
} from "./index-
|
|
45
|
-
import {
|
|
46
|
-
DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
|
|
47
|
-
joinRoutePath,
|
|
48
|
-
parseTrailingWildcard
|
|
49
|
-
} from "./index-0a349c33.js";
|
|
50
|
-
import {
|
|
51
|
-
resolveTraceContext
|
|
52
|
-
} from "./index-zcgf3gqf.js";
|
|
55
|
+
} from "./index-znfs20ss.js";
|
|
53
56
|
import {
|
|
54
57
|
AppError,
|
|
55
58
|
badRequest,
|
|
@@ -62,7 +65,7 @@ import {
|
|
|
62
65
|
import {
|
|
63
66
|
isRecord,
|
|
64
67
|
transportResult
|
|
65
|
-
} from "./index-
|
|
68
|
+
} from "./index-hffjpmq9.js";
|
|
66
69
|
|
|
67
70
|
// src/server/multipart.ts
|
|
68
71
|
var DEFAULT_MAX_REQUEST_BYTES = 25 * 1024 * 1024;
|
|
@@ -1052,7 +1055,243 @@ function contractStreamResponse(request, context, source, descriptor, operationA
|
|
|
1052
1055
|
return Promise.resolve(route.handler(request, context));
|
|
1053
1056
|
}
|
|
1054
1057
|
|
|
1058
|
+
// src/server/response-metadata.ts
|
|
1059
|
+
var RESERVED_HEADERS = new Set(["content-type", "content-length", "x-request-id"]);
|
|
1060
|
+
function hasGetSetCookie(headers) {
|
|
1061
|
+
return "getSetCookie" in headers && typeof headers.getSetCookie === "function";
|
|
1062
|
+
}
|
|
1063
|
+
function isReservedHeader(name) {
|
|
1064
|
+
const normalized = name.toLowerCase();
|
|
1065
|
+
return RESERVED_HEADERS.has(normalized) || normalized.startsWith("access-control-");
|
|
1066
|
+
}
|
|
1067
|
+
function createResponseMetadata() {
|
|
1068
|
+
return { headers: new Headers };
|
|
1069
|
+
}
|
|
1070
|
+
function applyResponseMetadata(target, metadata, endpointIdentity) {
|
|
1071
|
+
if (!metadata)
|
|
1072
|
+
return;
|
|
1073
|
+
for (const [name] of metadata.headers) {
|
|
1074
|
+
if (isReservedHeader(name)) {
|
|
1075
|
+
throw new Error(`${endpointIdentity} cannot set framework-owned response header "${name}"`);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const preservesSetCookie = hasGetSetCookie(metadata.headers);
|
|
1079
|
+
for (const [name, value] of metadata.headers) {
|
|
1080
|
+
if (name.toLowerCase() === "set-cookie" && preservesSetCookie)
|
|
1081
|
+
continue;
|
|
1082
|
+
target.append(name, value);
|
|
1083
|
+
}
|
|
1084
|
+
if (preservesSetCookie) {
|
|
1085
|
+
for (const cookie of metadata.headers.getSetCookie()) {
|
|
1086
|
+
target.append("Set-Cookie", cookie);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/server/endpoint-response.ts
|
|
1092
|
+
function isAsyncIterable(value) {
|
|
1093
|
+
if (typeof value !== "object" && typeof value !== "function" || value === null) {
|
|
1094
|
+
return false;
|
|
1095
|
+
}
|
|
1096
|
+
return typeof Reflect.get(value, Symbol.asyncIterator) === "function";
|
|
1097
|
+
}
|
|
1098
|
+
async function endpointResponse(state, request, outcome) {
|
|
1099
|
+
const { method } = outcome.match;
|
|
1100
|
+
if (method.rawResponse)
|
|
1101
|
+
return rawEndpointResponse(state, request, outcome);
|
|
1102
|
+
if (method.stream)
|
|
1103
|
+
return streamEndpointResponse(state, request, outcome);
|
|
1104
|
+
return dataEndpointResponse(state, request, outcome);
|
|
1105
|
+
}
|
|
1106
|
+
function rawEndpointResponse(state, request, { match: { method }, result }) {
|
|
1107
|
+
if (!(result instanceof Response)) {
|
|
1108
|
+
throw new AppError("INTERNAL_SERVER_ERROR", `Raw endpoint ${method.serviceName}.${method.key} must return a Response`, 500);
|
|
1109
|
+
}
|
|
1110
|
+
const response = method.method === "HEAD" ? new Response(null, {
|
|
1111
|
+
status: result.status,
|
|
1112
|
+
statusText: result.statusText,
|
|
1113
|
+
headers: result.headers
|
|
1114
|
+
}) : result;
|
|
1115
|
+
const rawRes = applyCors(response, state.cors, request.req);
|
|
1116
|
+
request.complete(rawRes.status);
|
|
1117
|
+
return rawRes;
|
|
1118
|
+
}
|
|
1119
|
+
async function streamEndpointResponse(state, request, { match: { method, pathParams }, result, streamAbort }) {
|
|
1120
|
+
const { req, server, clientIp } = request;
|
|
1121
|
+
if (!method.stream || !streamAbort || !isAsyncIterable(result)) {
|
|
1122
|
+
streamAbort?.abort();
|
|
1123
|
+
throw new AppError("INTERNAL_SERVER_ERROR", `Streaming endpoint ${method.serviceName}.${method.key} must return an AsyncIterable`, 500);
|
|
1124
|
+
}
|
|
1125
|
+
const response = await contractStreamResponse(req, { params: pathParams, server, ipAddress: clientIp.socketIp }, result, method.stream, streamAbort);
|
|
1126
|
+
const withCors = applyCors(response, state.cors, req);
|
|
1127
|
+
request.complete(withCors.status);
|
|
1128
|
+
return withCors;
|
|
1129
|
+
}
|
|
1130
|
+
async function dataEndpointResponse(state, request, {
|
|
1131
|
+
ctx,
|
|
1132
|
+
match: { method, groupHooks },
|
|
1133
|
+
result: handlerResult,
|
|
1134
|
+
responseMetadata
|
|
1135
|
+
}) {
|
|
1136
|
+
const { hooks, config, cors, warn } = state;
|
|
1137
|
+
const { req } = request;
|
|
1138
|
+
let result = handlerResult;
|
|
1139
|
+
if (groupHooks?.afterHandle) {
|
|
1140
|
+
const transformed = await groupHooks.afterHandle(ctx, result, method);
|
|
1141
|
+
if (transformed !== undefined)
|
|
1142
|
+
result = transformed;
|
|
1143
|
+
}
|
|
1144
|
+
if (hooks?.afterHandle) {
|
|
1145
|
+
const transformed = await hooks.afterHandle(ctx, result, method);
|
|
1146
|
+
if (transformed !== undefined)
|
|
1147
|
+
result = transformed;
|
|
1148
|
+
}
|
|
1149
|
+
if (result instanceof Response) {
|
|
1150
|
+
throw new AppError("INTERNAL_SERVER_ERROR", `${method.serviceName}.${method.key} produced a Response on the data path — only a \`rawResponse: true\` endpoint may return one (an afterHandle hook must return data)`, 500);
|
|
1151
|
+
}
|
|
1152
|
+
const checked = validateDeclaredOutput(method.outputSchema, result, config.warnOnOutputStrip && method.outputSchema ? (paths) => {
|
|
1153
|
+
warn(`[stitchkit] output strip ${method.serviceName}.${method.key}: ${paths.join(", ")}`);
|
|
1154
|
+
} : undefined);
|
|
1155
|
+
if (!checked.ok) {
|
|
1156
|
+
throw new AppError("INTERNAL_SERVER_ERROR", checked.message, 500);
|
|
1157
|
+
}
|
|
1158
|
+
result = checked.data;
|
|
1159
|
+
const responseStatus = method.responseMeta?.status ?? (method.outputSchema ? 200 : 204);
|
|
1160
|
+
if (method.outputSchema && (responseStatus === 204 || responseStatus === 205)) {
|
|
1161
|
+
throw new AppError("INTERNAL_SERVER_ERROR", `${method.serviceName}.${method.key} cannot combine output with bodyless status ${responseStatus}`, 500);
|
|
1162
|
+
}
|
|
1163
|
+
const responseHeaders2 = new Headers(requestCorsHeaders(cors, req));
|
|
1164
|
+
applyResponseMetadata(responseHeaders2, responseMetadata, `${method.serviceName}.${method.key}`);
|
|
1165
|
+
if (!method.outputSchema) {
|
|
1166
|
+
const empty = new Response(null, { status: responseStatus, headers: responseHeaders2 });
|
|
1167
|
+
request.complete(responseStatus);
|
|
1168
|
+
return empty;
|
|
1169
|
+
}
|
|
1170
|
+
const body = Response.json(result, { status: responseStatus, headers: responseHeaders2 });
|
|
1171
|
+
request.complete(responseStatus);
|
|
1172
|
+
return body;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// src/server/endpoint-dispatch.ts
|
|
1176
|
+
async function dispatchEndpoint(state, request, match) {
|
|
1177
|
+
const { hooks, config, cors } = state;
|
|
1178
|
+
const { req, url, traceId, clientIp } = request;
|
|
1179
|
+
const { method, pathParams, groupHooks } = match;
|
|
1180
|
+
const ctx = buildBaseContext(req, url, pathParams, traceId, clientIp);
|
|
1181
|
+
setRequestEndpoint(method.serviceName, method.key);
|
|
1182
|
+
let multipartLifecycle;
|
|
1183
|
+
try {
|
|
1184
|
+
parsePathParamsInto(ctx, method);
|
|
1185
|
+
if (hooks?.authorize) {
|
|
1186
|
+
await hooks.authorize(ctx, method);
|
|
1187
|
+
}
|
|
1188
|
+
if (groupHooks?.authorize) {
|
|
1189
|
+
await groupHooks.authorize(ctx, method);
|
|
1190
|
+
}
|
|
1191
|
+
multipartLifecycle = await parseRequestPayloadInto(ctx, req, url, method, config.maxJsonBodyBytes, cors);
|
|
1192
|
+
if (hooks?.beforeHandle) {
|
|
1193
|
+
await hooks.beforeHandle(ctx, method);
|
|
1194
|
+
}
|
|
1195
|
+
if (groupHooks?.beforeHandle) {
|
|
1196
|
+
await groupHooks.beforeHandle(ctx, method);
|
|
1197
|
+
}
|
|
1198
|
+
const responseMetadata = method.responseMeta ? createResponseMetadata() : undefined;
|
|
1199
|
+
if (responseMetadata)
|
|
1200
|
+
ctx.response = responseMetadata;
|
|
1201
|
+
const streamAbort = method.stream ? new AbortController : undefined;
|
|
1202
|
+
if (streamAbort) {
|
|
1203
|
+
if (req.signal.aborted)
|
|
1204
|
+
streamAbort.abort(req.signal.reason);
|
|
1205
|
+
else {
|
|
1206
|
+
req.signal.addEventListener("abort", () => streamAbort.abort(req.signal.reason), {
|
|
1207
|
+
once: true
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
ctx.signal = streamAbort.signal;
|
|
1211
|
+
}
|
|
1212
|
+
const result = await method.handler(ctx);
|
|
1213
|
+
return await endpointResponse(state, request, {
|
|
1214
|
+
ctx,
|
|
1215
|
+
match,
|
|
1216
|
+
result,
|
|
1217
|
+
responseMetadata,
|
|
1218
|
+
streamAbort
|
|
1219
|
+
});
|
|
1220
|
+
} catch (err) {
|
|
1221
|
+
await multipartLifecycle?.rollback();
|
|
1222
|
+
return request.respondError(err, ctx, method, groupHooks);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1055
1226
|
// src/server/error-dispatch.ts
|
|
1227
|
+
var MAX_REQUEST_ABORT_CAUSE_DEPTH = 8;
|
|
1228
|
+
function containsRequestAbortReason(error, reason) {
|
|
1229
|
+
let current = error;
|
|
1230
|
+
const visited = new Set;
|
|
1231
|
+
for (let depth = 0;depth <= MAX_REQUEST_ABORT_CAUSE_DEPTH; depth += 1) {
|
|
1232
|
+
if (current === reason)
|
|
1233
|
+
return true;
|
|
1234
|
+
if (depth === MAX_REQUEST_ABORT_CAUSE_DEPTH || !isRecord(current))
|
|
1235
|
+
return false;
|
|
1236
|
+
if (visited.has(current))
|
|
1237
|
+
return false;
|
|
1238
|
+
visited.add(current);
|
|
1239
|
+
current = current.cause;
|
|
1240
|
+
}
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
function isClientClosedRequest(req, error) {
|
|
1244
|
+
if (!req.signal.aborted)
|
|
1245
|
+
return false;
|
|
1246
|
+
if (isRecord(error) && error.name === "AbortError")
|
|
1247
|
+
return true;
|
|
1248
|
+
return req.signal.reason !== undefined && containsRequestAbortReason(error, req.signal.reason);
|
|
1249
|
+
}
|
|
1250
|
+
function createErrorResponder(state, request) {
|
|
1251
|
+
const { cors, hooks, customLogger } = state;
|
|
1252
|
+
const { req, url, traceId, clientIp, complete } = request;
|
|
1253
|
+
return async (err, errCtx, endpoint, group) => {
|
|
1254
|
+
if (isClientClosedRequest(req, err)) {
|
|
1255
|
+
const response = applyCors(new Response(null, { status: 499, statusText: "Client Closed Request" }), cors, req);
|
|
1256
|
+
complete(response.status, undefined, "cancelled");
|
|
1257
|
+
return response;
|
|
1258
|
+
}
|
|
1259
|
+
const recordFailure = (normalized) => {
|
|
1260
|
+
if (getRequestContext()?.error !== undefined)
|
|
1261
|
+
return;
|
|
1262
|
+
const known = AppError.is(err) ? err : normalized;
|
|
1263
|
+
const code = known?.code ?? errorCode(err) ?? "INTERNAL_SERVER_ERROR";
|
|
1264
|
+
setRequestError({
|
|
1265
|
+
code,
|
|
1266
|
+
message: recordedErrorMessage(code, known?.message, err),
|
|
1267
|
+
details: known?.details
|
|
1268
|
+
});
|
|
1269
|
+
};
|
|
1270
|
+
const customResponse = await dispatchErrorHooks({
|
|
1271
|
+
context: errCtx ?? buildErrorContext(req, url, traceId, clientIp),
|
|
1272
|
+
error: err,
|
|
1273
|
+
endpoint,
|
|
1274
|
+
group,
|
|
1275
|
+
global: hooks,
|
|
1276
|
+
logger: customLogger,
|
|
1277
|
+
respond: (response) => {
|
|
1278
|
+
recordFailure();
|
|
1279
|
+
const withCors = applyCors(response, cors, req);
|
|
1280
|
+
complete(withCors.status, errorCode(err));
|
|
1281
|
+
return withCors;
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
if (customResponse)
|
|
1285
|
+
return customResponse;
|
|
1286
|
+
const appErr = normalizeError(err);
|
|
1287
|
+
recordFailure(appErr);
|
|
1288
|
+
complete(appErr.status, appErr.code);
|
|
1289
|
+
return Response.json(appErr.toJSON(), {
|
|
1290
|
+
status: appErr.status,
|
|
1291
|
+
headers: requestCorsHeaders(cors, req)
|
|
1292
|
+
});
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1056
1295
|
async function dispatchErrorHooks(config) {
|
|
1057
1296
|
for (const [scope, hooks] of [
|
|
1058
1297
|
["group", config.group],
|
|
@@ -1077,134 +1316,6 @@ async function dispatchErrorHooks(config) {
|
|
|
1077
1316
|
return;
|
|
1078
1317
|
}
|
|
1079
1318
|
|
|
1080
|
-
// src/server/logger.ts
|
|
1081
|
-
var c = {
|
|
1082
|
-
reset: "\x1B[0m",
|
|
1083
|
-
dim: "\x1B[2m",
|
|
1084
|
-
red: "\x1B[31m",
|
|
1085
|
-
green: "\x1B[32m",
|
|
1086
|
-
yellow: "\x1B[33m",
|
|
1087
|
-
blue: "\x1B[34m",
|
|
1088
|
-
magenta: "\x1B[35m",
|
|
1089
|
-
cyan: "\x1B[36m",
|
|
1090
|
-
gray: "\x1B[90m"
|
|
1091
|
-
};
|
|
1092
|
-
var METHOD_COLOR = {
|
|
1093
|
-
GET: c.green,
|
|
1094
|
-
POST: c.yellow,
|
|
1095
|
-
PUT: c.blue,
|
|
1096
|
-
PATCH: c.cyan,
|
|
1097
|
-
DELETE: c.red,
|
|
1098
|
-
OPTIONS: c.gray
|
|
1099
|
-
};
|
|
1100
|
-
var runtimeEnv = process.env;
|
|
1101
|
-
function resolveLogFormat(preference) {
|
|
1102
|
-
if (preference)
|
|
1103
|
-
return preference;
|
|
1104
|
-
return runtimeEnv.NODE_ENV === "production" ? "json" : "pretty";
|
|
1105
|
-
}
|
|
1106
|
-
function timestamp() {
|
|
1107
|
-
const now = new Date;
|
|
1108
|
-
const t = now.toLocaleTimeString("en-US", {
|
|
1109
|
-
hour12: false,
|
|
1110
|
-
hour: "2-digit",
|
|
1111
|
-
minute: "2-digit",
|
|
1112
|
-
second: "2-digit"
|
|
1113
|
-
});
|
|
1114
|
-
return `${t}.${now.getMilliseconds().toString().padStart(3, "0")}`;
|
|
1115
|
-
}
|
|
1116
|
-
function safePath(pathname) {
|
|
1117
|
-
let out = "";
|
|
1118
|
-
for (let i = 0;i < pathname.length; i++) {
|
|
1119
|
-
const code = pathname.charCodeAt(i);
|
|
1120
|
-
if (code > 31 && code !== 127)
|
|
1121
|
-
out += pathname.charAt(i);
|
|
1122
|
-
}
|
|
1123
|
-
return out;
|
|
1124
|
-
}
|
|
1125
|
-
function levelForStatus(status) {
|
|
1126
|
-
if (status === 499)
|
|
1127
|
-
return "info";
|
|
1128
|
-
if (status >= 500)
|
|
1129
|
-
return "error";
|
|
1130
|
-
if (status >= 400)
|
|
1131
|
-
return "warn";
|
|
1132
|
-
return "info";
|
|
1133
|
-
}
|
|
1134
|
-
function buildLogFields(method, path, status, durationMs, traceId, errorCode2) {
|
|
1135
|
-
const fields = { traceId, method, path, status, durationMs };
|
|
1136
|
-
if (errorCode2 === undefined && status >= 400)
|
|
1137
|
-
return fields;
|
|
1138
|
-
return { ...fields, errorCode: errorCode2 };
|
|
1139
|
-
}
|
|
1140
|
-
function formatMs(ms) {
|
|
1141
|
-
if (ms >= 1000)
|
|
1142
|
-
return `${(ms / 1000).toFixed(2)}s`;
|
|
1143
|
-
if (ms >= 1)
|
|
1144
|
-
return `${Math.round(ms)}ms`;
|
|
1145
|
-
return `${Math.round(ms * 1000)}µs`;
|
|
1146
|
-
}
|
|
1147
|
-
function durationColor(ms) {
|
|
1148
|
-
if (ms >= 1000)
|
|
1149
|
-
return c.red;
|
|
1150
|
-
if (ms > 300)
|
|
1151
|
-
return c.yellow;
|
|
1152
|
-
return c.green;
|
|
1153
|
-
}
|
|
1154
|
-
function statusColor(status) {
|
|
1155
|
-
if (status >= 500)
|
|
1156
|
-
return c.red;
|
|
1157
|
-
if (status >= 400)
|
|
1158
|
-
return c.yellow;
|
|
1159
|
-
if (status >= 300)
|
|
1160
|
-
return c.cyan;
|
|
1161
|
-
return c.green;
|
|
1162
|
-
}
|
|
1163
|
-
function ipLabel(ip) {
|
|
1164
|
-
if (!ip || ip === "::1" || ip === "127.0.0.1")
|
|
1165
|
-
return `${c.magenta}local${c.reset}`;
|
|
1166
|
-
return `${c.dim}${ip}${c.reset}`;
|
|
1167
|
-
}
|
|
1168
|
-
var SKIP_PREFIXES = ["/_bun/", "/_bundle", "/favicon"];
|
|
1169
|
-
function shouldLog(pathname, method) {
|
|
1170
|
-
if (method === "OPTIONS")
|
|
1171
|
-
return false;
|
|
1172
|
-
return !SKIP_PREFIXES.some((prefix) => pathname.startsWith(prefix));
|
|
1173
|
-
}
|
|
1174
|
-
function logIncoming(req, pathname, traceId, format, ipAddress) {
|
|
1175
|
-
const log = { traceId };
|
|
1176
|
-
if (format === "pretty") {
|
|
1177
|
-
const mc = METHOD_COLOR[req.method] ?? c.dim;
|
|
1178
|
-
console.log(`${c.gray}[${timestamp()}]${c.reset} ${mc}${req.method}${c.reset} ${c.dim}${traceId}${c.reset} ${c.cyan}→${c.reset} ${safePath(pathname)} ${ipLabel(ipAddress ?? "")}`);
|
|
1179
|
-
}
|
|
1180
|
-
return log;
|
|
1181
|
-
}
|
|
1182
|
-
function structuredLine(own, extra) {
|
|
1183
|
-
try {
|
|
1184
|
-
return JSON.stringify({ ...extra, ...own });
|
|
1185
|
-
} catch {
|
|
1186
|
-
return JSON.stringify(own);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
function logOutgoing(entry) {
|
|
1190
|
-
const { req, pathname, status, log, ipAddress, errorCode: errorCode2, durationMs, format, extra } = entry;
|
|
1191
|
-
const ms = durationMs;
|
|
1192
|
-
if (format === "json") {
|
|
1193
|
-
const own = {
|
|
1194
|
-
ts: new Date().toISOString(),
|
|
1195
|
-
level: levelForStatus(status),
|
|
1196
|
-
msg: `${req.method} ${pathname} ${status}`,
|
|
1197
|
-
...buildLogFields(req.method, pathname, status, durationMs, log.traceId, errorCode2),
|
|
1198
|
-
ip: ipAddress
|
|
1199
|
-
};
|
|
1200
|
-
console.log(structuredLine(own, extra));
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
|
-
const mc = METHOD_COLOR[req.method] ?? c.dim;
|
|
1204
|
-
const code = errorCode2 ? ` ${c.red}${errorCode2}${c.reset}` : "";
|
|
1205
|
-
console.log(`${c.gray}[${timestamp()}]${c.reset} ${mc}${req.method}${c.reset} ${c.dim}${log.traceId}${c.reset} ${c.cyan}←${c.reset} ${safePath(pathname)} ${statusColor(status)}${status}${c.reset}${code} ${durationColor(ms)}${formatMs(ms)}${c.reset} ${ipLabel(ipAddress ?? "")}`);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
1319
|
// src/server/logging.ts
|
|
1209
1320
|
var LOGGER_METHODS = ["info", "warn", "error", "debug"];
|
|
1210
1321
|
function isBareLogger(value) {
|
|
@@ -1258,57 +1369,24 @@ function collectExtraLogFields(config, req, url, outcome) {
|
|
|
1258
1369
|
return { fields, enrichKeys };
|
|
1259
1370
|
}
|
|
1260
1371
|
|
|
1261
|
-
// src/server/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
return "getSetCookie" in headers && typeof headers.getSetCookie === "function";
|
|
1265
|
-
}
|
|
1266
|
-
function isReservedHeader(name) {
|
|
1267
|
-
const normalized = name.toLowerCase();
|
|
1268
|
-
return RESERVED_HEADERS.has(normalized) || normalized.startsWith("access-control-");
|
|
1372
|
+
// src/server/router.ts
|
|
1373
|
+
function routeSegments(path) {
|
|
1374
|
+
return path.split("/").filter(Boolean);
|
|
1269
1375
|
}
|
|
1270
|
-
function
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
continue;
|
|
1285
|
-
target.append(name, value);
|
|
1286
|
-
}
|
|
1287
|
-
if (preservesSetCookie) {
|
|
1288
|
-
for (const cookie of metadata.headers.getSetCookie()) {
|
|
1289
|
-
target.append("Set-Cookie", cookie);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
// src/server/router.ts
|
|
1295
|
-
function routeSegments(path) {
|
|
1296
|
-
return path.split("/").filter(Boolean);
|
|
1297
|
-
}
|
|
1298
|
-
function rawRouteShape(path) {
|
|
1299
|
-
parseTrailingWildcard(path);
|
|
1300
|
-
const segments = routeSegments(path).map((segment) => {
|
|
1301
|
-
if (segment.startsWith(":"))
|
|
1302
|
-
return { kind: "param" };
|
|
1303
|
-
if (segment.startsWith("*"))
|
|
1304
|
-
return { kind: "wildcard" };
|
|
1305
|
-
return { kind: "static", value: segment };
|
|
1306
|
-
});
|
|
1307
|
-
return {
|
|
1308
|
-
segments,
|
|
1309
|
-
signature: segments.map((segment) => segment.kind === "static" ? segment.value : `:${segment.kind}`).join("/"),
|
|
1310
|
-
wildcard: segments.at(-1)?.kind === "wildcard"
|
|
1311
|
-
};
|
|
1376
|
+
function rawRouteShape(path) {
|
|
1377
|
+
parseTrailingWildcard(path);
|
|
1378
|
+
const segments = routeSegments(path).map((segment) => {
|
|
1379
|
+
if (segment.startsWith(":"))
|
|
1380
|
+
return { kind: "param" };
|
|
1381
|
+
if (segment.startsWith("*"))
|
|
1382
|
+
return { kind: "wildcard" };
|
|
1383
|
+
return { kind: "static", value: segment };
|
|
1384
|
+
});
|
|
1385
|
+
return {
|
|
1386
|
+
segments,
|
|
1387
|
+
signature: segments.map((segment) => segment.kind === "static" ? segment.value : `:${segment.kind}`).join("/"),
|
|
1388
|
+
wildcard: segments.at(-1)?.kind === "wildcard"
|
|
1389
|
+
};
|
|
1312
1390
|
}
|
|
1313
1391
|
function segmentCovers(earlier, later) {
|
|
1314
1392
|
if (earlier.kind === "param")
|
|
@@ -1550,46 +1628,50 @@ function validateRawRoutes(rawRoutes) {
|
|
|
1550
1628
|
}
|
|
1551
1629
|
}
|
|
1552
1630
|
|
|
1553
|
-
// src/server/
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
for (let depth = 0;depth <= MAX_REQUEST_ABORT_CAUSE_DEPTH; depth += 1) {
|
|
1560
|
-
if (current === reason)
|
|
1561
|
-
return true;
|
|
1562
|
-
if (depth === MAX_REQUEST_ABORT_CAUSE_DEPTH || !isRecord(current))
|
|
1563
|
-
return false;
|
|
1564
|
-
if (visited.has(current))
|
|
1565
|
-
return false;
|
|
1566
|
-
visited.add(current);
|
|
1567
|
-
current = current.cause;
|
|
1631
|
+
// src/server/route-table.ts
|
|
1632
|
+
function compileRouteTable(config, warn) {
|
|
1633
|
+
for (const group of config.groups ?? []) {
|
|
1634
|
+
if (group.hooks && "onRequest" in group.hooks) {
|
|
1635
|
+
throw new Error("[stitchkit] a route group cannot declare `onRequest` — it runs before routing, so the group it belongs to is not known yet and the hook would never be dispatched. Refuse before dispatch with the server-level `hooks.onRequest`, or gate the group with its `authorize`, which runs once the endpoint is known.");
|
|
1636
|
+
}
|
|
1568
1637
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1638
|
+
const routeMap = buildRouteMap(normalizeGroups(config));
|
|
1639
|
+
validateRoutes(routeMap);
|
|
1640
|
+
validateRawRoutes(config.rawRoutes);
|
|
1641
|
+
for (const shadow of findShadowedRoutes(routeMap, config.rawRoutes)) {
|
|
1642
|
+
const gate = shadow.scope && shadow.scope !== "public" ? ` (scope "${shadow.scope}")` : "";
|
|
1643
|
+
const line = `[stitchkit] raw route ${shadow.rawRoute} shadows contract route ${shadow.pattern}` + ` → ${shadow.endpoint}${gate} will never run, and its hooks never apply`;
|
|
1644
|
+
warn(line);
|
|
1645
|
+
}
|
|
1646
|
+
return routeMap;
|
|
1577
1647
|
}
|
|
1578
|
-
function
|
|
1579
|
-
|
|
1580
|
-
|
|
1648
|
+
function normalizeGroups(config) {
|
|
1649
|
+
const result = [];
|
|
1650
|
+
if (config.services) {
|
|
1651
|
+
for (const service of config.services) {
|
|
1652
|
+
const prefix = config.scopePrefixes?.[service.scope] ?? "";
|
|
1653
|
+
result.push({ prefix, service });
|
|
1654
|
+
}
|
|
1581
1655
|
}
|
|
1582
|
-
|
|
1656
|
+
if (config.groups) {
|
|
1657
|
+
for (const group of config.groups) {
|
|
1658
|
+
for (const service of group.services) {
|
|
1659
|
+
result.push({ prefix: group.pathPrefix ?? "", service, hooks: group.hooks });
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
return result;
|
|
1583
1664
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1665
|
+
|
|
1666
|
+
// src/server/handler-state.ts
|
|
1667
|
+
function createHandlerState(config) {
|
|
1668
|
+
const { cors, hooks, logging = false, observability } = config;
|
|
1586
1669
|
if (cors)
|
|
1587
1670
|
assertCorsConfig(cors);
|
|
1588
1671
|
assertJsonBodyLimit(config.maxJsonBodyBytes, "HandlerConfig.maxJsonBodyBytes");
|
|
1589
1672
|
const logConfig = resolveLoggingConfig(logging);
|
|
1590
1673
|
const customLogger = logConfig?.logger ?? null;
|
|
1591
1674
|
const useDefaultLog = logConfig !== null && !logConfig.logger;
|
|
1592
|
-
const customTraceId = config.traceId;
|
|
1593
1675
|
const warn = (line) => {
|
|
1594
1676
|
try {
|
|
1595
1677
|
if (customLogger)
|
|
@@ -1598,9 +1680,23 @@ function createHandler(config) {
|
|
|
1598
1680
|
console.warn(line);
|
|
1599
1681
|
} catch {}
|
|
1600
1682
|
};
|
|
1683
|
+
return {
|
|
1684
|
+
config,
|
|
1685
|
+
cors,
|
|
1686
|
+
hooks,
|
|
1687
|
+
observability,
|
|
1688
|
+
logConfig,
|
|
1689
|
+
customLogger,
|
|
1690
|
+
useDefaultLog,
|
|
1691
|
+
warnedEnrichKeys: new Set,
|
|
1692
|
+
warn,
|
|
1693
|
+
resolveId: createTraceIdResolver(config.traceId, warn),
|
|
1694
|
+
routeMap: compileRouteTable(config, warn)
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
function createTraceIdResolver(customTraceId, warn) {
|
|
1601
1698
|
let traceResolverBroken = false;
|
|
1602
|
-
|
|
1603
|
-
const resolveId = (req, fallback) => {
|
|
1699
|
+
return (req, fallback) => {
|
|
1604
1700
|
if (!customTraceId)
|
|
1605
1701
|
return fallback ?? resolveTraceId(req);
|
|
1606
1702
|
try {
|
|
@@ -1613,281 +1709,238 @@ function createHandler(config) {
|
|
|
1613
1709
|
return fallback ?? resolveTraceId(req);
|
|
1614
1710
|
}
|
|
1615
1711
|
};
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
// src/server/logger.ts
|
|
1715
|
+
var c = {
|
|
1716
|
+
reset: "\x1B[0m",
|
|
1717
|
+
dim: "\x1B[2m",
|
|
1718
|
+
red: "\x1B[31m",
|
|
1719
|
+
green: "\x1B[32m",
|
|
1720
|
+
yellow: "\x1B[33m",
|
|
1721
|
+
blue: "\x1B[34m",
|
|
1722
|
+
magenta: "\x1B[35m",
|
|
1723
|
+
cyan: "\x1B[36m",
|
|
1724
|
+
gray: "\x1B[90m"
|
|
1725
|
+
};
|
|
1726
|
+
var METHOD_COLOR = {
|
|
1727
|
+
GET: c.green,
|
|
1728
|
+
POST: c.yellow,
|
|
1729
|
+
PUT: c.blue,
|
|
1730
|
+
PATCH: c.cyan,
|
|
1731
|
+
DELETE: c.red,
|
|
1732
|
+
OPTIONS: c.gray
|
|
1733
|
+
};
|
|
1734
|
+
var runtimeEnv = process.env;
|
|
1735
|
+
function resolveLogFormat(preference) {
|
|
1736
|
+
if (preference)
|
|
1737
|
+
return preference;
|
|
1738
|
+
return runtimeEnv.NODE_ENV === "production" ? "json" : "pretty";
|
|
1739
|
+
}
|
|
1740
|
+
function timestamp() {
|
|
1741
|
+
const now = new Date;
|
|
1742
|
+
const t = now.toLocaleTimeString("en-US", {
|
|
1743
|
+
hour12: false,
|
|
1744
|
+
hour: "2-digit",
|
|
1745
|
+
minute: "2-digit",
|
|
1746
|
+
second: "2-digit"
|
|
1747
|
+
});
|
|
1748
|
+
return `${t}.${now.getMilliseconds().toString().padStart(3, "0")}`;
|
|
1749
|
+
}
|
|
1750
|
+
function safePath(pathname) {
|
|
1751
|
+
let out = "";
|
|
1752
|
+
for (let i = 0;i < pathname.length; i++) {
|
|
1753
|
+
const code = pathname.charCodeAt(i);
|
|
1754
|
+
if (code > 31 && code !== 127)
|
|
1755
|
+
out += pathname.charAt(i);
|
|
1620
1756
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1757
|
+
return out;
|
|
1758
|
+
}
|
|
1759
|
+
function levelForStatus(status) {
|
|
1760
|
+
if (status === 499)
|
|
1761
|
+
return "info";
|
|
1762
|
+
if (status >= 500)
|
|
1763
|
+
return "error";
|
|
1764
|
+
if (status >= 400)
|
|
1765
|
+
return "warn";
|
|
1766
|
+
return "info";
|
|
1767
|
+
}
|
|
1768
|
+
function buildLogFields(method, path, status, durationMs, traceId, errorCode2) {
|
|
1769
|
+
const fields = { traceId, method, path, status, durationMs };
|
|
1770
|
+
if (errorCode2 === undefined && status >= 400)
|
|
1771
|
+
return fields;
|
|
1772
|
+
return { ...fields, errorCode: errorCode2 };
|
|
1773
|
+
}
|
|
1774
|
+
function formatMs(ms) {
|
|
1775
|
+
if (ms >= 1000)
|
|
1776
|
+
return `${(ms / 1000).toFixed(2)}s`;
|
|
1777
|
+
if (ms >= 1)
|
|
1778
|
+
return `${Math.round(ms)}ms`;
|
|
1779
|
+
return `${Math.round(ms * 1000)}µs`;
|
|
1780
|
+
}
|
|
1781
|
+
function durationColor(ms) {
|
|
1782
|
+
if (ms >= 1000)
|
|
1783
|
+
return c.red;
|
|
1784
|
+
if (ms > 300)
|
|
1785
|
+
return c.yellow;
|
|
1786
|
+
return c.green;
|
|
1787
|
+
}
|
|
1788
|
+
function statusColor(status) {
|
|
1789
|
+
if (status >= 500)
|
|
1790
|
+
return c.red;
|
|
1791
|
+
if (status >= 400)
|
|
1792
|
+
return c.yellow;
|
|
1793
|
+
if (status >= 300)
|
|
1794
|
+
return c.cyan;
|
|
1795
|
+
return c.green;
|
|
1796
|
+
}
|
|
1797
|
+
function ipLabel(ip) {
|
|
1798
|
+
if (!ip || ip === "::1" || ip === "127.0.0.1")
|
|
1799
|
+
return `${c.magenta}local${c.reset}`;
|
|
1800
|
+
return `${c.dim}${ip}${c.reset}`;
|
|
1801
|
+
}
|
|
1802
|
+
var SKIP_PREFIXES = ["/_bun/", "/_bundle", "/favicon"];
|
|
1803
|
+
function shouldLog(pathname, method) {
|
|
1804
|
+
if (method === "OPTIONS")
|
|
1805
|
+
return false;
|
|
1806
|
+
return !SKIP_PREFIXES.some((prefix) => pathname.startsWith(prefix));
|
|
1807
|
+
}
|
|
1808
|
+
function logIncoming(req, pathname, traceId, format, ipAddress) {
|
|
1809
|
+
const log = { traceId };
|
|
1810
|
+
if (format === "pretty") {
|
|
1811
|
+
const mc = METHOD_COLOR[req.method] ?? c.dim;
|
|
1812
|
+
console.log(`${c.gray}[${timestamp()}]${c.reset} ${mc}${req.method}${c.reset} ${c.dim}${traceId}${c.reset} ${c.cyan}→${c.reset} ${safePath(pathname)} ${ipLabel(ipAddress ?? "")}`);
|
|
1628
1813
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1814
|
+
return log;
|
|
1815
|
+
}
|
|
1816
|
+
function structuredLine(own, extra) {
|
|
1817
|
+
try {
|
|
1818
|
+
return JSON.stringify({ ...extra, ...own });
|
|
1819
|
+
} catch {
|
|
1820
|
+
return JSON.stringify(own);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
function logOutgoing(entry) {
|
|
1824
|
+
const { req, pathname, status, log, ipAddress, errorCode: errorCode2, durationMs, format, extra } = entry;
|
|
1825
|
+
const ms = durationMs;
|
|
1826
|
+
if (format === "json") {
|
|
1827
|
+
const own = {
|
|
1828
|
+
ts: new Date().toISOString(),
|
|
1829
|
+
level: levelForStatus(status),
|
|
1830
|
+
msg: `${req.method} ${pathname} ${status}`,
|
|
1831
|
+
...buildLogFields(req.method, pathname, status, durationMs, log.traceId, errorCode2),
|
|
1832
|
+
ip: ipAddress
|
|
1833
|
+
};
|
|
1834
|
+
console.log(structuredLine(own, extra));
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
const mc = METHOD_COLOR[req.method] ?? c.dim;
|
|
1838
|
+
const code = errorCode2 ? ` ${c.red}${errorCode2}${c.reset}` : "";
|
|
1839
|
+
console.log(`${c.gray}[${timestamp()}]${c.reset} ${mc}${req.method}${c.reset} ${c.dim}${log.traceId}${c.reset} ${c.cyan}←${c.reset} ${safePath(pathname)} ${statusColor(status)}${status}${c.reset}${code} ${durationColor(ms)}${formatMs(ms)}${c.reset} ${ipLabel(ipAddress ?? "")}`);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
// src/server/request-completion.ts
|
|
1843
|
+
var BODY_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
1844
|
+
function openRequestCompletion(state, window) {
|
|
1845
|
+
const { logConfig, customLogger, useDefaultLog, observability } = state;
|
|
1846
|
+
const { req, url, traceId, startedAt, ipAddress } = window;
|
|
1847
|
+
const shouldLogRequest = logConfig !== null && shouldLog(url.pathname, req.method) && !shouldSkipLog(logConfig, req, url);
|
|
1848
|
+
const payload = observability?.includePayload && BODY_METHODS.has(req.method) ? req.clone().json().catch(() => {
|
|
1849
|
+
return;
|
|
1850
|
+
}) : undefined;
|
|
1851
|
+
const logFormat = resolveLogFormat(logConfig?.format);
|
|
1852
|
+
let reqLog;
|
|
1853
|
+
if (shouldLogRequest && useDefaultLog) {
|
|
1854
|
+
reqLog = logIncoming(req, url.pathname, traceId, logFormat, ipAddress);
|
|
1855
|
+
}
|
|
1856
|
+
if (shouldLogRequest && customLogger) {
|
|
1857
|
+
reqLog = { traceId };
|
|
1858
|
+
try {
|
|
1859
|
+
customLogger.debug(`${req.method} ${url.pathname}`, {
|
|
1860
|
+
traceId,
|
|
1861
|
+
method: req.method,
|
|
1862
|
+
path: url.pathname,
|
|
1863
|
+
ip: ipAddress
|
|
1864
|
+
});
|
|
1865
|
+
} catch {}
|
|
1866
|
+
}
|
|
1867
|
+
let completed = false;
|
|
1868
|
+
return (status, errorCode2, outcome) => {
|
|
1869
|
+
if (completed)
|
|
1633
1870
|
return;
|
|
1634
|
-
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
if (shouldLogRequest && useDefaultLog) {
|
|
1638
|
-
reqLog = logIncoming(req, url.pathname, traceId, logFormat, ipAddress);
|
|
1639
|
-
}
|
|
1640
|
-
if (shouldLogRequest && customLogger) {
|
|
1641
|
-
reqLog = { traceId };
|
|
1871
|
+
completed = true;
|
|
1872
|
+
const durationMs = Math.round(Number(process.hrtime.bigint() - startedAt) / 1e6);
|
|
1873
|
+
if (reqLog && logConfig) {
|
|
1642
1874
|
try {
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1875
|
+
writeCompletionLine(state, logConfig, window, {
|
|
1876
|
+
reqLog,
|
|
1877
|
+
status,
|
|
1878
|
+
durationMs,
|
|
1879
|
+
errorCode: errorCode2,
|
|
1880
|
+
logFormat
|
|
1648
1881
|
});
|
|
1649
1882
|
} catch {}
|
|
1650
1883
|
}
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
status,
|
|
1661
|
-
durationMs,
|
|
1662
|
-
errorCode: errorCode2
|
|
1663
|
-
});
|
|
1664
|
-
const frameworkFields = buildLogFields(req.method, url.pathname, status, durationMs, reqLog.traceId, errorCode2);
|
|
1665
|
-
const ownedFields = { ...frameworkFields, ip: ipAddress };
|
|
1666
|
-
for (const key of collected.enrichKeys) {
|
|
1667
|
-
const ownedByActiveSink = Object.hasOwn(ownedFields, key) || useDefaultLog && (key === "ts" || key === "level" || key === "msg");
|
|
1668
|
-
if (ownedByActiveSink && !warnedEnrichKeys.has(key)) {
|
|
1669
|
-
warnedEnrichKeys.add(key);
|
|
1670
|
-
warn(`[stitchkit] logging.enrich field "${key}" was discarded because the framework owns it`);
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
const extra = collected.fields;
|
|
1674
|
-
if (useDefaultLog) {
|
|
1675
|
-
logOutgoing({
|
|
1676
|
-
req,
|
|
1677
|
-
pathname: url.pathname,
|
|
1678
|
-
status,
|
|
1679
|
-
log: reqLog,
|
|
1680
|
-
ipAddress,
|
|
1681
|
-
errorCode: errorCode2,
|
|
1682
|
-
durationMs,
|
|
1683
|
-
format: logFormat,
|
|
1684
|
-
extra
|
|
1685
|
-
});
|
|
1686
|
-
}
|
|
1687
|
-
if (customLogger) {
|
|
1688
|
-
const level = levelForStatus(status);
|
|
1689
|
-
customLogger[level](`${req.method} ${url.pathname} ${status}${errorCode2 ? ` ${errorCode2}` : ""} ${durationMs}ms`, {
|
|
1690
|
-
...extra,
|
|
1691
|
-
...frameworkFields,
|
|
1692
|
-
ip: ipAddress
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
|
-
} catch {}
|
|
1696
|
-
}
|
|
1697
|
-
const context = getRequestContext();
|
|
1698
|
-
if (observability && context) {
|
|
1699
|
-
try {
|
|
1700
|
-
observability.complete({
|
|
1701
|
-
context,
|
|
1702
|
-
statusCode: status,
|
|
1703
|
-
durationMs,
|
|
1704
|
-
payload,
|
|
1705
|
-
...outcome !== undefined && { outcome }
|
|
1706
|
-
});
|
|
1707
|
-
} catch {}
|
|
1708
|
-
}
|
|
1709
|
-
};
|
|
1710
|
-
const respondError = async (err, errCtx, endpoint, group) => {
|
|
1711
|
-
if (isClientClosedRequest(req, err)) {
|
|
1712
|
-
const response = applyCors(new Response(null, { status: 499, statusText: "Client Closed Request" }), cors, req);
|
|
1713
|
-
complete(response.status, undefined, "cancelled");
|
|
1714
|
-
return response;
|
|
1715
|
-
}
|
|
1716
|
-
const recordFailure = (normalized) => {
|
|
1717
|
-
if (getRequestContext()?.error !== undefined)
|
|
1718
|
-
return;
|
|
1719
|
-
const known = AppError.is(err) ? err : normalized;
|
|
1720
|
-
const code = known?.code ?? errorCode(err) ?? "INTERNAL_SERVER_ERROR";
|
|
1721
|
-
setRequestError({
|
|
1722
|
-
code,
|
|
1723
|
-
message: recordedErrorMessage(code, known?.message, err),
|
|
1724
|
-
details: known?.details
|
|
1884
|
+
const context = getRequestContext();
|
|
1885
|
+
if (observability && context) {
|
|
1886
|
+
try {
|
|
1887
|
+
observability.complete({
|
|
1888
|
+
context,
|
|
1889
|
+
statusCode: status,
|
|
1890
|
+
durationMs,
|
|
1891
|
+
payload,
|
|
1892
|
+
...outcome !== undefined && { outcome }
|
|
1725
1893
|
});
|
|
1726
|
-
}
|
|
1727
|
-
const customResponse = await dispatchErrorHooks({
|
|
1728
|
-
context: errCtx ?? buildErrorContext(req, url, traceId, clientIp),
|
|
1729
|
-
error: err,
|
|
1730
|
-
endpoint,
|
|
1731
|
-
group,
|
|
1732
|
-
global: hooks,
|
|
1733
|
-
logger: customLogger,
|
|
1734
|
-
respond: (response) => {
|
|
1735
|
-
recordFailure();
|
|
1736
|
-
const withCors = applyCors(response, cors, req);
|
|
1737
|
-
complete(withCors.status, errorCode(err));
|
|
1738
|
-
return withCors;
|
|
1739
|
-
}
|
|
1740
|
-
});
|
|
1741
|
-
if (customResponse)
|
|
1742
|
-
return customResponse;
|
|
1743
|
-
const appErr = normalizeError(err);
|
|
1744
|
-
recordFailure(appErr);
|
|
1745
|
-
complete(appErr.status, appErr.code);
|
|
1746
|
-
return json(appErr.toJSON(), appErr.status, cors, req);
|
|
1747
|
-
};
|
|
1748
|
-
if (cors && req.method === "OPTIONS") {
|
|
1749
|
-
const response = corsPreflightResponse(cors, req);
|
|
1750
|
-
complete(response.status);
|
|
1751
|
-
return response;
|
|
1752
|
-
}
|
|
1753
|
-
try {
|
|
1754
|
-
if (hooks?.onRequest) {
|
|
1755
|
-
const earlyResponse = await hooks.onRequest(req);
|
|
1756
|
-
if (earlyResponse instanceof Response) {
|
|
1757
|
-
const withCors = applyCors(earlyResponse, cors, req);
|
|
1758
|
-
complete(withCors.status);
|
|
1759
|
-
return withCors;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
} catch (err) {
|
|
1763
|
-
return respondError(err);
|
|
1764
|
-
}
|
|
1765
|
-
if (config.rawRoutes) {
|
|
1766
|
-
const rawMatch = matchRawRoute(config.rawRoutes, req.method, url.pathname);
|
|
1767
|
-
if (rawMatch) {
|
|
1768
|
-
if (rawMatch.route.serviceName !== undefined) {
|
|
1769
|
-
setRequestEndpoint(rawMatch.route.serviceName, rawMatch.route.action);
|
|
1770
|
-
}
|
|
1771
|
-
try {
|
|
1772
|
-
const res = await rawMatch.route.handler(req, {
|
|
1773
|
-
params: rawMatch.params,
|
|
1774
|
-
server,
|
|
1775
|
-
ipAddress
|
|
1776
|
-
});
|
|
1777
|
-
const withCors = applyCors(res, cors, req);
|
|
1778
|
-
complete(withCors.status);
|
|
1779
|
-
return withCors;
|
|
1780
|
-
} catch (err) {
|
|
1781
|
-
return respondError(err);
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
const match = matchRoute(routeMap, req.method, url.pathname);
|
|
1786
|
-
if (!match) {
|
|
1787
|
-
const allow = allowedMethods(routeMap, url.pathname);
|
|
1788
|
-
if (allow.length > 0) {
|
|
1789
|
-
const res = await respondError(new AppError("METHOD_NOT_ALLOWED", `Method ${req.method} not allowed`, 405));
|
|
1790
|
-
res.headers.set("Allow", allow.join(", "));
|
|
1791
|
-
return res;
|
|
1792
|
-
}
|
|
1793
|
-
return respondError(new AppError("NOT_FOUND", "Not found", 404));
|
|
1794
|
-
}
|
|
1795
|
-
const { method, pathParams, groupHooks } = match;
|
|
1796
|
-
const ctx = buildBaseContext(req, url, pathParams, traceId, clientIp);
|
|
1797
|
-
setRequestEndpoint(method.serviceName, method.key);
|
|
1798
|
-
let multipartLifecycle;
|
|
1799
|
-
try {
|
|
1800
|
-
parsePathParamsInto(ctx, method);
|
|
1801
|
-
if (hooks?.authorize) {
|
|
1802
|
-
await hooks.authorize(ctx, method);
|
|
1803
|
-
}
|
|
1804
|
-
if (groupHooks?.authorize) {
|
|
1805
|
-
await groupHooks.authorize(ctx, method);
|
|
1806
|
-
}
|
|
1807
|
-
multipartLifecycle = await parseRequestPayloadInto(ctx, req, url, method, config.maxJsonBodyBytes, cors);
|
|
1808
|
-
if (hooks?.beforeHandle) {
|
|
1809
|
-
await hooks.beforeHandle(ctx, method);
|
|
1810
|
-
}
|
|
1811
|
-
if (groupHooks?.beforeHandle) {
|
|
1812
|
-
await groupHooks.beforeHandle(ctx, method);
|
|
1813
|
-
}
|
|
1814
|
-
const responseMetadata = method.responseMeta ? createResponseMetadata() : undefined;
|
|
1815
|
-
if (responseMetadata)
|
|
1816
|
-
ctx.response = responseMetadata;
|
|
1817
|
-
const streamAbort = method.stream ? new AbortController : undefined;
|
|
1818
|
-
if (streamAbort) {
|
|
1819
|
-
if (req.signal.aborted)
|
|
1820
|
-
streamAbort.abort(req.signal.reason);
|
|
1821
|
-
else {
|
|
1822
|
-
req.signal.addEventListener("abort", () => streamAbort.abort(req.signal.reason), {
|
|
1823
|
-
once: true
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
ctx.signal = streamAbort.signal;
|
|
1827
|
-
}
|
|
1828
|
-
let result = await method.handler(ctx);
|
|
1829
|
-
if (method.rawResponse) {
|
|
1830
|
-
if (!(result instanceof Response)) {
|
|
1831
|
-
throw new AppError("INTERNAL_SERVER_ERROR", `Raw endpoint ${method.serviceName}.${method.key} must return a Response`, 500);
|
|
1832
|
-
}
|
|
1833
|
-
const response = method.method === "HEAD" ? new Response(null, {
|
|
1834
|
-
status: result.status,
|
|
1835
|
-
statusText: result.statusText,
|
|
1836
|
-
headers: result.headers
|
|
1837
|
-
}) : result;
|
|
1838
|
-
const rawRes = applyCors(response, cors, req);
|
|
1839
|
-
complete(rawRes.status);
|
|
1840
|
-
return rawRes;
|
|
1841
|
-
}
|
|
1842
|
-
if (method.stream) {
|
|
1843
|
-
if (!streamAbort || !isAsyncIterable(result)) {
|
|
1844
|
-
streamAbort?.abort();
|
|
1845
|
-
throw new AppError("INTERNAL_SERVER_ERROR", `Streaming endpoint ${method.serviceName}.${method.key} must return an AsyncIterable`, 500);
|
|
1846
|
-
}
|
|
1847
|
-
const response = await contractStreamResponse(req, { params: pathParams, server, ipAddress: clientIp.socketIp }, result, method.stream, streamAbort);
|
|
1848
|
-
const withCors = applyCors(response, cors, req);
|
|
1849
|
-
complete(withCors.status);
|
|
1850
|
-
return withCors;
|
|
1851
|
-
}
|
|
1852
|
-
if (groupHooks?.afterHandle) {
|
|
1853
|
-
const transformed = await groupHooks.afterHandle(ctx, result, method);
|
|
1854
|
-
if (transformed !== undefined)
|
|
1855
|
-
result = transformed;
|
|
1856
|
-
}
|
|
1857
|
-
if (hooks?.afterHandle) {
|
|
1858
|
-
const transformed = await hooks.afterHandle(ctx, result, method);
|
|
1859
|
-
if (transformed !== undefined)
|
|
1860
|
-
result = transformed;
|
|
1861
|
-
}
|
|
1862
|
-
if (result instanceof Response) {
|
|
1863
|
-
throw new AppError("INTERNAL_SERVER_ERROR", `${method.serviceName}.${method.key} produced a Response on the data path — only a \`rawResponse: true\` endpoint may return one (an afterHandle hook must return data)`, 500);
|
|
1864
|
-
}
|
|
1865
|
-
const checked = validateDeclaredOutput(method.outputSchema, result, config.warnOnOutputStrip && method.outputSchema ? (paths) => {
|
|
1866
|
-
warn(`[stitchkit] output strip ${method.serviceName}.${method.key}: ${paths.join(", ")}`);
|
|
1867
|
-
} : undefined);
|
|
1868
|
-
if (!checked.ok) {
|
|
1869
|
-
throw new AppError("INTERNAL_SERVER_ERROR", checked.message, 500);
|
|
1870
|
-
}
|
|
1871
|
-
result = checked.data;
|
|
1872
|
-
const responseStatus = method.responseMeta?.status ?? (method.outputSchema ? 200 : 204);
|
|
1873
|
-
if (method.outputSchema && (responseStatus === 204 || responseStatus === 205)) {
|
|
1874
|
-
throw new AppError("INTERNAL_SERVER_ERROR", `${method.serviceName}.${method.key} cannot combine output with bodyless status ${responseStatus}`, 500);
|
|
1875
|
-
}
|
|
1876
|
-
const responseHeaders2 = new Headers(corsHeaders2(cors, req));
|
|
1877
|
-
applyResponseMetadata(responseHeaders2, responseMetadata, `${method.serviceName}.${method.key}`);
|
|
1878
|
-
if (!method.outputSchema) {
|
|
1879
|
-
const empty = new Response(null, { status: responseStatus, headers: responseHeaders2 });
|
|
1880
|
-
complete(responseStatus);
|
|
1881
|
-
return empty;
|
|
1882
|
-
}
|
|
1883
|
-
const body = Response.json(result, { status: responseStatus, headers: responseHeaders2 });
|
|
1884
|
-
complete(responseStatus);
|
|
1885
|
-
return body;
|
|
1886
|
-
} catch (err) {
|
|
1887
|
-
await multipartLifecycle?.rollback();
|
|
1888
|
-
return respondError(err, ctx, method, groupHooks);
|
|
1894
|
+
} catch {}
|
|
1889
1895
|
}
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
function writeCompletionLine(state, logConfig, window, line) {
|
|
1899
|
+
const { customLogger, useDefaultLog, warnedEnrichKeys, warn } = state;
|
|
1900
|
+
const { req, url, ipAddress } = window;
|
|
1901
|
+
const { reqLog, status, durationMs, errorCode: errorCode2, logFormat } = line;
|
|
1902
|
+
const collected = collectExtraLogFields(logConfig, req, url, {
|
|
1903
|
+
status,
|
|
1904
|
+
durationMs,
|
|
1905
|
+
errorCode: errorCode2
|
|
1906
|
+
});
|
|
1907
|
+
const frameworkFields = buildLogFields(req.method, url.pathname, status, durationMs, reqLog.traceId, errorCode2);
|
|
1908
|
+
const ownedFields = { ...frameworkFields, ip: ipAddress };
|
|
1909
|
+
for (const key of collected.enrichKeys) {
|
|
1910
|
+
const ownedByActiveSink = Object.hasOwn(ownedFields, key) || useDefaultLog && (key === "ts" || key === "level" || key === "msg");
|
|
1911
|
+
if (ownedByActiveSink && !warnedEnrichKeys.has(key)) {
|
|
1912
|
+
warnedEnrichKeys.add(key);
|
|
1913
|
+
warn(`[stitchkit] logging.enrich field "${key}" was discarded because the framework owns it`);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
const extra = collected.fields;
|
|
1917
|
+
if (useDefaultLog) {
|
|
1918
|
+
logOutgoing({
|
|
1919
|
+
req,
|
|
1920
|
+
pathname: url.pathname,
|
|
1921
|
+
status,
|
|
1922
|
+
log: reqLog,
|
|
1923
|
+
ipAddress,
|
|
1924
|
+
errorCode: errorCode2,
|
|
1925
|
+
durationMs,
|
|
1926
|
+
format: logFormat,
|
|
1927
|
+
extra
|
|
1928
|
+
});
|
|
1890
1929
|
}
|
|
1930
|
+
if (customLogger) {
|
|
1931
|
+
const level = levelForStatus(status);
|
|
1932
|
+
customLogger[level](`${req.method} ${url.pathname} ${status}${errorCode2 ? ` ${errorCode2}` : ""} ${durationMs}ms`, {
|
|
1933
|
+
...extra,
|
|
1934
|
+
...frameworkFields,
|
|
1935
|
+
ip: ipAddress
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// src/server/create.ts
|
|
1941
|
+
function createHandler(config) {
|
|
1942
|
+
const { trustProxy = false, observability } = config;
|
|
1943
|
+
const state = createHandlerState(config);
|
|
1891
1944
|
return async (req, server) => {
|
|
1892
1945
|
const url = new URL(req.url, "http://localhost");
|
|
1893
1946
|
const requestStartedAt = process.hrtime.bigint();
|
|
@@ -1896,7 +1949,7 @@ function createHandler(config) {
|
|
|
1896
1949
|
socketIp: resolveSocketIp(req, server)
|
|
1897
1950
|
};
|
|
1898
1951
|
const run = async (traceId2, startedAt) => {
|
|
1899
|
-
const response = await dispatch(req, url, traceId2, server, clientIp, startedAt);
|
|
1952
|
+
const response = await dispatch(state, req, url, traceId2, server, clientIp, startedAt);
|
|
1900
1953
|
try {
|
|
1901
1954
|
response.headers.set("x-request-id", traceId2);
|
|
1902
1955
|
const buildId = config.release?.current();
|
|
@@ -1910,9 +1963,9 @@ function createHandler(config) {
|
|
|
1910
1963
|
return run(activeContext.trace.traceId, activeContext.startedAt);
|
|
1911
1964
|
}
|
|
1912
1965
|
if (!observability)
|
|
1913
|
-
return run(resolveId(req), requestStartedAt);
|
|
1966
|
+
return run(state.resolveId(req), requestStartedAt);
|
|
1914
1967
|
const trace = resolveTraceContext(req);
|
|
1915
|
-
const traceId = resolveId(req, trace.traceId);
|
|
1968
|
+
const traceId = state.resolveId(req, trace.traceId);
|
|
1916
1969
|
const ipAddress = extractIp(req, clientIp) || undefined;
|
|
1917
1970
|
const userAgent = req.headers.get("user-agent") ?? undefined;
|
|
1918
1971
|
return runWithRequestContext({
|
|
@@ -1926,63 +1979,69 @@ function createHandler(config) {
|
|
|
1926
1979
|
}, () => run(traceId, requestStartedAt));
|
|
1927
1980
|
};
|
|
1928
1981
|
}
|
|
1929
|
-
function
|
|
1930
|
-
const
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1982
|
+
async function dispatch(state, req, url, traceId, server, clientIp, startedAt) {
|
|
1983
|
+
const { cors, hooks, config, routeMap } = state;
|
|
1984
|
+
const ipAddress = extractIp(req, clientIp) || undefined;
|
|
1985
|
+
const complete = openRequestCompletion(state, { req, url, traceId, startedAt, ipAddress });
|
|
1986
|
+
const respondError = createErrorResponder(state, { req, url, traceId, clientIp, complete });
|
|
1987
|
+
const request = {
|
|
1988
|
+
req,
|
|
1989
|
+
url,
|
|
1990
|
+
traceId,
|
|
1991
|
+
server,
|
|
1992
|
+
clientIp,
|
|
1993
|
+
ipAddress,
|
|
1994
|
+
complete,
|
|
1995
|
+
respondError
|
|
1996
|
+
};
|
|
1997
|
+
if (cors && req.method === "OPTIONS") {
|
|
1998
|
+
const response = corsPreflightResponse(cors, req);
|
|
1999
|
+
complete(response.status);
|
|
2000
|
+
return response;
|
|
1936
2001
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2002
|
+
try {
|
|
2003
|
+
if (hooks?.onRequest) {
|
|
2004
|
+
const earlyResponse = await hooks.onRequest(req);
|
|
2005
|
+
if (earlyResponse instanceof Response) {
|
|
2006
|
+
const withCors = applyCors(earlyResponse, cors, req);
|
|
2007
|
+
complete(withCors.status);
|
|
2008
|
+
return withCors;
|
|
1941
2009
|
}
|
|
1942
2010
|
}
|
|
2011
|
+
} catch (err) {
|
|
2012
|
+
return respondError(err);
|
|
1943
2013
|
}
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
return new Response(res.body, {
|
|
1964
|
-
status: res.status,
|
|
1965
|
-
statusText: res.statusText,
|
|
1966
|
-
headers
|
|
1967
|
-
});
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
function setCorsHeader(headers, key, value) {
|
|
1971
|
-
if (key !== "Vary") {
|
|
1972
|
-
headers.set(key, value);
|
|
1973
|
-
return;
|
|
2014
|
+
if (config.rawRoutes) {
|
|
2015
|
+
const rawMatch = matchRawRoute(config.rawRoutes, req.method, url.pathname);
|
|
2016
|
+
if (rawMatch) {
|
|
2017
|
+
if (rawMatch.route.serviceName !== undefined) {
|
|
2018
|
+
setRequestEndpoint(rawMatch.route.serviceName, rawMatch.route.action);
|
|
2019
|
+
}
|
|
2020
|
+
try {
|
|
2021
|
+
const res = await rawMatch.route.handler(req, {
|
|
2022
|
+
params: rawMatch.params,
|
|
2023
|
+
server,
|
|
2024
|
+
ipAddress
|
|
2025
|
+
});
|
|
2026
|
+
const withCors = applyCors(res, cors, req);
|
|
2027
|
+
complete(withCors.status);
|
|
2028
|
+
return withCors;
|
|
2029
|
+
} catch (err) {
|
|
2030
|
+
return respondError(err);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
1974
2033
|
}
|
|
1975
|
-
const
|
|
1976
|
-
if (
|
|
1977
|
-
|
|
1978
|
-
|
|
2034
|
+
const match = matchRoute(routeMap, req.method, url.pathname);
|
|
2035
|
+
if (!match) {
|
|
2036
|
+
const allow = allowedMethods(routeMap, url.pathname);
|
|
2037
|
+
if (allow.length > 0) {
|
|
2038
|
+
const res = await respondError(new AppError("METHOD_NOT_ALLOWED", `Method ${req.method} not allowed`, 405));
|
|
2039
|
+
res.headers.set("Allow", allow.join(", "));
|
|
2040
|
+
return res;
|
|
2041
|
+
}
|
|
2042
|
+
return respondError(new AppError("NOT_FOUND", "Not found", 404));
|
|
1979
2043
|
}
|
|
1980
|
-
|
|
1981
|
-
if (!present)
|
|
1982
|
-
headers.set("Vary", `${existing}, ${value}`);
|
|
1983
|
-
}
|
|
1984
|
-
function json(data, status, cors, req) {
|
|
1985
|
-
return Response.json(data, { status, headers: corsHeaders2(cors, req) });
|
|
2044
|
+
return dispatchEndpoint(state, request, match);
|
|
1986
2045
|
}
|
|
1987
2046
|
|
|
1988
2047
|
// src/server/process-signals.ts
|
|
@@ -3002,7 +3061,7 @@ function createUnixClientTransport(config) {
|
|
|
3002
3061
|
const activeResponses = new Set;
|
|
3003
3062
|
const bunAborters = new Set;
|
|
3004
3063
|
let closed = false;
|
|
3005
|
-
const
|
|
3064
|
+
const dispatch2 = async (request, redirectCount) => {
|
|
3006
3065
|
if (closed) {
|
|
3007
3066
|
throw new UnixClientTransportError("UNIX_CLIENT_CLOSED", "Unix client transport is closed", "not-dispatched");
|
|
3008
3067
|
}
|
|
@@ -3037,7 +3096,7 @@ function createUnixClientTransport(config) {
|
|
|
3037
3096
|
}
|
|
3038
3097
|
if (request.redirect === "follow") {
|
|
3039
3098
|
await response.body?.cancel();
|
|
3040
|
-
return
|
|
3099
|
+
return dispatch2(redirectedRequest(request, location2, response.status, body), redirectCount + 1);
|
|
3041
3100
|
}
|
|
3042
3101
|
}
|
|
3043
3102
|
return response;
|
|
@@ -3123,7 +3182,7 @@ function createUnixClientTransport(config) {
|
|
|
3123
3182
|
if (request.redirect === "follow") {
|
|
3124
3183
|
incoming.destroy();
|
|
3125
3184
|
releaseResponse();
|
|
3126
|
-
return
|
|
3185
|
+
return dispatch2(redirectedRequest(request, location, status, body), redirectCount + 1);
|
|
3127
3186
|
}
|
|
3128
3187
|
}
|
|
3129
3188
|
const bodyless = request.method === "HEAD" || status === 204 || status === 205 || status === 304;
|
|
@@ -3144,7 +3203,7 @@ function createUnixClientTransport(config) {
|
|
|
3144
3203
|
};
|
|
3145
3204
|
return {
|
|
3146
3205
|
fetch(input, init) {
|
|
3147
|
-
return
|
|
3206
|
+
return dispatch2(new Request(input, init), 0);
|
|
3148
3207
|
},
|
|
3149
3208
|
get closed() {
|
|
3150
3209
|
return closed;
|