stitchkit 0.99.0 → 0.100.1

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.
Files changed (147) hide show
  1. package/CHANGELOG.md +124 -1
  2. package/dist/agent-runtime/contained-darwin.d.ts +0 -17
  3. package/dist/agent-runtime/contained-darwin.d.ts.map +1 -1
  4. package/dist/agent-runtime/contained-write.d.ts.map +1 -1
  5. package/dist/agent-runtime/invocation-attempt.d.ts +28 -0
  6. package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -0
  7. package/dist/agent-runtime/invocation-failure.d.ts +6 -0
  8. package/dist/agent-runtime/invocation-failure.d.ts.map +1 -0
  9. package/dist/agent-runtime/invocation-payload.d.ts +20 -0
  10. package/dist/agent-runtime/invocation-payload.d.ts.map +1 -0
  11. package/dist/agent-runtime/invocation-read.d.ts +131 -0
  12. package/dist/agent-runtime/invocation-read.d.ts.map +1 -0
  13. package/dist/agent-runtime/invocation-schema.d.ts +378 -0
  14. package/dist/agent-runtime/invocation-schema.d.ts.map +1 -0
  15. package/dist/agent-runtime/invocations.d.ts +52 -0
  16. package/dist/agent-runtime/invocations.d.ts.map +1 -0
  17. package/dist/agent-runtime/projections.d.ts.map +1 -1
  18. package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
  19. package/dist/agent-runtime/run-execution-state.d.ts +4 -2
  20. package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
  21. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  22. package/dist/agent-runtime/run-failure.d.ts.map +1 -1
  23. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
  24. package/dist/agent-runtime/run-operation-lifecycle.d.ts +2 -2
  25. package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +1 -1
  26. package/dist/agent-runtime/run-provider-ledger.d.ts +1 -0
  27. package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
  28. package/dist/agent-runtime/runtime.d.ts +11 -0
  29. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  30. package/dist/agent-runtime/schedule-dispatch.d.ts +9 -2
  31. package/dist/agent-runtime/schedule-dispatch.d.ts.map +1 -1
  32. package/dist/agent-runtime/schedule-records.d.ts +8 -2
  33. package/dist/agent-runtime/schedule-records.d.ts.map +1 -1
  34. package/dist/agent-runtime/schedules.d.ts +5 -0
  35. package/dist/agent-runtime/schedules.d.ts.map +1 -1
  36. package/dist/agent-runtime/sqlite-events.d.ts.map +1 -1
  37. package/dist/agent-runtime/store-create.d.ts.map +1 -1
  38. package/dist/agent-runtime/store-driver-contract.d.ts +9 -0
  39. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
  40. package/dist/agent-runtime/store-event-once.d.ts +37 -0
  41. package/dist/agent-runtime/store-event-once.d.ts.map +1 -0
  42. package/dist/agent-runtime/store-memory.d.ts.map +1 -1
  43. package/dist/agent-runtime/store.d.ts +11 -0
  44. package/dist/agent-runtime/store.d.ts.map +1 -1
  45. package/dist/application/change-subscription.d.ts +36 -0
  46. package/dist/application/change-subscription.d.ts.map +1 -0
  47. package/dist/application/diagnostic-journal-contract.d.ts +3 -6
  48. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  49. package/dist/application/notification-delivery.d.ts +55 -0
  50. package/dist/application/notification-delivery.d.ts.map +1 -0
  51. package/dist/application/notification-outbox-state.d.ts +41 -0
  52. package/dist/application/notification-outbox-state.d.ts.map +1 -0
  53. package/dist/application/notification-outbox.d.ts +7 -1
  54. package/dist/application/notification-outbox.d.ts.map +1 -1
  55. package/dist/application/watch-hub-core.d.ts +14 -84
  56. package/dist/application/watch-hub-core.d.ts.map +1 -1
  57. package/dist/application/watch-hub-source.d.ts +98 -0
  58. package/dist/application/watch-hub-source.d.ts.map +1 -0
  59. package/dist/application/watch-hub.d.ts +10 -2
  60. package/dist/application/watch-hub.d.ts.map +1 -1
  61. package/dist/browser/session-credentials.d.ts +26 -0
  62. package/dist/browser/session-credentials.d.ts.map +1 -0
  63. package/dist/browser/session.d.ts +33 -0
  64. package/dist/browser/session.d.ts.map +1 -0
  65. package/dist/durability/events.d.ts +6 -0
  66. package/dist/durability/events.d.ts.map +1 -1
  67. package/dist/entrypoints/agent-runtime/coding-tools.js +3 -2
  68. package/dist/entrypoints/agent-runtime/harness.js +5 -3
  69. package/dist/entrypoints/agent-runtime/sandbox.js +3 -2
  70. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  71. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  72. package/dist/entrypoints/agent-runtime/testing.js +3 -3
  73. package/dist/entrypoints/agent-runtime.d.ts +3 -0
  74. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  75. package/dist/entrypoints/agent-runtime.js +65 -20
  76. package/dist/entrypoints/application/diagnostic-journal.js +2 -1
  77. package/dist/entrypoints/application.d.ts +3 -1
  78. package/dist/entrypoints/application.d.ts.map +1 -1
  79. package/dist/entrypoints/application.js +820 -294
  80. package/dist/entrypoints/files.js +9 -2
  81. package/dist/entrypoints/index.d.ts +2 -0
  82. package/dist/entrypoints/index.d.ts.map +1 -1
  83. package/dist/entrypoints/index.js +199 -0
  84. package/dist/entrypoints/live.js +78 -19
  85. package/dist/entrypoints/node.js +1 -1
  86. package/dist/entrypoints/react.d.ts +1 -1
  87. package/dist/entrypoints/react.d.ts.map +1 -1
  88. package/dist/entrypoints/react.js +59 -16
  89. package/dist/entrypoints/server.js +4 -4
  90. package/dist/{index-sp1tzwnb.js → index-10x2hbx0.js} +5 -2
  91. package/dist/{index-8p52kd5p.js → index-c6bxbsnc.js} +100 -14
  92. package/dist/{index-gxrt5h6v.js → index-cyktc4bp.js} +3 -0
  93. package/dist/{index-1m2thnq0.js → index-eaysmdtq.js} +11 -2
  94. package/dist/{index-jhx828hc.js → index-f4fx2tza.js} +948 -279
  95. package/dist/{index-px2gm2jp.js → index-fhwqwxe0.js} +17 -55
  96. package/dist/{index-e4hkgm5t.js → index-gw8bmyaj.js} +4 -2
  97. package/dist/{index-p3vsv1fb.js → index-hadmp193.js} +14 -5
  98. package/dist/{index-wt743f7f.js → index-k6gpggb9.js} +2 -1
  99. package/dist/index-q3pyb9n0.js +22 -0
  100. package/dist/{index-wsm5w4ee.js → index-vqr7f7v8.js} +51 -3
  101. package/dist/index-zjjyynm3.js +42 -0
  102. package/dist/internal/coalesced-task.d.ts +17 -0
  103. package/dist/internal/coalesced-task.d.ts.map +1 -0
  104. package/dist/internal/darwin-binding.d.ts +19 -0
  105. package/dist/internal/darwin-binding.d.ts.map +1 -0
  106. package/dist/internal/exclusive-lock.d.ts +20 -7
  107. package/dist/internal/exclusive-lock.d.ts.map +1 -1
  108. package/dist/internal/mutation-queue.d.ts +4 -0
  109. package/dist/internal/mutation-queue.d.ts.map +1 -0
  110. package/dist/internal/process-identity.d.ts +1 -1
  111. package/dist/internal/process-identity.d.ts.map +1 -1
  112. package/dist/internal/process-instance.d.ts +26 -0
  113. package/dist/internal/process-instance.d.ts.map +1 -0
  114. package/dist/internal/with-exclusive-lock.d.ts.map +1 -1
  115. package/dist/live/watch-client-state.d.ts +71 -0
  116. package/dist/live/watch-client-state.d.ts.map +1 -0
  117. package/dist/live/watch-client.d.ts +5 -1
  118. package/dist/live/watch-client.d.ts.map +1 -1
  119. package/dist/live/watch-contract.d.ts +12 -0
  120. package/dist/live/watch-contract.d.ts.map +1 -1
  121. package/dist/react/cache-bridge.d.ts +10 -0
  122. package/dist/react/cache-bridge.d.ts.map +1 -1
  123. package/dist/server/realtime.d.ts.map +1 -1
  124. package/llms/agent-runtime.2.txt +102 -0
  125. package/llms/agent-runtime.3.txt +30 -1
  126. package/llms/agent-runtime.txt +8 -3
  127. package/llms/application.2.txt +84 -2
  128. package/llms/application.txt +32 -2
  129. package/llms/files.txt +1 -1
  130. package/llms/live.txt +8 -0
  131. package/llms/react.txt +8 -0
  132. package/llms/server.3.txt +57 -0
  133. package/llms/stitchkit.2.txt +41 -0
  134. package/llms/stitchkit.3.txt +26 -0
  135. package/llms/stitchkit.txt +3 -3
  136. package/llms/upgrading-0.37.0.txt +176 -0
  137. package/llms/{upgrading-0.37.0-0.58.0.txt → upgrading-0.44.0-0.60.0.txt} +229 -169
  138. package/llms/{upgrading-0.59.0-0.71.0.txt → upgrading-0.61.0-0.73.0.txt} +122 -229
  139. package/llms/{upgrading-0.72.0-0.99.0.txt → upgrading-0.74.0-0.100.0.txt} +80 -123
  140. package/llms/upgrading.txt +4 -3
  141. package/llms-full.txt +471 -11
  142. package/llms.txt +10 -9
  143. package/native/darwin-arm64.node +0 -0
  144. package/native/darwin-x64.node +0 -0
  145. package/package.json +1 -1
  146. package/dist/agent-runtime/run-mutation-queue.d.ts +0 -21
  147. package/dist/agent-runtime/run-mutation-queue.d.ts.map +0 -1
