agent-swarm-kit 1.0.131 → 1.0.133
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 +191 -19
- package/build/index.mjs +191 -19
- package/package.json +1 -1
- package/types.d.ts +68 -7
package/build/index.cjs
CHANGED
|
@@ -358,11 +358,13 @@ var INSTANCE_METHOD_NAME_CTOR = "HistoryInstance.CTOR";
|
|
|
358
358
|
var INSTANCE_METHOD_NAME_ITERATE_CONDITION = "HistoryInstance.iterate_condition";
|
|
359
359
|
var INSTANCE_METHOD_NAME_ITERATE = "HistoryInstance.iterate";
|
|
360
360
|
var INSTANCE_METHOD_NAME_PUSH = "HistoryInstance.push";
|
|
361
|
+
var INSTANCE_METHOD_NAME_POP = "HistoryInstance.pop";
|
|
361
362
|
var INSTANCE_METHOD_NAME_DISPOSE = "HistoryInstance.dispose";
|
|
362
363
|
var METHOD_NAME_USE_HISTORY_ADAPTER = "HistoryUtils.useHistoryAdapter";
|
|
363
364
|
var METHOD_NAME_USE_HISTORY_CALLBACKS = "HistoryUtils.useHistoryCallbacks";
|
|
364
365
|
var METHOD_NAME_ITERATE = "HistoryUtils.iterate";
|
|
365
366
|
var METHOD_NAME_PUSH = "HistoryUtils.push";
|
|
367
|
+
var METHOD_NAME_POP = "HistoryUtils.pop";
|
|
366
368
|
var METHOD_NAME_DISPOSE = "HistoryUtils.dispose";
|
|
367
369
|
var HISTORY_INSTANCE_WAIT_FOR_INIT_FN = function (agentName, self) { return __awaiter(void 0, void 0, void 0, function () {
|
|
368
370
|
var _b;
|
|
@@ -481,7 +483,7 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
481
483
|
role: "system",
|
|
482
484
|
content: content,
|
|
483
485
|
agentName: agentName,
|
|
484
|
-
mode: "tool"
|
|
486
|
+
mode: "tool",
|
|
485
487
|
})];
|
|
486
488
|
case 14: return [4 /*yield*/, _p.sent()];
|
|
487
489
|
case 15:
|
|
@@ -555,7 +557,7 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
555
557
|
role: "system",
|
|
556
558
|
content: content,
|
|
557
559
|
agentName: agentName,
|
|
558
|
-
mode: "tool"
|
|
560
|
+
mode: "tool",
|
|
559
561
|
})];
|
|
560
562
|
case 36: return [4 /*yield*/, _p.sent()];
|
|
561
563
|
case 37:
|
|
@@ -698,7 +700,7 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
698
700
|
role: "system",
|
|
699
701
|
content: content,
|
|
700
702
|
agentName: agentName,
|
|
701
|
-
mode: "tool"
|
|
703
|
+
mode: "tool",
|
|
702
704
|
})];
|
|
703
705
|
case 24: return [4 /*yield*/, _l.sent()];
|
|
704
706
|
case 25:
|
|
@@ -745,6 +747,25 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
745
747
|
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
746
748
|
return Promise.resolve();
|
|
747
749
|
};
|
|
750
|
+
/**
|
|
751
|
+
* Pop the last message from a history
|
|
752
|
+
* @param agentName - The agent name.
|
|
753
|
+
* @returns A promise that resolves when the message is pushed.
|
|
754
|
+
*/
|
|
755
|
+
HistoryInstance.prototype.pop = function (agentName) {
|
|
756
|
+
var _b;
|
|
757
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
758
|
+
swarm$1.loggerService.debug(INSTANCE_METHOD_NAME_POP, {
|
|
759
|
+
clientId: this.clientId,
|
|
760
|
+
agentName: agentName,
|
|
761
|
+
});
|
|
762
|
+
var value = (_b = this._array.pop()) !== null && _b !== void 0 ? _b : null;
|
|
763
|
+
this.callbacks.onPop &&
|
|
764
|
+
this.callbacks.onPop(value, this.clientId, agentName);
|
|
765
|
+
this.callbacks.onChange &&
|
|
766
|
+
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
767
|
+
return Promise.resolve(value);
|
|
768
|
+
};
|
|
748
769
|
/**
|
|
749
770
|
* Dispose of the history for a given agent.
|
|
750
771
|
* @param agentName - The agent name or null.
|
|
@@ -827,6 +848,35 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
827
848
|
}
|
|
828
849
|
});
|
|
829
850
|
}); };
|
|
851
|
+
/**
|
|
852
|
+
* Pop the last message from the history.
|
|
853
|
+
* @param value - The model message to push.
|
|
854
|
+
* @param clientId - The client ID.
|
|
855
|
+
* @param agentName - The agent name.
|
|
856
|
+
* @returns A promise that resolves when the message is pushed.
|
|
857
|
+
*/
|
|
858
|
+
this.pop = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
859
|
+
var isInitial, history;
|
|
860
|
+
return __generator(this, function (_b) {
|
|
861
|
+
switch (_b.label) {
|
|
862
|
+
case 0:
|
|
863
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
864
|
+
swarm$1.loggerService.log(METHOD_NAME_POP, {
|
|
865
|
+
clientId: clientId,
|
|
866
|
+
agentName: agentName,
|
|
867
|
+
});
|
|
868
|
+
isInitial = this.getHistory.has(clientId);
|
|
869
|
+
return [4 /*yield*/, this.getHistory(clientId)];
|
|
870
|
+
case 1:
|
|
871
|
+
history = _b.sent();
|
|
872
|
+
return [4 /*yield*/, history.waitForInit(agentName, isInitial)];
|
|
873
|
+
case 2:
|
|
874
|
+
_b.sent();
|
|
875
|
+
return [4 /*yield*/, history.pop(agentName)];
|
|
876
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
}); };
|
|
830
880
|
/**
|
|
831
881
|
* Dispose of the history for a given client and agent.
|
|
832
882
|
* @param clientId - The client ID.
|
|
@@ -1440,7 +1490,15 @@ var Logger = LoggerAdapter;
|
|
|
1440
1490
|
/**
|
|
1441
1491
|
* @description `ask for agent function` in `llama3.1:8b` to troubleshoot (need CC_OLLAMA_EMIT_TOOL_PROTOCOL to be turned off)
|
|
1442
1492
|
*/
|
|
1443
|
-
var
|
|
1493
|
+
var CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT = "Start the conversation";
|
|
1494
|
+
/**
|
|
1495
|
+
* @description fix for invalid tool calls on IlyaGusev/saiga_yandexgpt_8b_gguf (LMStudio, appear time to time)
|
|
1496
|
+
*/
|
|
1497
|
+
var CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT = "I see your previous message is malformed. Think again and resend it correct";
|
|
1498
|
+
/**
|
|
1499
|
+
* @description custom function to fix the model
|
|
1500
|
+
*/
|
|
1501
|
+
var CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION = function () { return Promise.resolve(); };
|
|
1444
1502
|
/**
|
|
1445
1503
|
* @description When the model output is empty just say hello to the customer
|
|
1446
1504
|
*/
|
|
@@ -1495,12 +1553,14 @@ var CC_LOGGER_ENABLE_INFO = false;
|
|
|
1495
1553
|
var CC_LOGGER_ENABLE_DEBUG = false;
|
|
1496
1554
|
var CC_LOGGER_ENABLE_LOG = true;
|
|
1497
1555
|
var CC_LOGGER_ENABLE_CONSOLE = false;
|
|
1556
|
+
var CC_RESQUE_STRATEGY;
|
|
1498
1557
|
var CC_NAME_TO_TITLE = nameToTitle;
|
|
1499
1558
|
var CC_FN_PLANTUML = function () { return Promise.resolve(""); };
|
|
1500
1559
|
var CC_PROCESS_UUID = functoolsKit.randomString();
|
|
1501
1560
|
var CC_BANHAMMER_PLACEHOLDER = "You have been banned! To continue conversation, please contact the administrator.";
|
|
1502
1561
|
var GLOBAL_CONFIG = {
|
|
1503
|
-
|
|
1562
|
+
CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT: CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
|
|
1563
|
+
CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT: CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
|
|
1504
1564
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
1505
1565
|
CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
|
|
1506
1566
|
CC_GET_AGENT_HISTORY_ADAPTER: CC_GET_AGENT_HISTORY_ADAPTER,
|
|
@@ -1522,11 +1582,14 @@ var GLOBAL_CONFIG = {
|
|
|
1522
1582
|
CC_LOGGER_ENABLE_DEBUG: CC_LOGGER_ENABLE_DEBUG,
|
|
1523
1583
|
CC_LOGGER_ENABLE_LOG: CC_LOGGER_ENABLE_LOG,
|
|
1524
1584
|
CC_LOGGER_ENABLE_CONSOLE: CC_LOGGER_ENABLE_CONSOLE,
|
|
1585
|
+
CC_RESQUE_STRATEGY: CC_RESQUE_STRATEGY,
|
|
1525
1586
|
CC_NAME_TO_TITLE: CC_NAME_TO_TITLE,
|
|
1526
1587
|
CC_FN_PLANTUML: CC_FN_PLANTUML,
|
|
1527
1588
|
CC_PROCESS_UUID: CC_PROCESS_UUID,
|
|
1528
1589
|
CC_BANHAMMER_PLACEHOLDER: CC_BANHAMMER_PLACEHOLDER,
|
|
1590
|
+
CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION: CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION,
|
|
1529
1591
|
};
|
|
1592
|
+
GLOBAL_CONFIG.CC_RESQUE_STRATEGY = "recomplete";
|
|
1530
1593
|
var setConfig = function (config) {
|
|
1531
1594
|
Object.assign(GLOBAL_CONFIG, config);
|
|
1532
1595
|
};
|
|
@@ -2165,45 +2228,67 @@ var ClientAgent = /** @class */ (function () {
|
|
|
2165
2228
|
* @returns {Promise<string>}
|
|
2166
2229
|
* @private
|
|
2167
2230
|
*/
|
|
2168
|
-
ClientAgent.prototype._resurrectModel = function (
|
|
2169
|
-
return __awaiter(this,
|
|
2231
|
+
ClientAgent.prototype._resurrectModel = function (mode_1) {
|
|
2232
|
+
return __awaiter(this, arguments, void 0, function (mode, reason) {
|
|
2170
2233
|
var rawMessage, message, result, validation, content;
|
|
2234
|
+
if (reason === void 0) { reason = "unknown"; }
|
|
2171
2235
|
return __generator(this, function (_a) {
|
|
2172
2236
|
switch (_a.label) {
|
|
2173
2237
|
case 0:
|
|
2174
2238
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2175
2239
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
|
|
2240
|
+
console.warn("agent-swarm model ressurect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " reason=").concat(reason));
|
|
2176
2241
|
this.params.onResurrect &&
|
|
2177
2242
|
this.params.onResurrect(this.params.clientId, this.params.agentName, mode, reason);
|
|
2243
|
+
if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete")) return [3 /*break*/, 2];
|
|
2244
|
+
return [4 /*yield*/, this.params.history.push({
|
|
2245
|
+
role: "user",
|
|
2246
|
+
mode: "tool",
|
|
2247
|
+
agentName: this.params.agentName,
|
|
2248
|
+
content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
|
|
2249
|
+
})];
|
|
2250
|
+
case 1:
|
|
2251
|
+
_a.sent();
|
|
2252
|
+
return [3 /*break*/, 8];
|
|
2253
|
+
case 2:
|
|
2254
|
+
if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "flush")) return [3 /*break*/, 5];
|
|
2178
2255
|
return [4 /*yield*/, this.params.history.push({
|
|
2179
2256
|
role: "resque",
|
|
2180
2257
|
mode: "tool",
|
|
2181
2258
|
agentName: this.params.agentName,
|
|
2182
2259
|
content: reason || "Unknown error",
|
|
2183
2260
|
})];
|
|
2184
|
-
case
|
|
2261
|
+
case 3:
|
|
2185
2262
|
_a.sent();
|
|
2186
2263
|
return [4 /*yield*/, this.params.history.push({
|
|
2187
2264
|
role: "user",
|
|
2188
2265
|
mode: "tool",
|
|
2189
2266
|
agentName: this.params.agentName,
|
|
2190
|
-
content: GLOBAL_CONFIG.
|
|
2267
|
+
content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
|
|
2191
2268
|
})];
|
|
2192
|
-
case
|
|
2269
|
+
case 4:
|
|
2193
2270
|
_a.sent();
|
|
2194
|
-
return [
|
|
2195
|
-
case
|
|
2271
|
+
return [3 /*break*/, 8];
|
|
2272
|
+
case 5:
|
|
2273
|
+
if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom")) return [3 /*break*/, 7];
|
|
2274
|
+
return [4 /*yield*/, GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION(this.params.clientId, this.params.agentName)];
|
|
2275
|
+
case 6:
|
|
2276
|
+
_a.sent();
|
|
2277
|
+
return [3 /*break*/, 8];
|
|
2278
|
+
case 7: throw new Error("agent-swarm _resurrectModel invalid strategy value=".concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " agentName=").concat(this.params.agentName, " clientId=").concat(this.params.clientId));
|
|
2279
|
+
case 8: return [4 /*yield*/, this.getCompletion(mode)];
|
|
2280
|
+
case 9:
|
|
2196
2281
|
rawMessage = _a.sent();
|
|
2197
2282
|
return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
|
|
2198
|
-
case
|
|
2283
|
+
case 10:
|
|
2199
2284
|
message = _a.sent();
|
|
2200
2285
|
return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
|
|
2201
|
-
case
|
|
2286
|
+
case 11:
|
|
2202
2287
|
result = _a.sent();
|
|
2203
2288
|
validation = null;
|
|
2204
2289
|
return [4 /*yield*/, this.params.validate(result)];
|
|
2205
|
-
case
|
|
2206
|
-
if (!(validation = _a.sent())) return [3 /*break*/,
|
|
2290
|
+
case 12:
|
|
2291
|
+
if (!(validation = _a.sent())) return [3 /*break*/, 14];
|
|
2207
2292
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2208
2293
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
|
|
2209
2294
|
content = getPlaceholder();
|
|
@@ -2213,11 +2298,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
2213
2298
|
mode: "tool",
|
|
2214
2299
|
content: content,
|
|
2215
2300
|
})];
|
|
2216
|
-
case
|
|
2301
|
+
case 13:
|
|
2217
2302
|
_a.sent();
|
|
2218
2303
|
return [2 /*return*/, content];
|
|
2219
|
-
case
|
|
2220
|
-
case
|
|
2304
|
+
case 14: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
2305
|
+
case 15:
|
|
2221
2306
|
_a.sent();
|
|
2222
2307
|
return [2 /*return*/, result];
|
|
2223
2308
|
}
|
|
@@ -2855,6 +2940,40 @@ var ClientHistory = /** @class */ (function () {
|
|
|
2855
2940
|
});
|
|
2856
2941
|
});
|
|
2857
2942
|
};
|
|
2943
|
+
/**
|
|
2944
|
+
* Pushes a message to the history.
|
|
2945
|
+
* @returns {Promise<IModelMessage | null>}
|
|
2946
|
+
*/
|
|
2947
|
+
ClientHistory.prototype.pop = function () {
|
|
2948
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2949
|
+
var value;
|
|
2950
|
+
return __generator(this, function (_a) {
|
|
2951
|
+
switch (_a.label) {
|
|
2952
|
+
case 0:
|
|
2953
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2954
|
+
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " pop"));
|
|
2955
|
+
return [4 /*yield*/, this.params.items.pop(this.params.clientId, this.params.agentName)];
|
|
2956
|
+
case 1:
|
|
2957
|
+
value = _a.sent();
|
|
2958
|
+
return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
|
|
2959
|
+
type: "pop",
|
|
2960
|
+
source: "history-bus",
|
|
2961
|
+
input: {},
|
|
2962
|
+
output: {
|
|
2963
|
+
value: value
|
|
2964
|
+
},
|
|
2965
|
+
context: {
|
|
2966
|
+
agentName: this.params.agentName,
|
|
2967
|
+
},
|
|
2968
|
+
clientId: this.params.clientId,
|
|
2969
|
+
})];
|
|
2970
|
+
case 2:
|
|
2971
|
+
_a.sent();
|
|
2972
|
+
return [2 /*return*/, value];
|
|
2973
|
+
}
|
|
2974
|
+
});
|
|
2975
|
+
});
|
|
2976
|
+
};
|
|
2858
2977
|
/**
|
|
2859
2978
|
* Converts the history to an array of raw messages.
|
|
2860
2979
|
* @returns {Promise<IModelMessage[]>} - The array of raw messages.
|
|
@@ -3127,6 +3246,21 @@ var HistoryConnectionService = /** @class */ (function () {
|
|
|
3127
3246
|
}
|
|
3128
3247
|
});
|
|
3129
3248
|
}); };
|
|
3249
|
+
/**
|
|
3250
|
+
* Pop a message from the history.
|
|
3251
|
+
* @returns {Promise<IModelMessage | null>} A promise that resolves when the message is popped.
|
|
3252
|
+
*/
|
|
3253
|
+
this.pop = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3254
|
+
return __generator(this, function (_a) {
|
|
3255
|
+
switch (_a.label) {
|
|
3256
|
+
case 0:
|
|
3257
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
3258
|
+
this.loggerService.info("historyConnectionService pop");
|
|
3259
|
+
return [4 /*yield*/, this.getHistory(this.methodContextService.context.clientId, this.methodContextService.context.agentName).pop()];
|
|
3260
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
3261
|
+
}
|
|
3262
|
+
});
|
|
3263
|
+
}); };
|
|
3130
3264
|
/**
|
|
3131
3265
|
* Converts the history to an array for the agent.
|
|
3132
3266
|
* @param {string} prompt - The prompt.
|
|
@@ -5553,6 +5687,43 @@ var HistoryPublicService = /** @class */ (function () {
|
|
|
5553
5687
|
}
|
|
5554
5688
|
});
|
|
5555
5689
|
}); };
|
|
5690
|
+
/**
|
|
5691
|
+
* Pushes a message to the history.
|
|
5692
|
+
* @param {string} clientId - The client ID.
|
|
5693
|
+
* @param {AgentName} agentName - The agent name.
|
|
5694
|
+
* @returns {Promise<IModelMessage | null>} A promise that resolves when the operation is complete.
|
|
5695
|
+
*/
|
|
5696
|
+
this.pop = function (methodName, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5697
|
+
var _this = this;
|
|
5698
|
+
return __generator(this, function (_a) {
|
|
5699
|
+
switch (_a.label) {
|
|
5700
|
+
case 0:
|
|
5701
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
5702
|
+
this.loggerService.info("historyPublicService pop", {
|
|
5703
|
+
methodName: methodName,
|
|
5704
|
+
clientId: clientId,
|
|
5705
|
+
agentName: agentName,
|
|
5706
|
+
});
|
|
5707
|
+
return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
5708
|
+
return __generator(this, function (_a) {
|
|
5709
|
+
switch (_a.label) {
|
|
5710
|
+
case 0: return [4 /*yield*/, this.historyConnectionService.pop()];
|
|
5711
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5712
|
+
}
|
|
5713
|
+
});
|
|
5714
|
+
}); }, {
|
|
5715
|
+
methodName: methodName,
|
|
5716
|
+
clientId: clientId,
|
|
5717
|
+
agentName: agentName,
|
|
5718
|
+
policyName: "",
|
|
5719
|
+
swarmName: "",
|
|
5720
|
+
storageName: "",
|
|
5721
|
+
stateName: "",
|
|
5722
|
+
})];
|
|
5723
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5724
|
+
}
|
|
5725
|
+
});
|
|
5726
|
+
}); };
|
|
5556
5727
|
/**
|
|
5557
5728
|
* Converts history to an array for a specific agent.
|
|
5558
5729
|
* @param {string} prompt - The prompt.
|
|
@@ -15556,6 +15727,7 @@ var SchemaUtils = /** @class */ (function () {
|
|
|
15556
15727
|
* @returns {string} The serialized string.
|
|
15557
15728
|
*/
|
|
15558
15729
|
this.serialize = function (data, map) {
|
|
15730
|
+
if (map === void 0) { map = {}; }
|
|
15559
15731
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15560
15732
|
swarm$1.loggerService.log(METHOD_NAME_SERIALIZE, {
|
|
15561
15733
|
data: data,
|
package/build/index.mjs
CHANGED
|
@@ -356,11 +356,13 @@ var INSTANCE_METHOD_NAME_CTOR = "HistoryInstance.CTOR";
|
|
|
356
356
|
var INSTANCE_METHOD_NAME_ITERATE_CONDITION = "HistoryInstance.iterate_condition";
|
|
357
357
|
var INSTANCE_METHOD_NAME_ITERATE = "HistoryInstance.iterate";
|
|
358
358
|
var INSTANCE_METHOD_NAME_PUSH = "HistoryInstance.push";
|
|
359
|
+
var INSTANCE_METHOD_NAME_POP = "HistoryInstance.pop";
|
|
359
360
|
var INSTANCE_METHOD_NAME_DISPOSE = "HistoryInstance.dispose";
|
|
360
361
|
var METHOD_NAME_USE_HISTORY_ADAPTER = "HistoryUtils.useHistoryAdapter";
|
|
361
362
|
var METHOD_NAME_USE_HISTORY_CALLBACKS = "HistoryUtils.useHistoryCallbacks";
|
|
362
363
|
var METHOD_NAME_ITERATE = "HistoryUtils.iterate";
|
|
363
364
|
var METHOD_NAME_PUSH = "HistoryUtils.push";
|
|
365
|
+
var METHOD_NAME_POP = "HistoryUtils.pop";
|
|
364
366
|
var METHOD_NAME_DISPOSE = "HistoryUtils.dispose";
|
|
365
367
|
var HISTORY_INSTANCE_WAIT_FOR_INIT_FN = function (agentName, self) { return __awaiter(void 0, void 0, void 0, function () {
|
|
366
368
|
var _b;
|
|
@@ -479,7 +481,7 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
479
481
|
role: "system",
|
|
480
482
|
content: content,
|
|
481
483
|
agentName: agentName,
|
|
482
|
-
mode: "tool"
|
|
484
|
+
mode: "tool",
|
|
483
485
|
})];
|
|
484
486
|
case 14: return [4 /*yield*/, _p.sent()];
|
|
485
487
|
case 15:
|
|
@@ -553,7 +555,7 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
553
555
|
role: "system",
|
|
554
556
|
content: content,
|
|
555
557
|
agentName: agentName,
|
|
556
|
-
mode: "tool"
|
|
558
|
+
mode: "tool",
|
|
557
559
|
})];
|
|
558
560
|
case 36: return [4 /*yield*/, _p.sent()];
|
|
559
561
|
case 37:
|
|
@@ -696,7 +698,7 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
696
698
|
role: "system",
|
|
697
699
|
content: content,
|
|
698
700
|
agentName: agentName,
|
|
699
|
-
mode: "tool"
|
|
701
|
+
mode: "tool",
|
|
700
702
|
})];
|
|
701
703
|
case 24: return [4 /*yield*/, _l.sent()];
|
|
702
704
|
case 25:
|
|
@@ -743,6 +745,25 @@ var HistoryInstance = /** @class */ (function () {
|
|
|
743
745
|
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
744
746
|
return Promise.resolve();
|
|
745
747
|
};
|
|
748
|
+
/**
|
|
749
|
+
* Pop the last message from a history
|
|
750
|
+
* @param agentName - The agent name.
|
|
751
|
+
* @returns A promise that resolves when the message is pushed.
|
|
752
|
+
*/
|
|
753
|
+
HistoryInstance.prototype.pop = function (agentName) {
|
|
754
|
+
var _b;
|
|
755
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
756
|
+
swarm$1.loggerService.debug(INSTANCE_METHOD_NAME_POP, {
|
|
757
|
+
clientId: this.clientId,
|
|
758
|
+
agentName: agentName,
|
|
759
|
+
});
|
|
760
|
+
var value = (_b = this._array.pop()) !== null && _b !== void 0 ? _b : null;
|
|
761
|
+
this.callbacks.onPop &&
|
|
762
|
+
this.callbacks.onPop(value, this.clientId, agentName);
|
|
763
|
+
this.callbacks.onChange &&
|
|
764
|
+
this.callbacks.onChange(this._array, this.clientId, agentName);
|
|
765
|
+
return Promise.resolve(value);
|
|
766
|
+
};
|
|
746
767
|
/**
|
|
747
768
|
* Dispose of the history for a given agent.
|
|
748
769
|
* @param agentName - The agent name or null.
|
|
@@ -825,6 +846,35 @@ var HistoryUtils = /** @class */ (function () {
|
|
|
825
846
|
}
|
|
826
847
|
});
|
|
827
848
|
}); };
|
|
849
|
+
/**
|
|
850
|
+
* Pop the last message from the history.
|
|
851
|
+
* @param value - The model message to push.
|
|
852
|
+
* @param clientId - The client ID.
|
|
853
|
+
* @param agentName - The agent name.
|
|
854
|
+
* @returns A promise that resolves when the message is pushed.
|
|
855
|
+
*/
|
|
856
|
+
this.pop = function (clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
857
|
+
var isInitial, history;
|
|
858
|
+
return __generator(this, function (_b) {
|
|
859
|
+
switch (_b.label) {
|
|
860
|
+
case 0:
|
|
861
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
862
|
+
swarm$1.loggerService.log(METHOD_NAME_POP, {
|
|
863
|
+
clientId: clientId,
|
|
864
|
+
agentName: agentName,
|
|
865
|
+
});
|
|
866
|
+
isInitial = this.getHistory.has(clientId);
|
|
867
|
+
return [4 /*yield*/, this.getHistory(clientId)];
|
|
868
|
+
case 1:
|
|
869
|
+
history = _b.sent();
|
|
870
|
+
return [4 /*yield*/, history.waitForInit(agentName, isInitial)];
|
|
871
|
+
case 2:
|
|
872
|
+
_b.sent();
|
|
873
|
+
return [4 /*yield*/, history.pop(agentName)];
|
|
874
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
875
|
+
}
|
|
876
|
+
});
|
|
877
|
+
}); };
|
|
828
878
|
/**
|
|
829
879
|
* Dispose of the history for a given client and agent.
|
|
830
880
|
* @param clientId - The client ID.
|
|
@@ -1438,7 +1488,15 @@ var Logger = LoggerAdapter;
|
|
|
1438
1488
|
/**
|
|
1439
1489
|
* @description `ask for agent function` in `llama3.1:8b` to troubleshoot (need CC_OLLAMA_EMIT_TOOL_PROTOCOL to be turned off)
|
|
1440
1490
|
*/
|
|
1441
|
-
var
|
|
1491
|
+
var CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT = "Start the conversation";
|
|
1492
|
+
/**
|
|
1493
|
+
* @description fix for invalid tool calls on IlyaGusev/saiga_yandexgpt_8b_gguf (LMStudio, appear time to time)
|
|
1494
|
+
*/
|
|
1495
|
+
var CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT = "I see your previous message is malformed. Think again and resend it correct";
|
|
1496
|
+
/**
|
|
1497
|
+
* @description custom function to fix the model
|
|
1498
|
+
*/
|
|
1499
|
+
var CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION = function () { return Promise.resolve(); };
|
|
1442
1500
|
/**
|
|
1443
1501
|
* @description When the model output is empty just say hello to the customer
|
|
1444
1502
|
*/
|
|
@@ -1493,12 +1551,14 @@ var CC_LOGGER_ENABLE_INFO = false;
|
|
|
1493
1551
|
var CC_LOGGER_ENABLE_DEBUG = false;
|
|
1494
1552
|
var CC_LOGGER_ENABLE_LOG = true;
|
|
1495
1553
|
var CC_LOGGER_ENABLE_CONSOLE = false;
|
|
1554
|
+
var CC_RESQUE_STRATEGY;
|
|
1496
1555
|
var CC_NAME_TO_TITLE = nameToTitle;
|
|
1497
1556
|
var CC_FN_PLANTUML = function () { return Promise.resolve(""); };
|
|
1498
1557
|
var CC_PROCESS_UUID = randomString();
|
|
1499
1558
|
var CC_BANHAMMER_PLACEHOLDER = "You have been banned! To continue conversation, please contact the administrator.";
|
|
1500
1559
|
var GLOBAL_CONFIG = {
|
|
1501
|
-
|
|
1560
|
+
CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT: CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
|
|
1561
|
+
CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT: CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
|
|
1502
1562
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: CC_EMPTY_OUTPUT_PLACEHOLDERS,
|
|
1503
1563
|
CC_KEEP_MESSAGES: CC_KEEP_MESSAGES,
|
|
1504
1564
|
CC_GET_AGENT_HISTORY_ADAPTER: CC_GET_AGENT_HISTORY_ADAPTER,
|
|
@@ -1520,11 +1580,14 @@ var GLOBAL_CONFIG = {
|
|
|
1520
1580
|
CC_LOGGER_ENABLE_DEBUG: CC_LOGGER_ENABLE_DEBUG,
|
|
1521
1581
|
CC_LOGGER_ENABLE_LOG: CC_LOGGER_ENABLE_LOG,
|
|
1522
1582
|
CC_LOGGER_ENABLE_CONSOLE: CC_LOGGER_ENABLE_CONSOLE,
|
|
1583
|
+
CC_RESQUE_STRATEGY: CC_RESQUE_STRATEGY,
|
|
1523
1584
|
CC_NAME_TO_TITLE: CC_NAME_TO_TITLE,
|
|
1524
1585
|
CC_FN_PLANTUML: CC_FN_PLANTUML,
|
|
1525
1586
|
CC_PROCESS_UUID: CC_PROCESS_UUID,
|
|
1526
1587
|
CC_BANHAMMER_PLACEHOLDER: CC_BANHAMMER_PLACEHOLDER,
|
|
1588
|
+
CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION: CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION,
|
|
1527
1589
|
};
|
|
1590
|
+
GLOBAL_CONFIG.CC_RESQUE_STRATEGY = "recomplete";
|
|
1528
1591
|
var setConfig = function (config) {
|
|
1529
1592
|
Object.assign(GLOBAL_CONFIG, config);
|
|
1530
1593
|
};
|
|
@@ -2163,45 +2226,67 @@ var ClientAgent = /** @class */ (function () {
|
|
|
2163
2226
|
* @returns {Promise<string>}
|
|
2164
2227
|
* @private
|
|
2165
2228
|
*/
|
|
2166
|
-
ClientAgent.prototype._resurrectModel = function (
|
|
2167
|
-
return __awaiter(this,
|
|
2229
|
+
ClientAgent.prototype._resurrectModel = function (mode_1) {
|
|
2230
|
+
return __awaiter(this, arguments, void 0, function (mode, reason) {
|
|
2168
2231
|
var rawMessage, message, result, validation, content;
|
|
2232
|
+
if (reason === void 0) { reason = "unknown"; }
|
|
2169
2233
|
return __generator(this, function (_a) {
|
|
2170
2234
|
switch (_a.label) {
|
|
2171
2235
|
case 0:
|
|
2172
2236
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2173
2237
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel"));
|
|
2238
|
+
console.warn("agent-swarm model ressurect for agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " strategy=").concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " reason=").concat(reason));
|
|
2174
2239
|
this.params.onResurrect &&
|
|
2175
2240
|
this.params.onResurrect(this.params.clientId, this.params.agentName, mode, reason);
|
|
2241
|
+
if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "recomplete")) return [3 /*break*/, 2];
|
|
2242
|
+
return [4 /*yield*/, this.params.history.push({
|
|
2243
|
+
role: "user",
|
|
2244
|
+
mode: "tool",
|
|
2245
|
+
agentName: this.params.agentName,
|
|
2246
|
+
content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT,
|
|
2247
|
+
})];
|
|
2248
|
+
case 1:
|
|
2249
|
+
_a.sent();
|
|
2250
|
+
return [3 /*break*/, 8];
|
|
2251
|
+
case 2:
|
|
2252
|
+
if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "flush")) return [3 /*break*/, 5];
|
|
2176
2253
|
return [4 /*yield*/, this.params.history.push({
|
|
2177
2254
|
role: "resque",
|
|
2178
2255
|
mode: "tool",
|
|
2179
2256
|
agentName: this.params.agentName,
|
|
2180
2257
|
content: reason || "Unknown error",
|
|
2181
2258
|
})];
|
|
2182
|
-
case
|
|
2259
|
+
case 3:
|
|
2183
2260
|
_a.sent();
|
|
2184
2261
|
return [4 /*yield*/, this.params.history.push({
|
|
2185
2262
|
role: "user",
|
|
2186
2263
|
mode: "tool",
|
|
2187
2264
|
agentName: this.params.agentName,
|
|
2188
|
-
content: GLOBAL_CONFIG.
|
|
2265
|
+
content: GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT,
|
|
2189
2266
|
})];
|
|
2190
|
-
case
|
|
2267
|
+
case 4:
|
|
2191
2268
|
_a.sent();
|
|
2192
|
-
return [
|
|
2193
|
-
case
|
|
2269
|
+
return [3 /*break*/, 8];
|
|
2270
|
+
case 5:
|
|
2271
|
+
if (!(GLOBAL_CONFIG.CC_RESQUE_STRATEGY === "custom")) return [3 /*break*/, 7];
|
|
2272
|
+
return [4 /*yield*/, GLOBAL_CONFIG.CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION(this.params.clientId, this.params.agentName)];
|
|
2273
|
+
case 6:
|
|
2274
|
+
_a.sent();
|
|
2275
|
+
return [3 /*break*/, 8];
|
|
2276
|
+
case 7: throw new Error("agent-swarm _resurrectModel invalid strategy value=".concat(GLOBAL_CONFIG.CC_RESQUE_STRATEGY, " agentName=").concat(this.params.agentName, " clientId=").concat(this.params.clientId));
|
|
2277
|
+
case 8: return [4 /*yield*/, this.getCompletion(mode)];
|
|
2278
|
+
case 9:
|
|
2194
2279
|
rawMessage = _a.sent();
|
|
2195
2280
|
return [4 /*yield*/, this.params.map(rawMessage, this.params.clientId, this.params.agentName)];
|
|
2196
|
-
case
|
|
2281
|
+
case 10:
|
|
2197
2282
|
message = _a.sent();
|
|
2198
2283
|
return [4 /*yield*/, this.params.transform(message.content, this.params.clientId, this.params.agentName)];
|
|
2199
|
-
case
|
|
2284
|
+
case 11:
|
|
2200
2285
|
result = _a.sent();
|
|
2201
2286
|
validation = null;
|
|
2202
2287
|
return [4 /*yield*/, this.params.validate(result)];
|
|
2203
|
-
case
|
|
2204
|
-
if (!(validation = _a.sent())) return [3 /*break*/,
|
|
2288
|
+
case 12:
|
|
2289
|
+
if (!(validation = _a.sent())) return [3 /*break*/, 14];
|
|
2205
2290
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2206
2291
|
this.params.logger.debug("ClientAgent agentName=".concat(this.params.agentName, " clientId=").concat(this.params.clientId, " _resurrectModel validation error: ").concat(validation));
|
|
2207
2292
|
content = getPlaceholder();
|
|
@@ -2211,11 +2296,11 @@ var ClientAgent = /** @class */ (function () {
|
|
|
2211
2296
|
mode: "tool",
|
|
2212
2297
|
content: content,
|
|
2213
2298
|
})];
|
|
2214
|
-
case
|
|
2299
|
+
case 13:
|
|
2215
2300
|
_a.sent();
|
|
2216
2301
|
return [2 /*return*/, content];
|
|
2217
|
-
case
|
|
2218
|
-
case
|
|
2302
|
+
case 14: return [4 /*yield*/, this.params.history.push(__assign(__assign({}, message), { agentName: this.params.agentName }))];
|
|
2303
|
+
case 15:
|
|
2219
2304
|
_a.sent();
|
|
2220
2305
|
return [2 /*return*/, result];
|
|
2221
2306
|
}
|
|
@@ -2853,6 +2938,40 @@ var ClientHistory = /** @class */ (function () {
|
|
|
2853
2938
|
});
|
|
2854
2939
|
});
|
|
2855
2940
|
};
|
|
2941
|
+
/**
|
|
2942
|
+
* Pushes a message to the history.
|
|
2943
|
+
* @returns {Promise<IModelMessage | null>}
|
|
2944
|
+
*/
|
|
2945
|
+
ClientHistory.prototype.pop = function () {
|
|
2946
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2947
|
+
var value;
|
|
2948
|
+
return __generator(this, function (_a) {
|
|
2949
|
+
switch (_a.label) {
|
|
2950
|
+
case 0:
|
|
2951
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
|
|
2952
|
+
this.params.logger.debug("ClientHistory agentName=".concat(this.params.agentName, " pop"));
|
|
2953
|
+
return [4 /*yield*/, this.params.items.pop(this.params.clientId, this.params.agentName)];
|
|
2954
|
+
case 1:
|
|
2955
|
+
value = _a.sent();
|
|
2956
|
+
return [4 /*yield*/, this.params.bus.emit(this.params.clientId, {
|
|
2957
|
+
type: "pop",
|
|
2958
|
+
source: "history-bus",
|
|
2959
|
+
input: {},
|
|
2960
|
+
output: {
|
|
2961
|
+
value: value
|
|
2962
|
+
},
|
|
2963
|
+
context: {
|
|
2964
|
+
agentName: this.params.agentName,
|
|
2965
|
+
},
|
|
2966
|
+
clientId: this.params.clientId,
|
|
2967
|
+
})];
|
|
2968
|
+
case 2:
|
|
2969
|
+
_a.sent();
|
|
2970
|
+
return [2 /*return*/, value];
|
|
2971
|
+
}
|
|
2972
|
+
});
|
|
2973
|
+
});
|
|
2974
|
+
};
|
|
2856
2975
|
/**
|
|
2857
2976
|
* Converts the history to an array of raw messages.
|
|
2858
2977
|
* @returns {Promise<IModelMessage[]>} - The array of raw messages.
|
|
@@ -3125,6 +3244,21 @@ var HistoryConnectionService = /** @class */ (function () {
|
|
|
3125
3244
|
}
|
|
3126
3245
|
});
|
|
3127
3246
|
}); };
|
|
3247
|
+
/**
|
|
3248
|
+
* Pop a message from the history.
|
|
3249
|
+
* @returns {Promise<IModelMessage | null>} A promise that resolves when the message is popped.
|
|
3250
|
+
*/
|
|
3251
|
+
this.pop = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
3252
|
+
return __generator(this, function (_a) {
|
|
3253
|
+
switch (_a.label) {
|
|
3254
|
+
case 0:
|
|
3255
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
3256
|
+
this.loggerService.info("historyConnectionService pop");
|
|
3257
|
+
return [4 /*yield*/, this.getHistory(this.methodContextService.context.clientId, this.methodContextService.context.agentName).pop()];
|
|
3258
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
3259
|
+
}
|
|
3260
|
+
});
|
|
3261
|
+
}); };
|
|
3128
3262
|
/**
|
|
3129
3263
|
* Converts the history to an array for the agent.
|
|
3130
3264
|
* @param {string} prompt - The prompt.
|
|
@@ -5551,6 +5685,43 @@ var HistoryPublicService = /** @class */ (function () {
|
|
|
5551
5685
|
}
|
|
5552
5686
|
});
|
|
5553
5687
|
}); };
|
|
5688
|
+
/**
|
|
5689
|
+
* Pushes a message to the history.
|
|
5690
|
+
* @param {string} clientId - The client ID.
|
|
5691
|
+
* @param {AgentName} agentName - The agent name.
|
|
5692
|
+
* @returns {Promise<IModelMessage | null>} A promise that resolves when the operation is complete.
|
|
5693
|
+
*/
|
|
5694
|
+
this.pop = function (methodName, clientId, agentName) { return __awaiter(_this, void 0, void 0, function () {
|
|
5695
|
+
var _this = this;
|
|
5696
|
+
return __generator(this, function (_a) {
|
|
5697
|
+
switch (_a.label) {
|
|
5698
|
+
case 0:
|
|
5699
|
+
GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
|
|
5700
|
+
this.loggerService.info("historyPublicService pop", {
|
|
5701
|
+
methodName: methodName,
|
|
5702
|
+
clientId: clientId,
|
|
5703
|
+
agentName: agentName,
|
|
5704
|
+
});
|
|
5705
|
+
return [4 /*yield*/, MethodContextService.runInContext(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
5706
|
+
return __generator(this, function (_a) {
|
|
5707
|
+
switch (_a.label) {
|
|
5708
|
+
case 0: return [4 /*yield*/, this.historyConnectionService.pop()];
|
|
5709
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5710
|
+
}
|
|
5711
|
+
});
|
|
5712
|
+
}); }, {
|
|
5713
|
+
methodName: methodName,
|
|
5714
|
+
clientId: clientId,
|
|
5715
|
+
agentName: agentName,
|
|
5716
|
+
policyName: "",
|
|
5717
|
+
swarmName: "",
|
|
5718
|
+
storageName: "",
|
|
5719
|
+
stateName: "",
|
|
5720
|
+
})];
|
|
5721
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
5722
|
+
}
|
|
5723
|
+
});
|
|
5724
|
+
}); };
|
|
5554
5725
|
/**
|
|
5555
5726
|
* Converts history to an array for a specific agent.
|
|
5556
5727
|
* @param {string} prompt - The prompt.
|
|
@@ -15554,6 +15725,7 @@ var SchemaUtils = /** @class */ (function () {
|
|
|
15554
15725
|
* @returns {string} The serialized string.
|
|
15555
15726
|
*/
|
|
15556
15727
|
this.serialize = function (data, map) {
|
|
15728
|
+
if (map === void 0) { map = {}; }
|
|
15557
15729
|
GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
|
|
15558
15730
|
swarm$1.loggerService.log(METHOD_NAME_SERIALIZE, {
|
|
15559
15731
|
data: data,
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1076,6 +1076,13 @@ interface IHistoryInstanceCallbacks {
|
|
|
1076
1076
|
* @param agentName - The agent name.
|
|
1077
1077
|
*/
|
|
1078
1078
|
onPush: (data: IModelMessage, clientId: string, agentName: AgentName) => void;
|
|
1079
|
+
/**
|
|
1080
|
+
* Callback for when the history pop the last message
|
|
1081
|
+
* @param data - The array of model messages.
|
|
1082
|
+
* @param clientId - The client ID.
|
|
1083
|
+
* @param agentName - The agent name.
|
|
1084
|
+
*/
|
|
1085
|
+
onPop: (data: IModelMessage | null, clientId: string, agentName: AgentName) => void;
|
|
1079
1086
|
/**
|
|
1080
1087
|
* Callback for when the history is read. Will be called for each message
|
|
1081
1088
|
* @param message - The model message.
|
|
@@ -1130,6 +1137,13 @@ interface IHistoryAdapter {
|
|
|
1130
1137
|
* @returns A promise that resolves when the message is pushed.
|
|
1131
1138
|
*/
|
|
1132
1139
|
push: (value: IModelMessage, clientId: string, agentName: AgentName) => Promise<void>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Pop the last message from a history
|
|
1142
|
+
* @param clientId - The client ID.
|
|
1143
|
+
* @param agentName - The agent name.
|
|
1144
|
+
* @returns The last message or null
|
|
1145
|
+
*/
|
|
1146
|
+
pop: (clientId: string, agentName: AgentName) => Promise<IModelMessage | null>;
|
|
1133
1147
|
/**
|
|
1134
1148
|
* Dispose of the history for a given client and agent.
|
|
1135
1149
|
* @param clientId - The client ID.
|
|
@@ -1177,6 +1191,13 @@ interface IHistoryInstance {
|
|
|
1177
1191
|
* @returns A promise that resolves when the message is pushed.
|
|
1178
1192
|
*/
|
|
1179
1193
|
push(value: IModelMessage, agentName: AgentName): Promise<void>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Pop the last message from a history
|
|
1196
|
+
* @param value - The model message to push.
|
|
1197
|
+
* @param agentName - The agent name.
|
|
1198
|
+
* @returns A promise that resolves the last message or null
|
|
1199
|
+
*/
|
|
1200
|
+
pop(agentName: AgentName): Promise<IModelMessage | null>;
|
|
1180
1201
|
/**
|
|
1181
1202
|
* Dispose of the history for a given agent.
|
|
1182
1203
|
* @param agentName - The agent name or null.
|
|
@@ -1225,6 +1246,12 @@ declare class HistoryInstance implements IHistoryInstance {
|
|
|
1225
1246
|
* @returns A promise that resolves when the message is pushed.
|
|
1226
1247
|
*/
|
|
1227
1248
|
push(value: IModelMessage, agentName: AgentName): Promise<void>;
|
|
1249
|
+
/**
|
|
1250
|
+
* Pop the last message from a history
|
|
1251
|
+
* @param agentName - The agent name.
|
|
1252
|
+
* @returns A promise that resolves when the message is pushed.
|
|
1253
|
+
*/
|
|
1254
|
+
pop(agentName: AgentName): Promise<IModelMessage>;
|
|
1228
1255
|
/**
|
|
1229
1256
|
* Dispose of the history for a given agent.
|
|
1230
1257
|
* @param agentName - The agent name or null.
|
|
@@ -1264,6 +1291,14 @@ declare class HistoryUtils implements IHistoryAdapter, IHistoryControl {
|
|
|
1264
1291
|
* @returns A promise that resolves when the message is pushed.
|
|
1265
1292
|
*/
|
|
1266
1293
|
push: (value: IModelMessage, clientId: string, agentName: AgentName) => Promise<void>;
|
|
1294
|
+
/**
|
|
1295
|
+
* Pop the last message from the history.
|
|
1296
|
+
* @param value - The model message to push.
|
|
1297
|
+
* @param clientId - The client ID.
|
|
1298
|
+
* @param agentName - The agent name.
|
|
1299
|
+
* @returns A promise that resolves when the message is pushed.
|
|
1300
|
+
*/
|
|
1301
|
+
pop: (clientId: string, agentName: AgentName) => Promise<IModelMessage>;
|
|
1267
1302
|
/**
|
|
1268
1303
|
* Dispose of the history for a given client and agent.
|
|
1269
1304
|
* @param clientId - The client ID.
|
|
@@ -1291,6 +1326,11 @@ interface IHistory {
|
|
|
1291
1326
|
* @returns {Promise<void>}
|
|
1292
1327
|
*/
|
|
1293
1328
|
push(message: IModelMessage): Promise<void>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Pop the last message from a history
|
|
1331
|
+
* @returns {Promise<IModelMessage | null>}
|
|
1332
|
+
*/
|
|
1333
|
+
pop(): Promise<IModelMessage | null>;
|
|
1294
1334
|
/**
|
|
1295
1335
|
* Converts the history to an array of messages for a specific agent.
|
|
1296
1336
|
* @param {string} prompt - The prompt to filter messages for the agent.
|
|
@@ -1401,11 +1441,12 @@ interface ICompletionSchema {
|
|
|
1401
1441
|
*/
|
|
1402
1442
|
type CompletionName = string;
|
|
1403
1443
|
|
|
1444
|
+
type ToolValue = string | number | boolean | null;
|
|
1404
1445
|
/**
|
|
1405
1446
|
* Interface representing lifecycle callbacks of a tool
|
|
1406
1447
|
* @template T - The type of the parameters for the tool.
|
|
1407
1448
|
*/
|
|
1408
|
-
interface IAgentToolCallbacks<T = Record<string,
|
|
1449
|
+
interface IAgentToolCallbacks<T = Record<string, ToolValue>> {
|
|
1409
1450
|
/**
|
|
1410
1451
|
* Callback triggered before the tool is called.
|
|
1411
1452
|
* @param toolId - The `tool_call_id` for openai history
|
|
@@ -1445,7 +1486,7 @@ interface IAgentToolCallbacks<T = Record<string, unknown>> {
|
|
|
1445
1486
|
* Interface representing a tool used by an agent.
|
|
1446
1487
|
* @template T - The type of the parameters for the tool.
|
|
1447
1488
|
*/
|
|
1448
|
-
interface IAgentTool<T = Record<string,
|
|
1489
|
+
interface IAgentTool<T = Record<string, ToolValue>> extends ITool {
|
|
1449
1490
|
/** The description for documentation */
|
|
1450
1491
|
docNote?: string;
|
|
1451
1492
|
/** The name of the tool. */
|
|
@@ -1972,6 +2013,11 @@ declare class ClientHistory implements IHistory {
|
|
|
1972
2013
|
* @returns {Promise<void>}
|
|
1973
2014
|
*/
|
|
1974
2015
|
push(message: IModelMessage): Promise<void>;
|
|
2016
|
+
/**
|
|
2017
|
+
* Pushes a message to the history.
|
|
2018
|
+
* @returns {Promise<IModelMessage | null>}
|
|
2019
|
+
*/
|
|
2020
|
+
pop(): Promise<IModelMessage | null>;
|
|
1975
2021
|
/**
|
|
1976
2022
|
* Converts the history to an array of raw messages.
|
|
1977
2023
|
* @returns {Promise<IModelMessage[]>} - The array of raw messages.
|
|
@@ -2013,6 +2059,11 @@ declare class HistoryConnectionService implements IHistory {
|
|
|
2013
2059
|
* @returns {Promise<void>} A promise that resolves when the message is pushed.
|
|
2014
2060
|
*/
|
|
2015
2061
|
push: (message: IModelMessage) => Promise<void>;
|
|
2062
|
+
/**
|
|
2063
|
+
* Pop a message from the history.
|
|
2064
|
+
* @returns {Promise<IModelMessage | null>} A promise that resolves when the message is popped.
|
|
2065
|
+
*/
|
|
2066
|
+
pop: () => Promise<IModelMessage>;
|
|
2016
2067
|
/**
|
|
2017
2068
|
* Converts the history to an array for the agent.
|
|
2018
2069
|
* @param {string} prompt - The prompt.
|
|
@@ -2542,6 +2593,13 @@ declare class HistoryPublicService implements THistoryConnectionService {
|
|
|
2542
2593
|
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
2543
2594
|
*/
|
|
2544
2595
|
push: (message: IModelMessage, methodName: string, clientId: string, agentName: AgentName) => Promise<void>;
|
|
2596
|
+
/**
|
|
2597
|
+
* Pushes a message to the history.
|
|
2598
|
+
* @param {string} clientId - The client ID.
|
|
2599
|
+
* @param {AgentName} agentName - The agent name.
|
|
2600
|
+
* @returns {Promise<IModelMessage | null>} A promise that resolves when the operation is complete.
|
|
2601
|
+
*/
|
|
2602
|
+
pop: (methodName: string, clientId: string, agentName: AgentName) => Promise<IModelMessage>;
|
|
2545
2603
|
/**
|
|
2546
2604
|
* Converts history to an array for a specific agent.
|
|
2547
2605
|
* @param {string} prompt - The prompt.
|
|
@@ -4397,7 +4455,7 @@ declare const addSwarm: (swarmSchema: ISwarmSchema) => string;
|
|
|
4397
4455
|
* @param {IAgentTool} toolSchema - The schema of the tool to be added.
|
|
4398
4456
|
* @returns {string} The name of the tool that was added.
|
|
4399
4457
|
*/
|
|
4400
|
-
declare const addTool: (toolSchema: IAgentTool<Record<string,
|
|
4458
|
+
declare const addTool: (toolSchema: IAgentTool<Record<string, string | number | boolean>>) => string;
|
|
4401
4459
|
|
|
4402
4460
|
/**
|
|
4403
4461
|
* Adds a new state to the state registry. The swarm takes only those states which was registered
|
|
@@ -5277,7 +5335,8 @@ declare const LoggerAdapter: LoggerUtils;
|
|
|
5277
5335
|
declare const Logger: ILoggerControl;
|
|
5278
5336
|
|
|
5279
5337
|
declare const GLOBAL_CONFIG: {
|
|
5280
|
-
|
|
5338
|
+
CC_TOOL_CALL_EXCEPTION_FLUSH_PROMPT: string;
|
|
5339
|
+
CC_TOOL_CALL_EXCEPTION_RECOMPLETE_PROMPT: string;
|
|
5281
5340
|
CC_EMPTY_OUTPUT_PLACEHOLDERS: string[];
|
|
5282
5341
|
CC_KEEP_MESSAGES: number;
|
|
5283
5342
|
CC_GET_AGENT_HISTORY_ADAPTER: (clientId: string, agentName: AgentName) => IHistoryAdapter;
|
|
@@ -5299,10 +5358,12 @@ declare const GLOBAL_CONFIG: {
|
|
|
5299
5358
|
CC_LOGGER_ENABLE_DEBUG: boolean;
|
|
5300
5359
|
CC_LOGGER_ENABLE_LOG: boolean;
|
|
5301
5360
|
CC_LOGGER_ENABLE_CONSOLE: boolean;
|
|
5361
|
+
CC_RESQUE_STRATEGY: "flush" | "recomplete" | "custom";
|
|
5302
5362
|
CC_NAME_TO_TITLE: (name: string) => string;
|
|
5303
5363
|
CC_FN_PLANTUML: (uml: string) => Promise<string>;
|
|
5304
5364
|
CC_PROCESS_UUID: string;
|
|
5305
5365
|
CC_BANHAMMER_PLACEHOLDER: string;
|
|
5366
|
+
CC_TOOL_CALL_EXCEPTION_CUSTON_FUNCTION: (clientId: string, agentName: AgentName) => Promise<void>;
|
|
5306
5367
|
};
|
|
5307
5368
|
declare const setConfig: (config: Partial<typeof GLOBAL_CONFIG>) => void;
|
|
5308
5369
|
|
|
@@ -5640,9 +5701,9 @@ declare class SchemaUtils {
|
|
|
5640
5701
|
* @param {T[] | T} data - The data to serialize.
|
|
5641
5702
|
* @returns {string} The serialized string.
|
|
5642
5703
|
*/
|
|
5643
|
-
serialize: <T extends object = any>(data: T[] | T, map
|
|
5644
|
-
mapKey
|
|
5645
|
-
mapValue
|
|
5704
|
+
serialize: <T extends object = any>(data: T[] | T, map?: {
|
|
5705
|
+
mapKey?: typeof GLOBAL_CONFIG.CC_NAME_TO_TITLE;
|
|
5706
|
+
mapValue?: (key: string, value: string) => string;
|
|
5646
5707
|
}) => string;
|
|
5647
5708
|
}
|
|
5648
5709
|
/**
|