@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/container/server.ts"],"names":[],"mappings":"AAAA
|
|
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,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"}
|
|
@@ -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
|
@@ -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,7 +33,9 @@ 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';
|
|
34
|
-
export {
|
|
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';
|
|
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';
|
|
37
41
|
export type { AttachmentStore, AttachmentStoreCallOptions, AttachmentOwner, AttachmentLoadAs, AttachmentContent, AttachmentWorkerConfig } from './attachments/store.js';
|
|
@@ -60,13 +64,22 @@ export type { TurnPolicy, StepTool } from './turn-policy.js';
|
|
|
60
64
|
export { defaultTurnPolicy } from './turn-policy.js';
|
|
61
65
|
export { createHttpEmitAdapter } from './emit/http-adapter.js';
|
|
62
66
|
export type { HttpEmitAdapterConfig } from './emit/http-adapter.js';
|
|
67
|
+
export { teeEmitAdapter } from './emit/tee.js';
|
|
68
|
+
export type { TurnEventObserver } from './emit/tee.js';
|
|
63
69
|
export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
|
|
64
|
-
export type { AgentTurnRunner, TurnOutcome, CategorizedError } from './runtime/turn-runner.js';
|
|
70
|
+
export type { AgentTurnRunner, TurnHost, TurnOutcome, CategorizedError } from './runtime/turn-runner.js';
|
|
65
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';
|
|
66
74
|
export type { AgentRuntimeConfig, LambdaAgentConfig, AgentTurnPayload, HistoryRequest, TurnHistory } from './runtime/types.js';
|
|
67
75
|
export { createLambdaAgentHandler } from './lambda/handler.js';
|
|
68
|
-
export { startContainerAgentWorker } from './container/server.js';
|
|
69
|
-
export type { ContainerAgentConfig, ContainerAgentWorker } from './container/server.js';
|
|
76
|
+
export { startContainerAgentWorker, DEFAULT_LIVE_CALL_PATH } from './container/server.js';
|
|
77
|
+
export type { ContainerAgentConfig, ContainerAgentWorker, ContainerLiveCallRoute } from './container/server.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';
|
|
81
|
+
export type { LiveCallTurnKind, LiveCallTurnRequest, LiveCallStreamEvents, LiveCallStreamEventName, LiveCallRequestReading, } from './live-call/protocol.js';
|
|
82
|
+
export { DEFAULT_KEEP_ALIVE_MS as LIVE_CALL_KEEP_ALIVE_MS } from './live-call/event-stream.js';
|
|
70
83
|
export { buildAgentSystemPrompt } from './prompt/index.js';
|
|
71
84
|
export type { AgentPersonaConfig, AgentKnowledgeEntry, AgentWorkflow, AgentFewShotExample, AgentPersonaOverrides, PromptBuildContext, CommunicationStyle, } from './prompt/index.js';
|
|
72
85
|
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,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACxJ,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAChH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACzE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACnG,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,qBAAqB,EAAE,MAAM,yB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AkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/H,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC1F,YAAY,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAIhH,OAAO,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACxG,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;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,10 +25,12 @@ 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.
|
|
30
|
-
export { createHttpTurnStopClient, watchTurnStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
33
|
+
export { createHttpTurnStopClient, watchTurnStop, withLocalStop, stopOf, TurnStopped, DEFAULT_STOP_GRACE_MS } from './stop/turn-stop.js';
|
|
31
34
|
export { stoppedTurnMessages } from './stop/partial.js';
|
|
32
35
|
export { AttachmentGuard } from './attachments/guard.js';
|
|
33
36
|
export { attachmentTools, ATTACHMENT_TOOLS, ATTACHMENT_TOOL_CLASS } from './attachments/tools.js';
|
|
@@ -48,11 +51,18 @@ export { PROMPT_CACHE_BREAKPOINTS, describeModel } from './model.js';
|
|
|
48
51
|
export { answerWithoutState } from './ui/page-state-at-end.js';
|
|
49
52
|
export { defaultTurnPolicy } from './turn-policy.js';
|
|
50
53
|
export { createHttpEmitAdapter } from './emit/http-adapter.js';
|
|
54
|
+
export { teeEmitAdapter } from './emit/tee.js';
|
|
51
55
|
// The runtime: one core, two host adapters (Lambda + SQS, container)
|
|
52
56
|
export { createAgentTurnRunner, categorizeError, payloadRefusal, TURN_DEADLINE_EXCEEDED } from './runtime/turn-runner.js';
|
|
53
57
|
export { assertAgentRuntimeConfig } from './runtime/config.js';
|
|
58
|
+
export { turnInfoOf, DEFAULT_TURN_CHANNEL } from './runtime/turn-info.js';
|
|
54
59
|
export { createLambdaAgentHandler } from './lambda/handler.js';
|
|
55
|
-
export { startContainerAgentWorker } from './container/server.js';
|
|
60
|
+
export { startContainerAgentWorker, DEFAULT_LIVE_CALL_PATH } from './container/server.js';
|
|
61
|
+
// Live calls: the call service's turns, answered by the product's own agent as
|
|
62
|
+
// a server-sent event stream, while the turn streams to its room as any turn does.
|
|
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';
|
|
65
|
+
export { DEFAULT_KEEP_ALIVE_MS as LIVE_CALL_KEEP_ALIVE_MS } from './live-call/event-stream.js';
|
|
56
66
|
// Prompt Framework
|
|
57
67
|
export { buildAgentSystemPrompt } from './prompt/index.js';
|
|
58
68
|
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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EA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AwB,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,MAAM,2BAA2B,CAAC;AAGlF;;;;;;;GAOG;AACH,MAAM,UA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I,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAqB,CAAC;QACtE,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,eAAe,OAAO,EAAE,CAAC,CAAC;QAEvD,2EAA2E;QAC3E,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE;YACxC,OAAO,EAAE,QAAQ;YACjB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9E,CAAC,CAAC;QACH,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW;YAAE,MAAM,OAAO,CAAC,KAAK,CAAC;IACrF,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-stream.js","sourceRoot":"","sources":["../../src/live-call/event-stream.ts"],"names":[],"mappings":"AAQA,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAW3C,gFAAgF;AAChF,MAAM,UAAU,uBAAuB,CAAC,GAAmB,EAAE,cAAsB,qBAAqB;IACtG,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,cAAc,EAAE,kCAAkC;QAClD,eAAe,EAAE,wBAAwB;QACzC,UAAU,EAAE,YAAY;QACxB,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|
3
|
+
import { type AgentTurnRunner, type TurnOutcome } from '../runtime/turn-runner.js';
|
|
4
|
+
import { type TurnSlots } from '../runtime/turn-slots.js';
|
|
5
|
+
import { type LiveCallTurnRequest } from './protocol.js';
|
|
6
|
+
/** Who and where a live-call turn is, in the product: what the host resolves a call's `clientRef` to. */
|
|
7
|
+
export interface LiveCallTurnTarget {
|
|
8
|
+
/** The product's conversation: the call is one more way to reach it. */
|
|
9
|
+
conversationId: string;
|
|
10
|
+
/** The user the turn acts as: the conversation's principal. */
|
|
11
|
+
userId: string;
|
|
12
|
+
accountId: string;
|
|
13
|
+
/** The conversation's realtime room: the turn streams there, and its UI actions reach every page joined to it. */
|
|
14
|
+
socketRoom: string;
|
|
15
|
+
/** Passed to the turn's tools as the payload's `userToken`. */
|
|
16
|
+
userToken?: string;
|
|
17
|
+
/**
|
|
18
|
+
* What the model reads as the person's message, in place of `request.text`
|
|
19
|
+
* (or, for an `opening`, of `liveCallOpeningMessage(request)`): the words
|
|
20
|
+
* with a card number or an account number redacted. Store the same copy.
|
|
21
|
+
* The runtime's `beforeTurn`, which every channel passes through, can do
|
|
22
|
+
* this too.
|
|
23
|
+
*/
|
|
24
|
+
content?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The turn's context, as the product would send it for a typed message on
|
|
27
|
+
* the conversation's page: its OUI snapshot, its knowledge, its page
|
|
28
|
+
* context. `input` and `output` are the request's, and are set by the handler.
|
|
29
|
+
*/
|
|
30
|
+
context?: Record<string, unknown> | null;
|
|
31
|
+
/**
|
|
32
|
+
* The decision on an approval the agent read back, when the host takes this
|
|
33
|
+
* message as the answer to it: the host classified the person's words, and
|
|
34
|
+
* decided as the user (`ApprovalStoreClient.decide` with a conversation
|
|
35
|
+
* channel). With `approve`, its `token`: the turn redeems it and runs
|
|
36
|
+
* exactly the stored call.
|
|
37
|
+
*/
|
|
38
|
+
approval?: ApprovalContinuation;
|
|
39
|
+
}
|
|
40
|
+
/** What the host's callbacks are told beside the request. */
|
|
41
|
+
export interface LiveCallTurnCallContext {
|
|
42
|
+
/** Aborts when the call service closes the connection: the person spoke again. */
|
|
43
|
+
signal: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
/** The live-call route's own settings, wherever it is mounted. */
|
|
46
|
+
export interface LiveCallTurnOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The credential the call service sends as `Authorization: Bearer …`, from
|
|
49
|
+
* the product's secret store. Several are accepted while one is rotated.
|
|
50
|
+
* Required.
|
|
51
|
+
*/
|
|
52
|
+
credential: string | readonly string[];
|
|
53
|
+
/**
|
|
54
|
+
* Resolves the call's `clientRef` to the turn's conversation, user and room,
|
|
55
|
+
* or null when the product has no such conversation (answered `404`).
|
|
56
|
+
* Required.
|
|
57
|
+
*
|
|
58
|
+
* This is where the product does what its API does for a message from its
|
|
59
|
+
* own chat: store the person's message (`request.text`, entered as
|
|
60
|
+
* `request.input`, or the redacted copy you return as `content`) in the
|
|
61
|
+
* conversation, or for an `opening` turn `liveCallOpeningMessage(request)`;
|
|
62
|
+
* claim the turn record; and, when a readback
|
|
63
|
+
* is waiting, decide on it from what the person said. What it throws is
|
|
64
|
+
* answered `500`, and nothing runs.
|
|
65
|
+
*/
|
|
66
|
+
resolveTurn: (request: LiveCallTurnRequest, call: LiveCallTurnCallContext) => LiveCallTurnTarget | null | Promise<LiveCallTurnTarget | null>;
|
|
67
|
+
/**
|
|
68
|
+
* A greeting for an `opening` turn from the product's template, instead of
|
|
69
|
+
* the model's: the turn's reply is this text, streamed and stored as the
|
|
70
|
+
* model's would be. Null, undefined or blank lets the model greet. What it
|
|
71
|
+
* throws fails the turn (`error` event); the model does not greet instead.
|
|
72
|
+
*/
|
|
73
|
+
opening?: (request: LiveCallTurnRequest, target: LiveCallTurnTarget, call: LiveCallTurnCallContext) => string | null | undefined | Promise<string | null | undefined>;
|
|
74
|
+
/** How long the response may be silent before a `: keep-alive` comment. Default 5 s, well inside the call service's 15 s. */
|
|
75
|
+
keepAliveMs?: number;
|
|
76
|
+
/**
|
|
77
|
+
* What of the reply is spoken. `all` (the default): every round, as the
|
|
78
|
+
* model writes it, the text before a tool call included. `final-round`:
|
|
79
|
+
* only the round the turn ends with. A round's text is held until the round
|
|
80
|
+
* ends (`agent:round_end`) and sent only when no round follows it, so
|
|
81
|
+
* nothing the model wrote before a tool call is spoken; the reply then
|
|
82
|
+
* starts when its last round is written, not as its first words are.
|
|
83
|
+
*/
|
|
84
|
+
speak?: LiveCallSpeech;
|
|
85
|
+
/**
|
|
86
|
+
* With `speak: 'final-round'`: a line of your own spoken once, as the
|
|
87
|
+
* turn's first tool starts, so the caller does not wait in silence ("One
|
|
88
|
+
* moment while I check."). A function is given the request (its
|
|
89
|
+
* `input.language`) and the target, once per turn; null, undefined or blank
|
|
90
|
+
* says nothing. What it throws fails the turn. Not used with `all`, where the
|
|
91
|
+
* model's own words before a tool call are spoken.
|
|
92
|
+
*/
|
|
93
|
+
holdingLine?: string | ((request: LiveCallTurnRequest, target: LiveCallTurnTarget) => string | null | undefined | Promise<string | null | undefined>);
|
|
94
|
+
}
|
|
95
|
+
/** What of a live-call turn's reply is spoken (`LiveCallTurnOptions.speak`). */
|
|
96
|
+
export declare const LIVE_CALL_SPEECH: readonly ["all", "final-round"];
|
|
97
|
+
export type LiveCallSpeech = (typeof LIVE_CALL_SPEECH)[number];
|
|
98
|
+
/** `createLiveCallTurnHandler`'s configuration: the route's settings and the runtime that runs its turns. */
|
|
99
|
+
export interface LiveCallTurnHandlerConfig extends LiveCallTurnOptions {
|
|
100
|
+
/** The runtime (`createAgentTurnRunner`): the same one that runs the product's other turns. Required. */
|
|
101
|
+
runner: AgentTurnRunner;
|
|
102
|
+
/** Turns run at once; more are answered `503`. Default 8. */
|
|
103
|
+
maxConcurrentTurns?: number;
|
|
104
|
+
/** Largest request body, in bytes. Default 64 KiB. */
|
|
105
|
+
maxBodyBytes?: number;
|
|
106
|
+
/** Called with each turn's outcome, after it ends. */
|
|
107
|
+
onTurnEnd?: (outcome: TurnOutcome) => void;
|
|
108
|
+
}
|
|
109
|
+
/** A Node request handler: mount it on a `POST` route of the product's own server. */
|
|
110
|
+
export interface LiveCallTurnHandler {
|
|
111
|
+
(req: IncomingMessage, res: ServerResponse): void;
|
|
112
|
+
/** Turns running now. */
|
|
113
|
+
running(): number;
|
|
114
|
+
/** Takes no more turns, and resolves once every running one has ended. */
|
|
115
|
+
close(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
/** What the route needs from its host: the runtime and the process's turn slots. */
|
|
118
|
+
interface LiveCallRouteHost {
|
|
119
|
+
runner: AgentTurnRunner;
|
|
120
|
+
slots: TurnSlots;
|
|
121
|
+
maxBodyBytes: number;
|
|
122
|
+
onTurnEnd?: (outcome: TurnOutcome) => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates the live-call turn handler.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* const runner = createAgentTurnRunner(runtimeConfig);
|
|
130
|
+
* const liveCall = createLiveCallTurnHandler({
|
|
131
|
+
* runner,
|
|
132
|
+
* credential: env.LIVE_CALL_BRAIN_CREDENTIAL,
|
|
133
|
+
* resolveTurn: async (request) => {
|
|
134
|
+
* const conversation = await db.conversation.findUnique({ where: { callRef: request.clientRef } });
|
|
135
|
+
* if (!conversation) return null;
|
|
136
|
+
* await db.message.create({ data: { conversationId: conversation.id, role: 'user', content: request.text, input: request.input } });
|
|
137
|
+
* return { conversationId: conversation.id, userId: conversation.userId, accountId: conversation.accountId, socketRoom: `conversation:${conversation.id}` };
|
|
138
|
+
* },
|
|
139
|
+
* });
|
|
140
|
+
* app.post('/agent/live-call/turns', liveCall);
|
|
141
|
+
* process.on('SIGTERM', () => liveCall.close());
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function createLiveCallTurnHandler(config: LiveCallTurnHandlerConfig): LiveCallTurnHandler;
|
|
145
|
+
/**
|
|
146
|
+
* The route, for a host that already runs turns (the container adapter): it
|
|
147
|
+
* shares that host's runtime and slots.
|
|
148
|
+
*/
|
|
149
|
+
export declare function liveCallRoute(options: LiveCallTurnOptions, host: LiveCallRouteHost): (req: IncomingMessage, res: ServerResponse) => void;
|
|
150
|
+
/** The channel the live-call handler's turns run on, as the host's hooks are told. */
|
|
151
|
+
export declare const LIVE_CALL_CHANNEL = "live-call";
|
|
152
|
+
export {};
|
|
153
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/live-call/handler.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAIL,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAkB,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAEnG,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAI3E,OAAO,EAA6F,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpJ,yGAAyG;AACzG,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,cAAc,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,kHAAkH;IAClH,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC;AAED,6DAA6D;AAC7D,MAAM,WAAW,uBAAuB;IACtC,kFAAkF;IAClF,M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