@happyvertical/smrt-chat 0.60.18 → 0.61.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.
Files changed (86) hide show
  1. package/AGENTS.md +16 -22
  2. package/README.md +78 -0
  3. package/agents/owner-approvals.md +161 -0
  4. package/agents/runtime-exposure.md +28 -0
  5. package/agents/runtime-report-tools.md +26 -0
  6. package/agents/token-streaming.md +6 -0
  7. package/agents/tool-loop.md +13 -0
  8. package/agents/tool-summaries.md +155 -0
  9. package/agents/turn-drivers.md +293 -0
  10. package/dist/assistant-approvals.d.ts +45 -0
  11. package/dist/assistant-approvals.d.ts.map +1 -0
  12. package/dist/assistant-approvals.js +83 -0
  13. package/dist/assistant-approvals.js.map +1 -0
  14. package/dist/assistant-turn-driver.d.ts +73 -0
  15. package/dist/assistant-turn-driver.d.ts.map +1 -0
  16. package/dist/assistant-turn-events.d.ts +28 -1
  17. package/dist/assistant-turn-events.d.ts.map +1 -1
  18. package/dist/assistant-turn-events.js +2 -2
  19. package/dist/assistant-turn.d.ts +24 -37
  20. package/dist/assistant-turn.d.ts.map +1 -1
  21. package/dist/chunks/{ChatService-BGBAqmZq.js → ChatService-C1UBz0MR.js} +684 -657
  22. package/dist/chunks/ChatService-C1UBz0MR.js.map +1 -0
  23. package/dist/chunks/{assistant-turn-events-BbZUf-Ju.js → assistant-turn-events-DwdCZzQ0.js} +15 -2
  24. package/dist/chunks/assistant-turn-events-DwdCZzQ0.js.map +1 -0
  25. package/dist/chunks/chat-stream-mTbNV3kt.js +3571 -0
  26. package/dist/chunks/chat-stream-mTbNV3kt.js.map +1 -0
  27. package/dist/engines.d.ts +34 -0
  28. package/dist/engines.d.ts.map +1 -0
  29. package/dist/engines.js +260 -0
  30. package/dist/engines.js.map +1 -0
  31. package/dist/index.d.ts +4 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +8 -6
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal/agent-runtime.js +1 -1
  36. package/dist/manifest.json +3 -1
  37. package/dist/persona-conversation.d.ts.map +1 -1
  38. package/dist/runtime-report-tools.d.ts.map +1 -1
  39. package/dist/services/ChatService.d.ts +3 -13
  40. package/dist/services/ChatService.d.ts.map +1 -1
  41. package/dist/smrt-knowledge.json +46 -9
  42. package/dist/smrt-knowledge.okf.md +29 -4
  43. package/dist/svelte/components/assistant/AssistantApprovalCard.svelte +198 -0
  44. package/dist/svelte/components/assistant/AssistantApprovalCard.svelte.d.ts +34 -0
  45. package/dist/svelte/components/assistant/AssistantApprovalCard.svelte.d.ts.map +1 -0
  46. package/dist/svelte/components/assistant/AssistantComposer.svelte +6 -3
  47. package/dist/svelte/components/assistant/AssistantComposer.svelte.d.ts +2 -0
  48. package/dist/svelte/components/assistant/AssistantComposer.svelte.d.ts.map +1 -1
  49. package/dist/svelte/components/assistant/AssistantDock.svelte +66 -17
  50. package/dist/svelte/components/assistant/AssistantDock.svelte.d.ts +2 -0
  51. package/dist/svelte/components/assistant/AssistantDock.svelte.d.ts.map +1 -1
  52. package/dist/svelte/components/assistant/assistant-http-client.d.ts +2 -0
  53. package/dist/svelte/components/assistant/assistant-http-client.d.ts.map +1 -1
  54. package/dist/svelte/components/assistant/assistant-http-client.js +28 -1
  55. package/dist/svelte/components/assistant/assistant-transport.d.ts +18 -1
  56. package/dist/svelte/components/assistant/assistant-transport.d.ts.map +1 -1
  57. package/dist/svelte/components/assistant/assistant-transport.js +2 -0
  58. package/dist/svelte/components/assistant/create-assistant-dock-controller.svelte.d.ts +5 -1
  59. package/dist/svelte/components/assistant/create-assistant-dock-controller.svelte.d.ts.map +1 -1
  60. package/dist/svelte/components/assistant/create-assistant-dock-controller.svelte.js +80 -4
  61. package/dist/svelte/i18n.d.ts +14 -0
  62. package/dist/svelte/i18n.d.ts.map +1 -1
  63. package/dist/svelte/i18n.js +14 -0
  64. package/dist/svelte/i18n.messages.d.ts +13 -0
  65. package/dist/svelte/i18n.messages.d.ts.map +1 -1
  66. package/dist/svelte/i18n.messages.js +13 -0
  67. package/dist/svelte/index.d.ts +2 -1
  68. package/dist/svelte/index.d.ts.map +1 -1
  69. package/dist/svelte/index.js +1 -0
  70. package/dist/sveltekit.d.ts +72 -4
  71. package/dist/sveltekit.d.ts.map +1 -1
  72. package/dist/sveltekit.js +439 -21
  73. package/dist/sveltekit.js.map +1 -1
  74. package/dist/tool-loop.d.ts +36 -3
  75. package/dist/tool-loop.d.ts.map +1 -1
  76. package/dist/tool-summary.d.ts +15 -0
  77. package/dist/tool-summary.d.ts.map +1 -0
  78. package/dist/tool-summary.js +95 -0
  79. package/dist/tool-summary.js.map +1 -0
  80. package/dist/work-profile.d.ts +64 -0
  81. package/dist/work-profile.d.ts.map +1 -0
  82. package/package.json +36 -22
  83. package/dist/chunks/ChatService-BGBAqmZq.js.map +0 -1
  84. package/dist/chunks/assistant-turn-events-BbZUf-Ju.js.map +0 -1
  85. package/dist/chunks/chat-stream-Blri3lj0.js +0 -2743
  86. package/dist/chunks/chat-stream-Blri3lj0.js.map +0 -1
