@happyvertical/smrt-chat 0.51.39 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +19 -2
- package/README.md +13 -0
- package/dist/assistant-turn-events.d.ts +152 -0
- package/dist/assistant-turn-events.d.ts.map +1 -0
- package/dist/assistant-turn-events.js +2 -0
- package/dist/assistant-turn.d.ts +236 -0
- package/dist/assistant-turn.d.ts.map +1 -0
- package/dist/chunks/{ChatService-D48KBDZy.js → ChatService-jJi2JJJi.js} +2 -2
- package/dist/chunks/ChatService-jJi2JJJi.js.map +1 -0
- package/dist/chunks/assistant-turn-events-BbZUf-Ju.js +77 -0
- package/dist/chunks/assistant-turn-events-BbZUf-Ju.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +776 -104
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-runtime.js +1 -1
- package/dist/manifest.json +6 -2
- package/dist/models/AgentSession.d.ts +11 -1
- package/dist/models/AgentSession.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +7 -13
- package/dist/svelte/components/assistant/AssistantChoiceCards.svelte +309 -0
- package/dist/svelte/components/assistant/AssistantChoiceCards.svelte.d.ts +19 -0
- package/dist/svelte/components/assistant/AssistantChoiceCards.svelte.d.ts.map +1 -0
- package/dist/svelte/components/assistant/AssistantComposer.svelte +116 -14
- package/dist/svelte/components/assistant/AssistantComposer.svelte.d.ts +28 -0
- package/dist/svelte/components/assistant/AssistantComposer.svelte.d.ts.map +1 -1
- package/dist/svelte/components/assistant/AssistantDock.svelte +196 -1
- package/dist/svelte/components/assistant/AssistantDock.svelte.d.ts +38 -1
- package/dist/svelte/components/assistant/AssistantDock.svelte.d.ts.map +1 -1
- package/dist/svelte/components/assistant/AssistantThreadList.svelte +13 -1
- package/dist/svelte/components/assistant/__tests__/AssistantDock.test.js +16 -16
- package/dist/svelte/components/assistant/__tests__/assistant-composer-dictation.test.js +197 -0
- package/dist/svelte/components/assistant/__tests__/assistant-dock-choices-pending.test.js +224 -0
- package/dist/svelte/components/assistant/__tests__/assistant-dock-choices-preview.test.js +312 -0
- package/dist/svelte/components/assistant/__tests__/assistant-dock-choices.test.js +338 -0
- package/dist/svelte/components/assistant/__tests__/assistant-dock-client-tools.test.js +442 -0
- package/dist/svelte/components/assistant/__tests__/assistant-dock-run.test.js +303 -0
- package/dist/svelte/components/assistant/__tests__/assistant-dock-settle.test.js +146 -0
- package/dist/svelte/components/assistant/assistant-choices.svelte.d.ts +251 -0
- package/dist/svelte/components/assistant/assistant-choices.svelte.d.ts.map +1 -0
- package/dist/svelte/components/assistant/assistant-choices.svelte.js +520 -0
- package/dist/svelte/components/assistant/assistant-transport.d.ts +54 -1
- package/dist/svelte/components/assistant/assistant-transport.d.ts.map +1 -1
- package/dist/svelte/components/assistant/assistant-transport.js +64 -0
- package/dist/svelte/components/assistant/client-tools.d.ts +85 -0
- package/dist/svelte/components/assistant/client-tools.d.ts.map +1 -0
- package/dist/svelte/components/assistant/client-tools.js +61 -0
- package/dist/svelte/components/assistant/create-assistant-dock-controller.svelte.d.ts +159 -0
- package/dist/svelte/components/assistant/create-assistant-dock-controller.svelte.d.ts.map +1 -1
- package/dist/svelte/components/assistant/create-assistant-dock-controller.svelte.js +0 -0
- package/dist/svelte/i18n.d.ts +15 -0
- package/dist/svelte/i18n.d.ts.map +1 -1
- package/dist/svelte/i18n.js +17 -1
- package/dist/svelte/index.d.ts +6 -2
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +8 -1
- package/dist/tool-allow-list.d.ts +8 -0
- package/dist/tool-allow-list.d.ts.map +1 -0
- package/dist/tool-loop.d.ts +191 -3
- package/dist/tool-loop.d.ts.map +1 -1
- package/package.json +19 -15
- package/dist/chunks/ChatService-D48KBDZy.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -45,7 +45,7 @@ by the module-local `sendAgentReply` function.
|
|
|
45
45
|
- **ChatParticipant**: `role` (owner/admin/member/viewer), `onlineStatus`, `lastReadMessageId`, `isMuted`. Tenant-scoped (required).
|
|
46
46
|
- **ChatThread**: `rootMessageId`, `isResolved`, `messageCount`. Created via `ChatService.startThread()` (member-checked). Tenant-scoped (required).
|
|
47
47
|
- **ChatReaction**: `messageId`, `profileId`, `emoji`. Added/removed via `ChatService.addReaction()`/`removeReaction()` (member-checked, self-keyed). Tenant-scoped (required).
|
|
48
|
-
- **AgentSession**: `agentId` (application slug, string ref, not FK), `agentProfileId` (nullable `crossPackageRef` to `Profile` — the `bot` profile the agent AUTHORS as, #2995), `allowedTools` (JSON string array), `sessionContext` (JSON), `systemPrompt`, limits (`maxTokens`/`maxMessages`/`expiresAt`). Optional tenancy.
|
|
48
|
+
- **AgentSession**: `agentId` (application slug, string ref, not FK), `agentProfileId` (nullable `crossPackageRef` to `Profile` — the `bot` profile the agent AUTHORS as, #2995), `allowedTools` (JSON string array), `sessionContext` (JSON, sensitive), `systemPrompt`, limits (`maxTokens`/`maxMessages`/`expiresAt`). Optional tenancy.
|
|
49
49
|
- **VoiceSession**: short-lived voice-gateway binding over `(tenant, actorProfileId, personaId, room/thread/agentSession)` plus a persona snapshot, gateway `session_id`, expiry, replay tracking, and metadata. Tenant-scoped (required). Generated surface is read-only; creation and turns go through `createVoiceChatSession()` / `handleVoiceGatewayTurn()`.
|
|
50
50
|
|
|
51
51
|
## ChatService
|
|
@@ -102,7 +102,7 @@ bounded query results, and audit authority remain in the authenticated
|
|
|
102
102
|
The `AgentSession` runtime depends on personas, agents, and users. Keep those
|
|
103
103
|
edges acyclic: none of those packages may depend back on chat.
|
|
104
104
|
|
|
105
|
-
- **`runToolLoop(options)`** (`tool-loop.ts`) — a bounded `tool_call → observe → respond` loop. Tools are **manifest operations** of installed packages: `buildManifestToolCatalog({ allowedTools })` reads the `PermissionCatalogService` catalog and keeps only the `(collection, action)` entries named in the persona's allow-list (the **offer gate**; absent/empty ⇒ NO tools). The loop runs inside one `executeAsPrincipal` context, and `invokeManifestTool` executes each op **in-process ("side door")** against `run.context.database` (the RLS tx when Postgres RLS is on), after re-asserting the fail-closed allow-list (`run.assertToolAllowed`) AND the catalog permission (`run.assertOperation`) — the **execution gate**. Bounded by a max-steps ceiling (`DEFAULT_MAX_STEPS = 8`): on the ceiling it disables tools for one final completion so the turn always terminates with text.
|
|
105
|
+
- **`runToolLoop(options)`** (`tool-loop.ts`) — a bounded `tool_call → observe → respond` loop. Tools are **manifest operations** of installed packages: `buildManifestToolCatalog({ allowedTools })` reads the `PermissionCatalogService` catalog and keeps only the `(collection, action)` entries named in the persona's allow-list (the **offer gate**; absent/empty ⇒ NO tools). The loop runs inside one `executeAsPrincipal` context, and `invokeManifestTool` executes each op **in-process ("side door")** against `run.context.database` (the RLS tx when Postgres RLS is on), after re-asserting the fail-closed allow-list (`run.assertToolAllowed`) AND the catalog permission (`run.assertOperation`) — the **execution gate**. Bounded by a max-steps ceiling (`DEFAULT_MAX_STEPS = 8`): on the ceiling it disables tools for one final completion so the turn always terminates with text. A thrown tool error is classified (`classifyToolError`): permission denials and 401/403 are `not_permitted`; a `ValidationError` or 400/404/409/422 is `invalid_request` (observation: actionable message, `publicMessage` first, `code`, fix-and-retry hint); else (incl. 429) `execution_error`.
|
|
106
106
|
- **`runPersonaConversationTurn(options)`** (`persona-conversation.ts`) — binds a conversation to an `AgentPersona`/`ResolvedPersona`: runs as its principal (`runAsUserId`), offers only its `allowedTools`, speaks its instructions (`resolvePersonaInstructions`, layering approved learned directives), and injects its **recalled learning memory** (`personaLearningMemory`, isolated per `memoryScope`) into the system prompt. `bindPersonaToSession()` mirrors the persona's `allowedTools`/instructions onto the `AgentSession` so the chat authoring gate agrees with the loop's offer gate. Authors the reply (and each executed tool) via the internal `sendAgentReply` bridge. Tools run with the run-as user's **live** permissions unless the host passes a `permissions` snapshot (#2978), which `runToolLoop` forwards to `executeAsPrincipal` so a narrowed principal (e.g. a shared station) cannot reach grants — such as `readPermission`-gated data-surface fields — beyond that snapshot, including through `agents.invoke` delegation (the snapshot becomes the worker's permission ceiling).
|
|
107
107
|
- **Agent orchestration** (L3, #1892) — the loop accepts non-manifest **`extraTools`** (`PrincipalTool[]`, from `@happyvertical/smrt-agents`), gated by the *same* fail-closed allow-list. The standard **`invoke-agent`** tool (`createInvokeAgentTool`, slug `agents.invoke`) lets a conversational agent delegate to a **worker agent under its own principal** — the worker runs via `executeAsPrincipal` as the originating user (never its own authority), the principal is immutable along the chain, and its completion is surfaced back into the conversation. `runPersonaConversationTurn` filters `extraTools` by the persona's `allowedTools` (offer gate); the tool's `execute` re-asserts `assertToolAllowed` (execution gate). See `@happyvertical/smrt-agents` for the delegation envelope + transports.
|
|
108
108
|
- **Chat feedback capture** (`chat-feedback.ts`) — `captureChatFeedback()` + `acceptAppliedChange`/`rejectAppliedChange`/`correctResponse`/`rateResponse`/`thumbsUp`/`thumbsDown` write a `Feedback` row (personas) carrying the conversation's **correlation-id**, and (by default) reinforce the persona's learning memory (`reinforceFromFeedback`). So an in-chat reject decays a strategy below the reuse floor and it stops being recalled; a correction supersedes its stored value.
|
|
@@ -123,6 +123,23 @@ The gateway bearer token proves only "this request came from the gateway"; it ne
|
|
|
123
123
|
- **Persona path reuses the harness's own gates unchanged** — persona principal, fail-closed `allowedTools` offer+execution gates, tenant binding. `onToken` is best-effort telemetry threaded through `runToolLoop`; it never changes what the loop persists or authorizes.
|
|
124
124
|
- **Custom tools stream via `binding.extraTools`** — the persona binding threads an optional `extraTools?: PrincipalTool[]` down to `runPersonaConversationTurn`, so a *streamed* persona chat can offer non-manifest, service-backed tools (the persona messaging tool `messages.send`, or an assistance-request/lead-ticket tool wrapping a `@smrt({ api:false, mcp:false })` service) and thus *act*, not only answer — matching the non-streaming persona path. It is resolved server-side by `authorize` (trusted), never from request input, and stays fully gated: each tool is filtered by the persona's `allowedTools` (offer gate) and re-asserts the bound principal's authority in `execute` (execution gate). Offering a tool is not authorizing it.
|
|
125
125
|
|
|
126
|
+
## Streamed assistant turns with browser tools (#2908)
|
|
127
|
+
|
|
128
|
+
`runAssistantTurn()` (`assistant-turn.ts`) is the host-route engine for the
|
|
129
|
+
AssistantDock: one turn over `runToolLoop` with server tools (offer-gated by
|
|
130
|
+
`principal.allowedTools`), browser tools (validated by
|
|
131
|
+
`sanitizeClientToolDeclarations` + a server allow-list), `maxSteps`, `signal`,
|
|
132
|
+
and `onUsage`. A browser tool call SUSPENDS the turn (`stoppedReason:
|
|
133
|
+
'client_tools'`); the transcript waits in an `AssistantContinuationStore`
|
|
134
|
+
(single-use, 15-minute TTL; `createSessionContinuationStore` keeps it in the
|
|
135
|
+
AgentSession's `sessionContext`) and the browser resumes it with results,
|
|
136
|
+
which reach the model wrapped `untrusted`. `createAssistantTurnResponse`
|
|
137
|
+
serves the events as SSE; `assistant-turn-events.ts` is the browser-safe wire
|
|
138
|
+
contract (`./assistant-turn` subpath, also a vite library entry because the
|
|
139
|
+
Svelte dock imports it). The dock decides whether a browser call runs or waits
|
|
140
|
+
for the user from the page registry, never the server's echo; destructive
|
|
141
|
+
always waits. Details: [`docs/assistant-dock.md`](../../docs/assistant-dock.md).
|
|
142
|
+
|
|
126
143
|
## AssistantDock (#2904)
|
|
127
144
|
|
|
128
145
|
`AssistantDock` (`svelte/components/assistant/`, exported from `./svelte`) is a
|
package/README.md
CHANGED
|
@@ -247,6 +247,19 @@ const dmRoom = await chat.getOrCreateDM({
|
|
|
247
247
|
});
|
|
248
248
|
```
|
|
249
249
|
|
|
250
|
+
### Assistant dock and supervised runs
|
|
251
|
+
|
|
252
|
+
`AssistantDock` / `createAssistantDockController` (`@happyvertical/smrt-chat/svelte`)
|
|
253
|
+
is an in-page assistant over a host transport; `runAssistantTurn` is its
|
|
254
|
+
server engine (model tools, browser tools that suspend and resume, budgets
|
|
255
|
+
`maxSteps` / `maxTurnTokens` / `maxTurnMs`). For "watch it work" hosts the
|
|
256
|
+
controller keeps a supervised `run` (goal, current step, `running | paused |
|
|
257
|
+
waiting | done | failed | cancelled`), with `pauseRun` / `continueRun`,
|
|
258
|
+
`holdForUser` for choices the person makes, a `clientToolFilter`, and a
|
|
259
|
+
`settle` hook so the step after a navigation sees the new page's tools.
|
|
260
|
+
`matchesToolAllowList` is exported browser-safe. Full guide:
|
|
261
|
+
[`docs/assistant-dock.md`](../../docs/assistant-dock.md).
|
|
262
|
+
|
|
250
263
|
## API
|
|
251
264
|
|
|
252
265
|
### Models
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assistant turn wire contract (#2908): the events one streamed assistant
|
|
3
|
+
* turn emits, the small generic status a host shell can show while it runs,
|
|
4
|
+
* and the browser-side SSE reader.
|
|
5
|
+
*
|
|
6
|
+
* BROWSER-SAFE and dependency-free, like `client.ts`: the server engine
|
|
7
|
+
* (`assistant-turn.ts`) imports the types from here, and the AssistantDock
|
|
8
|
+
* (`svelte/components/assistant/`) imports the reader. Exported under
|
|
9
|
+
* `@happyvertical/smrt-chat/assistant-turn`.
|
|
10
|
+
*
|
|
11
|
+
* Response: text/event-stream, one `data: <json>` line per event:
|
|
12
|
+
* { "type": "status", "status": AssistantStatus }
|
|
13
|
+
* { "type": "token", "text": "..." } (live preview only)
|
|
14
|
+
* { "type": "step", "step": AssistantTurnStep } ("calling X", "done")
|
|
15
|
+
* { "type": "message", "message": {...} } (a persisted message)
|
|
16
|
+
* { "type": "client_tool_calls", "continuationId": "...", "calls": [...] }
|
|
17
|
+
* { "type": "done", "message": {...}?, "stoppedReason": "..." }
|
|
18
|
+
* { "type": "error", "error": "...", "code": "..." }
|
|
19
|
+
* plus `: heartbeat` comment lines, which readers ignore.
|
|
20
|
+
*
|
|
21
|
+
* A turn ends with exactly one of `done`, `error`, or `client_tool_calls`.
|
|
22
|
+
* `client_tool_calls` suspends the turn: the browser runs the calls and
|
|
23
|
+
* resumes it with their results under `continuationId`.
|
|
24
|
+
*/
|
|
25
|
+
/** The coarse state a host shows ("working strip", status line). */
|
|
26
|
+
export type AssistantStatusState = 'idle' | 'working' | 'done' | 'error';
|
|
27
|
+
/**
|
|
28
|
+
* The generic assistant status: one plain-language line plus a state.
|
|
29
|
+
* Emitted by the server engine as `status` events and derived by the dock
|
|
30
|
+
* controller (`controller.status`, `onStatus`).
|
|
31
|
+
*/
|
|
32
|
+
export interface AssistantStatus {
|
|
33
|
+
state: AssistantStatusState;
|
|
34
|
+
/** Plain-language line ("Looking up articles…", "Done"), or null. */
|
|
35
|
+
label: string | null;
|
|
36
|
+
/** Changes the user applied during this piece of work (done state). */
|
|
37
|
+
changes?: number;
|
|
38
|
+
/** Whether the in-flight work can be stopped (`controller.cancel()`). */
|
|
39
|
+
cancellable?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Where a tool ran. */
|
|
42
|
+
export type AssistantToolLocation = 'server' | 'client';
|
|
43
|
+
/** A browser tool's declared effect (mirrors smrt-web's `WebMcpToolEffect`). */
|
|
44
|
+
export type AssistantToolEffect = 'read' | 'write' | 'destructive';
|
|
45
|
+
/** One progress step of a turn. */
|
|
46
|
+
export type AssistantTurnStep = {
|
|
47
|
+
kind: 'thinking';
|
|
48
|
+
step: number;
|
|
49
|
+
} | {
|
|
50
|
+
kind: 'tool_call';
|
|
51
|
+
callId: string;
|
|
52
|
+
tool: string;
|
|
53
|
+
label: string;
|
|
54
|
+
location: AssistantToolLocation;
|
|
55
|
+
} | {
|
|
56
|
+
kind: 'tool_result';
|
|
57
|
+
callId: string;
|
|
58
|
+
tool: string;
|
|
59
|
+
label: string;
|
|
60
|
+
ok: boolean;
|
|
61
|
+
error?: string;
|
|
62
|
+
};
|
|
63
|
+
/** A browser tool call the server suspended on. */
|
|
64
|
+
export interface AssistantClientToolCall {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
args: Record<string, unknown>;
|
|
68
|
+
/** The effect the page declared; the dock re-reads it from its registry. */
|
|
69
|
+
effect: AssistantToolEffect;
|
|
70
|
+
}
|
|
71
|
+
/** A browser tool declaration sent with a turn (untrusted on the server). */
|
|
72
|
+
export interface AssistantClientToolDeclaration {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
inputSchema: Record<string, unknown>;
|
|
76
|
+
effect: AssistantToolEffect;
|
|
77
|
+
}
|
|
78
|
+
/** The browser's answer to one {@link AssistantClientToolCall}. */
|
|
79
|
+
export interface AssistantClientToolResult {
|
|
80
|
+
id: string;
|
|
81
|
+
ok: boolean;
|
|
82
|
+
result?: string;
|
|
83
|
+
/** `declined` when the user said no; otherwise a short reason. */
|
|
84
|
+
error?: string;
|
|
85
|
+
}
|
|
86
|
+
/** Why a turn finished. */
|
|
87
|
+
export type AssistantTurnStopReason = 'stop' | 'max_steps'
|
|
88
|
+
/** The turn's token or time budget ran out (`maxTurnTokens`/`maxTurnMs`). */
|
|
89
|
+
| 'budget' | 'no_tools' | 'cancelled';
|
|
90
|
+
/** One event of a streamed assistant turn. `M` is the host's message shape. */
|
|
91
|
+
export type AssistantTurnEvent<M = Record<string, unknown>> = {
|
|
92
|
+
type: 'status';
|
|
93
|
+
status: AssistantStatus;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'token';
|
|
96
|
+
text: string;
|
|
97
|
+
} | {
|
|
98
|
+
type: 'step';
|
|
99
|
+
step: AssistantTurnStep;
|
|
100
|
+
} | {
|
|
101
|
+
type: 'message';
|
|
102
|
+
message: M;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'client_tool_calls';
|
|
105
|
+
continuationId: string;
|
|
106
|
+
calls: AssistantClientToolCall[];
|
|
107
|
+
} | {
|
|
108
|
+
type: 'done';
|
|
109
|
+
message?: M;
|
|
110
|
+
stoppedReason: AssistantTurnStopReason;
|
|
111
|
+
} | {
|
|
112
|
+
type: 'error';
|
|
113
|
+
/**
|
|
114
|
+
* A message safe to show the user: either a deliberate user-facing
|
|
115
|
+
* message or a generic one. Server detail is logged, never sent.
|
|
116
|
+
*/
|
|
117
|
+
error: string;
|
|
118
|
+
/** A stable machine code (`internal_error` for an unexpected failure). */
|
|
119
|
+
code?: string;
|
|
120
|
+
};
|
|
121
|
+
/** Serialize one event as an SSE frame. */
|
|
122
|
+
export declare function encodeAssistantTurnEvent(event: AssistantTurnEvent<unknown>): string;
|
|
123
|
+
/** The outcome of reading one streamed turn. */
|
|
124
|
+
export interface AssistantTurnStreamOutcome<M = Record<string, unknown>> {
|
|
125
|
+
/** Every persisted message the turn reported (tool results, the reply). */
|
|
126
|
+
messages: M[];
|
|
127
|
+
/** The terminal `done` event, when the turn finished. */
|
|
128
|
+
done?: Extract<AssistantTurnEvent<M>, {
|
|
129
|
+
type: 'done';
|
|
130
|
+
}>;
|
|
131
|
+
/** The suspension, when the turn is waiting on browser tools. */
|
|
132
|
+
clientToolCalls?: Extract<AssistantTurnEvent<M>, {
|
|
133
|
+
type: 'client_tool_calls';
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
/** Thrown by {@link readAssistantTurnStream} for an in-band `error` or a cut stream. */
|
|
137
|
+
export declare class AssistantTurnStreamError extends Error {
|
|
138
|
+
constructor(message: string);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Read a streamed assistant turn from a `text/event-stream` response,
|
|
142
|
+
* reporting each event to `onEvent` as it arrives.
|
|
143
|
+
*
|
|
144
|
+
* Resolves once a terminal event (`done` or `client_tool_calls`) arrives;
|
|
145
|
+
* rejects with {@link AssistantTurnStreamError} on an in-band `error` or when
|
|
146
|
+
* the stream closes without a terminal event (an intermediary cut it).
|
|
147
|
+
* Tolerates heartbeat comments and frames split across chunks.
|
|
148
|
+
*/
|
|
149
|
+
export declare function readAssistantTurnStream<M = Record<string, unknown>>(response: Response, onEvent?: (event: AssistantTurnEvent<M>) => void): Promise<AssistantTurnStreamOutcome<M>>;
|
|
150
|
+
/** Tool allow-list matching (browser-safe), re-exported for hosts. */
|
|
151
|
+
export { matchesToolAllowList } from './tool-allow-list.js';
|
|
152
|
+
//# sourceMappingURL=assistant-turn-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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C;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"}
|
|
@@ -0,0 +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 };
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamed assistant turn over the bounded tool loop (#2908).
|
|
3
|
+
*
|
|
4
|
+
* One call runs one assistant turn — model ↔ tools, up to `maxSteps` rounds —
|
|
5
|
+
* and yields {@link AssistantTurnEvent}s as it goes: a generic `status` line,
|
|
6
|
+
* `step`s ("calling X", "X done"), live `token` previews, each persisted
|
|
7
|
+
* `message`, and one terminal event. It is the engine behind an assistant
|
|
8
|
+
* dock's send route; the host owns authentication, tenancy, and persistence
|
|
9
|
+
* of the user message, and hands this module an already-authorized principal.
|
|
10
|
+
*
|
|
11
|
+
* Tools come from three places, all fail-closed:
|
|
12
|
+
*
|
|
13
|
+
* - **manifest tools** (`tools`) and **server tools** (`extraTools`, e.g.
|
|
14
|
+
* `createDataSurfaceTools()`), run in-process by {@link runToolLoop} under
|
|
15
|
+
* the principal. `extraTools` is narrowed to `principal.allowedTools` here
|
|
16
|
+
* (the offer gate) and each tool re-asserts it (the execution gate).
|
|
17
|
+
* - **browser tools** (`clientTools`): the page's WebMCP tools and view
|
|
18
|
+
* intents, declared by the browser. Validate and allow-list them with
|
|
19
|
+
* {@link sanitizeClientToolDeclarations} first. The server never runs them:
|
|
20
|
+
* when the model calls one, the turn SUSPENDS — the transcript is saved in
|
|
21
|
+
* the host's {@link AssistantContinuationStore} and a `client_tool_calls`
|
|
22
|
+
* event ends the stream. The browser runs the calls through its own
|
|
23
|
+
* registry (reads run; writes and destructive calls wait for the user's
|
|
24
|
+
* confirmation) and resumes the turn with `resume`. Results are fed back to
|
|
25
|
+
* the model marked untrusted.
|
|
26
|
+
*
|
|
27
|
+
* Suspension instead of an open connection keeps a turn independent of which
|
|
28
|
+
* server replica receives the resume, and the `maxSteps` bound spans every
|
|
29
|
+
* leg of the turn.
|
|
30
|
+
*
|
|
31
|
+
* @module
|
|
32
|
+
*/
|
|
33
|
+
import type { AIInterface, AIMessage, ChatOptions } from '@happyvertical/ai';
|
|
34
|
+
import type { PrincipalAuditSink, PrincipalBinding, PrincipalTool } from '@happyvertical/smrt-agents';
|
|
35
|
+
import type { SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
36
|
+
import type { AssistantTurnEvent, AssistantTurnStopReason } from './assistant-turn-events.js';
|
|
37
|
+
import type { AgentReplyService } from './services/ChatService.js';
|
|
38
|
+
import { type ClientToolDefinition, type ClientToolResultInput, type ManifestTool, type PendingClientToolCall, type ToolInvocation, type ToolLoopResult, type ToolLoopUsage } from './tool-loop.js';
|
|
39
|
+
/** How long a suspended turn waits for the browser's results. */
|
|
40
|
+
export declare const DEFAULT_CONTINUATION_TTL_MS: number;
|
|
41
|
+
/**
|
|
42
|
+
* A suspended turn: everything needed to resume it once the browser answers
|
|
43
|
+
* its tool calls. Serializable JSON, so a host can keep it anywhere.
|
|
44
|
+
*/
|
|
45
|
+
export interface AssistantTurnContinuation {
|
|
46
|
+
version: 1;
|
|
47
|
+
id: string;
|
|
48
|
+
/** `Date.now()` when it was saved. */
|
|
49
|
+
createdAt: number;
|
|
50
|
+
/** Tool rounds already used; the resumed leg continues the count. */
|
|
51
|
+
steps: number;
|
|
52
|
+
/** The loop transcript up to the suspension. */
|
|
53
|
+
messages: AIMessage[];
|
|
54
|
+
/** The browser calls the turn is waiting on. */
|
|
55
|
+
pending: PendingClientToolCall[];
|
|
56
|
+
/** The browser tools offered when it suspended. */
|
|
57
|
+
clientTools: ClientToolDefinition[];
|
|
58
|
+
/** Tokens the turn used so far (for `maxTurnTokens`). Absent: 0. */
|
|
59
|
+
tokens?: number;
|
|
60
|
+
/** `Date.now()` when the turn started (for `maxTurnMs`). Absent: `createdAt`. */
|
|
61
|
+
startedAt?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Where suspended turns wait. `take` is single-use: it returns the
|
|
65
|
+
* continuation once and removes it, so a result can never be replayed into a
|
|
66
|
+
* turn twice. `key` scopes continuations (e.g. to one thread) — a resume
|
|
67
|
+
* under another key never finds them.
|
|
68
|
+
*/
|
|
69
|
+
export interface AssistantContinuationStore {
|
|
70
|
+
save(key: string, continuation: AssistantTurnContinuation): Promise<void>;
|
|
71
|
+
take(key: string, id: string): Promise<AssistantTurnContinuation | null>;
|
|
72
|
+
}
|
|
73
|
+
/** In-memory store, for tests and single-process demos. */
|
|
74
|
+
export declare function createMemoryContinuationStore(options?: {
|
|
75
|
+
ttlMs?: number;
|
|
76
|
+
now?: () => number;
|
|
77
|
+
}): AssistantContinuationStore;
|
|
78
|
+
/** The slice of `AgentSession` {@link createSessionContinuationStore} uses. */
|
|
79
|
+
export interface ContinuationSessionLike {
|
|
80
|
+
getSessionContext(): Record<string, unknown>;
|
|
81
|
+
updateSessionContext(updates: Record<string, unknown>): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/** Reserved `AgentSession.sessionContext` field holding suspended turns. */
|
|
84
|
+
export declare const SESSION_CONTINUATIONS_FIELD = "__assistantContinuations";
|
|
85
|
+
/**
|
|
86
|
+
* A store kept in an `AgentSession`'s `sessionContext` (reserved field
|
|
87
|
+
* {@link SESSION_CONTINUATIONS_FIELD}), keyed by `key` — typically the thread
|
|
88
|
+
* id. Needs no schema: the session is already tenant-bound and
|
|
89
|
+
* participant-checked by the host that loaded it. Expired entries are pruned
|
|
90
|
+
* on every write.
|
|
91
|
+
*
|
|
92
|
+
* Pass a LOADER rather than a session instance whenever the turn also writes
|
|
93
|
+
* chat messages: authoring a reply updates the session row, so an instance
|
|
94
|
+
* loaded at the start of the request is stale by the time the turn suspends,
|
|
95
|
+
* and saving it fails its revision check. The loader is called before every
|
|
96
|
+
* read-modify-write so each one starts from the current row.
|
|
97
|
+
*/
|
|
98
|
+
export declare function createSessionContinuationStore(session: ContinuationSessionLike | (() => Promise<ContinuationSessionLike | null | undefined>), options?: {
|
|
99
|
+
ttlMs?: number;
|
|
100
|
+
now?: () => number;
|
|
101
|
+
}): AssistantContinuationStore;
|
|
102
|
+
/** A tool invocation the host wants persisted into the conversation. */
|
|
103
|
+
export interface AuthoredToolReply {
|
|
104
|
+
content: string;
|
|
105
|
+
messageType?: 'tool_call' | 'tool_result' | 'text';
|
|
106
|
+
toolCallData?: Record<string, unknown> | null;
|
|
107
|
+
}
|
|
108
|
+
/** Where and how a turn persists its messages (the trusted agent bridge). */
|
|
109
|
+
export interface AssistantTurnAuthor {
|
|
110
|
+
chatService: AgentReplyService;
|
|
111
|
+
agentSessionId: string;
|
|
112
|
+
tenantId: string;
|
|
113
|
+
threadId?: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Maps a server tool invocation to a persisted message, or `null` to keep
|
|
116
|
+
* it out of the conversation (the default for every invocation). The
|
|
117
|
+
* message's `toolCallData` tool name must be on the session's
|
|
118
|
+
* `allowedTools` — `sendAgentReply`'s gate is unchanged.
|
|
119
|
+
*/
|
|
120
|
+
authorInvocation?: (invocation: ToolInvocation) => AuthoredToolReply | null;
|
|
121
|
+
}
|
|
122
|
+
/** Options for {@link runAssistantTurn}. */
|
|
123
|
+
export interface AssistantTurnOptions<M = Record<string, unknown>> {
|
|
124
|
+
ai: AIInterface;
|
|
125
|
+
/** The already-authorized principal every server tool runs as. */
|
|
126
|
+
principal: PrincipalBinding;
|
|
127
|
+
db?: SmrtClassOptions['db'];
|
|
128
|
+
systemPrompt?: string;
|
|
129
|
+
/** Earlier turns, oldest first. Ignored on resume. */
|
|
130
|
+
history?: AIMessage[];
|
|
131
|
+
/** This turn's user message. Exactly one of `userMessage` / `resume`. */
|
|
132
|
+
userMessage?: string;
|
|
133
|
+
/** Resume a suspended turn with the browser's results. */
|
|
134
|
+
resume?: {
|
|
135
|
+
continuationId: string;
|
|
136
|
+
results: ClientToolResultInput[];
|
|
137
|
+
};
|
|
138
|
+
tools?: ManifestTool[];
|
|
139
|
+
/** Server tools, narrowed to `principal.allowedTools`. */
|
|
140
|
+
extraTools?: PrincipalTool[];
|
|
141
|
+
/** Validated, allow-listed browser tools (see `sanitizeClientToolDeclarations`). */
|
|
142
|
+
clientTools?: ClientToolDefinition[];
|
|
143
|
+
/** Required when `clientTools` are offered or `resume` is used. */
|
|
144
|
+
continuations?: AssistantContinuationStore;
|
|
145
|
+
/** Scope for `continuations` (e.g. the thread id). */
|
|
146
|
+
continuationKey?: string;
|
|
147
|
+
maxSteps?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Token budget for the whole turn, across every browser round trip. Once
|
|
150
|
+
* spent, the model gets one last round without tools to answer, and the
|
|
151
|
+
* turn ends with `stoppedReason: 'budget'`. Unset: no budget.
|
|
152
|
+
*/
|
|
153
|
+
maxTurnTokens?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Wall-clock budget for the whole turn (ms from its first leg, including
|
|
156
|
+
* time spent waiting on the browser). Same ending as `maxTurnTokens`.
|
|
157
|
+
*/
|
|
158
|
+
maxTurnMs?: number;
|
|
159
|
+
model?: string;
|
|
160
|
+
temperature?: number;
|
|
161
|
+
maxTokens?: number;
|
|
162
|
+
toolChoice?: ChatOptions['toolChoice'];
|
|
163
|
+
/** Cancels the turn (e.g. the request's own abort signal). */
|
|
164
|
+
signal?: AbortSignal;
|
|
165
|
+
/** Per-round token usage, for the host's usage attribution. */
|
|
166
|
+
onUsage?: (usage: ToolLoopUsage) => void;
|
|
167
|
+
permissions?: string[];
|
|
168
|
+
audit?: PrincipalAuditSink;
|
|
169
|
+
postgresRls?: boolean;
|
|
170
|
+
onBehalfOfUserId?: string | null;
|
|
171
|
+
agentClass?: string;
|
|
172
|
+
/** Persist tool results and the reply. Without it nothing is persisted. */
|
|
173
|
+
author?: AssistantTurnAuthor;
|
|
174
|
+
/** Maps a persisted chat message to the wire. Default: its `toJSON()`. */
|
|
175
|
+
serializeMessage?: (message: unknown) => M;
|
|
176
|
+
/**
|
|
177
|
+
* A plain-language label for a tool, used in steps and the status line.
|
|
178
|
+
* On a tool call it also gets the call's arguments, so a label can name
|
|
179
|
+
* the target ("Opening Events"); keep it free of ids and raw values.
|
|
180
|
+
*/
|
|
181
|
+
describeTool?: (name: string, args?: Record<string, unknown>) => string;
|
|
182
|
+
/** Mint continuation ids (tests). Default `crypto.randomUUID()`. */
|
|
183
|
+
createId?: () => string;
|
|
184
|
+
/**
|
|
185
|
+
* Server-side log for an unexpected failure (default `console.error`). The
|
|
186
|
+
* browser only ever gets a generic message and code for these.
|
|
187
|
+
*/
|
|
188
|
+
onError?: AssistantTurnErrorLogger;
|
|
189
|
+
now?: () => number;
|
|
190
|
+
}
|
|
191
|
+
/** What {@link runAssistantTurn} returns when its generator completes. */
|
|
192
|
+
export interface AssistantTurnResult {
|
|
193
|
+
stoppedReason: AssistantTurnStopReason | 'client_tools' | 'error';
|
|
194
|
+
content: string;
|
|
195
|
+
loop?: ToolLoopResult;
|
|
196
|
+
}
|
|
197
|
+
/** What the browser is told when a turn fails unexpectedly. */
|
|
198
|
+
export declare const ASSISTANT_TURN_GENERIC_ERROR = "The assistant ran into a problem. Please try again.";
|
|
199
|
+
/**
|
|
200
|
+
* A failure whose message is deliberately written for the user (an expired
|
|
201
|
+
* step, an empty message). Only these reach the browser verbatim, with their
|
|
202
|
+
* `code`; every other error is replaced by {@link ASSISTANT_TURN_GENERIC_ERROR}
|
|
203
|
+
* and code `internal_error`, and its detail goes to the server-side log.
|
|
204
|
+
*/
|
|
205
|
+
export declare class AssistantTurnUserError extends Error {
|
|
206
|
+
readonly code: string;
|
|
207
|
+
constructor(message: string, code: string);
|
|
208
|
+
}
|
|
209
|
+
/** Server-side sink for an unexpected turn failure. */
|
|
210
|
+
export type AssistantTurnErrorLogger = (error: unknown) => void;
|
|
211
|
+
/**
|
|
212
|
+
* Run one streamed assistant turn. Never throws: a failure is reported as an
|
|
213
|
+
* in-band `error` event (a streaming response has already committed its
|
|
214
|
+
* status by then). The generator's return value summarizes the turn.
|
|
215
|
+
*/
|
|
216
|
+
export declare function runAssistantTurn<M = Record<string, unknown>>(options: AssistantTurnOptions<M>): AsyncGenerator<AssistantTurnEvent<M>, AssistantTurnResult>;
|
|
217
|
+
/** Default SSE keep-alive for {@link createAssistantTurnResponse}. */
|
|
218
|
+
export declare const DEFAULT_ASSISTANT_TURN_HEARTBEAT_MS = 15000;
|
|
219
|
+
/**
|
|
220
|
+
* Wrap a turn's events as a `text/event-stream` `Response`. Heartbeat
|
|
221
|
+
* comments keep idle intermediaries from cutting a quiet tool round; a
|
|
222
|
+
* client disconnect ends the generator (the turn still persists what it did).
|
|
223
|
+
*
|
|
224
|
+
* The body is pulled by the runtime after the handler returns, outside the
|
|
225
|
+
* handler's async context. Every `next()` therefore runs in the async context
|
|
226
|
+
* captured here (`AsyncLocalStorage.snapshot()`), so a turn started inside
|
|
227
|
+
* `withTenant(...)` keeps its tenant scope for every step, including the
|
|
228
|
+
* reply it persists at the end.
|
|
229
|
+
*/
|
|
230
|
+
export declare function createAssistantTurnResponse(events: AsyncGenerator<AssistantTurnEvent<unknown>, unknown>, options?: {
|
|
231
|
+
heartbeatMs?: number;
|
|
232
|
+
headers?: Record<string, string>;
|
|
233
|
+
/** Server-side log for a failure while pulling (default `console.error`). */
|
|
234
|
+
onError?: AssistantTurnErrorLogger;
|
|
235
|
+
}): Response;
|
|
236
|
+
//# sourceMappingURL=assistant-turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant-turn.d.ts","sourceRoot":"","sources":["../src/assistant-turn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAEV,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2B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M,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,wBAAwB,CAAC;CAC/B,GACL,QAAQ,CAsDV"}
|
|
@@ -162,7 +162,7 @@ __decorateClass$6([crossPackageRef("@happyvertical/smrt-profiles:Profile", { req
|
|
|
162
162
|
__decorateClass$6([foreignKey("ChatRoom")], AgentSession.prototype, "chatRoomId", 2);
|
|
163
163
|
__decorateClass$6([field({ required: true })], AgentSession.prototype, "status", 2);
|
|
164
164
|
__decorateClass$6([field()], AgentSession.prototype, "allowedTools", 2);
|
|
165
|
-
__decorateClass$6([field()], AgentSession.prototype, "sessionContext", 2);
|
|
165
|
+
__decorateClass$6([field({ sensitive: true })], AgentSession.prototype, "sessionContext", 2);
|
|
166
166
|
__decorateClass$6([field()], AgentSession.prototype, "systemPrompt", 2);
|
|
167
167
|
__decorateClass$6([field()], AgentSession.prototype, "messageCount", 2);
|
|
168
168
|
__decorateClass$6([field()], AgentSession.prototype, "totalTokensUsed", 2);
|
|
@@ -2017,4 +2017,4 @@ function sendAgentReply(service, params) {
|
|
|
2017
2017
|
//#endregion
|
|
2018
2018
|
export { VoiceSession as a, ChatReaction as c, AgentSession as d, VoiceSessionCollection as i, ChatParticipant as l, ChatService_exports as n, ChatThread as o, sendAgentReply as r, ChatRoom as s, ChatService as t, ChatMessage as u };
|
|
2019
2019
|
|
|
2020
|
-
//# sourceMappingURL=ChatService-
|
|
2020
|
+
//# sourceMappingURL=ChatService-jJi2JJJi.js.map
|