@kuralle-agents/core 0.12.0 → 0.14.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 +89 -4
- package/dist/ai-sdk/uiMessageStream.d.ts +2 -2
- package/dist/ai-sdk/uiMessageStream.js +42 -29
- package/dist/capabilities/LivePromptAssembler.d.ts +1 -1
- package/dist/capabilities/LivePromptAssembler.js +2 -1
- package/dist/capabilities/index.d.ts +1 -1
- package/dist/eval/EvalRunner.js +4 -4
- package/dist/eval/simulation.js +4 -3
- package/dist/events/TurnHandle.d.ts +3 -3
- package/dist/flow/collectDigression.d.ts +5 -2
- package/dist/flow/collectDigression.js +48 -10
- package/dist/flow/collectUntilComplete.js +13 -5
- package/dist/flow/degrade.js +8 -4
- package/dist/flow/emitInteractive.d.ts +2 -2
- package/dist/flow/emitInteractive.js +6 -3
- package/dist/flow/extraction.d.ts +3 -2
- package/dist/flow/extraction.js +14 -4
- package/dist/flow/reduceTransition.d.ts +2 -2
- package/dist/flow/reduceTransition.js +7 -3
- package/dist/flow/runFlow.js +97 -17
- package/dist/foundation/AgentStateController.d.ts +1 -1
- package/dist/foundation/ToolExecutor.d.ts +2 -2
- package/dist/foundation/index.d.ts +0 -11
- package/dist/foundation/index.js +0 -5
- package/dist/index.d.ts +15 -15
- package/dist/index.js +9 -6
- package/dist/outcomes/streamPart.d.ts +2 -2
- package/dist/outcomes/streamPart.js +2 -3
- package/dist/prompts/PromptBuilder.d.ts +3 -3
- package/dist/prompts/PromptBuilder.js +13 -6
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/types.d.ts +9 -2
- package/dist/runtime/InMemoryRetrievalCache.d.ts +25 -0
- package/dist/runtime/InMemoryRetrievalCache.js +59 -0
- package/dist/runtime/KnowledgeProvider.d.ts +3 -2
- package/dist/runtime/KnowledgeProvider.js +60 -31
- package/dist/runtime/Runtime.d.ts +47 -1
- package/dist/runtime/Runtime.js +273 -36
- package/dist/runtime/TokenAccumulator.d.ts +7 -0
- package/dist/runtime/TokenAccumulator.js +7 -0
- package/dist/runtime/TraceRecorder.d.ts +51 -0
- package/dist/runtime/TraceRecorder.js +326 -0
- package/dist/runtime/buildAgentToolSurface.js +1 -1
- package/dist/runtime/channels/TextDriver.js +57 -31
- package/dist/runtime/channels/executeModelTool.d.ts +14 -1
- package/dist/runtime/channels/executeModelTool.js +132 -3
- package/dist/runtime/channels/extractionTurn.js +1 -1
- package/dist/runtime/channels/index.d.ts +0 -3
- package/dist/runtime/channels/index.js +0 -6
- package/dist/runtime/channels/inputBuffer.d.ts +1 -0
- package/dist/runtime/channels/inputBuffer.js +9 -0
- package/dist/runtime/channels/streaming/hostControlSpeak.js +5 -1
- package/dist/runtime/channels/streaming/speakGated.js +24 -12
- package/dist/runtime/citations/index.d.ts +3 -3
- package/dist/runtime/closeRun.js +14 -10
- package/dist/runtime/compaction.d.ts +2 -0
- package/dist/runtime/compaction.js +3 -2
- package/dist/runtime/controlFlowSignal.d.ts +24 -0
- package/dist/runtime/controlFlowSignal.js +29 -0
- package/dist/runtime/ctx.d.ts +3 -4
- package/dist/runtime/ctx.js +147 -60
- package/dist/runtime/durable/RunStore.d.ts +16 -0
- package/dist/runtime/durable/RunStore.js +7 -1
- package/dist/runtime/durable/SessionRunStore.d.ts +7 -2
- package/dist/runtime/durable/SessionRunStore.js +136 -34
- package/dist/runtime/durable/idempotency.d.ts +1 -0
- package/dist/runtime/durable/idempotency.js +3 -0
- package/dist/runtime/durable/replay.js +7 -2
- package/dist/runtime/durable/types.d.ts +11 -0
- package/dist/runtime/goals.d.ts +18 -0
- package/dist/runtime/goals.js +158 -0
- package/dist/runtime/grounding/gather.d.ts +1 -1
- package/dist/runtime/grounding/inMemoryKnowledge.d.ts +1 -1
- package/dist/runtime/grounding/knowledge.d.ts +1 -1
- package/dist/runtime/grounding/knowledge.js +1 -1
- package/dist/runtime/handoffContinuation.d.ts +20 -0
- package/dist/runtime/handoffContinuation.js +30 -0
- package/dist/runtime/handoffOscillation.d.ts +6 -0
- package/dist/runtime/handoffOscillation.js +17 -0
- package/dist/runtime/hostLoop.js +37 -6
- package/dist/runtime/index.d.ts +4 -3
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/openRun.d.ts +2 -0
- package/dist/runtime/openRun.js +46 -17
- package/dist/runtime/outcomeMarking.d.ts +2 -2
- package/dist/runtime/outcomeMarking.js +2 -1
- package/dist/runtime/policies/agentTurn.d.ts +1 -1
- package/dist/runtime/policies/limits.d.ts +1 -0
- package/dist/runtime/policies/limits.js +3 -0
- package/dist/runtime/runHookSafely.d.ts +3 -0
- package/dist/runtime/runHookSafely.js +19 -0
- package/dist/runtime/select.d.ts +5 -1
- package/dist/runtime/select.js +30 -1
- package/dist/runtime/turnTokenUsage.d.ts +28 -0
- package/dist/runtime/turnTokenUsage.js +70 -0
- package/dist/scheduler/index.d.ts +2 -2
- package/dist/scheduler/index.js +1 -1
- package/dist/services/TracingService.js +2 -3
- package/dist/session/SessionStore.d.ts +6 -0
- package/dist/session/SessionStore.js +12 -1
- package/dist/session/stores/MemoryStore.d.ts +1 -1
- package/dist/session/stores/MemoryStore.js +16 -2
- package/dist/session/testing.d.ts +6 -1
- package/dist/session/testing.js +34 -0
- package/dist/session/utils.d.ts +3 -0
- package/dist/session/utils.js +23 -0
- package/dist/skills/collectSkills.d.ts +11 -3
- package/dist/skills/collectSkills.js +51 -8
- package/dist/skills/compositeSkillStore.d.ts +26 -0
- package/dist/skills/compositeSkillStore.js +54 -0
- package/dist/skills/defineSkill.d.ts +21 -0
- package/dist/skills/defineSkill.js +26 -0
- package/dist/skills/fsSkillStore.d.ts +3 -0
- package/dist/skills/fsSkillStore.js +79 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +4 -0
- package/dist/skills/parseSkillFrontmatter.d.ts +14 -0
- package/dist/skills/parseSkillFrontmatter.js +183 -0
- package/dist/skills/wireAgentSkills.d.ts +2 -1
- package/dist/skills/wireAgentSkills.js +2 -2
- package/dist/testing/mocks.d.ts +3 -3
- package/dist/testing/mocks.js +7 -3
- package/dist/tools/controlResults.d.ts +14 -0
- package/dist/tools/controlResults.js +15 -0
- package/dist/tools/effect/ToolExecutor.d.ts +6 -0
- package/dist/tools/effect/ToolExecutor.js +75 -36
- package/dist/tools/effect/defineTool.d.ts +11 -0
- package/dist/tools/effect/defineTool.js +3 -0
- package/dist/tools/effect/errors.d.ts +2 -5
- package/dist/tools/effect/errors.js +2 -5
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tracing/MemoryTraceStore.d.ts +16 -0
- package/dist/tracing/MemoryTraceStore.js +56 -0
- package/dist/tracing/OtelTraceSink.d.ts +127 -0
- package/dist/tracing/OtelTraceSink.js +101 -0
- package/dist/tracing/TraceStore.d.ts +19 -0
- package/dist/tracing/TraceStore.js +32 -0
- package/dist/tracing/index.d.ts +3 -0
- package/dist/tracing/index.js +3 -0
- package/dist/tracing/testing.d.ts +3 -0
- package/dist/tracing/testing.js +45 -0
- package/dist/types/agentConfig.d.ts +2 -1
- package/dist/types/channel.d.ts +14 -1
- package/dist/types/effectTool.d.ts +6 -0
- package/dist/types/flow.d.ts +1 -1
- package/dist/types/guardrails.d.ts +5 -0
- package/dist/types/hooks.d.ts +2 -2
- package/dist/types/index.d.ts +25 -15
- package/dist/types/index.js +8 -12
- package/dist/types/knowledge.d.ts +213 -0
- package/dist/types/processors.d.ts +0 -58
- package/dist/types/run-context.d.ts +16 -7
- package/dist/types/runtime.d.ts +3 -74
- package/dist/types/session.d.ts +11 -1
- package/dist/types/skills.d.ts +15 -1
- package/dist/types/stream.d.ts +138 -68
- package/dist/types/stream.js +34 -1
- package/dist/types/trace.d.ts +52 -0
- package/guides/AGENTS.md +3 -3
- package/guides/EXAMPLE_VERIFICATION.md +4 -4
- package/guides/FLOWS.md +1 -1
- package/guides/GETTING_STARTED.md +1 -1
- package/guides/RUNTIME.md +20 -15
- package/guides/TOOLS.md +1 -1
- package/package.json +13 -14
- package/dist/foundation/AgentDefinition.d.ts +0 -17
- package/dist/foundation/ConversationEventLog.d.ts +0 -71
- package/dist/foundation/ConversationState.d.ts +0 -33
- package/dist/foundation/ConversationState.js +0 -1
- package/dist/foundation/DefaultConversationEventLog.d.ts +0 -27
- package/dist/foundation/DefaultConversationEventLog.js +0 -205
- package/dist/foundation/DefaultConversationState.d.ts +0 -36
- package/dist/foundation/DefaultConversationState.js +0 -103
- package/dist/foundation/DefaultToolExecutor.d.ts +0 -57
- package/dist/foundation/DefaultToolExecutor.js +0 -132
- package/dist/foundation/createFoundation.d.ts +0 -32
- package/dist/foundation/createFoundation.js +0 -33
- package/dist/hooks/HookRunner.d.ts +0 -37
- package/dist/hooks/HookRunner.js +0 -111
- package/dist/hooks/builtin/logging.d.ts +0 -5
- package/dist/hooks/builtin/logging.js +0 -98
- package/dist/hooks/builtin/metrics.d.ts +0 -7
- package/dist/hooks/builtin/metrics.js +0 -60
- package/dist/hooks/builtin/observability.d.ts +0 -20
- package/dist/hooks/builtin/observability.js +0 -572
- package/dist/hooks/helpers.d.ts +0 -22
- package/dist/hooks/helpers.js +0 -183
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -6
- package/dist/realtime/RealtimeAudioClient.d.ts +0 -166
- package/dist/realtime/RealtimeAudioClient.js +0 -14
- package/dist/realtime/RealtimeSessionHandle.d.ts +0 -6
- package/dist/realtime/RealtimeSessionHandle.js +0 -1
- package/dist/realtime/index.d.ts +0 -2
- package/dist/realtime/index.js +0 -1
- package/dist/runtime/channels/VoiceDriver.d.ts +0 -31
- package/dist/runtime/channels/VoiceDriver.js +0 -321
- package/dist/runtime/channels/voiceTools.d.ts +0 -9
- package/dist/runtime/channels/voiceTools.js +0 -51
- package/dist/tools/errorHandling.d.ts +0 -35
- package/dist/tools/errorHandling.js +0 -145
- package/dist/types/voice.d.ts +0 -517
- package/dist/types/voice.js +0 -14
- package/dist/utils/isRecord.d.ts +0 -1
- package/dist/utils/isRecord.js +0 -3
- package/dist/utils/messageNormalization.d.ts +0 -2
- package/dist/utils/messageNormalization.js +0 -137
- /package/dist/{foundation/AgentDefinition.js → types/knowledge.js} +0 -0
- /package/dist/{foundation/ConversationEventLog.js → types/trace.js} +0 -0
package/dist/hooks/helpers.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { TracingService } from '../services/TracingService.js';
|
|
2
|
-
import { InMemoryMetricsService } from '../services/MetricsService.js';
|
|
3
|
-
// Legacy Singleton for backward compatibility
|
|
4
|
-
const defaultTracingService = new TracingService();
|
|
5
|
-
let defaultMetricsService = null;
|
|
6
|
-
// Re-export specific legacy functions delegated to services
|
|
7
|
-
export function initTracing(config) {
|
|
8
|
-
defaultTracingService.init(config);
|
|
9
|
-
}
|
|
10
|
-
export function startSpan(name, attributes, parentSpanId) {
|
|
11
|
-
return defaultTracingService.startSpan(name, attributes, parentSpanId);
|
|
12
|
-
}
|
|
13
|
-
export function endSpan(span, status, error) {
|
|
14
|
-
return defaultTracingService.endSpan(span, status, error);
|
|
15
|
-
}
|
|
16
|
-
export function addSpanEvent(span, name, attributes) {
|
|
17
|
-
defaultTracingService.addSpanEvent(span, name, attributes);
|
|
18
|
-
}
|
|
19
|
-
export function getCurrentSpan() {
|
|
20
|
-
return defaultTracingService.getCurrentSpan();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Creates tracing hooks.
|
|
24
|
-
* @param service Optional TracingService instance. If not provided, uses the global singleton (legacy).
|
|
25
|
-
*/
|
|
26
|
-
export function createTracingHooks(service = defaultTracingService) {
|
|
27
|
-
return {
|
|
28
|
-
onAgentStart: async (context, agentId) => {
|
|
29
|
-
service.startSpan('agent.run', { agentId, sessionId: context.session.id });
|
|
30
|
-
},
|
|
31
|
-
onAgentEnd: async (context) => {
|
|
32
|
-
const span = service.getCurrentSpan();
|
|
33
|
-
if (span) {
|
|
34
|
-
service.endSpan(span, 'success');
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
onStepStart: async (context, step) => {
|
|
38
|
-
service.startSpan('agent.step', { step, agentId: context.agentId });
|
|
39
|
-
},
|
|
40
|
-
onStepEnd: async (context, step, result) => {
|
|
41
|
-
const span = service.getCurrentSpan();
|
|
42
|
-
if (span) {
|
|
43
|
-
service.endSpan(span, 'success');
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
onToolCall: async (context, call) => {
|
|
47
|
-
service.startSpan('tool.call', {
|
|
48
|
-
toolName: call.toolName,
|
|
49
|
-
toolCallId: call.toolCallId,
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
onToolResult: async (context, call) => {
|
|
53
|
-
const span = service.getCurrentSpan();
|
|
54
|
-
if (span) {
|
|
55
|
-
service.addSpanEvent(span, 'tool.result', {
|
|
56
|
-
success: String(call.success),
|
|
57
|
-
durationMs: call.durationMs ?? 0,
|
|
58
|
-
});
|
|
59
|
-
service.endSpan(span, call.success ? 'success' : 'error', call.error);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
onHandoff: async (context, from, to, reason) => {
|
|
63
|
-
service.startSpan('agent.handoff', { from, to, reason });
|
|
64
|
-
service.endSpan(service.getCurrentSpan(), 'success');
|
|
65
|
-
},
|
|
66
|
-
onError: async (context, error) => {
|
|
67
|
-
const span = service.getCurrentSpan();
|
|
68
|
-
if (span) {
|
|
69
|
-
service.endSpan(span, 'error', error);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
// Metrics delegation
|
|
75
|
-
export function createObservabilityMetrics(config = {}) {
|
|
76
|
-
return new InMemoryMetricsService(config);
|
|
77
|
-
}
|
|
78
|
-
export function initMetrics(metrics) {
|
|
79
|
-
defaultMetricsService = metrics;
|
|
80
|
-
}
|
|
81
|
-
export function getMetrics() {
|
|
82
|
-
if (!defaultMetricsService) {
|
|
83
|
-
throw new Error('Metrics not initialized. Call initMetrics() first.');
|
|
84
|
-
}
|
|
85
|
-
return defaultMetricsService;
|
|
86
|
-
}
|
|
87
|
-
export function createObservabilityHooks(service = getMetrics()) {
|
|
88
|
-
const metrics = service;
|
|
89
|
-
return {
|
|
90
|
-
onStart: async (context) => {
|
|
91
|
-
metrics.increment('run.start', 1, { agent: context.agentId });
|
|
92
|
-
metrics.gauge('run.active', 1);
|
|
93
|
-
},
|
|
94
|
-
onEnd: async (context, result) => {
|
|
95
|
-
const duration = Date.now() - context.startTime;
|
|
96
|
-
metrics.increment(result.success ? 'run.success' : 'run.failure');
|
|
97
|
-
metrics.gauge('run.active', -1);
|
|
98
|
-
metrics.timing('run.duration', duration);
|
|
99
|
-
metrics.histogram('run.steps', context.stepCount);
|
|
100
|
-
metrics.histogram('run.tokens', context.totalTokens);
|
|
101
|
-
metrics.histogram('run.handoffs', context.handoffStack.length);
|
|
102
|
-
},
|
|
103
|
-
onStepStart: async (context, step) => {
|
|
104
|
-
metrics.increment('step.start', 1, { agent: context.agentId });
|
|
105
|
-
},
|
|
106
|
-
onStepEnd: async (context, step, result) => {
|
|
107
|
-
metrics.increment('step.end', 1, { agent: context.agentId, reason: result.finishReason });
|
|
108
|
-
},
|
|
109
|
-
onToolCall: async (context, call) => {
|
|
110
|
-
metrics.increment('tool.call', 1, { tool: call.toolName });
|
|
111
|
-
},
|
|
112
|
-
onToolResult: async (context, call) => {
|
|
113
|
-
metrics.increment('tool.result', 1, { tool: call.toolName, success: String(call.success) });
|
|
114
|
-
if (call.durationMs) {
|
|
115
|
-
metrics.timing('tool.duration', call.durationMs, { tool: call.toolName });
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
onToolError: async (context, call) => {
|
|
119
|
-
metrics.increment('tool.error', 1, { tool: call.toolName });
|
|
120
|
-
},
|
|
121
|
-
onHandoff: async (context, from, to) => {
|
|
122
|
-
metrics.increment('handoff', 1, { from, to });
|
|
123
|
-
},
|
|
124
|
-
onError: async () => {
|
|
125
|
-
metrics.increment('error', 1);
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
export function captureSessionTelemetry(context, result) {
|
|
130
|
-
return {
|
|
131
|
-
sessionId: context.session.id,
|
|
132
|
-
agentId: context.agentId,
|
|
133
|
-
startTime: new Date(context.startTime),
|
|
134
|
-
endTime: new Date(),
|
|
135
|
-
duration: Date.now() - context.startTime,
|
|
136
|
-
steps: context.stepCount,
|
|
137
|
-
tokens: context.totalTokens,
|
|
138
|
-
toolCalls: context.toolCallHistory.length,
|
|
139
|
-
errors: context.toolCallHistory.filter(c => !c.success).length,
|
|
140
|
-
handoffs: context.handoffStack.length,
|
|
141
|
-
success: result.success,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
export function createTelemetryHooks() {
|
|
145
|
-
const sessions = [];
|
|
146
|
-
return {
|
|
147
|
-
onStart: async (context) => {
|
|
148
|
-
sessions.push({
|
|
149
|
-
sessionId: context.session.id,
|
|
150
|
-
agentId: context.agentId,
|
|
151
|
-
startTime: new Date(),
|
|
152
|
-
steps: 0,
|
|
153
|
-
tokens: 0,
|
|
154
|
-
toolCalls: 0,
|
|
155
|
-
errors: 0,
|
|
156
|
-
handoffs: 0,
|
|
157
|
-
success: false,
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
onEnd: async (context, result) => {
|
|
161
|
-
const session = sessions.find(s => s.sessionId === context.session.id);
|
|
162
|
-
if (session) {
|
|
163
|
-
session.endTime = new Date();
|
|
164
|
-
session.duration = Date.now() - context.startTime;
|
|
165
|
-
session.steps = context.stepCount;
|
|
166
|
-
session.tokens = context.totalTokens;
|
|
167
|
-
session.toolCalls = context.toolCallHistory.length;
|
|
168
|
-
session.errors = context.toolCallHistory.filter(c => !c.success).length;
|
|
169
|
-
session.handoffs = context.handoffStack.length;
|
|
170
|
-
session.success = result.success;
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
onStepEnd: async (context, step, result) => {
|
|
174
|
-
const session = sessions.find(s => s.sessionId === context.session.id);
|
|
175
|
-
if (session) {
|
|
176
|
-
session.steps = step + 1;
|
|
177
|
-
session.tokens += result.tokensUsed;
|
|
178
|
-
session.toolCalls += result.toolCalls.length;
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
// Previously removed generateSpanId is now in TracingService
|
package/dist/hooks/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { HookRunner, createHookRunner } from './HookRunner.js';
|
|
2
|
-
export { loggingHooks, createLoggingHooks } from './builtin/logging.js';
|
|
3
|
-
export { createMetricsHooks, InMemoryMetrics } from './builtin/metrics.js';
|
|
4
|
-
export type { Metrics } from './builtin/metrics.js';
|
|
5
|
-
export { TracingService } from '../services/TracingService.js';
|
|
6
|
-
export { MetricsService, InMemoryMetricsService } from '../services/MetricsService.js';
|
|
7
|
-
export type { TracingConfig, Span, SpanEvent, ObservabilityMetrics, SessionTelemetry, } from '../types/index.js';
|
|
8
|
-
export { initTracing, startSpan, endSpan, addSpanEvent, getCurrentSpan, createTracingHooks, initMetrics, getMetrics, createObservabilityMetrics, createObservabilityHooks, createTelemetryHooks, captureSessionTelemetry, } from './helpers.js';
|
package/dist/hooks/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { HookRunner, createHookRunner } from './HookRunner.js';
|
|
2
|
-
export { loggingHooks, createLoggingHooks } from './builtin/logging.js';
|
|
3
|
-
export { createMetricsHooks, InMemoryMetrics } from './builtin/metrics.js';
|
|
4
|
-
export { TracingService } from '../services/TracingService.js';
|
|
5
|
-
export { InMemoryMetricsService } from '../services/MetricsService.js';
|
|
6
|
-
export { initTracing, startSpan, endSpan, addSpanEvent, getCurrentSpan, createTracingHooks, initMetrics, getMetrics, createObservabilityMetrics, createObservabilityHooks, createTelemetryHooks, captureSessionTelemetry, } from './helpers.js';
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RealtimeAudioClient — Transport-agnostic interface for realtime voice AI models.
|
|
3
|
-
*
|
|
4
|
-
* Any model that accepts audio and returns audio + tool calls implements this.
|
|
5
|
-
* Paired with CapabilityHost:
|
|
6
|
-
* - CapabilityHost → agent logic (tools, prompts, flow state)
|
|
7
|
-
* - RealtimeAudioClient → voice transport (audio I/O, tool dispatch)
|
|
8
|
-
*
|
|
9
|
-
* Implementations:
|
|
10
|
-
* - GeminiRealtimeClient (Gemini Live, PCM16 @ 24kHz)
|
|
11
|
-
* - OpenAIRealtimeClient (OpenAI Realtime, native G.711 μ-law @ 8kHz)
|
|
12
|
-
* - LiveKit wraps these via @livekit/agents-plugin-google and @livekit/agents-plugin-openai
|
|
13
|
-
*/
|
|
14
|
-
import type { GeminiFunctionDeclaration } from '../capabilities/adapters/gemini.js';
|
|
15
|
-
export interface RealtimeSessionConfig {
|
|
16
|
-
/** System instruction / prompt for the model. */
|
|
17
|
-
systemInstruction: string;
|
|
18
|
-
/** Tool declarations (Gemini format — adapters convert to vendor-specific). */
|
|
19
|
-
tools: GeminiFunctionDeclaration[];
|
|
20
|
-
/** Voice preset (e.g., 'Puck', 'Charon', 'marin'). */
|
|
21
|
-
voice?: string;
|
|
22
|
-
/** Model identifier (e.g., 'gemini-3.1-flash-live-preview', 'gpt-realtime'). */
|
|
23
|
-
model?: string;
|
|
24
|
-
/** Session resumption handle (for reconnect continuity). */
|
|
25
|
-
resumptionHandle?: string;
|
|
26
|
-
/** Audio format preferences. */
|
|
27
|
-
audio?: RealtimeAudioConfig;
|
|
28
|
-
}
|
|
29
|
-
export interface RealtimeAudioConfig {
|
|
30
|
-
/** Input audio format. Default: 'pcm16'. */
|
|
31
|
-
inputFormat?: 'pcm16' | 'pcmu' | 'pcma';
|
|
32
|
-
/** Output audio format. Default: 'pcm16'. */
|
|
33
|
-
outputFormat?: 'pcm16' | 'pcmu' | 'pcma';
|
|
34
|
-
/** Input sample rate in Hz. Default varies by vendor (24000 for Gemini, 8000 for OpenAI G.711). */
|
|
35
|
-
inputSampleRate?: number;
|
|
36
|
-
/** Output sample rate in Hz. Default varies by vendor. */
|
|
37
|
-
outputSampleRate?: number;
|
|
38
|
-
}
|
|
39
|
-
export interface RealtimeToolResponse {
|
|
40
|
-
id: string;
|
|
41
|
-
name: string;
|
|
42
|
-
output: unknown;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Capability flags per provider. Declared at construction time; read by
|
|
46
|
-
* orchestration code (VoiceEngine, RealtimeCallWorker, etc.) to adapt
|
|
47
|
-
* behavior to provider limits.
|
|
48
|
-
*
|
|
49
|
-
* Shape mirrors LiveKit's `RealtimeCapabilities` (agents-js
|
|
50
|
-
* /agents/src/llm/realtime.ts:47-58) so plugins can bridge.
|
|
51
|
-
*
|
|
52
|
-
* Optional flags use `undefined = not declared` semantics: an implementation
|
|
53
|
-
* that omits `midSessionToolsUpdate` is treated as "not supported" by consumers
|
|
54
|
-
* that check `if (caps.midSessionToolsUpdate)`. Explicit `false` means the
|
|
55
|
-
* implementor confirmed the provider does not support it.
|
|
56
|
-
*/
|
|
57
|
-
export interface RealtimeCapabilities {
|
|
58
|
-
/** Provider handles turn detection server-side. If false, orchestrator owns it. */
|
|
59
|
-
turnDetection: boolean;
|
|
60
|
-
/** Provider emits user (input) transcripts. If false, orchestrator runs STT separately. */
|
|
61
|
-
userTranscription: boolean;
|
|
62
|
-
/** Provider supports truncating prior messages mid-session. */
|
|
63
|
-
messageTruncation: boolean;
|
|
64
|
-
/** Provider auto-replies after a tool result. If false, orchestrator sends `response.create`. */
|
|
65
|
-
autoToolReplyGeneration: boolean;
|
|
66
|
-
/** Provider produces audio output. If false, provider is text-only and needs external TTS. */
|
|
67
|
-
audioOutput: boolean;
|
|
68
|
-
/** Provider supports client-driven function calls. */
|
|
69
|
-
manualFunctionCalls: boolean;
|
|
70
|
-
/** Mid-session updates — optional because many providers require a full reconnect. */
|
|
71
|
-
midSessionChatCtxUpdate?: boolean;
|
|
72
|
-
midSessionInstructionsUpdate?: boolean;
|
|
73
|
-
midSessionToolsUpdate?: boolean;
|
|
74
|
-
perResponseToolChoice?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* How this provider recovers conversation context across a WS disconnect.
|
|
77
|
-
* Drives `withRealtimeVoice`'s reconnect strategy dispatch.
|
|
78
|
-
*
|
|
79
|
-
* - `"handle"` — server-side resumption via an opaque token (Gemini Live).
|
|
80
|
-
* - `"replay"` — client-side chat_ctx replay via `conversation.item.create`
|
|
81
|
-
* (OpenAI Realtime, Azure OpenAI, xAI Grok).
|
|
82
|
-
* - `"none"` — no recovery; session starts fresh (Workers AI, Phonic, etc.).
|
|
83
|
-
*
|
|
84
|
-
* Omitting the field is treated as `"none"` (migration-safe for older
|
|
85
|
-
* clients that predate this extension).
|
|
86
|
-
*/
|
|
87
|
-
reconnectStrategy?: 'handle' | 'replay' | 'none';
|
|
88
|
-
}
|
|
89
|
-
export interface RealtimeEventMap {
|
|
90
|
-
/** Raw PCM audio from the model (send to client/transport). */
|
|
91
|
-
audio: (data: Uint8Array) => void;
|
|
92
|
-
/** Transcript of user or assistant speech. */
|
|
93
|
-
transcript: (text: string, role: 'user' | 'assistant') => void;
|
|
94
|
-
/** Model wants to call a tool. */
|
|
95
|
-
'tool-call': (id: string, name: string, args: unknown) => void;
|
|
96
|
-
/** Model finished speaking for this turn. */
|
|
97
|
-
'turn-complete': () => void;
|
|
98
|
-
/** User interrupted the model (barge-in). */
|
|
99
|
-
interrupted: () => void;
|
|
100
|
-
/** Connection error. */
|
|
101
|
-
error: (error: string) => void;
|
|
102
|
-
/** Connection closed. */
|
|
103
|
-
disconnected: () => void;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Interface for realtime voice AI model connections.
|
|
107
|
-
*
|
|
108
|
-
* Lifecycle:
|
|
109
|
-
* 1. connect(config) — establish WebSocket, send initial config
|
|
110
|
-
* 2. sendAudio(frame) — stream user audio to model
|
|
111
|
-
* 3. on('tool-call', ...) — handle tool calls from model
|
|
112
|
-
* 4. sendToolResponse(...) — return tool results
|
|
113
|
-
* 5. on('audio', ...) — receive model audio output
|
|
114
|
-
* 6. updateConfig(...) — change prompt/tools mid-session (e.g., on flow transition)
|
|
115
|
-
* 7. disconnect() — close cleanly
|
|
116
|
-
*
|
|
117
|
-
* NOTE: For SDK-based implementations (e.g. `@google/genai`), `session.receive()`
|
|
118
|
-
* is an async iterator that completes after each turn and must be re-entered
|
|
119
|
-
* inside a `while(true)` loop. Raw-wire implementations (fetch()+Upgrade on
|
|
120
|
-
* Cloudflare Workers, direct `ws` WebSocket usage) do not have this quirk; the
|
|
121
|
-
* underlying WebSocket stays open for the session lifetime. Future authors
|
|
122
|
-
* porting this interface to a new transport should be aware that the SDK
|
|
123
|
-
* wrapper and the raw-wire path diverge at this seam.
|
|
124
|
-
*/
|
|
125
|
-
export interface RealtimeAudioClient {
|
|
126
|
-
/**
|
|
127
|
-
* Capability flags. Static per implementation; declared at construction.
|
|
128
|
-
* Implementations MUST NOT throw from this accessor.
|
|
129
|
-
*/
|
|
130
|
-
readonly capabilities: RealtimeCapabilities;
|
|
131
|
-
/** Short stable identifier for the provider, e.g. `"gemini"`, `"openai"`. */
|
|
132
|
-
readonly provider: string;
|
|
133
|
-
/** Model identifier configured for this client, e.g. `"gpt-realtime"`. */
|
|
134
|
-
readonly model: string;
|
|
135
|
-
/** Connect to the AI service with initial configuration. */
|
|
136
|
-
connect(config: RealtimeSessionConfig): Promise<void>;
|
|
137
|
-
/** Disconnect gracefully. */
|
|
138
|
-
disconnect(): Promise<void>;
|
|
139
|
-
/** Send a PCM audio frame to the model. */
|
|
140
|
-
sendAudio(frame: Uint8Array): void;
|
|
141
|
-
/** Send tool call results back to the model. */
|
|
142
|
-
sendToolResponse(responses: RealtimeToolResponse[]): void;
|
|
143
|
-
/**
|
|
144
|
-
* Update session configuration mid-call (system prompt, tools).
|
|
145
|
-
* Used when CapabilityHost signals 'reconfigure' after a flow transition.
|
|
146
|
-
*
|
|
147
|
-
* Implementation may:
|
|
148
|
-
* - Send in-place update (if model supports it)
|
|
149
|
-
* - Disconnect and reconnect with new config (fallback)
|
|
150
|
-
* - Use session resumption handle for continuity
|
|
151
|
-
*/
|
|
152
|
-
updateConfig(config: Partial<RealtimeSessionConfig>): Promise<void>;
|
|
153
|
-
/**
|
|
154
|
-
* Trigger a model response after config update.
|
|
155
|
-
* Optional — not all providers support it.
|
|
156
|
-
*/
|
|
157
|
-
requestResponse?(instruction?: string): void;
|
|
158
|
-
/** Check connection health (WebSocket ping). */
|
|
159
|
-
ping(): Promise<boolean>;
|
|
160
|
-
/** Subscribe to events from the model. */
|
|
161
|
-
on<K extends keyof RealtimeEventMap>(event: K, handler: RealtimeEventMap[K]): void;
|
|
162
|
-
/** Unsubscribe from events. */
|
|
163
|
-
off<K extends keyof RealtimeEventMap>(event: K, handler: RealtimeEventMap[K]): void;
|
|
164
|
-
/** Whether currently connected to the model. */
|
|
165
|
-
readonly connected: boolean;
|
|
166
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RealtimeAudioClient — Transport-agnostic interface for realtime voice AI models.
|
|
3
|
-
*
|
|
4
|
-
* Any model that accepts audio and returns audio + tool calls implements this.
|
|
5
|
-
* Paired with CapabilityHost:
|
|
6
|
-
* - CapabilityHost → agent logic (tools, prompts, flow state)
|
|
7
|
-
* - RealtimeAudioClient → voice transport (audio I/O, tool dispatch)
|
|
8
|
-
*
|
|
9
|
-
* Implementations:
|
|
10
|
-
* - GeminiRealtimeClient (Gemini Live, PCM16 @ 24kHz)
|
|
11
|
-
* - OpenAIRealtimeClient (OpenAI Realtime, native G.711 μ-law @ 8kHz)
|
|
12
|
-
* - LiveKit wraps these via @livekit/agents-plugin-google and @livekit/agents-plugin-openai
|
|
13
|
-
*/
|
|
14
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/realtime/index.d.ts
DELETED
package/dist/realtime/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { TurnResult, UserSignal, ResolvedNode } from '../../types/channel.js';
|
|
2
|
-
import type { RunContext } from '../../types/run-context.js';
|
|
3
|
-
import type { ChannelDriver } from '../../types/channel.js';
|
|
4
|
-
import type { DecideNode } from '../../types/flow.js';
|
|
5
|
-
import { buildNodePrompt } from '../../flow/nodeBuilders.js';
|
|
6
|
-
import type { AnyTool } from '../../types/effectTool.js';
|
|
7
|
-
import type { RealtimeSessionConfig } from '../../realtime/RealtimeAudioClient.js';
|
|
8
|
-
import type { RealtimeAudioClient } from '../../realtime/RealtimeAudioClient.js';
|
|
9
|
-
export interface VoiceDriverConfig {
|
|
10
|
-
client: RealtimeAudioClient;
|
|
11
|
-
toolDefs?: Record<string, AnyTool>;
|
|
12
|
-
maxSteps?: number;
|
|
13
|
-
}
|
|
14
|
-
export declare class VoiceDriver implements ChannelDriver {
|
|
15
|
-
readonly outputCapability: "native-realtime";
|
|
16
|
-
private readonly client;
|
|
17
|
-
private readonly toolDefs;
|
|
18
|
-
private readonly maxSteps;
|
|
19
|
-
private heardCharCount;
|
|
20
|
-
private pendingBargeInInput;
|
|
21
|
-
constructor(config: VoiceDriverConfig);
|
|
22
|
-
runAgentTurn(node: ResolvedNode, ctx: RunContext): Promise<TurnResult>;
|
|
23
|
-
runStructured(node: DecideNode, ctx: RunContext): Promise<unknown>;
|
|
24
|
-
runExtraction(node: ResolvedNode, ctx: RunContext): Promise<TurnResult>;
|
|
25
|
-
awaitUser(ctx: RunContext): Promise<UserSignal>;
|
|
26
|
-
reconfigure(config: Partial<RealtimeSessionConfig>): Promise<void>;
|
|
27
|
-
getHeardCharCount(): number;
|
|
28
|
-
private collectProviderTurn;
|
|
29
|
-
private waitForUserTurn;
|
|
30
|
-
}
|
|
31
|
-
export { buildNodePrompt };
|