stitchkit 0.136.8 → 0.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/dist/agent-runtime/stores/branch-observations.d.ts +19 -19
- package/dist/agent-runtime/stores/schedule-contract.d.ts.map +1 -1
- package/dist/agent-runtime/stores/schedule-records.d.ts.map +1 -1
- package/dist/agent-runtime/stores/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/stores/sql-rows.d.ts +36 -36
- package/dist/agent-runtime/terminal-commit.d.ts +5 -5
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +52 -52
- package/dist/agent-runtime/testing/store-conformance-support.d.ts +26 -26
- package/dist/browser/client-executors.d.ts +2 -3
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/realtime-client.d.ts +6 -1
- package/dist/browser/realtime-client.d.ts.map +1 -1
- package/dist/browser/socket-io-client.d.ts.map +1 -1
- package/dist/browser/socket-io-contract.d.ts +2 -0
- package/dist/browser/socket-io-contract.d.ts.map +1 -1
- package/dist/contract/define-validation.d.ts +6 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +1 -1
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/error-mapping.d.ts +71 -0
- package/dist/contract/error-mapping.d.ts.map +1 -0
- package/dist/contract/errors.d.ts +8 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/factory.d.ts +8 -0
- package/dist/contract/factory.d.ts.map +1 -1
- package/dist/contract/fragments.d.ts +45 -0
- package/dist/contract/fragments.d.ts.map +1 -0
- package/dist/contract/normalize.d.ts +6 -3
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/contract/operation-read.d.ts +38 -0
- package/dist/contract/operation-read.d.ts.map +1 -0
- package/dist/contract/stream.d.ts.map +1 -1
- package/dist/contract/time-zone.d.ts +31 -0
- package/dist/contract/time-zone.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +1 -1
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/device-relay/hub.d.ts +1 -1
- package/dist/device-relay/hub.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +9 -9
- package/dist/entrypoints/agent-executor/claude-sdk.js +11 -11
- package/dist/entrypoints/agent-executor/claude.js +8 -8
- package/dist/entrypoints/agent-executor/codex.js +15 -15
- package/dist/entrypoints/agent-executor/testing.js +11 -11
- package/dist/entrypoints/agent-executor.js +14 -13
- package/dist/entrypoints/agent-runtime/ai-sdk.js +5 -5
- package/dist/entrypoints/agent-runtime/anthropic.js +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +5 -5
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +14 -15
- package/dist/entrypoints/agent-runtime/openai.js +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +7 -7
- package/dist/entrypoints/agent-runtime/postgres.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +8 -8
- package/dist/entrypoints/agent-runtime/sandbox.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +33 -29
- package/dist/entrypoints/application/diagnostic-journal.js +3 -3
- package/dist/entrypoints/application/directory-inbox.js +1 -1
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application/opentelemetry.js +2 -2
- package/dist/entrypoints/application.js +10 -10
- package/dist/entrypoints/cli/publish.js +8 -8
- package/dist/entrypoints/cli.d.ts +2 -0
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +518 -59
- package/dist/entrypoints/contract.d.ts +5 -1
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +25 -7
- package/dist/entrypoints/device-relay.js +20 -10
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.js +10 -10
- package/dist/entrypoints/handler.d.ts +1 -1
- package/dist/entrypoints/handler.d.ts.map +1 -1
- package/dist/entrypoints/handler.js +12 -12
- package/dist/entrypoints/http.js +13 -12
- package/dist/entrypoints/index.js +36 -18
- package/dist/entrypoints/live.d.ts +2 -1
- package/dist/entrypoints/live.d.ts.map +1 -1
- package/dist/entrypoints/live.js +630 -1
- package/dist/entrypoints/node.d.ts +5 -0
- package/dist/entrypoints/node.d.ts.map +1 -1
- package/dist/entrypoints/node.js +36 -16
- package/dist/entrypoints/observability.js +25 -10
- package/dist/entrypoints/postgres.d.ts +1 -0
- package/dist/entrypoints/postgres.d.ts.map +1 -1
- package/dist/entrypoints/postgres.js +66 -0
- package/dist/entrypoints/primitives.js +11 -4
- package/dist/entrypoints/process.js +7 -7
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +6 -29
- package/dist/entrypoints/server.d.ts +6 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +93 -32
- package/dist/entrypoints/service-host/macos.js +6 -6
- package/dist/entrypoints/service-host/work.js +6 -6
- package/dist/entrypoints/service-host.js +10 -10
- package/dist/entrypoints/spend.js +2 -1
- package/dist/entrypoints/sync.js +5 -5
- package/dist/entrypoints/telegram.js +8 -8
- package/dist/entrypoints/testing.d.ts +1 -0
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +1501 -13
- package/dist/entrypoints/tools/agent.js +6 -7
- package/dist/entrypoints/tools/connections.js +9 -11
- package/dist/entrypoints/tools/contract.js +1 -2
- package/dist/entrypoints/tools/invoker.js +4 -5
- package/dist/entrypoints/tools/mcp.js +10 -11
- package/dist/entrypoints/tools/toolkit.d.ts +1 -1
- package/dist/entrypoints/tools/toolkit.d.ts.map +1 -1
- package/dist/entrypoints/tools/toolkit.js +29 -24
- package/dist/entrypoints/tools.js +28 -30
- package/dist/entrypoints/tracking/contract.js +2 -1
- package/dist/entrypoints/xlsx.js +5 -8
- package/dist/{index-033tyx59.js → index-0zw0hcyg.js} +4 -1
- package/dist/{index-zcq3dby3.js → index-1bjwfnnj.js} +1 -1
- package/dist/{index-3zt0r4y0.js → index-1cfacbe2.js} +4 -4
- package/dist/{index-gj4wdts6.js → index-1ckh9qx1.js} +1 -1
- package/dist/index-1pvwmbxp.js +1435 -0
- package/dist/{index-0s75mjh7.js → index-2e4hdh32.js} +1 -1
- package/dist/{index-3shdhzt6.js → index-2j0pqxkn.js} +12 -6
- package/dist/index-3k8w02se.js +28 -0
- package/dist/{index-7fjbdga8.js → index-3pb4ccj2.js} +8 -0
- package/dist/{index-w7e402wx.js → index-48kb4gqq.js} +46 -7
- package/dist/{index-cv9b7fz2.js → index-6rws2xf5.js} +8 -0
- package/dist/{index-bbpygynk.js → index-77w5vx0g.js} +1 -1
- package/dist/index-7dz1ngaf.js +35 -0
- package/dist/{index-y68gavb5.js → index-7n4atsm4.js} +1 -1
- package/dist/index-8ef1bfea.js +71 -0
- package/dist/{index-0x4mnwg5.js → index-8k3y9nd4.js} +6 -9
- package/dist/{index-ezwsqyad.js → index-8rkdkefj.js} +40 -23
- package/dist/{index-3cwq5byx.js → index-9nax7tkn.js} +2 -2
- package/dist/{index-dz6tstcp.js → index-9r6emjwz.js} +1 -1
- package/dist/{index-32ew02z1.js → index-c4b7d6ej.js} +5 -5
- package/dist/index-ceshyndf.js +284 -0
- package/dist/{index-w161azza.js → index-d13rw31w.js} +6 -6
- package/dist/{index-1h0dtfz3.js → index-dmm7vs3f.js} +1 -1
- package/dist/{index-ypm85xwe.js → index-dp8j2e77.js} +1 -1
- package/dist/{index-qqd979f7.js → index-edycjvrv.js} +9 -9
- package/dist/{index-18qdpbcq.js → index-egpf9dv0.js} +200 -1479
- package/dist/{index-fatke81t.js → index-ezgvsj9w.js} +2 -2
- package/dist/{index-chapre0y.js → index-f3e7tj1g.js} +1 -1
- package/dist/{index-df5xr2f9.js → index-frsd2a94.js} +16 -1
- package/dist/index-fy9mmek1.js +95 -0
- package/dist/{index-2331y2tf.js → index-g0gvfzrx.js} +12 -12
- package/dist/index-gpe8d1ka.js +19 -0
- package/dist/{index-4p2zx593.js → index-gyw4qd0m.js} +1 -1
- package/dist/index-gzqy81tw.js +172 -0
- package/dist/{index-yrhw10ef.js → index-h34c510q.js} +8 -4
- package/dist/{index-rr94xcj6.js → index-h527p1yj.js} +10 -4
- package/dist/{index-qj0sq69b.js → index-hgf1tbgz.js} +76 -16
- package/dist/{index-smvmnz5y.js → index-hvpan32x.js} +1 -1
- package/dist/{index-4gbybjg6.js → index-hxawqrb6.js} +2 -2
- package/dist/{index-0k1ba0ss.js → index-j91jffhv.js} +1 -1
- package/dist/{index-d01akj5n.js → index-jr4kwetx.js} +8 -8
- package/dist/{index-xqppqn97.js → index-ka6z48zc.js} +315 -69
- package/dist/{index-by8w2461.js → index-kw0segzt.js} +104 -3
- package/dist/{index-6f4fjygr.js → index-m5t4dr7h.js} +29 -7
- package/dist/{index-afaq0nc4.js → index-n0egp1ke.js} +1 -1
- package/dist/{index-9fzjgg86.js → index-n74rb1dq.js} +2 -2
- package/dist/{index-dwq6a6sq.js → index-pt25vmhc.js} +33 -16
- package/dist/{index-vwg0n3e6.js → index-pyazb8q4.js} +23 -14
- package/dist/{index-5md04mwc.js → index-qpjjbkc5.js} +4 -4
- package/dist/{index-08a3qfr8.js → index-r1qt6zgj.js} +1 -1
- package/dist/{index-ctaxjpa4.js → index-r709pqed.js} +1 -1
- package/dist/{index-2zrx0nzv.js → index-rzc40z6e.js} +3 -5
- package/dist/{index-gq35s3bm.js → index-s5axtd56.js} +2 -2
- package/dist/{index-edpkm3k7.js → index-scpcps66.js} +669 -16
- package/dist/{index-ry8m2mhg.js → index-sf2mt6wj.js} +1 -1
- package/dist/{index-tjhhsnjv.js → index-t1213r0t.js} +1 -1
- package/dist/{index-gvgtmt7a.js → index-t7efje30.js} +2 -2
- package/dist/{index-w3s79kcb.js → index-tzyk36dy.js} +1 -1
- package/dist/{index-8tn10tp6.js → index-v64bvwjr.js} +1 -1
- package/dist/{index-1fhbe4e4.js → index-vksbsqpb.js} +1 -1
- package/dist/{index-dxft2mnm.js → index-wdg7bswj.js} +1 -1
- package/dist/{index-ppy23bd2.js → index-wjx1zs2r.js} +7 -578
- package/dist/{index-efbzm2se.js → index-x2r0ma9t.js} +1 -1
- package/dist/{index-kd48gk7d.js → index-x8py72a3.js} +1 -1
- package/dist/index-xvydbxmk.js +1404 -0
- package/dist/index-xwaphv0d.js +31 -0
- package/dist/{index-a09r9ff0.js → index-y44j39yk.js} +1 -1
- package/dist/{index-7mjsb7zv.js → index-ybrrxjhb.js} +1 -1
- package/dist/{index-xsrma0jd.js → index-ysthxsa8.js} +6 -6
- package/dist/{index-6p5pshcd.js → index-yyh3ey4b.js} +1 -1
- package/dist/{index-mr3njw67.js → index-z6hq9j8j.js} +1 -1
- package/dist/{index-67mzzkdv.js → index-z72agxdn.js} +2 -2
- package/dist/{index-e4w0sfm1.js → index-z78mtc16.js} +1 -1
- package/dist/{index-7csn6pva.js → index-ze94h4ph.js} +5 -0
- package/dist/internal/json-stringify.d.ts +12 -0
- package/dist/internal/json-stringify.d.ts.map +1 -1
- package/dist/internal/unix-client-error.d.ts +4 -0
- package/dist/internal/unix-client-error.d.ts.map +1 -1
- package/dist/live/watch-contract.d.ts +4 -0
- package/dist/live/watch-contract.d.ts.map +1 -1
- package/dist/live/watch-fanout-frame.d.ts +81 -0
- package/dist/live/watch-fanout-frame.d.ts.map +1 -0
- package/dist/live/watch-fanout.d.ts +57 -0
- package/dist/live/watch-fanout.d.ts.map +1 -0
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/spool-core.d.ts +1 -0
- package/dist/observability/spool-core.d.ts.map +1 -1
- package/dist/observability/spool-drain.d.ts +48 -0
- package/dist/observability/spool-drain.d.ts.map +1 -0
- package/dist/observability/spool.d.ts +12 -6
- package/dist/observability/spool.d.ts.map +1 -1
- package/dist/postgres/rollback-transaction.d.ts +61 -0
- package/dist/postgres/rollback-transaction.d.ts.map +1 -0
- package/dist/primitives/deadline.d.ts +4 -4
- package/dist/primitives/deadline.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +3 -32
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/local-consent-key.d.ts +104 -0
- package/dist/server/local-consent-key.d.ts.map +1 -0
- package/dist/server/local-control-journal.d.ts +51 -0
- package/dist/server/local-control-journal.d.ts.map +1 -0
- package/dist/server/local-control-reporter.d.ts +32 -0
- package/dist/server/local-control-reporter.d.ts.map +1 -0
- package/dist/server/local-control.d.ts +48 -0
- package/dist/server/local-control.d.ts.map +1 -0
- package/dist/server/local-host-clients.d.ts +105 -0
- package/dist/server/local-host-clients.d.ts.map +1 -0
- package/dist/server/middleware/trust-fence.d.ts +20 -0
- package/dist/server/middleware/trust-fence.d.ts.map +1 -1
- package/dist/spend/receipt-spool.d.ts +9 -4
- package/dist/spend/receipt-spool.d.ts.map +1 -1
- package/dist/testing/tool-surface-checks.d.ts +89 -0
- package/dist/testing/tool-surface-checks.d.ts.map +1 -0
- package/dist/testing/tool-surface-cli-callable.d.ts +63 -0
- package/dist/testing/tool-surface-cli-callable.d.ts.map +1 -0
- package/dist/testing/tool-surface-dead-refs.d.ts +32 -0
- package/dist/testing/tool-surface-dead-refs.d.ts.map +1 -0
- package/dist/testing/tool-surface-gates.d.ts +72 -0
- package/dist/testing/tool-surface-gates.d.ts.map +1 -0
- package/dist/testing/tool-surface-parity-drivers.d.ts +56 -0
- package/dist/testing/tool-surface-parity-drivers.d.ts.map +1 -0
- package/dist/testing/tool-surface-parity.d.ts +28 -0
- package/dist/testing/tool-surface-parity.d.ts.map +1 -0
- package/dist/testing/tool-surface-ratchet.d.ts +71 -0
- package/dist/testing/tool-surface-ratchet.d.ts.map +1 -0
- package/dist/tools/agent-tools.d.ts +3 -0
- package/dist/tools/agent-tools.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +3 -0
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/create-cli.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts +3 -6
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +4 -0
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/local-key-command.d.ts +53 -0
- package/dist/tools/cli/local-key-command.d.ts.map +1 -0
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-stream.d.ts.map +1 -1
- package/dist/tools/cli/runner.d.ts +8 -3
- package/dist/tools/cli/runner.d.ts.map +1 -1
- package/dist/tools/cli/secret.d.ts +55 -0
- package/dist/tools/cli/secret.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +2 -2
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/stream.d.ts.map +1 -1
- package/dist/tools/cli/unix-outcome.d.ts +6 -0
- package/dist/tools/cli/unix-outcome.d.ts.map +1 -1
- package/dist/tools/execute-result.d.ts +20 -0
- package/dist/tools/execute-result.d.ts.map +1 -1
- package/dist/tools/execute.d.ts +3 -0
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/json-projection.d.ts +13 -9
- package/dist/tools/internal/json-projection.d.ts.map +1 -1
- package/dist/tools/internal/remote-error.d.ts +15 -0
- package/dist/tools/internal/remote-error.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +2 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +3 -0
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts +2 -0
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +5 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -0
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts +2 -0
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/mcp/stdio.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +3 -0
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/read-operation.d.ts +2 -6
- package/dist/tools/read-operation.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +10 -3
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/xlsx/schema.d.ts.map +1 -1
- package/llms/cli.2.txt +10 -8
- package/llms/cli.3.txt +2 -0
- package/llms/cli.txt +18 -3
- package/llms/contract.txt +47 -5
- package/llms/handler.txt +1 -1
- package/llms/live.txt +82 -0
- package/llms/node.txt +5 -0
- package/llms/observability.2.txt +1 -1
- package/llms/observability.txt +6 -0
- package/llms/postgres.txt +1 -0
- package/llms/server.2.txt +206 -240
- package/llms/server.3.txt +242 -202
- package/llms/server.4.txt +202 -1025
- package/llms/server.5.txt +1053 -255
- package/llms/server.6.txt +274 -0
- package/llms/server.txt +32 -116
- package/llms/spend.txt +8 -7
- package/llms/stitchkit.2.txt +13 -35
- package/llms/stitchkit.3.txt +27 -0
- package/llms/stitchkit.txt +81 -81
- package/llms/testing.txt +40 -0
- package/llms/tools-toolkit.txt +2 -2
- package/llms/tools.2.txt +29 -20
- package/llms/{upgrading-0.128.0-0.129.0.txt → upgrading-0.128.0-0.131.0.txt} +101 -3
- package/llms/{upgrading-0.130.0-0.136.0.txt → upgrading-0.132.0-0.137.0.txt} +62 -101
- package/llms/upgrading.txt +2 -2
- package/llms-full.txt +590 -171
- package/llms.txt +13 -13
- package/package.json +1 -1
- package/dist/index-9118dw8d.js +0 -603
- package/dist/index-9vj869rx.js +0 -19
- package/dist/index-a1rjr381.js +0 -114
- package/dist/index-dacxr7nf.js +0 -17
- package/dist/index-dm50x3by.js +0 -63
- package/dist/index-dmrx8xma.js +0 -163
- package/dist/index-ednf2cxs.js +0 -37
- package/dist/{index-e4zt2x70.js → index-3czppvrr.js} +3 -3
- package/dist/{index-42n9jycn.js → index-3f79t32b.js} +3 -3
- package/dist/{index-mfe9a266.js → index-84n49vam.js} +0 -0
- package/dist/{index-f16b7rze.js → index-er1tp8de.js} +3 -3
- package/dist/{index-k137ezb6.js → index-f5d0fdcf.js} +3 -3
- package/dist/{index-65p8v81y.js → index-psz8qrz0.js} +3 -3
- package/dist/{index-kadgaw1s.js → index-r8cq86h1.js} +0 -0
- package/dist/{index-1yky29qg.js → index-tyyvbarf.js} +0 -0
- package/dist/{index-tjakdpf2.js → index-wq71v08n.js} +3 -3
- package/dist/{index-7an2fs5h.js → index-wswcpbm4.js} +3 -3
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# stitchkit/server — stitchkit docs slice, part 6 of 6
|
|
2
|
+
|
|
3
|
+
> Generated from the `docs/` tree by `bun run gen:llms`. The index of all slices is
|
|
4
|
+
> `llms.txt` in this package.
|
|
5
|
+
|
|
6
|
+
Parts of this slice:
|
|
7
|
+
- `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
|
|
8
|
+
- `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md)
|
|
9
|
+
- `llms/server.3.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
|
|
10
|
+
- `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md)
|
|
11
|
+
- `llms/server.5.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
|
|
12
|
+
- `llms/server.6.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
|
|
13
|
+
|
|
14
|
+
Also read:
|
|
15
|
+
- see `llms/testing.txt` for the Testing & deployment guide
|
|
16
|
+
|
|
17
|
+
==============================================================================
|
|
18
|
+
# API reference: `stitchkit/server` (docs/api/reference.md)
|
|
19
|
+
==============================================================================
|
|
20
|
+
|
|
21
|
+
## `stitchkit/server`
|
|
22
|
+
|
|
23
|
+
`EndpointHandlerContext` is the server endpoint handler’s inferred params, input, files and runtime context.
|
|
24
|
+
|
|
25
|
+
Server-only. Builds and runs the HTTP server, and carries the server primitives.
|
|
26
|
+
Also re-exports the error helpers from `stitchkit/contract`.
|
|
27
|
+
|
|
28
|
+
### Server & handlers
|
|
29
|
+
|
|
30
|
+
| Export | Kind | Summary |
|
|
31
|
+
|--------|------|---------|
|
|
32
|
+
| `createServer` | function | build the router and start `Bun.serve` — [guide](../guide/server.md#createserver) |
|
|
33
|
+
| `createHandler` | function | the router as a bare `(req) => Response` — [guide](../guide/server.md#createserver) |
|
|
34
|
+
| `createLocalHostGuard` / `LocalHostGuard` / `LocalHostGuardConfig` / `LocalHostRefusal` | function / _types_ | a host that serves only its own machine's windows: loopback `Host`, allowed `Origin`, a constant-time Bearer secret — as `hooks.onRequest` and as Socket.IO `allowRequest` and `handshake`, with `cors` for the same origins (`undefined` when `origins` is empty for native-only hosts) — [guide](../guide/server.md#a-host-beside-its-own-window) |
|
|
35
|
+
| `createLocalHostClients` / `DEFAULT_LOCAL_HOST_CLIENT_ID_HEADER` / `HostClient` / `LocalHostClientData` / `LocalHostClients` / `LocalHostClientsConfig` / `LocalHostClientsSetup` | function / const / _types_ | per-window identity (`labelSchema` + `guard` handshake), targeted `sendTo(client, ...)`, HTTP `callerFromRequest(req)`, `clients()`, `onClientGone` / `onLastClientGone`, and CORS header extension for multi-window local hosts — [guide](../guide/server.md#tracking-multiple-windows-createlocalhostclients) |
|
|
36
|
+
| `extractReportedClient` / `ReportedClient` / `ReportedClientField` / `ReportedClientOptions` | function / _types_ | extract sanitized caller-supplied attribution headers tagged `verified: false` for local control sockets — [ADR 0346](../decisions/0346-local-control-socket-trust-model-and-consent-key-issuance.md), [ADR 0347](../decisions/0347-unix-socket-peer-credentials-boundary.md) |
|
|
37
|
+
| `createLocalControlJournal` / `LocalControlJournal` / `LocalControlJournalConfig` / `LocalControlJournalEntry` / `LocalControlJournalEntrySchema` | function / _types_ / schema | append-only `0600` metadata-only JSONL call journal with serialized `.1` rotation and bounded `maxPendingWrites` backpressure queue for local control sockets |
|
|
38
|
+
| `createLocalControlGuard` / `LocalControlGuard` / `LocalControlGuardConfig` | function / _types_ | wrap local control socket `fetch` with `maxHeaderBytes` (`431 HEADERS_TOO_LARGE`), explicit `Content-Length` / `maxBodyBytes` (`413 REQUEST_TOO_LARGE` / `400 BAD_REQUEST`), `maxConcurrentRequests` (`503 CONTROL_API_BUSY` holding slots for live streams), and journal recording |
|
|
39
|
+
| `createLocalConsentKeyIssuance` / `LocalConsentAuthorization` / `LocalConsentDecision` / `LocalConsentKeyConfig` / `LocalConsentKeyIssuance` / `LocalConsentKeyRequest` / `LocalConsentKeyRequestSchema` / `LocalConsentQuestion` | function / _types_ / schema | fail-closed native-consent program key issuance route (`ROLE_NOT_ALLOWED`, `KEYS_MANAGE_REQUIRED`, `INIT_DENIED`, `INIT_TIMEOUT` non-retryable, `CONSENT_PENDING`, `no-store`) plus `guardWhileConsentPending` |
|
|
40
|
+
| `implement` | function | bind a contract to typed handlers — [guide](../guide/server.md#implement) |
|
|
41
|
+
| `withContractIdentity` | function | the given services plus the one answering `contractIdentityContract` with their fingerprint — the list to mount — [guide](../guide/client.md#which-contract-does-the-server-speak) |
|
|
42
|
+
| `createImplement` | function | fix the handler context type once |
|
|
43
|
+
| `createScopedImplement` | function | fix one scope→context map, then type every handler by its endpoint's effective scope; `.declare(contract)(handlers)` types without binding for the registry path, `.stream(scope, …)` covers streaming multipart — [guide](../guide/server.md#per-scope-handler-context--createscopedimplement) |
|
|
44
|
+
| `ScopedHandlers` | _type_ | handler map typed per endpoint by its effective scope |
|
|
45
|
+
| `ScopeContexts` | _type_ | scope → extra context fields map accepted by `createScopedImplement` |
|
|
46
|
+
| `EffectiveScope` | _type_ | an endpoint's own `scope`, else its contract's group scope |
|
|
47
|
+
| `createScopedImplementRegistry` | function | the registry form of `createScopedImplement` — one contract registry, handlers still typed per endpoint scope |
|
|
48
|
+
| `ScopedRegistryHandlers` | _type_ | scoped handler registry inferred from a contract registry |
|
|
49
|
+
| `ScopedImplementationRegistry` | _type_ | contract registry whose every group scope is a key of the scope map |
|
|
50
|
+
| `StreamScope` | _type_ | the scope `createScopedImplement(...).stream` accepts for one endpoint |
|
|
51
|
+
| `ExactScopedRegistryHandlers` | _type_ | fail-first scoped registry shape that rejects extra registry and endpoint keys |
|
|
52
|
+
| `implementRegistry` | function | bind one exact contract registry to one exact backend handler registry |
|
|
53
|
+
| `createImplementRegistry` | function | context-typed factory for `implementRegistry` |
|
|
54
|
+
| `ImplementationRegistry` | _type_ | flat literal registry of concrete contracts accepted by `implementRegistry` |
|
|
55
|
+
| `ImplementOptions` | _type_ | `{ onMissingHandler }` — how a binding treats a contract endpoint with no handler |
|
|
56
|
+
| `MissingHandlerPolicy` | _type_ | `'throw'` (default) or `'stub'`, the dev-stand policy that mounts a `501` instead of refusing to start |
|
|
57
|
+
| `KeyedServices` | _type_ | registry result: the mount-ordered `ServiceDef[]` carrying the same services under `.byKey` |
|
|
58
|
+
| `RegistryHandlers` | _type_ | exact backend handler registry inferred from a contract registry |
|
|
59
|
+
| `ExactRegistryHandlers` | _type_ | fail-first handler shape that rejects extra registry and endpoint keys |
|
|
60
|
+
| `staticRoute` | function | a raw route that serves a contained directory through `serveFile` (`Range` / `304` / validators) |
|
|
61
|
+
| `StaticRouteOptions` | _type_ | `{ cacheControl, allowedDotNames }` — what `staticRoute` adds to every file it serves, and which dot-segment names it serves (none by default) |
|
|
62
|
+
| `serveFile` | function | serve a file with `Range` / `304` / `HEAD` — [guide](../guide/server.md#serving-files--range-requests) |
|
|
63
|
+
| `parseByteRange` | function | parse a single `Range` header → range / `unsatisfiable` / `null` |
|
|
64
|
+
| `isWithinDir` | function | path containment — `(root, resolvedTarget) => boolean`; call it before `serveFile` on any URL-derived path |
|
|
65
|
+
| `weakETag` | function | a weak `ETag` from size + mtime |
|
|
66
|
+
| `ServeFileOptions` | _type_ | options for `serveFile` |
|
|
67
|
+
| `ByteRange` | _type_ | an inclusive `{ start, end }` byte range |
|
|
68
|
+
| `respondJson` | function | a raw route's JSON response (`204` for null/undefined) |
|
|
69
|
+
| `errorResponse` | function | any thrown value → the framework error envelope + `x-request-id` |
|
|
70
|
+
| `normalizeError` | function | any thrown value → an `AppError` (an `AppError` as is — contract input failures arrive as `VALIDATION_ERROR` 400 with structured `details.issues`; anything else, a `ZodError` from handler code included, generic 500) — the framework's canonical classification, for a bespoke `onError` |
|
|
71
|
+
| `NormalizeErrorOptions` | _type_ | `logUnexpected` defaults to logging the raw server-side cause; tool adapters disable process dumps while their existing observers retain that cause |
|
|
72
|
+
| `errorCode` | function | the stable error code for a thrown value (side-effect-free — for log attribution) |
|
|
73
|
+
| `formatZodError` | function | a `ZodError` → a readable, field-summarised string |
|
|
74
|
+
| `zodIssues` | function | a `ZodError` → structured `{ path, code, message }[]` — the machine-readable sibling of `formatZodError` |
|
|
75
|
+
| `ZodIssueSummary` | _type_ | one structured validation issue (`{ path, code, message }`) |
|
|
76
|
+
| `parseBody` | function | parse + Zod-validate a JSON body → `data` or `null` (no throw); reads at most `options.maxBytes` (1 MiB by default) and is `null` for a larger body |
|
|
77
|
+
| `HandlerConfig` | _type_ | config for `createHandler`, including optional `maxJsonBodyBytes`; bound to `BunServer` on this entrypoint |
|
|
78
|
+
| `BunServerConfig` | _type_ | config for `createServer` (Bun); `unix` listens on a unix domain socket (mutually exclusive with `port`/`hostname`) — [details](../guide/server.md#local-daemon-over-a-unix-socket) |
|
|
79
|
+
| `defineRequestIngress` / `RequestIngress` / `RequestIngressSource` | function / _type_ | a typed key the code that builds a `Request` attaches a value to (`attach(request, value)`) and an endpoint, `authorize`, `beforeHandle` or `onError` reads from its `ctx` (`from(ctx)`); a header, `clone()` and `new Request(request)` carry nothing, a second `attach` is refused, and `ctx.req` is the very request the handler received — [guide](../guide/server.md#request-attributes-from-the-ingress) |
|
|
80
|
+
| `ProxyOriginConfig` | _type_ | explicit real-peer trust for Bun `createServer({ proxyOrigin })`; strict external-scheme normalization before composition — [details](../guide/server.md#external-origin-behind-a-trusted-proxy) |
|
|
81
|
+
| `UnixListenConfig` | _type_ | unix listener — a socket path bound under the process umask, or `{ path, mode }` for a socket born with exactly `mode` (`bindUnixSocket`) |
|
|
82
|
+
| `BunServerHandle` | _type_ | managed Bun handle (`url`, `port`, `runtime`, `status`, `shutdown`) |
|
|
83
|
+
| `ManagedServerHandle` | _type_ | shared lifecycle shape generic over the runtime escape hatch |
|
|
84
|
+
| `ShutdownOptionsSchema` / `ShutdownOptions` | schema / _type_ | HTTP/application grace, a separate WebSocket close-handshake bound, bounded forced-completion timeout, retry hint and optional external abort signal |
|
|
85
|
+
| `ShutdownStatusSchema` / `ShutdownStatus` | schema / _type_ | live state and request/WebSocket counters; owned streams remain pending through source cleanup |
|
|
86
|
+
| `ShutdownResultSchema` / `ShutdownResult` | schema / _type_ | clean/forced result with final counters, outer-force snapshots and `forcedWebSockets` including bounded realtime terminations |
|
|
87
|
+
| `ShutdownStateSchema` / `ShutdownState` | schema / _type_ | managed lifecycle state machine |
|
|
88
|
+
| `ServiceDef` | _type_ | the result of `implement` |
|
|
89
|
+
| `MethodDef` | _type_ | one resolved endpoint inside a service |
|
|
90
|
+
| `OperationIdentity` | _type_ | path-free service/action/scope/method/optional `effect?` identity shared by contract and native tool operations; repeatable-read derivation (`readOnlyHint` and CLI view withholding) follows explicit `annotations.readOnlyHint` → `effect: 'write'` (non-read) → `effect: 'read'` (read unless `destructiveHint: true`) → `GET` fallback (unless `destructiveHint: true`) |
|
|
91
|
+
| `Handlers` | _type_ | the typed handler map `implement` expects |
|
|
92
|
+
| `LifecycleHooks` | _type_ | `onRequest` / pre-body `authorize` / `beforeHandle` / `afterHandle` / `onError` |
|
|
93
|
+
| `composeLifecycleHooks` | function | compose HTTP lifecycle phases in declaration order with short-circuit/fallthrough semantics |
|
|
94
|
+
| `AuthorizationContext` | _type_ | HTTP pre-body context with validated params, `input: undefined` and no files |
|
|
95
|
+
| `RouteGroup` | _type_ | a prefixed group of services with its own hooks; matched errors try group `onError` → global `onError` → standard envelope, keeping the original error on fallback — [precedence](../guide/server.md#lifecycle-hooks) |
|
|
96
|
+
| `RawRoute` | _type_ | a non-contract `Request → Response` route with a concrete `BunServer` context and optional stable `serviceName` / `action` observability identity |
|
|
97
|
+
| `RawRouteContext` | _type_ | the Bun-bound routing context a raw handler receives |
|
|
98
|
+
| `BunServer` | _type_ | the `Bun.serve` instance type |
|
|
99
|
+
| `ServerPassthrough` | _type_ | extra `Bun.serve` options |
|
|
100
|
+
| `StitchLogger` | _type_ | the custom-logger interface |
|
|
101
|
+
| `LoggingConfig` | _type_ | the `logging` object — `logger` / `format` / `skip` / `enrich` |
|
|
102
|
+
| `LogFormat` | _type_ | `'pretty'` or `'json'` — what the built-in formatter writes |
|
|
103
|
+
| `LogOutcome` | _type_ | how a request finished, as `enrich` sees it |
|
|
104
|
+
| `FetchHandler` | _type_ | what `createHandler` returns, bound to `BunServer` here |
|
|
105
|
+
| `FetchComposition` | _type_ | the Bun-bound `wrapFetch` seam |
|
|
106
|
+
|
|
107
|
+
### Auth
|
|
108
|
+
|
|
109
|
+
| Export | Kind | Summary |
|
|
110
|
+
|--------|------|---------|
|
|
111
|
+
| `createAuthHook` | function | one scope gate for HTTP `authorize` and tool `beforeHandle` — [guide](../guide/auth-and-errors.md#createauthhook) |
|
|
112
|
+
| `composeAuthHooks` | function | route multiple canonical auth domains by owned scope and atomically commit their typed contributions |
|
|
113
|
+
| `createErrorHook` | function | an async-capable, endpoint-aware `onError` hook from a `defineErrors` vocabulary or a code map, plus an envelope renderer — [guide](../guide/auth-and-errors.md#createerrorhook) |
|
|
114
|
+
| `ErrorHookBase` / `ErrorCodeMapping` | _type_ | common hook fields and the transport-neutral vocabulary-or-map branch accepted by `createErrorHook` |
|
|
115
|
+
| `ErrorHookConfig` | _type_ | async observer/renderer config with partial `codeMap` and optional typed `unmappedCode` fallback |
|
|
116
|
+
| `ResolvedError` | _type_ | the normalised error handed to `createErrorHook`'s `render` |
|
|
117
|
+
| `createBearerResolver` | function | a bearer-token identity resolver |
|
|
118
|
+
| `signJwt` | function | sign an HS256 JWT |
|
|
119
|
+
| `VerifyJwtOptions` | _type_ | options for `verifyJwt` — `leewaySeconds`, `issuer`, `audience`, `expiration` (`'required'` by default) |
|
|
120
|
+
| `verifyJwt` | function | verify an HS256 JWT |
|
|
121
|
+
| `signLink` / `SignLinkOptions` | function / _type_ | a short-lived link for a request that cannot carry a header (`<audio src>`, `<img src>`): appends `expires` and an HMAC-SHA-256 `signature` over the method, path and every query parameter — [guide](../guide/auth-and-errors.md#signed-links) |
|
|
122
|
+
| `verifySignedLink` / `VerifySignedLinkOptions` | function / _type_ | check a request against its link (signature compared with a constant-time comparison, then expiry); call it from `createAuthHook`'s `resolve` or a raw route |
|
|
123
|
+
| `SignedLinkVerdict` / `SignedLinkRefusal` | _types_ | `{ ok: true, expiresAt }` or `{ ok: false, reason }` with `unsigned`, `malformed`, `expired` or `forged` |
|
|
124
|
+
| `MAX_SIGNED_LINK_SECONDS` | constant | the longest lifetime `signLink` accepts: seven days |
|
|
125
|
+
| `extractToken` | function | read a bearer token from header or cookie |
|
|
126
|
+
| `deriveCodeChallenge` | function | PKCE — derive the `code_challenge` from a verifier |
|
|
127
|
+
| `verifyPkce` | function | PKCE — verify a verifier against a stored challenge |
|
|
128
|
+
| `AuthHook` | _type_ | the hook `createAuthHook` returns |
|
|
129
|
+
| `AuthHookConfig` | _type_ | config for `createAuthHook` |
|
|
130
|
+
| `AuthRule` | _type_ | `'public' \| 'authenticated' \| predicate` |
|
|
131
|
+
| `AuthRuleContribution` | _type_ | plain context fields a sync/async rule may contribute after authorizing |
|
|
132
|
+
| `ScopedAuthRule` | _type_ | a rule plus its typed context contribution — `{ rule, inject? }` |
|
|
133
|
+
| `AuthRules` | _type_ | the `rules` map: bare rules or scoped rules |
|
|
134
|
+
| `RuleScopes` | _type_ | scope→context map derived from a `rules` object; `'public'` fields become optional |
|
|
135
|
+
| `ScopedAuthHook` | _type_ | an auth hook carrying its derived scope map at the type level |
|
|
136
|
+
| `AuthScopes` | _type_ | recover the derived map — `createScopedImplement<AuthScopes<typeof hook>>()` |
|
|
137
|
+
| `ComposeAuthHooksConfig` | _type_ | ordered canonical hooks plus the optional explicit composite default scope |
|
|
138
|
+
| `ComposedAuthScopes` | _type_ | scope→context map derived from every owner in a composed auth hook |
|
|
139
|
+
| `BearerResolverConfig` | _type_ | config for `createBearerResolver` |
|
|
140
|
+
| `JwtPayload` | _type_ | a decoded JWT payload |
|
|
141
|
+
| `SignJwtOptions` | _type_ | options for `signJwt` (expiry, claims) |
|
|
142
|
+
| `PkceMethod` | _type_ | the PKCE challenge method — `'S256' \| 'plain'` |
|
|
143
|
+
|
|
144
|
+
### Cookies & CORS
|
|
145
|
+
|
|
146
|
+
| Export | Kind | Summary |
|
|
147
|
+
|--------|------|---------|
|
|
148
|
+
| `defineCookie` | function | a typed cookie `get` / `getAll` / `set` / `clear` handle; `duplicates` names what `get` answers when two cookies share the name — [guide](../guide/auth-and-errors.md#cookies) |
|
|
149
|
+
| `parseCookies` | function | parse a `Cookie` header to a record (the last of two same-named cookies wins) |
|
|
150
|
+
| `parseCookieHeader` | function | parse a `Cookie` header to `[name, value]` pairs in header order, duplicates kept |
|
|
151
|
+
| `serializeCookie` | function | build a `Set-Cookie` value |
|
|
152
|
+
| `corsHeaders` | function | compute CORS response headers |
|
|
153
|
+
| `corsPreflightResponse` | function | build a preflight `Response` |
|
|
154
|
+
| `DEFAULT_CORS_ALLOW_HEADERS` | const | the default `Access-Control-Allow-Headers` (incl. `traceparent`) — extend it when overriding `cors.headers` |
|
|
155
|
+
| `DEFAULT_CORS_EXPOSE_HEADERS` | const | the default `Access-Control-Expose-Headers` (incl. `Content-Disposition`, `ETag`, `Content-Range`, `X-Build-Id`) — extend it when overriding `cors.exposeHeaders`, or a cross-origin page loses the build id |
|
|
156
|
+
| `CookieDef` | _type_ | the `defineCookie` handle |
|
|
157
|
+
| `CookieOptions` | _type_ | cookie attributes, plus the `duplicates` read policy |
|
|
158
|
+
| `CookieDuplicatesPolicy` | _type_ | `'last'` (default) / `'first'` / `'reject'` — `reject` yields `undefined` for two different values and the value when they agree |
|
|
159
|
+
| `CorsConfig` | _type_ | static CORS policy: origin (or list, or `'*'`) and one `credentials` flag |
|
|
160
|
+
| `CorsOriginPolicy` | _type_ | CORS decided per request: `origin(origin)` answers each exact serialized origin, sync or async; no `credentials` beside it. Decided once per request for every exit, always `Vary: Origin`, a throw or malformed answer grants nothing and runs nothing; a safelisted `text/plain` body needs a grant with credentials |
|
|
161
|
+
| `CorsOriginDecision` | _type_ | what the policy answers: `false` or `{ credentials: boolean }` |
|
|
162
|
+
|
|
163
|
+
### Realtime (server)
|
|
164
|
+
|
|
165
|
+
| `bindSocketRegistry` | function | room membership and consistent replay over an already-authenticated realtime server |
|
|
166
|
+
| `AuthorizedSocketRoom` / `SocketRegistry` / `SocketRegistryConnection` / `SocketRegistryOptions` / `SocketRegistryServer` / `SocketRegistrySnapshot` / `SocketReplayFrame` | _type_ | authorized room token, structural server boundary, replay frames and immutable registry state |
|
|
167
|
+
| `bindDevicePresence` | function | mounts account-scoped online device presence, ephemeral capability state slots and targeted remote commands onto an existing `RealtimeServerHandle` |
|
|
168
|
+
| `DevicePresenceServer` / `DevicePresenceServerOptions` / `DevicePresenceServerSnapshot` / `DevicePresenceAccountResolver` | _type_ | mounted server registry handle, `accountOf` authorization callback and diagnostic snapshot for `bindDevicePresence` |
|
|
169
|
+
| Export | Kind | Summary |
|
|
170
|
+
|--------|------|---------|
|
|
171
|
+
| `createSocketIOServer` | function | the typed Socket.IO server — [guide](../guide/realtime.md#server--createsocketioserver) |
|
|
172
|
+
| `bindRealtimeServer` | function | inferred, runtime-validated connection and broadcast boundary |
|
|
173
|
+
| `RealtimeServer` | _type_ | validated broadcast and connection API inferred from a realtime contract |
|
|
174
|
+
| `RealtimeServerConnection` | _type_ | one validated connection with raw socket access for auth and rooms |
|
|
175
|
+
| `RealtimeServerHandle` | _type_ | minimal Socket.IO server handle accepted by `bindRealtimeServer`; carries the handshake identity type through to `connection.raw.data` |
|
|
176
|
+
| `SocketIORequestPolicy` | _type_ | runtime-neutral async-capable Web `Request` handshake admission policy |
|
|
177
|
+
| `SocketIOServerConfig` | _type_ | config for `createSocketIOServer`; `handshake` is the typed identity gate — [guide](../guide/realtime.md#handshake-auth--cookie-or-token) |
|
|
178
|
+
| `SocketIOPeerLoaders` | _type_ | `peers: { server, bunEngine }` — literal dynamic imports written in YOUR source, so a bundler puts the optional peers inside a self-contained artifact. Omit for the lazy default |
|
|
179
|
+
| `SocketIOHandshakeConfig` | _type_ | the `handshake` gate — Zod `schema` over `handshake.auth` plus optional async `verify`; the result lands typed in `socket.data` |
|
|
180
|
+
| `SocketIOServerHandle` | _type_ | typed Socket.IO server plus Bun mount fields and idempotent lifecycle |
|
|
181
|
+
| `SocketIOServerLifecycle` | _type_ | non-generic Bun mount/shutdown portion accepted by `createServer` |
|
|
182
|
+
| `composeWebSocketHandlers` | function | compose one Bun `websocket` from N lanes — a raw binary lane beside Socket.IO ([guide](../guide/realtime.md#raw-binary-lane-bun)) |
|
|
183
|
+
| `webSocketLane` | function | a typed, cast-free lane for `composeWebSocketHandlers` |
|
|
184
|
+
| `socketIoLane` | function | the Socket.IO catch-all lane for `composeWebSocketHandlers` |
|
|
185
|
+
| `ComposedLane` | _type_ | a lane bridged to the loose data type |
|
|
186
|
+
| `WebSocketLane` | _type_ | a typed lane (`{ match, handlers }`) |
|
|
187
|
+
| `WebSocketComposeConfig` | _type_ | server-wide tuning for the composed handler |
|
|
188
|
+
|
|
189
|
+
### Primitives
|
|
190
|
+
|
|
191
|
+
| `createFileStateStore` | function | cross-process locked atomic JSON state updates over one Zod schema |
|
|
192
|
+
| `FileStateStoreCorruption` / `FileStateStoreOptions` | _type_ | explicit corrupt-state report/policy, lock timing and the state read cap `maxBytes`; a transition whose resulting state encodes to the bytes it started from writes nothing |
|
|
193
|
+
| Export | Kind | Summary |
|
|
194
|
+
|--------|------|---------|
|
|
195
|
+
| `streamSSE` | function | an async generator → SSE `Response` — [guide](../guide/server.md#sse-streaming) |
|
|
196
|
+
| `streamingRoute` | function | a long-lived subscription route: idle timeout, heartbeat, opening flush, cancellation — [guide](../guide/server.md#long-lived-subscriptions) |
|
|
197
|
+
| `ndjsonRoute` | function | `streamingRoute` framed as NDJSON |
|
|
198
|
+
| `sseRoute` | function | `streamingRoute` framed as SSE |
|
|
199
|
+
| `DEFAULT_STREAM_HEARTBEAT_MS` | const | 5000 — deliberately well under Bun's ten-second idle threshold |
|
|
200
|
+
| `MultipartLifecycle` | _type_ | request-scoped rollback ownership for accepted streamed handles |
|
|
201
|
+
| `MultipartResult` | _type_ | what `parseMultipart` returns |
|
|
202
|
+
| `parseMultipart` | function | parse a typed buffered/streaming multipart descriptor — [guide](../guide/server.md#multipart) |
|
|
203
|
+
| `defineMultipartStream` | function | bind typed streaming file receivers and a final endpoint handler |
|
|
204
|
+
| `createMultipartStream` | function | fix one handler context type for streaming multipart endpoints |
|
|
205
|
+
| `MultipartStreamConfig` | _type_ | receivers plus the context-typed handler accepted by the streaming builders |
|
|
206
|
+
| `MultipartFileMetadata` | _type_ | field, filename, declared media type and optional declared size |
|
|
207
|
+
| `MultipartReceiver` | _type_ | consumer-owned Web-stream storage receiver |
|
|
208
|
+
| `MultipartReceiverResult` | _type_ | receiver value plus rollback cleanup |
|
|
209
|
+
| `StreamingMultipartImplementation` | _type_ | receiver registry and handler shape inferred by `defineMultipartStream` |
|
|
210
|
+
| `bindReleaseRefreshSignal` / `ReleaseRefreshSignalOptions` / `ReleaseRefreshSignal` | function / _type_ | a deploy signal (`SIGUSR2`, the one user-defined signal the process vocabulary has) refreshes a `stitchkit/release` marker, whose subscribers tell every socket; never throws at the signal — [guide](../guide/release.md) |
|
|
211
|
+
| `bindProcessSignals` | function | bind `SIGINT` / `SIGTERM` to one managed `shutdown()` — one chain, force on a later signal, default disposition on the one after — [guide](../guide/testing-and-deployment.md#process-signals--bindprocesssignals) |
|
|
212
|
+
| `ProcessSignalsOptions` | _type_ | config for `bindProcessSignals` |
|
|
213
|
+
| `ProcessSignalsBinding` | _type_ | the `{ promise, close }` handle `bindProcessSignals` returns |
|
|
214
|
+
| `ProcessSignalsErrorPhase` | _type_ | `'prepare' \| 'shutdown' \| 'complete'` — which phase an `onError` report came from |
|
|
215
|
+
| `SignalSource` | _type_ | injectable signal source — `process` by default |
|
|
216
|
+
| `ProcessSignalName` | _type_ | signal names the binding accepts (owned, so the published types need no `@types/node`) |
|
|
217
|
+
| `ShutdownTarget` | _type_ | the `shutdown`-only slice a binding needs — an interface, so a [composite target](../guide/testing-and-deployment.md#composite-shutdown-target--parallel-domain-drains) can drain several domains under one signal machine |
|
|
218
|
+
| `createRateLimiter` | function | token-bucket rate limiting — [guide](../guide/server.md#rate-limiting) |
|
|
219
|
+
| `createCache` | function | an in-memory TTL cache |
|
|
220
|
+
| `CacheOptions` | _type_ | bounded-cache options, including the maximum retained entry count |
|
|
221
|
+
| `cacheHeaders` | function | build a `Cache-Control` header |
|
|
222
|
+
| `EventBusOptions` | _type_ | options for `createEventBus` |
|
|
223
|
+
| `EventHandler` | _type_ | one event-bus subscriber |
|
|
224
|
+
| `DefaultEventMap` | _type_ | the default event map — `Record<string, unknown>` |
|
|
225
|
+
| `createEventBus` | function | typed in-process pub/sub — [guide](../guide/server.md#event-bus) |
|
|
226
|
+
| `generateTraceId` | function | a fresh trace id |
|
|
227
|
+
| `resolveTraceId` | function | the default per-request trace-id resolver |
|
|
228
|
+
| `extractIp` | function | the caller IP from a request |
|
|
229
|
+
| `isPublicIp` | function | whether an address belongs to the public internet; anything unparseable is not |
|
|
230
|
+
| `resolveSocketIp` | function | the real socket peer IP from the runtime (`server.requestIP` on Bun, `req.ip` under `srvx`); headers are not read |
|
|
231
|
+
| `getClientInfo` | function | caller IP + user-agent |
|
|
232
|
+
| `EventBus` | _type_ | the `createEventBus` handle |
|
|
233
|
+
| `RateLimitConfig` | _type_ | config for `createRateLimiter` |
|
|
234
|
+
| `ClientIpOptions` | _type_ | socket peer and trusted-proxy config for `extractIp` / `getClientInfo` |
|
|
235
|
+
| `StreamingRouteOptions` | _type_ | options for `streamingRoute` / `ndjsonRoute` / `sseRoute` |
|
|
236
|
+
| `StreamingSourceContext` | _type_ | what a streaming source is given, including the cancellation `signal` |
|
|
237
|
+
| `StreamingFormat` | _type_ | `'ndjson' \| 'sse'` |
|
|
238
|
+
| `createUnixClientTransport` | function | owned Fetch-compatible Unix-socket transport on Bun and Node; enforces parent-directory, symlink, non-group/world-writable, and owner-UID (`expectedOwnerUid`, defaulting to current EUID) checks on every dispatch and redirect — [guide](../guide/client.md#unix-domain-sockets) |
|
|
239
|
+
| `UnixClientTransportConfig` | _type_ | absolute socket path, optional `expectedOwnerUid` for cross-UID group-accessible local daemons, request/header/connection/redirect bounds, and an explicit bounded-or-streaming response policy |
|
|
240
|
+
| `UnixClientTransport` | _type_ | `{ fetch, closed, close() }`; `close()` settles owned active work |
|
|
241
|
+
| `UnixResponseBodyMode` | _type_ | `bounded \| streaming`; bounded is the 16 MiB cumulative default, streaming keeps pull-driven buffering without a lifetime total |
|
|
242
|
+
| `UnixClientTransportError` | class | stable transport failure with `code` and dispatch certainty in `delivery` |
|
|
243
|
+
| `UnixClientTransportErrorCode` | _type_ | finite Unix transport failure-code union |
|
|
244
|
+
| `UnixClientDeliveryState` | _type_ | `not-dispatched \| possibly-dispatched \| response-received`; input to application retry policy, never an implicit retry |
|
|
245
|
+
|
|
246
|
+
### OpenAPI
|
|
247
|
+
|
|
248
|
+
| Export | Kind | Summary |
|
|
249
|
+
|--------|------|---------|
|
|
250
|
+
| `generateOpenApiDocument` | function | an OpenAPI 3.1 document from contract services — [ADR 0018](../decisions/0018-openapi-generation.md) |
|
|
251
|
+
| `openApiRoute` | function | a `RawRoute` that serves the document as JSON |
|
|
252
|
+
| `OpenApiConfig` | _type_ | config for `generateOpenApiDocument` (incl. `includeMethod` — curate a public subset) — [guide](../guide/server.md#curating-the-spec--includemethod) |
|
|
253
|
+
| `OpenApiDocument` | _type_ | the generated document |
|
|
254
|
+
| `OpenApiInfo` | _type_ | the spec `info` block |
|
|
255
|
+
| `OpenApiSecurity` | _type_ | `OpenApiConfig.security` — named schemes and the schemes each protected scope accepts — [guide](../guide/server.md#security-schemes--security) |
|
|
256
|
+
| `OpenApiSecurityScheme` | _type_ | one way a caller presents its credential: HTTP bearer or basic, or an API key in a header, query or cookie |
|
|
257
|
+
| `OpenApiServer` | _type_ | a spec `servers` entry |
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### Trust fence
|
|
262
|
+
|
|
263
|
+
Refuses a request whose `Host` is not a declared authority, at both admission points — the socket
|
|
264
|
+
lane never reaches the hooks on either runtime.
|
|
265
|
+
→ [ADR 0151](../decisions/0151-a-trust-fence-names-its-lanes-because-one-of-them-bypasses-hooks.md).
|
|
266
|
+
|
|
267
|
+
| Export | Kind | Summary |
|
|
268
|
+
|--------|------|---------|
|
|
269
|
+
| `createTrustFence` | function | `hooks` for the HTTP lane and `allowRequest` for the Socket.IO lane; a bare 403 that never says which rule refused |
|
|
270
|
+
| `isLoopbackAddress` | function | whether an address is this machine — for the auth rule a privileged operation belongs in, not for the fence |
|
|
271
|
+
| `TrustFence` / `TrustFenceConfig` / `TrustRefusal` / `TrustRefusalReason` / `TrustLane` | _types_ | the two admission points, the declared authorities (`trustedHosts`, `trustedOrigins`, and optional HTTP `GET`/`HEAD`-only `publicReads`), and why and where a request was refused |
|
|
272
|
+
| `RouteGroupHooks` | _type_ | a route group's hooks — `LifecycleHooks` without `onRequest`, which runs before the group is known |
|
|
273
|
+
|
|
274
|
+
---
|
package/llms/server.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# stitchkit/server — stitchkit docs slice, part 1 of
|
|
1
|
+
# stitchkit/server — stitchkit docs slice, part 1 of 6
|
|
2
2
|
|
|
3
3
|
> Generated from the `docs/` tree by `bun run gen:llms`. The index of all slices is
|
|
4
4
|
> `llms.txt` in this package.
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
Parts of this slice:
|
|
8
8
|
- `llms/server.txt`: Guide: HTTP server (docs/guide/server.md)
|
|
9
|
-
- `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md)
|
|
10
|
-
- `llms/server.3.txt`: Guide: Realtime (docs/guide/realtime.md)
|
|
11
|
-
- `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md)
|
|
12
|
-
- `llms/server.5.txt`:
|
|
9
|
+
- `llms/server.2.txt`: Guide: HTTP server (docs/guide/server.md)
|
|
10
|
+
- `llms/server.3.txt`: Guide: HTTP server (docs/guide/server.md) · Guide: Realtime (docs/guide/realtime.md)
|
|
11
|
+
- `llms/server.4.txt`: Guide: Realtime (docs/guide/realtime.md)
|
|
12
|
+
- `llms/server.5.txt`: Guide: Auth & errors (docs/guide/auth-and-errors.md) · Guide: Multi-tenant (docs/guide/multi-tenant.md)
|
|
13
|
+
- `llms/server.6.txt`: API reference: `stitchkit/server` (docs/api/reference.md)
|
|
13
14
|
|
|
14
15
|
Also read:
|
|
15
16
|
- see `llms/testing.txt` for the Testing & deployment guide
|
|
@@ -329,6 +330,32 @@ The registry is intentionally flat: every key must point to one concrete
|
|
|
329
330
|
`defineContract()` result. Composed namespace arrays are mounted explicitly with
|
|
330
331
|
`implement()` because they do not have a one-key-to-one-handler-map boundary.
|
|
331
332
|
|
|
333
|
+
### Splitting a large service surface by domain family
|
|
334
|
+
|
|
335
|
+
When an application grows past a handful of services, keep `surface.ts` thin by
|
|
336
|
+
assembling each domain family in its own module as a plain function returning
|
|
337
|
+
`readonly ServiceDef[]`:
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
// surface-documents.ts
|
|
341
|
+
export function documentServices(deps: AppDeps): readonly ServiceDef[] {
|
|
342
|
+
return [implement(documentsContract, documentHandlers(deps)), implement(templatesContract, templateHandlers(deps))]
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// surface.ts
|
|
346
|
+
export function appServices(deps: AppDeps): ServiceDef[] {
|
|
347
|
+
return [
|
|
348
|
+
...documentServices(deps),
|
|
349
|
+
...workspaceServices(deps),
|
|
350
|
+
...mediaServices(deps),
|
|
351
|
+
]
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Pair this with `defineEndpoints` and `composeEndpoints` from `stitchkit/contract` when a
|
|
356
|
+
single contract spans multiple files, so parallel changes stay isolated per domain module
|
|
357
|
+
without a single monolithic surface file.
|
|
358
|
+
|
|
332
359
|
## `createServer`
|
|
333
360
|
|
|
334
361
|
`createServer(config)` builds the router and starts `Bun.serve()`. It returns a
|
|
@@ -877,114 +904,3 @@ createServer({
|
|
|
877
904
|
|
|
878
905
|
Hooks see `RuntimeContext` (loose types); handlers see `HandlerContext` (typed).
|
|
879
906
|
That split is deliberate — see [ADR 0003](../decisions/0003-two-context-types.md).
|
|
880
|
-
|
|
881
|
-
## A host beside its own window
|
|
882
|
-
|
|
883
|
-
A desktop app's host — the process beside its window — is an ordinary StitchKit server, bound to
|
|
884
|
-
loopback. Calls are plain HTTP through the typed client; events travel the realtime socket with
|
|
885
|
-
`retain` per topic ([realtime](./realtime.md)). There is no second transport to learn.
|
|
886
|
-
|
|
887
|
-
Binding to `127.0.0.1` keeps other machines out, and nothing more. A web page open in a browser on
|
|
888
|
-
the same machine can still call `http://127.0.0.1:<port>` and open a WebSocket there (a WebSocket
|
|
889
|
-
obeys no CORS), and a DNS-rebinding page reaches it under an attacker's host name.
|
|
890
|
-
`createLocalHostGuard` closes both: a request must name a loopback `Host`, carry an allowed `Origin`
|
|
891
|
-
when it carries one, and present the host's secret. The same rules gate the Socket.IO handshake.
|
|
892
|
-
|
|
893
|
-
```ts
|
|
894
|
-
import { createLocalHostGuard, createServer, createSocketIOServer } from 'stitchkit/server'
|
|
895
|
-
|
|
896
|
-
const secret = crypto.randomUUID() + crypto.randomUUID() // per start; hand it to the window, never in a URL
|
|
897
|
-
const guard = createLocalHostGuard({ secret, origins: ['tauri://localhost'] })
|
|
898
|
-
const socket = await createSocketIOServer({
|
|
899
|
-
allowRequest: guard.allowRequest,
|
|
900
|
-
handshake: guard.handshake,
|
|
901
|
-
cors: guard.cors,
|
|
902
|
-
})
|
|
903
|
-
|
|
904
|
-
createServer({
|
|
905
|
-
hostname: '127.0.0.1',
|
|
906
|
-
port: 0,
|
|
907
|
-
services,
|
|
908
|
-
socket,
|
|
909
|
-
cors: guard.cors,
|
|
910
|
-
hooks: { onRequest: (request) => guard.onRequest(request) },
|
|
911
|
-
})
|
|
912
|
-
```
|
|
913
|
-
|
|
914
|
-
A window in a webview is a cross-origin page: `guard.cors` allows its origins, so the browser's
|
|
915
|
-
preflight — answered before `onRequest` — passes and the window can read every answer. The window
|
|
916
|
-
sends `Authorization: Bearer <secret>` on every call (`headers` on `createClient`) and
|
|
917
|
-
`auth: { secret }` on the socket. A refusal is the framework error envelope: `401` for the secret,
|
|
918
|
-
`403` for a foreign `Host` or `Origin`, before routing, raw routes included. Secrets compare in
|
|
919
|
-
constant time and a shorter or longer guess tells nothing about the real one. `stitchkit/node` exports
|
|
920
|
-
the same guard for `serveNode`.
|
|
921
|
-
|
|
922
|
-
A call in flight when the host restarts never gets an answer. The typed client sends it again only
|
|
923
|
-
when that is safe — see [calls that never got an answer](./client.md#calls-that-never-got-an-answer).
|
|
924
|
-
|
|
925
|
-
### Adding a unix-socket channel for local CLI and agents
|
|
926
|
-
|
|
927
|
-
To expose the same contract handlers to a local CLI or agent without a TCP port or bearer secret,
|
|
928
|
-
start a **second** `createServer` sharing the base configuration (`services`, `scopePrefixes`, audit
|
|
929
|
-
hooks) alongside the guarded loopback TCP server, and coordinate both with one composite
|
|
930
|
-
`ShutdownTarget` passed to `bindProcessSignals`:
|
|
931
|
-
|
|
932
|
-
```ts
|
|
933
|
-
import { bindProcessSignals, createLocalHostGuard, createServer } from 'stitchkit/server'
|
|
934
|
-
|
|
935
|
-
const base = { services, scopePrefixes }
|
|
936
|
-
|
|
937
|
-
const tcp = createServer({
|
|
938
|
-
...base,
|
|
939
|
-
hostname: '127.0.0.1',
|
|
940
|
-
port: 0,
|
|
941
|
-
socket,
|
|
942
|
-
cors: guard.cors,
|
|
943
|
-
hooks: {
|
|
944
|
-
onRequest: (request) => guard.onRequest(request),
|
|
945
|
-
authorize: (ctx, endpoint) => authorizeWindowRequest(ctx, endpoint),
|
|
946
|
-
},
|
|
947
|
-
})
|
|
948
|
-
|
|
949
|
-
// Opt-in: omit this server when the user disables local control.
|
|
950
|
-
const unix = createServer({
|
|
951
|
-
...base,
|
|
952
|
-
unix: { path: socketPath, mode: 0o600 },
|
|
953
|
-
hooks: {
|
|
954
|
-
// Filesystem permissions are the credential; scoped endpoints receive the local owner identity.
|
|
955
|
-
authorize: (ctx) => {
|
|
956
|
-
ctx.user = localSessionOwner
|
|
957
|
-
},
|
|
958
|
-
},
|
|
959
|
-
})
|
|
960
|
-
|
|
961
|
-
bindProcessSignals({
|
|
962
|
-
shutdown: (options) => Promise.all([tcp.shutdown(options), unix.shutdown(options)]),
|
|
963
|
-
})
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
Trust boundary and operational rules for the unix channel:
|
|
967
|
-
|
|
968
|
-
- **The trust boundary is the OS user, not a specific client binary.** Bun does not expose `SO_PEERCRED` /
|
|
969
|
-
`LOCAL_PEERCRED` peer credentials on `Bun.serve` requests, so any process running as the same OS user
|
|
970
|
-
can connect to the socket. Any custom client header (for example `X-Client-Name`, sent via
|
|
971
|
-
`HttpClientConfig.headers`) is **audit metadata only** and can be spoofed by any same-user process.
|
|
972
|
-
The client side (`createUnixClientTransport`) verifies the socket directory and socket owner (`uid`)
|
|
973
|
-
before connecting, guarding against talking to another user's or symlinked socket.
|
|
974
|
-
- **Opt-in by configuration.** No socket file is created unless the application explicitly configures
|
|
975
|
-
`createServer({ unix })`.
|
|
976
|
-
- **Narrowing the surface.** Passing the same `services` array gives local CLI and agents everything
|
|
977
|
-
the window can do. If sensitive operations (such as payments or destructive deletes) must stay
|
|
978
|
-
window-only, pass a narrowed `services` subset to the unix server instead.
|
|
979
|
-
- **Streaming events over the socket.** Socket.IO does not mount on a unix listener; expose live
|
|
980
|
-
events to local CLI/agent consumers through contract `stream` endpoints (NDJSON/SSE).
|
|
981
|
-
- **Bind order.** Because `bindUnixSocket` adjusts `process.umask` during bind, create the unix
|
|
982
|
-
server before spawning `Worker` threads.
|
|
983
|
-
- **macOS boundaries.** Under macOS App Sandbox, place the socket inside the app's App Group
|
|
984
|
-
container and keep the full UTF-8 path within 103 bytes; TCC permissions remain bound to the host
|
|
985
|
-
process's responsible bundle.
|
|
986
|
-
- **Embedded agents and shell tools.** An unsandboxed agent shell running as the same OS user has full
|
|
987
|
-
access to the socket. Inside StitchKit's Linux Bubblewrap sandbox (`stitchkit/agent-runtime/sandbox`),
|
|
988
|
-
the host's `$HOME`, `/tmp`, `/run` and `XDG_RUNTIME_DIR` are not mounted (`--unshare-all --clearenv`),
|
|
989
|
-
so keep the socket outside the agent's mounted `workspace` directory (note that macOS has no
|
|
990
|
-
Bubblewrap isolation).
|
package/llms/spend.txt
CHANGED
|
@@ -112,12 +112,13 @@ one learned. Ranks: 1 the gateway's transport view, 2 the response's reported
|
|
|
112
112
|
usage, 3 a reconciler's answer.
|
|
113
113
|
|
|
114
114
|
`createSpooledSpendStore({ store, path })` puts every attempt and receipt on disk
|
|
115
|
-
before the database is offered it. With the database down, calls go on
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
before the database is offered it. With the database down, calls go on; when the
|
|
116
|
+
database accepts a later write in the same process, a single-flight background pass
|
|
117
|
+
redelivers pending records in group order (an attempt always before its receipts,
|
|
118
|
+
in the live path too: a receipt whose attempt the database has not taken waits on
|
|
119
|
+
disk with it). Call `await store.flush()` to explicitly redeliver in-process alongside
|
|
120
|
+
live writes, and `await store.recover()` once at startup for what a previous process
|
|
121
|
+
left on disk. Only a record that could be neither spooled nor stored refuses the call.
|
|
121
122
|
|
|
122
123
|
## Afterwards
|
|
123
124
|
|
|
@@ -194,7 +195,7 @@ Peer-free, server-only spend accounting for paid model APIs (→ [guide](../guid
|
|
|
194
195
|
| `SpendGatewayError` | class | `code`: `unknown-provider`, `origin-mismatch`, `no-attribution`, `intent-unrecorded`, `refused` (`admit` said no; recorded as a `refused` attempt) — every one refused before anything was sent |
|
|
195
196
|
| `runWithSpendAttribution` / `getSpendAttribution` | function | the attribution of every gateway call in a call chain (AsyncLocalStorage); nested calls refine, `labels` merge |
|
|
196
197
|
| `openAiCompatibleUsage` / `SpendFactsReader` | const / _type_ | reads `id`, `model` and `usage` (tokens, reasoning, cache, OpenRouter's `cost`) from a JSON body or the stream's events |
|
|
197
|
-
| `createSpooledSpendStore` / `SpooledSpendStore` / `SpooledSpendStoreConfig` | function / _types_ | a ledger that survives its database: on disk first (`0o600`, bounded), delivered after; `recover()` replays in order, an attempt before its receipts — a receipt whose attempt is undelivered waits on disk with it, in the live path too; a record neither spooled nor stored refuses the call; `pendingCosts` and `openAttempts` pass through |
|
|
198
|
+
| `createSpooledSpendStore` / `SpooledSpendStore` / `SpooledSpendStoreConfig` | function / _types_ | a ledger that survives its database: on disk first (`0o600`, bounded), delivered after; `recover()` replays in order, an attempt before its receipts — a receipt whose attempt is undelivered waits on disk with it, in the live path too; once the store accepts a subsequent write, bounded single-flight in-process auto-drain and explicit `flush(): Promise<SpoolRecovery>` redeliver spooled rows in order without restarting; a record neither spooled nor stored refuses the call; `pendingCosts` and `openAttempts` pass through |
|
|
198
199
|
| `mergeSpendReceipt` | function | the monotone merge a ledger applies: a higher rank adds what it knows, equal ranks resolve by `at` (a factual cost breaks exact-timestamp ties), a closed outcome never returns to `pending`, a reported cost is never erased, a non-factual rank-3 reconciler receipt neither pollutes a factual cost with `failureCode`/`failureMessage` nor leaves those fields behind once a factual price arrives (while rank 1–2 transport failure codes stay intact), and an `orphaned` close never replaces a real one (a real one replaces it) |
|
|
199
200
|
| `reconcilePendingSpend` / `SpendReconciler` / `ReconcilePendingSpendOptions` / `SpendReconcileResult` | function / _types_ | one pass over attempts whose cost is `pending`: each gateway's reconciler answers, rank-3 receipts are settled; optional `maxPendingAgeMs` (positive safe integer validated upfront) settles attempts whose reconciler still returns `undefined` at or past that age since `record.receipt.at` (or `record.attempt.startedAt`) as `costStatus: 'unknown'` with `failureCode: 'price-never-reported'` (while reconciler throws and gateways without a reconciler stay `pending`); `onError` sees a reconciler that threw or returned invalid facts, an invalid record timestamp, or a receipt-merge failure (while broken `now()` clocks and `store.settle` failures still reject) |
|
|
200
201
|
| `closeOrphanedSpend` | function | closes attempts left open longer than `olderThanMs` as `orphaned` with an `unknown` cost |
|
package/llms/stitchkit.2.txt
CHANGED
|
@@ -513,20 +513,25 @@ upload.
|
|
|
513
513
|
A connection that drops after the request left and before an answer came — a host process that
|
|
514
514
|
restarted, a reset loopback socket — leaves the caller not knowing whether the call ran. A response
|
|
515
515
|
of any status is an answer and is never repeated. A network failure is repeated only when sending the
|
|
516
|
-
call twice is safe,
|
|
516
|
+
call twice is safe, using explicit `idempotent` first and then the single canonical
|
|
517
|
+
`isReadOnlyOperation` rule shared with MCP `readOnlyHint` and CLI refused views
|
|
518
|
+
([MCP & agents → `readOnlyHint`](./mcp-and-agents.md#saying-which-tools-only-read--readonlyhint)):
|
|
517
519
|
|
|
518
520
|
| endpoint | repeated after a network failure |
|
|
519
521
|
| --- | --- |
|
|
520
|
-
| `idempotent: true` | yes, whatever the method |
|
|
521
|
-
| `
|
|
522
|
-
| `
|
|
523
|
-
| `
|
|
524
|
-
|
|
|
522
|
+
| `idempotent: true` | yes, whatever the method or `effect` |
|
|
523
|
+
| `idempotent: false` | never, even a `GET` or `effect: 'read'` |
|
|
524
|
+
| `effect: 'write'` (with `idempotent` unset) | never, even a `GET` / `HEAD` |
|
|
525
|
+
| `tool.annotations.readOnlyHint: false` or `destructiveHint: true` (with `idempotent` unset) | never, even a `GET` / `HEAD` |
|
|
526
|
+
| `effect: 'read'` or `tool.annotations.readOnlyHint: true` (with `idempotent` unset) | yes, even on `POST` |
|
|
527
|
+
| `GET` / `HEAD` (with `idempotent`, `effect` and hints unset) | yes |
|
|
528
|
+
| any other method (with `idempotent`, `effect` and hints unset) | never |
|
|
525
529
|
|
|
526
530
|
Both clients read the rule from the endpoint itself: the bare `createClient(contract, { baseUrl })`
|
|
527
531
|
repeats up to `retry.limit` times (default 2) with a short doubling pause, and a client on
|
|
528
|
-
`createHttpClient` passes the
|
|
529
|
-
|
|
532
|
+
`createHttpClient` passes the resolved replay flag (`true` / `false`) to its own transport retry
|
|
533
|
+
while leaving ordinary unflagged `GET`/`HEAD` and non-`GET`/`HEAD` endpoints to respect
|
|
534
|
+
`createHttpClient({ retry: { methods } })`. A call that is not
|
|
530
535
|
repeated fails with the network error, and its outcome is unknown: the server may have run it.
|
|
531
536
|
Declare `idempotent: true` on a write that is safe twice — a `PUT` of a whole value, a delete, a
|
|
532
537
|
write keyed by an idempotency key — and it survives a restart of the server it talks to.
|
|
@@ -1052,30 +1057,3 @@ fragment as a value — the right policy for a socket or a child process, where
|
|
|
1052
1057
|
means the writer died. Both errors extend the `RangeError` / `SyntaxError` they replace, and
|
|
1053
1058
|
both are exported from `stitchkit` and `stitchkit/http`, so a React Native client checks a contract
|
|
1054
1059
|
stream's failure without importing the root entry.
|
|
1055
|
-
|
|
1056
|
-
## Reading a body up to a byte limit
|
|
1057
|
-
|
|
1058
|
-
`readBoundedBody` (from `stitchkit` or `stitchkit/http`) reads a request or response body, a
|
|
1059
|
-
`ReadableStream<Uint8Array>` or any `AsyncIterable<Uint8Array>`, and never reads past
|
|
1060
|
-
`maxBytes` plus one chunk. Whoever owns the boundary picks the two errors, so a body that is too
|
|
1061
|
-
large and a read that was cancelled stay different outcomes:
|
|
1062
|
-
|
|
1063
|
-
```ts
|
|
1064
|
-
import { readBoundedBody } from 'stitchkit'
|
|
1065
|
-
|
|
1066
|
-
const bytes = await readBoundedBody(request.body, {
|
|
1067
|
-
maxBytes: 64 * 1024,
|
|
1068
|
-
signal: request.signal,
|
|
1069
|
-
limitError: (observedBytes) => new PayloadTooLarge(observedBytes),
|
|
1070
|
-
abortError: (reason) => new ClientGone({ cause: reason }),
|
|
1071
|
-
})
|
|
1072
|
-
```
|
|
1073
|
-
|
|
1074
|
-
- The source is cancelled when the limit is crossed and when `signal` aborts. A read that never
|
|
1075
|
-
settles does not hold the call after an abort, and an abort is honoured before the first read
|
|
1076
|
-
(even for a `null` body).
|
|
1077
|
-
- A body of exactly `maxBytes` is read; one more byte calls `limitError` with the bytes seen so far
|
|
1078
|
-
(the chunk that crossed the limit included).
|
|
1079
|
-
- A `null` body, such as a request without one, is an empty result.
|
|
1080
|
-
- Without `abortError` the signal's own reason is thrown.
|
|
1081
|
-
- `maxBytes` is a positive safe integer.
|
package/llms/stitchkit.3.txt
CHANGED
|
@@ -17,6 +17,33 @@ Also read:
|
|
|
17
17
|
# Guide: Typed client (docs/guide/client.md) (continued)
|
|
18
18
|
==============================================================================
|
|
19
19
|
|
|
20
|
+
## Reading a body up to a byte limit
|
|
21
|
+
|
|
22
|
+
`readBoundedBody` (from `stitchkit` or `stitchkit/http`) reads a request or response body, a
|
|
23
|
+
`ReadableStream<Uint8Array>` or any `AsyncIterable<Uint8Array>`, and never reads past
|
|
24
|
+
`maxBytes` plus one chunk. Whoever owns the boundary picks the two errors, so a body that is too
|
|
25
|
+
large and a read that was cancelled stay different outcomes:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { readBoundedBody } from 'stitchkit'
|
|
29
|
+
|
|
30
|
+
const bytes = await readBoundedBody(request.body, {
|
|
31
|
+
maxBytes: 64 * 1024,
|
|
32
|
+
signal: request.signal,
|
|
33
|
+
limitError: (observedBytes) => new PayloadTooLarge(observedBytes),
|
|
34
|
+
abortError: (reason) => new ClientGone({ cause: reason }),
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- The source is cancelled when the limit is crossed and when `signal` aborts. A read that never
|
|
39
|
+
settles does not hold the call after an abort, and an abort is honoured before the first read
|
|
40
|
+
(even for a `null` body).
|
|
41
|
+
- A body of exactly `maxBytes` is read; one more byte calls `limitError` with the bytes seen so far
|
|
42
|
+
(the chunk that crossed the limit included).
|
|
43
|
+
- A `null` body, such as a request without one, is an empty result.
|
|
44
|
+
- Without `abortError` the signal's own reason is thrown.
|
|
45
|
+
- `maxBytes` is a positive safe integer.
|
|
46
|
+
|
|
20
47
|
## Resumable streams
|
|
21
48
|
|
|
22
49
|
A stream that survives a dropped connection needs four things beyond opening it:
|