@@ -0,0 +1,293 @@
1
+ # Assistant turn drivers
2
+
3
+ `mountAssistantRoutes({ turnDriver, resolveTurnDriver })` and
4
+ `runAssistantTurn({ turnDriver })` accept an `AssistantTurnDriver` with
5
+ `run(context, callbacks): Promise<void>`. Types are exported from the package
6
+ root and `./sveltekit`. No driver means the existing `runToolLoop`, with the
7
+ same model options, browser suspension/resume, budgets, persistence policy,
8
+ and wire events. An external driver replaces the loop only.
9
+
10
+ The route resolves `resolveTurnDriver(ctx)` once per send/resume, before
11
+ storing the user message. Its context includes the authenticated principal,
12
+ request event, validated but untrusted `requestContext`, and selected model.
13
+ An undefined result falls back to the static `turnDriver`, then the built-in
14
+ loop. Selection belongs to the host; never authorize an engine from request
15
+ input alone. A resolver may throw the same inference-unavailable error used
16
+ by the model factory to preserve the structured `ai_unavailable` 503 and its
17
+ engine-status/settings response. Other resolver failures become the existing
18
+ sanitized `assistant_unavailable` 503. Refused sends author nothing.
19
+
20
+ Without an external driver, `ai` is either an SDK-compatible client or a
21
+ factory called once per turn with that same authenticated request context.
22
+ That path supports user-specific model adapters, including adapters that
23
+ translate `chat(messages, options)` / `onProgress` and omit unsupported
24
+ sampling, token-limit or streaming options. Chat does not cache the factory's
25
+ result between requests. External drivers do not resolve `ai` at all.
26
+
27
+ ## External adapter
28
+
29
+ ```ts
30
+ import {
31
+ mountAssistantRoutes,
32
+ type AssistantTurnDriver,
33
+ } from '@happyvertical/smrt-chat/sveltekit';
34
+
35
+ const driver: AssistantTurnDriver = {
36
+ async run(context, callbacks) {
37
+ // Replace this body with the host's CLI/agent adapter.
38
+ // Supply context.signal to its subprocess and MCP transport.
39
+ callbacks.text('I am checking the studio.');
40
+ callbacks.done({ text: 'The studio is ready.' });
41
+ },
42
+ };
43
+
44
+ export const { GET, POST } = mountAssistantRoutes({
45
+ turnDriver: driver,
46
+ systemPrompt: 'Help the studio owner.',
47
+ allowedTools: [],
48
+ });
49
+ ```
50
+
51
+ `context` carries server-selected thread/session identity, origin message id,
52
+ prior user/assistant messages (oldest first), the new user message, system
53
+ instructions/persona guidance, the principal, optional permission ceiling,
54
+ allow-listed manifest/server tools and an `AbortSignal`. The route mirrors
55
+ that allow-list onto the session for authoring too. External drivers are
56
+ trusted server integrations: the host must bind their MCP credentials and
57
+ execution to this same principal, tool set, tenancy and permission ceiling.
58
+ Reporting a tool event is not execution authorization. No engine is imported
59
+ by chat, and driver callbacks never execute a tool.
60
+
61
+ The callbacks map directly to engine progress:
62
+
63
+ - `text(delta)` emits the existing `token` preview.
64
+ - `await toolCall({ id, name, args })` emits a server `tool_call` step and
65
+ authors a tool-call row. Names are canonical app slugs, not provider aliases.
66
+ - `await toolResult({ id, ok, result?, error? })` emits the matching result
67
+ step and authors a tool-result row. `result` is serialized text; `error`
68
+ must be user-safe, as it is shown in the step. Unknown, duplicate or
69
+ unoffered calls/results fail the turn without authoring an unauthorized row.
70
+ - `await approvalNeeded({ id, callId, tool, summary })` emits the additive
71
+ `approval_needed` wire event and waits for the host bridge described below.
72
+ - `done({ text, usage? })` selects the final answer and optional aggregate
73
+ `ToolLoopUsage` for `onUsage`. Chat authors the final answer once `run`
74
+ settles. Blank answers use the configured empty-answer fallback.
75
+ - `error(error)` or a thrown error logs detail through `onError`, authors any
76
+ partial text and a sanitized failure row, and emits the existing `error`
77
+ event. A run returning without `done` is also a failure.
78
+
79
+ Call `done` or `error` once and settle `run`; callbacks after termination or
80
+ abort are ignored. Await tool callbacks to preserve persistence ordering.
81
+ Request abort and response-body cancellation reach `context.signal`; chat
82
+ settles as cancelled even if the engine fails to settle. The adapter must
83
+ stop its subprocess and MCP activity when aborted. Partial streamed text is
84
+ saved on cancellation. All rows are authored by `ChatService` in the turn's
85
+ existing database lifetime and linked to the originating user message.
86
+ External tool-call and result rows are saved by default; the built-in loop's
87
+ `authorInvocation`/failure-collapse policy is unchanged.
88
+
89
+ External loops currently receive server tools only. Browser tool
90
+ suspension/resume remains owned by the default driver; selecting an external
91
+ driver on a browser continuation explicitly fails with
92
+ `driver_resume_unsupported`. Do not change engines between the legs of a
93
+ suspended browser turn. Existing dock token, step, message and terminal event
94
+ handling renders external progress without a new transport or panel.
95
+
96
+ ## Owner approval bridge
97
+
98
+ `AssistantApprovalRequest`, `AssistantApprovalDecision` and
99
+ `AssistantApprovalWaiter` define the server-write boundary. Mounted routes default
100
+ to app-runtime's durable owner authority over the canonical smrt-approvals ledger.
101
+ Chat rebuilds requests from the pending offered call, authors them to the thread,
102
+ streams `approval_needed`, and waits for the authenticated owner's exact decision.
103
+ The driver must await it before executing and honor denial; its host/MCP adapter
104
+ must execute under the original principal with live permissions and the supplied
105
+ ceiling. It must never expose the decision route as a model tool.
106
+
107
+ An explicitly supplied `waitForApproval` without `approvals` retains the trusted
108
+ host callback integration: it must durably store the exact call and authorize the
109
+ owner itself. Direct entry points without any bridge deny. Abort releases the
110
+ wait without granting permission. Durable defaults, policy, routes, card and crash
111
+ limits: [owner-approvals.md](owner-approvals.md).
112
+
113
+ ## Validation
114
+
115
+ `src/sveltekit.test.ts` (external turn drivers) covers the authenticated SQLite route,
116
+ stream ordering, tool and text persistence, origin links, safe failures,
117
+ abort propagation, per-user/request driver and model resolution, history,
118
+ offer/ownership gates and approval waits. Existing assistant-turn and dock
119
+ suites cover the unchanged default loop/wire reader. No live engines,
120
+ providers, MCP servers or containers are required.
121
+
122
+ The behavior-to-test matrix below uses `pnpm --dir packages/chat test` for
123
+ all rows. Each case is route integration on Node/SQLite with fake engines;
124
+ `ChatService` remains the data executor in the existing turn lifetime. There
125
+ are no new SQL statements, schema, transaction boundaries or retries; the
126
+ existing service/default-loop suites retain those dialect and atomicity
127
+ contracts. No external engine or durable approval-store implementation is
128
+ claimed here.
129
+
130
+ | Behavior/invariant | Reachable trigger | Positive case | Negative/failure case | Actor/context | Executor/transaction | Runtime/dialect | External edge | Level | Command |
131
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
132
+ | Authoring and wire parity | Send with a driver | Text, calls, results, final and origin links saved | Upstream failure saves partial and safe failure | Authenticated owner/thread | ChatService/turn lifetime | Node/SQLite | Engine callbacks → existing SSE reader | Route integration | Package test |
133
+ | Offer and ownership gates | Foreign send or reported tool | Offered canonical tool accepted | Foreign actor 404; unoffered or duplicate call refused | Owner × foreign actor × owned thread | ChatService/turn lifetime | Node/SQLite | Canonical app slugs | Route integration | Package test |
134
+ | Model/driver selection | Context engine selection | Two users get their own adapter/driver; history retained | Unconfigured resolver 503 without a user row | Authenticated request/user | ChatService/no writes on refusal | Node/SQLite | SDK factory and driver resolver | Route integration | Package test |
135
+ | Terminal contract | Engine settles | Done ends once | Missing done, unmatched result and duplicate call become safe errors | Owner/thread | ChatService/turn lifetime | Node/SQLite | Missing or malformed callbacks | Route integration | Package test |
136
+ | Abort/stop | Request abort or body cancel | Signal reaches driver | Never-settling run/approval released; late events ignored | Owner's active turn | ChatService/turn lifetime | Node/SQLite | AbortSignal | Route integration | Package test |
137
+ | Approval seam | Pending tool requests approval | Host decision awaited and event emitted | Missing bridge denies; cancellation denies | Bound principal and pending call | Host hook; durability deferred to C3 | Node/SQLite | Approval request/decision | Route integration | Package test |
138
+ | Default loop | Send with no driver | Existing loop and dock tests unchanged | Existing provider/tool/browser-failure cases retained | Existing principal fixtures | Existing service/loop transactions | Existing package suite runtimes | Existing model and browser wire | Package regression | Package test |
139
+
140
+ ## Reuse audit
141
+
142
+ Audited against base `06c0b64fe3` using `git diff --stat 06c0b64fe3 HEAD`:
143
+ C1 adds one production helper module and this contract reference; its driver
144
+ tests extend the existing route suite. It adds no component, model, route or
145
+ production tool. Existing
146
+ `mountAssistantRoutes`, `runAssistantTurn`, `AssistantTurnOptions`,
147
+ `MountAssistantRoutesOptions` and `AssistantTurnEvent` are extended in place.
148
+
149
+ The configured `smrt-dev-mcp` server was available. `review-smrt-project`
150
+ reviewed `packages/chat` with duplicate detection and source evidence;
151
+ `introspect-project` listed the existing chat models, `build-context`
152
+ (architecture) searched for external assistant loops, tool callbacks and
153
+ approval waits, and `build-package-specialist-context` searched chat's
154
+ assistant recipe and tool contracts. This server exposes no dedicated
155
+ component/intent/recipe search tool, so those lookups also read
156
+ `docs/knowledge/intents/index.md`, its human-approvals reference, the recipe
157
+ sources and the source packages with `rg`.
158
+
159
+ Both names and purposes were searched in `packages/smrt-ui`, `smrt-svelte`,
160
+ `chat`, `core`, `agents`, `inference`, `approvals`, `app-runtime` and
161
+ `app-shell`: `turn.?driver`, `external.*(agent|loop|turn)`, `toolCall`,
162
+ `AssistantClientToolCall`, `AssistantClientToolResult`, `ToolInvocation`,
163
+ `approval.*(wait|decision)`, `approved: boolean`, `confirmSave`, `consent`,
164
+ `holdForUser`, and `chat.assistant`. The results and decisions are:
165
+
166
+ | Introduced file/symbols | Existing capability and reuse decision |
167
+ | --- | --- |
168
+ | `src/assistant-turn-driver.ts`: `runExternalAssistantTurn`, its local `persist`, `enqueue`, `active` and abort closures | Reuses `sendAgentReply`/ChatService, `resolveTurnReply`, `replyMetadataFor`, the existing turn reporter, SSE producer and status/step/message contracts. No existing loop-independent bridge fits: `runPersonaConversationTurn` and `streamPersonaConversation` own model loops; shell `runAgentTurn` and `holdForUser` depend on shell models, credentials and event bus. Engine extraction belongs to C2, not this bridge. The queue only orders this driver's callbacks; it is not a durable/background queue. |
169
+ | Same file: `AssistantDriverToolCall`, callback tool-result parameter | Derives the call from `Pick<AssistantClientToolCall, 'id' \| 'name' \| 'args'>` and reuses `AssistantClientToolResult` directly. Existing `PendingClientToolCall` adds browser effect; `ToolInvocation` describes completed execution, not a started call. No duplicate field declarations remain. |
170
+ | Same file: `AssistantTurnDriver`, `AssistantTurnDriverContext`, `AssistantTurnDriverCallbacks` | New loop-independent host contract; reuses `AIMessage`, `PrincipalBinding`, `PrincipalTool`, `ManifestTool`, `ToolLoopUsage` and `AbortSignal`; `AssistantTurnOptions.thread` refers to the context's thread type. Existing model-loop options and shell-specific engine dependencies are not interchangeable with a host-owned loop. |
171
+ | Same file: `AssistantApprovalDecision`, `AssistantApprovalWaiter`; existing `src/assistant-turn-events.ts`: `AssistantApprovalRequest` | New transport notification/result and wait-hook contract only. `smrt-approvals` already owns durable `ApprovalRequest`, `ApprovalDecision` (approve/reject/request_changes), `ApprovalService.decide` and `consume`; they are not a callback outcome or chat tool-call notification. C3 must adapt that authority rather than implement another ledger. Shell `HoldOutcome` includes execution results and shell events and cannot serve as a package-neutral wait result. Chat's `RuntimeReportConfirmationHost.confirmSave` accepts only a report spec/hash and rejects to deny; data-surface confirmation is a required/none policy. Neither represents a generic pending tool notification or approval outcome. |
172
+ | Removed `src/sveltekit.turn-driver.test.ts`: its local `Round`, `Actor`, `scriptedAI`, `text`, `discoverTool`, `locals`, `events`, `mount`, `call`, `createThread`, `listMessages`, `send` and setup callbacks | Name/purpose searches found the same private helpers in `src/sveltekit.test.ts`. Moved all 11 driver cases into a nested describe there and deleted the duplicate file. Existing case bodies are unchanged; the new cases now reuse its SQLite/user/tenant fixtures, fake model/tool and SSE reader. No production tool is registered. |
173
+ | `agents/turn-drivers.md` | Contract documentation for the extension of existing `chat.assistant`/`AssistantDock`; no new recipe, UI or model. |
174
+
175
+ The review's missing-`smrt-svelte` dependency/shell advisories describe the
176
+ existing dev workbench, not new driver imports. `workspace-aliases.js`
177
+ explicitly documents that dev-only source alias: declaring the dependency
178
+ would introduce the prohibited `chat → smrt-svelte → smrt-content → chat`
179
+ cycle. Production driver code introduces neither that import nor a new
180
+ shell; no dependency change is appropriate for C1.
181
+
182
+ ## Work profiles and design interception
183
+
184
+ `resolveWorkProfile(context, name?)` selects intelligence from authenticated
185
+ owner settings before authoring the user message. It receives a requested name
186
+ only on escalation; known design flows select `design` in the initial callback.
187
+ The resolved profile is forwarded to inference and its budgets govern the loop.
188
+ Background work must request `background` explicitly. Profile selection never
189
+ changes principal, tenant, permission ceiling, allow-list or owner approvals.
190
+
191
+ Hosts declare structural tools with `designTools`, or trusted tool metadata
192
+ `annotations.workProfile: 'design'` (core cookbook tools provide this annotation).
193
+ The built-in loop checks the whole proposed batch before executing any call.
194
+ External drivers MUST call `context.beforeToolExecution(canonicalSlug)` at their
195
+ **authenticated MCP execution boundary**, before effects or approval creation.
196
+ A later CLI tool-call stream event is too late. Interception aborts and settles
197
+ the old pass, then restarts once under design while retaining completed tool
198
+ observations. The intercepted assist call never executes.
199
+
200
+ Production hosts use `onDesignEscalation(context, input)` to enqueue a durable
201
+ design job. Returning `{runId, message?}` ends the request with `done.runId` and
202
+ prevents inline restart. Without the hook, the shared bounded turn restarts
203
+ inline once. `resolveWorkProfileRuntime` reselects an engine on that restart.
204
+ `Thinking this through` identifies escalation using the existing status stream.
205
+
206
+ Stored assistant rows contain `metadata.workRun`: profile, engine, actual model
207
+ when reported by the engine, effort, cumulative tokens, duration, tool calls and
208
+ fallback. `onWorkRun` receives the same sanitized accounting; the default logs
209
+ one line. CLI adapters report observed execution through `callbacks.execution`;
210
+ this also preserves spent assist work when escalation aborts its attempt.
211
+
212
+ Reuse audit: the developer intent index and MCP build-context architecture
213
+ inventory, plus name/purpose searches in chat/core/inference/smrt-ui/smrt-svelte,
214
+ identified the existing turn driver, tool-loop and cookbook annotations as the
215
+ owning seams. This extends those APIs; it adds no alternate approval ledger,
216
+ model registry, UI component or tool executor.
217
+
218
+ For durable jobs, the browser's `createAssistantHttpTransport({designRuns:true})`
219
+ reads `GET /design-runs?threadId=…` and posts `/design-runs/{runId}/stop` or
220
+ `/resume`. Hosts authenticate and owner-scope these routes. Each returns
221
+ `{run?:{runId,pass:{index,count,name},status,note?}}` with a one-based pass index.
222
+ The dock reloads progress when opening a thread, polls it, and reuses its status
223
+ and Stop controls; stopped/failed jobs offer Resume. Closing/unmounting the dock
224
+ leaves a durable job running. No browser id grants access to a run.
225
+
226
+ `formatAssistantReply(content, context)` is a trusted host presentation hook for
227
+ structured pass output. It returns human-facing `content` and optional metadata
228
+ before persistence; hosts can keep the validated output under
229
+ `metadata.designOutput` for their durable runner. That output is available only
230
+ on the trusted internal pass SSE handoff, never ordinary message wire objects.
231
+ Ordinary replies are unchanged.
232
+
233
+ Known design flows set `deferDesignTurn` to queue through that same durable hook
234
+ before any model call. Detached passes use the trusted `internalTurn(context)`
235
+ callback to supply private pass input and the original owner-message id. The
236
+ route still authenticates ownership and validates that original message against
237
+ the same thread and actor, but authors no synthetic user message and does not
238
+ rewrite the original send's lifecycle. Private pass bindings belong to the host,
239
+ not browser request flags. After that callback and the original-message checks,
240
+ the route records the request in its own WeakSet and stamps every assistant/tool
241
+ write with trusted `assistantInternalTurn` provenance via the existing author
242
+ metadata. This applies to the built-in loop, external driver, errors and tool
243
+ holds. Request headers, body/context fields and user-authored metadata cannot
244
+ select that provenance. Raw rows remain available to private provider history.
245
+
246
+ The ordinary message route requests `ChatService`'s conversation visibility.
247
+ It excludes marked assistant/tool rows and positively identified legacy assistant
248
+ rows with `designOutput`; user rows are never hidden by metadata. Filtering runs
249
+ before the visible limit using ordinary tenant/member-scoped collection pages
250
+ of 200, deterministic timestamp/id ordering, and the existing list-bound resolver.
251
+ Reply lookup rejects a hidden root and filters linked replies in the same way.
252
+ Raw service reads retain their previous default. Legacy unmarked tool rows have
253
+ no reliable run/pass linkage and are not deleted or heuristically attributed.
254
+ Public wire metadata includes only `workRun` and `designRunId`.
255
+
256
+ Hosts may opt into `toolPresentation: 'generic'` on the routes and AssistantDock.
257
+ It uses `describeAssistantTool` without raw observations, summaries or arguments;
258
+ unknown tool messages receive a fixed person-facing fallback. The same projection
259
+ covers live SSE messages, steps/status, stored legacy tool messages, and approval
260
+ references. The dock also suppresses raw browser-tool name/description/argument
261
+ fallbacks while retaining destructive warnings and the existing decision controls.
262
+ Public generic streams omit provisional model tokens; the final formatted answer
263
+ remains visible. Trusted internal handoff streams retain their original tokens.
264
+ Default clients and private provider history keep their existing contracts.
265
+
266
+ For meaningful approval previews under generic presentation, the trusted async
267
+ `presentApproval(record)` callback receives the canonical authorized hold and
268
+ returns only a host-derived business summary. The public summary and explicit
269
+ `presentation.summary` carry that caption; unsafe/unrecognized holds fall back to
270
+ “Review this change.” No raw stored/model summary is promoted by this option.
271
+ The existing card uses only the explicit presentation in generic mode; polling
272
+ and decisions still use the canonical authority.
273
+
274
+ The route tests cover built-in and external actual-tool passes, raw private SSE
275
+ handoff, reload, forged request flags, hidden-root refusal, legacy app-description
276
+ and ordinary-record tool rows, ordinary human/assistant retention, and 201 internal
277
+ rows ahead of the public page. DOM tests render legacy messages, browser-tool
278
+ confirmation and approval refresh with malicious raw captions and safe host previews.
279
+ Both default contracts and opted presentation run in the affected regression suites.
280
+
281
+ Token accounting is conservative: `workRun.tokens` is omitted if any completion
282
+ omits valid usage, including across escalation and browser continuations. An
283
+ explicit zero remains zero. `ToolLoopResult.totalTokens` remains the numeric
284
+ known subtotal; `usageKnown` distinguishes it from complete usage. API model
285
+ metadata uses a provider-reported model when available; effort describes the
286
+ requested profile effort, subject to provider support and normalization.
287
+
288
+ On durable admission, the intercepted assist turn is recorded separately before
289
+ `done`: a human handoff message carries `metadata.designRunId` and its original
290
+ `workRun` (spent tokens when fully known, elapsed time and calls). The durable
291
+ job's budget begins at its own admission; earlier assist work is not presented
292
+ as part of that job's usage. Missing observed external models remain unknown;
293
+ the requested profile alias is never substituted as an actual model.
@@ -0,0 +1,45 @@
1
+ /** Server-write policy and durable hold bridge. Host code supplies authority, never model output. */
2
+ import type { PrincipalTool } from '@happyvertical/smrt-agents';
3
+ import type { OwnerApprovalAuthority } from '@happyvertical/smrt-app-runtime';
4
+ import type { AssistantApprovalWaiter } from './assistant-turn-driver.js';
5
+ import type { AssistantApprovalRequest } from './assistant-turn-events.js';
6
+ import type { ManifestTool } from './tool-loop.js';
7
+ export interface AssistantApprovalCall {
8
+ id: string;
9
+ originMessageId?: string;
10
+ permissions?: readonly string[];
11
+ tool: ManifestTool | PrincipalTool;
12
+ args: Record<string, unknown>;
13
+ }
14
+ /** Tool override, then operation override, then destructive-name default. */
15
+ export interface AssistantApprovalPolicy {
16
+ /** Trusted host choice for in-app chat only. Never read from tool arguments. */
17
+ allowRemovalsInChat?: boolean;
18
+ tools?: Readonly<Record<string, boolean>>;
19
+ operations?: Readonly<Record<string, boolean>>;
20
+ }
21
+ export declare function requiresOwnerApproval(tool: ManifestTool | PrincipalTool, args: Record<string, unknown>, policy?: AssistantApprovalPolicy, destructiveHint?: boolean): boolean;
22
+ export interface AssistantApprovalBridge {
23
+ policy?: AssistantApprovalPolicy;
24
+ request(call: AssistantApprovalCall): Promise<AssistantApprovalRequest>;
25
+ wait?: AssistantApprovalWaiter;
26
+ complete?: (request: AssistantApprovalRequest, ok: boolean, result: unknown) => Promise<void>;
27
+ }
28
+ /** Creates requests from server-supplied snapshots and canonical calls, never an engine's id/summary. */
29
+ export declare function createAssistantApprovalBridge(options: {
30
+ authority: OwnerApprovalAuthority;
31
+ tenantId: string;
32
+ requestedBy: string;
33
+ context: Record<string, unknown>;
34
+ policy?: AssistantApprovalPolicy;
35
+ summary?: (call: AssistantApprovalCall) => string;
36
+ }): AssistantApprovalBridge;
37
+ /** Observe a host-executed durable hold without deciding, consuming or replaying it. */
38
+ export declare function observeAssistantApproval(options: {
39
+ authority: OwnerApprovalAuthority;
40
+ tenantId: string;
41
+ id: string;
42
+ signal: AbortSignal;
43
+ timeoutMs: number;
44
+ }): Promise<import("@happyvertical/smrt-app-runtime").OwnerApproval | null>;
45
+ //# sourceMappingURL=assistant-approvals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant-approvals.d.ts","sourceRoot":"","sources":["../src/assistant-approvals.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,IAAI,EAAE,YAAY,GAAG,aAAa,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,6EAA6E;AAC7E,MAAM,WAAW,uBAAuB;IACtC,gFAAgF;IAChF,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAChD;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,YAAY,GAAG,aAAa,EAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,CAAC,EAAE,uBAAuB,EAChC,eAAe,UAAQ,GACtB,OAAO,CAsET;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACxE,IAAI,CAAC,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,CAAC,EAAE,CACT,OAAO,EAAE,wBAAwB,EACjC,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,OAAO,KACZ,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,yGAAyG;AACzG,wBAAgB,6BAA6B,CAAC,OAAO,EAAE;IACrD,SAAS,EAAE,sBAAsB,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,MAAM,CAAC;CACnD,GAAG,uBAAuB,CAkD1B;AAED,wFAAwF;AACxF,wBAAsB,wBAAwB,CAAC,OAAO,EAAE;IACtD,SAAS,EAAE,sBAAsB,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,2EAaA"}
@@ -0,0 +1,83 @@
1
+ import { ObjectRegistry } from "@happyvertical/smrt-core";
2
+ //#region src/assistant-approvals.ts
3
+ function requiresOwnerApproval(tool, args, policy, destructiveHint = false) {
4
+ const operation = "action" in tool ? tool.action : tool.slug.split(".").at(-1) ?? "";
5
+ const destructive = (value) => /(?:^|[._-])(delete|remove|destroy|purge|drop|truncate)(?:$|[._-])/i.test(value.replace(/([a-z])([A-Z])/g, "$1_$2"));
6
+ const purge = [
7
+ operation,
8
+ tool.slug,
9
+ String(args.operation ?? args.action ?? "")
10
+ ].map((value) => value.replace(/([a-z])([A-Z])/g, "$1_$2")).some((value) => /(?:^|[._-])(purge|drop|truncate|destroy)(?:$|[._-])/i.test(value));
11
+ const identity = "action" in tool ? tool.qualifiedName ?? tool.className : void 0;
12
+ const declaration = identity ? ObjectRegistry.getClass(identity) : void 0;
13
+ const recordDeletion = !([
14
+ identity,
15
+ ...declaration ? ObjectRegistry.getInheritanceChain(declaration.qualifiedName ?? declaration.name) : [],
16
+ ...declaration?.replacedQualifiedNames ?? []
17
+ ].some((name) => name && [
18
+ "@happyvertical/smrt-users",
19
+ "@happyvertical/smrt-profiles",
20
+ "@happyvertical/smrt-tenancy",
21
+ "@happyvertical/smrt-secrets",
22
+ "@happyvertical/smrt-preferences",
23
+ "@happyvertical/smrt-config",
24
+ "@happyvertical/smrt-features",
25
+ "@happyvertical/smrt-app-runtime",
26
+ "@happyvertical/smrt-app-shell",
27
+ "@happyvertical/smrt-inference",
28
+ "@happyvertical/smrt-approvals"
29
+ ].includes(name.split(":")[0])) || !!declaration && ObjectRegistry.getConfig(declaration.qualifiedName ?? declaration.name).sensitive === true) && "action" in tool && tool.action === "delete" && tool.annotations?.recordDeletion === true && tool.annotations?.workProfile !== "design" && typeof args.id === "string" && args.id.trim().length > 0;
30
+ if (purge) return true;
31
+ return policy?.tools?.[tool.slug] ?? policy?.operations?.[operation] ?? (policy?.allowRemovalsInChat && recordDeletion ? false : destructiveHint || destructive(operation) || destructive(tool.slug) || destructive(String(args.operation ?? args.action ?? "")));
32
+ }
33
+ function createAssistantApprovalBridge(options) {
34
+ return {
35
+ policy: options.policy,
36
+ async request(call) {
37
+ const record = await options.authority.request({
38
+ tenantId: options.tenantId,
39
+ requestedBy: options.requestedBy,
40
+ tool: call.tool.slug,
41
+ callId: call.id,
42
+ args: call.args,
43
+ summary: options.summary?.(call) ?? `Allow ${call.tool.slug}${typeof call.args.id === "string" ? ` for ${call.args.id.slice(0, 200)}` : ""}?`,
44
+ context: {
45
+ ...options.context,
46
+ ...call.permissions ? { permissionCeiling: [...call.permissions] } : {},
47
+ ...call.originMessageId ? { originMessageId: call.originMessageId } : {}
48
+ }
49
+ });
50
+ return {
51
+ id: record.id,
52
+ tool: record.tool,
53
+ callId: record.callId,
54
+ summary: record.summary
55
+ };
56
+ },
57
+ async complete(request, ok, result) {
58
+ await options.authority.complete(options.tenantId, request.id, ok, result);
59
+ },
60
+ async wait(request, context) {
61
+ const record = await options.authority.wait(options.tenantId, request.id, context.signal);
62
+ if (context.signal.aborted || record?.status !== "approved") return {
63
+ approved: false,
64
+ reason: record?.status ?? "cancelled"
65
+ };
66
+ await options.authority.consume(options.tenantId, request.id);
67
+ return { approved: true };
68
+ }
69
+ };
70
+ }
71
+ async function observeAssistantApproval(options) {
72
+ const timeout = new AbortController();
73
+ const timer = setTimeout(() => timeout.abort(), options.timeoutMs);
74
+ try {
75
+ return await options.authority.wait(options.tenantId, options.id, AbortSignal.any([options.signal, timeout.signal]), { settled: true });
76
+ } finally {
77
+ clearTimeout(timer);
78
+ }
79
+ }
80
+ //#endregion
81
+ export { createAssistantApprovalBridge, observeAssistantApproval, requiresOwnerApproval };
82
+
83
+ //# sourceMappingURL=assistant-approvals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant-approvals.js","names":[],"sources":["../src/assistant-approvals.ts"],"sourcesContent":["/** Server-write policy and durable hold bridge. Host code supplies authority, never model output. */\nimport type { PrincipalTool } from '@happyvertical/smrt-agents';\nimport type { OwnerApprovalAuthority } from '@happyvertical/smrt-app-runtime';\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\nimport type { AssistantApprovalWaiter } from './assistant-turn-driver.js';\nimport type { AssistantApprovalRequest } from './assistant-turn-events.js';\nimport type { ManifestTool } from './tool-loop.js';\n\nexport interface AssistantApprovalCall {\n id: string;\n originMessageId?: string;\n permissions?: readonly string[];\n tool: ManifestTool | PrincipalTool;\n args: Record<string, unknown>;\n}\n\n/** Tool override, then operation override, then destructive-name default. */\nexport interface AssistantApprovalPolicy {\n /** Trusted host choice for in-app chat only. Never read from tool arguments. */\n allowRemovalsInChat?: boolean;\n tools?: Readonly<Record<string, boolean>>;\n operations?: Readonly<Record<string, boolean>>;\n}\n\nexport function requiresOwnerApproval(\n tool: ManifestTool | PrincipalTool,\n args: Record<string, unknown>,\n policy?: AssistantApprovalPolicy,\n destructiveHint = false,\n): boolean {\n const operation =\n 'action' in tool ? tool.action : (tool.slug.split('.').at(-1) ?? '');\n const destructive = (value: string) =>\n /(?:^|[._-])(delete|remove|destroy|purge|drop|truncate)(?:$|[._-])/i.test(\n value.replace(/([a-z])([A-Z])/g, '$1_$2'),\n );\n const values = [\n operation,\n tool.slug,\n String(args.operation ?? args.action ?? ''),\n ].map((value) => value.replace(/([a-z])([A-Z])/g, '$1_$2'));\n const purge = values.some((value) =>\n /(?:^|[._-])(purge|drop|truncate|destroy)(?:$|[._-])/i.test(value),\n );\n // Opt-in metadata is server-owned. Names and model arguments never classify\n // a tool as ordinary app data; extra/custom/security operations stay held.\n const identity =\n 'action' in tool ? (tool.qualifiedName ?? tool.className) : undefined;\n const declaration = identity ? ObjectRegistry.getClass(identity) : undefined;\n const controlModel =\n [\n identity,\n ...(declaration\n ? ObjectRegistry.getInheritanceChain(\n declaration.qualifiedName ?? declaration.name,\n )\n : []),\n ...(declaration?.replacedQualifiedNames ?? []),\n ].some(\n (name) =>\n name &&\n [\n '@happyvertical/smrt-users',\n '@happyvertical/smrt-profiles',\n '@happyvertical/smrt-tenancy',\n '@happyvertical/smrt-secrets',\n '@happyvertical/smrt-preferences',\n '@happyvertical/smrt-config',\n '@happyvertical/smrt-features',\n '@happyvertical/smrt-app-runtime',\n '@happyvertical/smrt-app-shell',\n '@happyvertical/smrt-inference',\n '@happyvertical/smrt-approvals',\n ].includes(name.split(':')[0]),\n ) ||\n (!!declaration &&\n ObjectRegistry.getConfig(declaration.qualifiedName ?? declaration.name)\n .sensitive === true);\n const recordDeletion =\n !controlModel &&\n 'action' in tool &&\n tool.action === 'delete' &&\n tool.annotations?.recordDeletion === true &&\n tool.annotations?.workProfile !== 'design' &&\n typeof args.id === 'string' &&\n args.id.trim().length > 0;\n if (purge) return true;\n // Native tools may own an independent hold (the existing explicit overrides).\n // The new chat setting itself can never waive a purge or an unknown effect.\n return (\n policy?.tools?.[tool.slug] ??\n policy?.operations?.[operation] ??\n (policy?.allowRemovalsInChat && recordDeletion\n ? false\n : destructiveHint ||\n destructive(operation) ||\n destructive(tool.slug) ||\n destructive(String(args.operation ?? args.action ?? '')))\n );\n}\n\nexport interface AssistantApprovalBridge {\n policy?: AssistantApprovalPolicy;\n request(call: AssistantApprovalCall): Promise<AssistantApprovalRequest>;\n wait?: AssistantApprovalWaiter;\n complete?: (\n request: AssistantApprovalRequest,\n ok: boolean,\n result: unknown,\n ) => Promise<void>;\n}\n\n/** Creates requests from server-supplied snapshots and canonical calls, never an engine's id/summary. */\nexport function createAssistantApprovalBridge(options: {\n authority: OwnerApprovalAuthority;\n tenantId: string;\n requestedBy: string;\n context: Record<string, unknown>;\n policy?: AssistantApprovalPolicy;\n summary?: (call: AssistantApprovalCall) => string;\n}): AssistantApprovalBridge {\n return {\n policy: options.policy,\n async request(call) {\n const record = await options.authority.request({\n tenantId: options.tenantId,\n requestedBy: options.requestedBy,\n tool: call.tool.slug,\n callId: call.id,\n args: call.args,\n summary:\n options.summary?.(call) ??\n `Allow ${call.tool.slug}${typeof call.args.id === 'string' ? ` for ${call.args.id.slice(0, 200)}` : ''}?`,\n context: {\n ...options.context,\n ...(call.permissions\n ? { permissionCeiling: [...call.permissions] }\n : {}),\n ...(call.originMessageId\n ? { originMessageId: call.originMessageId }\n : {}),\n },\n });\n return {\n id: record.id,\n tool: record.tool,\n callId: record.callId,\n summary: record.summary,\n };\n },\n async complete(request, ok, result) {\n await options.authority.complete(\n options.tenantId,\n request.id,\n ok,\n result,\n );\n },\n async wait(request, context) {\n const record = await options.authority.wait(\n options.tenantId,\n request.id,\n context.signal,\n );\n if (context.signal.aborted || record?.status !== 'approved')\n return { approved: false, reason: record?.status ?? 'cancelled' };\n await options.authority.consume(options.tenantId, request.id);\n return { approved: true };\n },\n };\n}\n\n/** Observe a host-executed durable hold without deciding, consuming or replaying it. */\nexport async function observeAssistantApproval(options: {\n authority: OwnerApprovalAuthority;\n tenantId: string;\n id: string;\n signal: AbortSignal;\n timeoutMs: number;\n}) {\n const timeout = new AbortController();\n const timer = setTimeout(() => timeout.abort(), options.timeoutMs);\n try {\n return await options.authority.wait(\n options.tenantId,\n options.id,\n AbortSignal.any([options.signal, timeout.signal]),\n { settled: true },\n );\n } finally {\n clearTimeout(timer);\n }\n}\n"],"mappings":";;AAwBO,SAAS,sBACd,MACA,MACA,QACA,kBAAkB,OACT;CACT,MAAM,YACJ,YAAY,OAAO,KAAK,SAAU,KAAK,KAAK,MAAM,GAAG,CAAA,CAAE,GAAG,EAAE,KAAK;CACnE,MAAM,eAAe,UACnB,qEAAqE,KACnE,MAAM,QAAQ,mBAAmB,OAAO,CAC1C;CAMF,MAAM,QALS;EACb;EACA,KAAK;EACL,OAAO,KAAK,aAAa,KAAK,UAAU,EAAE;CAC5C,CAAA,CAAE,KAAK,UAAU,MAAM,QAAQ,mBAAmB,OAAO,CAC3C,CAAA,CAAO,MAAM,UACzB,uDAAuD,KAAK,KAAK,CACnE;CAGA,MAAM,WACJ,YAAY,OAAQ,KAAK,iBAAiB,KAAK,YAAa,KAAA;CAC9D,MAAM,cAAc,WAAW,eAAe,SAAS,QAAQ,IAAI,KAAA;CA8BnE,MAAM,iBACJ,EA7BA;EACE;EACA,GAAI,cACA,eAAe,oBACb,YAAY,iBAAiB,YAAY,IAC3C,IACA,CAAC;EACL,GAAI,aAAa,0BAA0B,CAAC;CAC9C,CAAA,CAAE,MACC,SACC,QACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAC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QAAQ,UACR,QAAQ,IACR,IACA,MACF;EACF;EACA,MAAM,KAAK,SAAS,SAAS;GAC3B,MAAM,SAAS,MAAM,QAAQ,UAAU,KACrC,QAAQ,UACR,QAAQ,IACR,QAAQ,MACV;GACA,IAAI,QAAQ,OAAO,WAAW,QAAQ,WAAW,YAC/C,OAAO;IAAE,UAAU;IAAO,QAAQ,QAAQ,UAAU;GAAY;GAClE,MAAM,QAAQ,UAAU,QAAQ,QAAQ,UAAU,QAAQ,EAAE;GAC5D,OAAO,EAAE,UAAU,KAAK;EAC1B;CACF;AACF;AAGA,eAAsB,yBAAyB,SAM5C;CACD,MAAM,UAAU,IAAI,gBAAgB;CACpC,MAAM,QAAQ,iBAAiB,QAAQ,MAAM,GAAG,QAAQ,SAAS;CACjE,IAAI;EACF,OAAO,MAAM,QAAQ,UAAU,KAC7B,QAAQ,UACR,QAAQ,IACR,YAAY,IAAI,CAAC,QAAQ,QAAQ,QAAQ,MAAM,CAAC,GAChD,EAAE,SAAS,KAAK,CAClB;CACF,UAAE;EACA,aAAa,KAAK;CACpB;AACF"}
@@ -0,0 +1,73 @@
1
+ /** Host-supplied assistant loops. This module never imports an inference engine. */
2
+ import type { AIMessage } from '@happyvertical/ai';
3
+ import type { PrincipalBinding, PrincipalTool } from '@happyvertical/smrt-agents';
4
+ import type { ResolvedWorkProfile, WorkRunMetadata } from '@happyvertical/smrt-inference';
5
+ import { type AssistantTurnOptions, type AssistantTurnResult, type AssistantTurnState } from './assistant-turn.js';
6
+ import type { AssistantApprovalRequest, AssistantClientToolCall, AssistantClientToolResult, AssistantTurnEvent } from './assistant-turn-events.js';
7
+ import { type ManifestTool, type ToolLoopUsage } from './tool-loop.js';
8
+ import type { DescribeAssistantTool } from './tool-summary.js';
9
+ /** A decision from the host's owner-approval authority, never from model output. */
10
+ export interface AssistantApprovalDecision {
11
+ approved: boolean;
12
+ reason?: string;
13
+ }
14
+ /** The context a trusted external loop receives; messages are oldest first. */
15
+ export interface AssistantTurnDriverContext {
16
+ thread?: {
17
+ id: string;
18
+ roomId?: string;
19
+ agentSessionId: string;
20
+ };
21
+ originMessageId?: string;
22
+ history: readonly AIMessage[];
23
+ userMessage: string;
24
+ systemPrompt: string;
25
+ principal: PrincipalBinding;
26
+ /** When supplied, an execution/MCP adapter must preserve this permission ceiling. */
27
+ permissions?: readonly string[];
28
+ /** Only offered, allow-listed server tools. MCP execution must enforce this principal too. */
29
+ tools: readonly ManifestTool[];
30
+ extraTools: readonly PrincipalTool[];
31
+ workProfile?: ResolvedWorkProfile;
32
+ /** MUST run at the authenticated MCP boundary before any side effect. */
33
+ beforeToolExecution(tool: string): void;
34
+ signal: AbortSignal;
35
+ /** The same host-configured server-write policy used by the built-in loop. */
36
+ requiresApproval(tool: string, args: Record<string, unknown>): boolean;
37
+ }
38
+ /** C3 bridge: persist a request and wait for a durable owner decision. */
39
+ export type AssistantApprovalWaiter = (request: AssistantApprovalRequest, context: AssistantTurnDriverContext) => Promise<AssistantApprovalDecision>;
40
+ /** One external tool call. Names are canonical app tool slugs, not provider aliases. */
41
+ export type AssistantDriverToolCall = Pick<AssistantClientToolCall, 'id' | 'name' | 'args'>;
42
+ /** Engine callbacks; await tool callbacks so persistence finishes before continuing. */
43
+ export interface AssistantTurnDriverCallbacks {
44
+ text(delta: string): void;
45
+ toolCall(call: AssistantDriverToolCall): Promise<void>;
46
+ toolResult(result: AssistantClientToolResult): Promise<void>;
47
+ approvalNeeded(request: AssistantApprovalRequest): Promise<AssistantApprovalDecision>;
48
+ execution?(metadata: WorkRunMetadata): void;
49
+ done(result: {
50
+ text: string;
51
+ usage?: ToolLoopUsage;
52
+ workRun?: WorkRunMetadata;
53
+ }): void;
54
+ /** Detail is logged server-side; the wire and stored error are sanitized. */
55
+ error(error: unknown): void;
56
+ }
57
+ /** A trusted, host-supplied loop. Call done/error once and settle run; honor signal. */
58
+ export interface AssistantTurnDriver {
59
+ /** Trusted host-owned durable ledger observer; never decides or executes a hold. */
60
+ waitForApproval?: AssistantApprovalWaiter;
61
+ run(context: AssistantTurnDriverContext, callbacks: AssistantTurnDriverCallbacks): Promise<void>;
62
+ }
63
+ /** Persist the human handoff and the intercepted assist work before the durable job takes over. */
64
+ export declare function recordDesignHandoff<M>(options: AssistantTurnOptions<M>, accepted: {
65
+ runId: string;
66
+ message?: string;
67
+ }, emit: (event: AssistantTurnEvent<M>) => void, serialize: (message: unknown) => M, observed?: WorkRunMetadata): Promise<{
68
+ content: string;
69
+ message?: M;
70
+ }>;
71
+ /** Restart once with the same authority after a host-boundary design interception. */
72
+ export declare function runExternalAssistantTurn<M>(options: AssistantTurnOptions<M>, emit: (event: AssistantTurnEvent<M>) => void, serialize: (message: unknown) => M, describe: DescribeAssistantTool, report: (state: AssistantTurnState['state']) => Promise<boolean>): Promise<AssistantTurnResult>;
73
+ //# sourceMappingURL=assistant-turn-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant-turn-driver.d.ts","sourceRoot":"","sources":["../src/assistant-turn-driver.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EAChB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAGxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAEL,KAAK,YAAY,EAGjB,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAO/D,oFAAoF;AACpF,MAAM,WAAW,yBAAyB;IACxC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,CAAC,EAChC,IAAI,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5C,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,EAClC,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GAC/D,OAAO,CAAC,mBAAmB,CAAC,CA0F9B"}
@@ -84,7 +84,7 @@ export interface AssistantClientToolResult {
84
84
  error?: string;
85
85
  }
