@teamlearners/clawops 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.cjs +125 -676
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +15 -326
- package/dist/agent/index.d.ts +15 -326
- package/dist/agent/index.js +29 -611
- 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-5PLVSC2U.js → chunk-7P2HGIPS.js} +3 -3
- package/dist/{chunk-5PLVSC2U.js.map → chunk-7P2HGIPS.js.map} +1 -1
- package/dist/{chunk-CJ2LJZDQ.cjs → chunk-LUA53NPZ.cjs} +3 -3
- package/dist/{chunk-CJ2LJZDQ.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.js
CHANGED
|
@@ -1,359 +1,10 @@
|
|
|
1
|
-
import { DEFAULT_BASE_URL, AgentError, AgentConnectionError, VERSION } from '../chunk-
|
|
2
|
-
import
|
|
1
|
+
import { DEFAULT_BASE_URL, AgentError, AgentConnectionError, VERSION } from '../chunk-7P2HGIPS.js';
|
|
2
|
+
import { NOOP_LOGGER, resolveBuiltinTools, createAgentLogger, createPipelineLogger, BufferingCall, attachBuffered, ulawToPcm16, resamplePcm16, getBuiltinToolSchemas, BUILTIN_TOOL_NAMES, executeBuiltinTool, pcm16ToUlaw, applyUlawGain } from '../chunk-2BAYUQ7O.js';
|
|
3
|
+
export { BUILTIN_TOOL_NAMES, BuiltinTool, DECODE_TABLE, createAgentLogger, createPipelineLogger, executeBuiltinTool, getBuiltinToolSchemas, isBuiltinTool, pcm16ToUlaw, resamplePcm16, ulawToPcm16 } from '../chunk-2BAYUQ7O.js';
|
|
3
4
|
import * as fs from 'fs';
|
|
4
5
|
import * as path from 'path';
|
|
5
6
|
import os from 'os';
|
|
6
7
|
|
|
7
|
-
// src/agent/audio.ts
|
|
8
|
-
var _BIAS = 132;
|
|
9
|
-
var _CLIP = 32635;
|
|
10
|
-
var DECODE_TABLE = [
|
|
11
|
-
-32124,
|
|
12
|
-
-31100,
|
|
13
|
-
-30076,
|
|
14
|
-
-29052,
|
|
15
|
-
-28028,
|
|
16
|
-
-27004,
|
|
17
|
-
-25980,
|
|
18
|
-
-24956,
|
|
19
|
-
-23932,
|
|
20
|
-
-22908,
|
|
21
|
-
-21884,
|
|
22
|
-
-20860,
|
|
23
|
-
-19836,
|
|
24
|
-
-18812,
|
|
25
|
-
-17788,
|
|
26
|
-
-16764,
|
|
27
|
-
-15996,
|
|
28
|
-
-15484,
|
|
29
|
-
-14972,
|
|
30
|
-
-14460,
|
|
31
|
-
-13948,
|
|
32
|
-
-13436,
|
|
33
|
-
-12924,
|
|
34
|
-
-12412,
|
|
35
|
-
-11900,
|
|
36
|
-
-11388,
|
|
37
|
-
-10876,
|
|
38
|
-
-10364,
|
|
39
|
-
-9852,
|
|
40
|
-
-9340,
|
|
41
|
-
-8828,
|
|
42
|
-
-8316,
|
|
43
|
-
-7932,
|
|
44
|
-
-7676,
|
|
45
|
-
-7420,
|
|
46
|
-
-7164,
|
|
47
|
-
-6908,
|
|
48
|
-
-6652,
|
|
49
|
-
-6396,
|
|
50
|
-
-6140,
|
|
51
|
-
-5884,
|
|
52
|
-
-5628,
|
|
53
|
-
-5372,
|
|
54
|
-
-5116,
|
|
55
|
-
-4860,
|
|
56
|
-
-4604,
|
|
57
|
-
-4348,
|
|
58
|
-
-4092,
|
|
59
|
-
-3900,
|
|
60
|
-
-3772,
|
|
61
|
-
-3644,
|
|
62
|
-
-3516,
|
|
63
|
-
-3388,
|
|
64
|
-
-3260,
|
|
65
|
-
-3132,
|
|
66
|
-
-3004,
|
|
67
|
-
-2876,
|
|
68
|
-
-2748,
|
|
69
|
-
-2620,
|
|
70
|
-
-2492,
|
|
71
|
-
-2364,
|
|
72
|
-
-2236,
|
|
73
|
-
-2108,
|
|
74
|
-
-1980,
|
|
75
|
-
-1884,
|
|
76
|
-
-1820,
|
|
77
|
-
-1756,
|
|
78
|
-
-1692,
|
|
79
|
-
-1628,
|
|
80
|
-
-1564,
|
|
81
|
-
-1500,
|
|
82
|
-
-1436,
|
|
83
|
-
-1372,
|
|
84
|
-
-1308,
|
|
85
|
-
-1244,
|
|
86
|
-
-1180,
|
|
87
|
-
-1116,
|
|
88
|
-
-1052,
|
|
89
|
-
-988,
|
|
90
|
-
-924,
|
|
91
|
-
-876,
|
|
92
|
-
-844,
|
|
93
|
-
-812,
|
|
94
|
-
-780,
|
|
95
|
-
-748,
|
|
96
|
-
-716,
|
|
97
|
-
-684,
|
|
98
|
-
-652,
|
|
99
|
-
-620,
|
|
100
|
-
-588,
|
|
101
|
-
-556,
|
|
102
|
-
-524,
|
|
103
|
-
-492,
|
|
104
|
-
-460,
|
|
105
|
-
-428,
|
|
106
|
-
-396,
|
|
107
|
-
-372,
|
|
108
|
-
-356,
|
|
109
|
-
-340,
|
|
110
|
-
-324,
|
|
111
|
-
-308,
|
|
112
|
-
-292,
|
|
113
|
-
-276,
|
|
114
|
-
-260,
|
|
115
|
-
-244,
|
|
116
|
-
-228,
|
|
117
|
-
-212,
|
|
118
|
-
-196,
|
|
119
|
-
-180,
|
|
120
|
-
-164,
|
|
121
|
-
-148,
|
|
122
|
-
-132,
|
|
123
|
-
-120,
|
|
124
|
-
-112,
|
|
125
|
-
-104,
|
|
126
|
-
-96,
|
|
127
|
-
-88,
|
|
128
|
-
-80,
|
|
129
|
-
-72,
|
|
130
|
-
-64,
|
|
131
|
-
-56,
|
|
132
|
-
-48,
|
|
133
|
-
-40,
|
|
134
|
-
-32,
|
|
135
|
-
-24,
|
|
136
|
-
-16,
|
|
137
|
-
-8,
|
|
138
|
-
0,
|
|
139
|
-
32124,
|
|
140
|
-
31100,
|
|
141
|
-
30076,
|
|
142
|
-
29052,
|
|
143
|
-
28028,
|
|
144
|
-
27004,
|
|
145
|
-
25980,
|
|
146
|
-
24956,
|
|
147
|
-
23932,
|
|
148
|
-
22908,
|
|
149
|
-
21884,
|
|
150
|
-
20860,
|
|
151
|
-
19836,
|
|
152
|
-
18812,
|
|
153
|
-
17788,
|
|
154
|
-
16764,
|
|
155
|
-
15996,
|
|
156
|
-
15484,
|
|
157
|
-
14972,
|
|
158
|
-
14460,
|
|
159
|
-
13948,
|
|
160
|
-
13436,
|
|
161
|
-
12924,
|
|
162
|
-
12412,
|
|
163
|
-
11900,
|
|
164
|
-
11388,
|
|
165
|
-
10876,
|
|
166
|
-
10364,
|
|
167
|
-
9852,
|
|
168
|
-
9340,
|
|
169
|
-
8828,
|
|
170
|
-
8316,
|
|
171
|
-
7932,
|
|
172
|
-
7676,
|
|
173
|
-
7420,
|
|
174
|
-
7164,
|
|
175
|
-
6908,
|
|
176
|
-
6652,
|
|
177
|
-
6396,
|
|
178
|
-
6140,
|
|
179
|
-
5884,
|
|
180
|
-
5628,
|
|
181
|
-
5372,
|
|
182
|
-
5116,
|
|
183
|
-
4860,
|
|
184
|
-
4604,
|
|
185
|
-
4348,
|
|
186
|
-
4092,
|
|
187
|
-
3900,
|
|
188
|
-
3772,
|
|
189
|
-
3644,
|
|
190
|
-
3516,
|
|
191
|
-
3388,
|
|
192
|
-
3260,
|
|
193
|
-
3132,
|
|
194
|
-
3004,
|
|
195
|
-
2876,
|
|
196
|
-
2748,
|
|
197
|
-
2620,
|
|
198
|
-
2492,
|
|
199
|
-
2364,
|
|
200
|
-
2236,
|
|
201
|
-
2108,
|
|
202
|
-
1980,
|
|
203
|
-
1884,
|
|
204
|
-
1820,
|
|
205
|
-
1756,
|
|
206
|
-
1692,
|
|
207
|
-
1628,
|
|
208
|
-
1564,
|
|
209
|
-
1500,
|
|
210
|
-
1436,
|
|
211
|
-
1372,
|
|
212
|
-
1308,
|
|
213
|
-
1244,
|
|
214
|
-
1180,
|
|
215
|
-
1116,
|
|
216
|
-
1052,
|
|
217
|
-
988,
|
|
218
|
-
924,
|
|
219
|
-
876,
|
|
220
|
-
844,
|
|
221
|
-
812,
|
|
222
|
-
780,
|
|
223
|
-
748,
|
|
224
|
-
716,
|
|
225
|
-
684,
|
|
226
|
-
652,
|
|
227
|
-
620,
|
|
228
|
-
588,
|
|
229
|
-
556,
|
|
230
|
-
524,
|
|
231
|
-
492,
|
|
232
|
-
460,
|
|
233
|
-
428,
|
|
234
|
-
396,
|
|
235
|
-
372,
|
|
236
|
-
356,
|
|
237
|
-
340,
|
|
238
|
-
324,
|
|
239
|
-
308,
|
|
240
|
-
292,
|
|
241
|
-
276,
|
|
242
|
-
260,
|
|
243
|
-
244,
|
|
244
|
-
228,
|
|
245
|
-
212,
|
|
246
|
-
196,
|
|
247
|
-
180,
|
|
248
|
-
164,
|
|
249
|
-
148,
|
|
250
|
-
132,
|
|
251
|
-
120,
|
|
252
|
-
112,
|
|
253
|
-
104,
|
|
254
|
-
96,
|
|
255
|
-
88,
|
|
256
|
-
80,
|
|
257
|
-
72,
|
|
258
|
-
64,
|
|
259
|
-
56,
|
|
260
|
-
48,
|
|
261
|
-
40,
|
|
262
|
-
32,
|
|
263
|
-
24,
|
|
264
|
-
16,
|
|
265
|
-
8,
|
|
266
|
-
0
|
|
267
|
-
];
|
|
268
|
-
function encodeUlawSample(sample) {
|
|
269
|
-
let sign = 0;
|
|
270
|
-
if (sample < 0) {
|
|
271
|
-
sign = 128;
|
|
272
|
-
sample = -sample;
|
|
273
|
-
}
|
|
274
|
-
if (sample > _CLIP) {
|
|
275
|
-
sample = _CLIP;
|
|
276
|
-
}
|
|
277
|
-
sample += _BIAS;
|
|
278
|
-
let exponent = 7;
|
|
279
|
-
const expValues = [16384, 8192, 4096, 2048, 1024, 512, 256];
|
|
280
|
-
for (const expVal of expValues) {
|
|
281
|
-
if (sample >= expVal) {
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
exponent -= 1;
|
|
285
|
-
}
|
|
286
|
-
const mantissa = sample >> exponent + 3 & 15;
|
|
287
|
-
return ~(sign | exponent << 4 | mantissa) & 255;
|
|
288
|
-
}
|
|
289
|
-
function pcm16ToUlaw(pcm) {
|
|
290
|
-
if (!pcm.length) return Buffer.alloc(0);
|
|
291
|
-
const nSamples = pcm.length >> 1;
|
|
292
|
-
const out = Buffer.alloc(nSamples);
|
|
293
|
-
for (let i = 0; i < nSamples; i++) {
|
|
294
|
-
const sample = pcm.readInt16LE(i * 2);
|
|
295
|
-
out[i] = encodeUlawSample(sample);
|
|
296
|
-
}
|
|
297
|
-
return out;
|
|
298
|
-
}
|
|
299
|
-
function ulawToPcm16(ulaw) {
|
|
300
|
-
if (!ulaw.length) return Buffer.alloc(0);
|
|
301
|
-
const out = Buffer.alloc(ulaw.length * 2);
|
|
302
|
-
for (let i = 0; i < ulaw.length; i++) {
|
|
303
|
-
out.writeInt16LE(DECODE_TABLE[ulaw[i]], i * 2);
|
|
304
|
-
}
|
|
305
|
-
return out;
|
|
306
|
-
}
|
|
307
|
-
function applyPcm16Gain(pcm, gain) {
|
|
308
|
-
if (!pcm.length) return Buffer.alloc(0);
|
|
309
|
-
if (gain === 1) return pcm;
|
|
310
|
-
if (!Number.isFinite(gain) || gain < 0) {
|
|
311
|
-
throw new Error("gain must be a finite number >= 0");
|
|
312
|
-
}
|
|
313
|
-
const nSamples = pcm.length >> 1;
|
|
314
|
-
const out = Buffer.alloc(nSamples * 2);
|
|
315
|
-
for (let i = 0; i < nSamples; i++) {
|
|
316
|
-
let value = Math.round(pcm.readInt16LE(i * 2) * gain);
|
|
317
|
-
if (value > 32767) value = 32767;
|
|
318
|
-
else if (value < -32768) value = -32768;
|
|
319
|
-
out.writeInt16LE(value, i * 2);
|
|
320
|
-
}
|
|
321
|
-
return out;
|
|
322
|
-
}
|
|
323
|
-
function applyUlawGain(ulaw, gain) {
|
|
324
|
-
if (!ulaw.length) return Buffer.alloc(0);
|
|
325
|
-
if (gain === 1) return ulaw;
|
|
326
|
-
return pcm16ToUlaw(applyPcm16Gain(ulawToPcm16(ulaw), gain));
|
|
327
|
-
}
|
|
328
|
-
function resamplePcm16(pcm, fromRate, toRate) {
|
|
329
|
-
if (fromRate === toRate || !pcm.length) return pcm;
|
|
330
|
-
const nSamples = pcm.length >> 1;
|
|
331
|
-
const ratio = fromRate / toRate;
|
|
332
|
-
const outLen = Math.floor(nSamples / ratio);
|
|
333
|
-
const out = Buffer.alloc(outLen * 2);
|
|
334
|
-
for (let i = 0; i < outLen; i++) {
|
|
335
|
-
const srcPos = i * ratio;
|
|
336
|
-
const idx = Math.floor(srcPos);
|
|
337
|
-
const frac = srcPos - idx;
|
|
338
|
-
let val;
|
|
339
|
-
if (idx + 1 < nSamples) {
|
|
340
|
-
val = pcm.readInt16LE(idx * 2) * (1 - frac) + pcm.readInt16LE((idx + 1) * 2) * frac;
|
|
341
|
-
} else {
|
|
342
|
-
val = pcm.readInt16LE(idx * 2);
|
|
343
|
-
}
|
|
344
|
-
out.writeInt16LE(Math.round(val), i * 2);
|
|
345
|
-
}
|
|
346
|
-
return out;
|
|
347
|
-
}
|
|
348
|
-
var DEFAULT_LOGGER = pino({ name: "clawops.agent" });
|
|
349
|
-
var NOOP_LOGGER = pino({ level: "silent" });
|
|
350
|
-
function createAgentLogger(userLogger) {
|
|
351
|
-
return userLogger ?? DEFAULT_LOGGER;
|
|
352
|
-
}
|
|
353
|
-
function createPipelineLogger(parent) {
|
|
354
|
-
return parent.child({ module: "pipeline" });
|
|
355
|
-
}
|
|
356
|
-
|
|
357
8
|
// src/agent/control-ws.ts
|
|
358
9
|
var INITIAL_RECONNECT_DELAY = 1e3;
|
|
359
10
|
var MAX_RECONNECT_DELAY = 3e4;
|
|
@@ -1097,6 +748,17 @@ var CallSession = class {
|
|
|
1097
748
|
_transferFn = null;
|
|
1098
749
|
/** @internal */
|
|
1099
750
|
_isTransportConnected = null;
|
|
751
|
+
/**
|
|
752
|
+
* @internal Media WS playout 마커 훅. LiveKit(`ClawOpsAudioOutput`)이 재생 완료
|
|
753
|
+
* 판정(mark echo)과 barge-in 절단 위치 계산에 쓴다. 다른 세션 타입은 읽지 않는다.
|
|
754
|
+
* prewarm 중(BufferingCall)에는 바인딩되지 않아 null 이다.
|
|
755
|
+
*/
|
|
756
|
+
/** @internal */
|
|
757
|
+
_sendMark = null;
|
|
758
|
+
/** @internal */
|
|
759
|
+
_waitForMark = null;
|
|
760
|
+
/** @internal */
|
|
761
|
+
_flushTransport = null;
|
|
1100
762
|
_dtmfCollectorActive = false;
|
|
1101
763
|
_dtmfResolvers = [];
|
|
1102
764
|
_dtmfBuffer = [];
|
|
@@ -1252,7 +914,9 @@ var CallSession = class {
|
|
|
1252
914
|
*
|
|
1253
915
|
* destinationType='pstn' (default): `to` is a phone number dialed via carrier.
|
|
1254
916
|
* destinationType='sip': `to` is a SIP URI (e.g. `sip:user@host`) connected
|
|
1255
|
-
* directly to a SIP endpoint without going through the PSTN carrier.
|
|
917
|
+
* directly to a SIP endpoint without going through the PSTN carrier. Requires the
|
|
918
|
+
* account to have an active `sip_trunk` add-on; otherwise the transfer fails and
|
|
919
|
+
* the call continues with the AI (result `{ status: 'failed', ... }`).
|
|
1256
920
|
*/
|
|
1257
921
|
async transfer(to, options) {
|
|
1258
922
|
if (!this._transferFn) {
|
|
@@ -1308,35 +972,6 @@ var CallSession = class {
|
|
|
1308
972
|
}
|
|
1309
973
|
}
|
|
1310
974
|
};
|
|
1311
|
-
|
|
1312
|
-
// src/agent/builtin-tool.ts
|
|
1313
|
-
var BuiltinTool = /* @__PURE__ */ ((BuiltinTool2) => {
|
|
1314
|
-
BuiltinTool2["HANG_UP"] = "hang_up";
|
|
1315
|
-
BuiltinTool2["COLLECT_DTMF"] = "collect_dtmf";
|
|
1316
|
-
BuiltinTool2["SEND_DTMF"] = "send_dtmf";
|
|
1317
|
-
BuiltinTool2["TRANSFER_CALL"] = "transfer_call";
|
|
1318
|
-
BuiltinTool2["ALL"] = "all";
|
|
1319
|
-
BuiltinTool2["NONE"] = "none";
|
|
1320
|
-
return BuiltinTool2;
|
|
1321
|
-
})(BuiltinTool || {});
|
|
1322
|
-
var INDIVIDUAL_TOOLS = /* @__PURE__ */ new Set([
|
|
1323
|
-
"hang_up" /* HANG_UP */,
|
|
1324
|
-
"collect_dtmf" /* COLLECT_DTMF */,
|
|
1325
|
-
"send_dtmf" /* SEND_DTMF */,
|
|
1326
|
-
"transfer_call" /* TRANSFER_CALL */
|
|
1327
|
-
]);
|
|
1328
|
-
function resolveBuiltinTools(value) {
|
|
1329
|
-
if (typeof value === "string") {
|
|
1330
|
-
if (value === "all" /* ALL */) {
|
|
1331
|
-
return new Set(INDIVIDUAL_TOOLS);
|
|
1332
|
-
}
|
|
1333
|
-
if (value === "none" /* NONE */) {
|
|
1334
|
-
return /* @__PURE__ */ new Set();
|
|
1335
|
-
}
|
|
1336
|
-
return /* @__PURE__ */ new Set([value]);
|
|
1337
|
-
}
|
|
1338
|
-
return new Set(value.filter((t) => INDIVIDUAL_TOOLS.has(t)));
|
|
1339
|
-
}
|
|
1340
975
|
var CHUNK_SIZE = 160;
|
|
1341
976
|
var SAMPLE_RATE2 = 8e3;
|
|
1342
977
|
var BELL_PARTIALS = [
|
|
@@ -1744,6 +1379,8 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1744
1379
|
/** prewarm 세션이 실제 CallSession 에 attach 완료된 callId. attached 이후의 stop() 은 정상 종료 경로가 책임진다. */
|
|
1745
1380
|
_prewarmAttached = /* @__PURE__ */ new Set();
|
|
1746
1381
|
_prewarmEnabled;
|
|
1382
|
+
/** 모든 발신에 적용되는 AMD default. call() 인자로 호출별 override 가능. */
|
|
1383
|
+
_machineDetection;
|
|
1747
1384
|
constructor(options) {
|
|
1748
1385
|
this._apiKey = options.apiKey ?? process.env["CLAWOPS_API_KEY"] ?? "";
|
|
1749
1386
|
this._accountId = options.accountId ?? process.env["CLAWOPS_ACCOUNT_ID"] ?? "";
|
|
@@ -1758,6 +1395,7 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1758
1395
|
this._rxGain = _ClawOpsAgent._validateGain("rxGain", options.rxGain ?? 1);
|
|
1759
1396
|
this._txGain = _ClawOpsAgent._validateGain("txGain", options.txGain ?? 1);
|
|
1760
1397
|
this._prewarmEnabled = options.prewarmEnabled ?? true;
|
|
1398
|
+
this._machineDetection = options.machineDetection;
|
|
1761
1399
|
if (options.tracing) {
|
|
1762
1400
|
setTracingConfig(options.tracing);
|
|
1763
1401
|
}
|
|
@@ -1886,6 +1524,8 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1886
1524
|
*
|
|
1887
1525
|
* @param options.machineDetection 자동응답기/음성사서함 감지(AMD).
|
|
1888
1526
|
* `'Enable'`=감지 후 `AnsweredBy` 통보(통화 계속), `'Hangup'`=음성사서함 감지 시 자동 종료.
|
|
1527
|
+
* 미지정 시 인스턴스 default(생성자의 `machineDetection`)를 따른다.
|
|
1528
|
+
* 우선순위: 호출 인자 > 인스턴스 default > 비활성.
|
|
1889
1529
|
*/
|
|
1890
1530
|
async call(to, options) {
|
|
1891
1531
|
await this.connect();
|
|
@@ -1895,8 +1535,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
1895
1535
|
From: this._fromNumber,
|
|
1896
1536
|
Timeout: options?.timeout ?? 60
|
|
1897
1537
|
};
|
|
1898
|
-
|
|
1899
|
-
|
|
1538
|
+
const effectiveMd = options?.machineDetection ?? this._machineDetection;
|
|
1539
|
+
if (effectiveMd) {
|
|
1540
|
+
body["MachineDetection"] = effectiveMd;
|
|
1900
1541
|
}
|
|
1901
1542
|
const resp = await fetch(url, {
|
|
1902
1543
|
method: "POST",
|
|
@@ -2191,6 +1832,9 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
2191
1832
|
() => mediaWs.isConnected
|
|
2192
1833
|
);
|
|
2193
1834
|
session._transferFn = (params) => this._controlWs.requestTransfer(session.callId, params);
|
|
1835
|
+
session._sendMark = (name) => mediaWs.sendMark(name);
|
|
1836
|
+
session._waitForMark = (name, timeoutMs) => mediaWs.waitForMark(name, timeoutMs);
|
|
1837
|
+
session._flushTransport = () => mediaWs.flush();
|
|
2194
1838
|
const sessionHandler = this._session;
|
|
2195
1839
|
if ("setToolRegistry" in sessionHandler && typeof sessionHandler.setToolRegistry === "function") {
|
|
2196
1840
|
sessionHandler.setToolRegistry(sessionTools);
|
|
@@ -2306,232 +1950,6 @@ var ClawOpsAgent = class _ClawOpsAgent {
|
|
|
2306
1950
|
}
|
|
2307
1951
|
};
|
|
2308
1952
|
|
|
2309
|
-
// src/agent/pipeline/builtin-tool-schemas.ts
|
|
2310
|
-
var HANG_UP = {
|
|
2311
|
-
name: "hang_up",
|
|
2312
|
-
description: "End the phone call. Use when the conversation is finished or the caller says goodbye.",
|
|
2313
|
-
parameters: { type: "object", properties: {} }
|
|
2314
|
-
};
|
|
2315
|
-
var COLLECT_DTMF = {
|
|
2316
|
-
name: "collect_dtmf",
|
|
2317
|
-
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.",
|
|
2318
|
-
parameters: {
|
|
2319
|
-
type: "object",
|
|
2320
|
-
properties: {
|
|
2321
|
-
max_digits: { type: "integer", description: "\uC218\uC9D1\uD560 \uCD5C\uB300 \uC790\uB9BF\uC218" },
|
|
2322
|
-
finish_on_key: { type: "string", description: "\uC785\uB825 \uC885\uB8CC \uD0A4 (\uAE30\uBCF8: #)" },
|
|
2323
|
-
timeout: { type: "integer", description: "\uC785\uB825 \uB300\uAE30 \uC2DC\uAC04(\uCD08, \uAE30\uBCF8: 5)" }
|
|
2324
|
-
},
|
|
2325
|
-
required: ["max_digits"]
|
|
2326
|
-
}
|
|
2327
|
-
};
|
|
2328
|
-
var SEND_DTMF = {
|
|
2329
|
-
name: "send_dtmf",
|
|
2330
|
-
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.",
|
|
2331
|
-
parameters: {
|
|
2332
|
-
type: "object",
|
|
2333
|
-
properties: {
|
|
2334
|
-
digits: {
|
|
2335
|
-
type: "string",
|
|
2336
|
-
description: "\uC804\uC1A1\uD560 \uBC88\uD638 (0-9, *, #). 'w'\uB294 500ms \uB300\uAE30, 'W'\uB294 1000ms \uB300\uAE30. \uC608: '1', '1234#', '1w2'"
|
|
2337
|
-
}
|
|
2338
|
-
},
|
|
2339
|
-
required: ["digits"]
|
|
2340
|
-
}
|
|
2341
|
-
};
|
|
2342
|
-
var TRANSFER_CALL = {
|
|
2343
|
-
name: "transfer_call",
|
|
2344
|
-
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).",
|
|
2345
|
-
parameters: {
|
|
2346
|
-
type: "object",
|
|
2347
|
-
properties: {
|
|
2348
|
-
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'." },
|
|
2349
|
-
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)." },
|
|
2350
|
-
mode: { type: "string", enum: ["blind", "warm"], description: "blind: direct transfer (default), warm: play whisper to target first" },
|
|
2351
|
-
after_transfer: { type: "string", enum: ["terminate", "return"], description: "terminate: end AI session (default), return: AI resumes after transfer ends" },
|
|
2352
|
-
whisper: { type: "string", description: "Message to speak to transfer target before connecting customer (warm mode only)" },
|
|
2353
|
-
caller_id: { type: "string", description: "Override caller ID for the transfer leg" },
|
|
2354
|
-
timeout: { type: "integer", description: "Seconds to wait for transfer target to answer (default 30)" }
|
|
2355
|
-
},
|
|
2356
|
-
required: ["to"]
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
var TOOL_MAP = /* @__PURE__ */ new Map([
|
|
2360
|
-
["hang_up" /* HANG_UP */, HANG_UP],
|
|
2361
|
-
["collect_dtmf" /* COLLECT_DTMF */, COLLECT_DTMF],
|
|
2362
|
-
["send_dtmf" /* SEND_DTMF */, SEND_DTMF],
|
|
2363
|
-
["transfer_call" /* TRANSFER_CALL */, TRANSFER_CALL]
|
|
2364
|
-
]);
|
|
2365
|
-
var BUILTIN_TOOL_NAMES = new Set(
|
|
2366
|
-
Array.from(TOOL_MAP.values()).map((s) => s.name)
|
|
2367
|
-
);
|
|
2368
|
-
function toChatCompletions(schema) {
|
|
2369
|
-
return {
|
|
2370
|
-
type: "function",
|
|
2371
|
-
function: {
|
|
2372
|
-
name: schema.name,
|
|
2373
|
-
description: schema.description,
|
|
2374
|
-
parameters: schema.parameters
|
|
2375
|
-
}
|
|
2376
|
-
};
|
|
2377
|
-
}
|
|
2378
|
-
function toRealtime(schema) {
|
|
2379
|
-
return {
|
|
2380
|
-
type: "function",
|
|
2381
|
-
name: schema.name,
|
|
2382
|
-
description: schema.description,
|
|
2383
|
-
parameters: schema.parameters
|
|
2384
|
-
};
|
|
2385
|
-
}
|
|
2386
|
-
function toGemini(schema) {
|
|
2387
|
-
return {
|
|
2388
|
-
name: schema.name,
|
|
2389
|
-
description: schema.description,
|
|
2390
|
-
parameters: schema.parameters
|
|
2391
|
-
};
|
|
2392
|
-
}
|
|
2393
|
-
var CONVERTERS = {
|
|
2394
|
-
chat: toChatCompletions,
|
|
2395
|
-
realtime: toRealtime,
|
|
2396
|
-
gemini: toGemini
|
|
2397
|
-
};
|
|
2398
|
-
function getBuiltinToolSchemas(builtinTools, fmt) {
|
|
2399
|
-
const converter = CONVERTERS[fmt];
|
|
2400
|
-
const result = [];
|
|
2401
|
-
for (const [toolEnum, schema] of TOOL_MAP) {
|
|
2402
|
-
if (builtinTools === null || builtinTools.has(toolEnum)) {
|
|
2403
|
-
result.push(converter(schema));
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
return result;
|
|
2407
|
-
}
|
|
2408
|
-
function isBuiltinTool(name) {
|
|
2409
|
-
return BUILTIN_TOOL_NAMES.has(name);
|
|
2410
|
-
}
|
|
2411
|
-
async function executeBuiltinTool(funcName, args, call) {
|
|
2412
|
-
if (funcName === "hang_up") {
|
|
2413
|
-
await call.hangup();
|
|
2414
|
-
return "";
|
|
2415
|
-
}
|
|
2416
|
-
if (funcName === "collect_dtmf") {
|
|
2417
|
-
try {
|
|
2418
|
-
const result = await call.collectDtmf({
|
|
2419
|
-
maxDigits: args["max_digits"] ?? 4,
|
|
2420
|
-
finishOnKey: args["finish_on_key"] ?? "#",
|
|
2421
|
-
timeout: args["timeout"] ?? 5
|
|
2422
|
-
});
|
|
2423
|
-
return result || "(\uD0C0\uC784\uC544\uC6C3 - \uC785\uB825 \uC5C6\uC74C)";
|
|
2424
|
-
} catch (e) {
|
|
2425
|
-
return `Error: ${e}`;
|
|
2426
|
-
}
|
|
2427
|
-
}
|
|
2428
|
-
if (funcName === "send_dtmf") {
|
|
2429
|
-
try {
|
|
2430
|
-
await call.sendDtmfSequence(args["digits"] ?? "");
|
|
2431
|
-
return "sent";
|
|
2432
|
-
} catch (e) {
|
|
2433
|
-
return `Error: ${e}`;
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
if (funcName === "transfer_call") {
|
|
2437
|
-
try {
|
|
2438
|
-
call.transfer(args["to"], {
|
|
2439
|
-
destinationType: args["destination_type"] ?? void 0,
|
|
2440
|
-
mode: args["mode"] ?? void 0,
|
|
2441
|
-
afterTransfer: args["after_transfer"] ?? void 0,
|
|
2442
|
-
whisper: args["whisper"] ?? void 0,
|
|
2443
|
-
callerId: args["caller_id"] ?? void 0,
|
|
2444
|
-
timeout: args["timeout"] ?? void 0
|
|
2445
|
-
}).catch(() => {
|
|
2446
|
-
});
|
|
2447
|
-
return JSON.stringify({ status: "transfer_initiated" });
|
|
2448
|
-
} catch (e) {
|
|
2449
|
-
return `Error: ${e}`;
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
return null;
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
// src/agent/pipeline/buffering-call.ts
|
|
2456
|
-
var MetricsStub = class {
|
|
2457
|
-
recordToolCall() {
|
|
2458
|
-
}
|
|
2459
|
-
recordInterrupt() {
|
|
2460
|
-
}
|
|
2461
|
-
recordToolError() {
|
|
2462
|
-
}
|
|
2463
|
-
};
|
|
2464
|
-
var BufferingCall = class {
|
|
2465
|
-
_buffer = [];
|
|
2466
|
-
_droppedEvents = {};
|
|
2467
|
-
metrics = new MetricsStub();
|
|
2468
|
-
async sendAudio(chunk) {
|
|
2469
|
-
this._buffer.push(chunk);
|
|
2470
|
-
}
|
|
2471
|
-
/** clearAudio 도 prewarm 동안엔 no-op (드물긴 하지만 안전하게). */
|
|
2472
|
-
clearAudio() {
|
|
2473
|
-
this._buffer = [];
|
|
2474
|
-
}
|
|
2475
|
-
/**
|
|
2476
|
-
* transcript 등 lifecycle 이벤트는 prewarm 동안 무시한다. silent drop 은 디버깅이
|
|
2477
|
-
* 어려우므로 event name 별 카운터로 누적하고 attachBuffered() 시 한 번에 로깅한다.
|
|
2478
|
-
*/
|
|
2479
|
-
_emit(...args) {
|
|
2480
|
-
this._recordDropped(args);
|
|
2481
|
-
}
|
|
2482
|
-
async emit(...args) {
|
|
2483
|
-
this._recordDropped(args);
|
|
2484
|
-
}
|
|
2485
|
-
_recordDropped(args) {
|
|
2486
|
-
let eventName = "?";
|
|
2487
|
-
if (args.length > 0 && typeof args[0] === "string") {
|
|
2488
|
-
eventName = args[0];
|
|
2489
|
-
}
|
|
2490
|
-
this._droppedEvents[eventName] = (this._droppedEvents[eventName] ?? 0) + 1;
|
|
2491
|
-
}
|
|
2492
|
-
recordToolCall() {
|
|
2493
|
-
}
|
|
2494
|
-
recordToolError() {
|
|
2495
|
-
}
|
|
2496
|
-
recordFirstResponse() {
|
|
2497
|
-
}
|
|
2498
|
-
recordBargeIn() {
|
|
2499
|
-
}
|
|
2500
|
-
drainBuffer() {
|
|
2501
|
-
const out = this._buffer;
|
|
2502
|
-
this._buffer = [];
|
|
2503
|
-
return out;
|
|
2504
|
-
}
|
|
2505
|
-
drainDroppedEvents() {
|
|
2506
|
-
const out = this._droppedEvents;
|
|
2507
|
-
this._droppedEvents = {};
|
|
2508
|
-
return out;
|
|
2509
|
-
}
|
|
2510
|
-
};
|
|
2511
|
-
function attachBuffered(prev, next) {
|
|
2512
|
-
if (!(prev instanceof BufferingCall)) {
|
|
2513
|
-
return false;
|
|
2514
|
-
}
|
|
2515
|
-
const drained = prev.drainBuffer();
|
|
2516
|
-
const flushed = drained.length > 0;
|
|
2517
|
-
const callId = next.callId ?? "?";
|
|
2518
|
-
if (flushed) {
|
|
2519
|
-
console.info(
|
|
2520
|
-
`[PREWARM-T] first-audio call_id=${callId} t=${(process.hrtime.bigint() / 1000000n).toString()} buffered_chunks=${drained.length} source=prebuffer`
|
|
2521
|
-
);
|
|
2522
|
-
}
|
|
2523
|
-
for (const chunk of drained) {
|
|
2524
|
-
next.sendAudio(chunk);
|
|
2525
|
-
}
|
|
2526
|
-
const dropped = prev.drainDroppedEvents();
|
|
2527
|
-
if (Object.keys(dropped).length > 0) {
|
|
2528
|
-
console.info(
|
|
2529
|
-
`[PREWARM] dropped events during prewarm call_id=${callId} events=${JSON.stringify(dropped)}`
|
|
2530
|
-
);
|
|
2531
|
-
}
|
|
2532
|
-
return flushed;
|
|
2533
|
-
}
|
|
2534
|
-
|
|
2535
1953
|
// src/agent/pipeline/pipeline-session.ts
|
|
2536
1954
|
var PipelineSession = class {
|
|
2537
1955
|
_stt;
|
|
@@ -4534,6 +3952,6 @@ function mcpServerHTTP(options) {
|
|
|
4534
3952
|
};
|
|
4535
3953
|
}
|
|
4536
3954
|
|
|
4537
|
-
export { AnthropicLLM, AudioRecorder,
|
|
3955
|
+
export { AnthropicLLM, AudioRecorder, CallSession, ClawOpsAgent, ControlWebSocket, DeepSeekLLM, DeepgramSTT, ElevenLabsTTS, FireworksLLM, GeminiLLM, GeminiRealtime, GroqLLM, MCPClient, MediaWebSocket, MistralLLM, OllamaLLM, OpenAICompatLLM, OpenAILLM, OpenAIRealtime, PerplexityLLM, PipelineSession, TogetherLLM, ToolRegistry, XaiLLM, buildControlWsUrl, functionTool, getTracingConfig, mcpServerHTTP, mcpServerStdio, resetTracingConfig, setTracingConfig, zodToToolParams };
|
|
4538
3956
|
//# sourceMappingURL=index.js.map
|
|
4539
3957
|
//# sourceMappingURL=index.js.map
|