@@ -834,3 +834,44 @@ A delivered item resets the backoff, so a stream that reconnects, works for an
834
834
  hour and drops again starts its next retry at `minDelayMs` rather than the
835
835
  ceiling it reached last time. Aborting the signal ends the iteration promptly,
836
836
  including in the middle of a wait.
837
+
838
+ ## Operations belong to a login lifetime
839
+
840
+ Use `createSessionScope` when a client can log out or switch accounts. The scope is
841
+ host-owned and context is immutable. Replace it for **every** login, even to the
842
+ same account. Capture once for an entire compound operation:
843
+
844
+ ```ts
845
+ import { createClient, createSessionScope } from 'stitchkit'
846
+
847
+ const sessions = createSessionScope<{ accountId: string }>()
848
+ const operation = sessions.replace({ accountId: 'account-a' })
849
+ const client = createClient(contract, {
850
+ baseUrl,
851
+ fetch: operation.bindFetch(fetch, () => ({ Authorization: tokenFor(operation) })),
852
+ })
853
+ const value = await operation.run(() => client.read())
854
+ operation.deliver(() => applyResult(value))
855
+ ```
856
+
857
+ Capture before the first request, keep the same operation for a second request or
858
+ one explicitly allowed auth retry, and guard the **actual** final transport send
859
+ or local state change. An async delivery callback needs another check after its
860
+ await; `deliver` itself is synchronous. Guard error delivery too. Cancellation is
861
+ additional protection and cannot undo server effects. `SessionExpiredError` means
862
+ discard the stale operation, not refresh a new user's credentials. For raw/stream
863
+ responses, guard each consumed chunk and final delivery; `run` returning a stream
864
+ does not mean its future contents have been consumed.
865
+
866
+ `createSessionCredentials({ scope, refresh, storage })` coordinates the same scope.
867
+ `login(context, credentials)` creates a generation, `read(operation)` resolves only
868
+ that generation's credentials, and concurrent `refresh(operation)` shares one
869
+ flight. `logout()` invalidates memory immediately and resolves after its ordered
870
+ storage clear (or a newer login superseding that clear). Handle storage and capacity
871
+ errors explicitly; a rejected write is not proof of durable login/logout. Refresh
872
+ network work never holds the storage queue. Callers decide whether a failed command
873
+ may be retried once; do not replay a multi-step callback or treat any `403` as expiry.
874
+
875
+ This is per-instance coordination. Route all writes through it; shared tabs/processes
876
+ need storage-level locking. Replace the local session counter and refresh queue when
877
+ adopting these primitives instead of retaining two independent lifetimes.
@@ -145,3 +145,29 @@ can emit / propagate a `traceparent` (see `HttpClientConfig.trace`).
145
145
  | `TraceContext` | _type_ | `{ traceId, spanId, parentSpanId?, tracestate?, baggage? }` |
