stitchkit 0.136.7 → 0.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -0
- package/dist/agent-runtime/stores/branch-observations.d.ts +19 -19
- package/dist/agent-runtime/stores/schedule-contract.d.ts.map +1 -1
- package/dist/agent-runtime/stores/schedule-records.d.ts.map +1 -1
- package/dist/agent-runtime/stores/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/stores/sql-rows.d.ts +36 -36
- package/dist/agent-runtime/terminal-commit.d.ts +5 -5
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +52 -52
- package/dist/agent-runtime/testing/store-conformance-support.d.ts +26 -26
- package/dist/browser/client-executors.d.ts +2 -3
- package/dist/browser/client-executors.d.ts.map +1 -1
- package/dist/browser/realtime-client.d.ts +6 -1
- package/dist/browser/realtime-client.d.ts.map +1 -1
- package/dist/browser/socket-io-client.d.ts.map +1 -1
- package/dist/browser/socket-io-contract.d.ts +2 -0
- package/dist/browser/socket-io-contract.d.ts.map +1 -1
- package/dist/contract/define-validation.d.ts +6 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +1 -1
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/error-mapping.d.ts +71 -0
- package/dist/contract/error-mapping.d.ts.map +1 -0
- package/dist/contract/errors.d.ts +8 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/factory.d.ts +8 -0
- package/dist/contract/factory.d.ts.map +1 -1
- package/dist/contract/fragments.d.ts +45 -0
- package/dist/contract/fragments.d.ts.map +1 -0
- package/dist/contract/normalize.d.ts +6 -3
- package/dist/contract/normalize.d.ts.map +1 -1
- package/dist/contract/operation-read.d.ts +38 -0
- package/dist/contract/operation-read.d.ts.map +1 -0
- package/dist/contract/stream.d.ts.map +1 -1
- package/dist/contract/time-zone.d.ts +31 -0
- package/dist/contract/time-zone.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +1 -1
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/device-relay/hub.d.ts +1 -1
- package/dist/device-relay/hub.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +9 -9
- package/dist/entrypoints/agent-executor/claude-sdk.js +11 -11
- package/dist/entrypoints/agent-executor/claude.js +8 -8
- package/dist/entrypoints/agent-executor/codex.js +15 -15
- package/dist/entrypoints/agent-executor/testing.js +11 -11
- package/dist/entrypoints/agent-executor.js +14 -13
- package/dist/entrypoints/agent-runtime/ai-sdk.js +5 -5
- package/dist/entrypoints/agent-runtime/anthropic.js +1 -1
- package/dist/entrypoints/agent-runtime/browser.js +5 -5
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +14 -15
- package/dist/entrypoints/agent-runtime/openai.js +1 -1
- package/dist/entrypoints/agent-runtime/openrouter.js +7 -7
- package/dist/entrypoints/agent-runtime/postgres.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +8 -8
- package/dist/entrypoints/agent-runtime/sandbox.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +33 -29
- package/dist/entrypoints/application/diagnostic-journal.js +3 -3
- package/dist/entrypoints/application/directory-inbox.js +1 -1
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application/opentelemetry.js +2 -2
- package/dist/entrypoints/application.js +10 -10
- package/dist/entrypoints/cli/publish.d.ts +4 -4
- package/dist/entrypoints/cli/publish.d.ts.map +1 -1
- package/dist/entrypoints/cli/publish.js +160 -52
- package/dist/entrypoints/cli.d.ts +3 -1
- package/dist/entrypoints/cli.d.ts.map +1 -1
- package/dist/entrypoints/cli.js +520 -59
- package/dist/entrypoints/contract.d.ts +5 -1
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +25 -7
- package/dist/entrypoints/device-relay.js +20 -10
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.js +10 -10
- package/dist/entrypoints/handler.d.ts +1 -1
- package/dist/entrypoints/handler.d.ts.map +1 -1
- package/dist/entrypoints/handler.js +12 -12
- package/dist/entrypoints/http.js +13 -12
- package/dist/entrypoints/index.js +36 -18
- package/dist/entrypoints/live.d.ts +2 -1
- package/dist/entrypoints/live.d.ts.map +1 -1
- package/dist/entrypoints/live.js +630 -1
- package/dist/entrypoints/node.d.ts +5 -0
- package/dist/entrypoints/node.d.ts.map +1 -1
- package/dist/entrypoints/node.js +36 -16
- package/dist/entrypoints/observability.js +25 -10
- package/dist/entrypoints/postgres.d.ts +4 -1
- package/dist/entrypoints/postgres.d.ts.map +1 -1
- package/dist/entrypoints/postgres.js +312 -0
- package/dist/entrypoints/primitives.js +11 -4
- package/dist/entrypoints/process.js +7 -7
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +6 -29
- package/dist/entrypoints/server.d.ts +6 -1
- package/dist/entrypoints/server.d.ts.map +1 -1
- package/dist/entrypoints/server.js +93 -32
- package/dist/entrypoints/service-host/macos.js +6 -6
- package/dist/entrypoints/service-host/work.js +6 -6
- package/dist/entrypoints/service-host.js +10 -10
- package/dist/entrypoints/spend.js +2 -1
- package/dist/entrypoints/sync.js +5 -5
- package/dist/entrypoints/telegram.js +8 -8
- package/dist/entrypoints/testing.d.ts +1 -0
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +1501 -13
- package/dist/entrypoints/tools/agent.js +6 -7
- package/dist/entrypoints/tools/connections.js +9 -11
- package/dist/entrypoints/tools/contract.js +1 -2
- package/dist/entrypoints/tools/invoker.js +4 -5
- package/dist/entrypoints/tools/mcp.js +10 -11
- package/dist/entrypoints/tools/toolkit.d.ts +1 -1
- package/dist/entrypoints/tools/toolkit.d.ts.map +1 -1
- package/dist/entrypoints/tools/toolkit.js +29 -24
- package/dist/entrypoints/tools.js +28 -30
- package/dist/entrypoints/tracking/contract.js +2 -1
- package/dist/entrypoints/xlsx.js +5 -8
- package/dist/{index-033tyx59.js → index-0zw0hcyg.js} +4 -1
- package/dist/{index-zcq3dby3.js → index-1bjwfnnj.js} +1 -1
- package/dist/{index-f103md2v.js → index-1cfacbe2.js} +88 -23
- package/dist/{index-gj4wdts6.js → index-1ckh9qx1.js} +1 -1
- package/dist/index-1pvwmbxp.js +1435 -0
- package/dist/{index-0s75mjh7.js → index-2e4hdh32.js} +1 -1
- package/dist/{index-3shdhzt6.js → index-2j0pqxkn.js} +12 -6
- package/dist/index-3k8w02se.js +28 -0
- package/dist/{index-7fjbdga8.js → index-3pb4ccj2.js} +8 -0
- package/dist/{index-w7e402wx.js → index-48kb4gqq.js} +46 -7
- package/dist/{index-cv9b7fz2.js → index-6rws2xf5.js} +8 -0
- package/dist/{index-bbpygynk.js → index-77w5vx0g.js} +1 -1
- package/dist/index-7dz1ngaf.js +35 -0
- package/dist/{index-y68gavb5.js → index-7n4atsm4.js} +1 -1
- package/dist/index-8ef1bfea.js +71 -0
- package/dist/{index-0x4mnwg5.js → index-8k3y9nd4.js} +6 -9
- package/dist/{index-ezwsqyad.js → index-8rkdkefj.js} +40 -23
- package/dist/{index-3cwq5byx.js → index-9nax7tkn.js} +2 -2
- package/dist/{index-dz6tstcp.js → index-9r6emjwz.js} +1 -1
- package/dist/{index-32ew02z1.js → index-c4b7d6ej.js} +5 -5
- package/dist/index-ceshyndf.js +284 -0
- package/dist/{index-w161azza.js → index-d13rw31w.js} +6 -6
- package/dist/{index-1h0dtfz3.js → index-dmm7vs3f.js} +1 -1
- package/dist/{index-ypm85xwe.js → index-dp8j2e77.js} +1 -1
- package/dist/{index-qqd979f7.js → index-edycjvrv.js} +9 -9
- package/dist/{index-18qdpbcq.js → index-egpf9dv0.js} +200 -1479
- package/dist/{index-fatke81t.js → index-ezgvsj9w.js} +2 -2
- package/dist/{index-chapre0y.js → index-f3e7tj1g.js} +1 -1
- package/dist/{index-df5xr2f9.js → index-frsd2a94.js} +16 -1
- package/dist/index-fy9mmek1.js +95 -0
- package/dist/{index-2331y2tf.js → index-g0gvfzrx.js} +12 -12
- package/dist/index-gpe8d1ka.js +19 -0
- package/dist/{index-4p2zx593.js → index-gyw4qd0m.js} +1 -1
- package/dist/index-gzqy81tw.js +172 -0
- package/dist/{index-yrhw10ef.js → index-h34c510q.js} +8 -4
- package/dist/{index-rr94xcj6.js → index-h527p1yj.js} +10 -4
- package/dist/{index-qj0sq69b.js → index-hgf1tbgz.js} +76 -16
- package/dist/{index-smvmnz5y.js → index-hvpan32x.js} +1 -1
- package/dist/{index-4gbybjg6.js → index-hxawqrb6.js} +2 -2
- package/dist/{index-0k1ba0ss.js → index-j91jffhv.js} +1 -1
- package/dist/{index-d01akj5n.js → index-jr4kwetx.js} +8 -8
- package/dist/{index-xqppqn97.js → index-ka6z48zc.js} +315 -69
- package/dist/{index-by8w2461.js → index-kw0segzt.js} +104 -3
- package/dist/{index-6f4fjygr.js → index-m5t4dr7h.js} +29 -7
- package/dist/{index-afaq0nc4.js → index-n0egp1ke.js} +1 -1
- package/dist/{index-9fzjgg86.js → index-n74rb1dq.js} +2 -2
- package/dist/{index-dwq6a6sq.js → index-pt25vmhc.js} +33 -16
- package/dist/{index-vwg0n3e6.js → index-pyazb8q4.js} +23 -14
- package/dist/{index-5md04mwc.js → index-qpjjbkc5.js} +4 -4
- package/dist/{index-08a3qfr8.js → index-r1qt6zgj.js} +1 -1
- package/dist/{index-ctaxjpa4.js → index-r709pqed.js} +1 -1
- package/dist/{index-2zrx0nzv.js → index-rzc40z6e.js} +3 -5
- package/dist/{index-gq35s3bm.js → index-s5axtd56.js} +2 -2
- package/dist/{index-edpkm3k7.js → index-scpcps66.js} +669 -16
- package/dist/{index-ry8m2mhg.js → index-sf2mt6wj.js} +1 -1
- package/dist/{index-tjhhsnjv.js → index-t1213r0t.js} +1 -1
- package/dist/{index-gvgtmt7a.js → index-t7efje30.js} +2 -2
- package/dist/{index-w3s79kcb.js → index-tzyk36dy.js} +1 -1
- package/dist/{index-8tn10tp6.js → index-v64bvwjr.js} +1 -1
- package/dist/{index-1fhbe4e4.js → index-vksbsqpb.js} +1 -1
- package/dist/{index-dxft2mnm.js → index-wdg7bswj.js} +1 -1
- package/dist/{index-ppy23bd2.js → index-wjx1zs2r.js} +7 -578
- package/dist/{index-efbzm2se.js → index-x2r0ma9t.js} +1 -1
- package/dist/{index-kd48gk7d.js → index-x8py72a3.js} +1 -1
- package/dist/index-xvydbxmk.js +1404 -0
- package/dist/index-xwaphv0d.js +31 -0
- package/dist/{index-a09r9ff0.js → index-y44j39yk.js} +1 -1
- package/dist/{index-7mjsb7zv.js → index-ybrrxjhb.js} +1 -1
- package/dist/{index-xsrma0jd.js → index-ysthxsa8.js} +6 -6
- package/dist/{index-6p5pshcd.js → index-yyh3ey4b.js} +1 -1
- package/dist/{index-mr3njw67.js → index-z6hq9j8j.js} +1 -1
- package/dist/{index-67mzzkdv.js → index-z72agxdn.js} +2 -2
- package/dist/{index-e4w0sfm1.js → index-z78mtc16.js} +1 -1
- package/dist/{index-7csn6pva.js → index-ze94h4ph.js} +5 -0
- package/dist/internal/json-stringify.d.ts +12 -0
- package/dist/internal/json-stringify.d.ts.map +1 -1
- package/dist/internal/unix-client-error.d.ts +4 -0
- package/dist/internal/unix-client-error.d.ts.map +1 -1
- package/dist/live/watch-contract.d.ts +4 -0
- package/dist/live/watch-contract.d.ts.map +1 -1
- package/dist/live/watch-fanout-frame.d.ts +81 -0
- package/dist/live/watch-fanout-frame.d.ts.map +1 -0
- package/dist/live/watch-fanout.d.ts +57 -0
- package/dist/live/watch-fanout.d.ts.map +1 -0
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/spool-core.d.ts +1 -0
- package/dist/observability/spool-core.d.ts.map +1 -1
- package/dist/observability/spool-drain.d.ts +48 -0
- package/dist/observability/spool-drain.d.ts.map +1 -0
- package/dist/observability/spool.d.ts +12 -6
- package/dist/observability/spool.d.ts.map +1 -1
- package/dist/postgres/connection-config.d.ts +54 -0
- package/dist/postgres/connection-config.d.ts.map +1 -0
- package/dist/postgres/rollback-transaction.d.ts +61 -0
- package/dist/postgres/rollback-transaction.d.ts.map +1 -0
- package/dist/primitives/deadline.d.ts +4 -4
- package/dist/primitives/deadline.d.ts.map +1 -1
- package/dist/server/error-hook.d.ts +3 -32
- package/dist/server/error-hook.d.ts.map +1 -1
- package/dist/server/local-consent-key.d.ts +104 -0
- package/dist/server/local-consent-key.d.ts.map +1 -0
- package/dist/server/local-control-journal.d.ts +51 -0
- package/dist/server/local-control-journal.d.ts.map +1 -0
- package/dist/server/local-control-reporter.d.ts +32 -0
- package/dist/server/local-control-reporter.d.ts.map +1 -0
- package/dist/server/local-control.d.ts +48 -0
- package/dist/server/local-control.d.ts.map +1 -0
- package/dist/server/local-host-clients.d.ts +105 -0
- package/dist/server/local-host-clients.d.ts.map +1 -0
- package/dist/server/middleware/trust-fence.d.ts +20 -0
- package/dist/server/middleware/trust-fence.d.ts.map +1 -1
- package/dist/spend/receipt-spool.d.ts +9 -4
- package/dist/spend/receipt-spool.d.ts.map +1 -1
- package/dist/testing/tool-surface-checks.d.ts +89 -0
- package/dist/testing/tool-surface-checks.d.ts.map +1 -0
- package/dist/testing/tool-surface-cli-callable.d.ts +63 -0
- package/dist/testing/tool-surface-cli-callable.d.ts.map +1 -0
- package/dist/testing/tool-surface-dead-refs.d.ts +32 -0
- package/dist/testing/tool-surface-dead-refs.d.ts.map +1 -0
- package/dist/testing/tool-surface-gates.d.ts +72 -0
- package/dist/testing/tool-surface-gates.d.ts.map +1 -0
- package/dist/testing/tool-surface-parity-drivers.d.ts +56 -0
- package/dist/testing/tool-surface-parity-drivers.d.ts.map +1 -0
- package/dist/testing/tool-surface-parity.d.ts +28 -0
- package/dist/testing/tool-surface-parity.d.ts.map +1 -0
- package/dist/testing/tool-surface-ratchet.d.ts +71 -0
- package/dist/testing/tool-surface-ratchet.d.ts.map +1 -0
- package/dist/tools/agent-tools.d.ts +3 -0
- package/dist/tools/agent-tools.d.ts.map +1 -1
- package/dist/tools/cli/command.d.ts +3 -0
- package/dist/tools/cli/command.d.ts.map +1 -1
- package/dist/tools/cli/create-cli.d.ts.map +1 -1
- package/dist/tools/cli/distribution-config.d.ts +39 -1
- package/dist/tools/cli/distribution-config.d.ts.map +1 -1
- package/dist/tools/cli/distribution-routes.d.ts +4 -2
- package/dist/tools/cli/distribution-routes.d.ts.map +1 -1
- package/dist/tools/cli/format.d.ts +3 -6
- package/dist/tools/cli/format.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +4 -0
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/local-key-command.d.ts +53 -0
- package/dist/tools/cli/local-key-command.d.ts.map +1 -0
- package/dist/tools/cli/managed-surface.d.ts.map +1 -1
- package/dist/tools/cli/publication-contract.d.ts +9 -2
- package/dist/tools/cli/publication-contract.d.ts.map +1 -1
- package/dist/tools/cli/publication.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/run-stream.d.ts.map +1 -1
- package/dist/tools/cli/runner.d.ts +8 -3
- package/dist/tools/cli/runner.d.ts.map +1 -1
- package/dist/tools/cli/secret.d.ts +55 -0
- package/dist/tools/cli/secret.d.ts.map +1 -0
- package/dist/tools/cli/session.d.ts +2 -2
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/cli/signature.d.ts +23 -9
- package/dist/tools/cli/signature.d.ts.map +1 -1
- package/dist/tools/cli/stream.d.ts.map +1 -1
- package/dist/tools/cli/unix-outcome.d.ts +6 -0
- package/dist/tools/cli/unix-outcome.d.ts.map +1 -1
- package/dist/tools/cli/update.d.ts +6 -1
- package/dist/tools/cli/update.d.ts.map +1 -1
- package/dist/tools/execute-result.d.ts +20 -0
- package/dist/tools/execute-result.d.ts.map +1 -1
- package/dist/tools/execute.d.ts +3 -0
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/internal/json-projection.d.ts +13 -9
- package/dist/tools/internal/json-projection.d.ts.map +1 -1
- package/dist/tools/internal/remote-error.d.ts +15 -0
- package/dist/tools/internal/remote-error.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +2 -0
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +3 -0
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts +2 -0
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +5 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -0
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts +2 -0
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/dist/tools/mcp/stdio.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +3 -0
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/read-operation.d.ts +2 -6
- package/dist/tools/read-operation.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools/toolkit.d.ts +10 -3
- package/dist/tools/toolkit.d.ts.map +1 -1
- package/dist/xlsx/schema.d.ts.map +1 -1
- package/llms/cli-publish.txt +4 -1
- package/llms/cli.2.txt +42 -51
- package/llms/cli.3.txt +34 -1
- package/llms/cli.txt +18 -3
- package/llms/contract.txt +47 -5
- package/llms/handler.txt +1 -1
- package/llms/live.txt +82 -0
- package/llms/node.txt +5 -0
- package/llms/observability.2.txt +1 -1
- package/llms/observability.txt +6 -0
- package/llms/postgres.txt +14 -3
- package/llms/server.2.txt +206 -240
- package/llms/server.3.txt +242 -202
- package/llms/server.4.txt +202 -1025
- package/llms/server.5.txt +1053 -255
- package/llms/server.6.txt +274 -0
- package/llms/server.txt +32 -116
- package/llms/spend.txt +8 -7
- package/llms/stitchkit.2.txt +13 -35
- package/llms/stitchkit.3.txt +27 -0
- package/llms/stitchkit.txt +82 -82
- package/llms/testing.txt +40 -0
- package/llms/tools-toolkit.txt +2 -2
- package/llms/tools.2.txt +29 -20
- package/llms/{upgrading-0.128.0-0.129.0.txt → upgrading-0.128.0-0.131.0.txt} +101 -3
- package/llms/{upgrading-0.130.0-0.136.0.txt → upgrading-0.132.0-0.137.0.txt} +62 -101
- package/llms/upgrading.txt +2 -2
- package/llms-full.txt +641 -189
- package/llms.txt +14 -14
- package/package.json +3 -3
- package/dist/index-9118dw8d.js +0 -603
- package/dist/index-9vj869rx.js +0 -19
- package/dist/index-a1rjr381.js +0 -114
- package/dist/index-dacxr7nf.js +0 -17
- package/dist/index-dm50x3by.js +0 -63
- package/dist/index-dmrx8xma.js +0 -163
- package/dist/index-ednf2cxs.js +0 -37
- package/dist/{index-e4zt2x70.js → index-3czppvrr.js} +3 -3
- package/dist/{index-42n9jycn.js → index-3f79t32b.js} +3 -3
- package/dist/{index-mfe9a266.js → index-84n49vam.js} +0 -0
- package/dist/{index-f16b7rze.js → index-er1tp8de.js} +3 -3
- package/dist/{index-k137ezb6.js → index-f5d0fdcf.js} +3 -3
- package/dist/{index-65p8v81y.js → index-psz8qrz0.js} +3 -3
- package/dist/{index-kadgaw1s.js → index-r8cq86h1.js} +0 -0
- package/dist/{index-1yky29qg.js → index-tyyvbarf.js} +0 -0
- package/dist/{index-tjakdpf2.js → index-wq71v08n.js} +3 -3
- package/dist/{index-7an2fs5h.js → index-wswcpbm4.js} +3 -3
package/llms/server.2.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# stitchkit/server — stitchkit docs slice, part 2 of
|
|
1
|
+
# stitchkit/server — stitchkit docs slice, part 2 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
|
|
@@ -18,6 +19,206 @@ Also read:
|
|
|
18
19
|
# Guide: HTTP server (docs/guide/server.md) (continued)
|
|
19
20
|
==============================================================================
|
|
20
21
|
|
|
22
|
+
## A host beside its own window
|
|
23
|
+
|
|
24
|
+
A desktop app's host — the process beside its window — is an ordinary StitchKit server, bound to
|
|
25
|
+
loopback. Calls are plain HTTP through the typed client; events travel the realtime socket with
|
|
26
|
+
`retain` per topic ([realtime](./realtime.md)). There is no second transport to learn.
|
|
27
|
+
|
|
28
|
+
Binding to `127.0.0.1` keeps other machines out, and nothing more. A web page open in a browser on
|
|
29
|
+
the same machine can still call `http://127.0.0.1:<port>` and open a WebSocket there (a WebSocket
|
|
30
|
+
obeys no CORS), and a DNS-rebinding page reaches it under an attacker's host name.
|
|
31
|
+
`createLocalHostGuard` closes both: a request must name a loopback `Host`, carry an allowed `Origin`
|
|
32
|
+
when it carries one, and present the host's secret. The same rules gate the Socket.IO handshake.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { createLocalHostGuard, createServer, createSocketIOServer } from 'stitchkit/server'
|
|
36
|
+
|
|
37
|
+
const secret = crypto.randomUUID() + crypto.randomUUID() // per start; hand it to the window, never in a URL
|
|
38
|
+
const guard = createLocalHostGuard({ secret, origins: ['tauri://localhost'] })
|
|
39
|
+
const socket = await createSocketIOServer({
|
|
40
|
+
allowRequest: guard.allowRequest,
|
|
41
|
+
handshake: guard.handshake,
|
|
42
|
+
cors: guard.cors,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
createServer({
|
|
46
|
+
hostname: '127.0.0.1',
|
|
47
|
+
port: 0,
|
|
48
|
+
services,
|
|
49
|
+
socket,
|
|
50
|
+
cors: guard.cors,
|
|
51
|
+
hooks: { onRequest: (request) => guard.onRequest(request) },
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A window in a webview is a cross-origin page: `guard.cors` allows its origins, so the browser's
|
|
56
|
+
preflight — answered before `onRequest` — passes and the window can read every answer. The window
|
|
57
|
+
sends `Authorization: Bearer <secret>` on every call (`headers` on `createClient`) and
|
|
58
|
+
`auth: { secret }` on the socket. A refusal is the framework error envelope: `401` for the secret,
|
|
59
|
+
`403` for a foreign `Host` or `Origin`, before routing, raw routes included. Secrets compare in
|
|
60
|
+
constant time and a shorter or longer guess tells nothing about the real one. `stitchkit/node` exports
|
|
61
|
+
the same guard for `serveNode`.
|
|
62
|
+
|
|
63
|
+
A call in flight when the host restarts never gets an answer. The typed client sends it again only
|
|
64
|
+
when that is safe — see [calls that never got an answer](./client.md#calls-that-never-got-an-answer).
|
|
65
|
+
|
|
66
|
+
### Tracking multiple windows (`createLocalHostClients`)
|
|
67
|
+
|
|
68
|
+
When a desktop app opens several windows against one local host, each window owns its own
|
|
69
|
+
subscriptions, audio/screen sessions, and targeted notifications. Pair `createLocalHostGuard`
|
|
70
|
+
with `createLocalHostClients` (`stitchkit/server` and `stitchkit/node`):
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import {
|
|
74
|
+
bindRealtimeServer,
|
|
75
|
+
createLocalHostClients,
|
|
76
|
+
createLocalHostGuard,
|
|
77
|
+
createServer,
|
|
78
|
+
createSocketIOServer,
|
|
79
|
+
} from 'stitchkit/server'
|
|
80
|
+
import { z } from 'zod'
|
|
81
|
+
|
|
82
|
+
const guard = createLocalHostGuard({ secret, origins: ['tauri://localhost'] })
|
|
83
|
+
const clientSetup = createLocalHostClients({
|
|
84
|
+
guard,
|
|
85
|
+
labelSchema: z.object({ windowId: z.string().min(1) }),
|
|
86
|
+
onClientGone: (caller) => fanout.release(caller.client),
|
|
87
|
+
onLastClientGone: () => pauseBackgroundWork(),
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const socket = await createSocketIOServer({
|
|
91
|
+
allowRequest: guard.allowRequest,
|
|
92
|
+
handshake: clientSetup.handshake, // validates secret + labelSchema together
|
|
93
|
+
cors: clientSetup.cors, // allows x-stitchkit-client alongside default headers
|
|
94
|
+
})
|
|
95
|
+
const realtime = bindRealtimeServer(contract, socket)
|
|
96
|
+
const hostClients = clientSetup.attach(realtime)
|
|
97
|
+
|
|
98
|
+
hostClients.on('claimCall', (caller, input, ack) => {
|
|
99
|
+
ack({ owner: caller.label.windowId })
|
|
100
|
+
})
|
|
101
|
+
hostClients.sendTo(targetClientId, 'incomingCall', { id })
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Each window reads its connection id from `realtimeClient.id` (`stitchkit` / `stitchkit/realtime`)
|
|
105
|
+
and passes it in the `x-stitchkit-client` header on HTTP requests so HTTP handlers can resolve
|
|
106
|
+
`hostClients.callerFromRequest(request)` against the live socket registry. `onClientGone` runs on
|
|
107
|
+
every individual window disconnect; `onLastClientGone` runs only when the final window disconnects.
|
|
108
|
+
|
|
109
|
+
### Adding a unix-socket control channel for local CLI and agents
|
|
110
|
+
|
|
111
|
+
Expose local state inspection and consent-gated key issuance to a local CLI or agent over a
|
|
112
|
+
dedicated `0600` Unix domain socket alongside the guarded loopback TCP server, wrapped with
|
|
113
|
+
`createLocalControlGuard`, `createLocalControlJournal`, and `createLocalConsentKeyIssuance`
|
|
114
|
+
(→ ADR 0346):
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import {
|
|
118
|
+
bindProcessSignals,
|
|
119
|
+
createLocalConsentKeyIssuance,
|
|
120
|
+
createLocalControlGuard,
|
|
121
|
+
createLocalControlJournal,
|
|
122
|
+
createServer,
|
|
123
|
+
extractReportedClient,
|
|
124
|
+
respondJson,
|
|
125
|
+
} from 'stitchkit/server'
|
|
126
|
+
|
|
127
|
+
const journal = createLocalControlJournal({
|
|
128
|
+
path: journalPath, // created 0600, rotates to <path>.1 after 1 MiB
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const controlGuard = createLocalControlGuard({
|
|
132
|
+
maxHeaderBytes: 8 * 1024, // 431 HEADERS_TOO_LARGE (Bun parser native cap is ~16 KiB)
|
|
133
|
+
maxBodyBytes: 2 * 1024 * 1024, // 413 REQUEST_TOO_LARGE; Transfer-Encoding or unsized body -> 400
|
|
134
|
+
maxConcurrentRequests: 16, // 503 CONTROL_API_BUSY (open SSE/NDJSON streams count)
|
|
135
|
+
reporter: { headerPrefix: 'x-app-' }, // always tagged verified: false
|
|
136
|
+
journal,
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const keyIssuance = createLocalConsentKeyIssuance({
|
|
140
|
+
path: '/v1/init-key',
|
|
141
|
+
reporter: { headerPrefix: 'x-app-' },
|
|
142
|
+
authorizeRequest: async ({ request }) => {
|
|
143
|
+
const role = lookupRole(request.role)
|
|
144
|
+
return {
|
|
145
|
+
callerCanManageKeys: currentDesktopSession.canManageKeys,
|
|
146
|
+
allowsKeyManagement: role.allowsKeyManagement, // true -> 403 ROLE_NOT_ALLOWED before consent
|
|
147
|
+
summary: `Issue "${request.role}" key`,
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
consent: (question, { signal }) => showNativeConsentDialog(question, signal),
|
|
151
|
+
issueKey: ({ request }) => createScopedProgramKey(currentDesktopSession, request),
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
// Opt-in: omit this server when the user disables local control.
|
|
155
|
+
const unix = createServer({
|
|
156
|
+
services: [],
|
|
157
|
+
unix: { path: socketPath, mode: 0o600 },
|
|
158
|
+
wrapFetch: (next) => controlGuard.wrapFetch(keyIssuance.guardWhileConsentPending(next)),
|
|
159
|
+
rawRoutes: [
|
|
160
|
+
keyIssuance.route,
|
|
161
|
+
{
|
|
162
|
+
method: 'GET',
|
|
163
|
+
path: '/v1/status',
|
|
164
|
+
handler: (req) =>
|
|
165
|
+
respondJson({
|
|
166
|
+
ok: true,
|
|
167
|
+
client: extractReportedClient(req, { headerPrefix: 'x-app-' }),
|
|
168
|
+
}),
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
bindProcessSignals({
|
|
174
|
+
shutdown: (options) => Promise.all([tcp.shutdown(options), unix.shutdown(options)]),
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Trust boundary and operational rules for the unix channel:
|
|
179
|
+
|
|
180
|
+
- **Do not silently delegate the signed-in human's session to the Unix socket.** The socket proves
|
|
181
|
+
only that the peer runs as the same OS user. Use the Unix channel to read local state and to issue
|
|
182
|
+
a scoped program key with explicit human approval via `createLocalConsentKeyIssuance` (with the
|
|
183
|
+
CLI counterpart `defineLocalKeyInitCommand` in `stitchkit/cli`), then send mutations over HTTPS
|
|
184
|
+
under that scoped key. If an application intentionally chooses to delegate a human session over a
|
|
185
|
+
Unix socket anyway, every edit made by a local agent or script is indistinguishable from the human
|
|
186
|
+
owner's own edits (same permissions, same author attribution).
|
|
187
|
+
- **No OS-verified peer credentials on `Bun.serve({ unix })` (→ ADR 0347).** On Bun 1.4.5,
|
|
188
|
+
`server.requestIP(request)` returns `null` for Unix domain sockets and exposes neither the socket
|
|
189
|
+
file descriptor nor `SO_PEERCRED` / `LOCAL_PEERCRED` / `LOCAL_PEERPID`. StitchKit intentionally
|
|
190
|
+
does not replace `Bun.serve` with a custom HTTP/1.1 server or FFI proxy over undocumented
|
|
191
|
+
`Bun.listen` internals. Every identity parsed by `extractReportedClient` carries `verified: false`
|
|
192
|
+
and must be presented in UIs and call journals as self-reported ("reported, not verified") until
|
|
193
|
+
Bun exposes native Unix peer credentials. Applications that need kernel-verified caller PID and
|
|
194
|
+
executable path today should terminate the Unix socket in their native desktop shell (Rust/Swift
|
|
195
|
+
via `LOCAL_PEERPID` + `proc_pidpath` or `SO_PEERCRED` + `/proc/<pid>/exe`) and pass verified
|
|
196
|
+
metadata over a private internal channel.
|
|
197
|
+
- **Request limits and call journal.** `createLocalControlGuard` enforces `maxHeaderBytes` (default
|
|
198
|
+
8 KiB; Bun's native parser caps raw headers at ~16 KiB so larger values cannot raise Bun's native
|
|
199
|
+
ceiling), explicit `Content-Length` up to `maxBodyBytes` (default 2 MiB; refuses
|
|
200
|
+
`Transfer-Encoding` and unsized bodies while accepting body-less requests such as body-less `POST`
|
|
201
|
+
from `createUnixClientTransport`), and `maxConcurrentRequests` (default 16, holding slots while
|
|
202
|
+
`text/event-stream` / `application/x-ndjson` responses stay open without cloning `Request` or
|
|
203
|
+
breaking `server.shutdown()`). `createLocalControlJournal` writes metadata-only `0600` JSONL
|
|
204
|
+
(`url.pathname` only — never query strings, request bodies, `Authorization`, or `2xx` responses)
|
|
205
|
+
with serialized rotation to `<path>.1`.
|
|
206
|
+
- **Opt-in by configuration.** No socket file is created unless the application explicitly configures
|
|
207
|
+
`createServer({ unix })`.
|
|
208
|
+
- **Streaming events over the socket.** Socket.IO does not mount on a unix listener; expose live
|
|
209
|
+
events to local CLI/agent consumers through `sseRoute` / `ndjsonRoute` or contract `stream`
|
|
210
|
+
endpoints.
|
|
211
|
+
- **Bind order.** Because `bindUnixSocket` adjusts `process.umask` during bind, create the unix
|
|
212
|
+
server before spawning `Worker` threads.
|
|
213
|
+
- **macOS boundaries.** Under macOS App Sandbox, place the socket inside the app's App Group
|
|
214
|
+
container and keep the full UTF-8 path within 103 bytes; TCC permissions remain bound to the host
|
|
215
|
+
process's responsible bundle.
|
|
216
|
+
- **Embedded agents and shell tools.** An unsandboxed agent shell running as the same OS user has full
|
|
217
|
+
access to the socket. Inside StitchKit's Linux Bubblewrap sandbox (`stitchkit/agent-runtime/sandbox`),
|
|
218
|
+
the host's `$HOME`, `/tmp`, `/run` and `XDG_RUNTIME_DIR` are not mounted (`--unshare-all --clearenv`),
|
|
219
|
+
so keep the socket outside the agent's mounted `workspace` directory (note that macOS has no
|
|
220
|
+
Bubblewrap isolation).
|
|
221
|
+
|
|
21
222
|
## A host inside React Native
|
|
22
223
|
|
|
23
224
|
When an app runs its contract host directly inside the React Native JavaScript runtime (Hermes) and
|
|
@@ -804,238 +1005,3 @@ bus.emit('user.created', { id: '1' })
|
|
|
804
1005
|
|
|
805
1006
|
A typed in-process pub/sub — decouple a handler from the side effects of its
|
|
806
1007
|
write without reaching for an external queue.
|
|
807
|
-
|
|
808
|
-
## OpenAPI
|
|
809
|
-
|
|
810
|
-
`generateOpenApiDocument` builds an OpenAPI 3.1 document straight from the
|
|
811
|
-
contracts — the contract *is* the spec, no decorators or hand-maintained
|
|
812
|
-
annotations (→ ADR 0018). `openApiRoute` serves it as a raw route:
|
|
813
|
-
|
|
814
|
-
```ts
|
|
815
|
-
import { generateOpenApiDocument, openApiRoute } from 'stitchkit/server'
|
|
816
|
-
|
|
817
|
-
const doc = generateOpenApiDocument({
|
|
818
|
-
info: { title: 'My API', version: '1.0.0' },
|
|
819
|
-
services: [users, orders],
|
|
820
|
-
})
|
|
821
|
-
createServer({ services: [users, orders], rawRoutes: [openApiRoute('/openapi.json', doc)] })
|
|
822
|
-
```
|
|
823
|
-
|
|
824
|
-
Only HTTP-exposed methods appear (an MCP/agent-only tool is skipped).
|
|
825
|
-
|
|
826
|
-
OpenAPI 3.1 has no standard multi-segment path parameter. For a contract path
|
|
827
|
-
ending in a named wildcard such as `/*filePath`, StitchKit keeps the literal
|
|
828
|
-
runtime path, omits `filePath` from the
|
|
829
|
-
standard `in: path` parameter list, and emits
|
|
830
|
-
`x-stitchkit-trailing-wildcard` on the operation with its parameter name,
|
|
831
|
-
schema and semantics. A generic OpenAPI client therefore cannot invent
|
|
832
|
-
catch-all expansion; use StitchKit's typed client or teach the generator that
|
|
833
|
-
extension.
|
|
834
|
-
|
|
835
|
-
### Curating the spec — `includeMethod`
|
|
836
|
-
|
|
837
|
-
To publish a **subset** — a public spec that advertises only some methods
|
|
838
|
-
without revealing the rest — pass `includeMethod`. It keeps the core generic:
|
|
839
|
-
*you* decide the policy, filtering on anything the method carries. The
|
|
840
|
-
recommended declarative allowlist marks endpoints with the existing `meta`
|
|
841
|
-
passthrough and keeps those:
|
|
842
|
-
|
|
843
|
-
```ts
|
|
844
|
-
// contract — declarative, one source of truth
|
|
845
|
-
getBalance: { method: 'GET', path: '/balance', desc: '…', scope: 'account',
|
|
846
|
-
meta: { public: true }, output: BalanceSchema }
|
|
847
|
-
|
|
848
|
-
// generation — the app's policy
|
|
849
|
-
const publicDoc = generateOpenApiDocument({
|
|
850
|
-
info: { title: 'Public API', version: '1.0.0' },
|
|
851
|
-
services: [account],
|
|
852
|
-
includeMethod: (m) => m.meta?.public === true,
|
|
853
|
-
})
|
|
854
|
-
```
|
|
855
|
-
|
|
856
|
-
An excluded method's whole entry — path *and* every schema inlined within it —
|
|
857
|
-
is simply never emitted, so nothing about a hidden endpoint leaks.
|
|
858
|
-
|
|
859
|
-
> **The filter advertises; it does not authorize.** Hiding a method from the
|
|
860
|
-
> spec does **not** protect it — it is still callable, and the auth `scope` gate
|
|
861
|
-
> is the only thing guarding it. And because `openApiRoute` closes over the
|
|
862
|
-
> document you hand it, the filter only matters if you feed it a filtered one:
|
|
863
|
-
> serve **two** documents — a full internal spec and a filtered public spec on
|
|
864
|
-
> separate routes — never one unfiltered `openApiRoute` on a public path.
|
|
865
|
-
|
|
866
|
-
```ts
|
|
867
|
-
const internal = openApiRoute('/internal/openapi.json', fullDoc) // behind auth
|
|
868
|
-
const publicSpec = openApiRoute('/openapi.json', publicDoc) // curated
|
|
869
|
-
```
|
|
870
|
-
|
|
871
|
-
### Security schemes — `security`
|
|
872
|
-
|
|
873
|
-
A generic client reads the spec to learn how to authenticate, and a scope name
|
|
874
|
-
alone does not tell it which header to send. Pass `security` to describe that in
|
|
875
|
-
standard OpenAPI terms: named schemes become `components.securitySchemes`, and
|
|
876
|
-
every protected operation gets a `security` requirement. It is keyed by the
|
|
877
|
-
scopes your contracts already declare, so there is no second list of which
|
|
878
|
-
endpoint is protected:
|
|
879
|
-
|
|
880
|
-
```ts
|
|
881
|
-
const publicDoc = generateOpenApiDocument({
|
|
882
|
-
info: { title: 'Public API', version: '1.0.0' },
|
|
883
|
-
services: [account],
|
|
884
|
-
includeMethod: (m) => m.meta?.public === true,
|
|
885
|
-
security: {
|
|
886
|
-
schemes: {
|
|
887
|
-
apiKey: { type: 'http', scheme: 'bearer', description: 'An account API key' },
|
|
888
|
-
},
|
|
889
|
-
// Each protected scope → the schemes that satisfy it, any one of them.
|
|
890
|
-
scopes: { account: ['apiKey'] },
|
|
891
|
-
},
|
|
892
|
-
})
|
|
893
|
-
```
|
|
894
|
-
|
|
895
|
-
A scheme is `{ type: 'http', scheme: 'bearer' | 'basic' }` or
|
|
896
|
-
`{ type: 'apiKey', in: 'header' | 'query' | 'cookie', name }` (a session cookie
|
|
897
|
-
is the `cookie` form). An operation is described by the scope the auth hook
|
|
898
|
-
checks it under:
|
|
899
|
-
|
|
900
|
-
| The operation's scope | In the document |
|
|
901
|
-
|---|---|
|
|
902
|
-
| `'public'` | no `security`, no 401/403 |
|
|
903
|
-
| listed in `scopes` with schemes | `security: [{ apiKey: [] }, …]` and 401/403 |
|
|
904
|
-
| listed with an empty list — a custom scope whose rule is `'public'` | no `security`, no 401/403 |
|
|
905
|
-
| not listed | generation throws, naming the operation |
|
|
906
|
-
| none of its own | read as `defaultScope` — pass the same value as `createAuthHook({ defaultScope })` |
|
|
907
|
-
|
|
908
|
-
Generation refuses a protected scope it cannot describe instead of emitting the
|
|
909
|
-
operation as open — a client would otherwise call it without a credential. Only
|
|
910
|
-
the operations the document advertises need a mapping: a method `includeMethod`
|
|
911
|
-
filters out is never checked. A scheme `scopes` names but `schemes` does not
|
|
912
|
-
declare, and an entry for `'public'`, are refused the same way.
|
|
913
|
-
|
|
914
|
-
The metadata describes your policy; it does not enforce it. The auth hook is
|
|
915
|
-
still the only gate, and removing `security` changes the document, never a
|
|
916
|
-
401 or 403. Credential values never belong here: describe where the key goes,
|
|
917
|
-
not what it is.
|
|
918
|
-
|
|
919
|
-
==============================================================================
|
|
920
|
-
# Guide: Realtime (docs/guide/realtime.md)
|
|
921
|
-
==============================================================================
|
|
922
|
-
|
|
923
|
-
# Realtime
|
|
924
|
-
|
|
925
|
-
stitchkit's realtime layer is [Socket.IO](https://socket.io) — `polling`
|
|
926
|
-
fallback, heartbeats, acks, a mature client. stitchkit does not ship its own
|
|
927
|
-
WebSocket engine; it ships thin, typed wrappers over Socket.IO and a bridge that
|
|
928
|
-
syncs socket events into the TanStack Query cache. See
|
|
929
|
-
[ADR 0008](../decisions/0008-thin-wrappers.md).
|
|
930
|
-
The separate contract shape and rejection ownership are recorded in
|
|
931
|
-
[ADR 0069](../decisions/0069-realtime-contracts-validate-without-owning-delivery.md).
|
|
932
|
-
|
|
933
|
-
## Zod-first event contract
|
|
934
|
-
|
|
935
|
-
Declare wire events once in the shared module. Each `args` schema is a tuple, so
|
|
936
|
-
Socket.IO's no-payload and variadic forms stay intact; `ack` describes the value
|
|
937
|
-
returned through an acknowledgement callback.
|
|
938
|
-
|
|
939
|
-
```ts
|
|
940
|
-
// shared/contracts.ts
|
|
941
|
-
import { defineRealtimeContract } from 'stitchkit'
|
|
942
|
-
import { z } from 'zod'
|
|
943
|
-
|
|
944
|
-
export const realtimeContract = defineRealtimeContract({
|
|
945
|
-
serverToClient: {
|
|
946
|
-
'note:created': { args: z.tuple([NoteSchema]) },
|
|
947
|
-
'note:deleted': { args: z.tuple([z.string()]) },
|
|
948
|
-
},
|
|
949
|
-
clientToServer: {
|
|
950
|
-
'room:join': {
|
|
951
|
-
args: z.tuple([z.string()]),
|
|
952
|
-
ack: z.object({ joined: z.boolean() }),
|
|
953
|
-
},
|
|
954
|
-
ready: { args: z.tuple([]) },
|
|
955
|
-
},
|
|
956
|
-
})
|
|
957
|
-
```
|
|
958
|
-
|
|
959
|
-
The contract derives every event handler type and validates both directions at
|
|
960
|
-
runtime. A malformed inbound tuple never reaches the application handler;
|
|
961
|
-
invalid outbound data throws before Socket.IO publishes it. Rejections call the
|
|
962
|
-
optional `onRejected` hook with event, direction, phase and the Zod error.
|
|
963
|
-
|
|
964
|
-
### Protocol generations
|
|
965
|
-
|
|
966
|
-
For a distributed producer/consumer pair, put a literal generation first in the
|
|
967
|
-
first payload object. Zod validates object fields in declaration order, so an
|
|
968
|
-
incompatible peer is identified before the rest of its payload is interpreted:
|
|
969
|
-
|
|
970
|
-
```ts
|
|
971
|
-
const ReplicationMessage = z.object({
|
|
972
|
-
v: z.literal(2),
|
|
973
|
-
item: ReplicatedItem,
|
|
974
|
-
})
|
|
975
|
-
|
|
976
|
-
const realtimeContract = defineRealtimeContract({
|
|
977
|
-
serverToClient: {
|
|
978
|
-
replicated: { args: z.tuple([ReplicationMessage]) },
|
|
979
|
-
},
|
|
980
|
-
clientToServer: {},
|
|
981
|
-
})
|
|
982
|
-
```
|
|
983
|
-
|
|
984
|
-
A frame that fails this check is **refused, and the sender is told so** — when
|
|
985
|
-
the event has an acknowledgement. `request()` rejects with
|
|
986
|
-
`RealtimeRequestRejectedError`, immediately, carrying the peer's own issues:
|
|
987
|
-
|
|
988
|
-
```ts
|
|
989
|
-
import { RealtimeRequestRejectedError } from 'stitchkit'
|
|
990
|
-
|
|
991
|
-
try {
|
|
992
|
-
await socket.request('replicate', message, { timeoutMs: 5_000 })
|
|
993
|
-
} catch (error) {
|
|
994
|
-
if (error instanceof RealtimeRequestRejectedError) {
|
|
995
|
-
// reason: 'invalid-arguments'; issues: [{ path: '0.v', code: 'invalid_value', … }]
|
|
996
|
-
if (error.issues?.some((issue) => issue.path === '0.v')) schedulePeerUpgrade()
|
|
997
|
-
else reportMalformedRealtimePayload(error)
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
```
|
|
1001
|
-
|
|
1002
|
-
`path` is `'0.v'` and not `'v'` because event arguments are a tuple: index `0`
|
|
1003
|
-
is the first payload. The issues are already flattened by StitchKit's own
|
|
1004
|
-
normaliser, so telling "wrong generation" from "malformed payload" is one
|
|
1005
|
-
comparison rather than an inspection of a `ZodError`'s internals.
|
|
1006
|
-
|
|
1007
|
-
The receiving side still reports it locally through `onRejected` — a refusal is
|
|
1008
|
-
now visible on **both** ends rather than only where it happened.
|
|
1009
|
-
|
|
1010
|
-
**Two limits, both real.** A **fire-and-forget** event has no acknowledgement
|
|
1011
|
-
channel, so its refusal stays local: the sender learns nothing, and no
|
|
1012
|
-
convention in the payload can change that. And an event the receiver's contract
|
|
1013
|
-
does not contain has no listener at all, so there is nothing on that side to
|
|
1014
|
-
answer with — adding an event is not a change a generation field can announce.
|
|
1015
|
-
|
|
1016
|
-
### Where protocol identity belongs
|
|
1017
|
-
|
|
1018
|
-
For a distributed pair whose planes are mostly fire-and-forget, compare
|
|
1019
|
-
identity **at the handshake** instead, where a mismatch is refused before the
|
|
1020
|
-
first frame is interpreted and both ends see it at once. The typed handshake is
|
|
1021
|
-
already the place:
|
|
1022
|
-
|
|
1023
|
-
```ts
|
|
1024
|
-
const handshake = {
|
|
1025
|
-
schema: z.object({ token: z.string(), protocol: z.string() }),
|
|
1026
|
-
verify: (auth) => {
|
|
1027
|
-
if (auth.protocol !== PROTOCOL_IDENTITY) return null // refused, with a reason
|
|
1028
|
-
return { subject: verifyToken(auth.token) }
|
|
1029
|
-
},
|
|
1030
|
-
}
|
|
1031
|
-
```
|
|
1032
|
-
|
|
1033
|
-
The client sends it as `auth`, and a rejection reaches `onConnectError` with
|
|
1034
|
-
`terminal: true` — distinguishable in a log from a bad token, so a half-rolled
|
|
1035
|
-
deployment reads as a half-rolled deployment and not as an access problem.
|
|
1036
|
-
|
|
1037
|
-
What that identity *is* remains the application's decision — a build version, a
|
|
1038
|
-
contract hash, a protocol generation. StitchKit does not compare it for you
|
|
1039
|
-
(→ ADR 0002); it gives the place where the comparison happens before any frame
|
|
1040
|
-
is interpreted, and it makes the per-frame alternative honest by letting its
|
|
1041
|
-
refusals be seen.
|