stitchkit 0.103.0 → 0.103.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 (76) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/agent-runtime/browser-control-contract.d.ts +1118 -0
  3. package/dist/agent-runtime/browser-control-contract.d.ts.map +1 -0
  4. package/dist/agent-runtime/browser-controller.d.ts +31 -0
  5. package/dist/agent-runtime/browser-controller.d.ts.map +1 -0
  6. package/dist/agent-runtime/harness-control.d.ts.map +1 -1
  7. package/dist/agent-runtime/harness-realtime.d.ts +25 -0
  8. package/dist/agent-runtime/harness-realtime.d.ts.map +1 -0
  9. package/dist/agent-runtime/harness-tools.d.ts +11 -0
  10. package/dist/agent-runtime/harness-tools.d.ts.map +1 -0
  11. package/dist/agent-runtime/react.d.ts +4 -0
  12. package/dist/agent-runtime/react.d.ts.map +1 -0
  13. package/dist/agent-runtime/run-assertions.d.ts +63 -0
  14. package/dist/agent-runtime/run-assertions.d.ts.map +1 -0
  15. package/dist/entrypoints/agent-runtime/browser.d.ts +2 -0
  16. package/dist/entrypoints/agent-runtime/browser.d.ts.map +1 -1
  17. package/dist/entrypoints/agent-runtime/browser.js +235 -0
  18. package/dist/entrypoints/agent-runtime/harness-tools.d.ts +2 -0
  19. package/dist/entrypoints/agent-runtime/harness-tools.d.ts.map +1 -0
  20. package/dist/entrypoints/agent-runtime/harness-tools.js +32 -0
  21. package/dist/entrypoints/agent-runtime/harness.js +11 -226
  22. package/dist/entrypoints/agent-runtime/react.d.ts +2 -0
  23. package/dist/entrypoints/agent-runtime/react.d.ts.map +1 -0
  24. package/dist/entrypoints/agent-runtime/react.js +8 -0
  25. package/dist/entrypoints/agent-runtime/realtime.d.ts +2 -0
  26. package/dist/entrypoints/agent-runtime/realtime.d.ts.map +1 -0
  27. package/dist/entrypoints/agent-runtime/realtime.js +159 -0
  28. package/dist/entrypoints/agent-runtime/testing.d.ts +1 -0
  29. package/dist/entrypoints/agent-runtime/testing.d.ts.map +1 -1
  30. package/dist/entrypoints/agent-runtime/testing.js +67 -2
  31. package/dist/entrypoints/agent-runtime.js +23 -18
  32. package/dist/entrypoints/cli.js +6 -6
  33. package/dist/entrypoints/index.js +15 -226
  34. package/dist/entrypoints/node.js +7 -5
  35. package/dist/entrypoints/observability.js +2 -2
  36. package/dist/entrypoints/react.js +2 -2
  37. package/dist/entrypoints/remote.js +3 -3
  38. package/dist/entrypoints/server.js +10 -8
  39. package/dist/entrypoints/testing.js +3 -3
  40. package/dist/entrypoints/tools/invoker.js +5 -5
  41. package/dist/entrypoints/tools.js +23 -34
  42. package/dist/entrypoints/tracking.js +2 -2
  43. package/dist/{index-d82d3xg4.js → index-0c419yx7.js} +1 -1
  44. package/dist/{index-dvwj1f43.js → index-0efgsyav.js} +1 -1
  45. package/dist/index-20yvtn9a.js +38 -0
  46. package/dist/{index-a9pd417t.js → index-5vyd0fkb.js} +1 -34
  47. package/dist/{index-r1z0rd9c.js → index-7n68nmc6.js} +1 -1
  48. package/dist/index-860vjkgm.js +48 -0
  49. package/dist/index-c9d05kvt.js +11 -0
  50. package/dist/{index-m9fndta6.js → index-ds7jdhep.js} +2 -2
  51. package/dist/index-jn9g8xdt.js +246 -0
  52. package/dist/{index-n9tyz8z3.js → index-kgmh97hf.js} +1 -1
  53. package/dist/{index-c6aagrbd.js → index-kkk1wzsq.js} +3 -3
  54. package/dist/index-nggfa2yn.js +34 -0
  55. package/dist/{index-m79yr938.js → index-pw99k9h5.js} +1 -10
  56. package/dist/index-qapzv4p5.js +54 -0
  57. package/dist/index-r34mvse1.js +225 -0
  58. package/dist/index-srs8hj9c.js +10 -0
  59. package/dist/index-vgkbcnkc.js +29 -0
  60. package/dist/{index-ewbaywk5.js → index-x1dkwx5x.js} +1 -1
  61. package/dist/{index-xkhk5d6g.js → index-xgc94hy6.js} +5 -48
  62. package/dist/{index-3ct7hhq6.js → index-xwq9j1sf.js} +6 -56
  63. package/dist/{index-hby4qhax.js → index-yex7eg1v.js} +4 -10
  64. package/dist/{index-1h6gtdrj.js → index-ygkka6zn.js} +1 -1
  65. package/dist/{index-zs4ms3th.js → index-z3pqcy7r.js} +7 -30
  66. package/dist/index-ze1eph1k.js +20 -0
  67. package/llms/agent-runtime-browser.txt +26 -0
  68. package/llms/agent-runtime-harness-tools.txt +25 -0
  69. package/llms/agent-runtime-harness.txt +140 -1
  70. package/llms/agent-runtime-react.txt +21 -0
  71. package/llms/agent-runtime-realtime.txt +30 -0
  72. package/llms/agent-runtime-testing.txt +6 -0
  73. package/llms/stitchkit.txt +5 -1
  74. package/llms-full.txt +209 -1
  75. package/llms.txt +8 -4
  76. package/package.json +13 -1