146
146
 
147
147
  ---
148
+
149
+ ### Session lifetime and credential coordination
150
+
151
+ `createSessionScope` (`stitchkit`) returns the generic `SessionScope`: `replace(context)`
152
+ creates a new login lifetime (including same-account relogin), `capture()` returns
153
+ its `SessionOperation<T>`, `clear()` invalidates it, `stop()` permanently closes
154
+ the host, and `owns(operation)` answers whether an operation is this scope's current
155
+ one — `current()` alone cannot tell an operation of another scope. Operations expose `id`, `generation`, `context`, `signal`, `current()` and
156
+ `assertCurrent()`. `run(callback)` checks both success and failure across an await;
157
+ `deliver(callback)` admits a synchronous final send/state change or returns false.
158
+ `bindFetch(fetch, headers?)` guards every attempt and scopes its abort signal. Wrap
159
+ the complete client call in `run` too: headers are not the response body boundary.
160
+ Expired work throws `SessionExpiredError`, not a refresh instruction; when the work
161
+ itself failed, that failure is its `cause`.
162
+
163
+ `createSessionCredentials` accepts `SessionCredentialsConfig`:
164
+ `scope`, `refresh(credentials, signal)`, `storage.write(session, credentials)`,
165
+ `storage.clear()`, `maxPendingWrites` (128), `refreshTimeoutMs` (30000, at most one
166
+ hour) and `storageTimeoutMs` (30000, at most one hour): a storage call past it
167
+ rejects and frees the queue, so `logout()` still clears; when the late call settles,
168
+ storage is written again from memory, or cleared when nobody is logged in. `SessionCredentials` provides `login`, `logout`, `read(operation)` and
169
+ `refresh(operation)`. Concurrent refresh calls in one generation share the same
170
+ promise. Logout invalidates memory before its returned persistence promise settles.
171
+ Storage errors and queue-capacity refusals reject; callers must handle them. All
172
+ writes must pass through the same instance. There is no cross-process/tab lock,
173
+ provider error classifier or automatic retry of arbitrary application callbacks.
@@ -77,11 +77,11 @@ own, recorded as an ADR.
77
77
  | `stitchkit/geo` | server (Bun or Node) | evolving | managed GeoIP reader generations, last-known-good reload and the optional MaxMind adapter |