86
86
  /** Why a turn finished. */
87
- export type AssistantTurnStopReason = 'stop' | 'max_steps'
87
+ export type AssistantTurnStopReason = 'approval' | 'stop' | 'max_steps'
88
88
  /** The turn's token or time budget ran out (`maxTurnTokens`/`maxTurnMs`). */
89
89
  | 'budget'
90
90
  /**
@@ -98,6 +98,28 @@ export type AssistantTurnStopReason = 'stop' | 'max_steps'
98
98
  | 'timeout'
99
99
  /** A model call failed and the host's `providerErrorFallback` answered (#4454). */
100
100
  | 'provider_error';
101
+ /** A server-owned approval reference; authority and storage belong to the host. */
102
+ export interface AssistantApprovalRequest {
103
+ id: string;
104
+ tool: string;
105
+ callId: string;
106
+ summary: string;
107
+ /** Optional host-authored business preview, supplied by the authenticated presentation seam. */
108
+ presentation?: {
109
+ summary: string;
110
+ };
111
+ }
112
+ export interface AssistantApprovalView extends AssistantApprovalRequest {
113
+ status: import('@happyvertical/smrt-app-runtime').OwnerApprovalStatus;
114
+ decidedBy?: string | null;
115
+ decidedAt?: number | null;
116
+ }
117
+ /**
118
+ * Reconcile same-hold browser presentation when canonical reads overlap.
119
+ * This grants no execution authority; server verification remains mandatory.
120
+ * The first terminal view wins, and unrelated hold identities never merge.
121
+ */
122
+ export declare function reconcileAssistantApprovalView(current: AssistantApprovalView | undefined, next: AssistantApprovalView): AssistantApprovalView;
101
123
  /** One event of a streamed assistant turn. `M` is the host's message shape. */
