@adminforth/agent 1.41.0 → 1.41.1
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/build.log +1 -1
- package/dist/index.js +30 -14
- package/index.ts +29 -7
- package/package.json +1 -1
package/build.log
CHANGED
|
@@ -58,5 +58,5 @@ custom/speech_recognition_frontend/voiceActivityDetection.ts
|
|
|
58
58
|
custom/speech_recognition_frontend/types/
|
|
59
59
|
custom/speech_recognition_frontend/types/voice-activity-detection.d.ts
|
|
60
60
|
|
|
61
|
-
sent 1,660,
|
|
61
|
+
sent 1,660,143 bytes received 856 bytes 3,321,998.00 bytes/sec
|
|
62
62
|
total size is 1,656,231 speedup is 1.00
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,15 @@ const sessionIdBodySchema = z.object({
|
|
|
47
47
|
const createSessionBodySchema = z.object({
|
|
48
48
|
triggerMessage: z.string().optional(),
|
|
49
49
|
}).strict();
|
|
50
|
+
function isAbortError(error) {
|
|
51
|
+
return (error instanceof DOMException && error.name === "AbortError") || (typeof error === "object" &&
|
|
52
|
+
error !== null &&
|
|
53
|
+
"name" in error &&
|
|
54
|
+
(error.name === "AbortError" || error.name === "APIUserAbortError"));
|
|
55
|
+
}
|
|
56
|
+
function getErrorMessage(error) {
|
|
57
|
+
return error instanceof Error ? error.message : String(error);
|
|
58
|
+
}
|
|
50
59
|
export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
51
60
|
parseBody(schema, body, response) {
|
|
52
61
|
const parsed = schema.safeParse(body !== null && body !== void 0 ? body : {});
|
|
@@ -165,7 +174,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
165
174
|
runAgentTurn(input) {
|
|
166
175
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
176
|
var _a, e_1, _b, _c;
|
|
168
|
-
var _d, _e, _f, _g;
|
|
177
|
+
var _d, _e, _f, _g, _h;
|
|
169
178
|
let fullResponse = "";
|
|
170
179
|
const maxTokens = (_d = this.options.maxTokens) !== null && _d !== void 0 ? _d : 1000;
|
|
171
180
|
const selectedMode = (_e = this.options.modes.find((mode) => mode.name === input.modeName)) !== null && _e !== void 0 ? _e : this.options.modes[0];
|
|
@@ -186,7 +195,11 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
186
195
|
const modelMiddleware = primaryModelSpec.middleware;
|
|
187
196
|
const userLanguage = yield detectUserLanguage(selectedMode.completionAdapter, input.prompt, input.previousUserMessages)
|
|
188
197
|
.catch((error) => {
|
|
189
|
-
|
|
198
|
+
var _a;
|
|
199
|
+
if (((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) || isAbortError(error)) {
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
logger.warn(`Failed to detect user language: ${getErrorMessage(error)}`);
|
|
190
203
|
return null;
|
|
191
204
|
});
|
|
192
205
|
const systemPrompt = buildAgentTurnSystemPrompt({
|
|
@@ -223,10 +236,13 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
223
236
|
sequenceDebugSink: input.sequenceDebugCollector,
|
|
224
237
|
});
|
|
225
238
|
try {
|
|
226
|
-
for (var
|
|
227
|
-
_c =
|
|
228
|
-
|
|
239
|
+
for (var _j = true, _k = __asyncValues(stream), _l; _l = yield _k.next(), _a = _l.done, !_a; _j = true) {
|
|
240
|
+
_c = _l.value;
|
|
241
|
+
_j = false;
|
|
229
242
|
const rawChunk = _c;
|
|
243
|
+
if ((_f = input.abortSignal) === null || _f === void 0 ? void 0 : _f.aborted) {
|
|
244
|
+
throw new DOMException("This operation was aborted", "AbortError");
|
|
245
|
+
}
|
|
230
246
|
const [token, metadata] = rawChunk;
|
|
231
247
|
const nodeName = typeof (metadata === null || metadata === void 0 ? void 0 : metadata.langgraph_node) === "string"
|
|
232
248
|
? metadata.langgraph_node
|
|
@@ -248,18 +264,18 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
248
264
|
.map((b) => { var _a; return String((_a = b.text) !== null && _a !== void 0 ? _a : ""); })
|
|
249
265
|
.join("");
|
|
250
266
|
if (reasoningDelta) {
|
|
251
|
-
(
|
|
267
|
+
(_g = input.emitReasoningDelta) === null || _g === void 0 ? void 0 : _g.call(input, reasoningDelta);
|
|
252
268
|
}
|
|
253
269
|
if (textDelta) {
|
|
254
270
|
fullResponse += textDelta;
|
|
255
|
-
(
|
|
271
|
+
(_h = input.emitTextDelta) === null || _h === void 0 ? void 0 : _h.call(input, textDelta);
|
|
256
272
|
}
|
|
257
273
|
}
|
|
258
274
|
}
|
|
259
275
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
260
276
|
finally {
|
|
261
277
|
try {
|
|
262
|
-
if (!
|
|
278
|
+
if (!_j && !_a && (_b = _k.return)) yield _b.call(_k);
|
|
263
279
|
}
|
|
264
280
|
finally { if (e_1) throw e_1.error; }
|
|
265
281
|
}
|
|
@@ -299,14 +315,14 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
299
315
|
fullResponse = agentResponse.text;
|
|
300
316
|
}
|
|
301
317
|
catch (error) {
|
|
302
|
-
if ((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
318
|
+
if (((_a = input.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) || isAbortError(error)) {
|
|
303
319
|
aborted = true;
|
|
304
320
|
logger.info(input.abortLogMessage);
|
|
305
321
|
}
|
|
306
322
|
else {
|
|
307
323
|
failed = true;
|
|
308
|
-
|
|
309
|
-
|
|
324
|
+
fullResponse = getErrorMessage(error);
|
|
325
|
+
logger.error(`${input.failureLogMessage}:\n${fullResponse}`);
|
|
310
326
|
(_b = input.emitErrorResponse) === null || _b === void 0 ? void 0 : _b.call(input, fullResponse);
|
|
311
327
|
}
|
|
312
328
|
}
|
|
@@ -406,12 +422,12 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
406
422
|
});
|
|
407
423
|
}
|
|
408
424
|
catch (error) {
|
|
409
|
-
if (abortSignal.aborted) {
|
|
425
|
+
if (abortSignal.aborted || isAbortError(error)) {
|
|
410
426
|
logger.info("Agent speech transcription aborted by the client");
|
|
411
427
|
stream.end();
|
|
412
428
|
return null;
|
|
413
429
|
}
|
|
414
|
-
logger.error(`Agent speech transcription failed:\n${error
|
|
430
|
+
logger.error(`Agent speech transcription failed:\n${getErrorMessage(error)}`);
|
|
415
431
|
stream.error("Speech transcription failed. Check server logs for details.");
|
|
416
432
|
stream.end();
|
|
417
433
|
return null;
|
|
@@ -495,7 +511,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
495
511
|
return null;
|
|
496
512
|
}
|
|
497
513
|
catch (error) {
|
|
498
|
-
if (abortSignal.aborted) {
|
|
514
|
+
if (abortSignal.aborted || isAbortError(error)) {
|
|
499
515
|
logger.info("Agent speech audio streaming aborted by the client");
|
|
500
516
|
}
|
|
501
517
|
else {
|
package/index.ts
CHANGED
|
@@ -75,6 +75,20 @@ const createSessionBodySchema = z.object({
|
|
|
75
75
|
triggerMessage: z.string().optional(),
|
|
76
76
|
}).strict();
|
|
77
77
|
|
|
78
|
+
function isAbortError(error: unknown): boolean {
|
|
79
|
+
return (
|
|
80
|
+
error instanceof DOMException && error.name === "AbortError"
|
|
81
|
+
) || (
|
|
82
|
+
typeof error === "object" &&
|
|
83
|
+
error !== null &&
|
|
84
|
+
"name" in error &&
|
|
85
|
+
(error.name === "AbortError" || error.name === "APIUserAbortError")
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getErrorMessage(error: unknown): string {
|
|
90
|
+
return error instanceof Error ? error.message : String(error);
|
|
91
|
+
}
|
|
78
92
|
|
|
79
93
|
export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
80
94
|
options: PluginOptions;
|
|
@@ -233,7 +247,11 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
233
247
|
|
|
234
248
|
const userLanguage = await detectUserLanguage(selectedMode.completionAdapter, input.prompt, input.previousUserMessages)
|
|
235
249
|
.catch((error) => {
|
|
236
|
-
|
|
250
|
+
if (input.abortSignal?.aborted || isAbortError(error)) {
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
logger.warn(`Failed to detect user language: ${getErrorMessage(error)}`);
|
|
237
255
|
return null;
|
|
238
256
|
});
|
|
239
257
|
const systemPrompt = buildAgentTurnSystemPrompt({
|
|
@@ -274,6 +292,10 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
274
292
|
});
|
|
275
293
|
|
|
276
294
|
for await (const rawChunk of stream as AsyncIterable<[any, any]>) {
|
|
295
|
+
if (input.abortSignal?.aborted) {
|
|
296
|
+
throw new DOMException("This operation was aborted", "AbortError");
|
|
297
|
+
}
|
|
298
|
+
|
|
277
299
|
const [token, metadata] = rawChunk;
|
|
278
300
|
|
|
279
301
|
const nodeName =
|
|
@@ -344,13 +366,13 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
344
366
|
});
|
|
345
367
|
fullResponse = agentResponse.text;
|
|
346
368
|
} catch (error) {
|
|
347
|
-
if (input.abortSignal?.aborted) {
|
|
369
|
+
if (input.abortSignal?.aborted || isAbortError(error)) {
|
|
348
370
|
aborted = true;
|
|
349
371
|
logger.info(input.abortLogMessage);
|
|
350
372
|
} else {
|
|
351
373
|
failed = true;
|
|
352
|
-
|
|
353
|
-
|
|
374
|
+
fullResponse = getErrorMessage(error);
|
|
375
|
+
logger.error(`${input.failureLogMessage}:\n${fullResponse}`);
|
|
354
376
|
input.emitErrorResponse?.(fullResponse);
|
|
355
377
|
}
|
|
356
378
|
}
|
|
@@ -454,13 +476,13 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
454
476
|
abortSignal,
|
|
455
477
|
});
|
|
456
478
|
} catch (error) {
|
|
457
|
-
if (abortSignal.aborted) {
|
|
479
|
+
if (abortSignal.aborted || isAbortError(error)) {
|
|
458
480
|
logger.info("Agent speech transcription aborted by the client");
|
|
459
481
|
stream.end();
|
|
460
482
|
return null;
|
|
461
483
|
}
|
|
462
484
|
|
|
463
|
-
logger.error(`Agent speech transcription failed:\n${error
|
|
485
|
+
logger.error(`Agent speech transcription failed:\n${getErrorMessage(error)}`);
|
|
464
486
|
stream.error("Speech transcription failed. Check server logs for details.");
|
|
465
487
|
stream.end();
|
|
466
488
|
return null;
|
|
@@ -562,7 +584,7 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
|
|
|
562
584
|
stream.end();
|
|
563
585
|
return null;
|
|
564
586
|
} catch (error) {
|
|
565
|
-
if (abortSignal.aborted) {
|
|
587
|
+
if (abortSignal.aborted || isAbortError(error)) {
|
|
566
588
|
logger.info("Agent speech audio streaming aborted by the client");
|
|
567
589
|
} else {
|
|
568
590
|
logger.error(`Agent speech audio streaming failed:\n${error}`);
|