@ouispec/agent-worker 0.14.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 +123 -6
- 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/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.d.ts +14 -0
- package/dist/container/server.d.ts.map +1 -1
- package/dist/container/server.js +36 -17
- 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/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 +17 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -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/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 +153 -0
- package/dist/live-call/handler.d.ts.map +1 -0
- package/dist/live-call/handler.js +416 -0
- package/dist/live-call/handler.js.map +1 -0
- package/dist/live-call/protocol.d.ts +157 -0
- package/dist/live-call/protocol.d.ts.map +1 -0
- package/dist/live-call/protocol.js +168 -0
- package/dist/live-call/protocol.js.map +1 -0
- package/dist/orchestrator.d.ts +5 -0
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +167 -33
- 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 +28 -0
- package/dist/prompt/spoken-reply.d.ts.map +1 -0
- package/dist/prompt/spoken-reply.js +49 -0
- package/dist/prompt/spoken-reply.js.map +1 -0
- 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 +42 -5
- package/dist/runtime/turn-runner.d.ts.map +1 -1
- package/dist/runtime/turn-runner.js +148 -36
- 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/runtime/types.d.ts +45 -4
- package/dist/runtime/types.d.ts.map +1 -1
- 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/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/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 +5 -5
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live-call turn handler: one route a product mounts so that the
|
|
3
|
+
* service running a live call reaches the product's own agent.
|
|
4
|
+
*
|
|
5
|
+
* Each request is one turn (protocol.ts). The handler checks the bearer
|
|
6
|
+
* credential, asks the host which conversation, user and realtime room the
|
|
7
|
+
* call's `clientRef` is, and runs the turn on the same runtime as every other
|
|
8
|
+
* turn (runtime/turn-runner.ts). So the turn still streams to the
|
|
9
|
+
* conversation's room, and every page joined to it receives the reply and
|
|
10
|
+
* every UI action, as for a typed message. The handler sees the turn's events
|
|
11
|
+
* as the room does (emit/tee.ts) and writes the reply's text, an approval's
|
|
12
|
+
* readback and the turn's end to the response as server-sent events: one
|
|
13
|
+
* stream of events, two destinations, no second model call.
|
|
14
|
+
*
|
|
15
|
+
* A closed connection is the call service's barge-in: the person spoke over
|
|
16
|
+
* the reply. The turn is stopped as a superseding message stops it, and the
|
|
17
|
+
* next request names it in `supersedes`.
|
|
18
|
+
*
|
|
19
|
+
* What the caller hears is the host's to choose (`speak`): every round of the
|
|
20
|
+
* reply as the model writes it (`all`, the default), or only the round the turn
|
|
21
|
+
* ends with (`final-round`), so nothing the model wrote before a tool call is
|
|
22
|
+
* spoken, save a holding line of the host's own while a tool runs.
|
|
23
|
+
*
|
|
24
|
+
* POST <path> 200 text/event-stream the turn
|
|
25
|
+
* 400 not a turn · 401 wrong credential · 404 unknown clientRef
|
|
26
|
+
* 405 not POST · 409 turn already running · 413 too large
|
|
27
|
+
* 415 not JSON · 500 the host's resolver failed · 503 at capacity or closing
|
|
28
|
+
*/
|
|
29
|
+
import crypto from 'node:crypto';
|
|
30
|
+
import { AGENT_SOCKET_EVENTS, MESSAGE_INPUT_CONTEXT_KEY, REPLY_OUTPUT_CONTEXT_KEY, } from '@ouispec/agent-core';
|
|
31
|
+
import { payloadRefusal } from '../runtime/turn-runner.js';
|
|
32
|
+
import { USER_INPUT_TOOLS } from '../orchestrator.js';
|
|
33
|
+
import { createTurnSlots } from '../runtime/turn-slots.js';
|
|
34
|
+
import { DEFAULT_KEEP_ALIVE_MS, openLiveCallEventStream } from './event-stream.js';
|
|
35
|
+
import { liveCallError, liveCallOpeningMessage, readLiveCallTurnRequest } from './protocol.js';
|
|
36
|
+
/** What of a live-call turn's reply is spoken (`LiveCallTurnOptions.speak`). */
|
|
37
|
+
export const LIVE_CALL_SPEECH = ['all', 'final-round'];
|
|
38
|
+
const DEFAULT_MAX_BODY_BYTES = 64 * 1024;
|
|
39
|
+
/**
|
|
40
|
+
* Creates the live-call turn handler.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* const runner = createAgentTurnRunner(runtimeConfig);
|
|
45
|
+
* const liveCall = createLiveCallTurnHandler({
|
|
46
|
+
* runner,
|
|
47
|
+
* credential: env.LIVE_CALL_BRAIN_CREDENTIAL,
|
|
48
|
+
* resolveTurn: async (request) => {
|
|
49
|
+
* const conversation = await db.conversation.findUnique({ where: { callRef: request.clientRef } });
|
|
50
|
+
* if (!conversation) return null;
|
|
51
|
+
* await db.message.create({ data: { conversationId: conversation.id, role: 'user', content: request.text, input: request.input } });
|
|
52
|
+
* return { conversationId: conversation.id, userId: conversation.userId, accountId: conversation.accountId, socketRoom: `conversation:${conversation.id}` };
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* app.post('/agent/live-call/turns', liveCall);
|
|
56
|
+
* process.on('SIGTERM', () => liveCall.close());
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function createLiveCallTurnHandler(config) {
|
|
60
|
+
if (!config?.runner || typeof config.runner.run !== 'function' || typeof config.runner.reply !== 'function') {
|
|
61
|
+
throw new Error('[agent-sdk] Missing required configuration: runner (createAgentTurnRunner(config))');
|
|
62
|
+
}
|
|
63
|
+
const slots = createTurnSlots(config.maxConcurrentTurns ?? 8);
|
|
64
|
+
const handle = liveCallRoute(config, {
|
|
65
|
+
runner: config.runner,
|
|
66
|
+
slots,
|
|
67
|
+
maxBodyBytes: config.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES,
|
|
68
|
+
onTurnEnd: config.onTurnEnd,
|
|
69
|
+
});
|
|
70
|
+
return Object.assign((req, res) => handle(req, res), {
|
|
71
|
+
running: () => slots.running(),
|
|
72
|
+
close: () => slots.drain(),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The route, for a host that already runs turns (the container adapter): it
|
|
77
|
+
* shares that host's runtime and slots.
|
|
78
|
+
*/
|
|
79
|
+
export function liveCallRoute(options, host) {
|
|
80
|
+
const credentials = (typeof options?.credential === 'string' ? [options.credential] : [...(options?.credential ?? [])]).filter((c) => typeof c === 'string' && c.length > 0);
|
|
81
|
+
const missing = [
|
|
82
|
+
credentials.length === 0 && 'credential (the bearer credential the call service sends)',
|
|
83
|
+
typeof options?.resolveTurn !== 'function' && 'resolveTurn (the call’s clientRef → its conversation, user and room)',
|
|
84
|
+
].filter(Boolean);
|
|
85
|
+
if (missing.length > 0)
|
|
86
|
+
throw new Error(`[agent-sdk] Missing required configuration for the live-call route: ${missing.join('; ')}`);
|
|
87
|
+
const keepAliveMs = options.keepAliveMs ?? DEFAULT_KEEP_ALIVE_MS;
|
|
88
|
+
if (!(Number.isFinite(keepAliveMs) && keepAliveMs > 0))
|
|
89
|
+
throw new Error(`[agent-sdk] keepAliveMs must be a positive number of ms, not ${keepAliveMs}`);
|
|
90
|
+
const speak = options.speak ?? 'all';
|
|
91
|
+
if (!LIVE_CALL_SPEECH.includes(speak)) {
|
|
92
|
+
throw new Error(`[agent-sdk] speak must be one of ${LIVE_CALL_SPEECH.join(', ')}, not ${JSON.stringify(speak)}`);
|
|
93
|
+
}
|
|
94
|
+
if (options.holdingLine !== undefined && speak !== 'final-round') {
|
|
95
|
+
throw new Error("[agent-sdk] holdingLine is spoken only with speak: 'final-round'; with 'all' the model's own words before a tool call are spoken");
|
|
96
|
+
}
|
|
97
|
+
if (options.holdingLine !== undefined && typeof options.holdingLine !== 'string' && typeof options.holdingLine !== 'function') {
|
|
98
|
+
throw new Error('[agent-sdk] holdingLine must be a string or a function');
|
|
99
|
+
}
|
|
100
|
+
const { runner, slots, maxBodyBytes } = host;
|
|
101
|
+
const logger = runner.logger;
|
|
102
|
+
// Compared as digests: equal length whatever was presented, so the comparison takes the same time.
|
|
103
|
+
const expected = credentials.map(digest);
|
|
104
|
+
const isCredential = (header) => {
|
|
105
|
+
const presented = /^Bearer[ ]+(\S+)\s*$/i.exec(header ?? '')?.[1];
|
|
106
|
+
if (!presented)
|
|
107
|
+
return false;
|
|
108
|
+
const given = digest(presented);
|
|
109
|
+
// Every credential is compared, matched or not.
|
|
110
|
+
return expected.map((e) => crypto.timingSafeEqual(given, e)).includes(true);
|
|
111
|
+
};
|
|
112
|
+
/** The hang-up of each running live-call turn, by turn id: a newer turn that supersedes one stops it here at once. */
|
|
113
|
+
const hangUps = new Map();
|
|
114
|
+
return (req, res) => {
|
|
115
|
+
if (req.method !== 'POST') {
|
|
116
|
+
res.setHeader('allow', 'POST');
|
|
117
|
+
refuse(res, 405, 'METHOD_NOT_ALLOWED', 'Use POST');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!isCredential(req.headers.authorization)) {
|
|
121
|
+
res.setHeader('www-authenticate', 'Bearer');
|
|
122
|
+
refuse(res, 401, 'UNAUTHORIZED', 'Invalid or missing credential');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const type = req.headers['content-type'];
|
|
126
|
+
if (type && !/^application\/json\s*(;|$)/i.test(type)) {
|
|
127
|
+
refuse(res, 415, 'UNSUPPORTED_MEDIA_TYPE', 'The body must be application/json');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
void readJsonBody(req, maxBodyBytes).then((body) => {
|
|
131
|
+
if (res.writableEnded)
|
|
132
|
+
return;
|
|
133
|
+
if (body.status !== 'ok') {
|
|
134
|
+
if (body.status === 'too_large')
|
|
135
|
+
refuse(res, 413, 'BODY_TOO_LARGE', `The body is larger than ${maxBodyBytes} bytes`);
|
|
136
|
+
else
|
|
137
|
+
refuse(res, 400, 'INVALID_REQUEST', 'The body is not JSON');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const reading = readLiveCallTurnRequest(body.value);
|
|
141
|
+
if (!reading.ok) {
|
|
142
|
+
refuse(res, 400, 'INVALID_REQUEST', reading.error);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const request = reading.request;
|
|
146
|
+
// The turns this one replaces stop now, if they still run here: their connections closed, or are closing.
|
|
147
|
+
for (const id of request.supersedes)
|
|
148
|
+
hangUps.get(id)?.abort('superseded');
|
|
149
|
+
const refusal = slots.take(request.turnId, () => serve(request, res));
|
|
150
|
+
if (refusal)
|
|
151
|
+
refuse(res, refusal.status, refusal.status === 409 ? 'TURN_RUNNING' : 'UNAVAILABLE', refusal.error);
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
async function serve(request, res) {
|
|
155
|
+
const { turnId } = request;
|
|
156
|
+
const hangUp = new AbortController();
|
|
157
|
+
// The caller closed the connection before the turn's answer ended: it stops the turn.
|
|
158
|
+
const onClose = () => {
|
|
159
|
+
if (!res.writableEnded)
|
|
160
|
+
hangUp.abort('superseded');
|
|
161
|
+
};
|
|
162
|
+
res.once('close', onClose);
|
|
163
|
+
hangUps.set(turnId, hangUp);
|
|
164
|
+
const call = { signal: hangUp.signal };
|
|
165
|
+
try {
|
|
166
|
+
let target;
|
|
167
|
+
try {
|
|
168
|
+
target = await options.resolveTurn(request, call);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
logger.error('[agent-sdk] The live-call turn could not be resolved; nothing was run', {
|
|
172
|
+
turnId,
|
|
173
|
+
sessionId: request.sessionId,
|
|
174
|
+
error: messageOf(error),
|
|
175
|
+
});
|
|
176
|
+
refuse(res, 500, 'RESOLVE_FAILED', 'The turn could not be resolved');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (!target) {
|
|
180
|
+
refuse(res, 404, 'UNKNOWN_CLIENT_REF', 'No conversation for this clientRef');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const payload = turnPayload(request, target);
|
|
184
|
+
const invalid = target.content !== undefined && typeof target.content !== 'string' ? 'content must be a string' : payloadRefusal(payload);
|
|
185
|
+
if (invalid) {
|
|
186
|
+
logger.error('[agent-sdk] resolveTurn answered a turn that cannot run; nothing was run', { turnId, error: invalid });
|
|
187
|
+
refuse(res, 500, 'RESOLVE_FAILED', 'The turn could not be resolved');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const stream = openLiveCallEventStream(res, keepAliveMs);
|
|
191
|
+
const relay = relayTurn(turnId, stream, speak);
|
|
192
|
+
logger.info('[agent-sdk] Live-call turn', {
|
|
193
|
+
turnId,
|
|
194
|
+
sessionId: request.sessionId,
|
|
195
|
+
kind: request.kind,
|
|
196
|
+
conversationId: target.conversationId,
|
|
197
|
+
...(request.supersedes.length ? { supersedes: request.supersedes } : {}),
|
|
198
|
+
});
|
|
199
|
+
let outcome;
|
|
200
|
+
try {
|
|
201
|
+
const greeting = request.kind === 'opening' && options.opening ? (await options.opening(request, target, call))?.trim() : null;
|
|
202
|
+
const holding = typeof options.holdingLine === 'function' ? await options.holdingLine(request, target) : options.holdingLine;
|
|
203
|
+
if (typeof holding === 'string' && holding.trim())
|
|
204
|
+
relay.holdWith(holding.trim());
|
|
205
|
+
// A caller already gone gets no greeting: the turn stops before it starts, and stores only that.
|
|
206
|
+
outcome = greeting && !hangUp.signal.aborted
|
|
207
|
+
? await runner.reply(payload, greeting, { observe: relay.observe, channel: LIVE_CALL_CHANNEL })
|
|
208
|
+
: await runner.run(payload, { observe: relay.observe, stopSignal: hangUp.signal, channel: LIVE_CALL_CHANNEL });
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
// A turn's own failure is an outcome; this is the host's opening template, or the runtime around the turn.
|
|
212
|
+
logger.error('[agent-sdk] The live-call turn could not run', { turnId, error: messageOf(error) });
|
|
213
|
+
outcome = { status: 'failed', turnId, error: { code: 'WORKER_ERROR', message: messageOf(error), recoverable: false }, cause: error };
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
host.onTurnEnd?.(outcome);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
logger.warn('[agent-sdk] onTurnEnd threw', { turnId, error: messageOf(error) });
|
|
220
|
+
}
|
|
221
|
+
if (outcome.status === 'failed')
|
|
222
|
+
stream.send('error', liveCallError(outcome.error.code));
|
|
223
|
+
else if (outcome.status === 'refused')
|
|
224
|
+
stream.send('error', liveCallError(outcome.refusedBy === 'beforeTurn' ? 'TURN_DECLINED' : 'TURN_REFUSED'));
|
|
225
|
+
else if (outcome.status === 'stopped' && outcome.stored === false)
|
|
226
|
+
stream.send('error', liveCallError('TURN_DEADLINE_EXCEEDED'));
|
|
227
|
+
else
|
|
228
|
+
stream.send('done', relay.ended() ?? (outcome.status === 'stopped' ? { stopReason: outcome.stopReason } : {}));
|
|
229
|
+
stream.end();
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
res.off('close', onClose);
|
|
233
|
+
if (hangUps.get(turnId) === hangUp)
|
|
234
|
+
hangUps.delete(turnId);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** The turn as the runtime takes it: the host's target, and what the request says. */
|
|
239
|
+
function turnPayload(request, target) {
|
|
240
|
+
const context = { ...(target.context ?? {}) };
|
|
241
|
+
// How the message was entered and how the reply reaches the person are the request's to say.
|
|
242
|
+
delete context[MESSAGE_INPUT_CONTEXT_KEY];
|
|
243
|
+
delete context[REPLY_OUTPUT_CONTEXT_KEY];
|
|
244
|
+
if (request.input)
|
|
245
|
+
context[MESSAGE_INPUT_CONTEXT_KEY] = request.input;
|
|
246
|
+
if (request.output)
|
|
247
|
+
context[REPLY_OUTPUT_CONTEXT_KEY] = request.output;
|
|
248
|
+
return {
|
|
249
|
+
turnId: request.turnId,
|
|
250
|
+
conversationId: target.conversationId,
|
|
251
|
+
userId: target.userId,
|
|
252
|
+
accountId: target.accountId,
|
|
253
|
+
socketRoom: target.socketRoom,
|
|
254
|
+
content: target.content ?? (request.kind === 'opening' ? liveCallOpeningMessage(request) : request.text),
|
|
255
|
+
context,
|
|
256
|
+
...(target.userToken ? { userToken: target.userToken } : {}),
|
|
257
|
+
...(target.approval ? { approval: target.approval } : {}),
|
|
258
|
+
...(request.supersedes.length > 0 ? { supersedes: request.supersedes } : {}),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** The channel the live-call handler's turns run on, as the host's hooks are told. */
|
|
262
|
+
export const LIVE_CALL_CHANNEL = 'live-call';
|
|
263
|
+
/**
|
|
264
|
+
* The turn's events, as the response carries them: its text as `text`, an
|
|
265
|
+
* approval's readback as `readback`, and how it ended, for `done`.
|
|
266
|
+
*
|
|
267
|
+
* With `speak: 'all'` each piece of text is sent as it comes. With
|
|
268
|
+
* `final-round` a round's text is held until the round ends, and sent only
|
|
269
|
+
* when the round is final; the host's holding line, if any, is sent once as
|
|
270
|
+
* the turn's first tool starts, in place of what the model said before it.
|
|
271
|
+
*
|
|
272
|
+
* The readback is sent when the turn has ended, after every piece of its
|
|
273
|
+
* text: it is spoken after what the model said before the call. It is the
|
|
274
|
+
* preview's `spokenReadback` when the host wrote one, else its `readback`. A
|
|
275
|
+
* turn that was stopped instead withdrew its approval, so its readback is
|
|
276
|
+
* never sent.
|
|
277
|
+
*/
|
|
278
|
+
function relayTurn(turnId, stream, speak) {
|
|
279
|
+
let ended = null;
|
|
280
|
+
let readback = null;
|
|
281
|
+
/** The holding line, until it is said: once a turn. */
|
|
282
|
+
let holdingLine = null;
|
|
283
|
+
/** Whether any text has been sent: what follows is set off from it. */
|
|
284
|
+
let sent = false;
|
|
285
|
+
/** With `final-round`: the text of the round being written, until it ends. */
|
|
286
|
+
let held = null;
|
|
287
|
+
const send = (text) => {
|
|
288
|
+
stream.send('text', { text });
|
|
289
|
+
sent = true;
|
|
290
|
+
};
|
|
291
|
+
const ofTurn = (data) => !!data && typeof data === 'object' && data.turnId === turnId;
|
|
292
|
+
return {
|
|
293
|
+
holdWith(line) {
|
|
294
|
+
holdingLine = line;
|
|
295
|
+
},
|
|
296
|
+
observe(event, data) {
|
|
297
|
+
if (!ofTurn(data))
|
|
298
|
+
return;
|
|
299
|
+
switch (event) {
|
|
300
|
+
case AGENT_SOCKET_EVENTS.TOKEN: {
|
|
301
|
+
const text = data.text;
|
|
302
|
+
if (typeof text !== 'string' || !text)
|
|
303
|
+
return;
|
|
304
|
+
if (speak === 'all') {
|
|
305
|
+
send(text);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const step = typeof data.step === 'number' ? data.step : (held?.step ?? 0);
|
|
309
|
+
// A round that never announced its end is not the one being written now: it is not spoken.
|
|
310
|
+
if (held && held.step !== step)
|
|
311
|
+
held = null;
|
|
312
|
+
held = { step, text: (held?.text ?? '') + text };
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
case AGENT_SOCKET_EVENTS.ROUND_END: {
|
|
316
|
+
if (speak === 'all')
|
|
317
|
+
return;
|
|
318
|
+
const round = held && held.step === data.step ? held.text : '';
|
|
319
|
+
held = null;
|
|
320
|
+
if (data.final !== true)
|
|
321
|
+
return;
|
|
322
|
+
// The round the turn ends with; what was said before it (a holding line) is set off from it.
|
|
323
|
+
const text = sent ? `\n\n${round.trimStart()}` : round.trimStart();
|
|
324
|
+
if (round.trim())
|
|
325
|
+
send(text);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
case AGENT_SOCKET_EVENTS.TOOL_CALL_STARTED: {
|
|
329
|
+
// A tool that asks the person something (a choice) is the turn's end, not a wait.
|
|
330
|
+
const name = data.name;
|
|
331
|
+
if (holdingLine && !(typeof name === 'string' && USER_INPUT_TOOLS.includes(name))) {
|
|
332
|
+
send(sent ? `\n\n${holdingLine}` : holdingLine);
|
|
333
|
+
holdingLine = null;
|
|
334
|
+
}
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
case AGENT_SOCKET_EVENTS.APPROVAL_REQUIRED: {
|
|
338
|
+
const approval = data;
|
|
339
|
+
readback = {
|
|
340
|
+
approvalId: approval.approvalId,
|
|
341
|
+
text: approval.preview.spokenReadback ?? approval.preview.readback,
|
|
342
|
+
expiresAt: new Date(approval.expiresAt).toISOString(),
|
|
343
|
+
};
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
case AGENT_SOCKET_EVENTS.TURN_COMPLETE: {
|
|
347
|
+
if (readback && data.stopReason === undefined)
|
|
348
|
+
stream.send('readback', readback);
|
|
349
|
+
const reason = data.stopReason ?? data.endReason;
|
|
350
|
+
ended = typeof reason === 'string' ? { stopReason: reason } : {};
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
ended: () => ended,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* The request's JSON body. A body a framework has already parsed (Express's
|
|
360
|
+
* `json()`) is taken as it is.
|
|
361
|
+
*/
|
|
362
|
+
function readJsonBody(req, maxBytes) {
|
|
363
|
+
const parsed = req.body;
|
|
364
|
+
if (req.readableEnded && parsed !== undefined) {
|
|
365
|
+
if (typeof parsed === 'string' || Buffer.isBuffer(parsed))
|
|
366
|
+
return Promise.resolve(parseJson(String(parsed), maxBytes));
|
|
367
|
+
return Promise.resolve({ status: 'ok', value: parsed });
|
|
368
|
+
}
|
|
369
|
+
return new Promise((resolve) => {
|
|
370
|
+
let size = 0;
|
|
371
|
+
const chunks = [];
|
|
372
|
+
let done = false;
|
|
373
|
+
const finish = (reading) => {
|
|
374
|
+
if (done)
|
|
375
|
+
return;
|
|
376
|
+
done = true;
|
|
377
|
+
resolve(reading);
|
|
378
|
+
};
|
|
379
|
+
req.on('data', (chunk) => {
|
|
380
|
+
size += chunk.length;
|
|
381
|
+
// Past the limit, the rest is read and dropped, so the refusal can still be answered.
|
|
382
|
+
if (size > maxBytes) {
|
|
383
|
+
finish({ status: 'too_large' });
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (!done)
|
|
387
|
+
chunks.push(chunk);
|
|
388
|
+
});
|
|
389
|
+
req.on('end', () => finish(parseJson(Buffer.concat(chunks).toString('utf8'), maxBytes)));
|
|
390
|
+
req.on('error', () => finish({ status: 'not_json' }));
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function parseJson(text, maxBytes) {
|
|
394
|
+
if (Buffer.byteLength(text) > maxBytes)
|
|
395
|
+
return { status: 'too_large' };
|
|
396
|
+
try {
|
|
397
|
+
return { status: 'ok', value: JSON.parse(text) };
|
|
398
|
+
}
|
|
399
|
+
catch {
|
|
400
|
+
return { status: 'not_json' };
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/** A refusal before the stream opens: a status and `{ error: { code, message } }`. Nothing once the caller has gone. */
|
|
404
|
+
function refuse(res, status, code, message) {
|
|
405
|
+
if (res.headersSent || res.writableEnded || res.destroyed)
|
|
406
|
+
return;
|
|
407
|
+
res.writeHead(status, { 'content-type': 'application/json' });
|
|
408
|
+
res.end(JSON.stringify({ error: { code, message } }));
|
|
409
|
+
}
|
|
410
|
+
function digest(value) {
|
|
411
|
+
return crypto.createHash('sha256').update(value).digest();
|
|
412
|
+
}
|
|
413
|
+
function messageOf(err) {
|
|
414
|
+
return err instanceof Error ? err.message : String(err);
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/live-call/handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,wBAAwB,GAGzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAA0C,MAAM,2BAA2B,CAAC;AACnG,OAAO,EAAE,gBAAgB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AAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live-call turn: what the service running a call sends for each turn,
|
|
3
|
+
* and the event stream the agent answers with.
|
|
4
|
+
*
|
|
5
|
+
* The call service hears the person, transcribes them, and speaks the reply in
|
|
6
|
+
* the character's voice. The agent is the product's: it holds the
|
|
7
|
+
* conversation, its tools, its UI actions and its approvals. Each turn is one
|
|
8
|
+
* request:
|
|
9
|
+
*
|
|
10
|
+
* POST <the product's route>
|
|
11
|
+
* Authorization: Bearer <credential>
|
|
12
|
+
* Content-Type: application/json
|
|
13
|
+
* Accept: text/event-stream
|
|
14
|
+
*
|
|
15
|
+
* { sessionId, clientRef, turnId, kind, text, input?, output?, supersedes?, disclosureLine? }
|
|
16
|
+
*
|
|
17
|
+
* `input` is `{ mode: 'voice', language? }` for what the person said and
|
|
18
|
+
* `{ mode: 'text' }` for what they typed during the call. `output` is
|
|
19
|
+
* `{ mode: 'voice', voiceDirections? }` when a voice reads the reply out, with
|
|
20
|
+
* the tags that voice can be directed with. `disclosureLine`, on an `opening`
|
|
21
|
+
* turn, is what the call service has just said to the person before the
|
|
22
|
+
* agent's greeting (that they are talking with an AI assistant), as spoken.
|
|
23
|
+
*
|
|
24
|
+
* and the answer is `200 text/event-stream`:
|
|
25
|
+
*
|
|
26
|
+
* event: text data: { "text": "…" } the reply, piece by piece
|
|
27
|
+
* event: readback data: { "approvalId", "text", "expiresAt" } an approval's readback, verbatim
|
|
28
|
+
* event: done data: { "stopReason"?: "…" } the turn is over
|
|
29
|
+
* event: error data: { "code": "…", "message": "…" } the turn failed
|
|
30
|
+
*
|
|
31
|
+
* with `: keep-alive` comments while nothing else is sent.
|
|
32
|
+
*/
|
|
33
|
+
import { type MessageInput, type ReplyOutput } from '@ouispec/agent-core';
|
|
34
|
+
/** `message`: the person said `text`. `opening`: the call has just connected; nothing has been said, and the agent greets. */
|
|
35
|
+
export declare const LIVE_CALL_TURN_KINDS: readonly ["message", "opening"];
|
|
36
|
+
export type LiveCallTurnKind = (typeof LIVE_CALL_TURN_KINDS)[number];
|
|
37
|
+
/** A live-call turn request, as read: every field checked, `input` and `output` kept only as far as they are known. */
|
|
38
|
+
export interface LiveCallTurnRequest {
|
|
39
|
+
/** The call service's session. */
|
|
40
|
+
sessionId: string;
|
|
41
|
+
/** The product's own conversation reference, set when the call was created: the host resolves its conversation, user and room from it. */
|
|
42
|
+
clientRef: string;
|
|
43
|
+
/** Unique per turn; the turn runs under this id. */
|
|
44
|
+
turnId: string;
|
|
45
|
+
kind: LiveCallTurnKind;
|
|
46
|
+
/** What the person said, as transcribed. Empty for `opening`. */
|
|
47
|
+
text: string;
|
|
48
|
+
/**
|
|
49
|
+
* How `text` was entered: `{ mode: 'voice', language? }` for what the person
|
|
50
|
+
* said. Null for a message they typed during the call (`{ mode: 'text' }` on
|
|
51
|
+
* the wire), for `opening`, and when not said: a typed message is read as
|
|
52
|
+
* typed, with no spoken-input line.
|
|
53
|
+
*/
|
|
54
|
+
input: MessageInput | null;
|
|
55
|
+
/**
|
|
56
|
+
* How the reply reaches the person: `{ mode: 'voice' }` when a voice reads
|
|
57
|
+
* it out, with `voiceDirections` when that voice can be directed by inline
|
|
58
|
+
* tags (the model is told it may use them).
|
|
59
|
+
*/
|
|
60
|
+
output: ReplyOutput | null;
|
|
61
|
+
/** Turns this one replaces: the call service closed their streams because the person spoke again. */
|
|
62
|
+
supersedes: string[];
|
|
63
|
+
/**
|
|
64
|
+
* On an `opening` turn: what the call service has already said to the person
|
|
65
|
+
* before the agent greets them (its disclosure that they are talking with
|
|
66
|
+
* an AI assistant), as spoken. The model is told it was said, so its greeting
|
|
67
|
+
* follows on from it instead of repeating it. Null when none was sent, and on
|
|
68
|
+
* a `message` turn, where it is not read.
|
|
69
|
+
*/
|
|
70
|
+
disclosureLine: string | null;
|
|
71
|
+
}
|
|
72
|
+
/** The events of a live-call turn's response stream. */
|
|
73
|
+
export interface LiveCallStreamEvents {
|
|
74
|
+
/** A piece of the reply's text. Pieces are concatenated in order. */
|
|
75
|
+
text: {
|
|
76
|
+
text: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* The turn stopped at a call that needs the person's approval: `text` is its
|
|
80
|
+
* readback, built from the action's declaration, to be spoken verbatim after
|
|
81
|
+
* any text already sent. The person's next utterance comes as an ordinary
|
|
82
|
+
* `message`; the host decides whether it approves.
|
|
83
|
+
*/
|
|
84
|
+
readback: {
|
|
85
|
+
approvalId: string;
|
|
86
|
+
text: string;
|
|
87
|
+
expiresAt: string;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The turn is over. `stopReason` is how it ended: `complete`,
|
|
91
|
+
* `awaiting_approval`, `present_options`, `time_limit`, `output_limit` or
|
|
92
|
+
* `step_count` for a turn that ended by itself; `user_stop`, `superseded`
|
|
93
|
+
* or `deadline` (and any later stop reason) for one that was stopped.
|
|
94
|
+
*/
|
|
95
|
+
done: {
|
|
96
|
+
stopReason?: string;
|
|
97
|
+
};
|
|
98
|
+
/** The turn failed. `message` is a fixed line for the code; the cause is in the host's logs, never on the wire. */
|
|
99
|
+
error: {
|
|
100
|
+
code: string;
|
|
101
|
+
message: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export type LiveCallStreamEventName = keyof LiveCallStreamEvents;
|
|
105
|
+
/**
|
|
106
|
+
* The person's message for an `opening` turn: an instruction to greet, which
|
|
107
|
+
* the model reads where the person's words would be. A host that stores the
|
|
108
|
+
* person's messages stores this one for the opening turn, so the conversation
|
|
109
|
+
* keeps the turn the greeting answers.
|
|
110
|
+
*/
|
|
111
|
+
export declare const LIVE_CALL_OPENING_MESSAGE: string;
|
|
112
|
+
/**
|
|
113
|
+
* The person's message for an `opening` turn, as the model reads it: an
|
|
114
|
+
* instruction to greet, and, when the call service sent one, the disclosure
|
|
115
|
+
* it has just spoken, so the greeting follows on from it rather than repeating
|
|
116
|
+
* it. Without a disclosure it is `LIVE_CALL_OPENING_MESSAGE`. A host that
|
|
117
|
+
* stores the person's messages stores this for the opening turn.
|
|
118
|
+
*/
|
|
119
|
+
export declare function liveCallOpeningMessage(request: Pick<LiveCallTurnRequest, 'disclosureLine'>): string;
|
|
120
|
+
/**
|
|
121
|
+
* The `input` mode of a message the person typed during the call. It is read
|
|
122
|
+
* as typed: the turn's context carries no `input`, as for a message typed in
|
|
123
|
+
* the product's own chat.
|
|
124
|
+
*/
|
|
125
|
+
export declare const LIVE_CALL_TYPED_INPUT_MODE = "text";
|
|
126
|
+
/** Limits on a request. */
|
|
127
|
+
export declare const LIVE_CALL_LIMITS: {
|
|
128
|
+
/** The longest `sessionId`, `turnId`, or turn id in `supersedes`. */
|
|
129
|
+
readonly idChars: 128;
|
|
130
|
+
/** The longest `clientRef`. */
|
|
131
|
+
readonly clientRefChars: 512;
|
|
132
|
+
/** The longest `text`. */
|
|
133
|
+
readonly textChars: 8000;
|
|
134
|
+
/** The most turn ids in `supersedes`. */
|
|
135
|
+
readonly supersedes: 32;
|
|
136
|
+
/** The longest `disclosureLine`. */
|
|
137
|
+
readonly disclosureLineChars: 1000;
|
|
138
|
+
};
|
|
139
|
+
/** A request read, or why it is not one. */
|
|
140
|
+
export type LiveCallRequestReading = {
|
|
141
|
+
ok: true;
|
|
142
|
+
request: LiveCallTurnRequest;
|
|
143
|
+
} | {
|
|
144
|
+
ok: false;
|
|
145
|
+
error: string;
|
|
146
|
+
};
|
|
147
|
+
/** Reads a live-call turn request's body. Every refusal names the field. */
|
|
148
|
+
export declare function readLiveCallTurnRequest(body: unknown): LiveCallRequestReading;
|
|
149
|
+
/**
|
|
150
|
+
* What a failed turn's `error` event says, by code. Fixed lines: the call
|
|
151
|
+
* service records the code and speaks its own apology, and the cause (a
|
|
152
|
+
* provider's error text, a stack) stays in the host's logs.
|
|
153
|
+
*/
|
|
154
|
+
export declare const LIVE_CALL_ERROR_MESSAGES: Readonly<Record<string, string>>;
|
|
155
|
+
/** The `error` event for a failure code. */
|
|
156
|
+
export declare function liveCallError(code: string): LiveCallStreamEvents['error'];
|
|
157
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/live-call/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAqC,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE7G,8HAA8H;AAC9H,eAAO,MAAM,oBAAoB,iCAAkC,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,uHAAuH;AACvH,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,0IAA0I;IAC1I,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,gBAAgB,CAAC;IACvB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B;;;;OAIG;IACH,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3B,qGAAqG;IACrG,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,wDAAwD;AACxD,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB;;;;;OAKG;IACH,QAAQ,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE;;;;;OAKG;IACH,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