@teamlearners/clawops 0.22.0 → 0.24.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.
@@ -1,68 +1,8 @@
1
- import { z } from 'zod';
1
+ import { F as FunctionTool, S as Session, B as BuiltinTool, C as CallSession, a as STT, L as LLM, T as TTS, b as ToolRegistry, c as SessionTelemetry, d as SpeechEvent, e as ConversationMessage, f as LLMChunk } from '../base-Z-uZdd27.cjs';
2
+ export { g as CallDirection, h as CallStatus, O as OpenAIToolDefinition, i as ToolCallRequest, j as functionTool, z as zodToToolParams } from '../base-Z-uZdd27.cjs';
2
3
  import { Logger } from 'pino';
3
4
  export { Logger } from 'pino';
4
-
5
- /**
6
- * Tool registry for function-calling in voice agent pipelines.
7
- * Uses Zod schemas for parameter validation.
8
- */
9
-
10
- interface FunctionTool {
11
- name: string;
12
- description: string;
13
- parameters: Record<string, unknown>;
14
- required: string[];
15
- handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
16
- }
17
- interface OpenAIToolDefinition {
18
- type: 'function';
19
- function: {
20
- name: string;
21
- description: string;
22
- parameters: {
23
- type: 'object';
24
- properties: Record<string, unknown>;
25
- required: string[];
26
- };
27
- };
28
- }
29
- /**
30
- * Decorator / identity function for marking a function as a tool handler.
31
- * In TypeScript, this simply returns the function as-is. Use with ToolRegistry.register().
32
- */
33
- declare function functionTool<T extends (...args: unknown[]) => unknown>(fn: T): T;
34
- declare class ToolRegistry {
35
- private _tools;
36
- private _mcpTools;
37
- /** Register a function tool. */
38
- register(tool: FunctionTool): void;
39
- /** Register tools discovered from MCP servers. */
40
- registerMcpTools(tools: FunctionTool[]): void;
41
- /** Clear all MCP-registered tools. */
42
- clearMcpTools(): void;
43
- /**
44
- * Create a fork (shallow copy) of this registry.
45
- * Useful for per-session tool isolation.
46
- */
47
- fork(): ToolRegistry;
48
- /** Check if a tool is registered. */
49
- has(name: string): boolean;
50
- /** Get a tool by name. */
51
- get(name: string): FunctionTool | undefined;
52
- /** Convert all registered tools to OpenAI function-calling format. */
53
- toOpenAITools(): OpenAIToolDefinition[];
54
- /** Call a tool by name with the given arguments. */
55
- call(name: string, args: Record<string, unknown>): Promise<unknown>;
56
- /** Get the number of registered tools (including MCP). */
57
- get size(): number;
58
- }
59
- /**
60
- * Helper to convert a Zod object schema into a JSON Schema properties + required list.
61
- */
62
- declare function zodToToolParams(schema: z.ZodObject<z.ZodRawShape>): {
63
- parameters: Record<string, unknown>;
64
- required: string[];
65
- };
5
+ import 'zod';
66
6
 
