@ouispec/agent-worker 0.14.0 → 0.15.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/README.md +82 -4
- package/dist/approvals/client.d.ts +14 -1
- package/dist/approvals/client.d.ts.map +1 -1
- package/dist/approvals/client.js +9 -0
- package/dist/approvals/client.js.map +1 -1
- package/dist/container/server.d.ts +14 -0
- package/dist/container/server.d.ts.map +1 -1
- package/dist/container/server.js +35 -16
- package/dist/container/server.js.map +1 -1
- package/dist/emit/tee.d.ts +18 -0
- package/dist/emit/tee.d.ts.map +1 -0
- package/dist/emit/tee.js +19 -0
- package/dist/emit/tee.js.map +1 -0
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/live-call/event-stream.d.ts +20 -0
- package/dist/live-call/event-stream.d.ts.map +1 -0
- package/dist/live-call/event-stream.js +43 -0
- package/dist/live-call/event-stream.js.map +1 -0
- package/dist/live-call/handler.d.ts +121 -0
- package/dist/live-call/handler.d.ts.map +1 -0
- package/dist/live-call/handler.js +338 -0
- package/dist/live-call/handler.js.map +1 -0
- package/dist/live-call/protocol.d.ts +131 -0
- package/dist/live-call/protocol.d.ts.map +1 -0
- package/dist/live-call/protocol.js +138 -0
- package/dist/live-call/protocol.js.map +1 -0
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +20 -5
- package/dist/orchestrator.js.map +1 -1
- package/dist/prompt/spoken-reply.d.ts +28 -0
- package/dist/prompt/spoken-reply.d.ts.map +1 -0
- package/dist/prompt/spoken-reply.js +37 -0
- package/dist/prompt/spoken-reply.js.map +1 -0
- package/dist/runtime/turn-runner.d.ts +28 -4
- package/dist/runtime/turn-runner.d.ts.map +1 -1
- package/dist/runtime/turn-runner.js +92 -35
- package/dist/runtime/turn-runner.js.map +1 -1
- package/dist/runtime/turn-slots.d.ts +30 -0
- package/dist/runtime/turn-slots.d.ts.map +1 -0
- package/dist/runtime/turn-slots.js +36 -0
- package/dist/runtime/turn-slots.js.map +1 -0
- package/dist/stop/turn-stop.d.ts +12 -1
- package/dist/stop/turn-stop.d.ts.map +1 -1
- package/dist/stop/turn-stop.js +47 -0
- package/dist/stop/turn-stop.js.map +1 -1
- package/dist/ui/snapshot.d.ts +6 -4
- package/dist/ui/snapshot.d.ts.map +1 -1
- package/dist/ui/snapshot.js +8 -6
- package/dist/ui/snapshot.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ouispec/agent-worker
|
|
2
2
|
|
|
3
|
-
The agent runtime. One core runs a turn: the model, the tool loop, UI actions answered by the user's own tab, streaming, retries and deadlines. Two host adapters run that core: Lambda + SQS, and a long-running container.
|
|
3
|
+
The agent runtime. One core runs a turn: the model, the tool loop, UI actions answered by the user's own tab, streaming, retries and deadlines. Two host adapters run that core: Lambda + SQS, and a long-running container. A third entry point, the live-call handler, lets a service that runs a voice call reach the same agent ("Live calls").
|
|
4
4
|
|
|
5
5
|
## What the host supplies
|
|
6
6
|
|
|
@@ -32,17 +32,18 @@ Policy hooks: `turnPolicy`, `toolPolicy`, `uiActions`, `approvals`, `stops`, `lo
|
|
|
32
32
|
|
|
33
33
|
## What a UI client sends with a turn
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
Four keys on the turn's `context` are for the worker itself, and your persona or `systemPrompt` callback never sees them:
|
|
36
36
|
|
|
37
37
|
| Key | What the tab puts there | What the worker does with it |
|
|
38
38
|
|---|---|---|
|
|
39
39
|
| `oui` | Its surface snapshot: `ouiRuntime.snapshot()` | Builds the turn's UI tools from it, and from nothing else |
|
|
40
40
|
| `uiKnowledge` | Its generated knowledge for the page the user is on: `resolveKnowledge(generatedKnowledge, path)` from `@ouispec/bindings` | Renders it after your prompt: each entry under "Platform Knowledge", then each recipe under "Active Workflows" |
|
|
41
|
-
| `input` | How the person entered the message, when they did not type it: `{ mode: 'voice', language }` for one they spoke, with the language the recogniser detected. `@ouispec/agent-react` sets it from `sendMessage(text, { input })` | Adds one line
|
|
41
|
+
| `input` | How the person entered the message, when they did not type it: `{ mode: 'voice', language }` for one they spoke, with the language the recogniser detected. `@ouispec/agent-react` sets it from `sendMessage(text, { input })` | Adds one line after the conversation: the message was spoken and machine-transcribed, so it may contain recognition errors; the language; and to ask rather than guess when a likely mis-hearing makes the request ambiguous. An unknown mode is read as typed, and a language that is not a BCP 47 tag of at most 16 characters is left out (`readMessageInput` in `@ouispec/agent-core`). A typed message, and the turn an approval card's click starts, get nothing |
|
|
42
|
+
| `output` | How the reply reaches the person, when it is not shown as text: `{ mode: 'voice' }` when a voice reads it out. The live-call handler sets it from the call's request | Adds one line after the conversation: the reply will be heard, not read, so short plain sentences; no markdown, lists, headings, links, code or emoji; numbers, prices, dates and times written as they are said; anything the person should look at shown through the page's actions rather than read out; and a few words before a slow lookup. An unknown mode is read as a shown reply, which gets nothing (`readReplyOutput` in `@ouispec/agent-core`). It applies on every turn of a call, the turn that continues an approval included |
|
|
42
43
|
|
|
43
44
|
`timeZone` (the user's IANA zone, which `@ouispec/agent-react` sends with every turn) is read by the worker too: the date and time on the user's clock are added to the turn's user message.
|
|
44
45
|
|
|
45
|
-
What
|
|
46
|
+
What is true only for this turn (the clock, how the message was entered, how the reply is delivered) goes after the conversation, never in the system prompt or on a message. The system prompt, the tools and every message are the cached prefix, and stay byte for byte the same whatever the turn says, so a conversation's chat turns and call turns read the same prefix. Store `input` with the user's message if your chat shows how a message was entered (`AgentStoredMessage.input`); the history the worker reads needs no copy of it.
|
|
46
47
|
|
|
47
48
|
Every other key is the page's context, which a persona prompt shows as the current UI state. A malformed `oui` or `uiKnowledge` fails the turn, naming the bad field. The worker logs `UI surfaces for this turn` with the surface ids and the knowledge's entry and workflow counts.
|
|
48
49
|
|
|
@@ -64,6 +65,8 @@ What happens:
|
|
|
64
65
|
|
|
65
66
|
In a browser, the turn after the decision comes from `ApprovalCard` (`@ouispec/agent-react`). Your `sendMessage` callback receives `approval` beside an empty `content`. Pass it unchanged to the worker as the turn payload's `approval`: `{ approvalId, decision: 'approve', token }` or `{ approvalId, decision: 'decline' }`. A UI action declares its effect on its OUI surface (`effect: 'transaction'`, or `confirm: true` for a destructive one). The tab's OUI runtime runs it only on the grant from the user's own click, which `grantApproval` in the client config hands it.
|
|
66
67
|
|
|
68
|
+
On a call there is no card. The live-call handler sends the preview's `readback`, verbatim, after the turn's text, and the person answers in words. Their next utterance comes as an ordinary message, and your `resolveTurn` decides whether it approves: classify the words, then decide as the user on a conversation channel with the approval store client (`createHttpApprovalStoreClient(...).decide(approvalId, { userId, decision, channel: 'voice' })`). An `approve` answers with the token; return `approval: { approvalId, decision: 'approve', token }` on the turn's target, and the turn runs exactly the stored call, once. Anything else (a no, a correction, a new request) leaves the approval to expire, or decline it with `decision: 'decline'`. A UI action that needs approval still runs only on the grant from the tab's own card click: the tab's OUI runtime refuses one approved by voice, so on a call put irreversible acts in host or API tools, or let the page show the card.
|
|
69
|
+
|
|
67
70
|
Declare a host tool's approval needs on the tool itself: `effect`, `destructive`, `title`, `consequence`, and `argsSensitive: false` when its arguments may be logged. Without an approval store, such a call is refused and never runs. The runtime uses the realtime server's store unless you pass `approvals.store`.
|
|
68
71
|
|
|
69
72
|
## Stopping a turn
|
|
@@ -166,10 +169,85 @@ Your API sends turns to the worker's HTTP endpoints:
|
|
|
166
169
|
| Request | Responses |
|
|
167
170
|
|---|---|
|
|
168
171
|
| `POST /turns` with an `AgentTurnPayload` and `x-api-key` | `202` once accepted. `400` if the body is not a turn, `401` for a wrong key, `409` if that turn is already running, `503` at capacity (`maxConcurrentTurns`, default 8) or while shutting down. |
|
|
172
|
+
| `POST /live-call/turns` with a live-call turn and `Authorization: Bearer` | Only with `liveCall` configured (below, and "Live calls"). `200 text/event-stream`. |
|
|
169
173
|
| `GET /health` | The worker's status, running turns, capacity and model. |
|
|
170
174
|
|
|
171
175
|
`onTurnEnd` receives each turn's outcome.
|
|
172
176
|
|
|
177
|
+
`liveCall: { credential, resolveTurn, opening?, keepAliveMs?, path? }` serves the live-call route on the same server, runtime and slots: `maxConcurrentTurns` bounds both routes together, a turn id runs once whichever route it came by, and `close` waits for both. Its requests carry the call service's credential, never `workerApiKey`. `path` defaults to `/live-call/turns`.
|
|
178
|
+
|
|
179
|
+
## Live calls
|
|
180
|
+
|
|
181
|
+
A service that runs a voice call (it hears the person, transcribes them, and speaks the reply in a character's voice) can be answered by your own agent: its persona, tools, UI actions, approvals and records. Each turn of the call is one HTTP request to a route you mount, and the reply streams back as server-sent events. The turn runs on the same runtime as every other turn, so it still streams to the conversation's realtime room: every page joined to that conversation receives the reply and every UI action, as for a typed message, and the call page can show what the agent is talking about.
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { createAgentTurnRunner, createLiveCallTurnHandler, LIVE_CALL_OPENING_MESSAGE } from '@ouispec/agent-worker';
|
|
185
|
+
|
|
186
|
+
const runner = createAgentTurnRunner(runtimeConfig); // the same config as your other turns
|
|
187
|
+
const liveCall = createLiveCallTurnHandler({
|
|
188
|
+
runner,
|
|
189
|
+
credential: env.LIVE_CALL_CREDENTIAL, // or [current, next] while rotating
|
|
190
|
+
resolveTurn: async (request, { signal }) => {
|
|
191
|
+
const conversation = await findConversationByCallRef(request.clientRef);
|
|
192
|
+
if (!conversation) return null; // answered 404
|
|
193
|
+
await storeUserMessage(conversation.id, request.kind === 'opening' ? LIVE_CALL_OPENING_MESSAGE : request.text, request.input);
|
|
194
|
+
return {
|
|
195
|
+
conversationId: conversation.id,
|
|
196
|
+
userId: conversation.userId,
|
|
197
|
+
accountId: conversation.accountId,
|
|
198
|
+
socketRoom: `conversation:${conversation.id}`,
|
|
199
|
+
context: conversation.pageContext, // the call page's OUI snapshot and knowledge, as for a typed turn
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
opening: (request, target) => greetingTemplateFor(target.accountId), // optional; null lets the model greet
|
|
203
|
+
});
|
|
204
|
+
app.post('/agent/live-call/turns', liveCall); // any Node server: (req, res)
|
|
205
|
+
process.on('SIGTERM', () => liveCall.close()); // waits for running turns
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`createLiveCallTurnHandler(config)` returns a Node `(req, res)` handler with `running()` and `close()`. A body that Express's `json()` already parsed is taken as it is.
|
|
209
|
+
|
|
210
|
+
| Config | |
|
|
211
|
+
|---|---|
|
|
212
|
+
| `runner` | Required. `createAgentTurnRunner(...)`: the runtime that runs your other turns. |
|
|
213
|
+
| `credential` | Required. The bearer credential the call service sends, from your secret store; a list while one is rotated. Compared in constant time. |
|
|
214
|
+
| `resolveTurn(request, { signal })` | Required. The call's `clientRef` → the turn's `conversationId`, `userId`, `accountId` and `socketRoom`, with optional `context`, `userToken` and `approval`; null when you have no such conversation. Do here what your API does for a chat message: store the person's message (for an `opening`, `LIVE_CALL_OPENING_MESSAGE`), claim the turn, and decide on a waiting readback ("Approvals"). `signal` aborts if the caller hangs up meanwhile. |
|
|
215
|
+
| `opening(request, target, { signal })` | Optional. A greeting from your template for an `opening` turn: streamed, sent to the room and stored as the turn's one assistant message (`runner.reply`), with no model call. Null, undefined or blank lets the model greet. A throw fails the turn. |
|
|
216
|
+
| `keepAliveMs` | Default 5 s: a `: keep-alive` comment after this long with nothing written. |
|
|
217
|
+
| `maxConcurrentTurns` | Default 8; more are answered `503`. |
|
|
218
|
+
| `maxBodyBytes` | Default 64 KiB. |
|
|
219
|
+
| `onTurnEnd(outcome)` | Each turn's outcome, after it ends. |
|
|
220
|
+
|
|
221
|
+
**The request.** `POST`, `Content-Type: application/json`, `Authorization: Bearer <credential>`:
|
|
222
|
+
|
|
223
|
+
| Field | |
|
|
224
|
+
|---|---|
|
|
225
|
+
| `sessionId` | The call service's session. |
|
|
226
|
+
| `clientRef` | Your conversation reference, given to the call service when the call was created. |
|
|
227
|
+
| `turnId` | Unique per turn; the turn runs under it. |
|
|
228
|
+
| `kind` | `message`: the person said `text`. `opening`: the call has just connected, `text` is empty, and the agent greets: the model reads `LIVE_CALL_OPENING_MESSAGE` where the person's words would be. |
|
|
229
|
+
| `text` | What the person said, as transcribed; at most 8,000 characters. |
|
|
230
|
+
| `input` | `{ mode: 'voice', language? }` for what the person said: set as the turn's `context.input`, so the model is told it was transcribed. `{ mode: 'text' }` for a message they typed during the call: read as typed, with no `context.input`. Dropped on an `opening`. |
|
|
231
|
+
| `output` | `{ mode: 'voice' }`: set as the turn's `context.output`, so the model writes for the ear ("What a UI client sends with a turn"). |
|
|
232
|
+
| `supersedes` | Turns this one replaces. Each still running in this process is stopped at once, and the turn's `getHistory` is given them to wait for, as for any superseding message. |
|
|
233
|
+
|
|
234
|
+
`readLiveCallTurnRequest` reads a body as the handler does, and `LIVE_CALL_LIMITS` holds its limits.
|
|
235
|
+
|
|
236
|
+
**The response.** `200 text/event-stream`, flushed event by event:
|
|
237
|
+
|
|
238
|
+
| Event | Data | |
|
|
239
|
+
|---|---|---|
|
|
240
|
+
| `text` | `{ text }` | The reply as the model writes it; concatenate the pieces. Rounds the model writes between tool calls are separated by a blank line, as in the room. |
|
|
241
|
+
| `readback` | `{ approvalId, text, expiresAt }` | The turn stopped at a call that needs approval. `text` is the preview's `readback`, verbatim, built from the action's declaration; `expiresAt` is ISO 8601. Sent once the turn has ended by itself, after all of its text. A turn that was stopped withdrew its approval, and sends none. |
|
|
242
|
+
| `done` | `{ stopReason? }` | The turn is over: `complete`, `awaiting_approval`, `present_options`, `time_limit`, `output_limit` or `step_count` when it ended by itself; `user_stop`, `superseded` or `deadline` when it was stopped. |
|
|
243
|
+
| `error` | `{ code, message }` | The turn failed: `RATE_LIMIT`, `SERVICE_UNAVAILABLE`, `MODEL_TIMEOUT`, `TURN_TIMEOUT`, `TURN_DEADLINE_EXCEEDED`, `TURN_REFUSED` or `WORKER_ERROR`. `message` is a fixed line for the code; the cause stays in your logs. |
|
|
244
|
+
|
|
245
|
+
The stream is written from the turn's own events as the room receives them (`TurnHost.observe`): the same text, from the same model call. Before the stream opens, a refusal is a status and `{ error: { code, message } }`: `400 INVALID_REQUEST` naming the field, `401 UNAUTHORIZED`, `404 UNKNOWN_CLIENT_REF`, `405`, `409 TURN_RUNNING`, `413 BODY_TOO_LARGE`, `415`, `500 RESOLVE_FAILED` (your `resolveTurn` threw, or returned a target that is not a turn; nothing ran) and `503 UNAVAILABLE`.
|
|
246
|
+
|
|
247
|
+
**Barge-in.** When the person speaks over the reply, the call service closes the connection. The turn is stopped as a superseding message stops it (`stopReason: 'superseded'`): what it had produced is stored with the mark and announced to the room, and the next request names it in `supersedes`. A stop asked for through the realtime server (the person's Stop on a page) is heard too, and that stream ends with `done`.
|
|
248
|
+
|
|
249
|
+
Keep the turn's deadline (`turnDeadlineMs`) and the model to a call's pace: a voice turn waits on its first `text` event, so run it on the container adapter, never behind a queue.
|
|
250
|
+
|
|
173
251
|
## Conversation history in the browser
|
|
174
252
|
|
|
175
253
|
`agent-sdk-react` restores a tab's conversation after a reload, and lists or switches conversations, when your API provides two endpoints behind `AgentClientConfig`. Both must be filtered by the signed-in user:
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* pending approval when it stops a turn, redeems the token the next turn
|
|
5
5
|
* carries, and reads a decline.
|
|
6
6
|
*/
|
|
7
|
-
import type { ApprovalOwner, ApprovalRedeemResult, ApprovalSettlement, ApprovalStatus, ApprovalWithdrawal, ApprovalWithdrawReason, PendingApprovalInput } from '@ouispec/agent-core';
|
|
7
|
+
import type { ApprovalChannel, ApprovalDecideResult, ApprovalDecision, ApprovalOwner, ApprovalRedeemResult, ApprovalSettlement, ApprovalStatus, ApprovalWithdrawal, ApprovalWithdrawReason, PendingApprovalInput } from '@ouispec/agent-core';
|
|
8
8
|
export interface ApprovalStoreClient {
|
|
9
9
|
/** Store a pending approval. Rejects when it was not stored: the call must then not wait on it. */
|
|
10
10
|
create(pending: PendingApprovalInput): Promise<void>;
|
|
@@ -34,6 +34,19 @@ export interface ApprovalStoreClient {
|
|
|
34
34
|
* cannot be reached.
|
|
35
35
|
*/
|
|
36
36
|
withdraw?(approvalId: string, owner: ApprovalOwner, reason: ApprovalWithdrawReason): Promise<ApprovalWithdrawal>;
|
|
37
|
+
/**
|
|
38
|
+
* A conversation channel's decision (voice, phone, SMS, chat): the host
|
|
39
|
+
* delivered the approval's readback, and decides as the user from their
|
|
40
|
+
* answer. An `approve` answers with the single-use token the next turn
|
|
41
|
+
* carries as `approval`. A UI approval is decided only by the user's click
|
|
42
|
+
* on their own socket, and the store refuses `ui` here. Optional; rejects
|
|
43
|
+
* when the store cannot be reached.
|
|
44
|
+
*/
|
|
45
|
+
decide?(approvalId: string, by: {
|
|
46
|
+
userId: string;
|
|
47
|
+
decision: ApprovalDecision;
|
|
48
|
+
channel: Exclude<ApprovalChannel, 'ui'>;
|
|
49
|
+
}): Promise<ApprovalDecideResult>;
|
|
37
50
|
}
|
|
38
51
|
export interface HttpApprovalStoreClientConfig {
|
|
39
52
|
/** The realtime server's base URL. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/approvals/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EAEpB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EAEtB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,WAAW,mBAAmB;IAClC,mGAAmG;IACnG,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,uJAAuJ;IACvJ,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzG,2EAA2E;IAC3E,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAA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;;;OAGG;IACH,oBAAoB,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E;;;;;OAKG;IACH,QAAQ,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACjH;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,gBAAgB,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACzJ;AAED,MAAM,WAAW,6BAA6B;IAC5C,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,8DAA8D;AAC9D,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,6BAA6B,GAAG,mBAAmB,CAgFxG"}
|
package/dist/approvals/client.js
CHANGED
|
@@ -62,6 +62,15 @@ export function createHttpApprovalStoreClient(config) {
|
|
|
62
62
|
return { approvalId, outcome: 'unknown' };
|
|
63
63
|
throw new Error(`[agent-sdk] The approval store could not withdraw approval ${approvalId}: HTTP ${status}`);
|
|
64
64
|
},
|
|
65
|
+
async decide(approvalId, by) {
|
|
66
|
+
const { status, json } = await call(`/internal/approvals/${encodeURIComponent(approvalId)}/decide`, by);
|
|
67
|
+
if (status === 200 && json.ok === true)
|
|
68
|
+
return json;
|
|
69
|
+
if (status >= 400 && status < 500 && typeof json.reason === 'string') {
|
|
70
|
+
return { ok: false, reason: json.reason, error: String(json.error ?? json.reason) };
|
|
71
|
+
}
|
|
72
|
+
throw new Error(`[agent-sdk] The approval store could not decide approval ${approvalId}: HTTP ${status}`);
|
|
73
|
+
},
|
|
65
74
|
async status(approvalId, userId) {
|
|
66
75
|
const { status, json } = await call(`/internal/approvals/${encodeURIComponent(approvalId)}?${new URLSearchParams({ userId })}`);
|
|
67
76
|
if (status === 200)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/approvals/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/approvals/client.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAgD1D,8DAA8D;AAC9D,MAAM,UAAU,6BAA6B,CAAC,MAAqC;IACjF,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC/B,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC;IAE5C,MAAM,IAAI,GAAG,KAAK,EAAE,IAAY,EAAE,IAAc,EAAE,EAAE;QAClD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI,EAAE,EAAE;YACvC,MAAM,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM;YAC3C,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,EAAE;YACpE,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC3D,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC;SACvC,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,IAAI,GAA4B,EAAE,CAA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C,CAAC;YAC7D,IAAI,MAAM,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,4DAA4D,UAAU,UAAU,MAAM,EAAE,CAAC,CAAC;QAC5G,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { type TurnOutcome } from '../runtime/turn-runner.js';
|
|
2
2
|
import type { AgentRuntimeConfig } from '../runtime/types.js';
|
|
3
|
+
import { type LiveCallTurnOptions } from '../live-call/handler.js';
|
|
4
|
+
/** The live-call route on the container: its settings, and where it is served. */
|
|
5
|
+
export interface ContainerLiveCallRoute extends LiveCallTurnOptions {
|
|
6
|
+
/** The path it is served at. Default `/live-call/turns`. */
|
|
7
|
+
path?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Where the container serves the live-call route unless told otherwise. */
|
|
10
|
+
export declare const DEFAULT_LIVE_CALL_PATH = "/live-call/turns";
|
|
3
11
|
export interface ContainerAgentConfig<TDb> extends AgentRuntimeConfig<TDb> {
|
|
4
12
|
/** The port to listen on. `0` picks a free one. Required. */
|
|
5
13
|
port: number;
|
|
@@ -11,6 +19,12 @@ export interface ContainerAgentConfig<TDb> extends AgentRuntimeConfig<TDb> {
|
|
|
11
19
|
maxBodyBytes?: number;
|
|
12
20
|
/** Called with each turn's outcome, after it ends. */
|
|
13
21
|
onTurnEnd?: (outcome: TurnOutcome) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Serves live-call turns too (`createLiveCallTurnHandler`), on the
|
|
24
|
+
* same runtime and slots. Its requests carry the call service's bearer
|
|
25
|
+
* credential, not `workerApiKey`.
|
|
26
|
+
*/
|
|
27
|
+
liveCall?: ContainerLiveCallRoute;
|
|
14
28
|
}
|
|
15
29
|
export interface ContainerAgentWorker {
|
|
16
30
|
/** The port the server listens on (the one picked, when configured with 0). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/container/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/container/server.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAEpG,OAAO,KAAK,EAAE,kBAAkB,EAAoB,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAElF,kFAAkF;AAClF,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAEzD,MAAM,WAAW,oBAAoB,CAAC,GAAG,CAAE,SAAQ,kBAAkB,CAAC,GAAG,CAAC;IACxE,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,kGAAkG;IAClG,YAAY,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC;CACnC;AAED,MAAM,WAAW,oBAAoB;IACnC,+EAA+E;IAC/E,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,OAAO,IAAI,MAAM,CAAC;IAClB,0EAA0E;IAC1E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAkHrH"}
|
package/dist/container/server.js
CHANGED
|
@@ -9,11 +9,20 @@
|
|
|
9
9
|
* POST /turns AgentTurnPayload → 202 { turnId }
|
|
10
10
|
* 400 not a turn · 401 wrong key · 409 turn already running
|
|
11
11
|
* 503 at capacity or shutting down (retry later)
|
|
12
|
+
* POST <liveCall.path> a live-call turn → 200 text/event-stream (live-call/handler.ts),
|
|
13
|
+
* when `liveCall` is configured
|
|
12
14
|
* GET /health 200 { status, running, capacity, model }
|
|
15
|
+
*
|
|
16
|
+
* Both routes take turns from one set of slots: `maxConcurrentTurns` bounds
|
|
17
|
+
* them together, and closing waits for both.
|
|
13
18
|
*/
|
|
14
19
|
import http from 'node:http';
|
|
15
20
|
import crypto from 'node:crypto';
|
|
16
21
|
import { createAgentTurnRunner, payloadRefusal } from '../runtime/turn-runner.js';
|
|
22
|
+
import { createTurnSlots } from '../runtime/turn-slots.js';
|
|
23
|
+
import { liveCallRoute } from '../live-call/handler.js';
|
|
24
|
+
/** Where the container serves the live-call route unless told otherwise. */
|
|
25
|
+
export const DEFAULT_LIVE_CALL_PATH = '/live-call/turns';
|
|
17
26
|
export async function startContainerAgentWorker(config) {
|
|
18
27
|
const missing = [
|
|
19
28
|
!(Number.isInteger(config?.port) && config.port >= 0) && 'port (the port to listen on, 0 for any free port)',
|
|
@@ -21,14 +30,21 @@ export async function startContainerAgentWorker(config) {
|
|
|
21
30
|
].filter(Boolean);
|
|
22
31
|
if (missing.length > 0)
|
|
23
32
|
throw new Error(`[agent-sdk] Missing required configuration: ${missing.join('; ')}`);
|
|
33
|
+
const liveCallPath = config.liveCall ? (config.liveCall.path ?? DEFAULT_LIVE_CALL_PATH) : null;
|
|
34
|
+
if (liveCallPath !== null && (!liveCallPath.startsWith('/') || liveCallPath === '/turns' || liveCallPath === '/health')) {
|
|
35
|
+
throw new Error(`[agent-sdk] liveCall.path must be a path of its own beginning with '/', not ${JSON.stringify(liveCallPath)}`);
|
|
36
|
+
}
|
|
24
37
|
const runner = createAgentTurnRunner(config);
|
|
25
38
|
const capacity = config.maxConcurrentTurns ?? 8;
|
|
39
|
+
const slots = createTurnSlots(capacity);
|
|
26
40
|
const maxBodyBytes = config.maxBodyBytes ?? 1024 * 1024;
|
|
41
|
+
const liveCall = config.liveCall
|
|
42
|
+
? liveCallRoute(config.liveCall, { runner, slots, maxBodyBytes: Math.min(maxBodyBytes, 64 * 1024), onTurnEnd: config.onTurnEnd })
|
|
43
|
+
: null;
|
|
27
44
|
const expectedKey = crypto.createHash('sha256').update(config.workerApiKey).digest();
|
|
28
45
|
const isKey = (presented) => typeof presented === 'string' &&
|
|
29
46
|
presented.length > 0 &&
|
|
30
47
|
crypto.timingSafeEqual(crypto.createHash('sha256').update(presented).digest(), expectedKey);
|
|
31
|
-
const inFlight = new Map();
|
|
32
48
|
let closing = false;
|
|
33
49
|
const send = (res, status, body) => {
|
|
34
50
|
res.writeHead(status, { 'content-type': 'application/json' });
|
|
@@ -36,7 +52,11 @@ export async function startContainerAgentWorker(config) {
|
|
|
36
52
|
};
|
|
37
53
|
const server = http.createServer((req, res) => {
|
|
38
54
|
if (req.method === 'GET' && req.url === '/health') {
|
|
39
|
-
send(res, closing ? 503 : 200, { status: closing ? 'closing' : 'ok', running:
|
|
55
|
+
send(res, closing ? 503 : 200, { status: closing ? 'closing' : 'ok', running: slots.running(), capacity, model: runner.model });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (liveCall && pathOf(req.url) === liveCallPath) {
|
|
59
|
+
liveCall(req, res);
|
|
40
60
|
return;
|
|
41
61
|
}
|
|
42
62
|
if (req.method !== 'POST' || req.url !== '/turns') {
|
|
@@ -74,15 +94,7 @@ export async function startContainerAgentWorker(config) {
|
|
|
74
94
|
send(res, 400, { error: refusal });
|
|
75
95
|
return;
|
|
76
96
|
}
|
|
77
|
-
|
|
78
|
-
send(res, 409, { error: `turn ${payload.turnId} is already running` });
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (closing || inFlight.size >= capacity) {
|
|
82
|
-
send(res, 503, { error: closing ? 'shutting down' : 'at capacity' });
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const run = runner
|
|
97
|
+
const busy = slots.take(payload.turnId, () => runner
|
|
86
98
|
.run(payload)
|
|
87
99
|
.then((outcome) => config.onTurnEnd?.(outcome))
|
|
88
100
|
.catch((err) => {
|
|
@@ -93,9 +105,11 @@ export async function startContainerAgentWorker(config) {
|
|
|
93
105
|
turnId: payload.turnId,
|
|
94
106
|
error: err instanceof Error ? err.message : String(err),
|
|
95
107
|
});
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
|
|
108
|
+
}));
|
|
109
|
+
if (busy) {
|
|
110
|
+
send(res, busy.status, { error: busy.error });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
99
113
|
send(res, 202, { turnId: payload.turnId });
|
|
100
114
|
});
|
|
101
115
|
});
|
|
@@ -108,12 +122,17 @@ export async function startContainerAgentWorker(config) {
|
|
|
108
122
|
});
|
|
109
123
|
return {
|
|
110
124
|
port: server.address().port,
|
|
111
|
-
running: () =>
|
|
125
|
+
running: () => slots.running(),
|
|
112
126
|
async close() {
|
|
113
127
|
closing = true;
|
|
114
|
-
await
|
|
128
|
+
await slots.drain();
|
|
115
129
|
await new Promise((resolve) => server.close(() => resolve()));
|
|
116
130
|
},
|
|
117
131
|
};
|
|
118
132
|
}
|
|
133
|
+
/** The path of a request URL, without its query. */
|
|
134
|
+
function pathOf(url) {
|
|
135
|
+
const end = (url ?? '').search(/[?#]/);
|
|
136
|
+
return end === -1 ? (url ?? '') : (url ?? '').slice(0, end);
|
|
137
|
+
}
|
|
119
138
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/container/server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/container/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAA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,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A turn's events, seen by its host as they are sent.
|
|
3
|
+
*
|
|
4
|
+
* A turn streams to its realtime room. A host that also answers the turn's
|
|
5
|
+
* caller directly (the live-call handler, which streams the reply back on the
|
|
6
|
+
* HTTP response) sees the same events, as the turn emits them: one stream of
|
|
7
|
+
* events, two destinations, and no second model call.
|
|
8
|
+
*/
|
|
9
|
+
import type { RealtimeEmitAdapter } from './types.js';
|
|
10
|
+
/** Called with each event a turn emits, before it is sent to the room. */
|
|
11
|
+
export type TurnEventObserver = (event: string, data: unknown) => void;
|
|
12
|
+
/**
|
|
13
|
+
* `adapter`, also handing each event to `observe` first. The observer is
|
|
14
|
+
* called synchronously and never delays or fails the send: what it throws is
|
|
15
|
+
* given to `onObserverError`, and the event still goes to the room.
|
|
16
|
+
*/
|
|
17
|
+
export declare function teeEmitAdapter(adapter: RealtimeEmitAdapter, observe: TurnEventObserver, onObserverError: (error: unknown, event: string) => void): RealtimeEmitAdapter;
|
|
18
|
+
//# sourceMappingURL=tee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tee.d.ts","sourceRoot":"","sources":["../../src/emit/tee.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;AAEvE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,iBAAiB,EAC1B,eAAe,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GACvD,mBAAmB,CAWrB"}
|
package/dist/emit/tee.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `adapter`, also handing each event to `observe` first. The observer is
|
|
3
|
+
* called synchronously and never delays or fails the send: what it throws is
|
|
4
|
+
* given to `onObserverError`, and the event still goes to the room.
|
|
5
|
+
*/
|
|
6
|
+
export function teeEmitAdapter(adapter, observe, onObserverError) {
|
|
7
|
+
return {
|
|
8
|
+
emit(room, event, data) {
|
|
9
|
+
try {
|
|
10
|
+
observe(event, data);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
onObserverError(error, event);
|
|
14
|
+
}
|
|
15
|
+
return adapter.emit(room, event, data);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=tee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tee.js","sourceRoot":"","sources":["../../src/emit/tee.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,OAA4B,EAC5B,OAA0B,EAC1B,eAAwD;IAExD,OAAO;QACL,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI;YACpB,IAAI,CAAC;gBACH,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACvB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC;YACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type { ApprovalStoreClient, HttpApprovalStoreClientConfig } from './appro
|
|
|
31
31
|
export { approvalRequirement, APPROVAL_TOOL_NOTE } from './approvals/requirement.js';
|
|
32
32
|
export type { ApprovalRequirement } from './approvals/requirement.js';
|
|
33
33
|
export { buildApprovalPreview } from './approvals/preview.js';
|
|
34
|
-
export { createHttpTurnStopClient, watchTurnStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
34
|
+
export { createHttpTurnStopClient, watchTurnStop, withLocalStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
35
35
|
export type { TurnStopClient, HttpTurnStopClientConfig, TurnStopWatch, TurnStopState } from './stop/turn-stop.js';
|
|
36
36
|
export { stoppedTurnMessages } from './stop/partial.js';
|
|
37
37
|
export type { AttachmentStore, AttachmentStoreCallOptions, AttachmentOwner, AttachmentLoadAs, AttachmentContent, AttachmentWorkerConfig } from './attachments/store.js';
|
|
@@ -60,13 +60,20 @@ export type { TurnPolicy, StepTool } from './turn-policy.js';
|
|
|
60
60
|
export { defaultTurnPolicy } from './turn-policy.js';
|
|
61
61
|
export { createHttpEmitAdapter } from './emit/http-adapter.js';
|
|
62
62
|
export type { HttpEmitAdapterConfig } from './emit/http-adapter.js';
|
|
63
|
+
export { teeEmitAdapter } from './emit/tee.js';
|
|
64
|
+
export type { TurnEventObserver } from './emit/tee.js';
|
|
63
65
|
export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
|
|
64
|
-
export type { AgentTurnRunner, TurnOutcome, CategorizedError } from './runtime/turn-runner.js';
|
|
66
|
+
export type { AgentTurnRunner, TurnHost, TurnOutcome, CategorizedError } from './runtime/turn-runner.js';
|
|
65
67
|
export { assertAgentRuntimeConfig } from './runtime/config.js';
|
|
66
68
|
export type { AgentRuntimeConfig, LambdaAgentConfig, AgentTurnPayload, HistoryRequest, TurnHistory } from './runtime/types.js';
|
|
67
69
|
export { createLambdaAgentHandler } from './lambda/handler.js';
|
|
68
|
-
export { startContainerAgentWorker } from './container/server.js';
|
|
69
|
-
export type { ContainerAgentConfig, ContainerAgentWorker } from './container/server.js';
|
|
70
|
+
export { startContainerAgentWorker, DEFAULT_LIVE_CALL_PATH } from './container/server.js';
|
|
71
|
+
export type { ContainerAgentConfig, ContainerAgentWorker, ContainerLiveCallRoute } from './container/server.js';
|
|
72
|
+
export { createLiveCallTurnHandler } from './live-call/handler.js';
|
|
73
|
+
export type { LiveCallTurnHandler, LiveCallTurnHandlerConfig, LiveCallTurnOptions, LiveCallTurnTarget, LiveCallTurnCallContext, } from './live-call/handler.js';
|
|
74
|
+
export { readLiveCallTurnRequest, liveCallError, LIVE_CALL_TURN_KINDS, LIVE_CALL_OPENING_MESSAGE, LIVE_CALL_TYPED_INPUT_MODE, LIVE_CALL_LIMITS, LIVE_CALL_ERROR_MESSAGES, } from './live-call/protocol.js';
|
|
75
|
+
export type { LiveCallTurnKind, LiveCallTurnRequest, LiveCallStreamEvents, LiveCallStreamEventName, LiveCallRequestReading, } from './live-call/protocol.js';
|
|
76
|
+
export { DEFAULT_KEEP_ALIVE_MS as LIVE_CALL_KEEP_ALIVE_MS } from './live-call/event-stream.js';
|
|
70
77
|
export { buildAgentSystemPrompt } from './prompt/index.js';
|
|
71
78
|
export type { AgentPersonaConfig, AgentKnowledgeEntry, AgentWorkflow, AgentFewShotExample, AgentPersonaOverrides, PromptBuildContext, CommunicationStyle, } from './prompt/index.js';
|
|
72
79
|
export { getBaseRules, getCommunicationRules, getToolStrategyRules, getUIControlRules } from './prompt/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,iBAAiB,EAAE,c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M,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ export { buildApprovalPreview } from './approvals/preview.js';
|
|
|
27
27
|
// Stopping a turn: the person's Stop, or a newer message that
|
|
28
28
|
// supersedes the turn, is kept by the realtime server and asked for by the
|
|
29
29
|
// turn. What the turn had produced is stored, then announced.
|
|
30
|
-
export { createHttpTurnStopClient, watchTurnStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
30
|
+
export { createHttpTurnStopClient, watchTurnStop, withLocalStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
31
31
|
export { stoppedTurnMessages } from './stop/partial.js';
|
|
32
32
|
export { AttachmentGuard } from './attachments/guard.js';
|
|
33
33
|
export { attachmentTools, ATTACHMENT_TOOLS, ATTACHMENT_TOOL_CLASS } from './attachments/tools.js';
|
|
@@ -48,11 +48,17 @@ export { PROMPT_CACHE_BREAKPOINTS, describeModel } from './model.js';
|
|
|
48
48
|
export { answerWithoutState } from './ui/page-state-at-end.js';
|
|
49
49
|
export { defaultTurnPolicy } from './turn-policy.js';
|
|
50
50
|
export { createHttpEmitAdapter } from './emit/http-adapter.js';
|
|
51
|
+
export { teeEmitAdapter } from './emit/tee.js';
|
|
51
52
|
// The runtime: one core, two host adapters (Lambda + SQS, container)
|
|
52
53
|
export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
|
|
53
54
|
export { assertAgentRuntimeConfig } from './runtime/config.js';
|
|
54
55
|
export { createLambdaAgentHandler } from './lambda/handler.js';
|
|
55
|
-
export { startContainerAgentWorker } from './container/server.js';
|
|
56
|
+
export { startContainerAgentWorker, DEFAULT_LIVE_CALL_PATH } from './container/server.js';
|
|
57
|
+
// Live calls: the call service's turns, answered by the product's own agent as
|
|
58
|
+
// a server-sent event stream, while the turn streams to its room as any turn does.
|
|
59
|
+
export { createLiveCallTurnHandler } from './live-call/handler.js';
|
|
60
|
+
export { readLiveCallTurnRequest, liveCallError, LIVE_CALL_TURN_KINDS, LIVE_CALL_OPENING_MESSAGE, LIVE_CALL_TYPED_INPUT_MODE, LIVE_CALL_LIMITS, LIVE_CALL_ERROR_MESSAGES, } from './live-call/protocol.js';
|
|
61
|
+
export { DEFAULT_KEEP_ALIVE_MS as LIVE_CALL_KEEP_ALIVE_MS } from './live-call/event-stream.js';
|
|
56
62
|
// Prompt Framework
|
|
57
63
|
export { buildAgentSystemPrompt } from './prompt/index.js';
|
|
58
64
|
export { getBaseRules, getCommunicationRules, getToolStrategyRules, getUIControlRules } from './prompt/index.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,oDAAoD;AACpD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,oEAAoE;AACpE,iEAAiE;AACjE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAkB/F,OAAO,EAAE,iBAAiB,EAAE,s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|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A live-call turn's response: a server-sent event stream, kept alive while
|
|
3
|
+
* the turn has nothing to say (a tool call, an answer from the page), so the
|
|
4
|
+
* call service's silence deadline is never reached by a turn that is working.
|
|
5
|
+
*/
|
|
6
|
+
import type { ServerResponse } from 'node:http';
|
|
7
|
+
import type { LiveCallStreamEventName, LiveCallStreamEvents } from './protocol.js';
|
|
8
|
+
/** How long the stream may be silent before a `: keep-alive` comment is sent. */
|
|
9
|
+
export declare const DEFAULT_KEEP_ALIVE_MS = 5000;
|
|
10
|
+
export interface LiveCallEventStream {
|
|
11
|
+
/** Sends one event. Does nothing once the stream is closed, by either end. */
|
|
12
|
+
send<E extends LiveCallStreamEventName>(event: E, data: LiveCallStreamEvents[E]): void;
|
|
13
|
+
/** Ends the response. */
|
|
14
|
+
end(): void;
|
|
15
|
+
/** Whether events can still be sent: the response has not ended and the caller has not gone. */
|
|
16
|
+
open(): boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Answers `200 text/event-stream` on `res` at once, and returns the stream. */
|
|
19
|
+
export declare function openLiveCallEventStream(res: ServerResponse, keepAliveMs?: number): LiveCallEventStream;
|
|
20
|
+
//# sourceMappingURL=event-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.d.ts","sourceRoot":"","sources":["../../src/live-call/event-stream.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAEnF,iFAAiF;AACjF,eAAO,MAAM,qBAAqB,OAAQ,CAAC;AAE3C,MAAM,WAAW,mBAAmB;IAClC,8EAA8E;IAC9E,IAAI,CAAC,CAAC,SAAS,uBAAuB,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACvF,yBAAyB;IACzB,GAAG,IAAI,IAAI,CAAC;IACZ,gGAAgG;IAChG,IAAI,IAAI,OAAO,CAAC;CACjB;AAED,gFAAgF;AAChF,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,cAAc,EAAE,WAAW,GAAE,MAA8B,GAAG,mBAAmB,CAsC7H"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** How long the stream may be silent before a `: keep-alive` comment is sent. */
|
|
2
|
+
export const DEFAULT_KEEP_ALIVE_MS = 5_000;
|
|
3
|
+
/** Answers `200 text/event-stream` on `res` at once, and returns the stream. */
|
|
4
|
+
export function openLiveCallEventStream(res, keepAliveMs = DEFAULT_KEEP_ALIVE_MS) {
|
|
5
|
+
res.writeHead(200, {
|
|
6
|
+
'content-type': 'text/event-stream; charset=utf-8',
|
|
7
|
+
'cache-control': 'no-cache, no-transform',
|
|
8
|
+
connection: 'keep-alive',
|
|
9
|
+
// A proxy in front of the product must pass each event on as it is written.
|
|
10
|
+
'x-accel-buffering': 'no',
|
|
11
|
+
});
|
|
12
|
+
res.flushHeaders();
|
|
13
|
+
// Each event is written as soon as it is produced: a reply's first words are what the caller waits on.
|
|
14
|
+
res.socket?.setNoDelay(true);
|
|
15
|
+
const open = () => !res.writableEnded && !res.destroyed;
|
|
16
|
+
const keepAlive = setTimeout(function beat() {
|
|
17
|
+
if (!open())
|
|
18
|
+
return;
|
|
19
|
+
res.write(': keep-alive\n\n');
|
|
20
|
+
keepAlive.refresh();
|
|
21
|
+
}, keepAliveMs);
|
|
22
|
+
const stop = () => clearTimeout(keepAlive);
|
|
23
|
+
res.once('close', stop);
|
|
24
|
+
const write = (chunk) => {
|
|
25
|
+
if (!open())
|
|
26
|
+
return;
|
|
27
|
+
res.write(chunk);
|
|
28
|
+
// The silence is counted from the last thing written.
|
|
29
|
+
keepAlive.refresh();
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
send(event, data) {
|
|
33
|
+
write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
|
|
34
|
+
},
|
|
35
|
+
end() {
|
|
36
|
+
stop();
|
|
37
|
+
if (open())
|
|
38
|
+
res.end();
|
|
39
|
+
},
|
|
40
|
+
open,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=event-stream.js.map
|