102
124
  export type AssistantTurnEvent<M = Record<string, unknown>> = {
103
125
  type: 'status';
@@ -105,6 +127,9 @@ export type AssistantTurnEvent<M = Record<string, unknown>> = {
105
127
  } | {
106
128
  type: 'token';
107
129
  text: string;
130
+ } | {
131
+ type: 'approval_needed';
132
+ approval: AssistantApprovalRequest;
108
133
  } | {
109
134
  type: 'step';
110
135
  step: AssistantTurnStep;
@@ -117,6 +142,8 @@ export type AssistantTurnEvent<M = Record<string, unknown>> = {
117
142
  calls: AssistantClientToolCall[];
118
143
  } | {
119
144
  type: 'done';
145
+ /** Durable design run accepted by the authenticated host. */
146
+ runId?: string;
120
147
  message?: M;
121
148
  stoppedReason: AssistantTurnStopReason;
122
149
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-turn-events.d.ts","sourceRoot":"","sources":["../src/assistant-turn-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,oEAAoE;AACpE,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzE;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,oBAAoB,CAAC;IAC5B,qEAAqE;IACrE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAwB;AACxB,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExD,gFAAgF;AAChF,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;AAEnE,mCAAmC;AACnC,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IA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AAG,QAAQ,GAAG,gBAAgB,CAAC;CACvD,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,2CAA2C;AAC3C,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,kBAAkB,CAAC,OAAO,CAAC,GACjC,MAAM,CAER;AAED,gDAAgD;AAChD,MAAM,WAAW,0BAA0B,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrE,2EAA2E;IAC3E,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,iEAAiE;IACjE,eAAe,CAAC,EAAE,OAAO,CACvB,kBAAkB,CAAC,CAAC,CAAC,EACrB;QAAE,IAAI,EAAE,mBAAmB,CAAA;KAAE,CAC9B,CAAC;CACH;AAED,wFAAwF;AACxF,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAaD;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvE,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KAAK,IAAI,GAC/C,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAgExC;AAED,sEAAsE;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,2 +1,2 @@
1
- import { i as matchesToolAllowList, n as encodeAssistantTurnEvent, r as readAssistantTurnStream, t as AssistantTurnStreamError } from "./chunks/assistant-turn-events-BbZUf-Ju.js";
2
- export { AssistantTurnStreamError, encodeAssistantTurnEvent, matchesToolAllowList, readAssistantTurnStream };
1
+ import { a as matchesToolAllowList, i as reconcileAssistantApprovalView, n as encodeAssistantTurnEvent, r as readAssistantTurnStream, t as AssistantTurnStreamError } from "./chunks/assistant-turn-events-DwdCZzQ0.js";
2
+ export { AssistantTurnStreamError, encodeAssistantTurnEvent, matchesToolAllowList, readAssistantTurnStream, reconcileAssistantApprovalView };