agent-swarm-kit 1.0.24 → 1.0.26
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/index.cjs +106 -102
- package/build/index.mjs +107 -103
- package/package.json +1 -1
- package/types.d.ts +5 -2
package/build/index.cjs
CHANGED
|
@@ -258,6 +258,103 @@ var AgentSchemaService = /** @class */ (function () {
|
|
|
258
258
|
return AgentSchemaService;
|
|
259
259
|
}());
|
|
260
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Validates that the given output string is not empty.
|
|
263
|
+
*
|
|
264
|
+
* @param {string} output - The output string to validate.
|
|
265
|
+
* @returns {Promise<string | null>} - Returns a promise that resolves to "Empty output" if the string is empty, otherwise null.
|
|
266
|
+
*/
|
|
267
|
+
var validateNoEmptyResult = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
268
|
+
return __generator(this, function (_a) {
|
|
269
|
+
if (!output.trim()) {
|
|
270
|
+
return [2 /*return*/, "Empty output"];
|
|
271
|
+
}
|
|
272
|
+
return [2 /*return*/, null];
|
|
273
|
+
});
|
|
274
|
+
}); };
|
|
275
|
+
|
|
276
|
+
var toolParser = new xml2js.Parser();
|
|
277
|
+
/**
|
|
278
|
+
* Validates that the given output string does not contain any tool call entries or disallowed symbols.
|
|
279
|
+
* @see https://github.com/ollama/ollama/issues/8287
|
|
280
|
+
*
|
|
281
|
+
* @param {string} output - The output string to validate.
|
|
282
|
+
* @returns {Promise<string | null>} - A promise that resolves to a string indicating a tool call in the text output, or null if no tool call is found.
|
|
283
|
+
* @throws {Error} - If an error occurs during XML parsing.
|
|
284
|
+
*/
|
|
285
|
+
var validateNoToolCall = functoolsKit.trycatch(function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
286
|
+
var _a, _b, symbol, result, _c, _d, tag;
|
|
287
|
+
var e_1, _e, e_2, _f;
|
|
288
|
+
return __generator(this, function (_g) {
|
|
289
|
+
switch (_g.label) {
|
|
290
|
+
case 0:
|
|
291
|
+
try {
|
|
292
|
+
for (_a = __values(GLOBAL_CONFIG.CC_AGENT_DISALLOWED_SYMBOLS), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
293
|
+
symbol = _b.value;
|
|
294
|
+
if (output.includes(symbol)) {
|
|
295
|
+
return [2 /*return*/, "Tool call in text output"];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
300
|
+
finally {
|
|
301
|
+
try {
|
|
302
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
303
|
+
}
|
|
304
|
+
finally { if (e_1) throw e_1.error; }
|
|
305
|
+
}
|
|
306
|
+
return [4 /*yield*/, toolParser.parseStringPromise(output)];
|
|
307
|
+
case 1:
|
|
308
|
+
result = _g.sent();
|
|
309
|
+
try {
|
|
310
|
+
for (_c = __values(GLOBAL_CONFIG.CC_AGENT_DISALLOWED_TAGS), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
311
|
+
tag = _d.value;
|
|
312
|
+
if (result[tag]) {
|
|
313
|
+
return [2 /*return*/, "Tool call in text output"];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
318
|
+
finally {
|
|
319
|
+
try {
|
|
320
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
321
|
+
}
|
|
322
|
+
finally { if (e_2) throw e_2.error; }
|
|
323
|
+
}
|
|
324
|
+
return [2 /*return*/, null];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}); }, {
|
|
328
|
+
defaultValue: null,
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Validates the given output string using a series of validation functions.
|
|
333
|
+
*
|
|
334
|
+
* @param {string} output - The output string to validate.
|
|
335
|
+
* @returns {Promise<string | null>} - A promise that resolves to a validation error message if any validation fails, or null if all validations pass.
|
|
336
|
+
*/
|
|
337
|
+
var validateDefault = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
338
|
+
var validation;
|
|
339
|
+
return __generator(this, function (_a) {
|
|
340
|
+
switch (_a.label) {
|
|
341
|
+
case 0:
|
|
342
|
+
validation = null;
|
|
343
|
+
return [4 /*yield*/, validateNoEmptyResult(output)];
|
|
344
|
+
case 1:
|
|
345
|
+
if (validation = _a.sent()) {
|
|
346
|
+
return [2 /*return*/, validation];
|
|
347
|
+
}
|
|
348
|
+
return [4 /*yield*/, validateNoToolCall(output)];
|
|
349
|
+
case 2:
|
|
350
|
+
if (validation = _a.sent()) {
|
|
351
|
+
return [2 /*return*/, validation];
|
|
352
|
+
}
|
|
353
|
+
return [2 /*return*/, null];
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}); };
|
|
357
|
+
|
|
261
358
|
/**
|
|
262
359
|
* @description `ask for agent function` in `llama3.1:8b` to troubleshoot (need CC_OLLAMA_EMIT_TOOL_PROTOCOL to be turned off)
|
|
263
360
|
*/
|
|
@@ -293,6 +390,12 @@ var CC_SWARM_DEFAULT_AGENT = function (_a, _b, defaultAgent_1) { return __awaite
|
|
|
293
390
|
}
|
|
294
391
|
});
|
|
295
392
|
}); };
|
|
393
|
+
var CC_AGENT_DEFAULT_VALIDATION = validateDefault;
|
|
394
|
+
var CC_AGENT_DISALLOWED_TAGS = ["tool_call", "toolcall", "tool"];
|
|
395
|
+
var CC_AGENT_DISALLOWED_SYMBOLS = [
|
|
396
|
+
"{",
|
|
397
|
+
"}",
|
|
398
|
+
];
|
|
296
399
|
var CC_KEEP_MESSAGES = 5;
|
|
297
400
|
var CC_ANSWER_TIMEOUT = 120000;
|
|
298
401
|
var CC_GET_AGENT_HISTORY = function () { return new functoolsKit.PubsubArrayAdapter(); };
|
|
@@ -304,6 +407,9 @@ var GLOBAL_CONFIG = {
|
|
|
304
407
|
CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
|
|
305
408
|
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
306
409
|
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
410
|
+
CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
|
|
411
|
+
CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
|
|
412
|
+
CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
|
|
307
413
|
};
|
|
308
414
|
var setConfig = function (config) {
|
|
309
415
|
Object.assign(GLOBAL_CONFIG, config);
|
|
@@ -657,108 +763,6 @@ var ClientAgent = /** @class */ (function () {
|
|
|
657
763
|
return ClientAgent;
|
|
658
764
|
}());
|
|
659
765
|
|
|
660
|
-
/**
|
|
661
|
-
* Validates that the given output string is not empty.
|
|
662
|
-
*
|
|
663
|
-
* @param {string} output - The output string to validate.
|
|
664
|
-
* @returns {Promise<string | null>} - Returns a promise that resolves to "Empty output" if the string is empty, otherwise null.
|
|
665
|
-
*/
|
|
666
|
-
var validateNoEmptyResult = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
667
|
-
return __generator(this, function (_a) {
|
|
668
|
-
if (!output.trim()) {
|
|
669
|
-
return [2 /*return*/, "Empty output"];
|
|
670
|
-
}
|
|
671
|
-
return [2 /*return*/, null];
|
|
672
|
-
});
|
|
673
|
-
}); };
|
|
674
|
-
|
|
675
|
-
var toolParser = new xml2js.Parser();
|
|
676
|
-
var TOOL_CALL_ENTRIES = ["tool_call", "toolcall", "tool"];
|
|
677
|
-
var DISALLOWED_SYMBOLS = [
|
|
678
|
-
"{",
|
|
679
|
-
"}",
|
|
680
|
-
];
|
|
681
|
-
/**
|
|
682
|
-
* Validates that the given output string does not contain any tool call entries or disallowed symbols.
|
|
683
|
-
* @see https://github.com/ollama/ollama/issues/8287
|
|
684
|
-
*
|
|
685
|
-
* @param {string} output - The output string to validate.
|
|
686
|
-
* @returns {Promise<string | null>} - A promise that resolves to a string indicating a tool call in the text output, or null if no tool call is found.
|
|
687
|
-
* @throws {Error} - If an error occurs during XML parsing.
|
|
688
|
-
*/
|
|
689
|
-
var validateNoToolCall = functoolsKit.trycatch(function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
690
|
-
var DISALLOWED_SYMBOLS_1, DISALLOWED_SYMBOLS_1_1, symbol, result, TOOL_CALL_ENTRIES_1, TOOL_CALL_ENTRIES_1_1, tag;
|
|
691
|
-
var e_1, _a, e_2, _b;
|
|
692
|
-
return __generator(this, function (_c) {
|
|
693
|
-
switch (_c.label) {
|
|
694
|
-
case 0:
|
|
695
|
-
try {
|
|
696
|
-
for (DISALLOWED_SYMBOLS_1 = __values(DISALLOWED_SYMBOLS), DISALLOWED_SYMBOLS_1_1 = DISALLOWED_SYMBOLS_1.next(); !DISALLOWED_SYMBOLS_1_1.done; DISALLOWED_SYMBOLS_1_1 = DISALLOWED_SYMBOLS_1.next()) {
|
|
697
|
-
symbol = DISALLOWED_SYMBOLS_1_1.value;
|
|
698
|
-
if (output.includes(symbol)) {
|
|
699
|
-
return [2 /*return*/, "Tool call in text output"];
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
704
|
-
finally {
|
|
705
|
-
try {
|
|
706
|
-
if (DISALLOWED_SYMBOLS_1_1 && !DISALLOWED_SYMBOLS_1_1.done && (_a = DISALLOWED_SYMBOLS_1.return)) _a.call(DISALLOWED_SYMBOLS_1);
|
|
707
|
-
}
|
|
708
|
-
finally { if (e_1) throw e_1.error; }
|
|
709
|
-
}
|
|
710
|
-
return [4 /*yield*/, toolParser.parseStringPromise(output)];
|
|
711
|
-
case 1:
|
|
712
|
-
result = _c.sent();
|
|
713
|
-
try {
|
|
714
|
-
for (TOOL_CALL_ENTRIES_1 = __values(TOOL_CALL_ENTRIES), TOOL_CALL_ENTRIES_1_1 = TOOL_CALL_ENTRIES_1.next(); !TOOL_CALL_ENTRIES_1_1.done; TOOL_CALL_ENTRIES_1_1 = TOOL_CALL_ENTRIES_1.next()) {
|
|
715
|
-
tag = TOOL_CALL_ENTRIES_1_1.value;
|
|
716
|
-
if (result[tag]) {
|
|
717
|
-
return [2 /*return*/, "Tool call in text output"];
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
722
|
-
finally {
|
|
723
|
-
try {
|
|
724
|
-
if (TOOL_CALL_ENTRIES_1_1 && !TOOL_CALL_ENTRIES_1_1.done && (_b = TOOL_CALL_ENTRIES_1.return)) _b.call(TOOL_CALL_ENTRIES_1);
|
|
725
|
-
}
|
|
726
|
-
finally { if (e_2) throw e_2.error; }
|
|
727
|
-
}
|
|
728
|
-
return [2 /*return*/, null];
|
|
729
|
-
}
|
|
730
|
-
});
|
|
731
|
-
}); }, {
|
|
732
|
-
defaultValue: null,
|
|
733
|
-
});
|
|
734
|
-
|
|
735
|
-
/**
|
|
736
|
-
* Validates the given output string using a series of validation functions.
|
|
737
|
-
*
|
|
738
|
-
* @param {string} output - The output string to validate.
|
|
739
|
-
* @returns {Promise<string | null>} - A promise that resolves to a validation error message if any validation fails, or null if all validations pass.
|
|
740
|
-
*/
|
|
741
|
-
var validateDefault = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
742
|
-
var validation;
|
|
743
|
-
return __generator(this, function (_a) {
|
|
744
|
-
switch (_a.label) {
|
|
745
|
-
case 0:
|
|
746
|
-
validation = null;
|
|
747
|
-
return [4 /*yield*/, validateNoEmptyResult(output)];
|
|
748
|
-
case 1:
|
|
749
|
-
if (validation = _a.sent()) {
|
|
750
|
-
return [2 /*return*/, validation];
|
|
751
|
-
}
|
|
752
|
-
return [4 /*yield*/, validateNoToolCall(output)];
|
|
753
|
-
case 2:
|
|
754
|
-
if (validation = _a.sent()) {
|
|
755
|
-
return [2 /*return*/, validation];
|
|
756
|
-
}
|
|
757
|
-
return [2 /*return*/, null];
|
|
758
|
-
}
|
|
759
|
-
});
|
|
760
|
-
}); };
|
|
761
|
-
|
|
762
766
|
/**
|
|
763
767
|
* Service for managing agent connections.
|
|
764
768
|
* @implements {IAgent}
|
package/build/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scoped } from 'di-scoped';
|
|
2
|
-
import { ToolRegistry, sleep, PubsubArrayAdapter, Subject, queued, not,
|
|
2
|
+
import { ToolRegistry, trycatch, sleep, PubsubArrayAdapter, Subject, queued, not, memoize, schedule, ttl, singleshot, Source } from 'functools-kit';
|
|
3
3
|
import { createActivator } from 'di-kit';
|
|
4
4
|
import { omit } from 'lodash-es';
|
|
5
5
|
import xml2js from 'xml2js';
|
|
@@ -256,6 +256,103 @@ var AgentSchemaService = /** @class */ (function () {
|
|
|
256
256
|
return AgentSchemaService;
|
|
257
257
|
}());
|
|
258
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Validates that the given output string is not empty.
|
|
261
|
+
*
|
|
262
|
+
* @param {string} output - The output string to validate.
|
|
263
|
+
* @returns {Promise<string | null>} - Returns a promise that resolves to "Empty output" if the string is empty, otherwise null.
|
|
264
|
+
*/
|
|
265
|
+
var validateNoEmptyResult = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
if (!output.trim()) {
|
|
268
|
+
return [2 /*return*/, "Empty output"];
|
|
269
|
+
}
|
|
270
|
+
return [2 /*return*/, null];
|
|
271
|
+
});
|
|
272
|
+
}); };
|
|
273
|
+
|
|
274
|
+
var toolParser = new xml2js.Parser();
|
|
275
|
+
/**
|
|
276
|
+
* Validates that the given output string does not contain any tool call entries or disallowed symbols.
|
|
277
|
+
* @see https://github.com/ollama/ollama/issues/8287
|
|
278
|
+
*
|
|
279
|
+
* @param {string} output - The output string to validate.
|
|
280
|
+
* @returns {Promise<string | null>} - A promise that resolves to a string indicating a tool call in the text output, or null if no tool call is found.
|
|
281
|
+
* @throws {Error} - If an error occurs during XML parsing.
|
|
282
|
+
*/
|
|
283
|
+
var validateNoToolCall = trycatch(function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
284
|
+
var _a, _b, symbol, result, _c, _d, tag;
|
|
285
|
+
var e_1, _e, e_2, _f;
|
|
286
|
+
return __generator(this, function (_g) {
|
|
287
|
+
switch (_g.label) {
|
|
288
|
+
case 0:
|
|
289
|
+
try {
|
|
290
|
+
for (_a = __values(GLOBAL_CONFIG.CC_AGENT_DISALLOWED_SYMBOLS), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
291
|
+
symbol = _b.value;
|
|
292
|
+
if (output.includes(symbol)) {
|
|
293
|
+
return [2 /*return*/, "Tool call in text output"];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
298
|
+
finally {
|
|
299
|
+
try {
|
|
300
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
301
|
+
}
|
|
302
|
+
finally { if (e_1) throw e_1.error; }
|
|
303
|
+
}
|
|
304
|
+
return [4 /*yield*/, toolParser.parseStringPromise(output)];
|
|
305
|
+
case 1:
|
|
306
|
+
result = _g.sent();
|
|
307
|
+
try {
|
|
308
|
+
for (_c = __values(GLOBAL_CONFIG.CC_AGENT_DISALLOWED_TAGS), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
309
|
+
tag = _d.value;
|
|
310
|
+
if (result[tag]) {
|
|
311
|
+
return [2 /*return*/, "Tool call in text output"];
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
316
|
+
finally {
|
|
317
|
+
try {
|
|
318
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
319
|
+
}
|
|
320
|
+
finally { if (e_2) throw e_2.error; }
|
|
321
|
+
}
|
|
322
|
+
return [2 /*return*/, null];
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}); }, {
|
|
326
|
+
defaultValue: null,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Validates the given output string using a series of validation functions.
|
|
331
|
+
*
|
|
332
|
+
* @param {string} output - The output string to validate.
|
|
333
|
+
* @returns {Promise<string | null>} - A promise that resolves to a validation error message if any validation fails, or null if all validations pass.
|
|
334
|
+
*/
|
|
335
|
+
var validateDefault = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
336
|
+
var validation;
|
|
337
|
+
return __generator(this, function (_a) {
|
|
338
|
+
switch (_a.label) {
|
|
339
|
+
case 0:
|
|
340
|
+
validation = null;
|
|
341
|
+
return [4 /*yield*/, validateNoEmptyResult(output)];
|
|
342
|
+
case 1:
|
|
343
|
+
if (validation = _a.sent()) {
|
|
344
|
+
return [2 /*return*/, validation];
|
|
345
|
+
}
|
|
346
|
+
return [4 /*yield*/, validateNoToolCall(output)];
|
|
347
|
+
case 2:
|
|
348
|
+
if (validation = _a.sent()) {
|
|
349
|
+
return [2 /*return*/, validation];
|
|
350
|
+
}
|
|
351
|
+
return [2 /*return*/, null];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}); };
|
|
355
|
+
|
|
259
356
|
/**
|
|
260
357
|
* @description `ask for agent function` in `llama3.1:8b` to troubleshoot (need CC_OLLAMA_EMIT_TOOL_PROTOCOL to be turned off)
|
|
261
358
|
*/
|
|
@@ -291,6 +388,12 @@ var CC_SWARM_DEFAULT_AGENT = function (_a, _b, defaultAgent_1) { return __awaite
|
|
|
291
388
|
}
|
|
292
389
|
});
|
|
293
390
|
}); };
|
|
391
|
+
var CC_AGENT_DEFAULT_VALIDATION = validateDefault;
|
|
392
|
+
var CC_AGENT_DISALLOWED_TAGS = ["tool_call", "toolcall", "tool"];
|
|
393
|
+
var CC_AGENT_DISALLOWED_SYMBOLS = [
|
|
394
|
+
"{",
|
|
395
|
+
"}",
|
|
396
|
+
];
|
|
294
397
|
var CC_KEEP_MESSAGES = 5;
|
|
295
398
|
var CC_ANSWER_TIMEOUT = 120000;
|
|
296
399
|
var CC_GET_AGENT_HISTORY = function () { return new PubsubArrayAdapter(); };
|
|
@@ -302,6 +405,9 @@ var GLOBAL_CONFIG = {
|
|
|
302
405
|
CC_GET_AGENT_HISTORY: CC_GET_AGENT_HISTORY,
|
|
303
406
|
CC_SWARM_AGENT_CHANGED: CC_SWARM_AGENT_CHANGED,
|
|
304
407
|
CC_SWARM_DEFAULT_AGENT: CC_SWARM_DEFAULT_AGENT,
|
|
408
|
+
CC_AGENT_DEFAULT_VALIDATION: CC_AGENT_DEFAULT_VALIDATION,
|
|
409
|
+
CC_AGENT_DISALLOWED_TAGS: CC_AGENT_DISALLOWED_TAGS,
|
|
410
|
+
CC_AGENT_DISALLOWED_SYMBOLS: CC_AGENT_DISALLOWED_SYMBOLS,
|
|
305
411
|
};
|
|
306
412
|
var setConfig = function (config) {
|
|
307
413
|
Object.assign(GLOBAL_CONFIG, config);
|
|
@@ -655,108 +761,6 @@ var ClientAgent = /** @class */ (function () {
|
|
|
655
761
|
return ClientAgent;
|
|
656
762
|
}());
|
|
657
763
|
|
|
658
|
-
/**
|
|
659
|
-
* Validates that the given output string is not empty.
|
|
660
|
-
*
|
|
661
|
-
* @param {string} output - The output string to validate.
|
|
662
|
-
* @returns {Promise<string | null>} - Returns a promise that resolves to "Empty output" if the string is empty, otherwise null.
|
|
663
|
-
*/
|
|
664
|
-
var validateNoEmptyResult = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
665
|
-
return __generator(this, function (_a) {
|
|
666
|
-
if (!output.trim()) {
|
|
667
|
-
return [2 /*return*/, "Empty output"];
|
|
668
|
-
}
|
|
669
|
-
return [2 /*return*/, null];
|
|
670
|
-
});
|
|
671
|
-
}); };
|
|
672
|
-
|
|
673
|
-
var toolParser = new xml2js.Parser();
|
|
674
|
-
var TOOL_CALL_ENTRIES = ["tool_call", "toolcall", "tool"];
|
|
675
|
-
var DISALLOWED_SYMBOLS = [
|
|
676
|
-
"{",
|
|
677
|
-
"}",
|
|
678
|
-
];
|
|
679
|
-
/**
|
|
680
|
-
* Validates that the given output string does not contain any tool call entries or disallowed symbols.
|
|
681
|
-
* @see https://github.com/ollama/ollama/issues/8287
|
|
682
|
-
*
|
|
683
|
-
* @param {string} output - The output string to validate.
|
|
684
|
-
* @returns {Promise<string | null>} - A promise that resolves to a string indicating a tool call in the text output, or null if no tool call is found.
|
|
685
|
-
* @throws {Error} - If an error occurs during XML parsing.
|
|
686
|
-
*/
|
|
687
|
-
var validateNoToolCall = trycatch(function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
688
|
-
var DISALLOWED_SYMBOLS_1, DISALLOWED_SYMBOLS_1_1, symbol, result, TOOL_CALL_ENTRIES_1, TOOL_CALL_ENTRIES_1_1, tag;
|
|
689
|
-
var e_1, _a, e_2, _b;
|
|
690
|
-
return __generator(this, function (_c) {
|
|
691
|
-
switch (_c.label) {
|
|
692
|
-
case 0:
|
|
693
|
-
try {
|
|
694
|
-
for (DISALLOWED_SYMBOLS_1 = __values(DISALLOWED_SYMBOLS), DISALLOWED_SYMBOLS_1_1 = DISALLOWED_SYMBOLS_1.next(); !DISALLOWED_SYMBOLS_1_1.done; DISALLOWED_SYMBOLS_1_1 = DISALLOWED_SYMBOLS_1.next()) {
|
|
695
|
-
symbol = DISALLOWED_SYMBOLS_1_1.value;
|
|
696
|
-
if (output.includes(symbol)) {
|
|
697
|
-
return [2 /*return*/, "Tool call in text output"];
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
702
|
-
finally {
|
|
703
|
-
try {
|
|
704
|
-
if (DISALLOWED_SYMBOLS_1_1 && !DISALLOWED_SYMBOLS_1_1.done && (_a = DISALLOWED_SYMBOLS_1.return)) _a.call(DISALLOWED_SYMBOLS_1);
|
|
705
|
-
}
|
|
706
|
-
finally { if (e_1) throw e_1.error; }
|
|
707
|
-
}
|
|
708
|
-
return [4 /*yield*/, toolParser.parseStringPromise(output)];
|
|
709
|
-
case 1:
|
|
710
|
-
result = _c.sent();
|
|
711
|
-
try {
|
|
712
|
-
for (TOOL_CALL_ENTRIES_1 = __values(TOOL_CALL_ENTRIES), TOOL_CALL_ENTRIES_1_1 = TOOL_CALL_ENTRIES_1.next(); !TOOL_CALL_ENTRIES_1_1.done; TOOL_CALL_ENTRIES_1_1 = TOOL_CALL_ENTRIES_1.next()) {
|
|
713
|
-
tag = TOOL_CALL_ENTRIES_1_1.value;
|
|
714
|
-
if (result[tag]) {
|
|
715
|
-
return [2 /*return*/, "Tool call in text output"];
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
720
|
-
finally {
|
|
721
|
-
try {
|
|
722
|
-
if (TOOL_CALL_ENTRIES_1_1 && !TOOL_CALL_ENTRIES_1_1.done && (_b = TOOL_CALL_ENTRIES_1.return)) _b.call(TOOL_CALL_ENTRIES_1);
|
|
723
|
-
}
|
|
724
|
-
finally { if (e_2) throw e_2.error; }
|
|
725
|
-
}
|
|
726
|
-
return [2 /*return*/, null];
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
}); }, {
|
|
730
|
-
defaultValue: null,
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* Validates the given output string using a series of validation functions.
|
|
735
|
-
*
|
|
736
|
-
* @param {string} output - The output string to validate.
|
|
737
|
-
* @returns {Promise<string | null>} - A promise that resolves to a validation error message if any validation fails, or null if all validations pass.
|
|
738
|
-
*/
|
|
739
|
-
var validateDefault = function (output) { return __awaiter(void 0, void 0, void 0, function () {
|
|
740
|
-
var validation;
|
|
741
|
-
return __generator(this, function (_a) {
|
|
742
|
-
switch (_a.label) {
|
|
743
|
-
case 0:
|
|
744
|
-
validation = null;
|
|
745
|
-
return [4 /*yield*/, validateNoEmptyResult(output)];
|
|
746
|
-
case 1:
|
|
747
|
-
if (validation = _a.sent()) {
|
|
748
|
-
return [2 /*return*/, validation];
|
|
749
|
-
}
|
|
750
|
-
return [4 /*yield*/, validateNoToolCall(output)];
|
|
751
|
-
case 2:
|
|
752
|
-
if (validation = _a.sent()) {
|
|
753
|
-
return [2 /*return*/, validation];
|
|
754
|
-
}
|
|
755
|
-
return [2 /*return*/, null];
|
|
756
|
-
}
|
|
757
|
-
});
|
|
758
|
-
}); };
|
|
759
|
-
|
|
760
764
|
/**
|
|
761
765
|
* Service for managing agent connections.
|
|
762
766
|
* @implements {IAgent}
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1806,7 +1806,10 @@ declare const GLOBAL_CONFIG: {
|
|
|
1806
1806
|
CC_GET_AGENT_HISTORY: (clientId: string, agentName: AgentName) => IPubsubArray<IModelMessage>;
|
|
1807
1807
|
CC_SWARM_AGENT_CHANGED: (clientId: string, agentName: AgentName, swarmName: SwarmName) => Promise<void>;
|
|
1808
1808
|
CC_SWARM_DEFAULT_AGENT: (clientId: string, swarmName: SwarmName, defaultAgent: AgentName) => Promise<AgentName>;
|
|
1809
|
+
CC_AGENT_DEFAULT_VALIDATION: (output: string) => Promise<string | null>;
|
|
1810
|
+
CC_AGENT_DISALLOWED_TAGS: string[];
|
|
1811
|
+
CC_AGENT_DISALLOWED_SYMBOLS: string[];
|
|
1809
1812
|
};
|
|
1810
|
-
declare const setConfig: (config: typeof GLOBAL_CONFIG) => void;
|
|
1813
|
+
declare const setConfig: (config: Partial<typeof GLOBAL_CONFIG>) => void;
|
|
1811
1814
|
|
|
1812
|
-
export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionSchema, type IIncomingMessage, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };
|
|
1815
|
+
export { ContextService, type IAgentSchema, type IAgentTool, type ICompletionArgs, type ICompletionSchema, type IIncomingMessage, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type ISwarmSchema, type ITool, type IToolCall, type ReceiveMessageFn, type SendMessageFn$1 as SendMessageFn, addAgent, addCompletion, addSwarm, addTool, changeAgent, commitSystemMessage, commitToolOutput, commitUserMessage, complete, disposeConnection, emit, execute, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getUserHistory, makeAutoDispose, makeConnection, session, setConfig, swarm };
|