@llmrtc/llmrtc-core 1.0.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/LICENSE +201 -0
- package/README.md +25 -0
- package/dist/hooks.d.ts +345 -0
- package/dist/hooks.js +52 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/logging-hooks.d.ts +120 -0
- package/dist/logging-hooks.js +280 -0
- package/dist/logging-hooks.js.map +1 -0
- package/dist/metrics.d.ts +243 -0
- package/dist/metrics.js +241 -0
- package/dist/metrics.js.map +1 -0
- package/dist/orchestrator.d.ts +73 -0
- package/dist/orchestrator.js +450 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/playbook-engine.d.ts +140 -0
- package/dist/playbook-engine.js +390 -0
- package/dist/playbook-engine.js.map +1 -0
- package/dist/playbook-orchestrator.d.ts +193 -0
- package/dist/playbook-orchestrator.js +687 -0
- package/dist/playbook-orchestrator.js.map +1 -0
- package/dist/playbook.d.ts +220 -0
- package/dist/playbook.js +92 -0
- package/dist/playbook.js.map +1 -0
- package/dist/protocol.d.ts +327 -0
- package/dist/protocol.js +149 -0
- package/dist/protocol.js.map +1 -0
- package/dist/tool-executor.d.ts +64 -0
- package/dist/tool-executor.js +240 -0
- package/dist/tool-executor.js.map +1 -0
- package/dist/tools.d.ts +183 -0
- package/dist/tools.js +157 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +213 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playbook-orchestrator.js","sourceRoot":"","sources":["../src/playbook-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAwC,MAAM,sBAAsB,CAA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AC,CAAC;QAElF,MAAM;YACJ,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE;gBACJ,QAAQ,EAAE,WAAW,EAAE,OAAO,IAAI,EAAE;gBACpC,SAAS,EAAE,YAAY,CAAC,SAAS;gBACjC,YAAY;gBACZ,UAAU;gBACV,QAAQ;gBACR,YAAY,EAAE,YAAY,CAAC,YAAY;gBACvC,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,UAAU;aACxF;SACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,EAAU,EACV,YAAoB,EACpB,KAAwB;IAExB,OAAO;QACL,EAAE;QACF,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,CAAC;gBACP,EAAE,EAAE,MAAM;gBACV,IAAI,EAAE,MAAM;gBACZ,YAAY;gBACZ,KAAK;aACN,CAAC;QACF,WAAW,EAAE,EAAE;QACf,YAAY,EAAE,MAAM;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playbook Types
|
|
3
|
+
*
|
|
4
|
+
* Playbooks define multi-stage conversation flows with:
|
|
5
|
+
* - Stages: Named conversation states with their own system prompts, tools, and config
|
|
6
|
+
* - Transitions: Rules for moving between stages based on conditions
|
|
7
|
+
* - Two-phase turn execution: Phase 1 (tool loop) → Phase 2 (final answer)
|
|
8
|
+
*/
|
|
9
|
+
import type { ToolDefinition, ToolChoice } from './tools.js';
|
|
10
|
+
/**
|
|
11
|
+
* Condition for triggering a stage transition
|
|
12
|
+
*/
|
|
13
|
+
export type TransitionCondition = {
|
|
14
|
+
type: 'tool_call';
|
|
15
|
+
toolName: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'intent';
|
|
18
|
+
intent: string;
|
|
19
|
+
confidence?: number;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'keyword';
|
|
22
|
+
keywords: string[];
|
|
23
|
+
} | {
|
|
24
|
+
type: 'llm_decision';
|
|
25
|
+
} | {
|
|
26
|
+
type: 'max_turns';
|
|
27
|
+
count: number;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'timeout';
|
|
30
|
+
durationMs: number;
|
|
31
|
+
} | {
|
|
32
|
+
type: 'custom';
|
|
33
|
+
evaluate: (context: TransitionContext) => boolean | Promise<boolean>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Context passed to transition evaluators
|
|
37
|
+
*/
|
|
38
|
+
export interface TransitionContext {
|
|
39
|
+
/** Current stage ID */
|
|
40
|
+
currentStage: string;
|
|
41
|
+
/** Number of turns in current stage */
|
|
42
|
+
turnCount: number;
|
|
43
|
+
/** Time spent in current stage (ms) */
|
|
44
|
+
timeInStage: number;
|
|
45
|
+
/** Last assistant message */
|
|
46
|
+
lastAssistantMessage?: string;
|
|
47
|
+
/** Tool calls made in last turn */
|
|
48
|
+
lastToolCalls?: Array<{
|
|
49
|
+
name: string;
|
|
50
|
+
arguments: Record<string, unknown>;
|
|
51
|
+
}>;
|
|
52
|
+
/** Accumulated conversation context */
|
|
53
|
+
conversationContext: Record<string, unknown>;
|
|
54
|
+
/** Session metadata */
|
|
55
|
+
sessionMetadata: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Action to take when a transition is triggered
|
|
59
|
+
*/
|
|
60
|
+
export interface TransitionAction {
|
|
61
|
+
/** Target stage to transition to */
|
|
62
|
+
targetStage: string;
|
|
63
|
+
/** Optional message to inject before transitioning */
|
|
64
|
+
transitionMessage?: string;
|
|
65
|
+
/** Whether to clear conversation history on transition */
|
|
66
|
+
clearHistory?: boolean;
|
|
67
|
+
/** Data to pass to the target stage */
|
|
68
|
+
data?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A transition rule defining when and how to move between stages
|
|
72
|
+
*/
|
|
73
|
+
export interface Transition {
|
|
74
|
+
/** Unique identifier for this transition */
|
|
75
|
+
id: string;
|
|
76
|
+
/** Human-readable description */
|
|
77
|
+
description?: string;
|
|
78
|
+
/** Source stage (or '*' for any stage) */
|
|
79
|
+
from: string | '*';
|
|
80
|
+
/** Condition that triggers this transition */
|
|
81
|
+
condition: TransitionCondition;
|
|
82
|
+
/** Action to take when triggered */
|
|
83
|
+
action: TransitionAction;
|
|
84
|
+
/** Priority for conflict resolution (higher = evaluated first) */
|
|
85
|
+
priority?: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* LLM configuration overrides for a stage
|
|
89
|
+
*/
|
|
90
|
+
export interface StageLLMConfig {
|
|
91
|
+
/** Temperature for this stage */
|
|
92
|
+
temperature?: number;
|
|
93
|
+
/** Max tokens for this stage */
|
|
94
|
+
maxTokens?: number;
|
|
95
|
+
/** Top-p sampling */
|
|
96
|
+
topP?: number;
|
|
97
|
+
/** Custom model to use for this stage (if supported) */
|
|
98
|
+
model?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A stage in the playbook - represents a distinct conversation state
|
|
102
|
+
*/
|
|
103
|
+
export interface Stage {
|
|
104
|
+
/** Unique identifier for this stage */
|
|
105
|
+
id: string;
|
|
106
|
+
/** Human-readable name */
|
|
107
|
+
name: string;
|
|
108
|
+
/** Description of this stage's purpose */
|
|
109
|
+
description?: string;
|
|
110
|
+
/** System prompt for this stage */
|
|
111
|
+
systemPrompt: string;
|
|
112
|
+
/** Tools available in this stage */
|
|
113
|
+
tools?: ToolDefinition[];
|
|
114
|
+
/** Tool choice mode for this stage */
|
|
115
|
+
toolChoice?: ToolChoice;
|
|
116
|
+
/** LLM config overrides for this stage */
|
|
117
|
+
llmConfig?: StageLLMConfig;
|
|
118
|
+
/** Whether this stage uses two-phase execution (default: true) */
|
|
119
|
+
twoPhaseExecution?: boolean;
|
|
120
|
+
/** Max turns allowed in this stage before forcing transition */
|
|
121
|
+
maxTurns?: number;
|
|
122
|
+
/** Timeout for this stage in milliseconds */
|
|
123
|
+
timeoutMs?: number;
|
|
124
|
+
/** Entry hook - called when entering this stage */
|
|
125
|
+
onEnter?: (context: StageContext) => void | Promise<void>;
|
|
126
|
+
/** Exit hook - called when leaving this stage */
|
|
127
|
+
onExit?: (context: StageContext) => void | Promise<void>;
|
|
128
|
+
/** Custom data for this stage */
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Context passed to stage lifecycle hooks
|
|
133
|
+
*/
|
|
134
|
+
export interface StageContext {
|
|
135
|
+
/** The stage being entered/exited */
|
|
136
|
+
stage: Stage;
|
|
137
|
+
/** Previous stage (on enter) or next stage (on exit) */
|
|
138
|
+
otherStage?: Stage;
|
|
139
|
+
/** Data passed via transition */
|
|
140
|
+
transitionData?: Record<string, unknown>;
|
|
141
|
+
/** Session metadata */
|
|
142
|
+
sessionMetadata: Record<string, unknown>;
|
|
143
|
+
/** Conversation context accumulated across stages */
|
|
144
|
+
conversationContext: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A playbook defines the complete conversation flow
|
|
148
|
+
*/
|
|
149
|
+
export interface Playbook {
|
|
150
|
+
/** Unique identifier */
|
|
151
|
+
id: string;
|
|
152
|
+
/** Human-readable name */
|
|
153
|
+
name: string;
|
|
154
|
+
/** Description of what this playbook does */
|
|
155
|
+
description?: string;
|
|
156
|
+
/** Version string */
|
|
157
|
+
version?: string;
|
|
158
|
+
/** All stages in this playbook */
|
|
159
|
+
stages: Stage[];
|
|
160
|
+
/** All transitions between stages */
|
|
161
|
+
transitions: Transition[];
|
|
162
|
+
/** ID of the initial stage */
|
|
163
|
+
initialStage: string;
|
|
164
|
+
/** Global tools available in all stages */
|
|
165
|
+
globalTools?: ToolDefinition[];
|
|
166
|
+
/** Global system prompt prepended to all stage prompts */
|
|
167
|
+
globalSystemPrompt?: string;
|
|
168
|
+
/** Default LLM config for all stages */
|
|
169
|
+
defaultLLMConfig?: StageLLMConfig;
|
|
170
|
+
/** Custom metadata */
|
|
171
|
+
metadata?: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Current state of a playbook execution
|
|
175
|
+
*/
|
|
176
|
+
export interface PlaybookState {
|
|
177
|
+
/** Currently active stage */
|
|
178
|
+
currentStage: Stage;
|
|
179
|
+
/** Number of turns in current stage */
|
|
180
|
+
turnCount: number;
|
|
181
|
+
/** Timestamp when current stage was entered */
|
|
182
|
+
stageEnteredAt: number;
|
|
183
|
+
/** Accumulated conversation context */
|
|
184
|
+
conversationContext: Record<string, unknown>;
|
|
185
|
+
/** History of stage transitions */
|
|
186
|
+
transitionHistory: Array<{
|
|
187
|
+
from: string;
|
|
188
|
+
to: string;
|
|
189
|
+
transitionId: string;
|
|
190
|
+
timestamp: number;
|
|
191
|
+
}>;
|
|
192
|
+
/** Whether playbook execution is complete */
|
|
193
|
+
isComplete: boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Result of evaluating transitions
|
|
197
|
+
*/
|
|
198
|
+
export interface TransitionEvaluationResult {
|
|
199
|
+
/** Whether a transition should occur */
|
|
200
|
+
shouldTransition: boolean;
|
|
201
|
+
/** The matched transition (if any) */
|
|
202
|
+
transition?: Transition;
|
|
203
|
+
/** Reason for the decision */
|
|
204
|
+
reason: string;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Built-in tool for LLM-initiated stage transitions
|
|
208
|
+
*/
|
|
209
|
+
export declare const PLAYBOOK_TRANSITION_TOOL: ToolDefinition;
|
|
210
|
+
/**
|
|
211
|
+
* Validates a playbook definition
|
|
212
|
+
*/
|
|
213
|
+
export declare function validatePlaybook(playbook: Playbook): {
|
|
214
|
+
valid: boolean;
|
|
215
|
+
errors: string[];
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Creates a new playbook state for a given playbook
|
|
219
|
+
*/
|
|
220
|
+
export declare function createPlaybookState(playbook: Playbook): PlaybookState;
|
package/dist/playbook.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playbook Types
|
|
3
|
+
*
|
|
4
|
+
* Playbooks define multi-stage conversation flows with:
|
|
5
|
+
* - Stages: Named conversation states with their own system prompts, tools, and config
|
|
6
|
+
* - Transitions: Rules for moving between stages based on conditions
|
|
7
|
+
* - Two-phase turn execution: Phase 1 (tool loop) → Phase 2 (final answer)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Built-in tool for LLM-initiated stage transitions
|
|
11
|
+
*/
|
|
12
|
+
export const PLAYBOOK_TRANSITION_TOOL = {
|
|
13
|
+
name: 'playbook_transition',
|
|
14
|
+
description: 'Request a transition to a different conversation stage. Use this when the conversation should move to a different phase or topic that requires a different context.',
|
|
15
|
+
parameters: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
targetStage: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'The ID of the stage to transition to'
|
|
21
|
+
},
|
|
22
|
+
reason: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: 'Brief explanation of why this transition is appropriate'
|
|
25
|
+
},
|
|
26
|
+
data: {
|
|
27
|
+
type: 'object',
|
|
28
|
+
description: 'Optional data to pass to the target stage'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
required: ['targetStage', 'reason']
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Validates a playbook definition
|
|
36
|
+
*/
|
|
37
|
+
export function validatePlaybook(playbook) {
|
|
38
|
+
const errors = [];
|
|
39
|
+
const stageIds = new Set(playbook.stages.map(s => s.id));
|
|
40
|
+
// Check initial stage exists
|
|
41
|
+
if (!stageIds.has(playbook.initialStage)) {
|
|
42
|
+
errors.push(`Initial stage '${playbook.initialStage}' not found in stages`);
|
|
43
|
+
}
|
|
44
|
+
// Check for duplicate stage IDs
|
|
45
|
+
const seenStageIds = new Set();
|
|
46
|
+
for (const stage of playbook.stages) {
|
|
47
|
+
if (seenStageIds.has(stage.id)) {
|
|
48
|
+
errors.push(`Duplicate stage ID: '${stage.id}'`);
|
|
49
|
+
}
|
|
50
|
+
seenStageIds.add(stage.id);
|
|
51
|
+
}
|
|
52
|
+
// Check transitions reference valid stages
|
|
53
|
+
const seenTransitionIds = new Set();
|
|
54
|
+
for (const transition of playbook.transitions) {
|
|
55
|
+
if (seenTransitionIds.has(transition.id)) {
|
|
56
|
+
errors.push(`Duplicate transition ID: '${transition.id}'`);
|
|
57
|
+
}
|
|
58
|
+
seenTransitionIds.add(transition.id);
|
|
59
|
+
if (transition.from !== '*' && !stageIds.has(transition.from)) {
|
|
60
|
+
errors.push(`Transition '${transition.id}' references unknown source stage: '${transition.from}'`);
|
|
61
|
+
}
|
|
62
|
+
if (!stageIds.has(transition.action.targetStage)) {
|
|
63
|
+
errors.push(`Transition '${transition.id}' references unknown target stage: '${transition.action.targetStage}'`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Check for stages with no outgoing transitions (warning, not error)
|
|
67
|
+
for (const stage of playbook.stages) {
|
|
68
|
+
const hasOutgoing = playbook.transitions.some(t => t.from === stage.id || t.from === '*');
|
|
69
|
+
if (!hasOutgoing && playbook.stages.length > 1) {
|
|
70
|
+
// This is a terminal stage - acceptable but worth noting
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { valid: errors.length === 0, errors };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new playbook state for a given playbook
|
|
77
|
+
*/
|
|
78
|
+
export function createPlaybookState(playbook) {
|
|
79
|
+
const initialStage = playbook.stages.find(s => s.id === playbook.initialStage);
|
|
80
|
+
if (!initialStage) {
|
|
81
|
+
throw new Error(`Initial stage '${playbook.initialStage}' not found`);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
currentStage: initialStage,
|
|
85
|
+
turnCount: 0,
|
|
86
|
+
stageEnteredAt: Date.now(),
|
|
87
|
+
conversationContext: {},
|
|
88
|
+
transitionHistory: [],
|
|
89
|
+
isComplete: false
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=playbook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playbook.js","sourceRoot":"","sources":["../src/playbook.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiMH;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAmB;IACtD,IAAI,EAAE,qBAAqB;IAC3B,WAAW,EAAE,qKAAqK;IAClL,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,yDAAyD;aACvE;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,2CAA2C;aACzD;SACF;QACD,QAAQ,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC;KACpC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAkB;IACjD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEzD,6BAA6B;IAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,kBAAkB,QAAQ,CAAC,YAAY,uBAAu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AQ,CAAC,MAAM,EAAE,CAAC;QACpC,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAC3C,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,GAAG,CAC3C,CAAC;QACF,IAAI,CAAC,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/C,yDAAyD;QAC3D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB;IACpD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/E,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,YAAY,aAAa,CAAC,CAAC;IACxE,CAAC;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,IAAI,CAAC,GAAG,EAAE;QAC1B,mBAAmB,EAAE,EAAE;QACvB,iBAAiB,EAAE,EAAE;QACrB,UAAU,EAAE,KAAK;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @llmrtc/llmrtc Wire Protocol v1
|
|
3
|
+
*
|
|
4
|
+
* This file defines all JSON message types exchanged between
|
|
5
|
+
* the web-client and backend over WebSocket and WebRTC data channel.
|
|
6
|
+
*
|
|
7
|
+
* See PROTOCOL.md in the repository root for full documentation.
|
|
8
|
+
*/
|
|
9
|
+
import type { VisionAttachment } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Current protocol version.
|
|
12
|
+
* Exchanged during handshake in the 'ready' message.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
15
|
+
/**
|
|
16
|
+
* Base interface for all protocol messages
|
|
17
|
+
*/
|
|
18
|
+
export interface BaseMessage {
|
|
19
|
+
type: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Heartbeat ping from client
|
|
23
|
+
* Server responds with PongMessage
|
|
24
|
+
*/
|
|
25
|
+
export interface PingMessage extends BaseMessage {
|
|
26
|
+
type: 'ping';
|
|
27
|
+
/** Client timestamp (Date.now()) for RTT calculation */
|
|
28
|
+
timestamp: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* WebRTC SDP offer from client
|
|
32
|
+
* Initiates WebRTC peer connection
|
|
33
|
+
*/
|
|
34
|
+
export interface OfferMessage extends BaseMessage {
|
|
35
|
+
type: 'offer';
|
|
36
|
+
/** SDP offer from RTCPeerConnection.createOffer() */
|
|
37
|
+
signal: RTCSessionDescriptionInit;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Session reconnection request
|
|
41
|
+
* Client attempts to recover a previous session after disconnect
|
|
42
|
+
*/
|
|
43
|
+
export interface ReconnectMessage extends BaseMessage {
|
|
44
|
+
type: 'reconnect';
|
|
45
|
+
/** Previous session ID to recover */
|
|
46
|
+
sessionId: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Audio data for transcription (legacy/fallback)
|
|
50
|
+
* Prefer WebRTC audio track for lower latency
|
|
51
|
+
*/
|
|
52
|
+
export interface AudioMessage extends BaseMessage {
|
|
53
|
+
type: 'audio';
|
|
54
|
+
/** Base64-encoded audio buffer (WAV or other format) */
|
|
55
|
+
data: string;
|
|
56
|
+
/** Optional vision attachments to include with this audio */
|
|
57
|
+
attachments?: VisionAttachment[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Vision attachments sent via data channel
|
|
61
|
+
* Queued and sent with next speech segment
|
|
62
|
+
*/
|
|
63
|
+
export interface AttachmentsMessage extends BaseMessage {
|
|
64
|
+
type: 'attachments';
|
|
65
|
+
/** Array of image attachments */
|
|
66
|
+
attachments: VisionAttachment[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Union of all client-to-server message types
|
|
70
|
+
*/
|
|
71
|
+
export type ClientMessage = PingMessage | OfferMessage | ReconnectMessage | AudioMessage | AttachmentsMessage;
|
|
72
|
+
/**
|
|
73
|
+
* Connection ready notification
|
|
74
|
+
* Sent immediately after WebSocket connection is established
|
|
75
|
+
*/
|
|
76
|
+
export interface ReadyMessage extends BaseMessage {
|
|
77
|
+
type: 'ready';
|
|
78
|
+
/** Unique session ID assigned by server */
|
|
79
|
+
id: string;
|
|
80
|
+
/** Protocol version for compatibility checking */
|
|
81
|
+
protocolVersion: number;
|
|
82
|
+
/** ICE servers for WebRTC (STUN/TURN) - provided by server for client use */
|
|
83
|
+
iceServers?: RTCIceServer[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Heartbeat pong response
|
|
87
|
+
* Echoes client timestamp for RTT calculation
|
|
88
|
+
*/
|
|
89
|
+
export interface PongMessage extends BaseMessage {
|
|
90
|
+
type: 'pong';
|
|
91
|
+
/** Echoed from PingMessage.timestamp */
|
|
92
|
+
timestamp: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* WebRTC SDP answer from server
|
|
96
|
+
* Response to client's OfferMessage
|
|
97
|
+
*/
|
|
98
|
+
export interface SignalMessage extends BaseMessage {
|
|
99
|
+
type: 'signal';
|
|
100
|
+
/** SDP answer from server's RTCPeerConnection */
|
|
101
|
+
signal: RTCSessionDescriptionInit;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Session reconnection acknowledgment
|
|
105
|
+
*/
|
|
106
|
+
export interface ReconnectAckMessage extends BaseMessage {
|
|
107
|
+
type: 'reconnect-ack';
|
|
108
|
+
/** Whether reconnection was successful */
|
|
109
|
+
success: boolean;
|
|
110
|
+
/** Session ID (may be new if original not found) */
|
|
111
|
+
sessionId: string;
|
|
112
|
+
/** Whether conversation history was recovered */
|
|
113
|
+
historyRecovered: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Speech-to-text transcription result
|
|
117
|
+
*/
|
|
118
|
+
export interface TranscriptMessage extends BaseMessage {
|
|
119
|
+
type: 'transcript';
|
|
120
|
+
/** Transcribed text */
|
|
121
|
+
text: string;
|
|
122
|
+
/** Whether this is the final transcription */
|
|
123
|
+
isFinal: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* LLM response chunk (streaming)
|
|
127
|
+
*/
|
|
128
|
+
export interface LLMChunkMessage extends BaseMessage {
|
|
129
|
+
type: 'llm-chunk';
|
|
130
|
+
/** Partial response content */
|
|
131
|
+
content: string;
|
|
132
|
+
/** Whether this is the final chunk */
|
|
133
|
+
done: boolean;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Complete LLM response
|
|
137
|
+
*/
|
|
138
|
+
export interface LLMMessage extends BaseMessage {
|
|
139
|
+
type: 'llm';
|
|
140
|
+
/** Full response text */
|
|
141
|
+
text: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* TTS playback starting
|
|
145
|
+
* Sent before first audio chunk
|
|
146
|
+
*/
|
|
147
|
+
export interface TTSStartMessage extends BaseMessage {
|
|
148
|
+
type: 'tts-start';
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* TTS audio chunk (streaming)
|
|
152
|
+
* Sent when WebRTC audio track is not available
|
|
153
|
+
*/
|
|
154
|
+
export interface TTSChunkMessage extends BaseMessage {
|
|
155
|
+
type: 'tts-chunk';
|
|
156
|
+
/** Audio format (e.g., 'pcm', 'mp3') */
|
|
157
|
+
format: string;
|
|
158
|
+
/** Sample rate in Hz */
|
|
159
|
+
sampleRate: number;
|
|
160
|
+
/** Base64-encoded audio data */
|
|
161
|
+
data: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Complete TTS audio (non-streaming)
|
|
165
|
+
* Sent when WebRTC audio track is not available
|
|
166
|
+
*/
|
|
167
|
+
export interface TTSMessage extends BaseMessage {
|
|
168
|
+
type: 'tts';
|
|
169
|
+
/** Audio format (e.g., 'mp3', 'wav') */
|
|
170
|
+
format: string;
|
|
171
|
+
/** Base64-encoded audio data */
|
|
172
|
+
data: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* TTS playback complete
|
|
176
|
+
* Sent after all audio has been delivered
|
|
177
|
+
*/
|
|
178
|
+
export interface TTSCompleteMessage extends BaseMessage {
|
|
179
|
+
type: 'tts-complete';
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* TTS playback cancelled
|
|
183
|
+
* Sent when user interrupts (barge-in)
|
|
184
|
+
*/
|
|
185
|
+
export interface TTSCancelledMessage extends BaseMessage {
|
|
186
|
+
type: 'tts-cancelled';
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* VAD detected speech start
|
|
190
|
+
* User has started speaking
|
|
191
|
+
*/
|
|
192
|
+
export interface SpeechStartMessage extends BaseMessage {
|
|
193
|
+
type: 'speech-start';
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* VAD detected speech end
|
|
197
|
+
* User has stopped speaking, processing begins
|
|
198
|
+
*/
|
|
199
|
+
export interface SpeechEndMessage extends BaseMessage {
|
|
200
|
+
type: 'speech-end';
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Tool call started
|
|
204
|
+
* Sent when PlaybookOrchestrator begins executing a tool
|
|
205
|
+
*/
|
|
206
|
+
export interface ToolCallStartMessage extends BaseMessage {
|
|
207
|
+
type: 'tool-call-start';
|
|
208
|
+
/** Tool function name */
|
|
209
|
+
name: string;
|
|
210
|
+
/** Unique call ID for correlation with tool-call-end */
|
|
211
|
+
callId: string;
|
|
212
|
+
/** Arguments passed to the tool */
|
|
213
|
+
arguments: Record<string, unknown>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Tool call completed
|
|
217
|
+
* Sent when tool execution finishes (success or failure)
|
|
218
|
+
*/
|
|
219
|
+
export interface ToolCallEndMessage extends BaseMessage {
|
|
220
|
+
type: 'tool-call-end';
|
|
221
|
+
/** Unique call ID matching tool-call-start */
|
|
222
|
+
callId: string;
|
|
223
|
+
/** Tool execution result (on success) */
|
|
224
|
+
result?: unknown;
|
|
225
|
+
/** Error message (on failure) */
|
|
226
|
+
error?: string;
|
|
227
|
+
/** Execution duration in milliseconds */
|
|
228
|
+
durationMs: number;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Stage transition in playbook
|
|
232
|
+
* Sent when PlaybookOrchestrator moves to a different stage
|
|
233
|
+
*/
|
|
234
|
+
export interface StageChangeMessage extends BaseMessage {
|
|
235
|
+
type: 'stage-change';
|
|
236
|
+
/** Previous stage name */
|
|
237
|
+
from: string;
|
|
238
|
+
/** New stage name */
|
|
239
|
+
to: string;
|
|
240
|
+
/** Reason for transition (e.g., tool result, keyword match) */
|
|
241
|
+
reason: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Error codes for structured error messages
|
|
245
|
+
*
|
|
246
|
+
* Error codes are grouped by category:
|
|
247
|
+
* - WebRTC/Connection: WEBRTC_*, CONNECTION_*, SESSION_*
|
|
248
|
+
* - Provider: STT_*, LLM_*, TTS_*
|
|
249
|
+
* - Processing: AUDIO_*, VAD_*, INVALID_*
|
|
250
|
+
* - Generic: INTERNAL_*, RATE_LIMITED
|
|
251
|
+
*/
|
|
252
|
+
export type ErrorCode = 'WEBRTC_UNAVAILABLE' | 'CONNECTION_FAILED' | 'SESSION_NOT_FOUND' | 'SESSION_EXPIRED' | 'STT_ERROR' | 'STT_TIMEOUT' | 'LLM_ERROR' | 'LLM_TIMEOUT' | 'TTS_ERROR' | 'TTS_TIMEOUT' | 'AUDIO_PROCESSING_ERROR' | 'VAD_ERROR' | 'INVALID_MESSAGE' | 'INVALID_AUDIO_FORMAT' | 'TOOL_ERROR' | 'PLAYBOOK_ERROR' | 'INTERNAL_ERROR' | 'RATE_LIMITED';
|
|
253
|
+
/**
|
|
254
|
+
* Error message from server
|
|
255
|
+
*/
|
|
256
|
+
export interface ErrorMessage extends BaseMessage {
|
|
257
|
+
type: 'error';
|
|
258
|
+
/** Structured error code */
|
|
259
|
+
code: ErrorCode;
|
|
260
|
+
/** Human-readable error description */
|
|
261
|
+
message: string;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Union of all server-to-client message types
|
|
265
|
+
*/
|
|
266
|
+
export type ServerMessage = ReadyMessage | PongMessage | SignalMessage | ReconnectAckMessage | TranscriptMessage | LLMChunkMessage | LLMMessage | TTSStartMessage | TTSChunkMessage | TTSMessage | TTSCompleteMessage | TTSCancelledMessage | SpeechStartMessage | SpeechEndMessage | ToolCallStartMessage | ToolCallEndMessage | StageChangeMessage | ErrorMessage;
|
|
267
|
+
/**
|
|
268
|
+
* Union of all protocol messages
|
|
269
|
+
*/
|
|
270
|
+
export type ProtocolMessage = ClientMessage | ServerMessage;
|
|
271
|
+
/**
|
|
272
|
+
* Check if a message is a client-to-server message
|
|
273
|
+
*/
|
|
274
|
+
export declare function isClientMessage(msg: ProtocolMessage): msg is ClientMessage;
|
|
275
|
+
/**
|
|
276
|
+
* Check if a message is a server-to-client message
|
|
277
|
+
*/
|
|
278
|
+
export declare function isServerMessage(msg: ProtocolMessage): msg is ServerMessage;
|
|
279
|
+
/**
|
|
280
|
+
* Check if a message is an error message
|
|
281
|
+
*/
|
|
282
|
+
export declare function isErrorMessage(msg: ProtocolMessage): msg is ErrorMessage;
|
|
283
|
+
/**
|
|
284
|
+
* Parse and validate a JSON message
|
|
285
|
+
* Returns null if parsing fails or message type is unknown
|
|
286
|
+
*/
|
|
287
|
+
export declare function parseMessage(json: string): ProtocolMessage | null;
|
|
288
|
+
/**
|
|
289
|
+
* Create a ready message
|
|
290
|
+
*/
|
|
291
|
+
export declare function createReadyMessage(id: string, iceServers?: RTCIceServer[]): ReadyMessage;
|
|
292
|
+
/**
|
|
293
|
+
* Create an error message
|
|
294
|
+
*/
|
|
295
|
+
export declare function createErrorMessage(code: ErrorCode, message: string): ErrorMessage;
|
|
296
|
+
/**
|
|
297
|
+
* Create a transcript message
|
|
298
|
+
*/
|
|
299
|
+
export declare function createTranscriptMessage(text: string, isFinal: boolean): TranscriptMessage;
|
|
300
|
+
/**
|
|
301
|
+
* Create an LLM chunk message
|
|
302
|
+
*/
|
|
303
|
+
export declare function createLLMChunkMessage(content: string, done: boolean): LLMChunkMessage;
|
|
304
|
+
/**
|
|
305
|
+
* Create an LLM message
|
|
306
|
+
*/
|
|
307
|
+
export declare function createLLMMessage(text: string): LLMMessage;
|
|
308
|
+
/**
|
|
309
|
+
* Create a TTS chunk message
|
|
310
|
+
*/
|
|
311
|
+
export declare function createTTSChunkMessage(data: string, format: string, sampleRate: number): TTSChunkMessage;
|
|
312
|
+
/**
|
|
313
|
+
* Create a TTS message
|
|
314
|
+
*/
|
|
315
|
+
export declare function createTTSMessage(data: string, format: string): TTSMessage;
|
|
316
|
+
/**
|
|
317
|
+
* Create a tool call start message
|
|
318
|
+
*/
|
|
319
|
+
export declare function createToolCallStartMessage(name: string, callId: string, args: Record<string, unknown>): ToolCallStartMessage;
|
|
320
|
+
/**
|
|
321
|
+
* Create a tool call end message
|
|
322
|
+
*/
|
|
323
|
+
export declare function createToolCallEndMessage(callId: string, durationMs: number, result?: unknown, error?: string): ToolCallEndMessage;
|
|
324
|
+
/**
|
|
325
|
+
* Create a stage change message
|
|
326
|
+
*/
|
|
327
|
+
export declare function createStageChangeMessage(from: string, to: string, reason: string): StageChangeMessage;
|