@@ -3,11 +3,150 @@
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.
5
5
 
6
- Contains: API reference: `stitchkit/agent-runtime/harness` (docs/api/reference.md)
6
+ Contains: Guide: Agent composition (docs/guide/agent-composition.md) · API reference: `stitchkit/agent-runtime/harness` (docs/api/reference.md)
7
7
 
8
8
  Also read:
9
9
  - see `llms/agent-runtime.txt` for the Agent application runtime guide
10
10
 
11
+ ==============================================================================
12
+ # Guide: Agent composition (docs/guide/agent-composition.md)
13
+ ==============================================================================
14
+
15
+ ---
16
+ title: "Agent composition without a second runtime"
17
+ description: "Compose contract tools, authenticated realtime control, React views and exact-run behavioral checks."
18
+ type: architecture
19
+ status: active
20
+ created: 2026-09-30 22:45 +07:00
21
+ updated: 2026-09-30 23:03 +07:00
22
+ participants:
23
+ - role: authored
24
+ harness: Codex
25
+ model: GPT-6
26
+ at: 2026-09-30 22:45 +07:00
27
+ ---
28
+
29
+ # Compose an agent application
30
+
31
+ Use these pieces when an application wants the existing headless harness and a generic
32
+ conversation view. An application with its own AI SDK loop keeps `mountAgent`; a product
33
+ with custom message projections can keep its transport and UI. No consumer migration is
34
+ required. Model selection, storage, compaction, approvals and recovery stay with their
35
+ existing owners.
36
+
37
+ ## Resources and tools
38
+
39
+ ```ts
40
+ import {
41
+ createAgentHarnessFileResources,
42
+ createHeadlessAgentHarness,
43
+ } from 'stitchkit/agent-runtime/harness';
44
+ import { createAgentHarnessTools } from 'stitchkit/agent-runtime/harness-tools';
45
+
46
+ const resources = createAgentHarnessFileResources({
47
+ roots: [{ id: 'guide', kind: 'instruction', path: instructionRoot }],
48
+ limits: { maxTotalBytes: 256 * 1024 },
49
+ });
50
+ const harness = createHeadlessAgentHarness({
51
+ protocol, store, models, promptBudget,
52
+ resources,
53
+ tools: createAgentHarnessTools(({ context, run }) => ({
54
+ services: [catalogService],
55
+ context: { ...context, messageId: run.assistantMessageId },
56
+ runtimeTools: resources.runtimeTools,
57
+ lifecycle: authorizeTools,
58
+ hooks: observeTools,
59
+ })),
60
+ });
61
+ ```
62
+
63
+ The factory composes application authorization then the runtime fence through `mountAgent`.
64
+ The optional harness-tools leaf preserves the complete tool types, including MCP presenter
65
+ declarations; install the same `ai` and `@modelcontextprotocol/server` peers as for
66
+ `stitchkit/tools`. The base harness stays AI-only. Every mount option remains available, including registry, runtime tools, extension,
67
+ coercion, output stripping, hooks and durability. Async per-run configuration is supported.
68
+ The original tools callback still accepts arbitrary typed AI SDK tools and prepareStep.
69
+ The resource reader is explicitly selected: filtered allowlists do not gain tools merely
70
+ because a loader exists. Root IDs, kinds, provenance and limits are unchanged.
71
+
72
+ ## Server and browser
73
+
74
+ ```ts
75
+ import { bindAgentHarnessRealtime } from 'stitchkit/agent-runtime/realtime';
76
+
77
+ const binding = bindAgentHarnessRealtime(harness, socket, {
78
+ async authorize({ identity, request, signal }) {
79
+ // socket.data comes from your verified Socket.IO handshake, not a browser context.
80
+ if (!await mayAccessConversation(identity, request, signal)) return null;
81
+ return { context: { userId: identity.userId } };
82
+ },
83
+ onError: reportServerError,
84
+ });
85
+ ```
86
+
87
+ `socket` is the existing `createSocketIOServer` handle, attached to `createServer` (Bun)
88
+ or the Node adapter. The access policy checks every operation, file/reference and metadata
89
+ as well as snapshot/event reads. Session handshake authentication alone is insufficient.
90
+ Conversation ownership and observer/controller roles are application policy; the canonical
91
+ control server additionally enforces its exclusive controller lease.
92
+
93
+ ```ts
94
+ import { createSocketIOClient } from 'stitchkit';
95
+ import { createAgentController } from 'stitchkit/agent-runtime/browser';
96
+ import { useAgent } from 'stitchkit/agent-runtime/react';
97
+
98
+ const transport = createSocketIOClient({ url: serverUrl, auth: sessionAuth });
99
+ const agent = createAgentController({ transport, conversationId, access: 'control' });
100
+ transport.connect();
101
+
102
+ function Conversation() {
103
+ const state = useAgent(agent);
104
+ const conversation = state.view.conversations[conversationId];
105
+ // Render canonical messages/parts, transient progress, approvals and state.error.
106
+ return <Transcript conversation={conversation} status={state.status} error={state.error} />;
107
+ }
108
+
109
+ await agent.request({
110
+ operation: 'submit', idempotencyKey: crypto.randomUUID(),
111
+ parts: [{ type: 'text', text: 'Find available items' }],
112
+ });
113
+ await agent.request({ operation: 'interrupt', runId });
114
+ await agent.request({ operation: 'respond-approval', approvalId, approved: true });
115
+ await agent.close(); // leaves transport and harness alive
116
+ ```
117
+
118
+ Wait for `ready` before sending. Share a controller among views of the same conversation;
119
+ create it at session scope, not during React render. Unmount only unsubscribes the view.
120
+ To release the session, await `close`; to stop the application, separately close the
121
+ binding, transport and harness through the application's shutdown lifecycle. Closing a
122
+ view does not interrupt its remote run. Use explicit `interrupt` for cancellation.
123
+
124
+ Reconnect reattaches and reads durable state. Mutations are not retried automatically:
125
+ if an acknowledgement is lost, retain the original idempotency key. Incoming event
126
+ buffers and outgoing requests have finite limits; capacity/overflow/lease failures stay
127
+ visible. A server overflow deliberately disconnects the transport; reconnect explicitly.
128
+
129
+ ## Check behavior, not just admission
130
+
131
+ ```ts
132
+ import { inspectAgentRun } from 'stitchkit/agent-runtime/testing';
133
+
134
+ const ticket = harness.submit(input);
135
+ const admitted = await ticket.admission;
136
+ await ticket.result;
137
+ const result = inspectAgentRun(await harness.snapshot(input.conversationId), admitted.runId);
138
+ result.calledTool('catalog_search');
139
+ result.toolSucceeded('catalog_search');
140
+ result.notCalledTool('catalog_delete');
141
+ result.completed();
142
+ ```
143
+
144
+ `calledTool` proves a call record (including an approved continuation linked through that
145
+ run’s exact input messages); `toolSucceeded` also needs a matching successful result.
146
+ `completed` requires successful terminal output with no pending approval. Prior runs,
147
+ provider/policy stops, failed calls and unfinished runs cannot satisfy those assertions.
148
+ The helper does not invoke a model or poll; the existing runtime ticket owns execution.
149
+
11
150
  ==============================================================================
