@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.
Files changed (210) hide show
  1. package/README.md +89 -4
  2. package/dist/ai-sdk/uiMessageStream.d.ts +2 -2
  3. package/dist/ai-sdk/uiMessageStream.js +42 -29
  4. package/dist/capabilities/LivePromptAssembler.d.ts +1 -1
  5. package/dist/capabilities/LivePromptAssembler.js +2 -1
  6. package/dist/capabilities/index.d.ts +1 -1
  7. package/dist/eval/EvalRunner.js +4 -4
  8. package/dist/eval/simulation.js +4 -3
  9. package/dist/events/TurnHandle.d.ts +3 -3
  10. package/dist/flow/collectDigression.d.ts +5 -2
  11. package/dist/flow/collectDigression.js +48 -10
  12. package/dist/flow/collectUntilComplete.js +13 -5
  13. package/dist/flow/degrade.js +8 -4
  14. package/dist/flow/emitInteractive.d.ts +2 -2
  15. package/dist/flow/emitInteractive.js +6 -3
  16. package/dist/flow/extraction.d.ts +3 -2
  17. package/dist/flow/extraction.js +14 -4
  18. package/dist/flow/reduceTransition.d.ts +2 -2
  19. package/dist/flow/reduceTransition.js +7 -3
  20. package/dist/flow/runFlow.js +97 -17
  21. package/dist/foundation/AgentStateController.d.ts +1 -1
  22. package/dist/foundation/ToolExecutor.d.ts +2 -2
  23. package/dist/foundation/index.d.ts +0 -11
  24. package/dist/foundation/index.js +0 -5
  25. package/dist/index.d.ts +15 -15
  26. package/dist/index.js +9 -6
  27. package/dist/outcomes/streamPart.d.ts +2 -2
  28. package/dist/outcomes/streamPart.js +2 -3
  29. package/dist/prompts/PromptBuilder.d.ts +3 -3
  30. package/dist/prompts/PromptBuilder.js +13 -6
  31. package/dist/prompts/index.d.ts +1 -1
  32. package/dist/prompts/types.d.ts +9 -2
  33. package/dist/runtime/InMemoryRetrievalCache.d.ts +25 -0
  34. package/dist/runtime/InMemoryRetrievalCache.js +59 -0
  35. package/dist/runtime/KnowledgeProvider.d.ts +3 -2
  36. package/dist/runtime/KnowledgeProvider.js +60 -31
  37. package/dist/runtime/Runtime.d.ts +47 -1
  38. package/dist/runtime/Runtime.js +273 -36
  39. package/dist/runtime/TokenAccumulator.d.ts +7 -0
  40. package/dist/runtime/TokenAccumulator.js +7 -0
  41. package/dist/runtime/TraceRecorder.d.ts +51 -0
  42. package/dist/runtime/TraceRecorder.js +326 -0
  43. package/dist/runtime/buildAgentToolSurface.js +1 -1
  44. package/dist/runtime/channels/TextDriver.js +57 -31
  45. package/dist/runtime/channels/executeModelTool.d.ts +14 -1
  46. package/dist/runtime/channels/executeModelTool.js +132 -3
  47. package/dist/runtime/channels/extractionTurn.js +1 -1
  48. package/dist/runtime/channels/index.d.ts +0 -3
  49. package/dist/runtime/channels/index.js +0 -6
  50. package/dist/runtime/channels/inputBuffer.d.ts +1 -0
  51. package/dist/runtime/channels/inputBuffer.js +9 -0
  52. package/dist/runtime/channels/streaming/hostControlSpeak.js +5 -1
  53. package/dist/runtime/channels/streaming/speakGated.js +24 -12
  54. package/dist/runtime/citations/index.d.ts +3 -3
  55. package/dist/runtime/closeRun.js +14 -10
  56. package/dist/runtime/compaction.d.ts +2 -0
  57. package/dist/runtime/compaction.js +3 -2
  58. package/dist/runtime/controlFlowSignal.d.ts +24 -0
  59. package/dist/runtime/controlFlowSignal.js +29 -0
  60. package/dist/runtime/ctx.d.ts +3 -4
  61. package/dist/runtime/ctx.js +147 -60
  62. package/dist/runtime/durable/RunStore.d.ts +16 -0
  63. package/dist/runtime/durable/RunStore.js +7 -1
  64. package/dist/runtime/durable/SessionRunStore.d.ts +7 -2
  65. package/dist/runtime/durable/SessionRunStore.js +136 -34
  66. package/dist/runtime/durable/idempotency.d.ts +1 -0
  67. package/dist/runtime/durable/idempotency.js +3 -0
  68. package/dist/runtime/durable/replay.js +7 -2
  69. package/dist/runtime/durable/types.d.ts +11 -0
  70. package/dist/runtime/goals.d.ts +18 -0
  71. package/dist/runtime/goals.js +158 -0
  72. package/dist/runtime/grounding/gather.d.ts +1 -1
  73. package/dist/runtime/grounding/inMemoryKnowledge.d.ts +1 -1
  74. package/dist/runtime/grounding/knowledge.d.ts +1 -1
  75. package/dist/runtime/grounding/knowledge.js +1 -1
  76. package/dist/runtime/handoffContinuation.d.ts +20 -0
  77. package/dist/runtime/handoffContinuation.js +30 -0
  78. package/dist/runtime/handoffOscillation.d.ts +6 -0
  79. package/dist/runtime/handoffOscillation.js +17 -0
  80. package/dist/runtime/hostLoop.js +37 -6
  81. package/dist/runtime/index.d.ts +4 -3
  82. package/dist/runtime/index.js +2 -1
  83. package/dist/runtime/openRun.d.ts +2 -0
  84. package/dist/runtime/openRun.js +46 -17
  85. package/dist/runtime/outcomeMarking.d.ts +2 -2
  86. package/dist/runtime/outcomeMarking.js +2 -1
  87. package/dist/runtime/policies/agentTurn.d.ts +1 -1
  88. package/dist/runtime/policies/limits.d.ts +1 -0
  89. package/dist/runtime/policies/limits.js +3 -0
  90. package/dist/runtime/runHookSafely.d.ts +3 -0
  91. package/dist/runtime/runHookSafely.js +19 -0
  92. package/dist/runtime/select.d.ts +5 -1
  93. package/dist/runtime/select.js +30 -1
  94. package/dist/runtime/turnTokenUsage.d.ts +28 -0
  95. package/dist/runtime/turnTokenUsage.js +70 -0
  96. package/dist/scheduler/index.d.ts +2 -2
  97. package/dist/scheduler/index.js +1 -1
  98. package/dist/services/TracingService.js +2 -3
  99. package/dist/session/SessionStore.d.ts +6 -0
  100. package/dist/session/SessionStore.js +12 -1
  101. package/dist/session/stores/MemoryStore.d.ts +1 -1
  102. package/dist/session/stores/MemoryStore.js +16 -2
  103. package/dist/session/testing.d.ts +6 -1
  104. package/dist/session/testing.js +34 -0
  105. package/dist/session/utils.d.ts +3 -0
  106. package/dist/session/utils.js +23 -0
  107. package/dist/skills/collectSkills.d.ts +11 -3
  108. package/dist/skills/collectSkills.js +51 -8
  109. package/dist/skills/compositeSkillStore.d.ts +26 -0
  110. package/dist/skills/compositeSkillStore.js +54 -0
  111. package/dist/skills/defineSkill.d.ts +21 -0
  112. package/dist/skills/defineSkill.js +26 -0
  113. package/dist/skills/fsSkillStore.d.ts +3 -0
  114. package/dist/skills/fsSkillStore.js +79 -0
  115. package/dist/skills/index.d.ts +4 -0
  116. package/dist/skills/index.js +4 -0
  117. package/dist/skills/parseSkillFrontmatter.d.ts +14 -0
  118. package/dist/skills/parseSkillFrontmatter.js +183 -0
  119. package/dist/skills/wireAgentSkills.d.ts +2 -1
  120. package/dist/skills/wireAgentSkills.js +2 -2
  121. package/dist/testing/mocks.d.ts +3 -3
  122. package/dist/testing/mocks.js +7 -3
  123. package/dist/tools/controlResults.d.ts +14 -0
  124. package/dist/tools/controlResults.js +15 -0
  125. package/dist/tools/effect/ToolExecutor.d.ts +6 -0
  126. package/dist/tools/effect/ToolExecutor.js +75 -36
  127. package/dist/tools/effect/defineTool.d.ts +11 -0
  128. package/dist/tools/effect/defineTool.js +3 -0
  129. package/dist/tools/effect/errors.d.ts +2 -5
  130. package/dist/tools/effect/errors.js +2 -5
  131. package/dist/tools/index.d.ts +0 -1
  132. package/dist/tools/index.js +0 -1
  133. package/dist/tracing/MemoryTraceStore.d.ts +16 -0
  134. package/dist/tracing/MemoryTraceStore.js +56 -0
  135. package/dist/tracing/OtelTraceSink.d.ts +127 -0
  136. package/dist/tracing/OtelTraceSink.js +101 -0
  137. package/dist/tracing/TraceStore.d.ts +19 -0
  138. package/dist/tracing/TraceStore.js +32 -0
  139. package/dist/tracing/index.d.ts +3 -0
  140. package/dist/tracing/index.js +3 -0
  141. package/dist/tracing/testing.d.ts +3 -0
  142. package/dist/tracing/testing.js +45 -0
  143. package/dist/types/agentConfig.d.ts +2 -1
  144. package/dist/types/channel.d.ts +14 -1
  145. package/dist/types/effectTool.d.ts +6 -0
  146. package/dist/types/flow.d.ts +1 -1
  147. package/dist/types/guardrails.d.ts +5 -0
  148. package/dist/types/hooks.d.ts +2 -2
  149. package/dist/types/index.d.ts +25 -15
  150. package/dist/types/index.js +8 -12
  151. package/dist/types/knowledge.d.ts +213 -0
  152. package/dist/types/processors.d.ts +0 -58
  153. package/dist/types/run-context.d.ts +16 -7
  154. package/dist/types/runtime.d.ts +3 -74
  155. package/dist/types/session.d.ts +11 -1
  156. package/dist/types/skills.d.ts +15 -1
  157. package/dist/types/stream.d.ts +138 -68
  158. package/dist/types/stream.js +34 -1
  159. package/dist/types/trace.d.ts +52 -0
  160. package/guides/AGENTS.md +3 -3
  161. package/guides/EXAMPLE_VERIFICATION.md +4 -4
  162. package/guides/FLOWS.md +1 -1
  163. package/guides/GETTING_STARTED.md +1 -1
  164. package/guides/RUNTIME.md +20 -15
  165. package/guides/TOOLS.md +1 -1
  166. package/package.json +13 -14
  167. package/dist/foundation/AgentDefinition.d.ts +0 -17
  168. package/dist/foundation/ConversationEventLog.d.ts +0 -71
  169. package/dist/foundation/ConversationState.d.ts +0 -33
  170. package/dist/foundation/ConversationState.js +0 -1
  171. package/dist/foundation/DefaultConversationEventLog.d.ts +0 -27
  172. package/dist/foundation/DefaultConversationEventLog.js +0 -205
  173. package/dist/foundation/DefaultConversationState.d.ts +0 -36
  174. package/dist/foundation/DefaultConversationState.js +0 -103
  175. package/dist/foundation/DefaultToolExecutor.d.ts +0 -57
  176. package/dist/foundation/DefaultToolExecutor.js +0 -132
  177. package/dist/foundation/createFoundation.d.ts +0 -32
  178. package/dist/foundation/createFoundation.js +0 -33
  179. package/dist/hooks/HookRunner.d.ts +0 -37
  180. package/dist/hooks/HookRunner.js +0 -111
  181. package/dist/hooks/builtin/logging.d.ts +0 -5
  182. package/dist/hooks/builtin/logging.js +0 -98
  183. package/dist/hooks/builtin/metrics.d.ts +0 -7
  184. package/dist/hooks/builtin/metrics.js +0 -60
  185. package/dist/hooks/builtin/observability.d.ts +0 -20
  186. package/dist/hooks/builtin/observability.js +0 -572
  187. package/dist/hooks/helpers.d.ts +0 -22
  188. package/dist/hooks/helpers.js +0 -183
  189. package/dist/hooks/index.d.ts +0 -8
  190. package/dist/hooks/index.js +0 -6
  191. package/dist/realtime/RealtimeAudioClient.d.ts +0 -166
  192. package/dist/realtime/RealtimeAudioClient.js +0 -14
  193. package/dist/realtime/RealtimeSessionHandle.d.ts +0 -6
  194. package/dist/realtime/RealtimeSessionHandle.js +0 -1
  195. package/dist/realtime/index.d.ts +0 -2
  196. package/dist/realtime/index.js +0 -1
  197. package/dist/runtime/channels/VoiceDriver.d.ts +0 -31
  198. package/dist/runtime/channels/VoiceDriver.js +0 -321
  199. package/dist/runtime/channels/voiceTools.d.ts +0 -9
  200. package/dist/runtime/channels/voiceTools.js +0 -51
  201. package/dist/tools/errorHandling.d.ts +0 -35
  202. package/dist/tools/errorHandling.js +0 -145
  203. package/dist/types/voice.d.ts +0 -517
  204. package/dist/types/voice.js +0 -14
  205. package/dist/utils/isRecord.d.ts +0 -1
  206. package/dist/utils/isRecord.js +0 -3
  207. package/dist/utils/messageNormalization.d.ts +0 -2
  208. package/dist/utils/messageNormalization.js +0 -137
  209. /package/dist/{foundation/AgentDefinition.js → types/knowledge.js} +0 -0
  210. /package/dist/{foundation/ConversationEventLog.js → types/trace.js} +0 -0
@@ -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
@@ -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';
@@ -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,6 +0,0 @@
1
- export interface RealtimeSessionHandle {
2
- readonly sessionId: string;
3
- readonly callId: string;
4
- start(): Promise<void>;
5
- stop(): Promise<void>;
6
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export type { RealtimeAudioClient, RealtimeCapabilities, RealtimeSessionConfig, RealtimeAudioConfig, RealtimeToolResponse, RealtimeEventMap, } from './RealtimeAudioClient.js';
2
- export type { RealtimeSessionHandle } from './RealtimeSessionHandle.js';
@@ -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 };