78
78
  | `stitchkit/oauth` | browser **and** server | evolving | provider-neutral Authorization Code + PKCE request and one-shot callback transaction mechanics |
79
79
  | `stitchkit/google` | server (Bun or Node) | evolving | optional Google code exchange and verified OIDC identity adapter |
80
- | `stitchkit/observability` | server | stable<br>_redefined in 2 of the 44 minors since 0.56.2, most recently 0.92.0_ | request/tool event projections — `createObservability`, trace context, sanitisation |
80
+ | `stitchkit/observability` | server | stable<br>_redefined in 2 of the 45 minors since 0.56.2, most recently 0.92.0_ | request/tool event projections — `createObservability`, trace context, sanitisation |
81
81
  | `stitchkit/testing` | tests on Bun or Node | stable | in-process generated clients over a real Fetch handler, plus the managed-resource conformance kit |
82
82
  | `stitchkit/declaration` | browser + build and deployment tooling (Bun or Node) | evolving | `ProjectDeclarationSchema` — the one machine-readable statement a repository makes about itself |
83
83
  | `stitchkit/react` | browser + server rendering | stable | `createCursorQuery`, `createCacheBridge`, QueryClient and `ApiError` retry policy |
84
- | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 22 of the 44 minors since 0.56.2, most recently 0.97.0_ | optional durable conversation/run loop, history, models, prompts, fencing and events |
84
+ | `stitchkit/agent-runtime` | server | evolving<br>_redefined in 22 of the 45 minors since 0.56.2, most recently 0.97.0_ | optional durable conversation/run loop, history, models, prompts, fencing and events |
85
85
  | `stitchkit/agent-runtime/sandbox` | server | evolving | optional Linux Bubblewrap sessions, durable workspaces and a host HTTP credential gateway; see [sandbox guide](sandbox.md) |
86
86
  | `stitchkit/agent-runtime/testing` | tests on Bun or Node | evolving | credential-free replay, scripted provider faults, deterministic race controls and the agent-store conformance kit |
87
87
  | `stitchkit/agent-runtime/harness` | server | evolving | resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
@@ -91,7 +91,7 @@ own, recorded as an ADR.
91
91
  | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving | durable built-in SQLite store for the agent runtime |
92
92
  | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving | durable built-in SQLite store for the agent runtime |
