@teamlearners/clawops 0.23.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.
- package/dist/agent/index.cjs +114 -673
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +4 -328
- package/dist/agent/index.d.ts +4 -328
- package/dist/agent/index.js +18 -608
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/livekit/index.cjs +496 -0
- package/dist/agent/livekit/index.cjs.map +1 -0
- package/dist/agent/livekit/index.d.cts +172 -0
- package/dist/agent/livekit/index.d.ts +172 -0
- package/dist/agent/livekit/index.js +490 -0
- package/dist/agent/livekit/index.js.map +1 -0
- package/dist/base-Z-uZdd27.d.cts +338 -0
- package/dist/base-Z-uZdd27.d.ts +338 -0
- package/dist/chunk-2BAYUQ7O.js +610 -0
- package/dist/chunk-2BAYUQ7O.js.map +1 -0
- package/dist/{chunk-JU36ASTU.js → chunk-7P2HGIPS.js} +3 -3
- package/dist/{chunk-JU36ASTU.js.map → chunk-7P2HGIPS.js.map} +1 -1
- package/dist/{chunk-NXMTLS2U.cjs → chunk-LUA53NPZ.cjs} +3 -3
- package/dist/{chunk-NXMTLS2U.cjs.map → chunk-LUA53NPZ.cjs.map} +1 -1
- package/dist/chunk-U4UFTVLX.cjs +631 -0
- package/dist/chunk-U4UFTVLX.cjs.map +1 -0
- package/dist/index.cjs +35 -35
- package/dist/index.js +2 -2
- package/package.json +14 -1
package/dist/agent/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkLUA53NPZ_cjs = require('../chunk-LUA53NPZ.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:
|
|
731
|
+
version: chunkLUA53NPZ_cjs.VERSION,
|
|
1083
732
|
runtime: `node/${process.versions.node}`,
|
|
1084
733
|
os: `${process.platform}/${os__default.default.arch()}`
|
|
1085
734
|
};
|
|
@@ -1124,10 +773,21 @@ var CallSession = class {
|
|
|
1124
773
|
_transferFn = null;
|
|
1125
774
|
/** @internal */
|
|
1126
775
|
_isTransportConnected = null;
|
|
776
|
+
/**
|
|
777
|
+
* @internal Media WS playout 마커 훅. LiveKit(`ClawOpsAudioOutput`)이 재생 완료
|
|
778
|
+
* 판정(mark echo)과 barge-in 절단 위치 계산에 쓴다. 다른 세션 타입은 읽지 않는다.
|
|
779
|
+
* prewarm 중(BufferingCall)에는 바인딩되지 않아 null 이다.
|
|
780
|
+
*/
|
|
781
|
+
/** @internal */
|
|
782
|
+
_sendMark = null;
|
|
783
|
+
/** @internal */
|
|
784
|
+
_waitForMark = null;
|
|
785
|
+
/** @internal */
|
|
786
|
+
_flushTransport = null;
|
|
1127
787
|
_dtmfCollectorActive = false;
|
|
1128
788
|
_dtmfResolvers = [];
|
|
1129
789
|
_dtmfBuffer = [];
|
|
1130
|
-
_log = NOOP_LOGGER;
|
|
790
|
+
_log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
|
|
1131
791
|
_handlers = /* @__PURE__ */ new Map();
|
|
1132
792
|
_endedPromise;
|
|
1133
793
|
_resolveEnded;
|
|
@@ -1337,35 +997,6 @@ var CallSession = class {
|
|
|
1337
997
|
}
|
|
1338
998
|
}
|
|
1339
999
|
};
|
|
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
1000
|
var CHUNK_SIZE = 160;
|
|
1370
1001
|
var SAMPLE_RATE2 = 8e3;
|
|
1371
1002
|
var BELL_PARTIALS = [
|
|
@@ -1450,7 +1081,7 @@ function generateComfortTone(volume = 0.12) {
|
|
|
1450
1081
|
}
|
|
1451
1082
|
}
|
|
1452
1083
|
const pcm = int16ArrayToBuffer(concatInt16Arrays(...parts));
|
|
1453
|
-
const ulaw = pcm16ToUlaw(pcm);
|
|
1084
|
+
const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcm);
|
|
1454
1085
|
const chunks = [];
|
|
1455
1086
|
for (let i = 0; i < ulaw.length; i += CHUNK_SIZE) {
|
|
1456
1087
|
chunks.push(ulaw.subarray(i, i + CHUNK_SIZE));
|
|
@@ -1507,9 +1138,9 @@ function loadHoldAudio(source) {
|
|
|
1507
1138
|
pcmData = mono;
|
|
1508
1139
|
}
|
|
1509
1140
|
if (sampleRate !== SAMPLE_RATE2) {
|
|
1510
|
-
pcmData = resamplePcm16(pcmData, sampleRate, SAMPLE_RATE2);
|
|
1141
|
+
pcmData = chunkU4UFTVLX_cjs.resamplePcm16(pcmData, sampleRate, SAMPLE_RATE2);
|
|
1511
1142
|
}
|
|
1512
|
-
const ulaw = pcm16ToUlaw(pcmData);
|
|
1143
|
+
const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcmData);
|
|
1513
1144
|
const chunks = [];
|
|
1514
1145
|
for (let i = 0; i < ulaw.length; i += CHUNK_SIZE) {
|
|
1515
1146
|
chunks.push(ulaw.subarray(i, i + CHUNK_SIZE));
|
|
@@ -1778,13 +1409,13 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1778
1409
|
constructor(options) {
|
|
1779
1410
|
this._apiKey = options.apiKey ?? process.env["CLAWOPS_API_KEY"] ?? "";
|
|
1780
1411
|
this._accountId = options.accountId ?? process.env["CLAWOPS_ACCOUNT_ID"] ?? "";
|
|
1781
|
-
this._baseUrl = options.baseUrl ??
|
|
1412
|
+
this._baseUrl = options.baseUrl ?? chunkLUA53NPZ_cjs.DEFAULT_BASE_URL;
|
|
1782
1413
|
this._fromNumber = options.from;
|
|
1783
1414
|
this._session = options.session;
|
|
1784
1415
|
this._recording = options.recording ?? false;
|
|
1785
1416
|
this._recordingPath = options.recordingPath ?? "./recordings";
|
|
1786
1417
|
this._mcpServers = options.mcpServers ?? [];
|
|
1787
|
-
this._builtinTools = resolveBuiltinTools(options.builtinTools ?? "all" /* ALL */);
|
|
1418
|
+
this._builtinTools = chunkU4UFTVLX_cjs.resolveBuiltinTools(options.builtinTools ?? "all" /* ALL */);
|
|
1788
1419
|
this._passiveDtmfDebounceMs = options.passiveDtmfDebounceMs ?? 500;
|
|
1789
1420
|
this._rxGain = _ClawOpsAgent._validateGain("rxGain", options.rxGain ?? 1);
|
|
1790
1421
|
this._txGain = _ClawOpsAgent._validateGain("txGain", options.txGain ?? 1);
|
|
@@ -1793,8 +1424,8 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1793
1424
|
if (options.tracing) {
|
|
1794
1425
|
setTracingConfig(options.tracing);
|
|
1795
1426
|
}
|
|
1796
|
-
this._log = createAgentLogger(options.logger);
|
|
1797
|
-
this._pipelineLog = createPipelineLogger(this._log);
|
|
1427
|
+
this._log = chunkU4UFTVLX_cjs.createAgentLogger(options.logger);
|
|
1428
|
+
this._pipelineLog = chunkU4UFTVLX_cjs.createPipelineLogger(this._log);
|
|
1798
1429
|
this._isPipelineSession = "_stt" in this._session && "_llm" in this._session;
|
|
1799
1430
|
if (options.toolConfig?.holdAudio) {
|
|
1800
1431
|
this._holdAudioChunks = loadHoldAudio(options.toolConfig.holdAudio);
|
|
@@ -1802,7 +1433,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1802
1433
|
}
|
|
1803
1434
|
static _validateGain(name, gain) {
|
|
1804
1435
|
if (typeof gain !== "number" || !Number.isFinite(gain) || gain < 0) {
|
|
1805
|
-
throw new
|
|
1436
|
+
throw new chunkLUA53NPZ_cjs.AgentError(`${name}=${gain} must be a finite number >= 0`);
|
|
1806
1437
|
}
|
|
1807
1438
|
return gain;
|
|
1808
1439
|
}
|
|
@@ -1816,7 +1447,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1816
1447
|
tool(nameOrTool, description, parameters, handler) {
|
|
1817
1448
|
if (typeof nameOrTool === "string") {
|
|
1818
1449
|
if (!description || !parameters || !handler) {
|
|
1819
|
-
throw new
|
|
1450
|
+
throw new chunkLUA53NPZ_cjs.AgentError(
|
|
1820
1451
|
"tool(name, description, parameters, handler) requires all arguments."
|
|
1821
1452
|
);
|
|
1822
1453
|
}
|
|
@@ -1852,10 +1483,10 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1852
1483
|
async connect() {
|
|
1853
1484
|
if (this._controlWs) return;
|
|
1854
1485
|
if (!this._apiKey) {
|
|
1855
|
-
throw new
|
|
1486
|
+
throw new chunkLUA53NPZ_cjs.AgentError("API key is required. Set CLAWOPS_API_KEY or pass apiKey option.");
|
|
1856
1487
|
}
|
|
1857
1488
|
if (!this._accountId) {
|
|
1858
|
-
throw new
|
|
1489
|
+
throw new chunkLUA53NPZ_cjs.AgentError(
|
|
1859
1490
|
"Account ID is required. Set CLAWOPS_ACCOUNT_ID or pass accountId option."
|
|
1860
1491
|
);
|
|
1861
1492
|
}
|
|
@@ -1879,7 +1510,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1879
1510
|
} catch {
|
|
1880
1511
|
}
|
|
1881
1512
|
} catch (err) {
|
|
1882
|
-
throw new
|
|
1513
|
+
throw new chunkLUA53NPZ_cjs.AgentConnectionError(
|
|
1883
1514
|
`Failed to connect to ClawOps: ${err instanceof Error ? err.message : String(err)}`
|
|
1884
1515
|
);
|
|
1885
1516
|
}
|
|
@@ -1943,7 +1574,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1943
1574
|
});
|
|
1944
1575
|
if (resp.status !== 201) {
|
|
1945
1576
|
const error = await resp.json();
|
|
1946
|
-
throw new
|
|
1577
|
+
throw new chunkLUA53NPZ_cjs.AgentError(`\uBC1C\uC2E0 \uC2E4\uD328 (${resp.status}): ${error["error"] ?? ""}`);
|
|
1947
1578
|
}
|
|
1948
1579
|
const data = await resp.json();
|
|
1949
1580
|
const callSession = new CallSession({
|
|
@@ -2202,9 +1833,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
2202
1833
|
let latestMediaTs = 0;
|
|
2203
1834
|
session._bindTransport(
|
|
2204
1835
|
(audio) => {
|
|
2205
|
-
const gained = applyUlawGain(audio, this._txGain);
|
|
1836
|
+
const gained = chunkU4UFTVLX_cjs.applyUlawGain(audio, this._txGain);
|
|
2206
1837
|
if (recorder) {
|
|
2207
|
-
recorder.writeOutbound(ulawToPcm16(gained), latestMediaTs);
|
|
1838
|
+
recorder.writeOutbound(chunkU4UFTVLX_cjs.ulawToPcm16(gained), latestMediaTs);
|
|
2208
1839
|
}
|
|
2209
1840
|
mediaWs.sendAudio(gained.toString("base64"));
|
|
2210
1841
|
session.recordFirstResponse();
|
|
@@ -2226,6 +1857,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
2226
1857
|
() => mediaWs.isConnected
|
|
2227
1858
|
);
|
|
2228
1859
|
session._transferFn = (params) => this._controlWs.requestTransfer(session.callId, params);
|
|
1860
|
+
session._sendMark = (name) => mediaWs.sendMark(name);
|
|
1861
|
+
session._waitForMark = (name, timeoutMs) => mediaWs.waitForMark(name, timeoutMs);
|
|
1862
|
+
session._flushTransport = () => mediaWs.flush();
|
|
2229
1863
|
const sessionHandler = this._session;
|
|
2230
1864
|
if ("setToolRegistry" in sessionHandler && typeof sessionHandler.setToolRegistry === "function") {
|
|
2231
1865
|
sessionHandler.setToolRegistry(sessionTools);
|
|
@@ -2245,9 +1879,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
2245
1879
|
this._callSessions.set(session.callId, sessionHandler);
|
|
2246
1880
|
mediaWs.onAudio((ulawAudio, timestamp) => {
|
|
2247
1881
|
latestMediaTs = timestamp;
|
|
2248
|
-
const gained = applyUlawGain(ulawAudio, this._rxGain);
|
|
1882
|
+
const gained = chunkU4UFTVLX_cjs.applyUlawGain(ulawAudio, this._rxGain);
|
|
2249
1883
|
if (recorder) {
|
|
2250
|
-
recorder.writeInbound(ulawToPcm16(gained), timestamp);
|
|
1884
|
+
recorder.writeInbound(chunkU4UFTVLX_cjs.ulawToPcm16(gained), timestamp);
|
|
2251
1885
|
}
|
|
2252
1886
|
if (sessionHandler) {
|
|
2253
1887
|
sessionHandler.feedAudio(gained, timestamp);
|
|
@@ -2341,232 +1975,6 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
2341
1975
|
}
|
|
2342
1976
|
};
|
|
2343
1977
|
|
|
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
1978
|
// src/agent/pipeline/pipeline-session.ts
|
|
2571
1979
|
var PipelineSession = class {
|
|
2572
1980
|
_stt;
|
|
@@ -2588,7 +1996,7 @@ var PipelineSession = class {
|
|
|
2588
1996
|
_speaking = false;
|
|
2589
1997
|
_builtinTools = null;
|
|
2590
1998
|
_holdAudioChunks = null;
|
|
2591
|
-
_log = NOOP_LOGGER;
|
|
1999
|
+
_log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
|
|
2592
2000
|
constructor(options) {
|
|
2593
2001
|
this._stt = options.stt;
|
|
2594
2002
|
this._llm = options.llm;
|
|
@@ -2650,7 +2058,7 @@ var PipelineSession = class {
|
|
|
2650
2058
|
*/
|
|
2651
2059
|
async prewarm(tools) {
|
|
2652
2060
|
if (tools) this._tools = tools;
|
|
2653
|
-
this._callSession = new BufferingCall();
|
|
2061
|
+
this._callSession = new chunkU4UFTVLX_cjs.BufferingCall();
|
|
2654
2062
|
this._running = true;
|
|
2655
2063
|
this._conversation = [];
|
|
2656
2064
|
this._log.info("PipelineSession prewarmed");
|
|
@@ -2673,7 +2081,7 @@ var PipelineSession = class {
|
|
|
2673
2081
|
async attach(callSession) {
|
|
2674
2082
|
const prev = this._callSession;
|
|
2675
2083
|
this._callSession = callSession;
|
|
2676
|
-
attachBuffered(prev, callSession);
|
|
2084
|
+
chunkU4UFTVLX_cjs.attachBuffered(prev, callSession);
|
|
2677
2085
|
}
|
|
2678
2086
|
async start(callSession, tools) {
|
|
2679
2087
|
this._tools = tools ?? null;
|
|
@@ -2720,8 +2128,8 @@ var PipelineSession = class {
|
|
|
2720
2128
|
while (this._running) {
|
|
2721
2129
|
if (this._audioBuffer.length > 0) {
|
|
2722
2130
|
const ulaw = this._audioBuffer.shift();
|
|
2723
|
-
const pcm8k = ulawToPcm16(ulaw);
|
|
2724
|
-
const pcm16k = resamplePcm16(pcm8k, 8e3, 16e3);
|
|
2131
|
+
const pcm8k = chunkU4UFTVLX_cjs.ulawToPcm16(ulaw);
|
|
2132
|
+
const pcm16k = chunkU4UFTVLX_cjs.resamplePcm16(pcm8k, 8e3, 16e3);
|
|
2725
2133
|
yield pcm16k;
|
|
2726
2134
|
} else {
|
|
2727
2135
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
@@ -2737,7 +2145,7 @@ var PipelineSession = class {
|
|
|
2737
2145
|
await this._respond();
|
|
2738
2146
|
}
|
|
2739
2147
|
_buildEffectiveTools() {
|
|
2740
|
-
const builtinSchemas = getBuiltinToolSchemas(this._builtinTools, "chat");
|
|
2148
|
+
const builtinSchemas = chunkU4UFTVLX_cjs.getBuiltinToolSchemas(this._builtinTools, "chat");
|
|
2741
2149
|
const dtmfSchemas = builtinSchemas.filter((s) => {
|
|
2742
2150
|
const name = s["function"]?.["name"];
|
|
2743
2151
|
return name === "collect_dtmf" || name === "send_dtmf";
|
|
@@ -2786,8 +2194,8 @@ var PipelineSession = class {
|
|
|
2786
2194
|
const { id, name, arguments: argsStr } = chunk.toolCall;
|
|
2787
2195
|
try {
|
|
2788
2196
|
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);
|
|
2197
|
+
if (chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES.has(name) && this._callSession && !(this._callSession instanceof chunkU4UFTVLX_cjs.BufferingCall)) {
|
|
2198
|
+
const result2 = await chunkU4UFTVLX_cjs.executeBuiltinTool(name, args, this._callSession);
|
|
2791
2199
|
if (result2 !== null) {
|
|
2792
2200
|
if (name === "hang_up") return;
|
|
2793
2201
|
this._conversation.push({ role: "tool", content: result2, tool_call_id: id, name });
|
|
@@ -2797,7 +2205,7 @@ var PipelineSession = class {
|
|
|
2797
2205
|
}
|
|
2798
2206
|
if (!this._tools) return;
|
|
2799
2207
|
this._callSession?.recordToolCall();
|
|
2800
|
-
const player = this._holdAudioChunks && this._callSession && !(this._callSession instanceof BufferingCall) ? new HoldAudioPlayer(this._callSession, this._holdAudioChunks) : null;
|
|
2208
|
+
const player = this._holdAudioChunks && this._callSession && !(this._callSession instanceof chunkU4UFTVLX_cjs.BufferingCall) ? new HoldAudioPlayer(this._callSession, this._holdAudioChunks) : null;
|
|
2801
2209
|
player?.start();
|
|
2802
2210
|
let result;
|
|
2803
2211
|
try {
|
|
@@ -2848,8 +2256,8 @@ var PipelineSession = class {
|
|
|
2848
2256
|
sampleRate: this._sampleRate
|
|
2849
2257
|
})) {
|
|
2850
2258
|
if (!this._running || !this._speaking) break;
|
|
2851
|
-
const pcm8k = resamplePcm16(audioChunk, this._sampleRate, 8e3);
|
|
2852
|
-
const ulaw = pcm16ToUlaw(pcm8k);
|
|
2259
|
+
const pcm8k = chunkU4UFTVLX_cjs.resamplePcm16(audioChunk, this._sampleRate, 8e3);
|
|
2260
|
+
const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcm8k);
|
|
2853
2261
|
for (let off = 0; off < ulaw.length; off += 160) {
|
|
2854
2262
|
let chunk = ulaw.subarray(off, off + 160);
|
|
2855
2263
|
if (chunk.length < 160) {
|
|
@@ -2876,7 +2284,7 @@ var OpenAIRealtime = class {
|
|
|
2876
2284
|
_language;
|
|
2877
2285
|
_turnDetection;
|
|
2878
2286
|
_greeting;
|
|
2879
|
-
_log = NOOP_LOGGER;
|
|
2287
|
+
_log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
|
|
2880
2288
|
_builtinTools = null;
|
|
2881
2289
|
setLogger(logger) {
|
|
2882
2290
|
this._log = logger;
|
|
@@ -2948,7 +2356,7 @@ var OpenAIRealtime = class {
|
|
|
2948
2356
|
/** Open WS + session.update + (optional) response.create without a CallSession. */
|
|
2949
2357
|
async prewarm(tools) {
|
|
2950
2358
|
if (tools) this._tools = tools;
|
|
2951
|
-
this._call = new BufferingCall();
|
|
2359
|
+
this._call = new chunkU4UFTVLX_cjs.BufferingCall();
|
|
2952
2360
|
this._closed = false;
|
|
2953
2361
|
this._playback = null;
|
|
2954
2362
|
this._latestMediaTs = 0;
|
|
@@ -2989,7 +2397,7 @@ var OpenAIRealtime = class {
|
|
|
2989
2397
|
async attach(callSession) {
|
|
2990
2398
|
const prev = this._call;
|
|
2991
2399
|
this._call = callSession;
|
|
2992
|
-
attachBuffered(prev, callSession);
|
|
2400
|
+
chunkU4UFTVLX_cjs.attachBuffered(prev, callSession);
|
|
2993
2401
|
}
|
|
2994
2402
|
async start(callSession, tools) {
|
|
2995
2403
|
if (tools) this._tools = tools;
|
|
@@ -3050,7 +2458,7 @@ var OpenAIRealtime = class {
|
|
|
3050
2458
|
_sendSessionUpdate() {
|
|
3051
2459
|
if (!this._ws || this._ws.readyState !== 1) return;
|
|
3052
2460
|
const toolSchemas = this._tools ? this._tools.toOpenAITools().map((t) => ({ type: "function", ...t.function })) : [];
|
|
3053
|
-
toolSchemas.push(...getBuiltinToolSchemas(this._builtinTools, "realtime"));
|
|
2461
|
+
toolSchemas.push(...chunkU4UFTVLX_cjs.getBuiltinToolSchemas(this._builtinTools, "realtime"));
|
|
3054
2462
|
this._send({
|
|
3055
2463
|
type: "session.update",
|
|
3056
2464
|
session: {
|
|
@@ -3195,9 +2603,9 @@ var OpenAIRealtime = class {
|
|
|
3195
2603
|
const controller = new AbortController();
|
|
3196
2604
|
this._pendingToolCalls.set(callId, controller);
|
|
3197
2605
|
try {
|
|
3198
|
-
if (BUILTIN_TOOL_NAMES.has(funcName) && this._call && !(this._call instanceof BufferingCall)) {
|
|
2606
|
+
if (chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES.has(funcName) && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall)) {
|
|
3199
2607
|
const args = JSON.parse(item["arguments"] ?? "{}");
|
|
3200
|
-
const result2 = await executeBuiltinTool(funcName, args, this._call);
|
|
2608
|
+
const result2 = await chunkU4UFTVLX_cjs.executeBuiltinTool(funcName, args, this._call);
|
|
3201
2609
|
if (result2 !== null) {
|
|
3202
2610
|
if (funcName === "hang_up") return;
|
|
3203
2611
|
if (controller.signal.aborted) return;
|
|
@@ -3229,7 +2637,7 @@ var OpenAIRealtime = class {
|
|
|
3229
2637
|
return;
|
|
3230
2638
|
}
|
|
3231
2639
|
let result;
|
|
3232
|
-
const player = this._holdAudioChunks && this._call && !(this._call instanceof BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
|
|
2640
|
+
const player = this._holdAudioChunks && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
|
|
3233
2641
|
player?.start();
|
|
3234
2642
|
try {
|
|
3235
2643
|
const args = JSON.parse(item["arguments"] ?? "{}");
|
|
@@ -3371,7 +2779,7 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3371
2779
|
_toolDrainTimer = null;
|
|
3372
2780
|
_lastAudioTime = 0;
|
|
3373
2781
|
_holdAudioChunks = null;
|
|
3374
|
-
_log = NOOP_LOGGER;
|
|
2782
|
+
_log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
|
|
3375
2783
|
constructor(options = {}) {
|
|
3376
2784
|
this._apiKey = options.apiKey ?? process.env["GOOGLE_API_KEY"] ?? "";
|
|
3377
2785
|
this._systemPrompt = options.systemPrompt ?? "";
|
|
@@ -3417,7 +2825,7 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3417
2825
|
/** Open Live session (no CallSession). Audio deltas accumulate into BufferingCall until attach(). */
|
|
3418
2826
|
async prewarm(tools) {
|
|
3419
2827
|
if (tools) this._tools = tools;
|
|
3420
|
-
this._call = new BufferingCall();
|
|
2828
|
+
this._call = new chunkU4UFTVLX_cjs.BufferingCall();
|
|
3421
2829
|
this._closed = false;
|
|
3422
2830
|
this._sentAudioChunks = 0;
|
|
3423
2831
|
this._audioRemainder = Buffer.alloc(0);
|
|
@@ -3474,7 +2882,7 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3474
2882
|
async attach(callSession) {
|
|
3475
2883
|
const prev = this._call;
|
|
3476
2884
|
this._call = callSession;
|
|
3477
|
-
attachBuffered(prev, callSession);
|
|
2885
|
+
chunkU4UFTVLX_cjs.attachBuffered(prev, callSession);
|
|
3478
2886
|
}
|
|
3479
2887
|
async start(callSession, tools) {
|
|
3480
2888
|
if (tools) this._tools = tools;
|
|
@@ -3483,8 +2891,8 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3483
2891
|
}
|
|
3484
2892
|
feedAudio(audio) {
|
|
3485
2893
|
if (this._session && !this._closed) {
|
|
3486
|
-
const pcm8k = ulawToPcm16(audio);
|
|
3487
|
-
const pcm16k = resamplePcm16(pcm8k, 8e3, 16e3);
|
|
2894
|
+
const pcm8k = chunkU4UFTVLX_cjs.ulawToPcm16(audio);
|
|
2895
|
+
const pcm16k = chunkU4UFTVLX_cjs.resamplePcm16(pcm8k, 8e3, 16e3);
|
|
3488
2896
|
this._session.sendRealtimeInput({
|
|
3489
2897
|
audio: {
|
|
3490
2898
|
data: Buffer.from(pcm16k).toString("base64"),
|
|
@@ -3528,7 +2936,7 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3528
2936
|
t.function.parameters ?? { type: "object", properties: {} }
|
|
3529
2937
|
)
|
|
3530
2938
|
})) : [];
|
|
3531
|
-
toolDefs.push(...getBuiltinToolSchemas(this._builtinTools, "gemini"));
|
|
2939
|
+
toolDefs.push(...chunkU4UFTVLX_cjs.getBuiltinToolSchemas(this._builtinTools, "gemini"));
|
|
3532
2940
|
return toolDefs;
|
|
3533
2941
|
}
|
|
3534
2942
|
_handleMessage(msg) {
|
|
@@ -3588,8 +2996,8 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3588
2996
|
_handleAudioData(b64Data) {
|
|
3589
2997
|
if (!this._call) return;
|
|
3590
2998
|
const pcm24k = Buffer.from(b64Data, "base64");
|
|
3591
|
-
const pcm8k = resamplePcm16(pcm24k, 24e3, 8e3);
|
|
3592
|
-
const ulaw = pcm16ToUlaw(pcm8k);
|
|
2999
|
+
const pcm8k = chunkU4UFTVLX_cjs.resamplePcm16(pcm24k, 24e3, 8e3);
|
|
3000
|
+
const ulaw = chunkU4UFTVLX_cjs.pcm16ToUlaw(pcm8k);
|
|
3593
3001
|
const combined = Buffer.concat([this._audioRemainder, ulaw]);
|
|
3594
3002
|
const chunkSize = 160;
|
|
3595
3003
|
const fullEnd = Math.floor(combined.length / chunkSize) * chunkSize;
|
|
@@ -3632,7 +3040,7 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3632
3040
|
const functionCalls = toolCall.functionCalls;
|
|
3633
3041
|
if (!functionCalls) return;
|
|
3634
3042
|
const responses = [];
|
|
3635
|
-
const player = this._holdAudioChunks && this._call && !(this._call instanceof BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
|
|
3043
|
+
const player = this._holdAudioChunks && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall) ? new HoldAudioPlayer(this._call, this._holdAudioChunks) : null;
|
|
3636
3044
|
player?.start();
|
|
3637
3045
|
try {
|
|
3638
3046
|
for (const fc of functionCalls) {
|
|
@@ -3640,8 +3048,8 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3640
3048
|
const fcId = fc.id ?? "";
|
|
3641
3049
|
const args = fc.args ?? {};
|
|
3642
3050
|
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(
|
|
3051
|
+
if (chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES.has(name) && this._call && !(this._call instanceof chunkU4UFTVLX_cjs.BufferingCall)) {
|
|
3052
|
+
const result = await chunkU4UFTVLX_cjs.executeBuiltinTool(
|
|
3645
3053
|
name,
|
|
3646
3054
|
args,
|
|
3647
3055
|
this._call
|
|
@@ -3698,7 +3106,7 @@ var GeminiRealtime = class _GeminiRealtime {
|
|
|
3698
3106
|
// src/agent/pipeline/stt/deepgram-stt.ts
|
|
3699
3107
|
var DeepgramSTT = class {
|
|
3700
3108
|
_options;
|
|
3701
|
-
_log = NOOP_LOGGER;
|
|
3109
|
+
_log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
|
|
3702
3110
|
get provider() {
|
|
3703
3111
|
return "deepgram";
|
|
3704
3112
|
}
|
|
@@ -3825,7 +3233,7 @@ var DeepgramSTT = class {
|
|
|
3825
3233
|
// src/agent/pipeline/tts/elevenlabs-tts.ts
|
|
3826
3234
|
var ElevenLabsTTS = class {
|
|
3827
3235
|
_options;
|
|
3828
|
-
_log = NOOP_LOGGER;
|
|
3236
|
+
_log = chunkU4UFTVLX_cjs.NOOP_LOGGER;
|
|
3829
3237
|
get provider() {
|
|
3830
3238
|
return "elevenlabs";
|
|
3831
3239
|
}
|
|
@@ -4569,14 +3977,55 @@ function mcpServerHTTP(options) {
|
|
|
4569
3977
|
};
|
|
4570
3978
|
}
|
|
4571
3979
|
|
|
3980
|
+
Object.defineProperty(exports, "BUILTIN_TOOL_NAMES", {
|
|
3981
|
+
enumerable: true,
|
|
3982
|
+
get: function () { return chunkU4UFTVLX_cjs.BUILTIN_TOOL_NAMES; }
|
|
3983
|
+
});
|
|
3984
|
+
Object.defineProperty(exports, "BuiltinTool", {
|
|
3985
|
+
enumerable: true,
|
|
3986
|
+
get: function () { return chunkU4UFTVLX_cjs.BuiltinTool; }
|
|
3987
|
+
});
|
|
3988
|
+
Object.defineProperty(exports, "DECODE_TABLE", {
|
|
3989
|
+
enumerable: true,
|
|
3990
|
+
get: function () { return chunkU4UFTVLX_cjs.DECODE_TABLE; }
|
|
3991
|
+
});
|
|
3992
|
+
Object.defineProperty(exports, "createAgentLogger", {
|
|
3993
|
+
enumerable: true,
|
|
3994
|
+
get: function () { return chunkU4UFTVLX_cjs.createAgentLogger; }
|
|
3995
|
+
});
|
|
3996
|
+
Object.defineProperty(exports, "createPipelineLogger", {
|
|
3997
|
+
enumerable: true,
|
|
3998
|
+
get: function () { return chunkU4UFTVLX_cjs.createPipelineLogger; }
|
|
3999
|
+
});
|
|
4000
|
+
Object.defineProperty(exports, "executeBuiltinTool", {
|
|
4001
|
+
enumerable: true,
|
|
4002
|
+
get: function () { return chunkU4UFTVLX_cjs.executeBuiltinTool; }
|
|
4003
|
+
});
|
|
4004
|
+
Object.defineProperty(exports, "getBuiltinToolSchemas", {
|
|
4005
|
+
enumerable: true,
|
|
4006
|
+
get: function () { return chunkU4UFTVLX_cjs.getBuiltinToolSchemas; }
|
|
4007
|
+
});
|
|
4008
|
+
Object.defineProperty(exports, "isBuiltinTool", {
|
|
4009
|
+
enumerable: true,
|
|
4010
|
+
get: function () { return chunkU4UFTVLX_cjs.isBuiltinTool; }
|
|
4011
|
+
});
|
|
4012
|
+
Object.defineProperty(exports, "pcm16ToUlaw", {
|
|
4013
|
+
enumerable: true,
|
|
4014
|
+
get: function () { return chunkU4UFTVLX_cjs.pcm16ToUlaw; }
|
|
4015
|
+
});
|
|
4016
|
+
Object.defineProperty(exports, "resamplePcm16", {
|
|
4017
|
+
enumerable: true,
|
|
4018
|
+
get: function () { return chunkU4UFTVLX_cjs.resamplePcm16; }
|
|
4019
|
+
});
|
|
4020
|
+
Object.defineProperty(exports, "ulawToPcm16", {
|
|
4021
|
+
enumerable: true,
|
|
4022
|
+
get: function () { return chunkU4UFTVLX_cjs.ulawToPcm16; }
|
|
4023
|
+
});
|
|
4572
4024
|
exports.AnthropicLLM = AnthropicLLM;
|
|
4573
4025
|
exports.AudioRecorder = AudioRecorder;
|
|
4574
|
-
exports.BUILTIN_TOOL_NAMES = BUILTIN_TOOL_NAMES;
|
|
4575
|
-
exports.BuiltinTool = BuiltinTool;
|
|
4576
4026
|
exports.CallSession = CallSession;
|
|
4577
4027
|
exports.ClawOpsAgent = ClawOpsAgent;
|
|
4578
4028
|
exports.ControlWebSocket = ControlWebSocket;
|
|
4579
|
-
exports.DECODE_TABLE = DECODE_TABLE;
|
|
4580
4029
|
exports.DeepSeekLLM = DeepSeekLLM;
|
|
4581
4030
|
exports.DeepgramSTT = DeepgramSTT;
|
|
4582
4031
|
exports.ElevenLabsTTS = ElevenLabsTTS;
|
|
@@ -4597,20 +4046,12 @@ exports.TogetherLLM = TogetherLLM;
|
|
|
4597
4046
|
exports.ToolRegistry = ToolRegistry;
|
|
4598
4047
|
exports.XaiLLM = XaiLLM;
|
|
4599
4048
|
exports.buildControlWsUrl = buildControlWsUrl;
|
|
4600
|
-
exports.createAgentLogger = createAgentLogger;
|
|
4601
|
-
exports.createPipelineLogger = createPipelineLogger;
|
|
4602
|
-
exports.executeBuiltinTool = executeBuiltinTool;
|
|
4603
4049
|
exports.functionTool = functionTool;
|
|
4604
|
-
exports.getBuiltinToolSchemas = getBuiltinToolSchemas;
|
|
4605
4050
|
exports.getTracingConfig = getTracingConfig;
|
|
4606
|
-
exports.isBuiltinTool = isBuiltinTool;
|
|
4607
4051
|
exports.mcpServerHTTP = mcpServerHTTP;
|
|
4608
4052
|
exports.mcpServerStdio = mcpServerStdio;
|
|
4609
|
-
exports.pcm16ToUlaw = pcm16ToUlaw;
|
|
4610
|
-
exports.resamplePcm16 = resamplePcm16;
|
|
4611
4053
|
exports.resetTracingConfig = resetTracingConfig;
|
|
4612
4054
|
exports.setTracingConfig = setTracingConfig;
|
|
4613
|
-
exports.ulawToPcm16 = ulawToPcm16;
|
|
4614
4055
|
exports.zodToToolParams = zodToToolParams;
|
|
4615
4056
|
//# sourceMappingURL=index.cjs.map
|
|
4616
4057
|
//# sourceMappingURL=index.cjs.map
|