67
7
  /**
68
8
  * MCP (Model Context Protocol) client for discovering and calling tools.
@@ -128,268 +68,6 @@ declare function mcpServerHTTP(options: {
128
68
  headers?: Record<string, string>;
129
69
  }): MCPServerHTTP;
130
70
 
131
- interface ProviderInfo {
132
- provider: string;
133
- model: string;
134
- }
135
- interface SessionTelemetry {
136
- sessionType: string;
137
- llm: ProviderInfo | null;
138
- stt: ProviderInfo | null;
139
- tts: ProviderInfo | null;
140
- voice: string | null;
141
- language: string;
142
- greetingEnabled: boolean;
143
- recordingEnabled: boolean;
144
- toolCount: number;
145
- mcpServerCount: number;
146
- builtinTools: string[];
147
- }
148
- interface CallMetrics {
149
- firstResponseMs: number | null;
150
- turnCount: number;
151
- toolCallCount: number;
152
- toolErrorCount: number;
153
- bargeInCount: number;
154
- endReason: string | null;
155
- errors: Array<{
156
- type: string;
157
- message: string;
158
- }>;
159
- }
160
-
161
- /**
162
- * CallSession represents an active phone call and provides methods to
163
- * send audio, hang up, and listen for lifecycle events.
164
- */
165
-
166
- type CallDirection = 'inbound' | 'outbound';
167
- type CallStatus = 'ringing' | 'active' | 'ended';
168
- /**
169
- * Session event handler: receives (call, ...args) like the Python SDK.
170
- * For example, 'transcript' events pass (call, role, text).
171
- */
172
- type SessionEventHandler = (...args: any[]) => void | Promise<void>;
173
- interface SendAudioFn {
174
- (audio: Buffer): void;
175
- }
176
- interface ClearAudioFn {
177
- (): void;
178
- }
179
- interface HangupFn {
180
- (): void | Promise<void>;
181
- }
182
- interface SendDtmfFn {
183
- (digit: string): Promise<void>;
184
- }
185
- interface TransferFn {
186
- (params: Record<string, unknown>): Promise<Record<string, unknown>>;
187
- }
188
- declare class CallSession {
189
- readonly callId: string;
190
- readonly fromNumber: string;
191
- readonly toNumber: string;
192
- readonly accountId: string;
193
- readonly direction: CallDirection;
194
- readonly startTime: Date;
195
- readonly metadata: Record<string, unknown>;
196
- private _status;
197
- private _sendAudioFn;
198
- private _clearAudioFn;
199
- private _hangupFn;
200
- /** @internal */ _sendDtmfFn: SendDtmfFn | null;
201
- /** @internal */ _transferFn: TransferFn | null;
202
- /** @internal */ _isTransportConnected: (() => boolean) | null;
203
- private _dtmfCollectorActive;
204
- private _dtmfResolvers;
205
- private _dtmfBuffer;
206
- private _log;
207
- private _handlers;
208
- private _endedPromise;
209
- private _resolveEnded;
210
- private _metrics;
211
- private _firstResponseSent;
212
- constructor(options: {
213
- callId: string;
214
- fromNumber: string;
215
- toNumber: string;
216
- accountId: string;
217
- direction: CallDirection;
218
- metadata?: Record<string, unknown>;
219
- });
220
- setLogger(logger: Logger): void;
221
- get status(): CallStatus;
222
- get duration(): number;
223
- get metrics(): Readonly<CallMetrics>;
224
- recordFirstResponse(): void;
225
- recordTurn(): void;
226
- recordToolCall(): void;
227
- recordToolError(err: Error): void;
228
- recordBargeIn(): void;
229
- recordEndReason(reason: string): void;
230
- /** Bind transport functions (called internally by the agent). */
231
- _bindTransport(send: SendAudioFn, clear: ClearAudioFn, hangup: HangupFn, sendDtmf?: SendDtmfFn, isConnected?: () => boolean): void;
232
- /** Send PCM16 or ulaw audio to the caller. */
233
- sendAudio(audio: Buffer): void;
234
- /** Clear any queued outbound audio. */
235
- clearAudio(): void;
236
- /** Hang up the call, waiting for pending audio to finish. */
237
- hangup(): Promise<void>;
238
- /** @internal Route a received DTMF digit to an active collector or buffer. */
239
- _routeDtmf(digit: string): void;
240
- /** Collect DTMF digits from the caller. */
241
- collectDtmf(options: {
242
- maxDigits: number;
243
- finishOnKey?: string;
244
- timeout?: number;
245
- secure?: boolean;
246
- }): Promise<string>;
247
- /** Send a sequence of DTMF digits. */
248
- sendDtmfSequence(digits: string): Promise<void>;
249
- /**
250
- * Transfer the call to a phone number or SIP endpoint.
251
- *
252
- * destinationType='pstn' (default): `to` is a phone number dialed via carrier.
253
- * destinationType='sip': `to` is a SIP URI (e.g. `sip:user@host`) connected
254
- * directly to a SIP endpoint without going through the PSTN carrier.
255
- */
256
- transfer(to: string, options?: {
257
- destinationType?: 'pstn' | 'sip';
258
- mode?: 'blind' | 'warm';
259
- afterTransfer?: 'terminate' | 'return';
260
- holdMedia?: string;
261
- whisper?: string;
262
- context?: Record<string, unknown>;
263
- callerId?: string;
264
- timeout?: number;
265
- }): Promise<Record<string, unknown>>;
266
- /** Register an event handler. */
267
- on(event: string, handler: SessionEventHandler): void;
268
- /** Wait for the call to end. */
269
- wait(): Promise<void>;
270
- /** Mark the session as ended (called internally). */
271
- _markEnded(): void;
272
- /** Emit an event to registered handlers. Matches Python SDK: _emit(event, ...args) */
273
- _emit(event: string, ...args: any[]): void;
274
- }
275
-
276
- /**
277
- * Built-in tool definitions and selection constants.
278
- */
279
- declare enum BuiltinTool {
280
- /** 전화 종료 도구. AI가 대화 완료 시 통화를 종료합니다. */
281
- HANG_UP = "hang_up",
282
- /** DTMF 수집 도구. 사용자의 키패드 입력을 수집합니다. */
283
- COLLECT_DTMF = "collect_dtmf",
284
- /** DTMF 전송 도구. ARS 탐색이나 내선번호 입력에 사용합니다. */
285
- SEND_DTMF = "send_dtmf",
286
- /** 통화 전환 도구. 현재 통화를 다른 번호로 전환합니다. */
287
- TRANSFER_CALL = "transfer_call",
288
- /** 모든 내장 도구를 활성화합니다. (기본값) */
289
- ALL = "all",
290
- /** 모든 내장 도구를 비활성화합니다. */
291
- NONE = "none"
292
- }
293
-
294
- /**
295
- * Base interfaces for the voice agent pipeline.
296
- */
297
-
298
- /** Speech recognition event. */
299
- interface SpeechEvent {
300
- type: 'interim' | 'final';
301
- transcript: string;
302
- }
303
- /** Conversation message for LLM context. */
304
- interface ConversationMessage {
305
- role: 'system' | 'user' | 'assistant' | 'tool';
306
- content: string;
307
- name?: string;
308
- tool_call_id?: string;
309
- }
310
- /** Tool call request from an LLM. */
311
- interface ToolCallRequest {
312
- id: string;
313
- name: string;
314
- arguments: string;
315
- }
316
- /** LLM response chunk (for streaming). */
317
- interface LLMChunk {
318
- type: 'text' | 'tool_call' | 'done';
319
- text?: string;
320
- toolCall?: ToolCallRequest;
321
- }
322
- /**
323
- * Session interface for realtime (speech-to-speech) providers.
324
- * Implementations: OpenAIRealtime, GeminiRealtime
325
- */
326
- interface Session {
327
- /** Start the realtime session with the call session and tools. Thin wrapper over prewarm + attach. */
328
- start(callSession: CallSession, tools?: ToolRegistry): Promise<void>;
329
- /**
330
- * Open LLM connection (and session.update + optional greeting trigger) without a CallSession.
331
- *
332
- * Audio deltas produced during the prewarm window accumulate in an internal BufferingCall.
333
- * attach() then replaces the BufferingCall with the real CallSession and flushes the buffer.
334
- *
335
- * Tools may optionally be injected here (alternative to calling setToolRegistry separately);
336
- * the Session is free to ignore the argument if tools are already set.
337
- */
338
- prewarm(tools?: ToolRegistry): Promise<void>;
339
- /** Attach a real CallSession to a prewarmed session and flush any buffered audio. */
340
- attach(callSession: CallSession): Promise<void>;
341
- /** Feed raw audio into the session. */
342
- feedAudio(audio: Buffer, timestamp?: number): void;
343
- /** Feed DTMF digits into the LLM context and trigger a response. */
344
- feedDtmf?(digits: string): Promise<void>;
345
- /** Stop the session. */
346
- stop(): Promise<void>;
347
- /** Set the logger instance for this session. */
348
- setLogger?(logger: Logger): void;
349
- /** Return session telemetry for reporting. */
350
- getTelemetry?(): SessionTelemetry | null;
351
- }
352
- /**
353
- * Speech-to-Text provider interface.
354
- */
355
- interface STT {
356
- /**
357
- * Transcribe audio. Returns an async generator of speech events.
358
- * The generator yields interim results and a final result.
359
- */
360
- transcribe(audioStream: AsyncIterable<Buffer>, options?: {
361
- language?: string;
362
- sampleRate?: number;
363
- }): AsyncGenerator<SpeechEvent>;
364
- }
365
- /**
366
- * LLM (Large Language Model) provider interface.
367
- */
368
- interface LLM {
369
- /**
370
- * Generate a response from the LLM.
371
- * Returns an async generator of response chunks.
372
- */
373
- generate(messages: ConversationMessage[], options?: {
374
- tools?: ToolRegistry;
375
- temperature?: number;
376
- maxTokens?: number;
377
- }): AsyncGenerator<LLMChunk>;
378
- }
379
- /**
380
- * Text-to-Speech provider interface.
381
- */
382
- interface TTS {
383
- /**
384
- * Synthesize text to audio.
385
- * Returns an async generator of PCM16 audio chunks.
386
- */
387
- synthesize(text: string | AsyncIterable<string>, options?: {
388
- voice?: string;
389
- sampleRate?: number;
390
- }): AsyncGenerator<Buffer>;
391
- }
392
-
393
71
  /**
394
72
  * Tracing configuration for OpenTelemetry integration.
395
73
  */
