@teamlearners/clawops 0.23.0 → 0.25.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,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkNXMTLS2U_cjs = require('../chunk-NXMTLS2U.cjs');
4
- var pino = require('pino');
3
+ var chunkIVJXHNUN_cjs = require('../chunk-IVJXHNUN.cjs');
4
+ var chunkU4UFTVLX_cjs = require('../chunk-U4UFTVLX.cjs');
5
5
  var fs = require('fs');
6
6
  var path = require('path');
7
7
  var os = require('os');
@@ -26,361 +26,10 @@ function _interopNamespace(e) {
26
26
  return Object.freeze(n);
27
27
  }
28
28
 
29
- var pino__default = /*#__PURE__*/_interopDefault(pino);
30
29
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
31
30
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
32
31
  var os__default = /*#__PURE__*/_interopDefault(os);
33
32
 
34
- // src/agent/audio.ts
35
- var _BIAS = 132;
36
- var _CLIP = 32635;
37
- var DECODE_TABLE = [
38
- -32124,
39
- -31100,
40
- -30076,
41
- -29052,
42
- -28028,
43
- -27004,
44
- -25980,
45
- -24956,
46
- -23932,
47
- -22908,
48
- -21884,
49
- -20860,
50
- -19836,
51
- -18812,
52
- -17788,
53
- -16764,
54
- -15996,
55
- -15484,
56
- -14972,
57
- -14460,
58
- -13948,
59
- -13436,
60
- -12924,
61
- -12412,
62
- -11900,
63
- -11388,
64
- -10876,
65
- -10364,
66
- -9852,
67
- -9340,
68
- -8828,
69
- -8316,
70
- -7932,
71
- -7676,
72
- -7420,
73
- -7164,
74
- -6908,
75
- -6652,
76
- -6396,
77
- -6140,
78
- -5884,
79
- -5628,
80
- -5372,
81
- -5116,
82
- -4860,
83
- -4604,
84
- -4348,
85
- -4092,
86
- -3900,
87
- -3772,
88
- -3644,
89
- -3516,
90
- -3388,
91
- -3260,
92
- -3132,
93
- -3004,
94
- -2876,
95
- -2748,
96
- -2620,
97
- -2492,
98
- -2364,
99
- -2236,
100
- -2108,
101
- -1980,
102
- -1884,
103
- -1820,
104
- -1756,
105
- -1692,
106
- -1628,
107
- -1564,
108
- -1500,
109
- -1436,
110
- -1372,
111
- -1308,
112
- -1244,
113
- -1180,
114
- -1116,
115
- -1052,
116
- -988,
117
- -924,
118
- -876,
119
- -844,
120
- -812,
121
- -780,
122
- -748,
123
- -716,
124
- -684,
125
- -652,
126
- -620,
127
- -588,
128
- -556,
129
- -524,
130
- -492,
131
- -460,
132
- -428,
133
- -396,
134
- -372,
135
- -356,
136
- -340,
137
- -324,
138
- -308,
139
- -292,
140
- -276,
141
- -260,
142
- -244,
143
- -228,
144
- -212,
145
- -196,
146
- -180,
147
- -164,
148
- -148,
149
- -132,
150
- -120,
151
- -112,
152
- -104,
153
- -96,
154
- -88,
155
- -80,
156
- -72,
157
- -64,
158
- -56,
159
- -48,
160
- -40,
161
- -32,
162
- -24,
163
- -16,
164
- -8,
165
- 0,
166
- 32124,
167
- 31100,
168
- 30076,
169
- 29052,
170
- 28028,
171
- 27004,
172
- 25980,
173
- 24956,
174
- 23932,
175
- 22908,
176
- 21884,
177
- 20860,
178
- 19836,
179
- 18812,
180
- 17788,
181
- 16764,
182
- 15996,
183
- 15484,
184
- 14972,
185
- 14460,
186
- 13948,
187
- 13436,
188
- 12924,
189
- 12412,
190
- 11900,
191
- 11388,
192
- 10876,
193
- 10364,
194
- 9852,
195
- 9340,
196
- 8828,
197
- 8316,
198
- 7932,
199
- 7676,
200
- 7420,
201
- 7164,
202
- 6908,
203
- 6652,
204
- 6396,
205
- 6140,
206
- 5884,
207
- 5628,
208
- 5372,
209
- 5116,
210
- 4860,
211
- 4604,
212
- 4348,
213
- 4092,
214
- 3900,
215
- 3772,
216
- 3644,
217
- 3516,
218
- 3388,
219
- 3260,
220
- 3132,
221
- 3004,
222
- 2876,
223
- 2748,
224
- 2620,
225
- 2492,
226
- 2364,
227
- 2236,
228
- 2108,
229
- 1980,
230
- 1884,
231
- 1820,
232
- 1756,
233
- 1692,
234
- 1628,
235
- 1564,
236
- 1500,
237
- 1436,
238
- 1372,
239
- 1308,
240
- 1244,
241
- 1180,
242
- 1116,
243
- 1052,
244
- 988,
245
- 924,
246
- 876,
247
- 844,
248
- 812,
249
- 780,
250
- 748,
251
- 716,
252
- 684,
253
- 652,
254
- 620,
255
- 588,
256
- 556,
257
- 524,
258
- 492,
259
- 460,
260
- 428,
261
- 396,
262
- 372,
263
- 356,
264
- 340,
265
- 324,
266
- 308,
267
- 292,
268
- 276,
269
- 260,
270
- 244,
271
- 228,
272
- 212,
273
- 196,
274
- 180,
275
- 164,
276
- 148,
277
- 132,
278
- 120,
279
- 112,
280
- 104,
281
- 96,
282
- 88,
283
- 80,
284
- 72,
285
- 64,
286
- 56,
287
- 48,
288
- 40,
289
- 32,
290
- 24,
291
- 16,
292
- 8,
293
- 0
294
- ];
295
- function encodeUlawSample(sample) {
296
- let sign = 0;
297
- if (sample < 0) {
298
- sign = 128;
299
- sample = -sample;
300
- }
301
- if (sample > _CLIP) {
302
- sample = _CLIP;
303
- }
304
- sample += _BIAS;
305
- let exponent = 7;
306
- const expValues = [16384, 8192, 4096, 2048, 1024, 512, 256];
307
- for (const expVal of expValues) {
308
- if (sample >= expVal) {
309
- break;
310
- }
311
- exponent -= 1;
312
- }
313
- const mantissa = sample >> exponent + 3 & 15;
314
- return ~(sign | exponent << 4 | mantissa) & 255;
315
- }
316
- function pcm16ToUlaw(pcm) {
317
- if (!pcm.length) return Buffer.alloc(0);
318
- const nSamples = pcm.length >> 1;
319
- const out = Buffer.alloc(nSamples);
320
- for (let i = 0; i < nSamples; i++) {
321
- const sample = pcm.readInt16LE(i * 2);
322
- out[i] = encodeUlawSample(sample);
323
- }
324
- return out;
325
- }
326
- function ulawToPcm16(ulaw) {
327
- if (!ulaw.length) return Buffer.alloc(0);
328
- const out = Buffer.alloc(ulaw.length * 2);
329
- for (let i = 0; i < ulaw.length; i++) {
330
- out.writeInt16LE(DECODE_TABLE[ulaw[i]], i * 2);
331
- }
332
- return out;
333
- }
334
- function applyPcm16Gain(pcm, gain) {
335
- if (!pcm.length) return Buffer.alloc(0);
336
- if (gain === 1) return pcm;
337
- if (!Number.isFinite(gain) || gain < 0) {
338
- throw new Error("gain must be a finite number >= 0");
339
- }
340
- const nSamples = pcm.length >> 1;
341
- const out = Buffer.alloc(nSamples * 2);
342
- for (let i = 0; i < nSamples; i++) {
343
- let value = Math.round(pcm.readInt16LE(i * 2) * gain);
344
- if (value > 32767) value = 32767;
345
- else if (value < -32768) value = -32768;
346
- out.writeInt16LE(value, i * 2);
347
- }
348
- return out;
349
- }
350
- function applyUlawGain(ulaw, gain) {
351
- if (!ulaw.length) return Buffer.alloc(0);
352
- if (gain === 1) return ulaw;
353
- return pcm16ToUlaw(applyPcm16Gain(ulawToPcm16(ulaw), gain));
354
- }
355
- function resamplePcm16(pcm, fromRate, toRate) {
356
- if (fromRate === toRate || !pcm.length) return pcm;
357
- const nSamples = pcm.length >> 1;
358
- const ratio = fromRate / toRate;
359
- const outLen = Math.floor(nSamples / ratio);
360
- const out = Buffer.alloc(outLen * 2);
361
- for (let i = 0; i < outLen; i++) {
362
- const srcPos = i * ratio;
363
- const idx = Math.floor(srcPos);
364
- const frac = srcPos - idx;
365
- let val;
366
- if (idx + 1 < nSamples) {
367
- val = pcm.readInt16LE(idx * 2) * (1 - frac) + pcm.readInt16LE((idx + 1) * 2) * frac;
368
- } else {
369
- val = pcm.readInt16LE(idx * 2);
370
- }
371
- out.writeInt16LE(Math.round(val), i * 2);
372
- }
373
- return out;
374
- }
375
- var DEFAULT_LOGGER = pino__default.default({ name: "clawops.agent" });
376
- var NOOP_LOGGER = pino__default.default({ level: "silent" });
377
- function createAgentLogger(userLogger) {
378
- return userLogger ?? DEFAULT_LOGGER;
379
- }
380
- function createPipelineLogger(parent) {
381
- return parent.child({ module: "pipeline" });
382
- }
383
-
384
33
  // src/agent/control-ws.ts