93
93
  | `stitchkit-tui` | terminal (Bun) | evolving | optional official OpenTUI host over a caller-composed headless runtime |
94
- | `stitchkit/application` | browser + server | evolving<br>_redefined in 9 of the 44 minors since 0.56.2, most recently 0.96.0_ | managed resource graph, readiness, admission, schedules, subtree restart and bounded shutdown |
94
+ | `stitchkit/application` | browser + server | evolving<br>_redefined in 10 of the 45 minors since 0.56.2, most recently 0.100.0_ | managed resource graph, readiness, admission, schedules, subtree restart and bounded shutdown |
95
95
  | `stitchkit/application/grammy` | server | evolving | a grammY bot as application resources — configuration, then polling with updates admitted by batch — and the webhook adapter |
96
96
  | `stitchkit/application/opentelemetry` | server | evolving | maps application snapshots onto an injected OpenTelemetry `Meter` |
97
97
  | `stitchkit/application/schemas` | browser + server | evolving | the application's snapshot, health and shutdown schemas alone, without the kernel |
@@ -0,0 +1,176 @@
1
+ # Upgrading 0.37.0 → 0.37.0 — stitchkit docs slice
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
+ Contains: Guide: Upgrading, 0.37.0 → 0.37.0 (docs/guide/upgrading.md)
7
+
8
+ ==============================================================================
9
+ # Guide: Upgrading, 0.37.0 → 0.37.0 (docs/guide/upgrading.md)
10
+ ==============================================================================
11
+
12
+ ## The 0.37 migration
13
+
14
+ Tool presentation is no longer an executable Zod parser. Replace the removed
15
+ flatten helpers with the JSON Schema compiler, and choose the explicit
16
+ `MountableTool` surface when using the advanced collection API:
17
+
18
+ ```ts
19
+ // before
20
+ const flat = flattenUnionsDeep(zodSchema)
21
+ mountable.schema
22
+
23
+ // after
24
+ const flat = flattenToolJsonSchema(
25
+ z.toJSONSchema(zodSchema, { target: 'draft-07', io: 'input' }),
26
+ )
27
+ mountable.presentationSchema // model/MCP/manifest JSON Schema
28
+ mountable.argumentSchema // executable CLI argument adapter only
29
+ ```
30
+
31
+ Contract and native handlers keep their original Zod schemas; MCP and agent SDK
32
+ adapters now forward raw arguments so defaults, coercions, refinements and
33
+ transforms execute exactly once inside Stitchkit. There are no compatibility
34
+ exports for `flattenDiscriminatedUnion`, `flattenUnionsDeep` or
35
+ `MountableTool.schema`. → ADR 0050
36
+
37
+ Tool-call hooks now take one options object. Migrate all three callbacks; there
38
+ are no positional overloads:
39
+
40
+ ```ts
41
+ // before
42
+ beforeToolCall: (toolName, args, context, endpoint) => {}
43
+ afterToolCall: (toolName, args, result, durationMs, context, endpoint, error) => {}
44
+ onToolError: (toolName, error, context, endpoint) => {}
45
+
46
+ // after
47
+ beforeToolCall: ({ toolName, args, context, endpoint }) => {}
48
+ afterToolCall: ({ toolName, args, result, durationMs, context, endpoint, error }) => {}
49
+ onToolError: ({ toolName, error, context, endpoint }) => {}
50
+ ```
51
+
52
+ ### MCP schema validation
53
+
54
+ The standalone validator now takes one object and live MCP configs carry the
55
+ same rules under `schemaValidation`. Migrate every positional call and every
56
+ `onIncompatibleSchema` field; there is no old-shape overload:
57
+
58
+ ```ts
59
+ // before
60
+ validateMcpSchemas(services, 'throw', logger, { requireTypedProperties: true })
61
+ createMcpHandler({ services, onIncompatibleSchema: 'throw' })
62
+
63
+ // after
64
+ validateMcpSchemas({ services, policy: 'throw', logger, requireTypedProperties: true })
65
+ createMcpHandler({ services, schemaValidation: { policy: 'throw' } })
66
+ ```
67
+
68
+ Put `extend` and `flattenUnionInput` beside `services`, not inside
69
+ `schemaValidation`. The handler applies the profile to the exact prepared schema
70
+ it advertises. Add `requirePortableFormats: true` when every custom JSON Schema
71
+ format must be rejected before a client sees it.
72
+
73
+ Native MCP registration also changed shape in 0.37. Move protected tools to the
74
+ framework registrar; keep an SDK-raw tool only by naming the opt-out:
75
+
76
+ ```ts
77
+ // before
78
+ nativeTools: (server, auth) => server.registerTool(name, config, handler)
79
+
80
+ // after — lifecycle, hooks and schema policy apply
81
+ nativeTools: ({ registerTool }, auth) => registerTool({
82
+ name, description, identity, input, output, handler,
83
+ })
84
+
85
+ // after — intentionally raw
86
+ nativeTools: ({ rawServer }, auth) => rawServer.registerTool(name, config, handler)
87
+ ```
88
+
89
+ If a tool hook annotated `endpoint` as `MethodDef`, remove that annotation or
90
+ use `OperationIdentity`: native operations have service/action/scope/method but
91
+ no HTTP path.
92
+
93
+ ### Node-facing server types
94
+
95
+ `stitchkit/server` remains Bun-concrete: an explicitly annotated `RawRoute`
96
+ still receives `BunServer`. `stitchkit/node` no longer drags Bun declarations
97
+ into a Node project. Its raw routes default the host server to `unknown`, and
98
+ its Socket.IO handle exposes only Node capabilities:
99
+
100
+ ```ts
101
+ // before — Node entry still leaked Bun-only fields and ambient types
102
+ const route: RawRoute = { handler: (_req, ctx) => ctx.server?.upgrade(...) }
103
+ const socket = await createSocketIOServer(config)
104
+ socket.websocket
105
+
106
+ // after — name a custom embedding host only when one exists
107
+ const route: RawRoute<MyHostServer> = {
108
+ handler: (_req, ctx) => useHost(ctx.server),
109
+ }
110
+ const socket = await createSocketIOServer(config)
111
+ socket.io
112
+ socket.attach(nodeHttpServer)
113
+ ```
114
+
115
+ Node consumers can remove `@types/bun` unless another dependency independently
116
+ requires it.
117
+
118
+ ### Managed server shutdown
119
+
120
+ `createServer()` and `serveNode()` now return the same structural managed
121
+ lifecycle. Replace every direct runtime stop and parallel Socket.IO close:
122
+
123
+ ```ts
124
+ // before — split ownership
125
+ const socket = await createSocketIOServer(config)
126
+ const server = createServer({
127
+ services,
128
+ websocket: socket.websocket,
129
+ rawRoutes: [socket.route],
130
+ })
131
+ server.stop()
132
+ await socket.io.close()
133
+
134
+ // after — one owner and one total deadline
135
+ const socket = await createSocketIOServer(config)
136
+ const server = createServer({ services, socket })
137
+ const result = await server.shutdown({ gracePeriodMs: 30_000 })
138
+ ```
139
+
140
+ On Node, keep the same `socket` field and replace `handle.close()` with
141
+ `handle.shutdown()`. Runtime-specific diagnostics move under `handle.runtime`;
142
+ do not use it as a second shutdown path. Standalone CLI/tools that create a
143
+ Socket.IO handle without an HTTP server call `await socket.close()`.
144
+
145
+ If Bun Socket.IO shares the port with a raw lane, keep the explicit composition
146
+ but let the server mount the Socket.IO route:
147
+
148
+ ```ts
149
+ createServer({
150
+ services,
151
+ socket,
152
+ websocket: composeWebSocketHandlers([
153
+ webSocketLane({ match: isRaw, handlers: rawHandlers }),
154
+ socketIoLane(socket.websocket),
155
+ ]),
156
+ rawRoutes: [rawUpgradeRoute],
157
+ })
158
+ ```
159
+
160
+ Move native Bun `routes` entries to `rawRoutes`. Native routes run before the
161
+ Fetch handler and therefore cannot participate in admission or drain. Wire
162
+ `SIGTERM`/`SIGINT` in the application; the first signal starts `shutdown()`, and
163
+ a later signal may abort the same controller. Close MCP, databases and queues
164
+ after the server result—those resources remain application-owned.
165
+
166
+ Move a handshake policy from the Node-only callback shape inside
167
+ `serverOptions` to the runtime-neutral top-level policy. It receives a Web
168
+ `Request`, may be async, and returns whether to admit the handshake:
169
+
170
+ ```ts
171
+ // before
172
+ serverOptions: { allowRequest: (request, done) => done(null, allowed(request)) }
173
+
174
+ // after
175
+ allowRequest: (request) => allowed(request)
176
+ ```