@framers/agentos 0.1.83 → 0.1.85
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/dist/orchestration/builders/VoiceNodeBuilder.d.ts +116 -0
- package/dist/orchestration/builders/VoiceNodeBuilder.d.ts.map +1 -0
- package/dist/orchestration/builders/VoiceNodeBuilder.js +140 -0
- package/dist/orchestration/builders/VoiceNodeBuilder.js.map +1 -0
- package/dist/orchestration/builders/WorkflowBuilder.d.ts +40 -1
- package/dist/orchestration/builders/WorkflowBuilder.d.ts.map +1 -1
- package/dist/orchestration/builders/WorkflowBuilder.js +47 -0
- package/dist/orchestration/builders/WorkflowBuilder.js.map +1 -1
- package/dist/orchestration/events/GraphEvent.d.ts +39 -0
- package/dist/orchestration/events/GraphEvent.d.ts.map +1 -1
- package/dist/orchestration/events/GraphEvent.js.map +1 -1
- package/dist/orchestration/ir/types.d.ts +34 -1
- package/dist/orchestration/ir/types.d.ts.map +1 -1
- package/dist/orchestration/runtime/NodeExecutor.d.ts +6 -0
- package/dist/orchestration/runtime/NodeExecutor.d.ts.map +1 -1
- package/dist/orchestration/runtime/NodeExecutor.js +5 -0
- package/dist/orchestration/runtime/NodeExecutor.js.map +1 -1
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts +105 -0
- package/dist/orchestration/runtime/VoiceNodeExecutor.d.ts.map +1 -0
- package/dist/orchestration/runtime/VoiceNodeExecutor.js +232 -0
- package/dist/orchestration/runtime/VoiceNodeExecutor.js.map +1 -0
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts +157 -0
- package/dist/orchestration/runtime/VoiceTransportAdapter.d.ts.map +1 -0
- package/dist/orchestration/runtime/VoiceTransportAdapter.js +193 -0
- package/dist/orchestration/runtime/VoiceTransportAdapter.js.map +1 -0
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts +95 -0
- package/dist/orchestration/runtime/VoiceTurnCollector.d.ts.map +1 -0
- package/dist/orchestration/runtime/VoiceTurnCollector.js +148 -0
- package/dist/orchestration/runtime/VoiceTurnCollector.js.map +1 -0
- package/dist/voice-pipeline/VoiceInterruptError.d.ts +52 -0
- package/dist/voice-pipeline/VoiceInterruptError.d.ts.map +1 -0
- package/dist/voice-pipeline/VoiceInterruptError.js +43 -0
- package/dist/voice-pipeline/VoiceInterruptError.js.map +1 -0
- package/dist/voice-pipeline/VoicePipelineOrchestrator.d.ts +44 -1
- package/dist/voice-pipeline/VoicePipelineOrchestrator.d.ts.map +1 -1
- package/dist/voice-pipeline/VoicePipelineOrchestrator.js +63 -0
- package/dist/voice-pipeline/VoicePipelineOrchestrator.js.map +1 -1
- package/dist/voice-pipeline/index.d.ts +1 -0
- package/dist/voice-pipeline/index.d.ts.map +1 -1
- package/dist/voice-pipeline/index.js +1 -0
- package/dist/voice-pipeline/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { GraphNode, GraphState, CompiledExecutionGraph } from '../ir/types.js';
|
|
16
16
|
import type { GraphEvent } from '../events/GraphEvent.js';
|
|
17
17
|
import type { LoopController, LoopChunk, LoopOutput } from './LoopController.js';
|
|
18
|
+
import type { VoiceNodeExecutor } from './VoiceNodeExecutor.js';
|
|
18
19
|
/**
|
|
19
20
|
* The normalised result returned by every `NodeExecutor.execute()` call regardless
|
|
20
21
|
* of which executor variant was dispatched.
|
|
@@ -137,6 +138,11 @@ export interface NodeExecutorDeps {
|
|
|
137
138
|
output?: unknown;
|
|
138
139
|
error?: string;
|
|
139
140
|
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Executor for `voice` nodes. Manages voice pipeline sessions, turn collection,
|
|
143
|
+
* and exit-condition racing. When absent, voice nodes return `success: false`.
|
|
144
|
+
*/
|
|
145
|
+
voiceExecutor?: VoiceNodeExecutor;
|
|
140
146
|
}
|
|
141
147
|
/**
|
|
142
148
|
* Stateless executor that dispatches a `GraphNode` to the appropriate handler.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeExecutor.d.ts","sourceRoot":"","sources":["../../../src/orchestration/runtime/NodeExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAkB,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeExecutor.d.ts","sourceRoot":"","sources":["../../../src/orchestration/runtime/NodeExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAkB,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAMhE;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;IACjB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,qEAAqE;IACrE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,wEAAwE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C;IAEF;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,CAClB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,KACX,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAErE;;;OAGG;IACH,aAAa,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAMD;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAY;IAKX,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJjC;;;OAGG;gBAC0B,IAAI,EAAE,gBAAgB;IAMnD;;;;;;;;;OASG;IACG,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAcxF;;;;;OAKG;YACW,WAAW;IAwCzB;;;;;;;;OAQG;YACW,WAAW;IAyBzB;;;;;;;;;OASG;YACW,aAAa;IAiB3B;;;;;;;;;;OAUG;YACW,gBAAgB;IAgC9B;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAWpB;;;;;;;;;;;;OAYG;YACW,UAAU;IAuDxB;;;;;;;;;;;;OAYG;YACW,eAAe;IA8C7B;;;;;OAKG;YACW,gBAAgB;IAkC9B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAQxB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAYpB;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;CAQ5B"}
|
|
@@ -85,6 +85,11 @@ export class NodeExecutor {
|
|
|
85
85
|
return this.executeExtension(config, state);
|
|
86
86
|
case 'subgraph':
|
|
87
87
|
return this.executeSubgraph(config, state);
|
|
88
|
+
case 'voice':
|
|
89
|
+
if (!this.deps.voiceExecutor) {
|
|
90
|
+
return { success: false, error: 'VoiceNodeExecutor not configured' };
|
|
91
|
+
}
|
|
92
|
+
return this.deps.voiceExecutor.execute(node, state);
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
// ---------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeExecutor.js","sourceRoot":"","sources":["../../../src/orchestration/runtime/NodeExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"NodeExecutor.js","sourceRoot":"","sources":["../../../src/orchestration/runtime/NodeExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgJH,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAY;IACvB;;;OAGG;IACH,YAA6B,IAAsB;QAAtB,SAAI,GAAJ,IAAI,CAAkB;IAAG,CAAC;IAEvD,8EAA8E;IAC9E,aAAa;IACb,8EAA8E;IAE9E;;;;;;;;;OASG;IACH,KAAK,CAAC,OAAO,CAAC,IAAe,EAAE,KAA0B;QACvD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,OAAO,CAAC,IAAI,CAAC;gBAClB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC;gBAC7B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;aAChD,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,8EAA8E;IAC9E,oBAAoB;IACpB,8EAA8E;IAE9E;;;;;OAKG;IACK,KAAK,CAAC,WAAW,CACvB,IAAe,EACf,KAA0B;QAE1B,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;QAEnC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;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,EAChF,EAAE,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file VoiceNodeExecutor.ts
|
|
3
|
+
* @description Executes voice nodes in the orchestration graph by managing a voice
|
|
4
|
+
* pipeline session, collecting turns via {@link VoiceTurnCollector}, and racing
|
|
5
|
+
* multiple exit conditions (hangup, turns exhausted, keyword, silence timeout,
|
|
6
|
+
* barge-in abort) to determine when the voice node completes.
|
|
7
|
+
*
|
|
8
|
+
* The executor follows the standard 2-arg `execute(node, state)` contract used by
|
|
9
|
+
* {@link NodeExecutor}. It creates an internal `AbortController` for barge-in
|
|
10
|
+
* support and optionally merges a parent abort signal from `state.scratch.abortSignal`.
|
|
11
|
+
*
|
|
12
|
+
* Voice transport and session references are expected in `state.scratch`:
|
|
13
|
+
* - `voiceTransport` — the bidirectional transport EventEmitter (emits `close` / `disconnected`).
|
|
14
|
+
* - `voiceTransport._voiceSession` — the voice pipeline session EventEmitter that fires
|
|
15
|
+
* `final_transcript`, `turn_complete`, `speech_start`, and `barge_in` events.
|
|
16
|
+
*
|
|
17
|
+
* Checkpoint data is stored in `state.scratch[nodeId]` as a {@link VoiceNodeCheckpoint},
|
|
18
|
+
* enabling the graph runtime to resume a voice session from the exact turn index where
|
|
19
|
+
* it was previously suspended.
|
|
20
|
+
*/
|
|
21
|
+
import type { GraphNode, GraphState, VoiceNodeConfig } from '../ir/types.js';
|
|
22
|
+
import type { GraphEvent } from '../events/GraphEvent.js';
|
|
23
|
+
import type { NodeExecutionResult } from './NodeExecutor.js';
|
|
24
|
+
/**
|
|
25
|
+
* Checkpoint data stored in `state.scratch[nodeId]` after a voice node completes.
|
|
26
|
+
*
|
|
27
|
+
* The graph runtime persists this structure so that a subsequent invocation of the
|
|
28
|
+
* same voice node (e.g. after a graph loop or checkpoint restore) can continue the
|
|
29
|
+
* conversation from `turnIndex` rather than resetting to zero.
|
|
30
|
+
*/
|
|
31
|
+
export interface VoiceNodeCheckpoint {
|
|
32
|
+
/** Number of turns completed when the checkpoint was captured. */
|
|
33
|
+
turnIndex: number;
|
|
34
|
+
/** Full transcript buffer at the time of checkpoint. */
|
|
35
|
+
transcript: Array<{
|
|
36
|
+
speaker: string;
|
|
37
|
+
text: string;
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}>;
|
|
40
|
+
/** Exit reason that caused the voice node to complete (`null` if still in progress). */
|
|
41
|
+
lastExitReason: string | null;
|
|
42
|
+
/** Maps diarization speaker labels to human-readable names (reserved for future use). */
|
|
43
|
+
speakerMap: Record<string, string>;
|
|
44
|
+
/** The voice config that was active when this checkpoint was created. */
|
|
45
|
+
sessionConfig: VoiceNodeConfig;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Executes voice-type graph nodes by running a voice pipeline session and racing
|
|
49
|
+
* multiple exit conditions to determine when the node is done.
|
|
50
|
+
*
|
|
51
|
+
* Exit conditions are evaluated concurrently via a single `Promise` race:
|
|
52
|
+
* - **Hangup** — transport emits `close` or `disconnected`.
|
|
53
|
+
* - **Turns exhausted** — session emits `turn_complete` and the collector's count
|
|
54
|
+
* reaches `config.maxTurns`.
|
|
55
|
+
* - **Keyword** — a `final_transcript` event contains one of `config.exitKeywords`.
|
|
56
|
+
* - **Silence timeout** — no speech activity for 30 seconds (when `exitOn: 'silence-timeout'`).
|
|
57
|
+
* - **Abort/barge-in** — the internal `AbortController` is signalled, either by a
|
|
58
|
+
* parent abort signal or a `VoiceInterruptError`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const executor = new VoiceNodeExecutor((event) => emitter.emit(event));
|
|
63
|
+
* const result = await executor.execute(voiceNode, graphState);
|
|
64
|
+
* console.log(result.output.exitReason); // 'turns-exhausted' | 'hangup' | 'keyword:goodbye' | ...
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare class VoiceNodeExecutor {
|
|
68
|
+
private readonly eventSink;
|
|
69
|
+
/**
|
|
70
|
+
* @param eventSink - Callback invoked synchronously for every emitted {@link GraphEvent}.
|
|
71
|
+
* Typically bound to the graph runtime's event emitter.
|
|
72
|
+
*/
|
|
73
|
+
constructor(eventSink: (event: GraphEvent) => void);
|
|
74
|
+
/**
|
|
75
|
+
* Execute a voice node. Matches the standard 2-arg `execute(node, state)` signature
|
|
76
|
+
* used throughout the orchestration runtime.
|
|
77
|
+
*
|
|
78
|
+
* Creates an internal `AbortController` for barge-in, wires up a
|
|
79
|
+
* {@link VoiceTurnCollector} on the session, and races exit conditions to
|
|
80
|
+
* determine when the node completes.
|
|
81
|
+
*
|
|
82
|
+
* @param node - Immutable voice node descriptor from the compiled graph IR.
|
|
83
|
+
* @param state - Current (partial) graph state threaded from the runtime.
|
|
84
|
+
* @returns A {@link NodeExecutionResult} with transcript, exit reason, and optional route target.
|
|
85
|
+
*/
|
|
86
|
+
execute(node: GraphNode, state: Partial<GraphState>): Promise<NodeExecutionResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Races all configured exit conditions against each other and resolves with
|
|
89
|
+
* the first one that fires.
|
|
90
|
+
*
|
|
91
|
+
* Listeners are attached to the session and transport EventEmitters. The
|
|
92
|
+
* `AbortController` signal is also monitored — if it fires with a
|
|
93
|
+
* {@link VoiceInterruptError} the Promise rejects (handled by the caller),
|
|
94
|
+
* otherwise it resolves with `{ reason: 'interrupted' }`.
|
|
95
|
+
*
|
|
96
|
+
* @param session - Voice pipeline session EventEmitter.
|
|
97
|
+
* @param collector - Active turn collector tracking turn count.
|
|
98
|
+
* @param config - Voice node configuration with exit settings.
|
|
99
|
+
* @param controller - Internal AbortController for barge-in signalling.
|
|
100
|
+
* @param transport - Bidirectional transport EventEmitter.
|
|
101
|
+
* @returns The winning exit condition's reason string and optional interrupted text.
|
|
102
|
+
*/
|
|
103
|
+
private raceExitConditions;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=VoiceNodeExecutor.d.ts.map
|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
* @description Executes voice nodes in the orchestration graph by managing a voice
|
|
4
|
+
* pipeline session, collecting turns via {@link VoiceTurnCollector}, and racing
|
|
5
|
+
* multiple exit conditions (hangup, turns exhausted, keyword, silence timeout,
|
|
6
|
+
* barge-in abort) to determine when the voice node completes.
|
|
7
|
+
*
|
|
8
|
+
* The executor follows the standard 2-arg `execute(node, state)` contract used by
|
|
9
|
+
* {@link NodeExecutor}. It creates an internal `AbortController` for barge-in
|
|
10
|
+
* support and optionally merges a parent abort signal from `state.scratch.abortSignal`.
|
|
11
|
+
*
|
|
12
|
+
* Voice transport and session references are expected in `state.scratch`:
|
|
13
|
+
* - `voiceTransport` — the bidirectional transport EventEmitter (emits `close` / `disconnected`).
|
|
14
|
+
* - `voiceTransport._voiceSession` — the voice pipeline session EventEmitter that fires
|
|
15
|
+
* `final_transcript`, `turn_complete`, `speech_start`, and `barge_in` events.
|
|
16
|
+
*
|
|
17
|
+
* Checkpoint data is stored in `state.scratch[nodeId]` as a {@link VoiceNodeCheckpoint},
|
|
18
|
+
* enabling the graph runtime to resume a voice session from the exact turn index where
|
|
19
|
+
* it was previously suspended.
|
|
20
|
+
*/
|
|
21
|
+
import { EventEmitter } from 'events';
|
|
22
|
+
import { VoiceTurnCollector } from './VoiceTurnCollector.js';
|
|
23
|
+
import { VoiceInterruptError } from '../../voice-pipeline/VoiceInterruptError.js';
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// VoiceNodeExecutor
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/**
|
|
28
|
+
* Executes voice-type graph nodes by running a voice pipeline session and racing
|
|
29
|
+
* multiple exit conditions to determine when the node is done.
|
|
30
|
+
*
|
|
31
|
+
* Exit conditions are evaluated concurrently via a single `Promise` race:
|
|
32
|
+
* - **Hangup** — transport emits `close` or `disconnected`.
|
|
33
|
+
* - **Turns exhausted** — session emits `turn_complete` and the collector's count
|
|
34
|
+
* reaches `config.maxTurns`.
|
|
35
|
+
* - **Keyword** — a `final_transcript` event contains one of `config.exitKeywords`.
|
|
36
|
+
* - **Silence timeout** — no speech activity for 30 seconds (when `exitOn: 'silence-timeout'`).
|
|
37
|
+
* - **Abort/barge-in** — the internal `AbortController` is signalled, either by a
|
|
38
|
+
* parent abort signal or a `VoiceInterruptError`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const executor = new VoiceNodeExecutor((event) => emitter.emit(event));
|
|
43
|
+
* const result = await executor.execute(voiceNode, graphState);
|
|
44
|
+
* console.log(result.output.exitReason); // 'turns-exhausted' | 'hangup' | 'keyword:goodbye' | ...
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export class VoiceNodeExecutor {
|
|
48
|
+
/**
|
|
49
|
+
* @param eventSink - Callback invoked synchronously for every emitted {@link GraphEvent}.
|
|
50
|
+
* Typically bound to the graph runtime's event emitter.
|
|
51
|
+
*/
|
|
52
|
+
constructor(eventSink) {
|
|
53
|
+
this.eventSink = eventSink;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Execute a voice node. Matches the standard 2-arg `execute(node, state)` signature
|
|
57
|
+
* used throughout the orchestration runtime.
|
|
58
|
+
*
|
|
59
|
+
* Creates an internal `AbortController` for barge-in, wires up a
|
|
60
|
+
* {@link VoiceTurnCollector} on the session, and races exit conditions to
|
|
61
|
+
* determine when the node completes.
|
|
62
|
+
*
|
|
63
|
+
* @param node - Immutable voice node descriptor from the compiled graph IR.
|
|
64
|
+
* @param state - Current (partial) graph state threaded from the runtime.
|
|
65
|
+
* @returns A {@link NodeExecutionResult} with transcript, exit reason, and optional route target.
|
|
66
|
+
*/
|
|
67
|
+
async execute(node, state) {
|
|
68
|
+
const config = node.executorConfig;
|
|
69
|
+
if (config.type !== 'voice') {
|
|
70
|
+
return { success: false, error: 'VoiceNodeExecutor received non-voice node' };
|
|
71
|
+
}
|
|
72
|
+
const voiceConfig = config.voiceConfig;
|
|
73
|
+
// Internal AbortController for barge-in or parent cancellation.
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
// If a parent abort signal exists in scratch, forward its abort to ours.
|
|
76
|
+
const parentSignal = state?.scratch?.abortSignal;
|
|
77
|
+
if (parentSignal) {
|
|
78
|
+
parentSignal.addEventListener('abort', () => controller.abort(parentSignal.reason), { once: true });
|
|
79
|
+
}
|
|
80
|
+
// Voice transport must be pre-placed in state.scratch by the graph runtime.
|
|
81
|
+
const transport = state?.scratch?.voiceTransport;
|
|
82
|
+
if (!transport) {
|
|
83
|
+
return { success: false, error: 'Voice node requires voiceTransport in state.scratch' };
|
|
84
|
+
}
|
|
85
|
+
// Check for checkpoint restore — continue from a prior turn index.
|
|
86
|
+
const checkpoint = state?.scratch?.[node.id];
|
|
87
|
+
const initialTurnCount = checkpoint?.turnIndex ?? 0;
|
|
88
|
+
// Emit session lifecycle event: started.
|
|
89
|
+
this.eventSink({ type: 'voice_session', nodeId: node.id, action: 'started' });
|
|
90
|
+
try {
|
|
91
|
+
// The voice session EventEmitter is expected on transport._voiceSession.
|
|
92
|
+
// In production this is the VoicePipelineSession; in tests it can be a plain EventEmitter.
|
|
93
|
+
const session = transport._voiceSession ?? new EventEmitter();
|
|
94
|
+
// Create the turn collector — it subscribes to session events and buffers transcript.
|
|
95
|
+
const collector = new VoiceTurnCollector(session, this.eventSink, node.id, initialTurnCount);
|
|
96
|
+
// Race all exit conditions against each other.
|
|
97
|
+
const result = await this.raceExitConditions(session, collector, voiceConfig, controller, transport);
|
|
98
|
+
// Resolve exitReason → routeTarget from node edges.
|
|
99
|
+
const edges = node.edges ?? {};
|
|
100
|
+
const routeTarget = typeof edges === 'object' ? edges[result.reason] : undefined;
|
|
101
|
+
// Build checkpoint for scratch so the runtime can persist/restore later.
|
|
102
|
+
const voiceCheckpoint = {
|
|
103
|
+
turnIndex: collector.getTurnCount(),
|
|
104
|
+
transcript: collector.getTranscript(),
|
|
105
|
+
lastExitReason: result.reason,
|
|
106
|
+
speakerMap: {},
|
|
107
|
+
sessionConfig: voiceConfig,
|
|
108
|
+
};
|
|
109
|
+
// Emit session lifecycle event: ended.
|
|
110
|
+
this.eventSink({ type: 'voice_session', nodeId: node.id, action: 'ended', exitReason: result.reason });
|
|
111
|
+
return {
|
|
112
|
+
success: true,
|
|
113
|
+
output: {
|
|
114
|
+
transcript: collector.getTranscript(),
|
|
115
|
+
turns: collector.getTurnCount(),
|
|
116
|
+
exitReason: result.reason,
|
|
117
|
+
lastSpeaker: collector.getLastSpeaker(),
|
|
118
|
+
interruptedText: result.interruptedText,
|
|
119
|
+
},
|
|
120
|
+
routeTarget,
|
|
121
|
+
scratchUpdate: { [node.id]: voiceCheckpoint },
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
// VoiceInterruptError is a structured barge-in — treat as a successful exit
|
|
126
|
+
// with exitReason: 'interrupted' so the graph can route accordingly.
|
|
127
|
+
if (err instanceof VoiceInterruptError) {
|
|
128
|
+
const edges = node.edges ?? {};
|
|
129
|
+
const routeTarget = edges['interrupted'];
|
|
130
|
+
this.eventSink({ type: 'voice_session', nodeId: node.id, action: 'ended', exitReason: 'interrupted' });
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
output: {
|
|
134
|
+
transcript: [],
|
|
135
|
+
turns: 0,
|
|
136
|
+
exitReason: 'interrupted',
|
|
137
|
+
interruptedText: err.interruptedText,
|
|
138
|
+
userSpeech: err.userSpeech,
|
|
139
|
+
},
|
|
140
|
+
routeTarget,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Unhandled error — surface as a failed result.
|
|
144
|
+
this.eventSink({ type: 'voice_session', nodeId: node.id, action: 'ended', exitReason: 'error' });
|
|
145
|
+
return { success: false, error: String(err) };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Private helpers
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
/**
|
|
152
|
+
* Races all configured exit conditions against each other and resolves with
|
|
153
|
+
* the first one that fires.
|
|
154
|
+
*
|
|
155
|
+
* Listeners are attached to the session and transport EventEmitters. The
|
|
156
|
+
* `AbortController` signal is also monitored — if it fires with a
|
|
157
|
+
* {@link VoiceInterruptError} the Promise rejects (handled by the caller),
|
|
158
|
+
* otherwise it resolves with `{ reason: 'interrupted' }`.
|
|
159
|
+
*
|
|
160
|
+
* @param session - Voice pipeline session EventEmitter.
|
|
161
|
+
* @param collector - Active turn collector tracking turn count.
|
|
162
|
+
* @param config - Voice node configuration with exit settings.
|
|
163
|
+
* @param controller - Internal AbortController for barge-in signalling.
|
|
164
|
+
* @param transport - Bidirectional transport EventEmitter.
|
|
165
|
+
* @returns The winning exit condition's reason string and optional interrupted text.
|
|
166
|
+
*/
|
|
167
|
+
async raceExitConditions(session, collector, config, controller, transport) {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
/** Prevent double-resolution from multiple conditions firing simultaneously. */
|
|
170
|
+
let settled = false;
|
|
171
|
+
/**
|
|
172
|
+
* Settle the promise with a resolve value, guarding against double-settle.
|
|
173
|
+
* @param result - The exit condition result.
|
|
174
|
+
*/
|
|
175
|
+
const settleWith = (result) => {
|
|
176
|
+
if (settled)
|
|
177
|
+
return;
|
|
178
|
+
settled = true;
|
|
179
|
+
resolve(result);
|
|
180
|
+
};
|
|
181
|
+
// -- Hangup: transport disconnects -----------------------------------
|
|
182
|
+
const onDisconnect = () => settleWith({ reason: 'hangup' });
|
|
183
|
+
transport.on('close', onDisconnect);
|
|
184
|
+
transport.on('disconnected', onDisconnect);
|
|
185
|
+
// -- Turns exhausted -------------------------------------------------
|
|
186
|
+
if (config.maxTurns && config.maxTurns > 0) {
|
|
187
|
+
session.on('turn_complete', () => {
|
|
188
|
+
if (collector.getTurnCount() >= config.maxTurns) {
|
|
189
|
+
settleWith({ reason: 'turns-exhausted' });
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// -- Keyword detection -----------------------------------------------
|
|
194
|
+
if (config.exitOn === 'keyword' && config.exitKeywords?.length) {
|
|
195
|
+
session.on('final_transcript', (evt) => {
|
|
196
|
+
const text = (evt.text ?? '').toLowerCase();
|
|
197
|
+
for (const kw of config.exitKeywords) {
|
|
198
|
+
if (text.includes(kw.toLowerCase())) {
|
|
199
|
+
settleWith({ reason: `keyword:${kw}` });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// -- Silence timeout (default 30 s) ----------------------------------
|
|
206
|
+
if (config.exitOn === 'silence-timeout') {
|
|
207
|
+
let silenceTimer = null;
|
|
208
|
+
const timeoutMs = 30000;
|
|
209
|
+
/** Reset the silence watchdog — called on any speech activity. */
|
|
210
|
+
const resetTimer = () => {
|
|
211
|
+
if (silenceTimer)
|
|
212
|
+
clearTimeout(silenceTimer);
|
|
213
|
+
silenceTimer = setTimeout(() => settleWith({ reason: 'silence-timeout' }), timeoutMs);
|
|
214
|
+
};
|
|
215
|
+
session.on('speech_start', resetTimer);
|
|
216
|
+
session.on('turn_complete', resetTimer);
|
|
217
|
+
resetTimer(); // Start the initial timer immediately.
|
|
218
|
+
}
|
|
219
|
+
// -- Abort signal (barge-in or parent cancellation) ------------------
|
|
220
|
+
controller.signal.addEventListener('abort', () => {
|
|
221
|
+
const reason = controller.signal.reason;
|
|
222
|
+
if (reason instanceof VoiceInterruptError) {
|
|
223
|
+
reject(reason);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
settleWith({ reason: 'interrupted' });
|
|
227
|
+
}
|
|
228
|
+
}, { once: true });
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=VoiceNodeExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoiceNodeExecutor.js","sourceRoot":"","sources":["../../../src/orchestration/runtime/VoiceNodeExecutor.ts"],"names":[],"m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,CAAC;gBACxC,IAAI,MAAM,YAAY,mBAAmB,EAAE,CAAC;oBAC1C,MAAM,CAAC,MAAM,CAAC,CAAC;gBACjB,CAAC;qBAAM,CAAC;oBACN,UAAU,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;gBACxC,CAAC;YACH,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file VoiceTransportAdapter.ts
|
|
3
|
+
* @description Bridges graph I/O to the voice pipeline when a workflow runs in
|
|
4
|
+
* voice transport mode.
|
|
5
|
+
*
|
|
6
|
+
* `VoiceTransportAdapter` wraps a graph's input/output cycle so that:
|
|
7
|
+
* - **Node input** is obtained by waiting for the user's next speech turn
|
|
8
|
+
* (`waitForUserTurn()` on the underlying `VoicePipelineOrchestrator`).
|
|
9
|
+
* - **Node output** is delivered to the TTS engine (`pushToTTS()` on the
|
|
10
|
+
* underlying `VoicePipelineOrchestrator`).
|
|
11
|
+
*
|
|
12
|
+
* The adapter is lazy — it does not create a `VoicePipelineOrchestrator` until
|
|
13
|
+
* `init()` is called. The pipeline reference is `any` typed to avoid a hard
|
|
14
|
+
* import cycle with the voice subsystem; callers that want stronger types may
|
|
15
|
+
* cast.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const adapter = new VoiceTransportAdapter(
|
|
20
|
+
* { stt: 'deepgram', tts: 'openai' },
|
|
21
|
+
* transport,
|
|
22
|
+
* (event) => eventBus.emit(event),
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* await adapter.init(state);
|
|
26
|
+
* const userInput = await adapter.getNodeInput('greet');
|
|
27
|
+
* await adapter.deliverNodeOutput('greet', 'Hello, how can I help you today?');
|
|
28
|
+
* await adapter.dispose();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
import type { GraphState } from '../ir/types.js';
|
|
32
|
+
import type { GraphEvent } from '../events/GraphEvent.js';
|
|
33
|
+
/**
|
|
34
|
+
* Configuration knobs forwarded to the voice pipeline when the adapter
|
|
35
|
+
* initialises its internal `VoicePipelineOrchestrator` instance.
|
|
36
|
+
*
|
|
37
|
+
* All fields are optional — defaults are resolved from agent.config.json or
|
|
38
|
+
* sensible library defaults.
|
|
39
|
+
*/
|
|
40
|
+
export interface VoiceTransportConfig {
|
|
41
|
+
/** STT provider identifier (e.g. `'deepgram'`, `'openai'`). */
|
|
42
|
+
stt?: string;
|
|
43
|
+
/** TTS provider identifier (e.g. `'openai'`, `'elevenlabs'`). */
|
|
44
|
+
tts?: string;
|
|
45
|
+
/** TTS voice name or id forwarded to the TTS provider. */
|
|
46
|
+
voice?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Barge-in handling strategy.
|
|
49
|
+
* - `'hard-cut'` — interrupt TTS immediately when speech is detected.
|
|
50
|
+
* - `'soft-fade'` — ramp TTS volume down before cutting.
|
|
51
|
+
* - `'disabled'` — ignore user speech while the agent is speaking.
|
|
52
|
+
*/
|
|
53
|
+
bargeIn?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Endpoint detection mode used to decide when the user has finished speaking.
|
|
56
|
+
* - `'acoustic'` — energy/VAD-based detection.
|
|
57
|
+
* - `'heuristic'` — punctuation + silence heuristics.
|
|
58
|
+
* - `'semantic'` — LLM-assisted turn boundary detection.
|
|
59
|
+
*/
|
|
60
|
+
endpointing?: string;
|
|
61
|
+
/** Whether to enable speaker diarization for multi-speaker sessions. */
|
|
62
|
+
diarization?: boolean;
|
|
63
|
+
/** BCP-47 language tag forwarded to STT (e.g. `'en-US'`). */
|
|
64
|
+
language?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Adapts a compiled graph's I/O cycle to the real-time voice pipeline.
|
|
68
|
+
*
|
|
69
|
+
* Lifecycle:
|
|
70
|
+
* 1. Construct with {@link VoiceTransportConfig}, an `IStreamTransport`, and an
|
|
71
|
+
* event sink callback.
|
|
72
|
+
* 2. Call `init()` once before the graph starts running.
|
|
73
|
+
* 3. Use `getNodeInput()` to obtain the user's transcribed speech for a node.
|
|
74
|
+
* 4. Use `deliverNodeOutput()` to send the node's response to TTS.
|
|
75
|
+
* 5. Call `dispose()` to clean up resources when the session ends.
|
|
76
|
+
*/
|
|
77
|
+
export declare class VoiceTransportAdapter {
|
|
78
|
+
private readonly config;
|
|
79
|
+
private readonly transport;
|
|
80
|
+
private readonly eventSink;
|
|
81
|
+
/**
|
|
82
|
+
* Lazily-initialised `VoicePipelineOrchestrator` instance.
|
|
83
|
+
* Typed as `any` to avoid a hard import cycle with the voice subsystem.
|
|
84
|
+
* In a full implementation this would be `VoicePipelineOrchestrator | null`.
|
|
85
|
+
*/
|
|
86
|
+
private pipeline;
|
|
87
|
+
/** Tracks whether `init()` has been called successfully. */
|
|
88
|
+
private initialized;
|
|
89
|
+
/**
|
|
90
|
+
* @param config - Voice pipeline configuration knobs.
|
|
91
|
+
* @param transport - Bidirectional audio/control stream transport (`IStreamTransport`).
|
|
92
|
+
* @param eventSink - Callback receiving all `GraphEvent` values emitted by this adapter.
|
|
93
|
+
*/
|
|
94
|
+
constructor(config: VoiceTransportConfig, transport: any, // IStreamTransport
|
|
95
|
+
eventSink: (event: GraphEvent) => void);
|
|
96
|
+
/**
|
|
97
|
+
* Initialise the adapter.
|
|
98
|
+
*
|
|
99
|
+
* Injects the `IStreamTransport` instance into `state.scratch.voiceTransport` so
|
|
100
|
+
* that graph nodes can access it if needed, then emits a `voice_session` started
|
|
101
|
+
* event to signal that the voice session is live.
|
|
102
|
+
*
|
|
103
|
+
* Must be called exactly once before {@link getNodeInput} or
|
|
104
|
+
* {@link deliverNodeOutput}.
|
|
105
|
+
*
|
|
106
|
+
* @param state - Mutable `GraphState` (or partial) for the current run.
|
|
107
|
+
* `state.scratch` is created lazily if absent.
|
|
108
|
+
*/
|
|
109
|
+
init(state: Partial<GraphState>): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Wait for the user's next speech turn and return the transcript text.
|
|
112
|
+
*
|
|
113
|
+
* In a full production implementation this delegates to
|
|
114
|
+
* `VoicePipelineOrchestrator.waitForUserTurn()`. In the current implementation
|
|
115
|
+
* it listens for a single `'turn_complete'` event from the underlying transport
|
|
116
|
+
* and resolves with the transcript text.
|
|
117
|
+
*
|
|
118
|
+
* Also emits a {@link GraphEvent} of type `voice_turn_complete` so that the
|
|
119
|
+
* runtime event bus stays in sync.
|
|
120
|
+
*
|
|
121
|
+
* @param nodeId - The id of the graph node requesting input; used to tag the emitted event.
|
|
122
|
+
* @returns Resolved transcript string from the user's speech turn.
|
|
123
|
+
* @throws {Error} If called before `init()`.
|
|
124
|
+
*/
|
|
125
|
+
getNodeInput(nodeId: string): Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Deliver a node's text output to the TTS engine.
|
|
128
|
+
*
|
|
129
|
+
* Accepts either a plain `string` or an `AsyncIterable<string>` of token
|
|
130
|
+
* chunks (e.g. a streaming LLM response). In a full production implementation
|
|
131
|
+
* this delegates to `VoicePipelineOrchestrator.pushToTTS(output)`.
|
|
132
|
+
*
|
|
133
|
+
* Emits a {@link GraphEvent} of type `voice_audio` (direction `'outbound'`)
|
|
134
|
+
* so that the runtime event bus records the TTS delivery.
|
|
135
|
+
*
|
|
136
|
+
* @param nodeId - The id of the graph node delivering the output.
|
|
137
|
+
* @param output - Text or async token stream to synthesise as speech.
|
|
138
|
+
* @throws {Error} If called before `init()`.
|
|
139
|
+
*/
|
|
140
|
+
deliverNodeOutput(nodeId: string, output: string | AsyncIterable<string>): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Handle a user barge-in at the transport level.
|
|
143
|
+
*
|
|
144
|
+
* Should be called by the runtime or transport layer when the user starts
|
|
145
|
+
* speaking while the agent is mid-utterance. Emits a `voice_barge_in` event
|
|
146
|
+
* so that graph event consumers can react (e.g. cancel pending tool calls).
|
|
147
|
+
*/
|
|
148
|
+
handleBargeIn(): void;
|
|
149
|
+
/**
|
|
150
|
+
* Dispose the adapter and emit a `voice_session` ended event.
|
|
151
|
+
*
|
|
152
|
+
* Marks the adapter as uninitialised so subsequent calls to `getNodeInput()`
|
|
153
|
+
* or `deliverNodeOutput()` will throw, preventing accidental use after teardown.
|
|
154
|
+
*/
|
|
155
|
+
dispose(): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=VoiceTransportAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoiceTransportAdapter.d.ts","sourceRoot":"","sources":["../../../src/orchestration/runtime/VoiceTransportAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1D;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAMD;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;IAiB9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAlB5B;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAo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