385
34
  var INITIAL_RECONNECT_DELAY = 1e3;
386
35
  var MAX_RECONNECT_DELAY = 3e4;
@@ -410,7 +59,7 @@ var ControlWebSocket = class {
410
59
  _closed = false;
411
60
  _connectedResolve = null;
412
61
  _connectedPromise;
413
- _log = NOOP_LOGGER;
62
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
414
63
  _pingTimer = null;
415
64
  setLogger(logger) {
416
65
  this._log = logger;
@@ -575,7 +224,7 @@ var ControlWebSocket = class {
575
224
  var MCPClient = class {
576
225
  _servers = /* @__PURE__ */ new Map();
577
226
  _clients = /* @__PURE__ */ new Map();
578
- _log = NOOP_LOGGER;
227
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
579
228
  setLogger(logger) {
580
229
  this._log = logger;
581
230
  }
@@ -717,7 +366,7 @@ var MediaWebSocket = class {
717
366
  _onClose = null;
718
367
  _onDtmf = null;
719
368
  _markWaiters = /* @__PURE__ */ new Map();
720
- _log = NOOP_LOGGER;
369
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
721
370
  setLogger(logger) {
722
371
  this._log = logger;
723
372
  }
@@ -943,7 +592,7 @@ var AudioRecorder = class {
943
592
  _started = false;
944
593
  _baseTs = null;
945
594
  _outCursor = 0;
946
- _log = NOOP_LOGGER;
595
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
947
596
  setLogger(logger) {
948
597
  this._log = logger;
949
598
  }
@@ -1079,7 +728,7 @@ var MAX_ERROR_MESSAGE_LENGTH = 200;
1079
728
  function getSdkInfo() {
1080
729
  return {
1081
730
  name: "clawops-node",
1082
- version: chunkNXMTLS2U_cjs.VERSION,
731
+ version: chunkIVJXHNUN_cjs.VERSION,
1083
732
  runtime: `node/${process.versions.node}`,
1084
733
  os: `${process.platform}/${os__default.default.arch()}`
1085
734
  };
@@ -1115,6 +764,7 @@ var CallSession = class {
1115
764
  startTime;
1116
765
  metadata;
1117
766
  _status;
767
+ _endedStatus = null;
1118
768
  _sendAudioFn = null;
1119
769
  _clearAudioFn = null;
1120
770
  _hangupFn = null;
@@ -1124,10 +774,21 @@ var CallSession = class {
1124
774
  _transferFn = null;
1125
775
  /** @internal */
1126
776
  _isTransportConnected = null;
777
+ /**
778
+ * @internal Media WS playout 마커 훅. LiveKit(`ClawOpsAudioOutput`)이 재생 완료
779
+ * 판정(mark echo)과 barge-in 절단 위치 계산에 쓴다. 다른 세션 타입은 읽지 않는다.
780
+ * prewarm 중(BufferingCall)에는 바인딩되지 않아 null 이다.
781
+ */
782
+ /** @internal */
783
+ _sendMark = null;
784
+ /** @internal */
785
+ _waitForMark = null;
786
+ /** @internal */
787
+ _flushTransport = null;
1127
788
  _dtmfCollectorActive = false;
1128
789
  _dtmfResolvers = [];
1129
790
  _dtmfBuffer = [];
1130
- _log = NOOP_LOGGER;
791
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
1131
792
  _handlers = /* @__PURE__ */ new Map();
1132
793
  _endedPromise;
1133
794
  _resolveEnded;
@@ -1152,6 +813,17 @@ var CallSession = class {
1152
813
  get status() {
1153
814
  return this._status;
1154
815
  }
816
+ /**
817
+ * 서버가 통보한 최종 종료 상태. 통화가 끝나기 전에는 null.
818
+ *
819
+ * `completed`(성사) / `no-answer`(벨은 울렸으나 무응답) / `busy`(통화중) /
820
+ * `rejected`(수신 거절) / `canceled`(응답 전 발신 측 취소) / `failed`(시스템·망 오류).
821
+ * `status` 는 SDK 내부 수명주기(ringing→active→ended)이므로 통화 성사 여부는
822
+ * 이 값이나 `call_failed` 이벤트로 판단한다.
823
+ */
824
+ get endedStatus() {
825
+ return this._endedStatus;
826
+ }
1155
827
  get duration() {
1156
828
  return (Date.now() - this.startTime.getTime()) / 1e3;
1157
829
  }
@@ -1312,8 +984,20 @@ var CallSession = class {
1312
984
  async wait() {
1313
985
  return this._endedPromise;
1314
986
  }
1315
- /** Mark the session as ended (called internally). */
1316
- _markEnded() {
987
+ /**
988
+ * Mark the session as ended (called internally).
989
+ *
990
+ * @param status 서버가 통보한 최종 상태(completed/no-answer/busy/rejected/canceled/
991
+ * failed). 주어지면 `endedStatus` 로 확정한다 — 상대가 받지 않은 통화를 성사된 통화와
992
+ * 구분하기 위함이다. 생략하면 미디어 세션 정리 경로에서의 호출이므로, 아직 종료 전일
993
+ * 때만 'completed' 로 채우고 이미 확정된 서버 상태는 덮어쓰지 않는다.
994
+ */
995
+ _markEnded(status) {
996
+ if (status !== void 0) {
997
+ this._endedStatus = status;
998
+ } else if (this._status !== "ended") {
999
+ this._endedStatus = "completed";
1000
+ }
1317
1001
  this._status = "ended";
1318
1002
  this._resolveEnded();
1319
1003
  }
@@ -1337,35 +1021,6 @@ var CallSession = class {
1337
1021
  }
1338
1022
  }
1339
1023
  };
1340
-
1341
- // src/agent/builtin-tool.ts
1342
- var BuiltinTool = /* @__PURE__ */ ((BuiltinTool2) => {
1343
- BuiltinTool2["HANG_UP"] = "hang_up";
1344
- BuiltinTool2["COLLECT_DTMF"] = "collect_dtmf";
1345
- BuiltinTool2["SEND_DTMF"] = "send_dtmf";
1346
- BuiltinTool2["TRANSFER_CALL"] = "transfer_call";
1347
- BuiltinTool2["ALL"] = "all";
1348
- BuiltinTool2["NONE"] = "none";
1349
- return BuiltinTool2;
1350
- })(BuiltinTool || {});
1351
- var INDIVIDUAL_TOOLS = /* @__PURE__ */ new Set([
1352
- "hang_up" /* HANG_UP */,
1353
- "collect_dtmf" /* COLLECT_DTMF */,
1354
- "send_dtmf" /* SEND_DTMF */,
1355
- "transfer_call" /* TRANSFER_CALL */
1356
- ]);
1357
- function resolveBuiltinTools(value) {
1358
- if (typeof value === "string") {
1359
- if (value === "all" /* ALL */) {
1360
- return new Set(INDIVIDUAL_TOOLS);
1361
- }
1362
- if (value === "none" /* NONE */) {
1363
- return /* @__PURE__ */ new Set();
1364
- }
1365
- return /* @__PURE__ */ new Set([value]);
1366
- }
1367
- return new Set(value.filter((t) => INDIVIDUAL_TOOLS.has(t)));
1368
- }
1369
1024
  var CHUNK_SIZE = 160;
1370
1025
  var SAMPLE_RATE2 = 8e3;
1371
1026
  var BELL_PARTIALS = [
@@ -1450,7 +1105,7 @@ function generateComfortTone(volume = 0.12) {
1450
1105
  }
1451
1106
  }
1452
1107
  const pcm = int16ArrayToBuffer(concatInt16Arrays(...parts));
1453
- const ulaw = pcm16ToUlaw(pcm);
1108
+ const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcm);
1454
1109
  const chunks = [];
1455
1110
  for (let i = 0; i < ulaw.length; i += CHUNK_SIZE) {
1456
1111
  chunks.push(ulaw.subarray(i, i + CHUNK_SIZE));
@@ -1507,9 +1162,9 @@ function loadHoldAudio(source) {
1507
1162
  pcmData = mono;
1508
1163
  }
1509
1164
  if (sampleRate !== SAMPLE_RATE2) {
1510
- pcmData = resamplePcm16(pcmData, sampleRate, SAMPLE_RATE2);
1165
+ pcmData = chunkU4UFTVLX_cjs.resamplePcm16(pcmData, sampleRate, SAMPLE_RATE2);
1511
1166
  }
1512
- const ulaw = pcm16ToUlaw(pcmData);
1167
+ const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcmData);
1513
1168
  const chunks = [];
1514
1169
  for (let i = 0; i < ulaw.length; i += CHUNK_SIZE) {
1515
1170
  chunks.push(ulaw.subarray(i, i + CHUNK_SIZE));
@@ -1778,13 +1433,13 @@ var ClawOpsAgent = class _ClawOpsAgent {
1778
1433
  constructor(options) {
1779
1434
  this._apiKey = options.apiKey ?? process.env["CLAWOPS_API_KEY"] ?? "";
1780
1435
  this._accountId = options.accountId ?? process.env["CLAWOPS_ACCOUNT_ID"] ?? "";
1781
- this._baseUrl = options.baseUrl ?? chunkNXMTLS2U_cjs.DEFAULT_BASE_URL;
1436
+ this._baseUrl = options.baseUrl ?? chunkIVJXHNUN_cjs.DEFAULT_BASE_URL;
1782
1437
  this._fromNumber = options.from;
1783
1438
  this._session = options.session;
1784
1439
  this._recording = options.recording ?? false;
1785
1440
  this._recordingPath = options.recordingPath ?? "./recordings";
1786
1441
  this._mcpServers = options.mcpServers ?? [];
1787
- this._builtinTools = resolveBuiltinTools(options.builtinTools ?? "all" /* ALL */);
1442
+ this._builtinTools = chunkU4UFTVLX_cjs.resolveBuiltinTools(options.builtinTools ?? "all" /* ALL */);
1788
1443
  this._passiveDtmfDebounceMs = options.passiveDtmfDebounceMs ?? 500;
1789
1444
  this._rxGain = _ClawOpsAgent._validateGain("rxGain", options.rxGain ?? 1);
1790
1445
  this._txGain = _ClawOpsAgent._validateGain("txGain", options.txGain ?? 1);
@@ -1793,8 +1448,8 @@ var ClawOpsAgent = class _ClawOpsAgent {
1793
1448
  if (options.tracing) {
1794
1449
  setTracingConfig(options.tracing);
1795
1450
  }
1796
- this._log = createAgentLogger(options.logger);
1797
- this._pipelineLog = createPipelineLogger(this._log);
1451
+ this._log = chunkU4UFTVLX_cjs.createAgentLogger(options.logger);
1452
+ this._pipelineLog = chunkU4UFTVLX_cjs.createPipelineLogger(this._log);
1798
1453
  this._isPipelineSession = "_stt" in this._session && "_llm" in this._session;
1799
1454
  if (options.toolConfig?.holdAudio) {
1800
1455
  this._holdAudioChunks = loadHoldAudio(options.toolConfig.holdAudio);
@@ -1802,7 +1457,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
1802
1457
  }
1803
1458
  static _validateGain(name, gain) {
1804
1459
  if (typeof gain !== "number" || !Number.isFinite(gain) || gain < 0) {
1805
- throw new chunkNXMTLS2U_cjs.AgentError(`${name}=${gain} must be a finite number >= 0`);
1460
+ throw new chunkIVJXHNUN_cjs.AgentError(`${name}=${gain} must be a finite number >= 0`);
1806
1461
  }
1807
1462
  return gain;
1808
1463
  }
@@ -1816,7 +1471,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
1816
1471
  tool(nameOrTool, description, parameters, handler) {
1817
1472
  if (typeof nameOrTool === "string") {
1818
1473
  if (!description || !parameters || !handler) {
1819
- throw new chunkNXMTLS2U_cjs.AgentError(
1474
+ throw new chunkIVJXHNUN_cjs.AgentError(
1820
1475
  "tool(name, description, parameters, handler) requires all arguments."
1821
1476
  );
1822
1477
  }
@@ -1852,10 +1507,10 @@ var ClawOpsAgent = class _ClawOpsAgent {
1852
1507
  async connect() {
1853
1508
  if (this._controlWs) return;
1854
1509
  if (!this._apiKey) {
1855
- throw new chunkNXMTLS2U_cjs.AgentError("API key is required. Set CLAWOPS_API_KEY or pass apiKey option.");
1510
+ throw new chunkIVJXHNUN_cjs.AgentError("API key is required. Set CLAWOPS_API_KEY or pass apiKey option.");
1856
1511
  }
1857
1512
  if (!this._accountId) {
1858
- throw new chunkNXMTLS2U_cjs.AgentError(
1513
+ throw new chunkIVJXHNUN_cjs.AgentError(
1859
1514
  "Account ID is required. Set CLAWOPS_ACCOUNT_ID or pass accountId option."
1860
1515
  );
1861
1516
  }
@@ -1879,7 +1534,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
1879
1534
  } catch {
1880
1535
  }
1881
1536
  } catch (err) {
1882
- throw new chunkNXMTLS2U_cjs.AgentConnectionError(
1537
+ throw new chunkIVJXHNUN_cjs.AgentConnectionError(
1883
1538
  `Failed to connect to ClawOps: ${err instanceof Error ? err.message : String(err)}`
1884
1539
  );
1885
1540
  }
@@ -1943,7 +1598,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
1943
1598
  });
1944
1599
  if (resp.status !== 201) {
1945
1600
  const error = await resp.json();
1946
- throw new chunkNXMTLS2U_cjs.AgentError(`\uBC1C\uC2E0 \uC2E4\uD328 (${resp.status}): ${error["error"] ?? ""}`);
1601
+ throw new chunkIVJXHNUN_cjs.AgentError(`\uBC1C\uC2E0 \uC2E4\uD328 (${resp.status}): ${error["error"] ?? ""}`);
1947
1602
  }
1948
1603
  const data = await resp.json();
1949
1604
  const callSession = new CallSession({
@@ -1994,10 +1649,15 @@ var ClawOpsAgent = class _ClawOpsAgent {
1994
1649
  }
1995
1650
  _handleEnded(event) {
1996
1651
  const callId = event["callId"];
1652
+ const status = event["status"] || "completed";
1997
1653
  const session = this._activeSessions.get(callId);
1998
1654
  if (session) {
1999
- this._log.info("Call ended (server): %s", callId);
2000
- session._markEnded();
1655
+ this._log.info("Call ended (server): %s (status=%s)", callId, status);
1656
+ if (status !== "completed") {
1657
+ this._log.info("Outbound call not connected: %s (%s)", callId, status);
1658
+ session._emit("call_failed", status);
1659
+ }
1660
+ session._markEnded(status);
2001
1661
  this._activeSessions.delete(callId);
2002
1662
  }
2003
1663
  void this._cleanupPrewarm(callId);
@@ -2109,9 +1769,10 @@ var ClawOpsAgent = class _ClawOpsAgent {
2109
1769
  const callId = event["callId"];
2110
1770
  const session = this._activeSessions.get(callId);
2111
1771
  if (session) {
2112
- this._log.info("Outbound call failed: %s (%s)", callId, event["reason"] ?? "failed");
2113
- session._emit("call_failed", event["reason"] ?? "failed");
2114
- session._markEnded();
1772
+ const reason = event["reason"] ?? "failed";
1773
+ this._log.info("Outbound call failed: %s (%s)", callId, reason);
1774
+ session._emit("call_failed", reason);
1775
+ session._markEnded(reason);
2115
1776
  this._activeSessions.delete(callId);
2116
1777
  }
2117
1778
  void this._cleanupPrewarm(callId);
@@ -2202,9 +1863,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
2202
1863
  let latestMediaTs = 0;
2203
1864
  session._bindTransport(
2204
1865
  (audio) => {
2205
- const gained = applyUlawGain(audio, this._txGain);
1866
+ const gained = chunkU4UFTVLX_cjs.applyUlawGain(audio, this._txGain);
2206
1867
  if (recorder) {
2207
- recorder.writeOutbound(ulawToPcm16(gained), latestMediaTs);
1868
+ recorder.writeOutbound(chunkU4UFTVLX_cjs.ulawToPcm16(gained), latestMediaTs);
2208
1869
  }
2209
1870
  mediaWs.sendAudio(gained.toString("base64"));
2210
1871
  session.recordFirstResponse();
@@ -2226,6 +1887,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
2226
1887
  () => mediaWs.isConnected
2227
1888
  );
2228
1889
  session._transferFn = (params) => this._controlWs.requestTransfer(session.callId, params);
1890
+ session._sendMark = (name) => mediaWs.sendMark(name);
1891
+ session._waitForMark = (name, timeoutMs) => mediaWs.waitForMark(name, timeoutMs);
1892
+ session._flushTransport = () => mediaWs.flush();
2229
1893
  const sessionHandler = this._session;
2230
1894
  if ("setToolRegistry" in sessionHandler && typeof sessionHandler.setToolRegistry === "function") {
2231
1895
  sessionHandler.setToolRegistry(sessionTools);
@@ -2245,9 +1909,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
2245
1909
  this._callSessions.set(session.callId, sessionHandler);
2246
1910
  mediaWs.onAudio((ulawAudio, timestamp) => {
2247
1911
  latestMediaTs = timestamp;
2248
- const gained = applyUlawGain(ulawAudio, this._rxGain);
1912
+ const gained = chunkU4UFTVLX_cjs.applyUlawGain(ulawAudio, this._rxGain);
2249
1913
  if (recorder) {
2250
- recorder.writeInbound(ulawToPcm16(gained), timestamp);
1914
+ recorder.writeInbound(chunkU4UFTVLX_cjs.ulawToPcm16(gained), timestamp);
2251
1915
  }
2252
1916
  if (sessionHandler) {
2253
1917
  sessionHandler.feedAudio(gained, timestamp);
@@ -2341,232 +2005,6 @@ var ClawOpsAgent = class _ClawOpsAgent {
2341
2005
  }
2342
2006
  };
2343
2007
 
2344
- // src/agent/pipeline/builtin-tool-schemas.ts
2345
- var HANG_UP = {
2346
- name: "hang_up",
2347
- description: "End the phone call. Use when the conversation is finished or the caller says goodbye.",
2348
- parameters: { type: "object", properties: {} }
2349
- };
2350
- var COLLECT_DTMF = {
2351
- name: "collect_dtmf",
2352
- description: "\uC0AC\uC6A9\uC790\uB85C\uBD80\uD130 DTMF(\uC804\uD654 \uD0A4\uD328\uB4DC) \uC785\uB825\uC744 \uC218\uC9D1\uD569\uB2C8\uB2E4. \uBC18\uB4DC\uC2DC \uC0AC\uC6A9\uC790\uC5D0\uAC8C \uBB34\uC5C7\uC744 \uC785\uB825\uD574\uC57C \uD558\uB294\uC9C0 \uC548\uB0B4\uD55C \uD6C4 \uD638\uCD9C\uD558\uC138\uC694.",
2353
- parameters: {
2354
- type: "object",
2355
- properties: {
2356
- max_digits: { type: "integer", description: "\uC218\uC9D1\uD560 \uCD5C\uB300 \uC790\uB9BF\uC218" },
2357
- finish_on_key: { type: "string", description: "\uC785\uB825 \uC885\uB8CC \uD0A4 (\uAE30\uBCF8: #)" },
2358
- timeout: { type: "integer", description: "\uC785\uB825 \uB300\uAE30 \uC2DC\uAC04(\uCD08, \uAE30\uBCF8: 5)" }
2359
- },
2360
- required: ["max_digits"]
2361
- }
2362
- };
2363
- var SEND_DTMF = {
2364
- name: "send_dtmf",
2365
- description: "DTMF \uC2E0\uD638\uB97C \uC804\uC1A1\uD569\uB2C8\uB2E4. ARS \uBA54\uB274 \uD0D0\uC0C9\uC774\uB098 \uB0B4\uC120\uBC88\uD638 \uC785\uB825 \uC2DC \uC0AC\uC6A9\uD569\uB2C8\uB2E4.",
2366
- parameters: {
2367
- type: "object",
2368
- properties: {
2369
- digits: {
2370
- type: "string",
2371
- description: "\uC804\uC1A1\uD560 \uBC88\uD638 (0-9, *, #). 'w'\uB294 500ms \uB300\uAE30, 'W'\uB294 1000ms \uB300\uAE30. \uC608: '1', '1234#', '1w2'"
2372
- }
2373
- },
2374
- required: ["digits"]
2375
- }
2376
- };
2377
- var TRANSFER_CALL = {
2378
- name: "transfer_call",
2379
- description: "Transfer the current call to another phone number or SIP endpoint. Use for blind transfer (direct handoff) or warm transfer (with whisper message to the target).",
2380
- parameters: {
2381
- type: "object",
2382
- properties: {
2383
- to: { type: "string", description: "Transfer destination. A phone number when destination_type is 'pstn', or a SIP URI (e.g. 'sip:user@host') when destination_type is 'sip'." },
2384
- destination_type: { type: "string", enum: ["pstn", "sip"], description: "pstn: dial a phone number via carrier (default). sip: connect directly to a SIP endpoint (no carrier/PSTN)." },
2385
- mode: { type: "string", enum: ["blind", "warm"], description: "blind: direct transfer (default), warm: play whisper to target first" },
2386
- after_transfer: { type: "string", enum: ["terminate", "return"], description: "terminate: end AI session (default), return: AI resumes after transfer ends" },
2387
- whisper: { type: "string", description: "Message to speak to transfer target before connecting customer (warm mode only)" },
2388
- caller_id: { type: "string", description: "Override caller ID for the transfer leg" },
2389
- timeout: { type: "integer", description: "Seconds to wait for transfer target to answer (default 30)" }
2390
- },
2391
- required: ["to"]
2392
- }
2393
- };
2394
- var TOOL_MAP = /* @__PURE__ */ new Map([
2395
- ["hang_up" /* HANG_UP */, HANG_UP],
2396
- ["collect_dtmf" /* COLLECT_DTMF */, COLLECT_DTMF],
2397
- ["send_dtmf" /* SEND_DTMF */, SEND_DTMF],
2398
- ["transfer_call" /* TRANSFER_CALL */, TRANSFER_CALL]
2399
- ]);
2400
- var BUILTIN_TOOL_NAMES = new Set(
2401
- Array.from(TOOL_MAP.values()).map((s) => s.name)
2402
- );
2403
- function toChatCompletions(schema) {
2404
- return {
2405
- type: "function",
2406
- function: {
2407
- name: schema.name,
2408
- description: schema.description,
2409
- parameters: schema.parameters
2410
- }
2411
- };
2412
- }
2413
- function toRealtime(schema) {
2414
- return {
2415
- type: "function",
2416
- name: schema.name,
2417
- description: schema.description,
2418
- parameters: schema.parameters
2419
- };
2420
- }
2421
- function toGemini(schema) {
2422
- return {
2423
- name: schema.name,
2424
- description: schema.description,
2425
- parameters: schema.parameters
2426
- };
2427
- }
2428
- var CONVERTERS = {
2429
- chat: toChatCompletions,
2430
- realtime: toRealtime,
2431
- gemini: toGemini
2432
- };
2433
- function getBuiltinToolSchemas(builtinTools, fmt) {
2434
- const converter = CONVERTERS[fmt];
2435
- const result = [];
2436
- for (const [toolEnum, schema] of TOOL_MAP) {
2437
- if (builtinTools === null || builtinTools.has(toolEnum)) {
2438
- result.push(converter(schema));
2439
- }
2440
- }
2441
- return result;
2442
- }
2443
- function isBuiltinTool(name) {
2444
- return BUILTIN_TOOL_NAMES.has(name);
2445
- }
2446
- async function executeBuiltinTool(funcName, args, call) {
2447
- if (funcName === "hang_up") {
2448
- await call.hangup();
2449
- return "";
2450
- }
2451
- if (funcName === "collect_dtmf") {
2452
- try {
2453
- const result = await call.collectDtmf({
2454
- maxDigits: args["max_digits"] ?? 4,
2455
- finishOnKey: args["finish_on_key"] ?? "#",
2456
- timeout: args["timeout"] ?? 5
2457
- });
2458
- return result || "(\uD0C0\uC784\uC544\uC6C3 - \uC785\uB825 \uC5C6\uC74C)";
2459
- } catch (e) {
2460
- return `Error: ${e}`;
2461
- }
2462
- }
2463
- if (funcName === "send_dtmf") {
2464
- try {
2465
- await call.sendDtmfSequence(args["digits"] ?? "");
2466
- return "sent";
2467
- } catch (e) {
2468
- return `Error: ${e}`;
2469
- }
2470
- }
2471
- if (funcName === "transfer_call") {
2472
- try {
2473
- call.transfer(args["to"], {
2474
- destinationType: args["destination_type"] ?? void 0,
2475
- mode: args["mode"] ?? void 0,
2476
- afterTransfer: args["after_transfer"] ?? void 0,
2477
- whisper: args["whisper"] ?? void 0,
2478
- callerId: args["caller_id"] ?? void 0,
2479
- timeout: args["timeout"] ?? void 0
2480
- }).catch(() => {
2481
- });
2482
- return JSON.stringify({ status: "transfer_initiated" });
2483
- } catch (e) {
2484
- return `Error: ${e}`;
2485
- }
2486
- }
2487
- return null;
2488
- }
2489
-
2490
- // src/agent/pipeline/buffering-call.ts
2491
- var MetricsStub = class {
2492
- recordToolCall() {
2493
- }
2494
- recordInterrupt() {
2495
- }
2496
- recordToolError() {
2497
- }
2498
- };
2499
- var BufferingCall = class {
2500
- _buffer = [];
2501
- _droppedEvents = {};
2502
- metrics = new MetricsStub();
2503
- async sendAudio(chunk) {
2504
- this._buffer.push(chunk);
2505
- }
2506
- /** clearAudio 도 prewarm 동안엔 no-op (드물긴 하지만 안전하게). */
2507
- clearAudio() {
2508
- this._buffer = [];
2509
- }
2510
- /**
2511
- * transcript 등 lifecycle 이벤트는 prewarm 동안 무시한다. silent drop 은 디버깅이
2512
- * 어려우므로 event name 별 카운터로 누적하고 attachBuffered() 시 한 번에 로깅한다.
2513
- */
2514
- _emit(...args) {
2515
- this._recordDropped(args);
2516
- }
2517
- async emit(...args) {
2518
- this._recordDropped(args);
2519
- }
2520
- _recordDropped(args) {
2521
- let eventName = "?";
2522
- if (args.length > 0 && typeof args[0] === "string") {
2523
- eventName = args[0];
2524
- }
2525
- this._droppedEvents[eventName] = (this._droppedEvents[eventName] ?? 0) + 1;
2526
- }
2527
- recordToolCall() {
2528
- }
2529
- recordToolError() {
2530
- }
2531
- recordFirstResponse() {
2532
- }
2533
- recordBargeIn() {
2534
- }
2535
- drainBuffer() {
2536
- const out = this._buffer;
2537
- this._buffer = [];
2538
- return out;
2539
- }
2540
- drainDroppedEvents() {
2541
- const out = this._droppedEvents;
2542
- this._droppedEvents = {};
2543
- return out;
2544
- }
2545
- };
2546
- function attachBuffered(prev, next) {
2547
- if (!(prev instanceof BufferingCall)) {
2548
- return false;
2549
- }
2550
- const drained = prev.drainBuffer();
2551
- const flushed = drained.length > 0;
2552
- const callId = next.callId ?? "?";
2553
- if (flushed) {
2554
- console.info(
2555
- `[PREWARM-T] first-audio call_id=${callId} t=${(process.hrtime.bigint() / 1000000n).toString()} buffered_chunks=${drained.length} source=prebuffer`
2556
- );
2557
- }
2558
- for (const chunk of drained) {
2559
- next.sendAudio(chunk);
2560
- }
2561
- const dropped = prev.drainDroppedEvents();
2562
- if (Object.keys(dropped).length > 0) {
2563
- console.info(
2564
- `[PREWARM] dropped events during prewarm call_id=${callId} events=${JSON.stringify(dropped)}`
2565
- );
2566
- }
2567
- return flushed;
2568
- }
2569
-
2570
2008
  // src/agent/pipeline/pipeline-session.ts
2571
2009
  var PipelineSession = class {
2572
2010
  _stt;
@@ -2588,7 +2026,7 @@ var PipelineSession = class {
2588
2026
  _speaking = false;
2589
2027
  _builtinTools = null;
2590
2028
  _holdAudioChunks = null;
2591
- _log = NOOP_LOGGER;
2029
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
2592
2030
  constructor(options) {
2593
2031
  this._stt = options.stt;
2594
2032
  this._llm = options.llm;
@@ -2650,7 +2088,7 @@ var PipelineSession = class {
2650
2088
  */
2651
2089
  async prewarm(tools) {
2652
2090
  if (tools) this._tools = tools;
2653
- this._callSession = new BufferingCall();
2091
+ this._callSession = new chunkU4UFTVLX_cjs.BufferingCall();
2654
2092
  this._running = true;
2655
2093
  this._conversation = [];
2656
2094
  this._log.info("PipelineSession prewarmed");
@@ -2673,7 +2111,7 @@ var PipelineSession = class {
2673
2111
  async attach(callSession) {
2674
2112
  const prev = this._callSession;
2675
2113
  this._callSession = callSession;
2676
- attachBuffered(prev, callSession);
2114
+ chunkU4UFTVLX_cjs.attachBuffered(prev, callSession);
2677
2115
  }
2678
2116
  async start(callSession, tools) {
2679
2117
  this._tools = tools ?? null;
@@ -2720,8 +2158,8 @@ var PipelineSession = class {
2720
2158
  while (this._running) {
2721
2159
  if (this._audioBuffer.length > 0) {
2722
2160
  const ulaw = this._audioBuffer.shift();
2723
- const pcm8k = ulawToPcm16(ulaw);
2724
- const pcm16k = resamplePcm16(pcm8k, 8e3, 16e3);
2161
+ const pcm8k = chunkU4UFTVLX_cjs.ulawToPcm16(ulaw);
2162
+ const pcm16k = chunkU4UFTVLX_cjs.resamplePcm16(pcm8k, 8e3, 16e3);
2725
2163
  yield pcm16k;
2726
2164
  } else {
2727
2165
  await new Promise((resolve) => setTimeout(resolve, 20));
@@ -2737,7 +2175,7 @@ var PipelineSession = class {
2737
2175
  await this._respond();
2738
2176
  }
2739
2177
  _buildEffectiveTools() {
2740
- const builtinSchemas = getBuiltinToolSchemas(this._builtinTools, "chat");
2178
+ const builtinSchemas = chunkU4UFTVLX_cjs.getBuiltinToolSchemas(this._builtinTools, "chat");
2741
2179
  const dtmfSchemas = builtinSchemas.filter((s) => {
2742
2180
  const name = s["function"]?.["name"];
2743
2181
  return name === "collect_dtmf" || name === "send_dtmf";
@@ -2786,8 +2224,8 @@ var PipelineSession = class {
2786
2224
  const { id, name, arguments: argsStr } = chunk.toolCall;
2787
2225
  try {
2788
2226
  const args = JSON.parse(argsStr);
2789
- if (BUILTIN_TOOL_NAMES.has(name) && this._callSession && !(this._callSession instanceof BufferingCall)) {
2790
- const result2 = await executeBuiltinTool(name, args, this._callSession);
2227
+ if (chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES.has(name) && this._callSession && !(this._callSession instanceof chunkU4UFTVLX_cjs.BufferingCall)) {
2228
+ const result2 = await chunkU4UFTVLX_cjs.executeBuiltinTool(name, args, this._callSession);
2791
2229
  if (result2 !== null) {
2792
2230
  if (name === "hang_up") return;
2793
2231
  this._conversation.push({ role: "tool", content: result2, tool_call_id: id, name });
@@ -2797,7 +2235,7 @@ var PipelineSession = class {
2797
2235
  }
2798
2236
  if (!this._tools) return;
2799
2237
  this._callSession?.recordToolCall();
2800
- const player = this._holdAudioChunks && this._callSession && !(this._callSession instanceof BufferingCall) ? new HoldAudioPlayer(this._callSession, this._holdAudioChunks) : null;
2238
+ const player = this._holdAudioChunks && this._callSession && !(this._callSession instanceof chunkU4UFTVLX_cjs.BufferingCall) ? new HoldAudioPlayer(this._callSession, this._holdAudioChunks) : null;
2801
2239
  player?.start();
2802
2240
  let result;
2803
2241
  try {
@@ -2848,8 +2286,8 @@ var PipelineSession = class {
2848
2286
  sampleRate: this._sampleRate
2849
2287
  })) {
2850
2288
  if (!this._running || !this._speaking) break;
2851
- const pcm8k = resamplePcm16(audioChunk, this._sampleRate, 8e3);
2852
- const ulaw = pcm16ToUlaw(pcm8k);
2289
+ const pcm8k = chunkU4UFTVLX_cjs.resamplePcm16(audioChunk, this._sampleRate, 8e3);
2290
+ const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcm8k);
2853
2291
  for (let off = 0; off < ulaw.length; off += 160) {
2854
2292
  let chunk = ulaw.subarray(off, off + 160);
2855
2293
  if (chunk.length < 160) {
@@ -2876,7 +2314,7 @@ var OpenAIRealtime = class {
2876
2314
  _language;
2877
2315
  _turnDetection;
2878
2316
  _greeting;
2879
- _log = NOOP_LOGGER;
2317
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
2880
2318
  _builtinTools = null;
2881
2319
  setLogger(logger) {
2882
2320
  this._log = logger;
@@ -2948,7 +2386,7 @@ var OpenAIRealtime = class {
2948
2386
  /** Open WS + session.update + (optional) response.create without a CallSession. */
2949
2387
  async prewarm(tools) {
2950
2388
  if (tools) this._tools = tools;
2951
- this._call = new BufferingCall();
2389
+ this._call = new chunkU4UFTVLX_cjs.BufferingCall();
2952
2390
  this._closed = false;
2953
2391
  this._playback = null;
2954
2392
  this._latestMediaTs = 0;
@@ -2989,7 +2427,7 @@ var OpenAIRealtime = class {
2989
2427
  async attach(callSession) {
2990
2428
  const prev = this._call;
2991
2429
  this._call = callSession;
2992
- attachBuffered(prev, callSession);
2430
+ chunkU4UFTVLX_cjs.attachBuffered(prev, callSession);
2993
2431
  }
2994
2432
  async start(callSession, tools) {
2995
2433
  if (tools) this._tools = tools;
@@ -3050,7 +2488,7 @@ var OpenAIRealtime = class {
3050
2488
  _sendSessionUpdate() {
3051
2489
  if (!this._ws || this._ws.readyState !== 1) return;
3052
2490
  const toolSchemas = this._tools ? this._tools.toOpenAITools().map((t) => ({ type: "function", ...t.function })) : [];
3053
- toolSchemas.push(...getBuiltinToolSchemas(this._builtinTools, "realtime"));
2491
+ toolSchemas.push(...chunkU4UFTVLX_cjs.getBuiltinToolSchemas(this._builtinTools, "realtime"));
3054
2492
  this._send({
3055
2493
  type: "session.update",
3056
2494
  session: {
@@ -3195,9 +2633,9 @@ var OpenAIRealtime = class {
3195
2633
  const controller = new AbortController();
3196
2634
  this._pendingToolCalls.set(callId, controller);
3197
2635
  try {
3198
- if (BUILTIN_TOOL_NAMES.has(funcName) && this._call && !(this._call instanceof BufferingCall)) {
2636
+ if (chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES.has(funcName) && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall)) {
3199
2637
  const args = JSON.parse(item["arguments"] ?? "{}");
3200
- const result2 = await executeBuiltinTool(funcName, args, this._call);
2638
+ const result2 = await chunkU4UFTVLX_cjs.executeBuiltinTool(funcName, args, this._call);
3201
2639
  if (result2 !== null) {
3202
2640
  if (funcName === "hang_up") return;
3203
2641
  if (controller.signal.aborted) return;
@@ -3229,7 +2667,7 @@ var OpenAIRealtime = class {
3229
2667
  return;
3230
2668
  }
3231
2669
  let result;
3232
- const player = this._holdAudioChunks && this._call && !(this._call instanceof BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
2670
+ const player = this._holdAudioChunks && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
3233
2671
  player?.start();
3234
2672
  try {
3235
2673
  const args = JSON.parse(item["arguments"] ?? "{}");
@@ -3371,7 +2809,7 @@ var GeminiRealtime = class _GeminiRealtime {
3371
2809
  _toolDrainTimer = null;
3372
2810
  _lastAudioTime = 0;
3373
2811
  _holdAudioChunks = null;
3374
- _log = NOOP_LOGGER;
2812
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
3375
2813
  constructor(options = {}) {
3376
2814
  this._apiKey = options.apiKey ?? process.env["GOOGLE_API_KEY"] ?? "";
3377
2815
  this._systemPrompt = options.systemPrompt ?? "";
@@ -3417,7 +2855,7 @@ var GeminiRealtime = class _GeminiRealtime {
3417
2855
  /** Open Live session (no CallSession). Audio deltas accumulate into BufferingCall until attach(). */
3418
2856
  async prewarm(tools) {
3419
2857
  if (tools) this._tools = tools;
3420
- this._call = new BufferingCall();
2858
+ this._call = new chunkU4UFTVLX_cjs.BufferingCall();
3421
2859
  this._closed = false;
3422
2860
  this._sentAudioChunks = 0;
3423
2861
  this._audioRemainder = Buffer.alloc(0);
@@ -3474,7 +2912,7 @@ var GeminiRealtime = class _GeminiRealtime {
3474
2912
  async attach(callSession) {
3475
2913
  const prev = this._call;
3476
2914
  this._call = callSession;
3477
- attachBuffered(prev, callSession);
2915
+ chunkU4UFTVLX_cjs.attachBuffered(prev, callSession);
3478
2916
  }
3479
2917
  async start(callSession, tools) {
3480
2918
  if (tools) this._tools = tools;
@@ -3483,8 +2921,8 @@ var GeminiRealtime = class _GeminiRealtime {
3483
2921
  }
3484
2922
  feedAudio(audio) {
3485
2923
  if (this._session && !this._closed) {
3486
- const pcm8k = ulawToPcm16(audio);
3487
- const pcm16k = resamplePcm16(pcm8k, 8e3, 16e3);
2924
+ const pcm8k = chunkU4UFTVLX_cjs.ulawToPcm16(audio);
2925
+ const pcm16k = chunkU4UFTVLX_cjs.resamplePcm16(pcm8k, 8e3, 16e3);
3488
2926
  this._session.sendRealtimeInput({
3489
2927
  audio: {
3490
2928
  data: Buffer.from(pcm16k).toString("base64"),
@@ -3528,7 +2966,7 @@ var GeminiRealtime = class _GeminiRealtime {
3528
2966
  t.function.parameters ?? { type: "object", properties: {} }
3529
2967
  )
3530
2968
  })) : [];
3531
- toolDefs.push(...getBuiltinToolSchemas(this._builtinTools, "gemini"));
2969
+ toolDefs.push(...chunkU4UFTVLX_cjs.getBuiltinToolSchemas(this._builtinTools, "gemini"));
3532
2970
  return toolDefs;
3533
2971
  }
3534
2972
  _handleMessage(msg) {
@@ -3588,8 +3026,8 @@ var GeminiRealtime = class _GeminiRealtime {
3588
3026
  _handleAudioData(b64Data) {
3589
3027
  if (!this._call) return;
3590
3028
  const pcm24k = Buffer.from(b64Data, "base64");
3591
- const pcm8k = resamplePcm16(pcm24k, 24e3, 8e3);
3592
- const ulaw = pcm16ToUlaw(pcm8k);
3029
+ const pcm8k = chunkU4UFTVLX_cjs.resamplePcm16(pcm24k, 24e3, 8e3);
3030
+ const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcm8k);
3593
3031
  const combined = Buffer.concat([this._audioRemainder, ulaw]);
3594
3032
  const chunkSize = 160;
3595
3033
  const fullEnd = Math.floor(combined.length / chunkSize) * chunkSize;
@@ -3632,7 +3070,7 @@ var GeminiRealtime = class _GeminiRealtime {
3632
3070
  const functionCalls = toolCall.functionCalls;
3633
3071
  if (!functionCalls) return;
3634
3072
  const responses = [];
3635
- const player = this._holdAudioChunks && this._call && !(this._call instanceof BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
3073
+ const player = this._holdAudioChunks && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
3636
3074
  player?.start();
3637
3075
  try {
3638
3076
  for (const fc of functionCalls) {
@@ -3640,8 +3078,8 @@ var GeminiRealtime = class _GeminiRealtime {
3640
3078
  const fcId = fc.id ?? "";
3641
3079
  const args = fc.args ?? {};
3642
3080
  this._log.info({ tool: name, args }, "Tool call: %s", name);
3643
- if (BUILTIN_TOOL_NAMES.has(name) && this._call && !(this._call instanceof BufferingCall)) {
3644
- const result = await executeBuiltinTool(
3081
+ if (chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES.has(name) && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall)) {
3082
+ const result = await chunkU4UFTVLX_cjs.executeBuiltinTool(
3645
3083
  name,
3646
3084
  args,
3647
3085
  this._call
@@ -3698,7 +3136,7 @@ var GeminiRealtime = class _GeminiRealtime {
3698
3136
  // src/agent/pipeline/stt/deepgram-stt.ts
3699
3137
  var DeepgramSTT = class {
3700
3138
  _options;
3701
- _log = NOOP_LOGGER;
3139
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
3702
3140
  get provider() {
3703
3141
  return "deepgram";
3704
3142
  }
@@ -3825,7 +3263,7 @@ var DeepgramSTT = class {
3825
3263
  // src/agent/pipeline/tts/elevenlabs-tts.ts
3826
3264
  var ElevenLabsTTS = class {
3827
3265
  _options;
3828
- _log = NOOP_LOGGER;
3266
+ _log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
3829
3267
  get provider() {
3830
3268
  return "elevenlabs";
3831
3269
  }
@@ -4569,14 +4007,55 @@ function mcpServerHTTP(options) {
4569
4007
  };
4570
4008
  }
4571
4009
 
4010
+ Object.defineProperty(exports, "BUILTIN_TOOL_NAMES", {
4011
+ enumerable: true,
4012
+ get: function () { return chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES; }
4013
+ });
4014
+ Object.defineProperty(exports, "BuiltinTool", {
4015
+ enumerable: true,
4016
+ get: function () { return chunkU4UFTVLX_cjs.BuiltinTool; }
4017
+ });
4018
+ Object.defineProperty(exports, "DECODE_TABLE", {
4019
+ enumerable: true,
4020
+ get: function () { return chunkU4UFTVLX_cjs.DECODE_TABLE; }
4021
+ });
4022
+ Object.defineProperty(exports, "createAgentLogger", {
4023
+ enumerable: true,
4024
+ get: function () { return chunkU4UFTVLX_cjs.createAgentLogger; }
4025
+ });
4026
+ Object.defineProperty(exports, "createPipelineLogger", {
4027
+ enumerable: true,
4028
+ get: function () { return chunkU4UFTVLX_cjs.createPipelineLogger; }
4029
+ });
4030
+ Object.defineProperty(exports, "executeBuiltinTool", {
4031
+ enumerable: true,
4032
+ get: function () { return chunkU4UFTVLX_cjs.executeBuiltinTool; }
4033
+ });
4034
+ Object.defineProperty(exports, "getBuiltinToolSchemas", {
4035
+ enumerable: true,
4036
+ get: function () { return chunkU4UFTVLX_cjs.getBuiltinToolSchemas; }
4037
+ });
4038
+ Object.defineProperty(exports, "isBuiltinTool", {
4039
+ enumerable: true,
4040
+ get: function () { return chunkU4UFTVLX_cjs.isBuiltinTool; }
4041
+ });
4042
+ Object.defineProperty(exports, "pcm16ToUlaw", {
4043
+ enumerable: true,
4044
+ get: function () { return chunkU4UFTVLX_cjs.pcm16ToUlaw; }
4045
+ });
4046
+ Object.defineProperty(exports, "resamplePcm16", {
4047
+ enumerable: true,
4048
+ get: function () { return chunkU4UFTVLX_cjs.resamplePcm16; }
4049
+ });
4050
+ Object.defineProperty(exports, "ulawToPcm16", {
4051
+ enumerable: true,
4052
+ get: function () { return chunkU4UFTVLX_cjs.ulawToPcm16; }
4053
+ });
4572
4054
  exports.AnthropicLLM = AnthropicLLM;
4573
4055
  exports.AudioRecorder = AudioRecorder;
4574
- exports.BUILTIN_TOOL_NAMES = BUILTIN_TOOL_NAMES;
4575
- exports.BuiltinTool = BuiltinTool;
4576
4056
  exports.CallSession = CallSession;
4577
4057
  exports.ClawOpsAgent = ClawOpsAgent;
4578
4058
  exports.ControlWebSocket = ControlWebSocket;
4579
- exports.DECODE_TABLE = DECODE_TABLE;
4580
4059
  exports.DeepSeekLLM = DeepSeekLLM;
4581
4060
  exports.DeepgramSTT = DeepgramSTT;
4582
4061
  exports.ElevenLabsTTS = ElevenLabsTTS;
@@ -4597,20 +4076,12 @@ exports.TogetherLLM = TogetherLLM;
4597
4076
  exports.ToolRegistry = ToolRegistry;
4598
4077
  exports.XaiLLM = XaiLLM;
4599
4078
  exports.buildControlWsUrl = buildControlWsUrl;
4600
- exports.createAgentLogger = createAgentLogger;
4601
- exports.createPipelineLogger = createPipelineLogger;
4602
- exports.executeBuiltinTool = executeBuiltinTool;
4603
4079
  exports.functionTool = functionTool;
4604
- exports.getBuiltinToolSchemas = getBuiltinToolSchemas;
4605
4080
  exports.getTracingConfig = getTracingConfig;
4606
- exports.isBuiltinTool = isBuiltinTool;
4607
4081
  exports.mcpServerHTTP = mcpServerHTTP;
4608
4082
  exports.mcpServerStdio = mcpServerStdio;
4609
- exports.pcm16ToUlaw = pcm16ToUlaw;
4610
- exports.resamplePcm16 = resamplePcm16;
4611
4083
  exports.resetTracingConfig = resetTracingConfig;
4612
4084
  exports.setTracingConfig = setTracingConfig;
4613
- exports.ulawToPcm16 = ulawToPcm16;
4614
4085
  exports.zodToToolParams = zodToToolParams;
4615
4086
  //# sourceMappingURL=index.cjs.map
4616
4087
  //# sourceMappingURL=index.cjs.map