12
151
  # API reference: `stitchkit/agent-runtime/harness` (docs/api/reference.md)
13
152
  ==============================================================================
@@ -0,0 +1,21 @@
1
+ # stitchkit/agent-runtime/react — 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: API reference: `stitchkit/agent-runtime/react` (docs/api/reference.md)
7
+
8
+ Also read:
9
+ - see `llms/agent-runtime.txt` for the Agent application runtime guide
10
+ - see `llms/agent-runtime-harness.txt` for the Agent composition guide
11
+
12
+ ==============================================================================
13
+ # API reference: `stitchkit/agent-runtime/react` (docs/api/reference.md)
14
+ ==============================================================================
15
+
16
+ ## `stitchkit/agent-runtime/react`
17
+
18
+ Optional evolving React peer leaf. `useAgent` takes a controller and subscribes through
19
+ `useSyncExternalStore`, returning the same `AgentControllerState` as `getSnapshot()`.
20
+ Create and close the controller at application/session scope. Multiple components can
21
+ observe it; StrictMode and unmount release only the component's own subscription.
@@ -0,0 +1,30 @@
1
+ # stitchkit/agent-runtime/realtime — 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: API reference: `stitchkit/agent-runtime/realtime` (docs/api/reference.md)
7
+
8
+ Also read:
9
+ - see `llms/agent-runtime.txt` for the Agent application runtime guide
10
+ - see `llms/agent-runtime-harness.txt` for the Agent composition guide
11
+
12
+ ==============================================================================
13
+ # API reference: `stitchkit/agent-runtime/realtime` (docs/api/reference.md)
14
+ ==============================================================================
15
+
16
+ ## `stitchkit/agent-runtime/realtime`
17
+
18
+ Optional evolving Socket.IO server binding. `bindAgentHarnessRealtime` takes `(harness, socket, config)` and returns `close()` for its subscriptions and control connections, without closing
19
+ socket or harness. `AgentHarnessRealtimeConfig` requires `authorize({ identity, request,
20
+ signal })`: return `{ context }` after verifying the session principal, conversation,
21
+ operation, files and metadata, or `null`. Identity is `socket.data` from the application's
22
+ verified handshake. Every request and event delivery is authorized. Observe access does
23
+ not grant mutation; controller leases and approval policy still belong to the harness.
24
+
25
+ `maxPendingEvents` and `maxPendingAttachments` forward to the canonical control server;
26
+ `maxPendingRequests` bounds in-flight authorization/control requests per socket (32);
27
+ `authorizationTimeoutMs` bounds each authorization (10000 ms). Honor its AbortSignal.
28
+ `onError` receives internal errors; peers receive generic denials. Revoking a conversation
29
+ releases only its attachment. Event overflow closes the socket; explicitly reconnect the
30
+ application transport. A transport's Engine.IO payload limit remains application-owned.
@@ -7,6 +7,7 @@ Contains: API reference: `stitchkit/agent-runtime/testing` (docs/api/reference.
7
7
 
8
8
  Also read:
9
9
  - see `llms/agent-runtime.txt` for the Agent application runtime guide
10
+ - see `llms/agent-runtime-harness.txt` for the Agent composition guide
10
11
 
11
12
  ==============================================================================
12
13
  # API reference: `stitchkit/agent-runtime/testing` (docs/api/reference.md)
@@ -28,3 +29,8 @@ Credential-free provider and concurrency fixtures for Bun and Node tests.
28
29
  | `runAgentStoreConformance` | function | reusable black-box duplicate/coalescing/stale/recovery contract for durable agent-store adapters |
29
30
  | `AgentStoreConformanceConfig` | _type_ | `{ createStore(context), cleanup?(context) }` — the factory the contract runs against, plus a teardown that runs once whether the scenario passed or failed |
30
31
  | `AgentStoreConformanceContext` | _type_ | `{ conversationIds }` — every conversation the scenario will mutate, handed over **before** the first mutation so an adapter can provision application-owned parent rows; a zero-argument factory stays valid |
32
+
33
+ `inspectAgentRun` takes `(snapshot, runId)` and returns `completed()`, `calledTool(name)`,
34
+ `notCalledTool(name)` and `toolSucceeded(name)` assertions over durable evidence for
35
+ that exact run. Completion requires terminal reason `success`, not `policy_stop` or
36
+ `provider_stop`, and no pending approval. Successful tools require matching call/result IDs.
@@ -90,7 +90,10 @@ own, recorded as an ADR.
90
90
  | `stitchkit/agent-runtime/harness` | server | evolving | resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
91
91
  | `stitchkit/agent-runtime/coding-tools` | server (Bun or Node) | evolving | bounded host-authorized direct file and shell tools; a root boundary, not an OS sandbox |
92
92
  | `stitchkit/agent-runtime/openrouter` | server | evolving | isolated OpenRouter language-model adapter |
93
- | `stitchkit/agent-runtime/browser` | browser + server | evolving | canonical agent records, events and reconnect cursor without execution or sinks |
93
+ | `stitchkit/agent-runtime/browser` | browser + server | evolving | canonical agent records, events, reconnect cursor and optional conversation controller |
94
+ | `stitchkit/agent-runtime/harness-tools` | server | evolving | full mountAgent configuration with the current run fence |
95
+ | `stitchkit/agent-runtime/react` | browser + server | evolving | React subscription to an application-owned agent controller |
96
+ | `stitchkit/agent-runtime/realtime` | server (Bun or Node) | evolving | authorized agent control over the existing Socket.IO server |
94
97
  | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving | durable built-in SQLite store for the agent runtime |
95
98
  | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving | durable built-in SQLite store for the agent runtime |
96
99
  | `stitchkit-tui` | terminal (Bun) | evolving | optional official OpenTUI host over a caller-composed headless runtime |
@@ -200,6 +203,7 @@ map — feature → packages:
200
203
  | MCP / agent adapters (`stitchkit/tools`) | `@modelcontextprotocol/server` `ai` |
201
204
  | Agent application runtime (`stitchkit/agent-runtime`) | `ai` |
202
205
  | Headless Agent harness (`stitchkit/agent-runtime/harness`) | `ai` |
206
+ | Harness tools (`stitchkit/agent-runtime/harness-tools`) | `ai` `@modelcontextprotocol/server` (tool declarations) |
203
207
  | Agent coding tools (`stitchkit/agent-runtime/coding-tools`) | — |
204
208
  | OpenRouter runtime adapter (`stitchkit/agent-runtime/openrouter`) | `ai` `@openrouter/ai-sdk-provider` |
205
209
  | SQLite agent store (`stitchkit/agent-runtime/sqlite/bun` or `/node`) | — (runtime built-in) |
package/llms-full.txt CHANGED
@@ -81,7 +81,10 @@ own, recorded as an ADR.
81
81
  | `stitchkit/agent-runtime/harness` | server | evolving | resource-aware process-local facade over the canonical Agent runtime; supervision stays outside |
82
82
  | `stitchkit/agent-runtime/coding-tools` | server (Bun or Node) | evolving | bounded host-authorized direct file and shell tools; a root boundary, not an OS sandbox |
83
83
  | `stitchkit/agent-runtime/openrouter` | server | evolving | isolated OpenRouter language-model adapter |
84
- | `stitchkit/agent-runtime/browser` | browser + server | evolving | canonical agent records, events and reconnect cursor without execution or sinks |
84
+ | `stitchkit/agent-runtime/browser` | browser + server | evolving | canonical agent records, events, reconnect cursor and optional conversation controller |
85
+ | `stitchkit/agent-runtime/harness-tools` | server | evolving | full mountAgent configuration with the current run fence |
86
+ | `stitchkit/agent-runtime/react` | browser + server | evolving | React subscription to an application-owned agent controller |
87
+ | `stitchkit/agent-runtime/realtime` | server (Bun or Node) | evolving | authorized agent control over the existing Socket.IO server |
85
88
  | `stitchkit/agent-runtime/sqlite/bun` | server (Bun) | evolving | durable built-in SQLite store for the agent runtime |
86
89
  | `stitchkit/agent-runtime/sqlite/node` | server (Node ≥ 22.5) | evolving | durable built-in SQLite store for the agent runtime |
87
90
  | `stitchkit-tui` | terminal (Bun) | evolving | optional official OpenTUI host over a caller-composed headless runtime |
@@ -191,6 +194,7 @@ map — feature → packages:
191
194
  | MCP / agent adapters (`stitchkit/tools`) | `@modelcontextprotocol/server` `ai` |
192
195
  | Agent application runtime (`stitchkit/agent-runtime`) | `ai` |
193
196
  | Headless Agent harness (`stitchkit/agent-runtime/harness`) | `ai` |
197
+ | Harness tools (`stitchkit/agent-runtime/harness-tools`) | `ai` `@modelcontextprotocol/server` (tool declarations) |
194
198
  | Agent coding tools (`stitchkit/agent-runtime/coding-tools`) | — |
195
199
  | OpenRouter runtime adapter (`stitchkit/agent-runtime/openrouter`) | `ai` `@openrouter/ai-sdk-provider` |
196
200
  | SQLite agent store (`stitchkit/agent-runtime/sqlite/bun` or `/node`) | — (runtime built-in) |
@@ -6612,6 +6616,146 @@ for receipt queries; do not import runtime internals. Available since 0.100.0;
6612
6616
  existing runtime configurations need no migration.
6613
6617
 
6614
6618
 
6619
+ ==============================================================================
6620
+ # Guide: Agent composition (docs/guide/agent-composition.md)
6621
+ ==============================================================================
6622
+
6623
+ ---
6624
+ title: "Agent composition without a second runtime"
6625
+ description: "Compose contract tools, authenticated realtime control, React views and exact-run behavioral checks."
6626
+ type: architecture
6627
+ status: active
6628
+ created: 2026-09-30 22:45 +07:00
6629
+ updated: 2026-09-30 23:03 +07:00
6630
+ participants:
6631
+ - role: authored
6632
+ harness: Codex
6633
+ model: GPT-6
6634
+ at: 2026-09-30 22:45 +07:00
6635
+ ---
6636
+
6637
+ # Compose an agent application
6638
+
6639
+ Use these pieces when an application wants the existing headless harness and a generic
6640
+ conversation view. An application with its own AI SDK loop keeps `mountAgent`; a product
6641
+ with custom message projections can keep its transport and UI. No consumer migration is
6642
+ required. Model selection, storage, compaction, approvals and recovery stay with their
6643
+ existing owners.
6644
+
6645
+ ## Resources and tools
6646
+
6647
+ ```ts
6648
+ import {
6649
+ createAgentHarnessFileResources,
6650
+ createHeadlessAgentHarness,
6651
+ } from 'stitchkit/agent-runtime/harness';
6652
+ import { createAgentHarnessTools } from 'stitchkit/agent-runtime/harness-tools';
6653
+
6654
+ const resources = createAgentHarnessFileResources({
6655
+ roots: [{ id: 'guide', kind: 'instruction', path: instructionRoot }],
6656
+ limits: { maxTotalBytes: 256 * 1024 },
6657
+ });
6658
+ const harness = createHeadlessAgentHarness({
6659
+ protocol, store, models, promptBudget,
6660
+ resources,
6661
+ tools: createAgentHarnessTools(({ context, run }) => ({
6662
+ services: [catalogService],
6663
+ context: { ...context, messageId: run.assistantMessageId },
6664
+ runtimeTools: resources.runtimeTools,
6665
+ lifecycle: authorizeTools,
6666
+ hooks: observeTools,
6667
+ })),
6668
+ });
6669
+ ```
6670
+
6671
+ The factory composes application authorization then the runtime fence through `mountAgent`.
6672
+ The optional harness-tools leaf preserves the complete tool types, including MCP presenter
6673
+ declarations; install the same `ai` and `@modelcontextprotocol/server` peers as for
6674
+ `stitchkit/tools`. The base harness stays AI-only. Every mount option remains available, including registry, runtime tools, extension,
6675
+ coercion, output stripping, hooks and durability. Async per-run configuration is supported.
6676
+ The original tools callback still accepts arbitrary typed AI SDK tools and prepareStep.
6677
+ The resource reader is explicitly selected: filtered allowlists do not gain tools merely
6678
+ because a loader exists. Root IDs, kinds, provenance and limits are unchanged.
6679
+
6680
+ ## Server and browser
6681
+
6682
+ ```ts
6683
+ import { bindAgentHarnessRealtime } from 'stitchkit/agent-runtime/realtime';
6684
+
6685
+ const binding = bindAgentHarnessRealtime(harness, socket, {
6686
+ async authorize({ identity, request, signal }) {
6687
+ // socket.data comes from your verified Socket.IO handshake, not a browser context.
6688
+ if (!await mayAccessConversation(identity, request, signal)) return null;
6689
+ return { context: { userId: identity.userId } };
6690
+ },
6691
+ onError: reportServerError,
6692
+ });
6693
+ ```
6694
+
6695
+ `socket` is the existing `createSocketIOServer` handle, attached to `createServer` (Bun)
6696
+ or the Node adapter. The access policy checks every operation, file/reference and metadata
6697
+ as well as snapshot/event reads. Session handshake authentication alone is insufficient.
6698
+ Conversation ownership and observer/controller roles are application policy; the canonical
6699
+ control server additionally enforces its exclusive controller lease.
6700
+
6701
+ ```ts
6702
+ import { createSocketIOClient } from 'stitchkit';
6703
+ import { createAgentController } from 'stitchkit/agent-runtime/browser';
6704
+ import { useAgent } from 'stitchkit/agent-runtime/react';
6705
+
6706
+ const transport = createSocketIOClient({ url: serverUrl, auth: sessionAuth });
6707
+ const agent = createAgentController({ transport, conversationId, access: 'control' });
6708
+ transport.connect();
6709
+
6710
+ function Conversation() {
6711
+ const state = useAgent(agent);
6712
+ const conversation = state.view.conversations[conversationId];
6713
+ // Render canonical messages/parts, transient progress, approvals and state.error.
6714
+ return <Transcript conversation={conversation} status={state.status} error={state.error} />;
6715
+ }
6716
+
6717
+ await agent.request({
6718
+ operation: 'submit', idempotencyKey: crypto.randomUUID(),
6719
+ parts: [{ type: 'text', text: 'Find available items' }],
6720
+ });
6721
+ await agent.request({ operation: 'interrupt', runId });
6722
+ await agent.request({ operation: 'respond-approval', approvalId, approved: true });
6723
+ await agent.close(); // leaves transport and harness alive
6724
+ ```
6725
+
6726
+ Wait for `ready` before sending. Share a controller among views of the same conversation;
6727
+ create it at session scope, not during React render. Unmount only unsubscribes the view.
6728
+ To release the session, await `close`; to stop the application, separately close the
6729
+ binding, transport and harness through the application's shutdown lifecycle. Closing a
6730
+ view does not interrupt its remote run. Use explicit `interrupt` for cancellation.
6731
+
6732
+ Reconnect reattaches and reads durable state. Mutations are not retried automatically:
6733
+ if an acknowledgement is lost, retain the original idempotency key. Incoming event
6734
+ buffers and outgoing requests have finite limits; capacity/overflow/lease failures stay
6735
+ visible. A server overflow deliberately disconnects the transport; reconnect explicitly.
6736
+
6737
+ ## Check behavior, not just admission
6738
+
6739
+ ```ts
6740
+ import { inspectAgentRun } from 'stitchkit/agent-runtime/testing';
6741
+
6742
+ const ticket = harness.submit(input);
6743
+ const admitted = await ticket.admission;
6744
+ await ticket.result;
6745
+ const result = inspectAgentRun(await harness.snapshot(input.conversationId), admitted.runId);
6746
+ result.calledTool('catalog_search');
6747
+ result.toolSucceeded('catalog_search');
6748
+ result.notCalledTool('catalog_delete');
6749
+ result.completed();
6750
+ ```
6751
+
6752
+ `calledTool` proves a call record (including an approved continuation linked through that
6753
+ run’s exact input messages); `toolSucceeded` also needs a matching successful result.
6754
+ `completed` requires successful terminal output with no pending approval. Prior runs,
6755
+ provider/policy stops, failed calls and unfinished runs cannot satisfy those assertions.
6756
+ The helper does not invoke a model or poll; the existing runtime ticket owns execution.
6757
+
6758
+
6615
6759
  ==============================================================================
6616
6760
  # Guide: Managed application kernel (docs/guide/application-kernel.md)
6617
6761
  ==============================================================================
@@ -19506,6 +19650,11 @@ Credential-free provider and concurrency fixtures for Bun and Node tests.
19506
19650
  | `AgentStoreConformanceConfig` | _type_ | `{ createStore(context), cleanup?(context) }` — the factory the contract runs against, plus a teardown that runs once whether the scenario passed or failed |
19507
19651
  | `AgentStoreConformanceContext` | _type_ | `{ conversationIds }` — every conversation the scenario will mutate, handed over **before** the first mutation so an adapter can provision application-owned parent rows; a zero-argument factory stays valid |
19508
19652
 
19653
+ `inspectAgentRun` takes `(snapshot, runId)` and returns `completed()`, `calledTool(name)`,
19654
+ `notCalledTool(name)` and `toolSucceeded(name)` assertions over durable evidence for
19655
+ that exact run. Completion requires terminal reason `success`, not `policy_stop` or
19656
+ `provider_stop`, and no pending approval. Successful tools require matching call/result IDs.
19657
+
19509
19658
  ## `stitchkit/agent-runtime/harness`
19510
19659
 
19511
19660
  Server-only evolving facade over the canonical Agent runtime. It requires the optional `ai` peer
@@ -19603,6 +19752,31 @@ Use this entrypoint from client components and shared DTO packages. The full
19603
19752
 
19604
19753
  ---
19605
19754
 
19755
+ ### Browser control composition
19756
+
19757
+ `AgentBrowserRequestSchema` / `AgentBrowserRequest` derive from the trusted control
19758
+ protocol but exclude runtime `context`. Submit permits only strict text/file parts;
19759
+ file ownership and metadata policy are checked by server authorization. The shared
19760
+ `agentControlRealtimeContract` owns `agent:control` acknowledgements and `agent:delivery`.
19761
+
19762
+ `createAgentController` / `AgentControllerConfig` take an existing Stitchkit
19763
+ realtime `transport`, `conversationId`, `access` (`observe` or `control`), optional
19764
+ `timeoutMs` (10000), `maxBufferedEvents` (256), `maxBufferedBytes` (1048576) and
19765
+ `maxPendingRequests` (32). All bounds are positive safe integers. One controller owns one
19766
+ attachment per conversation on that transport; share the controller between views.
19767
+
19768
+ `AgentController` exposes stable `subscribe`, `getSnapshot`, `request(command)` and async
19769
+ `close`. `AgentBrowserCommand` uses the canonical operations, without request/conversation identity;
19770
+ `submit` requires a caller-owned idempotency key. Unknown-outcome mutations are never
19771
+ replayed automatically. `AgentControllerState` distinguishes connecting, ready,
19772
+ disconnected, error and closed and retains the canonical full `view` plus safe error
19773
+ code/message. Errors in automatic attach/refresh appear there. Reconnect attaches again
19774
+ and reads a snapshot; snapshot gaps coalesce, stale generations cannot overwrite state,
19775
+ and buffers/queues are bounded. Overflow or failed refresh is visible and requires
19776
+ explicit recovery. Closing detaches without closing the shared transport or remote run.
19777
+
19778
+ See [agent composition](../guide/agent-composition.md) for a complete wiring example.
19779
+
19606
19780
  ## `stitchkit/agent-runtime/openrouter`
19607
19781
 
19608
19782
  | Export | Kind | Summary |
@@ -20668,3 +20842,37 @@ Its types are `BubblewrapSandboxConfig`, `SandboxBackend`, `SandboxCommand`,
20668
20842
  `SandboxPrewarmInput`, `SandboxProcess`, `SandboxRunOptions`, `SandboxSession`,
20669
20843
  and `SandboxState`. The [sandbox guide](../guide/sandbox.md) specifies lifecycle,
20670
20844
  network enforcement, gateway credentials and platform/resource boundaries.
20845
+
20846
+ ## `stitchkit/agent-runtime/realtime`
20847
+
20848
+ Optional evolving Socket.IO server binding. `bindAgentHarnessRealtime` takes `(harness, socket, config)` and returns `close()` for its subscriptions and control connections, without closing
20849
+ socket or harness. `AgentHarnessRealtimeConfig` requires `authorize({ identity, request,
20850
+ signal })`: return `{ context }` after verifying the session principal, conversation,
20851
+ operation, files and metadata, or `null`. Identity is `socket.data` from the application's
20852
+ verified handshake. Every request and event delivery is authorized. Observe access does
20853
+ not grant mutation; controller leases and approval policy still belong to the harness.
20854
+
20855
+ `maxPendingEvents` and `maxPendingAttachments` forward to the canonical control server;
20856
+ `maxPendingRequests` bounds in-flight authorization/control requests per socket (32);
20857
+ `authorizationTimeoutMs` bounds each authorization (10000 ms). Honor its AbortSignal.
20858
+ `onError` receives internal errors; peers receive generic denials. Revoking a conversation
20859
+ releases only its attachment. Event overflow closes the socket; explicitly reconnect the
20860
+ application transport. A transport's Engine.IO payload limit remains application-owned.
20861
+
20862
+ ## `stitchkit/agent-runtime/react`
20863
+
20864
+ Optional evolving React peer leaf. `useAgent` takes a controller and subscribes through
20865
+ `useSyncExternalStore`, returning the same `AgentControllerState` as `getSnapshot()`.
20866
+ Create and close the controller at application/session scope. Multiple components can
20867
+ observe it; StrictMode and unmount release only the component's own subscription.
20868
+
20869
+ ## `stitchkit/agent-runtime/harness-tools`
20870
+
20871
+ Optional evolving composition of the full `mountAgent` configuration with the runtime
20872
+ fence. Its runtime peer is `ai`; its full tool presenter declarations also require
20873
+ `@modelcontextprotocol/server`, as `stitchkit/tools` does. The base harness retains its
20874
+ AI-only peer boundary. Existing custom tool callbacks need no new import.
20875
+
20876
+ | Export | Kind | Summary |
20877
+ |--------|------|---------|
20878
+ | `createAgentHarnessTools` / `AgentHarnessToolsConfig` | function / _type_ | async per-run full mount configuration (`services` plus all `AgentMountConfig` options); composes application lifecycle then runtime fence exactly once |
package/llms.txt CHANGED
@@ -9,7 +9,7 @@ Build with stitchkit: define a contract once, then `implement` it and serve it (
9
9
  Load the slice for each entrypoint your code imports — `import … from 'stitchkit/server'` → `llms/server.txt`; the root `stitchkit` import → `llms/stitchkit.txt`. A slice holds that entrypoint's API reference section and the guide pages whose home it is; every guide lives in exactly one slice, and a slice that needs another's guide names it under "Also read". Each file is at most 50.0 KB; a longer one continues in numbered parts, each naming the next at its top. Moving across versions: load `llms/upgrading.txt` and the range slices it lists between your version and the target. `llms-full.txt` inlines everything; it is far larger than a context window, so do not read it whole.
10
10
 
11
11
  ## Entrypoint slices
12
- - **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 16.6 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt) 45.2 KB → [llms/stitchkit.3.txt](llms/stitchkit.3.txt) 17.1 KB
12
+ - **stitchkit**: [llms/stitchkit.txt](llms/stitchkit.txt) 17.0 KB → [llms/stitchkit.2.txt](llms/stitchkit.2.txt) 45.2 KB → [llms/stitchkit.3.txt](llms/stitchkit.3.txt) 17.1 KB
13
13
  - **stitchkit/live**: [llms/live.txt](llms/live.txt) 21.6 KB
14
14
  - **stitchkit/react**: [llms/react.txt](llms/react.txt) 9.0 KB
15
15
  - **stitchkit/react/keyboard**: [llms/react-keyboard.txt](llms/react-keyboard.txt) 9.4 KB
@@ -24,10 +24,10 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
24
24
  - **stitchkit/server**: [llms/server.txt](llms/server.txt) 45.3 KB → [llms/server.2.txt](llms/server.2.txt) 14.6 KB → [llms/server.3.txt](llms/server.3.txt) 45.6 KB → [llms/server.4.txt](llms/server.4.txt) 38.1 KB → [llms/server.5.txt](llms/server.5.txt) 21.8 KB
25
25
  - **stitchkit/observability**: [llms/observability.txt](llms/observability.txt) 44.8 KB
26
26
  - **stitchkit/agent-runtime**: [llms/agent-runtime.txt](llms/agent-runtime.txt) 36.8 KB → [llms/agent-runtime.2.txt](llms/agent-runtime.2.txt) 46.7 KB → [llms/agent-runtime.3.txt](llms/agent-runtime.3.txt) 34.3 KB
27
- - **stitchkit/agent-runtime/testing**: [llms/agent-runtime-testing.txt](llms/agent-runtime-testing.txt) 2.2 KB
28
- - **stitchkit/agent-runtime/harness**: [llms/agent-runtime-harness.txt](llms/agent-runtime-harness.txt) 4.1 KB
27
+ - **stitchkit/agent-runtime/testing**: [llms/agent-runtime-testing.txt](llms/agent-runtime-testing.txt) 2.6 KB
28
+ - **stitchkit/agent-runtime/harness**: [llms/agent-runtime-harness.txt](llms/agent-runtime-harness.txt) 10.1 KB
29
29
  - **stitchkit/agent-runtime/coding-tools**: [llms/agent-runtime-coding-tools.txt](llms/agent-runtime-coding-tools.txt) 4.9 KB
30
- - **stitchkit/agent-runtime/browser**: [llms/agent-runtime-browser.txt](llms/agent-runtime-browser.txt) 1.6 KB
30
+ - **stitchkit/agent-runtime/browser**: [llms/agent-runtime-browser.txt](llms/agent-runtime-browser.txt) 3.3 KB
31
31
  - **stitchkit/agent-runtime/openrouter**: [llms/agent-runtime-openrouter.txt](llms/agent-runtime-openrouter.txt) 1.1 KB
32
32
  - **stitchkit/agent-runtime/sqlite/bun**: [llms/agent-runtime-sqlite-bun.txt](llms/agent-runtime-sqlite-bun.txt) 1.8 KB
33
33
  - **stitchkit/agent-runtime/sqlite/node**: [llms/agent-runtime-sqlite-node.txt](llms/agent-runtime-sqlite-node.txt) 1.7 KB
@@ -52,6 +52,9 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
52
52
  - **stitchkit/google**: [llms/google.txt](llms/google.txt) 1.4 KB
53
53
  - **stitchkit/declaration**: [llms/declaration.txt](llms/declaration.txt) 16.0 KB
54
54
  - **stitchkit/node**: [llms/node.txt](llms/node.txt) 3.1 KB
55
+ - **stitchkit/agent-runtime/react**: [llms/agent-runtime-react.txt](llms/agent-runtime-react.txt) 1.0 KB
56
+ - **stitchkit/agent-runtime/realtime**: [llms/agent-runtime-realtime.txt](llms/agent-runtime-realtime.txt) 1.8 KB
57
+ - **stitchkit/agent-runtime/harness-tools**: [llms/agent-runtime-harness-tools.txt](llms/agent-runtime-harness-tools.txt) 1.3 KB
55
58
 
56
59
  ## Upgrading slices
57
60
  - **Upgrading — how to move across versions**: [llms/upgrading.txt](llms/upgrading.txt) 10.3 KB
@@ -69,6 +72,7 @@ Load the slice for each entrypoint your code imports — `import … from 'stitc
69
72
  - [Typed client](https://github.com/max-listov/stitchkit/blob/master/docs/guide/client.md): createClient/createHttpClient, the typed call surface, scoped clients, SSE
70
73
  - [MCP & agents](https://github.com/max-listov/stitchkit/blob/master/docs/guide/mcp-and-agents.md): contracts as MCP tools (createMcpHandler) and AI-agent tools (mountAgent); tool lifecycle, extend, identity, a separate tool answer (withToolView)
71
74
  - [Agent application runtime](https://github.com/max-listov/stitchkit/blob/master/docs/guide/agent-runtime.md): optional durable history, prompt/model composition, stream loop, coordination, fencing and events
75
+ - [Agent composition](https://github.com/max-listov/stitchkit/blob/master/docs/guide/agent-composition.md): tool factories, authorized realtime control, shared React views and exact-run behavior checks
72
76
  - [Managed application kernel](https://github.com/max-listov/stitchkit/blob/master/docs/guide/application-kernel.md): process-local resources, readiness, admission, schedules, projections and optional provider adapters
73
77
  - [Optional process sandbox](https://github.com/max-listov/stitchkit/blob/master/docs/guide/sandbox.md): Linux Bubblewrap sessions, durable workspace reconnect, network policy and host credential brokering
74
78
  - [Generic application primitives](https://github.com/max-listov/stitchkit/blob/master/docs/guide/primitives.md): lifecycle transitions, owner scope, permissions, exact money and quantities, deadlines, audit, delivery and exports — declared, not persisted
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.103.0",
3
+ "version": "0.103.1",
4
4
  "description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
5
5
  "keywords": [
6
6
  "bun",
@@ -221,6 +221,18 @@
221
221
  "./node": {
222
222
  "types": "./dist/entrypoints/node.d.ts",
223
223
  "import": "./dist/entrypoints/node.js"
224
+ },
225
+ "./agent-runtime/react": {
226
+ "types": "./dist/entrypoints/agent-runtime/react.d.ts",
227
+ "import": "./dist/entrypoints/agent-runtime/react.js"
228
+ },
229
+ "./agent-runtime/realtime": {
230
+ "types": "./dist/entrypoints/agent-runtime/realtime.d.ts",
231
+ "import": "./dist/entrypoints/agent-runtime/realtime.js"
232
+ },
233
+ "./agent-runtime/harness-tools": {
234
+ "types": "./dist/entrypoints/agent-runtime/harness-tools.d.ts",
235
+ "import": "./dist/entrypoints/agent-runtime/harness-tools.js"
224
236
  }
225
237
  },
226
238
  "publishConfig": {