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
package/llms/server.3.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# stitchkit/server — stitchkit docs slice, part 3 of
|
|
1
|
+
# stitchkit/server — stitchkit docs slice, part 3 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,18 +6,254 @@
|
|
|
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
|
|
16
17
|
|
|
17
18
|
==============================================================================
|
|
18
|
-
# Guide:
|
|
19
|
+
# Guide: HTTP server (docs/guide/server.md) (continued)
|
|
19
20
|
==============================================================================
|
|
20
21
|
|
|
22
|
+
## OpenAPI
|
|
23
|
+
|
|
24
|
+
`generateOpenApiDocument` builds an OpenAPI 3.1 document straight from the
|
|
25
|
+
contracts — the contract *is* the spec, no decorators or hand-maintained
|
|
26
|
+
annotations (→ ADR 0018). `openApiRoute` serves it as a raw route:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { generateOpenApiDocument, openApiRoute } from 'stitchkit/server'
|
|
30
|
+
|
|
31
|
+
const doc = generateOpenApiDocument({
|
|
32
|
+
info: { title: 'My API', version: '1.0.0' },
|
|
33
|
+
services: [users, orders],
|
|
34
|
+
})
|
|
35
|
+
createServer({ services: [users, orders], rawRoutes: [openApiRoute('/openapi.json', doc)] })
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Only HTTP-exposed methods appear (an MCP/agent-only tool is skipped).
|
|
39
|
+
|
|
40
|
+
OpenAPI 3.1 has no standard multi-segment path parameter. For a contract path
|
|
41
|
+
ending in a named wildcard such as `/*filePath`, StitchKit keeps the literal
|
|
42
|
+
runtime path, omits `filePath` from the
|
|
43
|
+
standard `in: path` parameter list, and emits
|
|
44
|
+
`x-stitchkit-trailing-wildcard` on the operation with its parameter name,
|
|
45
|
+
schema and semantics. A generic OpenAPI client therefore cannot invent
|
|
46
|
+
catch-all expansion; use StitchKit's typed client or teach the generator that
|
|
47
|
+
extension.
|
|
48
|
+
|
|
49
|
+
### Curating the spec — `includeMethod`
|
|
50
|
+
|
|
51
|
+
To publish a **subset** — a public spec that advertises only some methods
|
|
52
|
+
without revealing the rest — pass `includeMethod`. It keeps the core generic:
|
|
53
|
+
*you* decide the policy, filtering on anything the method carries. The
|
|
54
|
+
recommended declarative allowlist marks endpoints with the existing `meta`
|
|
55
|
+
passthrough and keeps those:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// contract — declarative, one source of truth
|
|
59
|
+
getBalance: { method: 'GET', path: '/balance', desc: '…', scope: 'account',
|
|
60
|
+
meta: { public: true }, output: BalanceSchema }
|
|
61
|
+
|
|
62
|
+
// generation — the app's policy
|
|
63
|
+
const publicDoc = generateOpenApiDocument({
|
|
64
|
+
info: { title: 'Public API', version: '1.0.0' },
|
|
65
|
+
services: [account],
|
|
66
|
+
includeMethod: (m) => m.meta?.public === true,
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
An excluded method's whole entry — path *and* every schema inlined within it —
|
|
71
|
+
is simply never emitted, so nothing about a hidden endpoint leaks.
|
|
72
|
+
|
|
73
|
+
> **The filter advertises; it does not authorize.** Hiding a method from the
|
|
74
|
+
> spec does **not** protect it — it is still callable, and the auth `scope` gate
|
|
75
|
+
> is the only thing guarding it. And because `openApiRoute` closes over the
|
|
76
|
+
> document you hand it, the filter only matters if you feed it a filtered one:
|
|
77
|
+
> serve **two** documents — a full internal spec and a filtered public spec on
|
|
78
|
+
> separate routes — never one unfiltered `openApiRoute` on a public path.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const internal = openApiRoute('/internal/openapi.json', fullDoc) // behind auth
|
|
82
|
+
const publicSpec = openApiRoute('/openapi.json', publicDoc) // curated
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Security schemes — `security`
|
|
86
|
+
|
|
87
|
+
A generic client reads the spec to learn how to authenticate, and a scope name
|
|
88
|
+
alone does not tell it which header to send. Pass `security` to describe that in
|
|
89
|
+
standard OpenAPI terms: named schemes become `components.securitySchemes`, and
|
|
90
|
+
every protected operation gets a `security` requirement. It is keyed by the
|
|
91
|
+
scopes your contracts already declare, so there is no second list of which
|
|
92
|
+
endpoint is protected:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const publicDoc = generateOpenApiDocument({
|
|
96
|
+
info: { title: 'Public API', version: '1.0.0' },
|
|
97
|
+
services: [account],
|
|
98
|
+
includeMethod: (m) => m.meta?.public === true,
|
|
99
|
+
security: {
|
|
100
|
+
schemes: {
|
|
101
|
+
apiKey: { type: 'http', scheme: 'bearer', description: 'An account API key' },
|
|
102
|
+
},
|
|
103
|
+
// Each protected scope → the schemes that satisfy it, any one of them.
|
|
104
|
+
scopes: { account: ['apiKey'] },
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
A scheme is `{ type: 'http', scheme: 'bearer' | 'basic' }` or
|
|
110
|
+
`{ type: 'apiKey', in: 'header' | 'query' | 'cookie', name }` (a session cookie
|
|
111
|
+
is the `cookie` form). An operation is described by the scope the auth hook
|
|
112
|
+
checks it under:
|
|
113
|
+
|
|
114
|
+
| The operation's scope | In the document |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `'public'` | no `security`, no 401/403 |
|
|
117
|
+
| listed in `scopes` with schemes | `security: [{ apiKey: [] }, …]` and 401/403 |
|
|
118
|
+
| listed with an empty list — a custom scope whose rule is `'public'` | no `security`, no 401/403 |
|
|
119
|
+
| not listed | generation throws, naming the operation |
|
|
120
|
+
| none of its own | read as `defaultScope` — pass the same value as `createAuthHook({ defaultScope })` |
|
|
121
|
+
|
|
122
|
+
Generation refuses a protected scope it cannot describe instead of emitting the
|
|
123
|
+
operation as open — a client would otherwise call it without a credential. Only
|
|
124
|
+
the operations the document advertises need a mapping: a method `includeMethod`
|
|
125
|
+
filters out is never checked. A scheme `scopes` names but `schemes` does not
|
|
126
|
+
declare, and an entry for `'public'`, are refused the same way.
|
|
127
|
+
|
|
128
|
+
The metadata describes your policy; it does not enforce it. The auth hook is
|
|
129
|
+
still the only gate, and removing `security` changes the document, never a
|
|
130
|
+
401 or 403. Credential values never belong here: describe where the key goes,
|
|
131
|
+
not what it is.
|
|
132
|
+
|
|
133
|
+
==============================================================================
|
|
134
|
+
# Guide: Realtime (docs/guide/realtime.md)
|
|
135
|
+
==============================================================================
|
|
136
|
+
|
|
137
|
+
# Realtime
|
|
138
|
+
|
|
139
|
+
stitchkit's realtime layer is [Socket.IO](https://socket.io) — `polling`
|
|
140
|
+
fallback, heartbeats, acks, a mature client. stitchkit does not ship its own
|
|
141
|
+
WebSocket engine; it ships thin, typed wrappers over Socket.IO and a bridge that
|
|
142
|
+
syncs socket events into the TanStack Query cache. See
|
|
143
|
+
[ADR 0008](../decisions/0008-thin-wrappers.md).
|
|
144
|
+
The separate contract shape and rejection ownership are recorded in
|
|
145
|
+
[ADR 0069](../decisions/0069-realtime-contracts-validate-without-owning-delivery.md).
|
|
146
|
+
|
|
147
|
+
## Zod-first event contract
|
|
148
|
+
|
|
149
|
+
Declare wire events once in the shared module. Each `args` schema is a tuple, so
|
|
150
|
+
Socket.IO's no-payload and variadic forms stay intact; `ack` describes the value
|
|
151
|
+
returned through an acknowledgement callback.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
// shared/contracts.ts
|
|
155
|
+
import { defineRealtimeContract } from 'stitchkit'
|
|
156
|
+
import { z } from 'zod'
|
|
157
|
+
|
|
158
|
+
export const realtimeContract = defineRealtimeContract({
|
|
159
|
+
serverToClient: {
|
|
160
|
+
'note:created': { args: z.tuple([NoteSchema]) },
|
|
161
|
+
'note:deleted': { args: z.tuple([z.string()]) },
|
|
162
|
+
},
|
|
163
|
+
clientToServer: {
|
|
164
|
+
'room:join': {
|
|
165
|
+
args: z.tuple([z.string()]),
|
|
166
|
+
ack: z.object({ joined: z.boolean() }),
|
|
167
|
+
},
|
|
168
|
+
ready: { args: z.tuple([]) },
|
|
169
|
+
},
|
|
170
|
+
})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The contract derives every event handler type and validates both directions at
|
|
174
|
+
runtime. A malformed inbound tuple never reaches the application handler;
|
|
175
|
+
invalid outbound data throws before Socket.IO publishes it. Rejections call the
|
|
176
|
+
optional `onRejected` hook with event, direction, phase and the Zod error.
|
|
177
|
+
|
|
178
|
+
### Protocol generations
|
|
179
|
+
|
|
180
|
+
For a distributed producer/consumer pair, put a literal generation first in the
|
|
181
|
+
first payload object. Zod validates object fields in declaration order, so an
|
|
182
|
+
incompatible peer is identified before the rest of its payload is interpreted:
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
const ReplicationMessage = z.object({
|
|
186
|
+
v: z.literal(2),
|
|
187
|
+
item: ReplicatedItem,
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
const realtimeContract = defineRealtimeContract({
|
|
191
|
+
serverToClient: {
|
|
192
|
+
replicated: { args: z.tuple([ReplicationMessage]) },
|
|
193
|
+
},
|
|
194
|
+
clientToServer: {},
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
A frame that fails this check is **refused, and the sender is told so** — when
|
|
199
|
+
the event has an acknowledgement. `request()` rejects with
|
|
200
|
+
`RealtimeRequestRejectedError`, immediately, carrying the peer's own issues:
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
import { RealtimeRequestRejectedError } from 'stitchkit'
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
await socket.request('replicate', message, { timeoutMs: 5_000 })
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (error instanceof RealtimeRequestRejectedError) {
|
|
209
|
+
// reason: 'invalid-arguments'; issues: [{ path: '0.v', code: 'invalid_value', … }]
|
|
210
|
+
if (error.issues?.some((issue) => issue.path === '0.v')) schedulePeerUpgrade()
|
|
211
|
+
else reportMalformedRealtimePayload(error)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
`path` is `'0.v'` and not `'v'` because event arguments are a tuple: index `0`
|
|
217
|
+
is the first payload. The issues are already flattened by StitchKit's own
|
|
218
|
+
normaliser, so telling "wrong generation" from "malformed payload" is one
|
|
219
|
+
comparison rather than an inspection of a `ZodError`'s internals.
|
|
220
|
+
|
|
221
|
+
The receiving side still reports it locally through `onRejected` — a refusal is
|
|
222
|
+
now visible on **both** ends rather than only where it happened.
|
|
223
|
+
|
|
224
|
+
**Two limits, both real.** A **fire-and-forget** event has no acknowledgement
|
|
225
|
+
channel, so its refusal stays local: the sender learns nothing, and no
|
|
226
|
+
convention in the payload can change that. And an event the receiver's contract
|
|
227
|
+
does not contain has no listener at all, so there is nothing on that side to
|
|
228
|
+
answer with — adding an event is not a change a generation field can announce.
|
|
229
|
+
|
|
230
|
+
### Where protocol identity belongs
|
|
231
|
+
|
|
232
|
+
For a distributed pair whose planes are mostly fire-and-forget, compare
|
|
233
|
+
identity **at the handshake** instead, where a mismatch is refused before the
|
|
234
|
+
first frame is interpreted and both ends see it at once. The typed handshake is
|
|
235
|
+
already the place:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const handshake = {
|
|
239
|
+
schema: z.object({ token: z.string(), protocol: z.string() }),
|
|
240
|
+
verify: (auth) => {
|
|
241
|
+
if (auth.protocol !== PROTOCOL_IDENTITY) return null // refused, with a reason
|
|
242
|
+
return { subject: verifyToken(auth.token) }
|
|
243
|
+
},
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The client sends it as `auth`, and a rejection reaches `onConnectError` with
|
|
248
|
+
`terminal: true` — distinguishable in a log from a bad token, so a half-rolled
|
|
249
|
+
deployment reads as a half-rolled deployment and not as an access problem.
|
|
250
|
+
|
|
251
|
+
What that identity *is* remains the application's decision — a build version, a
|
|
252
|
+
contract hash, a protocol generation. StitchKit does not compare it for you
|
|
253
|
+
(→ ADR 0002); it gives the place where the comparison happens before any frame
|
|
254
|
+
is interpreted, and it makes the per-frame alternative honest by letting its
|
|
255
|
+
refusals be seen.
|
|
256
|
+
|
|
21
257
|
## Server — `createSocketIOServer`
|
|
22
258
|
|
|
23
259
|
```ts
|
|
@@ -874,199 +1110,3 @@ Notes:
|
|
|
874
1110
|
global — keep `idleTimeout` ≥ Socket.IO needs (> 2 × `pingInterval`).
|
|
875
1111
|
- For high throughput, handle backpressure in the raw lane: `ws.send()` returns
|
|
876
1112
|
`-1` under pressure; resume on the `drain` callback.
|
|
877
|
-
|
|
878
|
-
## Bring-your-own transport
|
|
879
|
-
|
|
880
|
-
Sometimes the transport is neither HTTP nor Socket.IO — a desktop app whose UI
|
|
881
|
-
webview talks to its own local Bun sidecar over a raw WebSocket, an IPC channel,
|
|
882
|
-
a queue worker. You can still drive it from one `defineContract`: share the
|
|
883
|
-
contract's Zod schemas to validate each inbound frame, run your handlers, and
|
|
884
|
-
reuse the contract metadata below. You own **both** the wire (framing,
|
|
885
|
-
handshake, reconnect) *and* the per-call validate-run loop — stitchkit ships the
|
|
886
|
-
contract and its metadata, not a transport engine. A reliable-RPC-over-raw-
|
|
887
|
-
WebSocket engine would be a competing WebSocket transport
|
|
888
|
-
([ADR 0008](../decisions/0008-thin-wrappers.md)); the wire stays yours.
|
|
889
|
-
|
|
890
|
-
Two pieces of the contract carry straight over to a bring-your-own lane:
|
|
891
|
-
|
|
892
|
-
- **`source` is an open tag.** `TransportSource` is `'http' | 'mcp' | 'agent' |
|
|
893
|
-
'cli' | (string & {})`, so a handler or hook can tell your transport's calls
|
|
894
|
-
apart — tag them `source: 'local-ws'` and read `ctx.source`.
|
|
895
|
-
- **`idempotent` drives replay-on-reconnect** — see below.
|
|
896
|
-
|
|
897
|
-
### Durability — `idempotent` + replay
|
|
898
|
-
|
|
899
|
-
If the sidecar can restart mid-call, the client decides what to do with an
|
|
900
|
-
in-flight request on reconnect from the operation's **idempotency**, declared on
|
|
901
|
-
the contract:
|
|
902
|
-
|
|
903
|
-
```ts
|
|
904
|
-
export const runtimeContract = defineContract({ prefix: 'runtime' }, {
|
|
905
|
-
'tasks.setDone': { method: 'POST', path: '/done', desc: '…',
|
|
906
|
-
idempotent: true, input: taskDone, output: ok }, // re-send after reconnect — same result
|
|
907
|
-
'capture.start': { method: 'POST', path: '/start', desc: '…',
|
|
908
|
-
output: snapshot }, // unset → one-shot, do not re-send
|
|
909
|
-
})
|
|
910
|
-
```
|
|
911
|
-
|
|
912
|
-
`idempotent` rides through to `MethodDef.idempotent`; the core attaches no
|
|
913
|
-
behaviour. Your reconnect logic reads it: replay an idempotent call (the
|
|
914
|
-
durability guarantee — the user's action is not lost), reject a non-idempotent
|
|
915
|
-
one rather than fire a second side effect. Pair it with
|
|
916
|
-
[sticky events](#sticky-events) (`createRetainedTopics`) so a reconnected client
|
|
917
|
-
also catches up on the latest pushed state.
|
|
918
|
-
|
|
919
|
-
This is deliberately *not* a reliable-RPC engine — that would be a competing
|
|
920
|
-
WebSocket transport ([ADR 0008](../decisions/0008-thin-wrappers.md)). stitchkit
|
|
921
|
-
gives you the contract and the metadata (`idempotent`, the open `source` tag,
|
|
922
|
-
`createRetainedTopics`); the wire and the per-call execution stay yours. See
|
|
923
|
-
[ADR 0028](../decisions/0028-revert-contract-dispatcher.md).
|
|
924
|
-
|
|
925
|
-
## Authenticated room registry and replay
|
|
926
|
-
|
|
927
|
-
`bindSocketRegistry` composes over `bindRealtimeServer`; it never authenticates
|
|
928
|
-
a socket a second time and never creates another outbound validator. The
|
|
929
|
-
identity in `connection.raw.data` has already passed the Socket.IO handshake.
|
|
930
|
-
|
|
931
|
-
`rooms(identity)` names the rooms a connecting identity may be in; the registry
|
|
932
|
-
joins them and refuses a later `join` to any other. The disconnect listener is
|
|
933
|
-
attached before that lookup is awaited, so a socket that drops while its
|
|
934
|
-
permissions are still being resolved never becomes a member. `registry.room(name)` mints
|
|
935
|
-
the opaque `AuthorizedSocketRoom` for a name — the token proves the name came
|
|
936
|
-
through this registry, not that anyone is in the room, so a room with no open
|
|
937
|
-
tab is an ordinary `emitTo` target that reports zero recipients. The registry
|
|
938
|
-
owns join/leave, multiple sockets per identity, immutable snapshots and
|
|
939
|
-
listener cleanup.
|
|
940
|
-
|
|
941
|
-
Replay is revisioned: while a socket's snapshot is open, frames sent through
|
|
942
|
-
`emitTo` to its rooms are held back and delivered after the snapshot, so the
|
|
943
|
-
socket never sees a delta for state its snapshot already contains, nor a
|
|
944
|
-
snapshot that predates a delta it already received. A snapshot taken across a
|
|
945
|
-
`revision` change is retried up to `replayAttempts` (default 3). The hold-back buffer is
|
|
946
|
-
bounded by `maxBufferedFrames` (default 1000): past it the attempt is abandoned
|
|
947
|
-
and retried, and when the attempts are spent `onResyncRequired(socketId,
|
|
948
|
-
identity)` fires with nothing half-delivered — the application decides what a
|
|
949
|
-
resync means for that socket. A retry relies on the fresh snapshot carrying
|
|
950
|
-
what the abandoned frames carried, which holds when every emitted change also
|
|
951
|
-
moves `revision`; without a `revision` the registry has no way to tell, so
|
|
952
|
-
declare one wherever replay matters. Room tokens are recognised, not
|
|
953
|
-
remembered: a token the application keeps stays valid for the life of the
|
|
954
|
-
registry, and a name seen once does not live on in a map. This ordering exists only for frames that go
|
|
955
|
-
through `emitTo`; a broadcast through `realtime.to(room).emit` reaches the
|
|
956
|
-
socket immediately, replay or not, so keep room traffic whose order matters
|
|
957
|
-
relative to the snapshot on the registry.
|
|
958
|
-
|
|
959
|
-
## Session-scoped watches and query cache
|
|
960
|
-
|
|
961
|
-
Pass the captured login operation as `createWatchClient(contract, { transport,
|
|
962
|
-
session })`. It adds a lifetime nonce to watch keys and detaches on invalidation;
|
|
963
|
-
a late frame for a previous login cannot match a new client's key on the same socket.
|
|
964
|
-
Both client and server must support the new optional `WatchKey.instance` field.
|
|
965
|
-
The nonce is not authorization: the server still admits a verified identity and
|
|
966
|
-
uses `hub.attach(subscriber, { key: verifiedScope, signal: revocationSignal })`.
|
|
967
|
-
The scope key must change with session and permission boundaries.
|
|
968
|
-
|
|
969
|
-
One scope and one question share one source and one read, however many client
|
|
970
|
-
instances watch it: the hub routes each frame to every instance under its own
|
|
971
|
-
key. A new tab of the same session costs a route, not a read.
|
|
972
|
-
|
|
973
|
-
### Capacity
|
|
974
|
-
|
|
975
|
-
A hub admits at most `maxSources` sources (1024) and `maxSubscribers` attached
|
|
976
|
-
subscribers (1024); a client holds at most `maxKeys` keys (1024) and
|
|
977
|
-
`maxListenersPerKey` listeners per key (128). Every excess is a refusal, never
|
|
978
|
-
unbounded state: `open` answers `{ accepted: false, reason }` — including for a
|
|
979
|
-
subscriber attached over capacity, whose `attach` returns a watcher that refuses
|
|
980
|
-
every `open` — and a client's `subscribe` throws. A client handle takes its key
|
|
981
|
-
when it subscribes, so handles a render creates and never subscribes cost
|
|
982
|
-
nothing. A connection handler that throws closes that connection and is logged;
|
|
983
|
-
the server goes on. A subscriber attached over capacity is not tracked: its
|
|
984
|
-
refusals stand until it reconnects.
|
|
985
|
-
|
|
986
|
-
A read that fails sends its subscribers `unavailable` / `source-error` with the
|
|
987
|
-
`code` and `message` of an `AppError`, which is written for its caller. Any other
|
|
988
|
-
error reaches only the hub's `logger`; the browser reads `The watched read failed`. Set larger finite limits for larger workloads, and
|
|
989
|
-
`reconcileIntervalMs` when a lost invalidation must recover without a reconnect.
|
|
990
|
-
|
|
991
|
-
`createCacheBridge` can bind watched handles directly:
|
|
992
|
-
|
|
993
|
-
```ts
|
|
994
|
-
const bridge = createCacheBridge({
|
|
995
|
-
socket, queryClient, handlers: {}, session,
|
|
996
|
-
watched: [{
|
|
997
|
-
handle: watches.list({ folderId }),
|
|
998
|
-
queryKey: ['items', session.id, folderId],
|
|
999
|
-
state: frame => showWatchState(frame),
|
|
1000
|
-
}],
|
|
1001
|
-
})
|
|
1002
|
-
bridge.connect()
|
|
1003
|
-
```
|
|
1004
|
-
|
|
1005
|
-
A value updates that exact query; non-live state marks it stale while retaining its
|
|
1006
|
-
value. The existing phases (`opening`, `live`, `unavailable`, `resync-required`)
|
|
1007
|
-
remain the status model. Do not replace unavailable data with an empty collection.
|
|
1008
|
-
Session invalidation removes bound queries. Include the session identity in query
|
|
1009
|
-
keys and guard any application-level side effects with that same operation.
|
|
1010
|
-
|
|
1011
|
-
Use existing shared watches for paginated lists and selected-detail queries; bind
|
|
1012
|
-
each exact argument set to its query key. No global domain/query registry or new
|
|
1013
|
-
UI components are needed. Reconnect and revision/delta recovery remain owned by the
|
|
1014
|
-
watch client; silent lost notifications are repaired by hub reconciliation.
|
|
1015
|
-
|
|
1016
|
-
## Account-scoped device presence
|
|
1017
|
-
|
|
1018
|
-
When an account spans multiple online devices (desktop, mobile, web) that advertise typed
|
|
1019
|
-
capability state and accept targeted remote commands, mount device presence onto your existing
|
|
1020
|
-
`RealtimeServerHandle` instead of opening a second connection:
|
|
1021
|
-
|
|
1022
|
-
```ts
|
|
1023
|
-
// shared/presence.ts
|
|
1024
|
-
import { createDevicePresenceContract } from 'stitchkit/realtime'
|
|
1025
|
-
import { z } from 'zod'
|
|
1026
|
-
|
|
1027
|
-
export const devicePresence = createDevicePresenceContract({
|
|
1028
|
-
mic: {
|
|
1029
|
-
state: z.strictObject({ recording: z.boolean() }),
|
|
1030
|
-
command: z.discriminatedUnion('action', [
|
|
1031
|
-
z.strictObject({ action: z.literal('start') }),
|
|
1032
|
-
z.strictObject({ action: z.literal('stop') }),
|
|
1033
|
-
]),
|
|
1034
|
-
result: z.strictObject({ recording: z.boolean() }),
|
|
1035
|
-
},
|
|
1036
|
-
})
|
|
1037
|
-
|
|
1038
|
-
// server (stitchkit/server)
|
|
1039
|
-
import { bindDevicePresence } from 'stitchkit/server'
|
|
1040
|
-
|
|
1041
|
-
const presence = bindDevicePresence(devicePresence, socket, {
|
|
1042
|
-
accountOf: (identity) => identity.userId ?? null, // null refuses non-user principals
|
|
1043
|
-
})
|
|
1044
|
-
// Call presence.readmit(socketId) after logout or permission changes to evict immediately.
|
|
1045
|
-
|
|
1046
|
-
// device client (stitchkit/realtime)
|
|
1047
|
-
import { createDevicePresenceClient } from 'stitchkit/realtime'
|
|
1048
|
-
|
|
1049
|
-
const client = createDevicePresenceClient(devicePresence, {
|
|
1050
|
-
transport,
|
|
1051
|
-
device: { deviceId: 'desktop-1', name: 'Desktop', platform: 'macos' },
|
|
1052
|
-
capabilities: ['mic'],
|
|
1053
|
-
initialStates: { mic: { recording: false } },
|
|
1054
|
-
})
|
|
1055
|
-
|
|
1056
|
-
const offMic = client.onCommand('mic', async (command) => ({
|
|
1057
|
-
recording: command.action === 'start',
|
|
1058
|
-
}))
|
|
1059
|
-
|
|
1060
|
-
// Send a typed command from another device in the same account:
|
|
1061
|
-
const ack = await client.sendCommand({
|
|
1062
|
-
targetDeviceId: 'desktop-1',
|
|
1063
|
-
capability: 'mic',
|
|
1064
|
-
command: { action: 'stop' },
|
|
1065
|
-
})
|
|
1066
|
-
```
|
|
1067
|
-
|
|
1068
|
-
Each account's online device list is versioned (`revision`), capacity-bounded
|
|
1069
|
-
(`maxDevicesPerAccount`), and scoped strictly to `accountOf(handshakeIdentity)`. Local capability
|
|
1070
|
-
states are republished automatically after reconnect (`publishState(capability, state | null)`),
|
|
1071
|
-
and `createDevicePresenceRelayAdapter` in `stitchkit/realtime` can mirror a `DeviceRelayAgent`'s
|
|
1072
|
-
liveness into a `DevicePresenceRelayStateSchema` capability slot.
|