@ouispec/agent-worker 0.15.0 → 0.16.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 +51 -12
- package/dist/approvals/hooks.d.ts +82 -0
- package/dist/approvals/hooks.d.ts.map +1 -0
- package/dist/approvals/hooks.js +94 -0
- package/dist/approvals/hooks.js.map +1 -0
- package/dist/container/server.js +1 -1
- package/dist/container/server.js.map +1 -1
- package/dist/emit/filter.d.ts +23 -0
- package/dist/emit/filter.d.ts.map +1 -0
- package/dist/emit/filter.js +27 -0
- package/dist/emit/filter.js.map +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/lambda/handler.d.ts.map +1 -1
- package/dist/lambda/handler.js +4 -1
- package/dist/lambda/handler.js.map +1 -1
- package/dist/live-call/handler.d.ts +34 -2
- package/dist/live-call/handler.d.ts.map +1 -1
- package/dist/live-call/handler.js +91 -13
- package/dist/live-call/handler.js.map +1 -1
- package/dist/live-call/protocol.d.ts +29 -3
- package/dist/live-call/protocol.d.ts.map +1 -1
- package/dist/live-call/protocol.js +32 -2
- package/dist/live-call/protocol.js.map +1 -1
- package/dist/orchestrator.d.ts +5 -0
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +147 -28
- package/dist/orchestrator.js.map +1 -1
- package/dist/prompt/builder.d.ts +1 -1
- package/dist/prompt/builder.d.ts.map +1 -1
- package/dist/prompt/builder.js +8 -2
- package/dist/prompt/builder.js.map +1 -1
- package/dist/prompt/rules/base.js +4 -4
- package/dist/prompt/spoken-reply.d.ts +1 -1
- package/dist/prompt/spoken-reply.d.ts.map +1 -1
- package/dist/prompt/spoken-reply.js +14 -2
- package/dist/prompt/spoken-reply.js.map +1 -1
- package/dist/prompt/types.d.ts +12 -0
- package/dist/prompt/types.d.ts.map +1 -1
- package/dist/runtime/turn-info.d.ts +28 -0
- package/dist/runtime/turn-info.d.ts.map +1 -0
- package/dist/runtime/turn-info.js +23 -0
- package/dist/runtime/turn-info.js.map +1 -0
- package/dist/runtime/turn-runner.d.ts +15 -2
- package/dist/runtime/turn-runner.d.ts.map +1 -1
- package/dist/runtime/turn-runner.js +65 -10
- package/dist/runtime/turn-runner.js.map +1 -1
- package/dist/runtime/types.d.ts +45 -4
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/turn-policy.d.ts +8 -1
- package/dist/turn-policy.d.ts.map +1 -1
- package/dist/turn-policy.js.map +1 -1
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Optional tuning, with its defaults:
|
|
|
28
28
|
|
|
29
29
|
A host that fits its stored history loads `@ouispec/agent-worker/history` (`answerWithoutState`): a module with no runtime imports, which also answers a CommonJS resolver.
|
|
30
30
|
|
|
31
|
-
Policy hooks: `turnPolicy`, `toolPolicy`, `uiActions`, `approvals`, `stops`, `logger
|
|
31
|
+
Policy hooks: `turnPolicy`, `toolPolicy`, `uiActions`, `approvals`, `stops`, `logger`, and the hooks every turn passes through, `beforeTurn` and `filterEvent` ("Hooks on every turn").
|
|
32
32
|
|
|
33
33
|
## What a UI client sends with a turn
|
|
34
34
|
|
|
@@ -39,13 +39,38 @@ Four keys on the turn's `context` are for the worker itself, and your persona or
|
|
|
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
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
|
+
| `output` | How the reply reaches the person, when it is not shown as text: `{ mode: 'voice' }` when a voice reads it out, with `voiceDirections: { engine, tags, guidance }` when that voice can be directed by inline tags. 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. With `voiceDirections`, the same line offers the engine's tags, written exactly as given, says they are performed rather than read out and that no other tags are used, and ends with the service's `guidance`. An unknown mode is read as a shown reply, which gets nothing, and malformed directions (an empty tag list, a tag or engine with a control character, guidance over 2,000 characters; `VOICE_DIRECTIONS_LIMITS`) are left out while the reply is still spoken (`readReplyOutput` in `@ouispec/agent-core`). It applies on every turn of a call, the turn that continues an approval included |
|
|
43
43
|
|
|
44
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.
|
|
45
45
|
|
|
46
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.
|
|
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
|
+
Every other key is the page's context, which a persona prompt shows as the current UI state ("CURRENT UI CONTEXT", as JSON). A persona whose context is not a page renders it itself: `persona.renderContext(ctx)` returns the section to end the system prompt with, or null (or blank) for none, and is given the context without the four keys above. It renders into the system prompt, the start of the cached prefix, so render nothing that changes from turn to turn unless the conversation's context did. 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.
|
|
49
|
+
|
|
50
|
+
## Hooks on every turn
|
|
51
|
+
|
|
52
|
+
Every turn reaches the runtime one of four ways: the Lambda adapter, the container's `/turns`, the live-call handler, or your own code calling `runner.run`. Each hook below runs for all of them, and is told which turn it is called for (`AgentTurnInfo`):
|
|
53
|
+
|
|
54
|
+
| Field | |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `id` | The turn's id. |
|
|
57
|
+
| `channel` | How it came: `lambda`, `container`, `live-call`, or what you pass as `runner.run(payload, { channel })` when you call it yourself (`sms`, `chat`); `direct` when you pass none. |
|
|
58
|
+
| `inputMode` | `voice` when the person's message was spoken and transcribed (its context's `input`), else `text`. |
|
|
59
|
+
| `language` | The language it was recognised in, a BCP 47 tag, when spoken and the recogniser said; else null. |
|
|
60
|
+
|
|
61
|
+
**`beforeTurn(payload, info)`**, on the runtime config, runs before anything else. Return the payload to run, changed or not: the person's words with a card number redacted before the model reads them (`content`), a reshaped context. Store the same redacted copy yourself. Return null to refuse the turn: nothing is read, run, stored or sent to the room, and the runner's outcome is `{ status: 'refused', refusedBy: 'beforeTurn' }` (a live call is answered `error` `TURN_DECLINED`); tell your own client why. The turn's `turnId`, `conversationId`, `userId`, `accountId` and `socketRoom` are not the hook's to change: a returned turn that changes one, or is not a turn, fails it, as a throw does (`agent:turn_error` to the turn's own room).
|
|
62
|
+
|
|
63
|
+
**`filterEvent(event, data, turn)`**, on the runtime config, decides what of each turn event leaves the runtime: return the payload to send (it is given a copy, so change it freely), or null to send nothing. It runs before the room, before a host that observes the turn, and so before the live-call handler speaks anything: one filter covers the page, the call and the room alike. Mask a phone number in a tool call's `input`, in a readback, or in the reply's text; drop `agent:reasoning_*`. It is synchronous, so events keep their order. It fails closed: a throw, or a return that is neither a payload nor null, drops that event and logs `The host’s event filter failed; the event was not sent`. A tool still runs with the arguments the model gave it: the filter governs what is sent, not what runs. The UI action requests the worker sends the user's own tab are not turn events, and do not pass through it.
|
|
64
|
+
|
|
65
|
+
**The turn policy** is told the turn too: `classifyTurn(content, history, turn)`, and `turn` on the context of `prepareStep` and `onTurnClassified`.
|
|
66
|
+
|
|
67
|
+
### The rounds of a turn
|
|
68
|
+
|
|
69
|
+
The model writes a reply in rounds: text, tool calls, more text. Each `agent:token` names its round (`step`, from 0), and each round's end is sent once all of its text has been: `agent:round_end { turnId, step, calledTools, final, timestamp }`. `calledTools` says the round called tools; `final` says no round follows it, so its text is the turn's last word. A round that ended at an approval, at a choice for the person (`present_options`), at the hand-back for time or at the last step allowed is final though it called a tool; a round cut off at the output limit having said nothing never is. A round's tool calls (`agent:tool_call_started`) are sent after its text and before its end. A host reply (`runner.reply`) is one final round, and so is the line the person is told when every attempt at a step was cut off.
|
|
70
|
+
|
|
71
|
+
A consumer that shows or speaks only what the turn ends with, never what the model wrote before a tool call, holds each round's text until its `round_end` and keeps it when `final`. The live-call handler does this with `speak: 'final-round'` ("Live calls"). Text before a tool call is otherwise shown and spoken as it streams, and the shipped prompt tells the model so: at most one brief line for the person before a tool call, or nothing, and never its reasoning.
|
|
72
|
+
|
|
73
|
+
Update the realtime server with the worker: a server on an older `@ouispec/agent-events` refuses `agent:round_end` as undeclared, and the worker logs each refused emit.
|
|
49
74
|
|
|
50
75
|
## Approvals
|
|
51
76
|
|
|
@@ -69,6 +94,13 @@ On a call there is no card. The live-call handler sends the preview's `readback`
|
|
|
69
94
|
|
|
70
95
|
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`.
|
|
71
96
|
|
|
97
|
+
Two hooks give you a say before an approval is asked for. Both are told the turn (`turn`, `channel`), the user, account and conversation, and `locale`: the language the person's message was recognised in (on a call, the request's `input.language`), null for a typed message.
|
|
98
|
+
|
|
99
|
+
- **`approvals.validateBeforeApproval(tool, args, ctx)`** checks the call before it is read back: `{ ok: true }`, or `{ ok: false, error }` to refuse it. A refused call is not stored or shown; the model gets `error` as the call's result (`refusedBeforeApproval: true`) and can correct it, so a booking for a time you never offered is caught before the person approves it, not after. A throw refuses the call too.
|
|
100
|
+
- **`approvals.preview(tool, args, ctx)`** writes the approval's display copy in place of the one built from the declaration (`ctx.built`): `{ title, consequence?, arguments, readback, spokenReadback? }`. Redact a value there, and write it in the person's language with dates, times and numbers as words; `spokenReadback` is the readback as a voice should say it, digits grouped for speech, and a live call speaks it in place of `readback`. That copy is what the approval store keeps with the call, what `agent:approval_required` carries to the card, and what is read back. The call that runs is still exactly the model's: the store keeps its original arguments and `argsHash` is over them, so a decision redeems exactly the call the model made. A throw, or an answer that is not a preview within the store's limits (`APPROVAL_PREVIEW_LIMITS`), means the approval cannot be asked for, and the call is not run: the built preview, with the values you meant to remove, is never the fallback.
|
|
101
|
+
|
|
102
|
+
Of the calls in one response, only the first that needs approval is asked for. While its check and preview are written, a call that arrives waits for the outcome: if the first is refused, the next is checked as if it had come first.
|
|
103
|
+
|
|
72
104
|
## Stopping a turn
|
|
73
105
|
|
|
74
106
|
A turn can be stopped by the person, or superseded by their next message. The request is kept by the realtime server (`@ouispec/agent-realtime`, "Stopping a turn"), and the turn asks for it there for as long as it runs. Nothing needs configuring: the runtime uses the realtime server you already gave it. `stops.graceMs` (default 2 s) is how long an answer already on its way is still waited for.
|
|
@@ -174,14 +206,14 @@ Your API sends turns to the worker's HTTP endpoints:
|
|
|
174
206
|
|
|
175
207
|
`onTurnEnd` receives each turn's outcome.
|
|
176
208
|
|
|
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`.
|
|
209
|
+
`liveCall: { credential, resolveTurn, opening?, speak?, holdingLine?, 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
210
|
|
|
179
211
|
## Live calls
|
|
180
212
|
|
|
181
213
|
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
214
|
|
|
183
215
|
```ts
|
|
184
|
-
import { createAgentTurnRunner, createLiveCallTurnHandler,
|
|
216
|
+
import { createAgentTurnRunner, createLiveCallTurnHandler, liveCallOpeningMessage } from '@ouispec/agent-worker';
|
|
185
217
|
|
|
186
218
|
const runner = createAgentTurnRunner(runtimeConfig); // the same config as your other turns
|
|
187
219
|
const liveCall = createLiveCallTurnHandler({
|
|
@@ -190,16 +222,20 @@ const liveCall = createLiveCallTurnHandler({
|
|
|
190
222
|
resolveTurn: async (request, { signal }) => {
|
|
191
223
|
const conversation = await findConversationByCallRef(request.clientRef);
|
|
192
224
|
if (!conversation) return null; // answered 404
|
|
193
|
-
|
|
225
|
+
const said = request.kind === 'opening' ? liveCallOpeningMessage(request) : redactCardNumbers(request.text);
|
|
226
|
+
await storeUserMessage(conversation.id, said, request.input);
|
|
194
227
|
return {
|
|
195
228
|
conversationId: conversation.id,
|
|
196
229
|
userId: conversation.userId,
|
|
197
230
|
accountId: conversation.accountId,
|
|
198
231
|
socketRoom: `conversation:${conversation.id}`,
|
|
199
232
|
context: conversation.pageContext, // the call page's OUI snapshot and knowledge, as for a typed turn
|
|
233
|
+
content: said, // what the model reads: your redacted copy
|
|
200
234
|
};
|
|
201
235
|
},
|
|
202
236
|
opening: (request, target) => greetingTemplateFor(target.accountId), // optional; null lets the model greet
|
|
237
|
+
speak: 'final-round', // optional; only the round the turn ends with is spoken
|
|
238
|
+
holdingLine: (request) => (request.input?.language === 'es' ? 'Un momento.' : 'One moment.'),
|
|
203
239
|
});
|
|
204
240
|
app.post('/agent/live-call/turns', liveCall); // any Node server: (req, res)
|
|
205
241
|
process.on('SIGTERM', () => liveCall.close()); // waits for running turns
|
|
@@ -211,8 +247,10 @@ process.on('SIGTERM', () => liveCall.close()); // waits for running turns
|
|
|
211
247
|
|---|---|
|
|
212
248
|
| `runner` | Required. `createAgentTurnRunner(...)`: the runtime that runs your other turns. |
|
|
213
249
|
| `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 `
|
|
250
|
+
| `resolveTurn(request, { signal })` | Required. The call's `clientRef` → the turn's `conversationId`, `userId`, `accountId` and `socketRoom`, with optional `context`, `userToken`, `approval` and `content`; null when you have no such conversation. `content` is what the model reads in place of `request.text`: your redacted copy (the runtime's `beforeTurn` can do the same on every channel). Do here what your API does for a chat message: store the person's message (your redacted copy; for an `opening`, `liveCallOpeningMessage(request)`), claim the turn, and decide on a waiting readback ("Approvals"). `signal` aborts if the caller hangs up meanwhile. |
|
|
215
251
|
| `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. |
|
|
252
|
+
| `speak` | `all` (the default): every round of the reply is spoken as the model writes it, its words before a tool call included. `final-round`: only the round the turn ends with ("The rounds of a turn"): each round's text is held until it ends and sent only when it is final, so nothing written before a tool call is spoken. The reply then starts when its last round is written, not with its first words. |
|
|
253
|
+
| `holdingLine` | With `final-round` only: a line of yours spoken once, as the turn's first tool starts (not a choice the turn ends with), so the caller does not wait in silence. A string, or `(request, target)` returning one (localise from `request.input.language`); null or blank says nothing; a throw fails the turn. Set with `all`, the handler refuses to start: there the model's own words before a tool call are spoken. |
|
|
216
254
|
| `keepAliveMs` | Default 5 s: a `: keep-alive` comment after this long with nothing written. |
|
|
217
255
|
| `maxConcurrentTurns` | Default 8; more are answered `503`. |
|
|
218
256
|
| `maxBodyBytes` | Default 64 KiB. |
|
|
@@ -225,10 +263,11 @@ process.on('SIGTERM', () => liveCall.close()); // waits for running turns
|
|
|
225
263
|
| `sessionId` | The call service's session. |
|
|
226
264
|
| `clientRef` | Your conversation reference, given to the call service when the call was created. |
|
|
227
265
|
| `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 `
|
|
266
|
+
| `kind` | `message`: the person said `text`. `opening`: the call has just connected, `text` is empty, and the agent greets: the model reads `liveCallOpeningMessage(request)` where the person's words would be (`LIVE_CALL_OPENING_MESSAGE` when no disclosure was sent). |
|
|
229
267
|
| `text` | What the person said, as transcribed; at most 8,000 characters. |
|
|
230
268
|
| `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"). |
|
|
269
|
+
| `output` | `{ mode: 'voice', voiceDirections? }`: set as the turn's `context.output`, so the model writes for the ear, and may use the voice's tags when `voiceDirections: { engine, tags, guidance }` offers them ("What a UI client sends with a turn"). |
|
|
270
|
+
| `disclosureLine` | On an `opening`: what the call service has just said to the person before the greeting (that they are talking with an AI assistant), as spoken; at most 1,000 characters. The model is told it was said, and greets following on from it without repeating it. Not read on a `message`. |
|
|
232
271
|
| `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
272
|
|
|
234
273
|
`readLiveCallTurnRequest` reads a body as the handler does, and `LIVE_CALL_LIMITS` holds its limits.
|
|
@@ -237,10 +276,10 @@ process.on('SIGTERM', () => liveCall.close()); // waits for running turns
|
|
|
237
276
|
|
|
238
277
|
| Event | Data | |
|
|
239
278
|
|---|---|---|
|
|
240
|
-
| `text` | `{ text }` | The reply
|
|
241
|
-
| `readback` | `{ approvalId, text, expiresAt }` | The turn stopped at a call that needs approval. `text` is the preview's `
|
|
279
|
+
| `text` | `{ text }` | The reply; concatenate the pieces. With `speak: 'all'`, as the model writes it: rounds written between tool calls are separated by a blank line, as in the room. With `final-round`, the holding line and the turn's last round. |
|
|
280
|
+
| `readback` | `{ approvalId, text, expiresAt }` | The turn stopped at a call that needs approval. `text` is the preview's `spokenReadback` when your `approvals.preview` wrote one, else its `readback`, verbatim; `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
281
|
| `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. |
|
|
282
|
+
| `error` | `{ code, message }` | The turn failed or did not run: `RATE_LIMIT`, `SERVICE_UNAVAILABLE`, `MODEL_TIMEOUT`, `TURN_TIMEOUT`, `TURN_DEADLINE_EXCEEDED`, `TURN_REFUSED` (your turn record refused it), `TURN_DECLINED` (your `beforeTurn` refused it) or `WORKER_ERROR`. `message` is a fixed line for the code; the cause stays in your logs. |
|
|
244
283
|
|
|
245
284
|
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
285
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's say over an approval before it is asked for: whether the call
|
|
3
|
+
* may be asked for at all, and the words the person is shown and told.
|
|
4
|
+
*
|
|
5
|
+
* - **`validateBeforeApproval`** checks a call before it is read back. A
|
|
6
|
+
* booking for a time the product never offered is refused here, and the
|
|
7
|
+
* model is told why as the call's error and can correct it, instead of the
|
|
8
|
+
* person approving a readback the tool then refuses.
|
|
9
|
+
* - **`preview`** writes the approval's display copy: what the card shows, the
|
|
10
|
+
* readback a conversation channel reads or sends, and the readback a voice
|
|
11
|
+
* speaks. A host redacts a value there (an account number, a phone number),
|
|
12
|
+
* or writes it in the person's language, with dates, times and numbers as
|
|
13
|
+
* words. The call that runs is still exactly the model's: the approval store
|
|
14
|
+
* keeps the original arguments, and the args hash it is bound to is theirs.
|
|
15
|
+
* Only the preview stored with it, sent to the room and spoken is the
|
|
16
|
+
* host's.
|
|
17
|
+
*
|
|
18
|
+
* Both fail closed. A validator that throws refuses the call; a preview hook
|
|
19
|
+
* that throws, or returns something that is not a preview, means the approval
|
|
20
|
+
* cannot be asked for, so the call is not run. Falling back to the built
|
|
21
|
+
* preview would show the very values a redacting host removed.
|
|
22
|
+
*/
|
|
23
|
+
import { type ApprovalPreview } from '@ouispec/agent-core';
|
|
24
|
+
import type { RegisteredTool } from '../tools/types.js';
|
|
25
|
+
import type { AgentTurnChannel, AgentTurnInfo } from '../runtime/turn-info.js';
|
|
26
|
+
/** What a host's approval hooks are told of the call's turn. */
|
|
27
|
+
export interface ApprovalHookContext {
|
|
28
|
+
turn: AgentTurnInfo;
|
|
29
|
+
/** How the turn reached the runtime: `turn.channel`. */
|
|
30
|
+
channel: AgentTurnChannel;
|
|
31
|
+
/**
|
|
32
|
+
* The language to write the person's copy in, as a BCP 47 tag: the
|
|
33
|
+
* language their message was recognised in (on a call, the request's
|
|
34
|
+
* `input.language`). Null when the turn does not say: a typed message.
|
|
35
|
+
*/
|
|
36
|
+
locale: string | null;
|
|
37
|
+
userId: string;
|
|
38
|
+
accountId: string;
|
|
39
|
+
conversationId: string;
|
|
40
|
+
}
|
|
41
|
+
/** What `approvals.preview` is told: the turn, and the preview the SDK built from the action's declaration. */
|
|
42
|
+
export interface ApprovalPreviewContext extends ApprovalHookContext {
|
|
43
|
+
/** The SDK's preview, built from the declaration and the call's raw arguments. */
|
|
44
|
+
built: ApprovalPreview;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Writes an approval's display copy. Return the preview to store, show and
|
|
48
|
+
* read back: `readback` for the card's line and for text channels,
|
|
49
|
+
* `spokenReadback` for a voice (the live-call handler speaks it in place of
|
|
50
|
+
* `readback`). Return `built` unchanged to keep the SDK's.
|
|
51
|
+
*/
|
|
52
|
+
export type ApprovalPreviewHook = (tool: RegisteredTool, args: Record<string, unknown>, ctx: ApprovalPreviewContext) => ApprovalPreview | Promise<ApprovalPreview>;
|
|
53
|
+
/** Whether a call may be asked for: `{ ok: false, error }` refuses it, and `error` is the model's to read. */
|
|
54
|
+
export type ApprovalValidation = {
|
|
55
|
+
ok: true;
|
|
56
|
+
} | {
|
|
57
|
+
ok: false;
|
|
58
|
+
error: string;
|
|
59
|
+
};
|
|
60
|
+
/** Checks a call that needs approval before its readback is shown or spoken. */
|
|
61
|
+
export type ValidateBeforeApproval = (tool: RegisteredTool, args: Record<string, unknown>, ctx: ApprovalHookContext) => ApprovalValidation | Promise<ApprovalValidation>;
|
|
62
|
+
/** The approval hooks the orchestrator runs. */
|
|
63
|
+
export interface ApprovalHooks {
|
|
64
|
+
preview?: ApprovalPreviewHook;
|
|
65
|
+
validateBeforeApproval?: ValidateBeforeApproval;
|
|
66
|
+
}
|
|
67
|
+
/** The longest refusal a validator's error is given to the model as. */
|
|
68
|
+
export declare const MAX_VALIDATION_ERROR_CHARS = 2000;
|
|
69
|
+
/** A validator's answer as the orchestrator acts on it: refused with the model's reason, or not. */
|
|
70
|
+
export declare function readValidation(value: unknown): ApprovalValidation;
|
|
71
|
+
/**
|
|
72
|
+
* A host's preview, checked against what the approval store accepts: the
|
|
73
|
+
* preview, or why it is not one.
|
|
74
|
+
*/
|
|
75
|
+
export declare function readHostPreview(value: unknown): {
|
|
76
|
+
ok: true;
|
|
77
|
+
preview: ApprovalPreview;
|
|
78
|
+
} | {
|
|
79
|
+
ok: false;
|
|
80
|
+
error: string;
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/approvals/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAgC,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE/E,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,wDAAwD;IACxD,OAAO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CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAyCrH"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's say over an approval before it is asked for: whether the call
|
|
3
|
+
* may be asked for at all, and the words the person is shown and told.
|
|
4
|
+
*
|
|
5
|
+
* - **`validateBeforeApproval`** checks a call before it is read back. A
|
|
6
|
+
* booking for a time the product never offered is refused here, and the
|
|
7
|
+
* model is told why as the call's error and can correct it, instead of the
|
|
8
|
+
* person approving a readback the tool then refuses.
|
|
9
|
+
* - **`preview`** writes the approval's display copy: what the card shows, the
|
|
10
|
+
* readback a conversation channel reads or sends, and the readback a voice
|
|
11
|
+
* speaks. A host redacts a value there (an account number, a phone number),
|
|
12
|
+
* or writes it in the person's language, with dates, times and numbers as
|
|
13
|
+
* words. The call that runs is still exactly the model's: the approval store
|
|
14
|
+
* keeps the original arguments, and the args hash it is bound to is theirs.
|
|
15
|
+
* Only the preview stored with it, sent to the room and spoken is the
|
|
16
|
+
* host's.
|
|
17
|
+
*
|
|
18
|
+
* Both fail closed. A validator that throws refuses the call; a preview hook
|
|
19
|
+
* that throws, or returns something that is not a preview, means the approval
|
|
20
|
+
* cannot be asked for, so the call is not run. Falling back to the built
|
|
21
|
+
* preview would show the very values a redacting host removed.
|
|
22
|
+
*/
|
|
23
|
+
import { APPROVAL_PREVIEW_LIMITS as L } from '@ouispec/agent-core';
|
|
24
|
+
/** The longest refusal a validator's error is given to the model as. */
|
|
25
|
+
export const MAX_VALIDATION_ERROR_CHARS = 2_000;
|
|
26
|
+
/** A validator's answer as the orchestrator acts on it: refused with the model's reason, or not. */
|
|
27
|
+
export function readValidation(value) {
|
|
28
|
+
if (value && typeof value === 'object' && value.ok === true)
|
|
29
|
+
return { ok: true };
|
|
30
|
+
const error = value && typeof value === 'object' ? value.error : undefined;
|
|
31
|
+
if (value && typeof value === 'object' && value.ok === false && typeof error === 'string' && error.trim()) {
|
|
32
|
+
return { ok: false, error: error.trim().slice(0, MAX_VALIDATION_ERROR_CHARS) };
|
|
33
|
+
}
|
|
34
|
+
return { ok: false, error: 'It could not be checked, so it was not asked for.' };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A host's preview, checked against what the approval store accepts: the
|
|
38
|
+
* preview, or why it is not one.
|
|
39
|
+
*/
|
|
40
|
+
export function readHostPreview(value) {
|
|
41
|
+
const refuse = (error) => ({ ok: false, error });
|
|
42
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
43
|
+
return refuse('it is not an object');
|
|
44
|
+
const v = value;
|
|
45
|
+
const text = (field, max, required, nonBlank = false) => {
|
|
46
|
+
const s = v[field];
|
|
47
|
+
if (s === undefined && !required)
|
|
48
|
+
return null;
|
|
49
|
+
if (typeof s !== 'string')
|
|
50
|
+
return `${field} must be a string`;
|
|
51
|
+
if (s.length > max)
|
|
52
|
+
return `${field} is longer than ${max} characters`;
|
|
53
|
+
if (nonBlank && !s.trim())
|
|
54
|
+
return `${field} is blank`;
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
const problem = text('title', L.title, true, true) ??
|
|
58
|
+
text('consequence', L.consequence, false) ??
|
|
59
|
+
text('readback', L.readback, true, true) ??
|
|
60
|
+
text('spokenReadback', L.readback, false, true);
|
|
61
|
+
if (problem)
|
|
62
|
+
return refuse(problem);
|
|
63
|
+
const args = v.arguments;
|
|
64
|
+
if (!Array.isArray(args))
|
|
65
|
+
return refuse('arguments must be a list');
|
|
66
|
+
if (args.length > L.arguments)
|
|
67
|
+
return refuse(`arguments holds more than ${L.arguments} entries`);
|
|
68
|
+
for (const [i, a] of args.entries()) {
|
|
69
|
+
const entry = a;
|
|
70
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
71
|
+
return refuse(`arguments[${i}] is not an object`);
|
|
72
|
+
if (typeof entry.name !== 'string' || !entry.name || entry.name.length > L.argumentName)
|
|
73
|
+
return refuse(`arguments[${i}].name must be 1–${L.argumentName} characters`);
|
|
74
|
+
if (typeof entry.label !== 'string' || !entry.label || entry.label.length > L.argumentLabel)
|
|
75
|
+
return refuse(`arguments[${i}].label must be 1–${L.argumentLabel} characters`);
|
|
76
|
+
if (typeof entry.value !== 'string' || entry.value.length > L.argumentValue)
|
|
77
|
+
return refuse(`arguments[${i}].value must be a string of at most ${L.argumentValue} characters`);
|
|
78
|
+
}
|
|
79
|
+
const known = new Set(['title', 'consequence', 'arguments', 'readback', 'spokenReadback']);
|
|
80
|
+
const unknown = Object.keys(v).filter((k) => !known.has(k));
|
|
81
|
+
if (unknown.length > 0)
|
|
82
|
+
return refuse(`it has fields a preview does not: ${unknown.join(', ')}`);
|
|
83
|
+
return {
|
|
84
|
+
ok: true,
|
|
85
|
+
preview: {
|
|
86
|
+
title: v.title,
|
|
87
|
+
...(typeof v.consequence === 'string' ? { consequence: v.consequence } : {}),
|
|
88
|
+
arguments: args.map((a) => ({ name: a.name, label: a.label, value: a.value })),
|
|
89
|
+
readback: v.readback,
|
|
90
|
+
...(typeof v.spokenReadback === 'string' ? { spokenReadback: v.spokenReadback } : {}),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/approvals/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,uBAAuB,IAAI,CAAC,EAAwB,MAAM,qBAAqB,CAAC;AAsDzF,wEAAwE;AACxE,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAC;AAEhD,oGAAoG;AACpG,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAK,KAA0B,CAAC,EAAE,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EA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C,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;YACjH,QAAQ,EAAE,CAAC,CAAC,QAAkB;YAC9B,GAAG,CAAC,OAAO,CAAC,CAAC,cAAc,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/container/server.js
CHANGED
|
@@ -95,7 +95,7 @@ export async function startContainerAgentWorker(config) {
|
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
const busy = slots.take(payload.turnId, () => runner
|
|
98
|
-
.run(payload)
|
|
98
|
+
.run(payload, { channel: 'container' })
|
|
99
99
|
.then((outcome) => config.onTurnEnd?.(outcome))
|
|
100
100
|
.catch((err) => {
|
|
101
101
|
// A turn's own failure is an outcome, not a throw; this is the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/container/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAoB,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAA4B,MAAM,yBAAyB,CAAC;AAQlF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AA8BzD,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAM,MAAiC;IACpF,MAAM,OAAO,GAAG;QACd,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,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AAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YAC9B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC5B,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,IAAI,EAAG,MAAM,CAAC,OAAO,EAAkB,CAAC,IAAI;QAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE;QAC9B,KAAK,CAAC,KAAK;YACT,OAAO,GAAG,IAAI,CAAC;YACf,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;YACpB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACtE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,SAAS,MAAM,CAAC,GAAuB;IACrC,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,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's filter on a turn's events: what leaves the runtime, decided by
|
|
3
|
+
* the host before anything else sees it.
|
|
4
|
+
*
|
|
5
|
+
* A turn's events go to its realtime room, and to a host that observes them
|
|
6
|
+
* (the live-call handler speaks the reply from them, emit/tee.ts). A host that
|
|
7
|
+
* must redact what a turn sends (a card number in a tool call's input, a
|
|
8
|
+
* phone number in a readback) or hold some of it back filters here, once:
|
|
9
|
+
* the room, the observer and the call all receive what the filter returns,
|
|
10
|
+
* and nothing receives what it drops.
|
|
11
|
+
*
|
|
12
|
+
* The filter is synchronous, so events keep the order the turn emitted them
|
|
13
|
+
* in. It is given a copy of each payload, so what it changes reaches no other
|
|
14
|
+
* part of the turn. A filter that throws, or returns something that is not a
|
|
15
|
+
* payload, fails closed: the event is dropped and the failure logged. A
|
|
16
|
+
* redaction that fails must never send what it was there to remove.
|
|
17
|
+
*/
|
|
18
|
+
import type { RealtimeEmitAdapter } from './types.js';
|
|
19
|
+
/** Decides what of one turn event leaves the runtime: the payload to send, changed or not, or null to send nothing. */
|
|
20
|
+
export type TurnEventFilter = (event: string, data: Record<string, unknown>) => Record<string, unknown> | null;
|
|
21
|
+
/** `adapter`, sending each event as `filter` returns it, and nothing it drops. */
|
|
22
|
+
export declare function filterEmitAdapter(adapter: RealtimeEmitAdapter, filter: TurnEventFilter, onFilterError: (error: unknown, event: string) => void): RealtimeEmitAdapter;
|
|
23
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/emit/filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,uHAAuH;AACvH,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;AAE/G,kFAAkF;AAClF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,eAAe,EACvB,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GACrD,mBAAmB,CAmBrB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** `adapter`, sending each event as `filter` returns it, and nothing it drops. */
|
|
2
|
+
export function filterEmitAdapter(adapter, filter, onFilterError) {
|
|
3
|
+
return {
|
|
4
|
+
emit(room, event, data) {
|
|
5
|
+
let kept;
|
|
6
|
+
try {
|
|
7
|
+
// Every turn event's payload is a JSON object.
|
|
8
|
+
kept = filter(event, structuredClone(data));
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
onFilterError(error, event);
|
|
12
|
+
return Promise.resolve();
|
|
13
|
+
}
|
|
14
|
+
if (kept === null)
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
if (!isPayload(kept)) {
|
|
17
|
+
onFilterError(new Error(`the filter returned ${kept === undefined ? 'undefined' : typeof kept}, not a payload or null`), event);
|
|
18
|
+
return Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
return adapter.emit(room, event, kept);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function isPayload(value) {
|
|
25
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../src/emit/filter.ts"],"names":[],"mappings":"AAsBA,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAC/B,OAA4B,EAC5B,MAAuB,EACvB,aAAsD;IAEtD,OAAO;QACL,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI;YACpB,IAAI,IAAa,CAAC;YAClB,IAAI,CAAC;gBACH,+CAA+C;gBAC/C,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,eAAe,CAAC,IAAI,CAA4B,CAAC,CAAC;YACzE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAC5B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC;YACD,IAAI,IAAI,KAAK,IAAI;gBAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAC5C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,aAAa,CAAC,IAAI,KAAK,CAAC,uBAAuB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,IAAI,yBAAyB,CAAC,EAAE,KAAK,CAAC,CAAC;gBAChI,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAC3B,CAAC;YACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export type { AgentWorkerConfig, AgentTurnInput, AgentTurnResult, TurnMessage, TurnHistoryMessage, ToolCallRef, SystemPromptContext } from './types.js';
|
|
10
10
|
export type { RealtimeEmitAdapter } from './emit/types.js';
|
|
11
|
+
export { filterEmitAdapter } from './emit/filter.js';
|
|
12
|
+
export type { TurnEventFilter } from './emit/filter.js';
|
|
11
13
|
export type { ToolRegistry, RegisteredTool, ToolExecutionResult, ToolExecutionContext } from './tools/types.js';
|
|
12
14
|
export { createToolRegistry } from './tools/types.js';
|
|
13
15
|
export { loadToolsFromSchema } from './tools/schema-loader.js';
|
|
@@ -31,6 +33,8 @@ export type { ApprovalStoreClient, HttpApprovalStoreClientConfig } from './appro
|
|
|
31
33
|
export { approvalRequirement, APPROVAL_TOOL_NOTE } from './approvals/requirement.js';
|
|
32
34
|
export type { ApprovalRequirement } from './approvals/requirement.js';
|
|
33
35
|
export { buildApprovalPreview } from './approvals/preview.js';
|
|
36
|
+
export { readHostPreview, readValidation, MAX_VALIDATION_ERROR_CHARS } from './approvals/hooks.js';
|
|
37
|
+
export type { ApprovalHookContext, ApprovalPreviewContext, ApprovalPreviewHook, ApprovalValidation, ValidateBeforeApproval, ApprovalHooks, } from './approvals/hooks.js';
|
|
34
38
|
export { createHttpTurnStopClient, watchTurnStop, withLocalStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
35
39
|
export type { TurnStopClient, HttpTurnStopClientConfig, TurnStopWatch, TurnStopState } from './stop/turn-stop.js';
|
|
36
40
|
export { stoppedTurnMessages } from './stop/partial.js';
|
|
@@ -65,13 +69,15 @@ export type { TurnEventObserver } from './emit/tee.js';
|
|
|
65
69
|
export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
|
|
66
70
|
export type { AgentTurnRunner, TurnHost, TurnOutcome, CategorizedError } from './runtime/turn-runner.js';
|
|
67
71
|
export { assertAgentRuntimeConfig } from './runtime/config.js';
|
|
72
|
+
export { turnInfoOf, DEFAULT_TURN_CHANNEL } from './runtime/turn-info.js';
|
|
73
|
+
export type { AgentTurnInfo, AgentTurnChannel, AgentTurnInputMode } from './runtime/turn-info.js';
|
|
68
74
|
export type { AgentRuntimeConfig, LambdaAgentConfig, AgentTurnPayload, HistoryRequest, TurnHistory } from './runtime/types.js';
|
|
69
75
|
export { createLambdaAgentHandler } from './lambda/handler.js';
|
|
70
76
|
export { startContainerAgentWorker, DEFAULT_LIVE_CALL_PATH } from './container/server.js';
|
|
71
77
|
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';
|
|
78
|
+
export { createLiveCallTurnHandler, LIVE_CALL_SPEECH, LIVE_CALL_CHANNEL } from './live-call/handler.js';
|
|
79
|
+
export type { LiveCallSpeech, LiveCallTurnHandler, LiveCallTurnHandlerConfig, LiveCallTurnOptions, LiveCallTurnTarget, LiveCallTurnCallContext, } from './live-call/handler.js';
|
|
80
|
+
export { readLiveCallTurnRequest, liveCallError, LIVE_CALL_TURN_KINDS, LIVE_CALL_OPENING_MESSAGE, liveCallOpeningMessage, LIVE_CALL_TYPED_INPUT_MODE, LIVE_CALL_LIMITS, LIVE_CALL_ERROR_MESSAGES, } from './live-call/protocol.js';
|
|
75
81
|
export type { LiveCallTurnKind, LiveCallTurnRequest, LiveCallStreamEvents, LiveCallStreamEventName, LiveCallRequestReading, } from './live-call/protocol.js';
|
|
76
82
|
export { DEFAULT_KEEP_ALIVE_MS as LIVE_CALL_KEEP_ALIVE_MS } from './live-call/event-stream.js';
|
|
77
83
|
export { buildAgentSystemPrompt } 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,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACxJ,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,Y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AACjC,OAAO,EAAE,qBAAqB,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* The worker handles: the multi-round tool loop, UI actions, streaming,
|
|
7
7
|
* retries and timeouts, on Lambda + SQS or in a container.
|
|
8
8
|
*/
|
|
9
|
+
export { filterEmitAdapter } from './emit/filter.js';
|
|
9
10
|
export { createToolRegistry } from './tools/types.js';
|
|
10
11
|
export { loadToolsFromSchema } from './tools/schema-loader.js';
|
|
11
12
|
// Async tools wait on the product's declared events
|
|
@@ -24,6 +25,8 @@ export { defaultToolPolicy, evaluateToolPolicySafe } from './authz/tool-policy.j
|
|
|
24
25
|
export { createHttpApprovalStoreClient } from './approvals/client.js';
|
|
25
26
|
export { approvalRequirement, APPROVAL_TOOL_NOTE } from './approvals/requirement.js';
|
|
26
27
|
export { buildApprovalPreview } from './approvals/preview.js';
|
|
28
|
+
// The host's say before an approval is asked for: a check, and the display copy.
|
|
29
|
+
export { readHostPreview, readValidation, MAX_VALIDATION_ERROR_CHARS } from './approvals/hooks.js';
|
|
27
30
|
// Stopping a turn: the person's Stop, or a newer message that
|
|
28
31
|
// supersedes the turn, is kept by the realtime server and asked for by the
|
|
29
32
|
// turn. What the turn had produced is stored, then announced.
|
|
@@ -52,12 +55,13 @@ export { teeEmitAdapter } from './emit/tee.js';
|
|
|
52
55
|
// The runtime: one core, two host adapters (Lambda + SQS, container)
|
|
53
56
|
export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
|
|
54
57
|
export { assertAgentRuntimeConfig } from './runtime/config.js';
|
|
58
|
+
export { turnInfoOf, DEFAULT_TURN_CHANNEL } from './runtime/turn-info.js';
|
|
55
59
|
export { createLambdaAgentHandler } from './lambda/handler.js';
|
|
56
60
|
export { startContainerAgentWorker, DEFAULT_LIVE_CALL_PATH } from './container/server.js';
|
|
57
61
|
// Live calls: the call service's turns, answered by the product's own agent as
|
|
58
62
|
// 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';
|
|
63
|
+
export { createLiveCallTurnHandler, LIVE_CALL_SPEECH, LIVE_CALL_CHANNEL } from './live-call/handler.js';
|
|
64
|
+
export { readLiveCallTurnRequest, liveCallError, LIVE_CALL_TURN_KINDS, LIVE_CALL_OPENING_MESSAGE, liveCallOpeningMessage, LIVE_CALL_TYPED_INPUT_MODE, LIVE_CALL_LIMITS, LIVE_CALL_ERROR_MESSAGES, } from './live-call/protocol.js';
|
|
61
65
|
export { DEFAULT_KEEP_ALIVE_MS as LIVE_CALL_KEEP_ALIVE_MS } from './live-call/event-stream.js';
|
|
62
66
|
// Prompt Framework
|
|
63
67
|
export { buildAgentSystemPrompt } 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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,iBAAiB,EAAE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qBAAqB,CAAC;AAE/E;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,IAG5D,OAAO,QAAQ,EAAE,UAAU,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/lambda/handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE/E;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,IAG5D,OAAO,QAAQ,EAAE,UAAU,OAAO,KAAG,OAAO,CAAC,IAAI,CAAC,CAgBjE;AAED,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/lambda/handler.js
CHANGED
|
@@ -19,7 +19,10 @@ export function createLambdaAgentHandler(config) {
|
|
|
19
19
|
if (refusal)
|
|
20
20
|
throw new Error(`[agent-sdk] ${refusal}`);
|
|
21
21
|
// A stopped turn stores and announces within what the invocation has left.
|
|
22
|
-
const outcome = await runner.run(payload,
|
|
22
|
+
const outcome = await runner.run(payload, {
|
|
23
|
+
channel: 'lambda',
|
|
24
|
+
...(context ? { remainingMs: () => context.getRemainingTimeInMillis() } : {}),
|
|
25
|
+
});
|
|
23
26
|
if (outcome.status === 'failed' && !outcome.error.recoverable)
|
|
24
27
|
throw outcome.cause;
|
|
25
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/lambda/handler.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MA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