@@ -465,6 +143,13 @@ interface ClawOpsAgentOptions {
465
143
  * Python SDK 의 `prewarm_enabled` 과 mirror.
466
144
  */
467
145
  prewarmEnabled?: boolean;
146
+ /**
147
+ * 이 에이전트의 모든 발신에 적용되는 AMD(machineDetection) default.
148
+ * `'Enable'`=감지 후 `AnsweredBy` 통보(통화 계속), `'Hangup'`=음성사서함 감지 시 자동 종료.
149
+ * `call(to, { machineDetection })` 로 호출별 override 가능.
150
+ * 우선순위: 호출 인자 > 인스턴스 default > 비활성. Python SDK 의 `machine_detection` 과 mirror.
151
+ */
152
+ machineDetection?: 'Enable' | 'Hangup';
468
153
  }
469
154
  declare class ClawOpsAgent {
470
155
  private _apiKey;
@@ -496,6 +181,8 @@ declare class ClawOpsAgent {
496
181
  /** prewarm 세션이 실제 CallSession 에 attach 완료된 callId. attached 이후의 stop() 은 정상 종료 경로가 책임진다. */
497
182
  private _prewarmAttached;
498
183
  private _prewarmEnabled;
184
+ /** 모든 발신에 적용되는 AMD default. call() 인자로 호출별 override 가능. */
185
+ private _machineDetection?;
499
186
  constructor(options: ClawOpsAgentOptions);
500
187
  private static _validateGain;
501
188
  /**
@@ -529,6 +216,8 @@ declare class ClawOpsAgent {
529
216
  *
530
217
  * @param options.machineDetection 자동응답기/음성사서함 감지(AMD).
531
218
  * `'Enable'`=감지 후 `AnsweredBy` 통보(통화 계속), `'Hangup'`=음성사서함 감지 시 자동 종료.
219
+ * 미지정 시 인스턴스 default(생성자의 `machineDetection`)를 따른다.
220
+ * 우선순위: 호출 인자 > 인스턴스 default > 비활성.
532
221
  */
533
222
  call(to: string, options?: {
534
223
  timeout?: number;
@@ -1327,4 +1016,4 @@ declare function createAgentLogger(userLogger?: Logger): Logger;
1327
1016
  */
1328
1017
  declare function createPipelineLogger(parent: Logger): Logger;
1329
1018
 
1330
- export { type AgentEventType, AnthropicLLM, type AnthropicLLMOptions, AudioRecorder, BUILTIN_TOOL_NAMES, BuiltinTool, type CallDirection, CallSession, type CallStatus, ClawOpsAgent, type ClawOpsAgentOptions, type ControlEvent, ControlWebSocket, type ControlWsOptions, type ConversationMessage, DECODE_TABLE, DeepSeekLLM, type DeepSeekLLMOptions, DeepgramSTT, type DeepgramSTTOptions, type DtmfEvent, ElevenLabsTTS, type ElevenLabsTTSOptions, FireworksLLM, type FireworksLLMOptions, type FunctionTool, GeminiLLM, type GeminiLLMOptions, GeminiRealtime, type GeminiRealtimeOptions, GroqLLM, type GroqLLMOptions, type LLM, type LLMChunk, MCPClient, type MCPServerConfig, type MCPServerHTTP, type MCPServerStdio, type MediaEvent, type MediaStartEvent, MediaWebSocket, MistralLLM, type MistralLLMOptions, OllamaLLM, type OllamaLLMOptions, OpenAICompatLLM, type OpenAICompatLLMOptions, OpenAILLM, type OpenAILLMOptions, OpenAIRealtime, type OpenAIRealtimeOptions, type OpenAIToolDefinition, PerplexityLLM, type PerplexityLLMOptions, PipelineSession, type PipelineSessionOptions, type STT, type Session, type SpeechEvent, type TTS, TogetherLLM, type TogetherLLMOptions, type ToolCallRequest, type ToolConfig, ToolRegistry, type TracingConfig, XaiLLM, type XaiLLMOptions, buildControlWsUrl, createAgentLogger, createPipelineLogger, executeBuiltinTool, functionTool, getBuiltinToolSchemas, getTracingConfig, isBuiltinTool, mcpServerHTTP, mcpServerStdio, pcm16ToUlaw, resamplePcm16, resetTracingConfig, setTracingConfig, ulawToPcm16, zodToToolParams };
1019
+ export { type AgentEventType, AnthropicLLM, type AnthropicLLMOptions, AudioRecorder, BUILTIN_TOOL_NAMES, BuiltinTool, CallSession, ClawOpsAgent, type ClawOpsAgentOptions, type ControlEvent, ControlWebSocket, type ControlWsOptions, ConversationMessage, DECODE_TABLE, DeepSeekLLM, type DeepSeekLLMOptions, DeepgramSTT, type DeepgramSTTOptions, type DtmfEvent, ElevenLabsTTS, type ElevenLabsTTSOptions, FireworksLLM, type FireworksLLMOptions, FunctionTool, GeminiLLM, type GeminiLLMOptions, GeminiRealtime, type GeminiRealtimeOptions, GroqLLM, type GroqLLMOptions, LLM, LLMChunk, MCPClient, type MCPServerConfig, type MCPServerHTTP, type MCPServerStdio, type MediaEvent, type MediaStartEvent, MediaWebSocket, MistralLLM, type MistralLLMOptions, OllamaLLM, type OllamaLLMOptions, OpenAICompatLLM, type OpenAICompatLLMOptions, OpenAILLM, type OpenAILLMOptions, OpenAIRealtime, type OpenAIRealtimeOptions, PerplexityLLM, type PerplexityLLMOptions, PipelineSession, type PipelineSessionOptions, STT, Session, SpeechEvent, TTS, TogetherLLM, type TogetherLLMOptions, type ToolConfig, ToolRegistry, type TracingConfig, XaiLLM, type XaiLLMOptions, buildControlWsUrl, createAgentLogger, createPipelineLogger, executeBuiltinTool, getBuiltinToolSchemas, getTracingConfig, isBuiltinTool, mcpServerHTTP, mcpServerStdio, pcm16ToUlaw, resamplePcm16, resetTracingConfig, setTracingConfig, ulawToPcm16 };