@iqai/adk 0.0.5 → 0.0.7
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/CHANGELOG.md +2 -2
- package/README.md +177 -0
- package/dist/index.d.mts +76 -144
- package/dist/index.d.ts +76 -144
- package/dist/index.js +706 -552
- package/dist/index.mjs +516 -362
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14;var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29;var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -19,11 +19,48 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
};
|
|
20
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
21
|
|
|
22
|
+
// src/helpers/logger.ts
|
|
23
|
+
function isDebugEnabled() {
|
|
24
|
+
return process.env.NODE_ENV === "development" || process.env.DEBUG === "true";
|
|
25
|
+
}
|
|
26
|
+
var Logger;
|
|
27
|
+
var init_logger = __esm({
|
|
28
|
+
"src/helpers/logger.ts"() {
|
|
29
|
+
Logger = (_class = class {
|
|
30
|
+
|
|
31
|
+
__init2() {this.isDebugEnabled = isDebugEnabled()}
|
|
32
|
+
constructor({ name }) {;_class.prototype.__init2.call(this);
|
|
33
|
+
this.name = name;
|
|
34
|
+
}
|
|
35
|
+
debug(message, ...args) {
|
|
36
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
37
|
+
if (this.isDebugEnabled) {
|
|
38
|
+
console.log(`[${time}] \u{1F41B} [DEBUG] \u2728 [${this.name}] ${message}`, ...args);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
info(message, ...args) {
|
|
42
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
43
|
+
console.info(`[${time}] \u2139\uFE0F [INFO] \u2728 [${this.name}] ${message}`, ...args);
|
|
44
|
+
}
|
|
45
|
+
warn(message, ...args) {
|
|
46
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
47
|
+
console.warn(`[${time}] \u{1F6A7} [WARN] \u2728 [${this.name}] ${message}`, ...args);
|
|
48
|
+
}
|
|
49
|
+
error(message, ...args) {
|
|
50
|
+
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
51
|
+
console.error(`[${time}] \u274C [ERROR] \u2728 [${this.name}] ${message}`, ...args);
|
|
52
|
+
}
|
|
53
|
+
}, _class);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
22
57
|
// src/tools/base/base-tool.ts
|
|
23
|
-
var BaseTool;
|
|
58
|
+
var logger2, BaseTool;
|
|
24
59
|
var init_base_tool = __esm({
|
|
25
60
|
"src/tools/base/base-tool.ts"() {
|
|
26
|
-
|
|
61
|
+
init_logger();
|
|
62
|
+
logger2 = new Logger({ name: "BaseTool" });
|
|
63
|
+
BaseTool = exports.BaseTool = (_class2 = class {
|
|
27
64
|
/**
|
|
28
65
|
* Name of the tool
|
|
29
66
|
*/
|
|
@@ -47,15 +84,15 @@ var init_base_tool = __esm({
|
|
|
47
84
|
/**
|
|
48
85
|
* Base delay for retry in ms (will be used with exponential backoff)
|
|
49
86
|
*/
|
|
50
|
-
|
|
87
|
+
__init3() {this.baseRetryDelay = 1e3}
|
|
51
88
|
/**
|
|
52
89
|
* Maximum delay for retry in ms
|
|
53
90
|
*/
|
|
54
|
-
|
|
91
|
+
__init4() {this.maxRetryDelay = 1e4}
|
|
55
92
|
/**
|
|
56
93
|
* Constructor for BaseTool
|
|
57
94
|
*/
|
|
58
|
-
constructor(config) {;
|
|
95
|
+
constructor(config) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
|
|
59
96
|
this.name = config.name;
|
|
60
97
|
this.description = config.description;
|
|
61
98
|
this.isLongRunning = config.isLongRunning || false;
|
|
@@ -112,11 +149,9 @@ var init_base_tool = __esm({
|
|
|
112
149
|
while (attempts <= (this.shouldRetryOnFailure ? this.maxRetryAttempts : 0)) {
|
|
113
150
|
try {
|
|
114
151
|
if (attempts > 0) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
);
|
|
119
|
-
}
|
|
152
|
+
logger2.debug(
|
|
153
|
+
`Retrying tool ${this.name} (attempt ${attempts} of ${this.maxRetryAttempts})...`
|
|
154
|
+
);
|
|
120
155
|
const delay = Math.min(
|
|
121
156
|
this.baseRetryDelay * 2 ** (attempts - 1) + Math.random() * 1e3,
|
|
122
157
|
this.maxRetryDelay
|
|
@@ -137,7 +172,7 @@ var init_base_tool = __esm({
|
|
|
137
172
|
tool: this.name
|
|
138
173
|
};
|
|
139
174
|
}
|
|
140
|
-
},
|
|
175
|
+
}, _class2);
|
|
141
176
|
}
|
|
142
177
|
});
|
|
143
178
|
|
|
@@ -263,9 +298,9 @@ var init_function_tool = __esm({
|
|
|
263
298
|
"src/tools/function/function-tool.ts"() {
|
|
264
299
|
init_base_tool();
|
|
265
300
|
init_function_utils();
|
|
266
|
-
FunctionTool = exports.FunctionTool = (
|
|
301
|
+
FunctionTool = exports.FunctionTool = (_class3 = class extends BaseTool {
|
|
267
302
|
|
|
268
|
-
|
|
303
|
+
__init5() {this.mandatoryArgs = []}
|
|
269
304
|
/**
|
|
270
305
|
* Creates a new FunctionTool wrapping the provided function.
|
|
271
306
|
*
|
|
@@ -281,7 +316,7 @@ var init_function_tool = __esm({
|
|
|
281
316
|
isLongRunning: _optionalChain([options, 'optionalAccess', _8 => _8.isLongRunning]) || false,
|
|
282
317
|
shouldRetryOnFailure: _optionalChain([options, 'optionalAccess', _9 => _9.shouldRetryOnFailure]) || false,
|
|
283
318
|
maxRetryAttempts: _optionalChain([options, 'optionalAccess', _10 => _10.maxRetryAttempts]) || 3
|
|
284
|
-
});
|
|
319
|
+
});_class3.prototype.__init5.call(this);;
|
|
285
320
|
this.func = func;
|
|
286
321
|
this.mandatoryArgs = this.getMandatoryArgs(func);
|
|
287
322
|
}
|
|
@@ -357,7 +392,7 @@ You could retry calling this tool, but it is IMPORTANT for you to provide all th
|
|
|
357
392
|
getMissingMandatoryArgs(args) {
|
|
358
393
|
return this.mandatoryArgs.filter((arg) => !(arg in args));
|
|
359
394
|
}
|
|
360
|
-
},
|
|
395
|
+
}, _class3);
|
|
361
396
|
}
|
|
362
397
|
});
|
|
363
398
|
|
|
@@ -459,8 +494,13 @@ var BaseAgent = class {
|
|
|
459
494
|
}
|
|
460
495
|
};
|
|
461
496
|
|
|
497
|
+
// src/agents/llm-agent.ts
|
|
498
|
+
init_logger();
|
|
499
|
+
|
|
462
500
|
// src/models/llm-registry.ts
|
|
463
|
-
|
|
501
|
+
init_logger();
|
|
502
|
+
var logger = new Logger({ name: "LLMRegistry" });
|
|
503
|
+
var LLMRegistry = (_class4 = class _LLMRegistry {
|
|
464
504
|
/**
|
|
465
505
|
* Map of model name regex to LLM class
|
|
466
506
|
*/
|
|
@@ -516,14 +556,12 @@ var LLMRegistry = (_class3 = class _LLMRegistry {
|
|
|
516
556
|
* Logs all registered models for debugging
|
|
517
557
|
*/
|
|
518
558
|
static logRegisteredModels() {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
}
|
|
559
|
+
logger.debug(
|
|
560
|
+
"Registered LLM models:",
|
|
561
|
+
[..._LLMRegistry.llmRegistry.entries()].map(([regex]) => regex.toString())
|
|
562
|
+
);
|
|
525
563
|
}
|
|
526
|
-
},
|
|
564
|
+
}, _class4.__initStatic(), _class4);
|
|
527
565
|
|
|
528
566
|
// src/models/llm-request.ts
|
|
529
567
|
var LLMRequest = class {
|
|
@@ -542,7 +580,7 @@ var LLMRequest = class {
|
|
|
542
580
|
};
|
|
543
581
|
|
|
544
582
|
// src/tools/tool-context.ts
|
|
545
|
-
var ToolContext = (
|
|
583
|
+
var ToolContext = (_class5 = class {
|
|
546
584
|
/**
|
|
547
585
|
* The parent invocation context
|
|
548
586
|
*/
|
|
@@ -558,11 +596,11 @@ var ToolContext = (_class4 = class {
|
|
|
558
596
|
/**
|
|
559
597
|
* Tool name
|
|
560
598
|
*/
|
|
561
|
-
|
|
599
|
+
__init6() {this.toolName = ""}
|
|
562
600
|
/**
|
|
563
601
|
* Tool ID
|
|
564
602
|
*/
|
|
565
|
-
|
|
603
|
+
__init7() {this.toolId = ""}
|
|
566
604
|
/**
|
|
567
605
|
* Variables stored in the context
|
|
568
606
|
*/
|
|
@@ -570,7 +608,7 @@ var ToolContext = (_class4 = class {
|
|
|
570
608
|
/**
|
|
571
609
|
* Constructor for ToolContext
|
|
572
610
|
*/
|
|
573
|
-
constructor(options) {;
|
|
611
|
+
constructor(options) {;_class5.prototype.__init6.call(this);_class5.prototype.__init7.call(this);
|
|
574
612
|
this.invocationContext = options.invocationContext;
|
|
575
613
|
this.auth = options.auth;
|
|
576
614
|
this.parameters = options.parameters || {};
|
|
@@ -636,7 +674,7 @@ var ToolContext = (_class4 = class {
|
|
|
636
674
|
async searchMemory(query, options) {
|
|
637
675
|
return this.invocationContext.searchMemory(query, options);
|
|
638
676
|
}
|
|
639
|
-
},
|
|
677
|
+
}, _class5);
|
|
640
678
|
|
|
641
679
|
// src/agents/run-config.ts
|
|
642
680
|
var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
@@ -688,7 +726,7 @@ var RunConfig = class {
|
|
|
688
726
|
};
|
|
689
727
|
|
|
690
728
|
// src/agents/invocation-context.ts
|
|
691
|
-
var InvocationContext = (
|
|
729
|
+
var InvocationContext = (_class6 = class _InvocationContext {
|
|
692
730
|
/**
|
|
693
731
|
* Unique session ID for the current conversation
|
|
694
732
|
*/
|
|
@@ -728,11 +766,11 @@ var InvocationContext = (_class5 = class _InvocationContext {
|
|
|
728
766
|
/**
|
|
729
767
|
* In-memory storage for node execution results
|
|
730
768
|
*/
|
|
731
|
-
|
|
769
|
+
__init8() {this.memory = /* @__PURE__ */ new Map()}
|
|
732
770
|
/**
|
|
733
771
|
* Constructor for InvocationContext
|
|
734
772
|
*/
|
|
735
|
-
constructor(options = {}) {;
|
|
773
|
+
constructor(options = {}) {;_class6.prototype.__init8.call(this);
|
|
736
774
|
this.sessionId = options.sessionId || this.generateSessionId();
|
|
737
775
|
this.messages = options.messages || [];
|
|
738
776
|
this.config = options.config || new RunConfig();
|
|
@@ -835,10 +873,10 @@ var InvocationContext = (_class5 = class _InvocationContext {
|
|
|
835
873
|
};
|
|
836
874
|
return await this.memoryService.searchMemory(query, searchOptions);
|
|
837
875
|
}
|
|
838
|
-
},
|
|
876
|
+
}, _class6);
|
|
839
877
|
|
|
840
878
|
// src/agents/llm-agent.ts
|
|
841
|
-
var Agent = class extends BaseAgent {
|
|
879
|
+
var Agent = (_class7 = class extends BaseAgent {
|
|
842
880
|
/**
|
|
843
881
|
* The LLM model to use
|
|
844
882
|
*/
|
|
@@ -887,6 +925,7 @@ var Agent = class extends BaseAgent {
|
|
|
887
925
|
* The minimum relevance score for memory augmentation (0-1)
|
|
888
926
|
*/
|
|
889
927
|
|
|
928
|
+
__init9() {this.logger = new Logger({ name: "LlmAgent" })}
|
|
890
929
|
/**
|
|
891
930
|
* Constructor for Agent
|
|
892
931
|
*/
|
|
@@ -894,7 +933,7 @@ var Agent = class extends BaseAgent {
|
|
|
894
933
|
super({
|
|
895
934
|
name: config.name,
|
|
896
935
|
description: config.description
|
|
897
|
-
});
|
|
936
|
+
});_class7.prototype.__init9.call(this);;
|
|
898
937
|
this.model = config.model;
|
|
899
938
|
this.instructions = config.instructions;
|
|
900
939
|
this.tools = config.tools || [];
|
|
@@ -919,9 +958,7 @@ var Agent = class extends BaseAgent {
|
|
|
919
958
|
*/
|
|
920
959
|
async executeTool(toolCall, context) {
|
|
921
960
|
const { name, arguments: argsString } = toolCall.function;
|
|
922
|
-
|
|
923
|
-
console.log(`Executing tool: ${name}`);
|
|
924
|
-
}
|
|
961
|
+
this.logger.debug(`Executing tool: ${name}`);
|
|
925
962
|
const tool = this.findTool(name);
|
|
926
963
|
if (!tool) {
|
|
927
964
|
console.warn(`Tool '${name}' not found`);
|
|
@@ -939,9 +976,7 @@ var Agent = class extends BaseAgent {
|
|
|
939
976
|
toolContext.toolName = name;
|
|
940
977
|
toolContext.toolId = toolCall.id;
|
|
941
978
|
const result = await tool.runAsync(args, toolContext);
|
|
942
|
-
|
|
943
|
-
console.log(`Tool ${name} execution complete`);
|
|
944
|
-
}
|
|
979
|
+
this.logger.debug(`Tool ${name} execution complete`);
|
|
945
980
|
return {
|
|
946
981
|
name,
|
|
947
982
|
result: typeof result === "string" ? result : JSON.stringify(result)
|
|
@@ -1110,10 +1145,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1110
1145
|
let stepCount = 0;
|
|
1111
1146
|
while (stepCount < this.maxToolExecutionSteps) {
|
|
1112
1147
|
stepCount++;
|
|
1113
|
-
|
|
1114
|
-
console.log(`
|
|
1115
|
-
[Agent] Step ${stepCount}: Thinking...`);
|
|
1116
|
-
}
|
|
1148
|
+
this.logger.debug(`Step ${stepCount}: Thinking...`);
|
|
1117
1149
|
const llmRequest = new LLMRequest({
|
|
1118
1150
|
messages: context.messages,
|
|
1119
1151
|
config: {
|
|
@@ -1130,9 +1162,9 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1130
1162
|
throw new Error("No response from LLM");
|
|
1131
1163
|
}
|
|
1132
1164
|
if (currentResponse.tool_calls && currentResponse.tool_calls.length > 0) {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1165
|
+
this.logger.debug(
|
|
1166
|
+
`Tool calls: ${JSON.stringify(currentResponse.tool_calls)}`
|
|
1167
|
+
);
|
|
1136
1168
|
context.addMessage({
|
|
1137
1169
|
role: "assistant",
|
|
1138
1170
|
content: currentResponse.content || "",
|
|
@@ -1151,9 +1183,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1151
1183
|
});
|
|
1152
1184
|
}
|
|
1153
1185
|
} else {
|
|
1154
|
-
|
|
1155
|
-
console.log("[Agent] No tool calls, finishing...");
|
|
1156
|
-
}
|
|
1186
|
+
this.logger.debug("No tool calls, finishing...");
|
|
1157
1187
|
context.addMessage({
|
|
1158
1188
|
role: "assistant",
|
|
1159
1189
|
content: currentResponse.content || ""
|
|
@@ -1191,10 +1221,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1191
1221
|
let stepCount = 0;
|
|
1192
1222
|
let hadToolCalls = false;
|
|
1193
1223
|
while (stepCount < this.maxToolExecutionSteps) {
|
|
1194
|
-
|
|
1195
|
-
console.log(`
|
|
1196
|
-
[Agent] Step ${stepCount + 1}: Thinking...`);
|
|
1197
|
-
}
|
|
1224
|
+
this.logger.debug(`Step ${stepCount}: Thinking...`);
|
|
1198
1225
|
const toolDeclarations = this.tools.map((tool) => tool.getDeclaration()).filter((declaration) => declaration !== null);
|
|
1199
1226
|
const request = {
|
|
1200
1227
|
messages: context.messages,
|
|
@@ -1223,14 +1250,10 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1223
1250
|
function_call: finalResponse.function_call
|
|
1224
1251
|
});
|
|
1225
1252
|
if (!hadToolCalls) {
|
|
1226
|
-
|
|
1227
|
-
console.log("[Agent] No tool calls, finishing...");
|
|
1228
|
-
}
|
|
1253
|
+
this.logger.debug("No tool calls, finishing...");
|
|
1229
1254
|
break;
|
|
1230
1255
|
}
|
|
1231
|
-
|
|
1232
|
-
console.log("[Agent] Executing tools...");
|
|
1233
|
-
}
|
|
1256
|
+
this.logger.debug(`Step ${stepCount + 1}: Executing tools...`);
|
|
1234
1257
|
stepCount++;
|
|
1235
1258
|
if (finalResponse.function_call) {
|
|
1236
1259
|
const toolCall = {
|
|
@@ -1247,11 +1270,9 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1247
1270
|
content: JSON.stringify(result.result)
|
|
1248
1271
|
});
|
|
1249
1272
|
} else if (finalResponse.tool_calls && finalResponse.tool_calls.length > 0) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
);
|
|
1254
|
-
}
|
|
1273
|
+
this.logger.debug(
|
|
1274
|
+
`Step ${stepCount + 1}: Executing ${finalResponse.tool_calls.length} tool(s)...`
|
|
1275
|
+
);
|
|
1255
1276
|
context.messages.pop();
|
|
1256
1277
|
context.addMessage({
|
|
1257
1278
|
role: "assistant",
|
|
@@ -1273,10 +1294,12 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1273
1294
|
}
|
|
1274
1295
|
await this.saveToMemory(context);
|
|
1275
1296
|
}
|
|
1276
|
-
};
|
|
1297
|
+
}, _class7);
|
|
1277
1298
|
|
|
1278
1299
|
// src/agents/sequential-agent.ts
|
|
1279
|
-
|
|
1300
|
+
init_logger();
|
|
1301
|
+
var SequentialAgent = (_class8 = class extends BaseAgent {
|
|
1302
|
+
__init10() {this.logger = new Logger({ name: "SequentialAgent" })}
|
|
1280
1303
|
/**
|
|
1281
1304
|
* Constructor for SequentialAgent
|
|
1282
1305
|
*/
|
|
@@ -1284,7 +1307,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1284
1307
|
super({
|
|
1285
1308
|
name: config.name,
|
|
1286
1309
|
description: config.description
|
|
1287
|
-
});
|
|
1310
|
+
});_class8.prototype.__init10.call(this);;
|
|
1288
1311
|
if (config.agents && config.agents.length > 0) {
|
|
1289
1312
|
for (const agent of config.agents) {
|
|
1290
1313
|
this.addSubAgent(agent);
|
|
@@ -1296,11 +1319,9 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1296
1319
|
* Executes sub-agents sequentially, passing output from one to the next
|
|
1297
1320
|
*/
|
|
1298
1321
|
async run(options) {
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
);
|
|
1303
|
-
}
|
|
1322
|
+
this.logger.debug(
|
|
1323
|
+
`Running ${this.subAgents.length} sub-agents in sequence`
|
|
1324
|
+
);
|
|
1304
1325
|
if (this.subAgents.length === 0) {
|
|
1305
1326
|
return {
|
|
1306
1327
|
content: "No sub-agents defined for sequential execution.",
|
|
@@ -1316,11 +1337,9 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1316
1337
|
let finalResponse = null;
|
|
1317
1338
|
for (let i = 0; i < this.subAgents.length; i++) {
|
|
1318
1339
|
const agent = this.subAgents[i];
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
);
|
|
1323
|
-
}
|
|
1340
|
+
this.logger.debug(
|
|
1341
|
+
`Running sub-agent ${i + 1}/${this.subAgents.length}: ${agent.name}`
|
|
1342
|
+
);
|
|
1324
1343
|
try {
|
|
1325
1344
|
const response = await agent.run({
|
|
1326
1345
|
messages: currentMessages,
|
|
@@ -1335,10 +1354,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1335
1354
|
});
|
|
1336
1355
|
}
|
|
1337
1356
|
} catch (error) {
|
|
1338
|
-
console.error(
|
|
1339
|
-
`[SequentialAgent] Error in sub-agent ${agent.name}:`,
|
|
1340
|
-
error
|
|
1341
|
-
);
|
|
1357
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1342
1358
|
return {
|
|
1343
1359
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1344
1360
|
role: "assistant",
|
|
@@ -1376,11 +1392,9 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1376
1392
|
* Streams responses from each sub-agent in sequence
|
|
1377
1393
|
*/
|
|
1378
1394
|
async *runStreaming(options) {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
);
|
|
1383
|
-
}
|
|
1395
|
+
this.logger.debug(
|
|
1396
|
+
`Streaming ${this.subAgents.length} sub-agents in sequence`
|
|
1397
|
+
);
|
|
1384
1398
|
if (this.subAgents.length === 0) {
|
|
1385
1399
|
yield {
|
|
1386
1400
|
content: "No sub-agents defined for sequential execution.",
|
|
@@ -1396,11 +1410,9 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1396
1410
|
const currentMessages = [...options.messages];
|
|
1397
1411
|
for (let i = 0; i < this.subAgents.length; i++) {
|
|
1398
1412
|
const agent = this.subAgents[i];
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1413
|
+
this.logger.debug(
|
|
1414
|
+
`Streaming sub-agent ${i + 1}/${this.subAgents.length}: ${agent.name}`
|
|
1415
|
+
);
|
|
1404
1416
|
try {
|
|
1405
1417
|
const streamGenerator = agent.runStreaming({
|
|
1406
1418
|
messages: currentMessages,
|
|
@@ -1432,10 +1444,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1432
1444
|
});
|
|
1433
1445
|
}
|
|
1434
1446
|
} catch (error) {
|
|
1435
|
-
console.error(
|
|
1436
|
-
`[SequentialAgent] Error in streaming sub-agent ${agent.name}:`,
|
|
1437
|
-
error
|
|
1438
|
-
);
|
|
1447
|
+
console.error(`Error in streaming sub-agent ${agent.name}:`, error);
|
|
1439
1448
|
yield {
|
|
1440
1449
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1441
1450
|
role: "assistant",
|
|
@@ -1450,10 +1459,12 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1450
1459
|
}
|
|
1451
1460
|
}
|
|
1452
1461
|
}
|
|
1453
|
-
};
|
|
1462
|
+
}, _class8);
|
|
1454
1463
|
|
|
1455
1464
|
// src/agents/parallel-agent.ts
|
|
1456
|
-
|
|
1465
|
+
init_logger();
|
|
1466
|
+
var ParallelAgent = (_class9 = class extends BaseAgent {
|
|
1467
|
+
__init11() {this.logger = new Logger({ name: "ParallelAgent" })}
|
|
1457
1468
|
/**
|
|
1458
1469
|
* Constructor for ParallelAgent
|
|
1459
1470
|
*/
|
|
@@ -1461,7 +1472,7 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1461
1472
|
super({
|
|
1462
1473
|
name: config.name,
|
|
1463
1474
|
description: config.description
|
|
1464
|
-
});
|
|
1475
|
+
});_class9.prototype.__init11.call(this);;
|
|
1465
1476
|
if (config.agents && config.agents.length > 0) {
|
|
1466
1477
|
for (const agent of config.agents) {
|
|
1467
1478
|
this.addSubAgent(agent);
|
|
@@ -1473,11 +1484,9 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1473
1484
|
* Executes all sub-agents in parallel
|
|
1474
1485
|
*/
|
|
1475
1486
|
async run(options) {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
);
|
|
1480
|
-
}
|
|
1487
|
+
this.logger.debug(
|
|
1488
|
+
`Running ${this.subAgents.length} sub-agents in parallel`
|
|
1489
|
+
);
|
|
1481
1490
|
if (this.subAgents.length === 0) {
|
|
1482
1491
|
return {
|
|
1483
1492
|
content: "No sub-agents defined for parallel execution.",
|
|
@@ -1489,10 +1498,7 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1489
1498
|
messages: options.messages,
|
|
1490
1499
|
config: options.config
|
|
1491
1500
|
}).catch((error) => {
|
|
1492
|
-
console.error(
|
|
1493
|
-
`[ParallelAgent] Error in sub-agent ${agent.name}:`,
|
|
1494
|
-
error
|
|
1495
|
-
);
|
|
1501
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1496
1502
|
return {
|
|
1497
1503
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1498
1504
|
role: "assistant"
|
|
@@ -1520,11 +1526,9 @@ ${result.content || "No content"}
|
|
|
1520
1526
|
* Collects streaming responses from all sub-agents
|
|
1521
1527
|
*/
|
|
1522
1528
|
async *runStreaming(options) {
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
);
|
|
1527
|
-
}
|
|
1529
|
+
this.logger.debug(
|
|
1530
|
+
`Streaming ${this.subAgents.length} sub-agents in parallel`
|
|
1531
|
+
);
|
|
1528
1532
|
if (this.subAgents.length === 0) {
|
|
1529
1533
|
yield {
|
|
1530
1534
|
content: "No sub-agents defined for parallel execution.",
|
|
@@ -1537,10 +1541,7 @@ ${result.content || "No content"}
|
|
|
1537
1541
|
messages: options.messages,
|
|
1538
1542
|
config: options.config
|
|
1539
1543
|
}).catch((error) => {
|
|
1540
|
-
console.error(
|
|
1541
|
-
`[ParallelAgent] Error in sub-agent ${agent.name}:`,
|
|
1542
|
-
error
|
|
1543
|
-
);
|
|
1544
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1544
1545
|
return {
|
|
1545
1546
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1546
1547
|
role: "assistant"
|
|
@@ -1587,10 +1588,11 @@ ${response.content || "No content"}
|
|
|
1587
1588
|
};
|
|
1588
1589
|
}
|
|
1589
1590
|
}
|
|
1590
|
-
};
|
|
1591
|
+
}, _class9);
|
|
1591
1592
|
|
|
1592
1593
|
// src/agents/loop-agent.ts
|
|
1593
|
-
|
|
1594
|
+
init_logger();
|
|
1595
|
+
var LoopAgent = (_class10 = class extends BaseAgent {
|
|
1594
1596
|
/**
|
|
1595
1597
|
* Maximum number of iterations to prevent infinite loops
|
|
1596
1598
|
*/
|
|
@@ -1603,6 +1605,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1603
1605
|
* Custom condition check function
|
|
1604
1606
|
*/
|
|
1605
1607
|
|
|
1608
|
+
__init12() {this.logger = new Logger({ name: "LoopAgent" })}
|
|
1606
1609
|
/**
|
|
1607
1610
|
* Constructor for LoopAgent
|
|
1608
1611
|
*/
|
|
@@ -1610,7 +1613,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1610
1613
|
super({
|
|
1611
1614
|
name: config.name,
|
|
1612
1615
|
description: config.description
|
|
1613
|
-
});
|
|
1616
|
+
});_class10.prototype.__init12.call(this);;
|
|
1614
1617
|
this.maxIterations = config.maxIterations || 10;
|
|
1615
1618
|
this.conditionAgent = config.conditionAgent;
|
|
1616
1619
|
this.conditionCheck = config.conditionCheck;
|
|
@@ -1630,28 +1633,20 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1630
1633
|
*/
|
|
1631
1634
|
async shouldContinue(response, iterationCount, messages, config) {
|
|
1632
1635
|
if (iterationCount >= this.maxIterations) {
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
);
|
|
1637
|
-
}
|
|
1636
|
+
this.logger.debug(
|
|
1637
|
+
`Maximum iterations (${this.maxIterations}) reached. Stopping loop.`
|
|
1638
|
+
);
|
|
1638
1639
|
return false;
|
|
1639
1640
|
}
|
|
1640
1641
|
if (this.conditionCheck) {
|
|
1641
1642
|
const shouldContinue = await this.conditionCheck(response);
|
|
1642
|
-
|
|
1643
|
-
console.log(
|
|
1644
|
-
`[LoopAgent] Custom condition check result: ${shouldContinue}`
|
|
1645
|
-
);
|
|
1646
|
-
}
|
|
1643
|
+
this.logger.debug(`Custom condition check result: ${shouldContinue}`);
|
|
1647
1644
|
return shouldContinue;
|
|
1648
1645
|
}
|
|
1649
1646
|
if (this.conditionAgent) {
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
);
|
|
1654
|
-
}
|
|
1647
|
+
this.logger.debug(
|
|
1648
|
+
`Using condition agent ${this.conditionAgent.name} to check loop condition`
|
|
1649
|
+
);
|
|
1655
1650
|
const conditionMessages = [
|
|
1656
1651
|
...messages,
|
|
1657
1652
|
{
|
|
@@ -1670,14 +1665,12 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1670
1665
|
});
|
|
1671
1666
|
const content = _optionalChain([conditionResponse, 'access', _21 => _21.content, 'optionalAccess', _22 => _22.toLowerCase, 'call', _23 => _23()]) || "";
|
|
1672
1667
|
const shouldContinue = content.includes("yes") && !content.includes("no");
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
);
|
|
1677
|
-
}
|
|
1668
|
+
this.logger.debug(
|
|
1669
|
+
`Condition agent result: ${shouldContinue ? "Continue loop" : "Stop loop"}`
|
|
1670
|
+
);
|
|
1678
1671
|
return shouldContinue;
|
|
1679
1672
|
} catch (error) {
|
|
1680
|
-
console.error("
|
|
1673
|
+
console.error("Error in condition agent:", error);
|
|
1681
1674
|
return false;
|
|
1682
1675
|
}
|
|
1683
1676
|
}
|
|
@@ -1688,11 +1681,9 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1688
1681
|
* Executes the sub-agent in a loop until the condition is met
|
|
1689
1682
|
*/
|
|
1690
1683
|
async run(options) {
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
);
|
|
1695
|
-
}
|
|
1684
|
+
this.logger.debug(
|
|
1685
|
+
`Starting loop with max ${this.maxIterations} iterations`
|
|
1686
|
+
);
|
|
1696
1687
|
if (this.subAgents.length === 0) {
|
|
1697
1688
|
return {
|
|
1698
1689
|
content: "No sub-agent defined for loop execution.",
|
|
@@ -1706,11 +1697,9 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1706
1697
|
let shouldContinueLoop = true;
|
|
1707
1698
|
while (shouldContinueLoop && iterationCount < this.maxIterations) {
|
|
1708
1699
|
iterationCount++;
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
);
|
|
1713
|
-
}
|
|
1700
|
+
this.logger.debug(
|
|
1701
|
+
`Running iteration ${iterationCount}/${this.maxIterations}`
|
|
1702
|
+
);
|
|
1714
1703
|
try {
|
|
1715
1704
|
const response = await subAgent.run({
|
|
1716
1705
|
messages: currentMessages,
|
|
@@ -1734,10 +1723,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1734
1723
|
});
|
|
1735
1724
|
}
|
|
1736
1725
|
} catch (error) {
|
|
1737
|
-
console.error(
|
|
1738
|
-
`[LoopAgent] Error in loop iteration ${iterationCount}:`,
|
|
1739
|
-
error
|
|
1740
|
-
);
|
|
1726
|
+
console.error(`Error in loop iteration ${iterationCount}:`, error);
|
|
1741
1727
|
break;
|
|
1742
1728
|
}
|
|
1743
1729
|
}
|
|
@@ -1758,11 +1744,9 @@ ${lastResponse.content || ""}`,
|
|
|
1758
1744
|
* Runs the agent with streaming support
|
|
1759
1745
|
*/
|
|
1760
1746
|
async *runStreaming(options) {
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
);
|
|
1765
|
-
}
|
|
1747
|
+
this.logger.debug(
|
|
1748
|
+
`Starting loop with max ${this.maxIterations} iterations (streaming)`
|
|
1749
|
+
);
|
|
1766
1750
|
if (this.subAgents.length === 0) {
|
|
1767
1751
|
yield {
|
|
1768
1752
|
content: "No sub-agent defined for loop execution.",
|
|
@@ -1781,11 +1765,9 @@ ${lastResponse.content || ""}`,
|
|
|
1781
1765
|
};
|
|
1782
1766
|
while (shouldContinueLoop && iterationCount < this.maxIterations) {
|
|
1783
1767
|
iterationCount++;
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
);
|
|
1788
|
-
}
|
|
1768
|
+
this.logger.debug(
|
|
1769
|
+
`Running iteration ${iterationCount}/${this.maxIterations} (streaming)`
|
|
1770
|
+
);
|
|
1789
1771
|
yield {
|
|
1790
1772
|
content: `Running iteration ${iterationCount}/${this.maxIterations}...`,
|
|
1791
1773
|
role: "assistant",
|
|
@@ -1809,11 +1791,9 @@ ${lastResponse.content || ""}`,
|
|
|
1809
1791
|
}
|
|
1810
1792
|
}
|
|
1811
1793
|
if (!lastChunk) {
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
);
|
|
1816
|
-
}
|
|
1794
|
+
this.logger.debug(
|
|
1795
|
+
`No complete chunk received from iteration ${iterationCount}`
|
|
1796
|
+
);
|
|
1817
1797
|
shouldContinueLoop = false;
|
|
1818
1798
|
continue;
|
|
1819
1799
|
}
|
|
@@ -1839,9 +1819,8 @@ ${lastResponse.content || ""}`,
|
|
|
1839
1819
|
};
|
|
1840
1820
|
}
|
|
1841
1821
|
} catch (error) {
|
|
1842
|
-
|
|
1843
|
-
`
|
|
1844
|
-
error
|
|
1822
|
+
this.logger.debug(
|
|
1823
|
+
`Error in loop iteration ${iterationCount}: ${error instanceof Error ? error.message : String(error)}`
|
|
1845
1824
|
);
|
|
1846
1825
|
yield {
|
|
1847
1826
|
content: `Error in loop iteration ${iterationCount}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -1855,10 +1834,11 @@ ${lastResponse.content || ""}`,
|
|
|
1855
1834
|
role: "assistant"
|
|
1856
1835
|
};
|
|
1857
1836
|
}
|
|
1858
|
-
};
|
|
1837
|
+
}, _class10);
|
|
1859
1838
|
|
|
1860
1839
|
// src/agents/lang-graph-agent.ts
|
|
1861
|
-
|
|
1840
|
+
init_logger();
|
|
1841
|
+
var LangGraphAgent = (_class11 = class extends BaseAgent {
|
|
1862
1842
|
/**
|
|
1863
1843
|
* Graph nodes (agents and their connections)
|
|
1864
1844
|
*/
|
|
@@ -1874,7 +1854,8 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1874
1854
|
/**
|
|
1875
1855
|
* Results from node executions
|
|
1876
1856
|
*/
|
|
1877
|
-
|
|
1857
|
+
__init13() {this.results = []}
|
|
1858
|
+
__init14() {this.logger = new Logger({ name: "LangGraphAgent" })}
|
|
1878
1859
|
/**
|
|
1879
1860
|
* Constructor for LangGraphAgent
|
|
1880
1861
|
*/
|
|
@@ -1882,7 +1863,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1882
1863
|
super({
|
|
1883
1864
|
name: config.name,
|
|
1884
1865
|
description: config.description
|
|
1885
|
-
});
|
|
1866
|
+
});_class11.prototype.__init13.call(this);_class11.prototype.__init14.call(this);;
|
|
1886
1867
|
this.nodes = /* @__PURE__ */ new Map();
|
|
1887
1868
|
for (const node of config.nodes) {
|
|
1888
1869
|
if (this.nodes.has(node.name)) {
|
|
@@ -1949,17 +1930,13 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1949
1930
|
for (const targetName of currentNode.targets) {
|
|
1950
1931
|
const targetNode = this.nodes.get(targetName);
|
|
1951
1932
|
if (!targetNode) {
|
|
1952
|
-
console.error(`
|
|
1933
|
+
console.error(`Target node "${targetName}" not found`);
|
|
1953
1934
|
continue;
|
|
1954
1935
|
}
|
|
1955
1936
|
if (targetNode.condition) {
|
|
1956
1937
|
const shouldExecute = await targetNode.condition(result, context);
|
|
1957
1938
|
if (!shouldExecute) {
|
|
1958
|
-
|
|
1959
|
-
console.log(
|
|
1960
|
-
`[LangGraphAgent] Skipping node "${targetName}" due to condition`
|
|
1961
|
-
);
|
|
1962
|
-
}
|
|
1939
|
+
this.logger.debug(`Skipping node "${targetName}" due to condition`);
|
|
1963
1940
|
continue;
|
|
1964
1941
|
}
|
|
1965
1942
|
}
|
|
@@ -1984,11 +1961,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1984
1961
|
};
|
|
1985
1962
|
const shouldExecute = await node.condition(mockResponse, mockContext);
|
|
1986
1963
|
if (!shouldExecute) {
|
|
1987
|
-
|
|
1988
|
-
console.log(
|
|
1989
|
-
`[LangGraphAgent] Skipping node "${targetName}" due to condition`
|
|
1990
|
-
);
|
|
1991
|
-
}
|
|
1964
|
+
this.logger.debug(`Skipping node "${targetName}" due to condition`);
|
|
1992
1965
|
}
|
|
1993
1966
|
return { shouldExecute };
|
|
1994
1967
|
}
|
|
@@ -2001,11 +1974,9 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2001
1974
|
messages: options.messages,
|
|
2002
1975
|
config: options.config
|
|
2003
1976
|
});
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
);
|
|
2008
|
-
}
|
|
1977
|
+
this.logger.debug(
|
|
1978
|
+
`Starting graph execution from root node "${this.rootNode}"`
|
|
1979
|
+
);
|
|
2009
1980
|
if (this.nodes.size === 0) {
|
|
2010
1981
|
return {
|
|
2011
1982
|
content: "No nodes defined in the graph.",
|
|
@@ -2025,11 +1996,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2025
1996
|
while (nodesToExecute.length > 0 && stepCount < this.maxSteps) {
|
|
2026
1997
|
stepCount++;
|
|
2027
1998
|
const { node, messages } = nodesToExecute.shift();
|
|
2028
|
-
|
|
2029
|
-
console.log(
|
|
2030
|
-
`[LangGraphAgent] Step ${stepCount}: Executing node "${node.name}"`
|
|
2031
|
-
);
|
|
2032
|
-
}
|
|
1999
|
+
this.logger.debug(`Step ${stepCount}: Executing node "${node.name}"`);
|
|
2033
2000
|
executedNodes.push(node.name);
|
|
2034
2001
|
try {
|
|
2035
2002
|
const result = await node.agent.run({
|
|
@@ -2077,7 +2044,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2077
2044
|
});
|
|
2078
2045
|
}
|
|
2079
2046
|
} catch (error) {
|
|
2080
|
-
console.error(`
|
|
2047
|
+
console.error(`Error in node "${node.name}":`, error);
|
|
2081
2048
|
return {
|
|
2082
2049
|
content: `Error in node "${node.name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
2083
2050
|
role: "assistant"
|
|
@@ -2101,11 +2068,9 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2101
2068
|
messages: options.messages,
|
|
2102
2069
|
config: options.config
|
|
2103
2070
|
});
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
);
|
|
2108
|
-
}
|
|
2071
|
+
this.logger.debug(
|
|
2072
|
+
`Starting graph execution from root node "${this.rootNode}" (streaming)`
|
|
2073
|
+
);
|
|
2109
2074
|
if (this.nodes.size === 0) {
|
|
2110
2075
|
yield {
|
|
2111
2076
|
content: "No nodes defined in the graph.",
|
|
@@ -2132,11 +2097,9 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2132
2097
|
while (nodesToExecute.length > 0 && stepCount < this.maxSteps) {
|
|
2133
2098
|
stepCount++;
|
|
2134
2099
|
const { node, messages } = nodesToExecute.shift();
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
);
|
|
2139
|
-
}
|
|
2100
|
+
this.logger.debug(
|
|
2101
|
+
`Step ${stepCount}: Executing node "${node.name}" (streaming)`
|
|
2102
|
+
);
|
|
2140
2103
|
executedNodes.push(node.name);
|
|
2141
2104
|
try {
|
|
2142
2105
|
const result = await node.agent.run({
|
|
@@ -2190,7 +2153,7 @@ Node output: ${this.extractTextContent(result.content)}` : ""}`,
|
|
|
2190
2153
|
});
|
|
2191
2154
|
}
|
|
2192
2155
|
} catch (error) {
|
|
2193
|
-
console.error(`
|
|
2156
|
+
console.error(`Error in node "${node.name}":`, error);
|
|
2194
2157
|
yield {
|
|
2195
2158
|
content: `Error in node "${node.name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
2196
2159
|
role: "assistant"
|
|
@@ -2208,7 +2171,7 @@ Node output: ${this.extractTextContent(result.content)}` : ""}`,
|
|
|
2208
2171
|
};
|
|
2209
2172
|
}
|
|
2210
2173
|
}
|
|
2211
|
-
},
|
|
2174
|
+
}, _class11);
|
|
2212
2175
|
|
|
2213
2176
|
// src/tools/index.ts
|
|
2214
2177
|
var tools_exports = {};
|
|
@@ -2250,8 +2213,10 @@ function createFunctionTool(func, options) {
|
|
|
2250
2213
|
init_function_utils();
|
|
2251
2214
|
|
|
2252
2215
|
// src/tools/common/google-search.ts
|
|
2216
|
+
init_logger();
|
|
2253
2217
|
init_base_tool();
|
|
2254
|
-
var GoogleSearch = class extends BaseTool {
|
|
2218
|
+
var GoogleSearch = (_class12 = class extends BaseTool {
|
|
2219
|
+
__init15() {this.logger = new Logger({ name: "GoogleSearch" })}
|
|
2255
2220
|
/**
|
|
2256
2221
|
* Constructor for GoogleSearch
|
|
2257
2222
|
*/
|
|
@@ -2259,7 +2224,7 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2259
2224
|
super({
|
|
2260
2225
|
name: "google_search",
|
|
2261
2226
|
description: "Search the web using Google"
|
|
2262
|
-
});
|
|
2227
|
+
});_class12.prototype.__init15.call(this);;
|
|
2263
2228
|
}
|
|
2264
2229
|
/**
|
|
2265
2230
|
* Get the function declaration for the tool
|
|
@@ -2290,9 +2255,9 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2290
2255
|
* This is a simplified implementation that doesn't actually search, just returns mock results
|
|
2291
2256
|
*/
|
|
2292
2257
|
async runAsync(args, _context) {
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2258
|
+
this.logger.debug(
|
|
2259
|
+
`[GoogleSearch] Executing Google search for: ${args.query}`
|
|
2260
|
+
);
|
|
2296
2261
|
return {
|
|
2297
2262
|
results: [
|
|
2298
2263
|
{
|
|
@@ -2308,7 +2273,7 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2308
2273
|
]
|
|
2309
2274
|
};
|
|
2310
2275
|
}
|
|
2311
|
-
};
|
|
2276
|
+
}, _class12);
|
|
2312
2277
|
|
|
2313
2278
|
// src/tools/common/http-request-tool.ts
|
|
2314
2279
|
init_base_tool();
|
|
@@ -2432,7 +2397,7 @@ var HttpRequestTool = class extends BaseTool {
|
|
|
2432
2397
|
// src/tools/common/file-operations-tool.ts
|
|
2433
2398
|
init_base_tool();
|
|
2434
2399
|
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
|
|
2435
|
-
var _path = require('path'); var
|
|
2400
|
+
var _path = require('path'); var path3 = _interopRequireWildcard(_path);
|
|
2436
2401
|
var FileOperationsTool = class extends BaseTool {
|
|
2437
2402
|
|
|
2438
2403
|
constructor(options) {
|
|
@@ -2528,14 +2493,14 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
2528
2493
|
* Resolve a file path relative to the base path
|
|
2529
2494
|
*/
|
|
2530
2495
|
resolvePath(filepath) {
|
|
2531
|
-
return
|
|
2496
|
+
return path3.default.isAbsolute(filepath) ? filepath : path3.default.resolve(this.basePath, filepath);
|
|
2532
2497
|
}
|
|
2533
2498
|
/**
|
|
2534
2499
|
* Validate that a path is within the base path for security
|
|
2535
2500
|
*/
|
|
2536
2501
|
validatePath(filepath) {
|
|
2537
|
-
const normalizedPath =
|
|
2538
|
-
const normalizedBasePath =
|
|
2502
|
+
const normalizedPath = path3.default.normalize(filepath);
|
|
2503
|
+
const normalizedBasePath = path3.default.normalize(this.basePath);
|
|
2539
2504
|
if (!normalizedPath.startsWith(normalizedBasePath)) {
|
|
2540
2505
|
throw new Error(
|
|
2541
2506
|
`Access denied: Can't access paths outside the base directory`
|
|
@@ -2564,7 +2529,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
2564
2529
|
*/
|
|
2565
2530
|
async writeFile(filepath, content, encoding) {
|
|
2566
2531
|
try {
|
|
2567
|
-
const dir =
|
|
2532
|
+
const dir = path3.default.dirname(filepath);
|
|
2568
2533
|
await _promises2.default.mkdir(dir, { recursive: true });
|
|
2569
2534
|
await _promises2.default.writeFile(filepath, content, { encoding });
|
|
2570
2535
|
return {
|
|
@@ -2582,7 +2547,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
2582
2547
|
*/
|
|
2583
2548
|
async appendFile(filepath, content, encoding) {
|
|
2584
2549
|
try {
|
|
2585
|
-
const dir =
|
|
2550
|
+
const dir = path3.default.dirname(filepath);
|
|
2586
2551
|
await _promises2.default.mkdir(dir, { recursive: true });
|
|
2587
2552
|
await _promises2.default.appendFile(filepath, content, { encoding });
|
|
2588
2553
|
return {
|
|
@@ -2636,7 +2601,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
2636
2601
|
const entries = await _promises2.default.readdir(dirpath, { withFileTypes: true });
|
|
2637
2602
|
const results = await Promise.all(
|
|
2638
2603
|
entries.map(async (entry) => {
|
|
2639
|
-
const entryPath =
|
|
2604
|
+
const entryPath = path3.default.join(dirpath, entry.name);
|
|
2640
2605
|
const stats = await _promises2.default.stat(entryPath);
|
|
2641
2606
|
return {
|
|
2642
2607
|
name: entry.name,
|
|
@@ -2755,8 +2720,10 @@ var UserInteractionTool = class extends BaseTool {
|
|
|
2755
2720
|
};
|
|
2756
2721
|
|
|
2757
2722
|
// src/tools/common/exit-loop-tool.ts
|
|
2723
|
+
init_logger();
|
|
2758
2724
|
init_base_tool();
|
|
2759
|
-
var ExitLoopTool = class extends BaseTool {
|
|
2725
|
+
var ExitLoopTool = (_class13 = class extends BaseTool {
|
|
2726
|
+
__init16() {this.logger = new Logger({ name: "ExitLoopTool" })}
|
|
2760
2727
|
/**
|
|
2761
2728
|
* Constructor for ExitLoopTool
|
|
2762
2729
|
*/
|
|
@@ -2764,7 +2731,7 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2764
2731
|
super({
|
|
2765
2732
|
name: "exit_loop",
|
|
2766
2733
|
description: "Exits the loop. Call this function only when you are instructed to do so."
|
|
2767
|
-
});
|
|
2734
|
+
});_class13.prototype.__init16.call(this);;
|
|
2768
2735
|
}
|
|
2769
2736
|
/**
|
|
2770
2737
|
* Get the function declaration for the tool
|
|
@@ -2784,9 +2751,7 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2784
2751
|
* Execute the exit loop action
|
|
2785
2752
|
*/
|
|
2786
2753
|
async runAsync(_args, context) {
|
|
2787
|
-
|
|
2788
|
-
console.log("Executing exit loop tool");
|
|
2789
|
-
}
|
|
2754
|
+
this.logger.debug("Executing exit loop tool");
|
|
2790
2755
|
if (context.actions) {
|
|
2791
2756
|
context.actions.escalate = true;
|
|
2792
2757
|
} else {
|
|
@@ -2798,11 +2763,13 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2798
2763
|
message: "Loop exited successfully"
|
|
2799
2764
|
};
|
|
2800
2765
|
}
|
|
2801
|
-
};
|
|
2766
|
+
}, _class13);
|
|
2802
2767
|
|
|
2803
2768
|
// src/tools/common/get-user-choice-tool.ts
|
|
2769
|
+
init_logger();
|
|
2804
2770
|
init_base_tool();
|
|
2805
|
-
var GetUserChoiceTool = class extends BaseTool {
|
|
2771
|
+
var GetUserChoiceTool = (_class14 = class extends BaseTool {
|
|
2772
|
+
__init17() {this.logger = new Logger({ name: "GetUserChoiceTool" })}
|
|
2806
2773
|
/**
|
|
2807
2774
|
* Constructor for GetUserChoiceTool
|
|
2808
2775
|
*/
|
|
@@ -2811,7 +2778,7 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2811
2778
|
name: "get_user_choice",
|
|
2812
2779
|
description: "This tool provides the options to the user and asks them to choose one. Use this tool when you need the user to make a selection between multiple options. Do not list options in your response - use this tool instead.",
|
|
2813
2780
|
isLongRunning: true
|
|
2814
|
-
});
|
|
2781
|
+
});_class14.prototype.__init17.call(this);;
|
|
2815
2782
|
}
|
|
2816
2783
|
/**
|
|
2817
2784
|
* Get the function declaration for the tool
|
|
@@ -2845,13 +2812,11 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2845
2812
|
* and the actual choice will be provided asynchronously
|
|
2846
2813
|
*/
|
|
2847
2814
|
async runAsync(args, context) {
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
console.log(`Question: ${args.question}`);
|
|
2854
|
-
}
|
|
2815
|
+
this.logger.debug(
|
|
2816
|
+
`Executing get_user_choice with options: ${args.options.join(", ")}`
|
|
2817
|
+
);
|
|
2818
|
+
if (args.question) {
|
|
2819
|
+
this.logger.debug(`Question: ${args.question}`);
|
|
2855
2820
|
}
|
|
2856
2821
|
if (context.actions) {
|
|
2857
2822
|
context.actions.skip_summarization = true;
|
|
@@ -2862,11 +2827,13 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2862
2827
|
}
|
|
2863
2828
|
return null;
|
|
2864
2829
|
}
|
|
2865
|
-
};
|
|
2830
|
+
}, _class14);
|
|
2866
2831
|
|
|
2867
2832
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
2833
|
+
init_logger();
|
|
2868
2834
|
init_base_tool();
|
|
2869
|
-
var TransferToAgentTool = class extends BaseTool {
|
|
2835
|
+
var TransferToAgentTool = (_class15 = class extends BaseTool {
|
|
2836
|
+
__init18() {this.logger = new Logger({ name: "TransferToAgentTool" })}
|
|
2870
2837
|
/**
|
|
2871
2838
|
* Constructor for TransferToAgentTool
|
|
2872
2839
|
*/
|
|
@@ -2874,7 +2841,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2874
2841
|
super({
|
|
2875
2842
|
name: "transfer_to_agent",
|
|
2876
2843
|
description: "Transfer the question to another agent."
|
|
2877
|
-
});
|
|
2844
|
+
});_class15.prototype.__init18.call(this);;
|
|
2878
2845
|
}
|
|
2879
2846
|
/**
|
|
2880
2847
|
* Get the function declaration for the tool
|
|
@@ -2899,9 +2866,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2899
2866
|
* Execute the transfer to agent action
|
|
2900
2867
|
*/
|
|
2901
2868
|
async runAsync(args, context) {
|
|
2902
|
-
|
|
2903
|
-
console.log(`Executing transfer to agent: ${args.agent_name}`);
|
|
2904
|
-
}
|
|
2869
|
+
this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
|
|
2905
2870
|
if (context.actions) {
|
|
2906
2871
|
context.actions.transfer_to_agent = args.agent_name;
|
|
2907
2872
|
} else {
|
|
@@ -2913,11 +2878,13 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2913
2878
|
message: `Transferred to agent: ${args.agent_name}`
|
|
2914
2879
|
};
|
|
2915
2880
|
}
|
|
2916
|
-
};
|
|
2881
|
+
}, _class15);
|
|
2917
2882
|
|
|
2918
2883
|
// src/tools/common/load-memory-tool.ts
|
|
2884
|
+
init_logger();
|
|
2919
2885
|
init_base_tool();
|
|
2920
|
-
var LoadMemoryTool = class extends BaseTool {
|
|
2886
|
+
var LoadMemoryTool = (_class16 = class extends BaseTool {
|
|
2887
|
+
__init19() {this.logger = new Logger({ name: "LoadMemoryTool" })}
|
|
2921
2888
|
/**
|
|
2922
2889
|
* Constructor for LoadMemoryTool
|
|
2923
2890
|
*/
|
|
@@ -2925,7 +2892,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2925
2892
|
super({
|
|
2926
2893
|
name: "load_memory",
|
|
2927
2894
|
description: "Loads the memory for the current user based on a query."
|
|
2928
|
-
});
|
|
2895
|
+
});_class16.prototype.__init19.call(this);;
|
|
2929
2896
|
}
|
|
2930
2897
|
/**
|
|
2931
2898
|
* Get the function declaration for the tool
|
|
@@ -2950,9 +2917,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2950
2917
|
* Execute the memory loading action
|
|
2951
2918
|
*/
|
|
2952
2919
|
async runAsync(args, context) {
|
|
2953
|
-
|
|
2954
|
-
console.log(`Executing load_memory with query: ${args.query}`);
|
|
2955
|
-
}
|
|
2920
|
+
this.logger.debug(`Executing load_memory with query: ${args.query}`);
|
|
2956
2921
|
if (!context.memoryService) {
|
|
2957
2922
|
return {
|
|
2958
2923
|
error: "Memory service is not available",
|
|
@@ -2973,12 +2938,14 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2973
2938
|
};
|
|
2974
2939
|
}
|
|
2975
2940
|
}
|
|
2976
|
-
};
|
|
2941
|
+
}, _class16);
|
|
2977
2942
|
|
|
2978
2943
|
// src/tools/mcp/client.ts
|
|
2944
|
+
init_logger();
|
|
2979
2945
|
var _indexjs = require('@modelcontextprotocol/sdk/client/index.js');
|
|
2980
2946
|
var _ssejs = require('@modelcontextprotocol/sdk/client/sse.js');
|
|
2981
2947
|
var _stdiojs = require('@modelcontextprotocol/sdk/client/stdio.js');
|
|
2948
|
+
var _typesjs = require('@modelcontextprotocol/sdk/types.js');
|
|
2982
2949
|
|
|
2983
2950
|
// src/tools/mcp/types.ts
|
|
2984
2951
|
var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
@@ -2987,6 +2954,8 @@ var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
|
2987
2954
|
McpErrorType2["RESOURCE_CLOSED_ERROR"] = "resource_closed_error";
|
|
2988
2955
|
McpErrorType2["TIMEOUT_ERROR"] = "timeout_error";
|
|
2989
2956
|
McpErrorType2["INVALID_SCHEMA_ERROR"] = "invalid_schema_error";
|
|
2957
|
+
McpErrorType2["SAMPLING_ERROR"] = "SAMPLING_ERROR";
|
|
2958
|
+
McpErrorType2["INVALID_REQUEST_ERROR"] = "INVALID_REQUEST_ERROR";
|
|
2990
2959
|
return McpErrorType2;
|
|
2991
2960
|
})(McpErrorType || {});
|
|
2992
2961
|
var McpError = class extends Error {
|
|
@@ -3029,13 +2998,16 @@ function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
|
3029
2998
|
}
|
|
3030
2999
|
|
|
3031
3000
|
// src/tools/mcp/client.ts
|
|
3032
|
-
var McpClientService = (
|
|
3001
|
+
var McpClientService = (_class17 = class {
|
|
3033
3002
|
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3003
|
+
__init20() {this.client = null}
|
|
3004
|
+
__init21() {this.transport = null}
|
|
3005
|
+
__init22() {this.isClosing = false}
|
|
3006
|
+
__init23() {this.samplingHandler = null}
|
|
3007
|
+
__init24() {this.logger = new Logger({ name: "McpClientService" })}
|
|
3008
|
+
constructor(config) {;_class17.prototype.__init20.call(this);_class17.prototype.__init21.call(this);_class17.prototype.__init22.call(this);_class17.prototype.__init23.call(this);_class17.prototype.__init24.call(this);
|
|
3038
3009
|
this.config = config;
|
|
3010
|
+
this.samplingHandler = config.samplingHandler || null;
|
|
3039
3011
|
}
|
|
3040
3012
|
/**
|
|
3041
3013
|
* Initializes and returns an MCP client based on configuration.
|
|
@@ -3084,6 +3056,7 @@ var McpClientService = (_class7 = class {
|
|
|
3084
3056
|
} else {
|
|
3085
3057
|
await connectPromise;
|
|
3086
3058
|
}
|
|
3059
|
+
await this.setupSamplingHandler(client);
|
|
3087
3060
|
if (this.config.debug) {
|
|
3088
3061
|
console.log("\u2705 MCP client connected successfully");
|
|
3089
3062
|
}
|
|
@@ -3235,9 +3208,77 @@ var McpClientService = (_class7 = class {
|
|
|
3235
3208
|
isConnected() {
|
|
3236
3209
|
return !!this.client && !this.isClosing;
|
|
3237
3210
|
}
|
|
3238
|
-
|
|
3211
|
+
async setupSamplingHandler(client) {
|
|
3212
|
+
if (!this.samplingHandler) {
|
|
3213
|
+
if (this.config.debug) {
|
|
3214
|
+
console.log(
|
|
3215
|
+
"\u26A0\uFE0F No sampling handler provided - sampling requests will be rejected"
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
3218
|
+
return;
|
|
3219
|
+
}
|
|
3220
|
+
client.setRequestHandler(_typesjs.CreateMessageRequestSchema, async (request) => {
|
|
3221
|
+
try {
|
|
3222
|
+
this.logger.debug("Received sampling request:", request);
|
|
3223
|
+
const samplingRequest = request.params;
|
|
3224
|
+
if (!samplingRequest.messages || !Array.isArray(samplingRequest.messages)) {
|
|
3225
|
+
throw new McpError(
|
|
3226
|
+
"Invalid sampling request: messages array is required",
|
|
3227
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3228
|
+
);
|
|
3229
|
+
}
|
|
3230
|
+
if (!samplingRequest.maxTokens || samplingRequest.maxTokens <= 0) {
|
|
3231
|
+
throw new McpError(
|
|
3232
|
+
"Invalid sampling request: maxTokens must be a positive number",
|
|
3233
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3234
|
+
);
|
|
3235
|
+
}
|
|
3236
|
+
const response = await this.samplingHandler({
|
|
3237
|
+
method: request.method,
|
|
3238
|
+
params: request.params
|
|
3239
|
+
});
|
|
3240
|
+
if (this.config.debug) {
|
|
3241
|
+
console.log("\u2705 Sampling request completed successfully");
|
|
3242
|
+
}
|
|
3243
|
+
return response;
|
|
3244
|
+
} catch (error) {
|
|
3245
|
+
console.error("\u274C Error handling sampling request:", error);
|
|
3246
|
+
if (error instanceof McpError) {
|
|
3247
|
+
throw error;
|
|
3248
|
+
}
|
|
3249
|
+
throw new McpError(
|
|
3250
|
+
`Sampling request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3251
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */,
|
|
3252
|
+
error instanceof Error ? error : void 0
|
|
3253
|
+
);
|
|
3254
|
+
}
|
|
3255
|
+
});
|
|
3256
|
+
if (this.config.debug) {
|
|
3257
|
+
console.log("\u{1F3AF} Sampling handler registered successfully");
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
setSamplingHandler(handler) {
|
|
3261
|
+
this.samplingHandler = handler;
|
|
3262
|
+
if (this.client) {
|
|
3263
|
+
this.setupSamplingHandler(this.client).catch((error) => {
|
|
3264
|
+
console.error("Failed to update sampling handler:", error);
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
removeSamplingHandler() {
|
|
3269
|
+
this.samplingHandler = null;
|
|
3270
|
+
if (this.client) {
|
|
3271
|
+
try {
|
|
3272
|
+
_optionalChain([this, 'access', _42 => _42.client, 'access', _43 => _43.removeRequestHandler, 'optionalCall', _44 => _44("sampling/createMessage")]);
|
|
3273
|
+
} catch (error) {
|
|
3274
|
+
console.error("Failed to remove sampling handler:", error);
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
}, _class17);
|
|
3239
3279
|
|
|
3240
3280
|
// src/tools/mcp/create-tool.ts
|
|
3281
|
+
init_logger();
|
|
3241
3282
|
init_base_tool();
|
|
3242
3283
|
|
|
3243
3284
|
// src/tools/mcp/schema-conversion.ts
|
|
@@ -3436,10 +3477,11 @@ async function createTool(mcpTool, client) {
|
|
|
3436
3477
|
throw error;
|
|
3437
3478
|
}
|
|
3438
3479
|
}
|
|
3439
|
-
var McpToolAdapter = (
|
|
3480
|
+
var McpToolAdapter = (_class18 = class extends BaseTool {
|
|
3440
3481
|
|
|
3441
3482
|
|
|
3442
|
-
|
|
3483
|
+
__init25() {this.clientService = null}
|
|
3484
|
+
__init26() {this.logger = new Logger({ name: "McpToolAdapter" })}
|
|
3443
3485
|
constructor(mcpTool, client) {
|
|
3444
3486
|
const metadata = mcpTool.metadata || {};
|
|
3445
3487
|
super({
|
|
@@ -3448,7 +3490,7 @@ var McpToolAdapter = (_class8 = class extends BaseTool {
|
|
|
3448
3490
|
isLongRunning: _nullishCoalesce(metadata.isLongRunning, () => ( false)),
|
|
3449
3491
|
shouldRetryOnFailure: _nullishCoalesce(metadata.shouldRetryOnFailure, () => ( false)),
|
|
3450
3492
|
maxRetryAttempts: _nullishCoalesce(metadata.maxRetryAttempts, () => ( 3))
|
|
3451
|
-
});
|
|
3493
|
+
});_class18.prototype.__init25.call(this);_class18.prototype.__init26.call(this);;
|
|
3452
3494
|
this.mcpTool = mcpTool;
|
|
3453
3495
|
this.client = client;
|
|
3454
3496
|
if (client.reinitialize && typeof client.reinitialize === "function") {
|
|
@@ -3472,9 +3514,7 @@ var McpToolAdapter = (_class8 = class extends BaseTool {
|
|
|
3472
3514
|
}
|
|
3473
3515
|
}
|
|
3474
3516
|
async runAsync(args, _context) {
|
|
3475
|
-
|
|
3476
|
-
console.log(`Executing MCP tool ${this.name} with args:`, args);
|
|
3477
|
-
}
|
|
3517
|
+
this.logger.debug(`Executing MCP tool ${this.name} with args:`, args);
|
|
3478
3518
|
try {
|
|
3479
3519
|
if (typeof this.mcpTool.execute === "function") {
|
|
3480
3520
|
return await this.mcpTool.execute(args);
|
|
@@ -3523,16 +3563,16 @@ var McpToolAdapter = (_class8 = class extends BaseTool {
|
|
|
3523
3563
|
throw error;
|
|
3524
3564
|
}
|
|
3525
3565
|
}
|
|
3526
|
-
},
|
|
3566
|
+
}, _class18);
|
|
3527
3567
|
|
|
3528
3568
|
// src/tools/mcp/index.ts
|
|
3529
|
-
var McpToolset = (
|
|
3569
|
+
var McpToolset = (_class19 = class {
|
|
3530
3570
|
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
constructor(config, toolFilter = null) {;
|
|
3571
|
+
__init27() {this.clientService = null}
|
|
3572
|
+
__init28() {this.toolFilter = null}
|
|
3573
|
+
__init29() {this.tools = []}
|
|
3574
|
+
__init30() {this.isClosing = false}
|
|
3575
|
+
constructor(config, toolFilter = null) {;_class19.prototype.__init27.call(this);_class19.prototype.__init28.call(this);_class19.prototype.__init29.call(this);_class19.prototype.__init30.call(this);
|
|
3536
3576
|
this.config = config;
|
|
3537
3577
|
this.toolFilter = toolFilter;
|
|
3538
3578
|
this.clientService = new McpClientService(config);
|
|
@@ -3581,7 +3621,7 @@ var McpToolset = (_class9 = class {
|
|
|
3581
3621
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
3582
3622
|
);
|
|
3583
3623
|
}
|
|
3584
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
3624
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _45 => _45.config, 'access', _46 => _46.cacheConfig, 'optionalAccess', _47 => _47.enabled]) === false) {
|
|
3585
3625
|
return this.tools;
|
|
3586
3626
|
}
|
|
3587
3627
|
if (!this.clientService) {
|
|
@@ -3607,7 +3647,7 @@ var McpToolset = (_class9 = class {
|
|
|
3607
3647
|
}
|
|
3608
3648
|
}
|
|
3609
3649
|
}
|
|
3610
|
-
if (_optionalChain([this, 'access',
|
|
3650
|
+
if (_optionalChain([this, 'access', _48 => _48.config, 'access', _49 => _49.cacheConfig, 'optionalAccess', _50 => _50.enabled]) !== false) {
|
|
3611
3651
|
this.tools = tools;
|
|
3612
3652
|
}
|
|
3613
3653
|
return tools;
|
|
@@ -3667,7 +3707,7 @@ var McpToolset = (_class9 = class {
|
|
|
3667
3707
|
async dispose() {
|
|
3668
3708
|
await this.close();
|
|
3669
3709
|
}
|
|
3670
|
-
},
|
|
3710
|
+
}, _class19);
|
|
3671
3711
|
async function getMcpTools(config, toolFilter) {
|
|
3672
3712
|
const toolset = new McpToolset(config, toolFilter);
|
|
3673
3713
|
try {
|
|
@@ -3774,11 +3814,11 @@ var BaseLLM = class {
|
|
|
3774
3814
|
};
|
|
3775
3815
|
|
|
3776
3816
|
// src/models/base-llm-connection.ts
|
|
3777
|
-
var BaseLLMConnection = (
|
|
3817
|
+
var BaseLLMConnection = (_class20 = class {constructor() { _class20.prototype.__init31.call(this); }
|
|
3778
3818
|
/**
|
|
3779
3819
|
* Whether the connection is active
|
|
3780
3820
|
*/
|
|
3781
|
-
|
|
3821
|
+
__init31() {this._isActive = true}
|
|
3782
3822
|
/**
|
|
3783
3823
|
* Gets whether the connection is active
|
|
3784
3824
|
*/
|
|
@@ -3791,13 +3831,15 @@ var BaseLLMConnection = (_class10 = class {constructor() { _class10.prototype.__
|
|
|
3791
3831
|
close() {
|
|
3792
3832
|
this._isActive = false;
|
|
3793
3833
|
}
|
|
3794
|
-
},
|
|
3834
|
+
}, _class20);
|
|
3795
3835
|
|
|
3796
3836
|
// src/models/anthropic-llm.ts
|
|
3837
|
+
init_logger();
|
|
3797
3838
|
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
3798
3839
|
|
|
3799
3840
|
// src/models/anthropic-llm-connection.ts
|
|
3800
|
-
|
|
3841
|
+
init_logger();
|
|
3842
|
+
var AnthropicLLMConnection = (_class21 = class extends BaseLLMConnection {
|
|
3801
3843
|
/**
|
|
3802
3844
|
* Axios instance for API calls
|
|
3803
3845
|
*/
|
|
@@ -3824,11 +3866,12 @@ var AnthropicLLMConnection = class extends BaseLLMConnection {
|
|
|
3824
3866
|
|
|
3825
3867
|
|
|
3826
3868
|
|
|
3869
|
+
__init32() {this.logger = new Logger({ name: "AnthropicLlmConnection" })}
|
|
3827
3870
|
/**
|
|
3828
3871
|
* Constructor
|
|
3829
3872
|
*/
|
|
3830
3873
|
constructor(client, model, initialRequest, defaultParams) {
|
|
3831
|
-
super();
|
|
3874
|
+
super();_class21.prototype.__init32.call(this);;
|
|
3832
3875
|
this.client = client;
|
|
3833
3876
|
this.model = model;
|
|
3834
3877
|
this.defaultParams = defaultParams;
|
|
@@ -3908,7 +3951,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3908
3951
|
* Convert Anthropic tool calls to ADK tool calls
|
|
3909
3952
|
*/
|
|
3910
3953
|
convertToolCalls(toolUses) {
|
|
3911
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
3954
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _51 => _51.length])) {
|
|
3912
3955
|
return void 0;
|
|
3913
3956
|
}
|
|
3914
3957
|
return toolUses.map((toolUse) => ({
|
|
@@ -3923,22 +3966,15 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3923
3966
|
* Extract tool uses from response content
|
|
3924
3967
|
*/
|
|
3925
3968
|
extractToolUses(content) {
|
|
3926
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
3969
|
+
if (!_optionalChain([content, 'optionalAccess', _52 => _52.length])) return [];
|
|
3927
3970
|
const toolUses = [];
|
|
3928
3971
|
for (const block of content) {
|
|
3929
|
-
|
|
3930
|
-
console.log(
|
|
3931
|
-
"Connection - Processing content block of type:",
|
|
3932
|
-
block.type
|
|
3933
|
-
);
|
|
3934
|
-
}
|
|
3972
|
+
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
3935
3973
|
if (block.type === "tool_use") {
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
);
|
|
3941
|
-
}
|
|
3974
|
+
this.logger.debug(
|
|
3975
|
+
"Found tool_use block:",
|
|
3976
|
+
JSON.stringify(block, null, 2)
|
|
3977
|
+
);
|
|
3942
3978
|
toolUses.push({
|
|
3943
3979
|
id: block.id || "unknown-id",
|
|
3944
3980
|
name: block.name || "unknown-name",
|
|
@@ -3946,14 +3982,12 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3946
3982
|
});
|
|
3947
3983
|
}
|
|
3948
3984
|
}
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
);
|
|
3956
|
-
}
|
|
3985
|
+
this.logger.debug(`Found ${toolUses.length} tool uses in content`);
|
|
3986
|
+
if (toolUses.length > 0) {
|
|
3987
|
+
this.logger.debug(
|
|
3988
|
+
"Extracted tool uses:",
|
|
3989
|
+
JSON.stringify(toolUses, null, 2)
|
|
3990
|
+
);
|
|
3957
3991
|
}
|
|
3958
3992
|
return toolUses;
|
|
3959
3993
|
}
|
|
@@ -4047,50 +4081,34 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4047
4081
|
}
|
|
4048
4082
|
const toolUses = this.extractToolUses(apiResponse.content);
|
|
4049
4083
|
const toolCalls = this.convertToolCalls(toolUses);
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
"Connection - Extracted Tool Uses:",
|
|
4054
|
-
JSON.stringify(toolUses, null, 2)
|
|
4055
|
-
);
|
|
4056
|
-
console.log(
|
|
4057
|
-
"Connection - Converted Tool Calls:",
|
|
4058
|
-
JSON.stringify(toolCalls, null, 2)
|
|
4059
|
-
);
|
|
4060
|
-
}
|
|
4061
|
-
}
|
|
4084
|
+
this.logger.debug(
|
|
4085
|
+
`- Extracted ${toolUses.length} tool uses in content and converted ${_optionalChain([toolCalls, 'optionalAccess', _53 => _53.length]) || 0} tool calls`
|
|
4086
|
+
);
|
|
4062
4087
|
const llmResponse = new LLMResponse({
|
|
4063
4088
|
role: "assistant",
|
|
4064
4089
|
content,
|
|
4065
|
-
tool_calls: _optionalChain([toolCalls, 'optionalAccess',
|
|
4090
|
+
tool_calls: _optionalChain([toolCalls, 'optionalAccess', _54 => _54.length]) ? toolCalls : void 0,
|
|
4066
4091
|
raw_response: apiResponse
|
|
4067
4092
|
});
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
null,
|
|
4078
|
-
2
|
|
4079
|
-
)
|
|
4080
|
-
);
|
|
4081
|
-
}
|
|
4093
|
+
const logObject = {
|
|
4094
|
+
role: llmResponse.role,
|
|
4095
|
+
content: _optionalChain([llmResponse, 'access', _55 => _55.content, 'optionalAccess', _56 => _56.substring, 'call', _57 => _57(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4096
|
+
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4097
|
+
};
|
|
4098
|
+
this.logger.debug(
|
|
4099
|
+
"Final LLMResponse object:",
|
|
4100
|
+
JSON.stringify(logObject, null, 2)
|
|
4101
|
+
);
|
|
4082
4102
|
return llmResponse;
|
|
4083
4103
|
} catch (error) {
|
|
4084
|
-
|
|
4085
|
-
console.error("Error sending message to Anthropic:", error);
|
|
4086
|
-
}
|
|
4104
|
+
this.logger.debug("Error sending message to Anthropic:", error);
|
|
4087
4105
|
throw error;
|
|
4088
4106
|
}
|
|
4089
4107
|
}
|
|
4090
|
-
};
|
|
4108
|
+
}, _class21);
|
|
4091
4109
|
|
|
4092
4110
|
// src/models/anthropic-llm.ts
|
|
4093
|
-
var AnthropicLLM = class extends BaseLLM {
|
|
4111
|
+
var AnthropicLLM = (_class22 = class extends BaseLLM {
|
|
4094
4112
|
/**
|
|
4095
4113
|
* Anthropic API key
|
|
4096
4114
|
*/
|
|
@@ -4103,22 +4121,23 @@ var AnthropicLLM = class extends BaseLLM {
|
|
|
4103
4121
|
* Default parameters for requests
|
|
4104
4122
|
*/
|
|
4105
4123
|
|
|
4124
|
+
__init33() {this.logger = new Logger({ name: "AnthropicLLM" })}
|
|
4106
4125
|
/**
|
|
4107
4126
|
* Constructor for AnthropicLLM
|
|
4108
4127
|
*/
|
|
4109
4128
|
constructor(model, config) {
|
|
4110
|
-
super(model);
|
|
4111
|
-
this.apiKey = _optionalChain([config, 'optionalAccess',
|
|
4112
|
-
this.baseURL = _optionalChain([config, 'optionalAccess',
|
|
4129
|
+
super(model);_class22.prototype.__init33.call(this);;
|
|
4130
|
+
this.apiKey = _optionalChain([config, 'optionalAccess', _58 => _58.apiKey]) || process.env.ANTHROPIC_API_KEY || "";
|
|
4131
|
+
this.baseURL = _optionalChain([config, 'optionalAccess', _59 => _59.baseURL]) || "https://api.anthropic.com/v1";
|
|
4113
4132
|
if (!this.apiKey) {
|
|
4114
4133
|
throw new Error(
|
|
4115
4134
|
"Anthropic API key is required. Provide it in config or set ANTHROPIC_API_KEY environment variable."
|
|
4116
4135
|
);
|
|
4117
4136
|
}
|
|
4118
4137
|
this.defaultParams = {
|
|
4119
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4120
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4121
|
-
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4138
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _60 => _60.defaultParams, 'optionalAccess', _61 => _61.temperature]), () => ( 0.7)),
|
|
4139
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _62 => _62.defaultParams, 'optionalAccess', _63 => _63.top_p]), () => ( 1)),
|
|
4140
|
+
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _64 => _64.defaultParams, 'optionalAccess', _65 => _65.max_tokens]), () => ( 1024))
|
|
4122
4141
|
};
|
|
4123
4142
|
}
|
|
4124
4143
|
/**
|
|
@@ -4204,7 +4223,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4204
4223
|
* Convert ADK function declarations to Anthropic tool format
|
|
4205
4224
|
*/
|
|
4206
4225
|
convertFunctionsToTools(functions) {
|
|
4207
|
-
if (!_optionalChain([functions, 'optionalAccess',
|
|
4226
|
+
if (!_optionalChain([functions, 'optionalAccess', _66 => _66.length])) {
|
|
4208
4227
|
return [];
|
|
4209
4228
|
}
|
|
4210
4229
|
return functions.map((func) => ({
|
|
@@ -4217,7 +4236,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4217
4236
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4218
4237
|
*/
|
|
4219
4238
|
convertToolUses(toolUses) {
|
|
4220
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4239
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _67 => _67.length])) {
|
|
4221
4240
|
return [];
|
|
4222
4241
|
}
|
|
4223
4242
|
return toolUses.map((toolUse) => ({
|
|
@@ -4232,16 +4251,14 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4232
4251
|
* Extract tool uses from response content
|
|
4233
4252
|
*/
|
|
4234
4253
|
extractToolUses(content) {
|
|
4235
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4254
|
+
if (!_optionalChain([content, 'optionalAccess', _68 => _68.length])) return [];
|
|
4236
4255
|
const toolUses = [];
|
|
4237
4256
|
for (const block of content) {
|
|
4238
|
-
|
|
4239
|
-
console.log("Processing content block of type:", block.type);
|
|
4240
|
-
}
|
|
4257
|
+
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
4241
4258
|
if (block.type === "tool_use") {
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4259
|
+
this.logger.debug(
|
|
4260
|
+
`Found tool_use block: ${JSON.stringify(block, null, 2)}`
|
|
4261
|
+
);
|
|
4245
4262
|
toolUses.push({
|
|
4246
4263
|
id: block.id || "unknown-id",
|
|
4247
4264
|
name: block.name || "unknown-name",
|
|
@@ -4249,12 +4266,10 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4249
4266
|
});
|
|
4250
4267
|
}
|
|
4251
4268
|
}
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
}
|
|
4257
|
-
}
|
|
4269
|
+
this.logger.debug(
|
|
4270
|
+
`Found ${toolUses.length} tool uses in content`,
|
|
4271
|
+
toolUses
|
|
4272
|
+
);
|
|
4258
4273
|
return toolUses;
|
|
4259
4274
|
}
|
|
4260
4275
|
/**
|
|
@@ -4276,16 +4291,14 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4276
4291
|
},
|
|
4277
4292
|
responseType: stream ? "stream" : "json"
|
|
4278
4293
|
});
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
}
|
|
4288
|
-
}
|
|
4294
|
+
this.logger.debug(
|
|
4295
|
+
`API Response done with ${response.status}:`,
|
|
4296
|
+
response.data
|
|
4297
|
+
);
|
|
4298
|
+
this.logger.debug(
|
|
4299
|
+
"API Response content:",
|
|
4300
|
+
response.data.content.map((block) => ({ type: block.type }))
|
|
4301
|
+
);
|
|
4289
4302
|
return response.data;
|
|
4290
4303
|
} catch (error) {
|
|
4291
4304
|
console.error("Error calling Anthropic API:", error);
|
|
@@ -4309,26 +4322,19 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4309
4322
|
temperature: _nullishCoalesce(llmRequest.config.temperature, () => ( this.defaultParams.temperature)),
|
|
4310
4323
|
max_tokens: _nullishCoalesce(llmRequest.config.max_tokens, () => ( this.defaultParams.max_tokens)),
|
|
4311
4324
|
top_p: _nullishCoalesce(llmRequest.config.top_p, () => ( this.defaultParams.top_p)),
|
|
4312
|
-
tools: _optionalChain([tools, 'optionalAccess',
|
|
4325
|
+
tools: _optionalChain([tools, 'optionalAccess', _69 => _69.length]) ? tools : void 0
|
|
4313
4326
|
};
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
});
|
|
4321
|
-
}
|
|
4327
|
+
this.logger.debug("API Request:", {
|
|
4328
|
+
model: params.model,
|
|
4329
|
+
messageCount: params.messages.length,
|
|
4330
|
+
systemMessage: params.system ? "present" : "none",
|
|
4331
|
+
tools: params.tools ? params.tools.map((t) => t.name) : "none"
|
|
4332
|
+
});
|
|
4322
4333
|
if (stream) {
|
|
4323
4334
|
throw new Error("Streaming is not supported in this implementation");
|
|
4324
4335
|
}
|
|
4325
4336
|
const response = await this.callAnthropicAPI(params);
|
|
4326
|
-
|
|
4327
|
-
console.log(
|
|
4328
|
-
"Full Response Content:",
|
|
4329
|
-
JSON.stringify(response.content, null, 2)
|
|
4330
|
-
);
|
|
4331
|
-
}
|
|
4337
|
+
this.logger.debug("Full Response Content:", response.content);
|
|
4332
4338
|
let content = "";
|
|
4333
4339
|
for (const block of response.content) {
|
|
4334
4340
|
if (block.type === "text") {
|
|
@@ -4337,43 +4343,26 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4337
4343
|
}
|
|
4338
4344
|
const toolUses = this.extractToolUses(response.content);
|
|
4339
4345
|
const toolCalls = this.convertToolUses(toolUses);
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
console.log(
|
|
4343
|
-
"Extracted Tool Uses:",
|
|
4344
|
-
JSON.stringify(toolUses, null, 2)
|
|
4345
|
-
);
|
|
4346
|
-
console.log(
|
|
4347
|
-
"Converted Tool Calls:",
|
|
4348
|
-
JSON.stringify(toolCalls, null, 2)
|
|
4349
|
-
);
|
|
4350
|
-
}
|
|
4351
|
-
}
|
|
4346
|
+
this.logger.debug("Extracted Tool Uses:", toolUses);
|
|
4347
|
+
this.logger.debug("Converted Tool Calls:", toolCalls);
|
|
4352
4348
|
const llmResponse = new LLMResponse({
|
|
4353
4349
|
role: "assistant",
|
|
4354
4350
|
content,
|
|
4355
4351
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
4356
4352
|
raw_response: response
|
|
4357
4353
|
});
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
null,
|
|
4368
|
-
2
|
|
4369
|
-
)
|
|
4370
|
-
);
|
|
4371
|
-
}
|
|
4354
|
+
const logObject = {
|
|
4355
|
+
role: llmResponse.role,
|
|
4356
|
+
content: _optionalChain([llmResponse, 'access', _70 => _70.content, 'optionalAccess', _71 => _71.substring, 'call', _72 => _72(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4357
|
+
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4358
|
+
};
|
|
4359
|
+
this.logger.debug(
|
|
4360
|
+
"Final LLMResponse object:",
|
|
4361
|
+
JSON.stringify(logObject, null, 2)
|
|
4362
|
+
);
|
|
4372
4363
|
yield llmResponse;
|
|
4373
4364
|
} catch (error) {
|
|
4374
|
-
|
|
4375
|
-
console.error("Error calling Anthropic:", error);
|
|
4376
|
-
}
|
|
4365
|
+
this.logger.debug("Error:", error);
|
|
4377
4366
|
throw error;
|
|
4378
4367
|
}
|
|
4379
4368
|
}
|
|
@@ -4396,7 +4385,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4396
4385
|
this.defaultParams
|
|
4397
4386
|
);
|
|
4398
4387
|
}
|
|
4399
|
-
};
|
|
4388
|
+
}, _class22);
|
|
4400
4389
|
|
|
4401
4390
|
// src/models/google-llm.ts
|
|
4402
4391
|
|
|
@@ -4417,9 +4406,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4417
4406
|
constructor(model, config) {
|
|
4418
4407
|
super(model);
|
|
4419
4408
|
const apiKey = process.env.GOOGLE_API_KEY;
|
|
4420
|
-
const projectId = _optionalChain([config, 'optionalAccess',
|
|
4421
|
-
const location = _optionalChain([config, 'optionalAccess',
|
|
4422
|
-
const useVertexAI = _optionalChain([process, 'access',
|
|
4409
|
+
const projectId = _optionalChain([config, 'optionalAccess', _73 => _73.projectId]) || process.env.GOOGLE_CLOUD_PROJECT;
|
|
4410
|
+
const location = _optionalChain([config, 'optionalAccess', _74 => _74.location]) || process.env.GOOGLE_CLOUD_LOCATION;
|
|
4411
|
+
const useVertexAI = _optionalChain([process, 'access', _75 => _75.env, 'access', _76 => _76.USE_VERTEX_AI, 'optionalAccess', _77 => _77.toLowerCase, 'call', _78 => _78()]) === "true";
|
|
4423
4412
|
if (!useVertexAI && !apiKey) {
|
|
4424
4413
|
throw new Error(
|
|
4425
4414
|
"Google API Key is required. Provide via config or GOOGLE_API_KEY env var."
|
|
@@ -4444,9 +4433,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4444
4433
|
}
|
|
4445
4434
|
this.ai = new (0, _genai.GoogleGenAI)(options);
|
|
4446
4435
|
this.defaultParams = {
|
|
4447
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4448
|
-
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4449
|
-
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4436
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _79 => _79.defaultParams, 'optionalAccess', _80 => _80.temperature]), () => ( 0.7)),
|
|
4437
|
+
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _81 => _81.defaultParams, 'optionalAccess', _82 => _82.top_p]), () => ( 1)),
|
|
4438
|
+
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _83 => _83.defaultParams, 'optionalAccess', _84 => _84.maxOutputTokens]), () => ( 1024))
|
|
4450
4439
|
};
|
|
4451
4440
|
}
|
|
4452
4441
|
/**
|
|
@@ -4584,7 +4573,7 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4584
4573
|
);
|
|
4585
4574
|
parts.push({ text: "" });
|
|
4586
4575
|
}
|
|
4587
|
-
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access',
|
|
4576
|
+
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access', _85 => _85[0], 'optionalAccess', _86 => _86.functionResponse]))) {
|
|
4588
4577
|
console.error(
|
|
4589
4578
|
`[GoogleLLM] convertMessage - Invalid parts for 'function' role. Expected 1 functionResponse part. Got:`,
|
|
4590
4579
|
JSON.stringify(parts),
|
|
@@ -4692,13 +4681,13 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4692
4681
|
role: "assistant",
|
|
4693
4682
|
content: null
|
|
4694
4683
|
});
|
|
4695
|
-
if (typeof _optionalChain([response, 'optionalAccess',
|
|
4684
|
+
if (typeof _optionalChain([response, 'optionalAccess', _87 => _87.candidates, 'optionalAccess', _88 => _88[0], 'optionalAccess', _89 => _89.content, 'optionalAccess', _90 => _90.parts, 'optionalAccess', _91 => _91[0], 'optionalAccess', _92 => _92.text]) === "string") {
|
|
4696
4685
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4697
4686
|
}
|
|
4698
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4687
|
+
if (_optionalChain([response, 'optionalAccess', _93 => _93.candidates, 'optionalAccess', _94 => _94[0], 'optionalAccess', _95 => _95.content, 'optionalAccess', _96 => _96.parts, 'optionalAccess', _97 => _97[0], 'optionalAccess', _98 => _98.text])) {
|
|
4699
4688
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4700
4689
|
}
|
|
4701
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4690
|
+
if (_optionalChain([response, 'optionalAccess', _99 => _99.candidates, 'optionalAccess', _100 => _100[0], 'optionalAccess', _101 => _101.content, 'optionalAccess', _102 => _102.parts, 'optionalAccess', _103 => _103[0], 'optionalAccess', _104 => _104.functionCall])) {
|
|
4702
4691
|
const functionCall = response.candidates[0].content.parts[0].functionCall;
|
|
4703
4692
|
result.function_call = {
|
|
4704
4693
|
name: functionCall.name,
|
|
@@ -4745,10 +4734,10 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4745
4734
|
if (stream) {
|
|
4746
4735
|
const streamingResult = await this.ai.models.generateContentStream(requestOptions);
|
|
4747
4736
|
for await (const chunk of streamingResult) {
|
|
4748
|
-
if (!_optionalChain([chunk, 'access',
|
|
4737
|
+
if (!_optionalChain([chunk, 'access', _105 => _105.candidates, 'optionalAccess', _106 => _106[0], 'optionalAccess', _107 => _107.content, 'optionalAccess', _108 => _108.parts, 'optionalAccess', _109 => _109[0], 'optionalAccess', _110 => _110.text])) {
|
|
4749
4738
|
continue;
|
|
4750
4739
|
}
|
|
4751
|
-
const partialText = _optionalChain([chunk, 'access',
|
|
4740
|
+
const partialText = _optionalChain([chunk, 'access', _111 => _111.candidates, 'access', _112 => _112[0], 'optionalAccess', _113 => _113.content, 'optionalAccess', _114 => _114.parts, 'access', _115 => _115[0], 'optionalAccess', _116 => _116.text]) || "";
|
|
4752
4741
|
const partialResponse = new LLMResponse({
|
|
4753
4742
|
content: partialText,
|
|
4754
4743
|
role: "assistant",
|
|
@@ -4768,10 +4757,11 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4768
4757
|
};
|
|
4769
4758
|
|
|
4770
4759
|
// src/models/openai-llm.ts
|
|
4760
|
+
init_logger();
|
|
4771
4761
|
var _openai = require('openai'); var _openai2 = _interopRequireDefault(_openai);
|
|
4772
4762
|
|
|
4773
4763
|
// src/models/openai-llm-connection.ts
|
|
4774
|
-
var OpenAILLMConnection = (
|
|
4764
|
+
var OpenAILLMConnection = (_class23 = class extends BaseLLMConnection {
|
|
4775
4765
|
/**
|
|
4776
4766
|
* OpenAI client
|
|
4777
4767
|
*/
|
|
@@ -4803,12 +4793,12 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4803
4793
|
/**
|
|
4804
4794
|
* Ongoing chat history
|
|
4805
4795
|
*/
|
|
4806
|
-
|
|
4796
|
+
__init34() {this.messages = []}
|
|
4807
4797
|
/**
|
|
4808
4798
|
* Constructor for OpenAILLMConnection
|
|
4809
4799
|
*/
|
|
4810
4800
|
constructor(client, model, initialRequest, defaultParams) {
|
|
4811
|
-
super();
|
|
4801
|
+
super();_class23.prototype.__init34.call(this);;
|
|
4812
4802
|
this.client = client;
|
|
4813
4803
|
this.model = model;
|
|
4814
4804
|
this.initialRequest = initialRequest;
|
|
@@ -4888,10 +4878,10 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4888
4878
|
for await (const chunk of stream) {
|
|
4889
4879
|
if (chunk.choices.length === 0) continue;
|
|
4890
4880
|
const delta = chunk.choices[0].delta;
|
|
4891
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
4881
|
+
if (_optionalChain([delta, 'optionalAccess', _117 => _117.content])) {
|
|
4892
4882
|
responseContent += delta.content;
|
|
4893
4883
|
}
|
|
4894
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
4884
|
+
if (_optionalChain([delta, 'optionalAccess', _118 => _118.function_call])) {
|
|
4895
4885
|
if (!functionCall) {
|
|
4896
4886
|
functionCall = {
|
|
4897
4887
|
name: delta.function_call.name || "",
|
|
@@ -4902,7 +4892,7 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4902
4892
|
functionCall.arguments += delta.function_call.arguments || "";
|
|
4903
4893
|
}
|
|
4904
4894
|
}
|
|
4905
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
4895
|
+
if (_optionalChain([delta, 'optionalAccess', _119 => _119.tool_calls])) {
|
|
4906
4896
|
for (const toolDelta of delta.tool_calls) {
|
|
4907
4897
|
const id = toolDelta.id || "";
|
|
4908
4898
|
let tool = toolCalls.find((t) => t.id === id);
|
|
@@ -4910,20 +4900,20 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4910
4900
|
tool = {
|
|
4911
4901
|
id,
|
|
4912
4902
|
function: {
|
|
4913
|
-
name: _optionalChain([toolDelta, 'access',
|
|
4914
|
-
arguments: _optionalChain([toolDelta, 'access',
|
|
4903
|
+
name: _optionalChain([toolDelta, 'access', _120 => _120.function, 'optionalAccess', _121 => _121.name]) || "",
|
|
4904
|
+
arguments: _optionalChain([toolDelta, 'access', _122 => _122.function, 'optionalAccess', _123 => _123.arguments]) || ""
|
|
4915
4905
|
}
|
|
4916
4906
|
};
|
|
4917
4907
|
toolCalls.push(tool);
|
|
4918
4908
|
} else {
|
|
4919
|
-
tool.function.name += _optionalChain([toolDelta, 'access',
|
|
4920
|
-
tool.function.arguments += _optionalChain([toolDelta, 'access',
|
|
4909
|
+
tool.function.name += _optionalChain([toolDelta, 'access', _124 => _124.function, 'optionalAccess', _125 => _125.name]) || "";
|
|
4910
|
+
tool.function.arguments += _optionalChain([toolDelta, 'access', _126 => _126.function, 'optionalAccess', _127 => _127.arguments]) || "";
|
|
4921
4911
|
}
|
|
4922
4912
|
}
|
|
4923
4913
|
}
|
|
4924
4914
|
if (this.responseCallback) {
|
|
4925
4915
|
const response = new LLMResponse({
|
|
4926
|
-
content: _optionalChain([delta, 'optionalAccess',
|
|
4916
|
+
content: _optionalChain([delta, 'optionalAccess', _128 => _128.content]) || null,
|
|
4927
4917
|
role: "assistant",
|
|
4928
4918
|
function_call: functionCall,
|
|
4929
4919
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
@@ -5015,10 +5005,10 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
5015
5005
|
onEnd(callback) {
|
|
5016
5006
|
this.endCallback = callback;
|
|
5017
5007
|
}
|
|
5018
|
-
},
|
|
5008
|
+
}, _class23);
|
|
5019
5009
|
|
|
5020
5010
|
// src/models/openai-llm.ts
|
|
5021
|
-
var OpenAILLM = class extends BaseLLM {
|
|
5011
|
+
var OpenAILLM = (_class24 = class extends BaseLLM {
|
|
5022
5012
|
/**
|
|
5023
5013
|
* OpenAI client instance
|
|
5024
5014
|
*/
|
|
@@ -5027,22 +5017,23 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5027
5017
|
* Default parameters for requests
|
|
5028
5018
|
*/
|
|
5029
5019
|
|
|
5020
|
+
__init35() {this.logger = new Logger({ name: "OpenAILLM" })}
|
|
5030
5021
|
/**
|
|
5031
5022
|
* Constructor for OpenAILLM
|
|
5032
5023
|
*/
|
|
5033
5024
|
constructor(model, config) {
|
|
5034
|
-
super(model);
|
|
5025
|
+
super(model);_class24.prototype.__init35.call(this);;
|
|
5035
5026
|
this.client = new (0, _openai2.default)({
|
|
5036
|
-
apiKey: _optionalChain([config, 'optionalAccess',
|
|
5037
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
5038
|
-
organization: _optionalChain([config, 'optionalAccess',
|
|
5027
|
+
apiKey: _optionalChain([config, 'optionalAccess', _129 => _129.apiKey]) || process.env.OPENAI_API_KEY,
|
|
5028
|
+
baseURL: _optionalChain([config, 'optionalAccess', _130 => _130.baseURL]),
|
|
5029
|
+
organization: _optionalChain([config, 'optionalAccess', _131 => _131.organization])
|
|
5039
5030
|
});
|
|
5040
5031
|
this.defaultParams = {
|
|
5041
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5042
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5043
|
-
max_tokens: _optionalChain([config, 'optionalAccess',
|
|
5044
|
-
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5045
|
-
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5032
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _132 => _132.defaultParams, 'optionalAccess', _133 => _133.temperature]), () => ( 0.7)),
|
|
5033
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _134 => _134.defaultParams, 'optionalAccess', _135 => _135.top_p]), () => ( 1)),
|
|
5034
|
+
max_tokens: _optionalChain([config, 'optionalAccess', _136 => _136.defaultParams, 'optionalAccess', _137 => _137.max_tokens]),
|
|
5035
|
+
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _138 => _138.defaultParams, 'optionalAccess', _139 => _139.frequency_penalty]), () => ( 0)),
|
|
5036
|
+
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _140 => _140.defaultParams, 'optionalAccess', _141 => _141.presence_penalty]), () => ( 0))
|
|
5046
5037
|
};
|
|
5047
5038
|
}
|
|
5048
5039
|
/**
|
|
@@ -5152,16 +5143,16 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5152
5143
|
*/
|
|
5153
5144
|
convertResponse(response) {
|
|
5154
5145
|
const result = new LLMResponse({
|
|
5155
|
-
content: _optionalChain([response, 'access',
|
|
5156
|
-
role: _optionalChain([response, 'access',
|
|
5146
|
+
content: _optionalChain([response, 'access', _142 => _142.message, 'optionalAccess', _143 => _143.content]) || null,
|
|
5147
|
+
role: _optionalChain([response, 'access', _144 => _144.message, 'optionalAccess', _145 => _145.role]) || "assistant"
|
|
5157
5148
|
});
|
|
5158
|
-
if (_optionalChain([response, 'access',
|
|
5149
|
+
if (_optionalChain([response, 'access', _146 => _146.message, 'optionalAccess', _147 => _147.function_call])) {
|
|
5159
5150
|
result.function_call = {
|
|
5160
5151
|
name: response.message.function_call.name,
|
|
5161
5152
|
arguments: response.message.function_call.arguments
|
|
5162
5153
|
};
|
|
5163
5154
|
}
|
|
5164
|
-
if (_optionalChain([response, 'access',
|
|
5155
|
+
if (_optionalChain([response, 'access', _148 => _148.message, 'optionalAccess', _149 => _149.tool_calls])) {
|
|
5165
5156
|
result.tool_calls = response.message.tool_calls.map((tool) => ({
|
|
5166
5157
|
id: tool.id,
|
|
5167
5158
|
function: {
|
|
@@ -5176,29 +5167,27 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5176
5167
|
* Convert OpenAI streaming chunk to LLMResponse
|
|
5177
5168
|
*/
|
|
5178
5169
|
convertChunk(chunk) {
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
}
|
|
5184
|
-
const content = _optionalChain([chunk, 'access', _146 => _146.delta, 'optionalAccess', _147 => _147.content]);
|
|
5170
|
+
this.logger.debug(
|
|
5171
|
+
`Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
|
|
5172
|
+
);
|
|
5173
|
+
const content = _optionalChain([chunk, 'access', _150 => _150.delta, 'optionalAccess', _151 => _151.content]);
|
|
5185
5174
|
const result = new LLMResponse({
|
|
5186
5175
|
content: content !== void 0 ? content : null,
|
|
5187
|
-
role: _optionalChain([chunk, 'access',
|
|
5176
|
+
role: _optionalChain([chunk, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.role]) || "assistant",
|
|
5188
5177
|
is_partial: true
|
|
5189
5178
|
});
|
|
5190
|
-
if (_optionalChain([chunk, 'access',
|
|
5179
|
+
if (_optionalChain([chunk, 'access', _154 => _154.delta, 'optionalAccess', _155 => _155.function_call])) {
|
|
5191
5180
|
result.function_call = {
|
|
5192
5181
|
name: chunk.delta.function_call.name || "",
|
|
5193
5182
|
arguments: chunk.delta.function_call.arguments || ""
|
|
5194
5183
|
};
|
|
5195
5184
|
}
|
|
5196
|
-
if (_optionalChain([chunk, 'access',
|
|
5185
|
+
if (_optionalChain([chunk, 'access', _156 => _156.delta, 'optionalAccess', _157 => _157.tool_calls])) {
|
|
5197
5186
|
result.tool_calls = chunk.delta.tool_calls.map((tool) => ({
|
|
5198
5187
|
id: tool.id || "",
|
|
5199
5188
|
function: {
|
|
5200
|
-
name: _optionalChain([tool, 'access',
|
|
5201
|
-
arguments: _optionalChain([tool, 'access',
|
|
5189
|
+
name: _optionalChain([tool, 'access', _158 => _158.function, 'optionalAccess', _159 => _159.name]) || "",
|
|
5190
|
+
arguments: _optionalChain([tool, 'access', _160 => _160.function, 'optionalAccess', _161 => _161.arguments]) || ""
|
|
5202
5191
|
}
|
|
5203
5192
|
}));
|
|
5204
5193
|
}
|
|
@@ -5221,32 +5210,24 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5221
5210
|
presence_penalty: _nullishCoalesce(llmRequest.config.presence_penalty, () => ( this.defaultParams.presence_penalty)),
|
|
5222
5211
|
stream: shouldStream
|
|
5223
5212
|
};
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
);
|
|
5228
|
-
}
|
|
5213
|
+
this.logger.debug(
|
|
5214
|
+
`Request parameters - model: ${params.model}, messages: ${params.messages.length}, functions: ${params.tools ? params.tools.length : 0}, streaming: ${shouldStream}`
|
|
5215
|
+
);
|
|
5229
5216
|
if (tools && tools.length > 0) {
|
|
5230
5217
|
params.tools = tools;
|
|
5231
5218
|
}
|
|
5232
5219
|
try {
|
|
5233
5220
|
if (shouldStream) {
|
|
5234
|
-
|
|
5235
|
-
console.log("OpenAI: Starting streaming request");
|
|
5236
|
-
}
|
|
5221
|
+
this.logger.debug("Starting streaming request");
|
|
5237
5222
|
const streamResponse = await this.client.chat.completions.create(params);
|
|
5238
5223
|
let partialFunctionCall;
|
|
5239
5224
|
const partialToolCalls = /* @__PURE__ */ new Map();
|
|
5240
5225
|
let accumulatedContent = "";
|
|
5241
5226
|
const asyncIterable = streamResponse;
|
|
5242
|
-
|
|
5243
|
-
console.log("OpenAI: Stream response received, processing chunks");
|
|
5244
|
-
}
|
|
5227
|
+
this.logger.debug("Stream response received, processing chunks");
|
|
5245
5228
|
for await (const chunk of asyncIterable) {
|
|
5246
5229
|
if (!chunk.choices || chunk.choices.length === 0) {
|
|
5247
|
-
|
|
5248
|
-
console.log("OpenAI: Empty chunk received, skipping");
|
|
5249
|
-
}
|
|
5230
|
+
this.logger.debug("Empty chunk received, skipping");
|
|
5250
5231
|
continue;
|
|
5251
5232
|
}
|
|
5252
5233
|
const choice = chunk.choices[0];
|
|
@@ -5254,14 +5235,12 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5254
5235
|
if (responseChunk.content !== null) {
|
|
5255
5236
|
accumulatedContent += responseChunk.content;
|
|
5256
5237
|
}
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
);
|
|
5264
|
-
}
|
|
5238
|
+
this.logger.debug(
|
|
5239
|
+
`Chunk received - delta: "${_optionalChain([choice, 'access', _162 => _162.delta, 'optionalAccess', _163 => _163.content]) || ""}"`,
|
|
5240
|
+
`responseChunk content: "${responseChunk.content || ""}"`,
|
|
5241
|
+
`is_partial: ${responseChunk.is_partial}`,
|
|
5242
|
+
`accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
5243
|
+
);
|
|
5265
5244
|
if (responseChunk.function_call) {
|
|
5266
5245
|
if (!partialFunctionCall) {
|
|
5267
5246
|
partialFunctionCall = {
|
|
@@ -5286,37 +5265,27 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5286
5265
|
}
|
|
5287
5266
|
responseChunk.tool_calls = Array.from(partialToolCalls.values());
|
|
5288
5267
|
}
|
|
5289
|
-
|
|
5290
|
-
console.log("OpenAI: Yielding chunk to caller");
|
|
5291
|
-
}
|
|
5268
|
+
this.logger.debug("Yielding chunk to caller");
|
|
5292
5269
|
yield responseChunk;
|
|
5293
5270
|
}
|
|
5294
5271
|
if (accumulatedContent.length > 0) {
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
);
|
|
5299
|
-
}
|
|
5272
|
+
this.logger.debug(
|
|
5273
|
+
`Yielding final accumulated content: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
5274
|
+
);
|
|
5300
5275
|
yield new LLMResponse({
|
|
5301
5276
|
content: accumulatedContent,
|
|
5302
5277
|
role: "assistant",
|
|
5303
5278
|
is_partial: false
|
|
5304
5279
|
});
|
|
5305
5280
|
}
|
|
5306
|
-
|
|
5307
|
-
console.log("OpenAI: Finished processing all stream chunks");
|
|
5308
|
-
}
|
|
5281
|
+
this.logger.debug("Finished processing all stream chunks");
|
|
5309
5282
|
} else {
|
|
5310
|
-
|
|
5311
|
-
console.log("OpenAI: Making non-streaming request");
|
|
5312
|
-
}
|
|
5283
|
+
this.logger.debug("Making non-streaming request");
|
|
5313
5284
|
const response = await this.client.chat.completions.create(params);
|
|
5314
5285
|
if (!response.choices || response.choices.length === 0) {
|
|
5315
5286
|
throw new Error("No response from OpenAI");
|
|
5316
5287
|
}
|
|
5317
|
-
|
|
5318
|
-
console.log("OpenAI: Non-streaming response received");
|
|
5319
|
-
}
|
|
5288
|
+
this.logger.debug("Non-streaming response received");
|
|
5320
5289
|
yield this.convertResponse(response.choices[0]);
|
|
5321
5290
|
}
|
|
5322
5291
|
} catch (error) {
|
|
@@ -5335,7 +5304,7 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5335
5304
|
this.defaultParams
|
|
5336
5305
|
);
|
|
5337
5306
|
}
|
|
5338
|
-
};
|
|
5307
|
+
}, _class24);
|
|
5339
5308
|
|
|
5340
5309
|
// src/models/registry.ts
|
|
5341
5310
|
function registerProviders() {
|
|
@@ -5533,7 +5502,7 @@ var OAuth2Credential = class extends AuthCredential {
|
|
|
5533
5502
|
"Cannot refresh token: no refresh token or refresh function"
|
|
5534
5503
|
);
|
|
5535
5504
|
}
|
|
5536
|
-
const result = await _optionalChain([this, 'access',
|
|
5505
|
+
const result = await _optionalChain([this, 'access', _164 => _164.refreshFunction, 'optionalCall', _165 => _165(this.refreshToken)]);
|
|
5537
5506
|
if (!result) {
|
|
5538
5507
|
throw new Error("Failed to refresh token");
|
|
5539
5508
|
}
|
|
@@ -5587,7 +5556,7 @@ var AuthHandler = class {
|
|
|
5587
5556
|
* Gets the authentication token
|
|
5588
5557
|
*/
|
|
5589
5558
|
getToken() {
|
|
5590
|
-
return _optionalChain([this, 'access',
|
|
5559
|
+
return _optionalChain([this, 'access', _166 => _166.credential, 'optionalAccess', _167 => _167.getToken, 'call', _168 => _168()]);
|
|
5591
5560
|
}
|
|
5592
5561
|
/**
|
|
5593
5562
|
* Gets headers for HTTP requests
|
|
@@ -5602,7 +5571,7 @@ var AuthHandler = class {
|
|
|
5602
5571
|
* Refreshes the token if necessary
|
|
5603
5572
|
*/
|
|
5604
5573
|
async refreshToken() {
|
|
5605
|
-
if (_optionalChain([this, 'access',
|
|
5574
|
+
if (_optionalChain([this, 'access', _169 => _169.credential, 'optionalAccess', _170 => _170.canRefresh, 'call', _171 => _171()])) {
|
|
5606
5575
|
await this.credential.refresh();
|
|
5607
5576
|
}
|
|
5608
5577
|
}
|
|
@@ -5828,7 +5797,7 @@ var InMemoryMemoryService = class {
|
|
|
5828
5797
|
};
|
|
5829
5798
|
const normalizedQuery = query.toLowerCase().trim();
|
|
5830
5799
|
const queryTerms = normalizedQuery.split(/\s+/);
|
|
5831
|
-
const sessionsToSearch = _optionalChain([options, 'optionalAccess',
|
|
5800
|
+
const sessionsToSearch = _optionalChain([options, 'optionalAccess', _172 => _172.sessionId]) ? this.sessions.has(options.sessionId) ? [this.sessions.get(options.sessionId)] : [] : Array.from(this.sessions.values());
|
|
5832
5801
|
for (const session of sessionsToSearch) {
|
|
5833
5802
|
const matchedEvents = [];
|
|
5834
5803
|
const scores = [];
|
|
@@ -5854,7 +5823,7 @@ var InMemoryMemoryService = class {
|
|
|
5854
5823
|
}
|
|
5855
5824
|
}
|
|
5856
5825
|
const score = queryTerms.length > 0 ? termMatches / queryTerms.length : 0;
|
|
5857
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5826
|
+
if (_optionalChain([options, 'optionalAccess', _173 => _173.threshold]) !== void 0 && score < options.threshold) {
|
|
5858
5827
|
continue;
|
|
5859
5828
|
}
|
|
5860
5829
|
if (score > 0) {
|
|
@@ -5874,7 +5843,7 @@ var InMemoryMemoryService = class {
|
|
|
5874
5843
|
response.memories.sort(
|
|
5875
5844
|
(a, b) => (_nullishCoalesce(b.relevanceScore, () => ( 0))) - (_nullishCoalesce(a.relevanceScore, () => ( 0)))
|
|
5876
5845
|
);
|
|
5877
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5846
|
+
if (_optionalChain([options, 'optionalAccess', _174 => _174.limit]) !== void 0 && options.limit > 0) {
|
|
5878
5847
|
response.memories = response.memories.slice(0, options.limit);
|
|
5879
5848
|
}
|
|
5880
5849
|
return response;
|
|
@@ -5903,9 +5872,10 @@ var InMemoryMemoryService = class {
|
|
|
5903
5872
|
};
|
|
5904
5873
|
|
|
5905
5874
|
// src/memory/persistent-memory-service.ts
|
|
5906
|
-
|
|
5875
|
+
init_logger();
|
|
5876
|
+
var _fs = require('fs'); var fs3 = _interopRequireWildcard(_fs);
|
|
5907
5877
|
|
|
5908
|
-
var PersistentMemoryService = class {
|
|
5878
|
+
var PersistentMemoryService = (_class25 = class {
|
|
5909
5879
|
/**
|
|
5910
5880
|
* In-memory service used for search operations
|
|
5911
5881
|
*/
|
|
@@ -5918,15 +5888,16 @@ var PersistentMemoryService = class {
|
|
|
5918
5888
|
* File prefix for memory files
|
|
5919
5889
|
*/
|
|
5920
5890
|
|
|
5891
|
+
__init36() {this.logger = new Logger({ name: "PersistentMemoryService" })}
|
|
5921
5892
|
/**
|
|
5922
5893
|
* Constructor for PersistentMemoryService
|
|
5923
5894
|
*/
|
|
5924
|
-
constructor(config) {
|
|
5895
|
+
constructor(config) {;_class25.prototype.__init36.call(this);
|
|
5925
5896
|
this.inMemoryService = new InMemoryMemoryService();
|
|
5926
5897
|
this.storageDir = config.storageDir;
|
|
5927
5898
|
this.filePrefix = config.filePrefix || "memory";
|
|
5928
|
-
if (config.createDir && !
|
|
5929
|
-
|
|
5899
|
+
if (config.createDir && !fs3.default.existsSync(this.storageDir)) {
|
|
5900
|
+
fs3.default.mkdirSync(this.storageDir, { recursive: true });
|
|
5930
5901
|
}
|
|
5931
5902
|
this.loadMemoryFiles();
|
|
5932
5903
|
}
|
|
@@ -5963,7 +5934,7 @@ var PersistentMemoryService = class {
|
|
|
5963
5934
|
persistedAt: /* @__PURE__ */ new Date()
|
|
5964
5935
|
}
|
|
5965
5936
|
};
|
|
5966
|
-
await
|
|
5937
|
+
await fs3.default.promises.writeFile(
|
|
5967
5938
|
filePath,
|
|
5968
5939
|
JSON.stringify(sessionData, null, 2),
|
|
5969
5940
|
"utf-8"
|
|
@@ -5981,22 +5952,22 @@ var PersistentMemoryService = class {
|
|
|
5981
5952
|
* @returns The file path
|
|
5982
5953
|
*/
|
|
5983
5954
|
getSessionFilePath(sessionId) {
|
|
5984
|
-
return
|
|
5955
|
+
return path3.default.join(this.storageDir, `${this.filePrefix}-${sessionId}.json`);
|
|
5985
5956
|
}
|
|
5986
5957
|
/**
|
|
5987
5958
|
* Loads all memory files from disk
|
|
5988
5959
|
*/
|
|
5989
5960
|
loadMemoryFiles() {
|
|
5990
5961
|
try {
|
|
5991
|
-
if (!
|
|
5962
|
+
if (!fs3.default.existsSync(this.storageDir)) {
|
|
5992
5963
|
return;
|
|
5993
5964
|
}
|
|
5994
|
-
const files =
|
|
5965
|
+
const files = fs3.default.readdirSync(this.storageDir);
|
|
5995
5966
|
for (const file of files) {
|
|
5996
5967
|
if (file.startsWith(this.filePrefix) && file.endsWith(".json")) {
|
|
5997
5968
|
try {
|
|
5998
|
-
const filePath =
|
|
5999
|
-
const content =
|
|
5969
|
+
const filePath = path3.default.join(this.storageDir, file);
|
|
5970
|
+
const content = fs3.default.readFileSync(filePath, "utf-8");
|
|
6000
5971
|
const session = JSON.parse(content);
|
|
6001
5972
|
session.createdAt = new Date(session.createdAt);
|
|
6002
5973
|
session.updatedAt = new Date(session.updatedAt);
|
|
@@ -6006,11 +5977,9 @@ var PersistentMemoryService = class {
|
|
|
6006
5977
|
}
|
|
6007
5978
|
}
|
|
6008
5979
|
}
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
);
|
|
6013
|
-
}
|
|
5980
|
+
this.logger.debug(
|
|
5981
|
+
`Loaded ${this.inMemoryService.getAllSessions().length} sessions from persistent storage`
|
|
5982
|
+
);
|
|
6014
5983
|
} catch (error) {
|
|
6015
5984
|
console.error("Error loading memory files:", error);
|
|
6016
5985
|
}
|
|
@@ -6037,8 +6006,8 @@ var PersistentMemoryService = class {
|
|
|
6037
6006
|
async deleteSession(sessionId) {
|
|
6038
6007
|
const filePath = this.getSessionFilePath(sessionId);
|
|
6039
6008
|
try {
|
|
6040
|
-
if (
|
|
6041
|
-
await
|
|
6009
|
+
if (fs3.default.existsSync(filePath)) {
|
|
6010
|
+
await fs3.default.promises.unlink(filePath);
|
|
6042
6011
|
}
|
|
6043
6012
|
this.inMemoryService.getSession(sessionId);
|
|
6044
6013
|
} catch (error) {
|
|
@@ -6065,7 +6034,7 @@ var PersistentMemoryService = class {
|
|
|
6065
6034
|
);
|
|
6066
6035
|
}
|
|
6067
6036
|
}
|
|
6068
|
-
};
|
|
6037
|
+
}, _class25);
|
|
6069
6038
|
|
|
6070
6039
|
// src/sessions/index.ts
|
|
6071
6040
|
var sessions_exports = {};
|
|
@@ -6074,9 +6043,9 @@ __export(sessions_exports, {
|
|
|
6074
6043
|
PgLiteSessionService: () => PgLiteSessionService,
|
|
6075
6044
|
PostgresSessionService: () => PostgresSessionService,
|
|
6076
6045
|
SessionState: () => SessionState,
|
|
6046
|
+
SqliteSessionService: () => SqliteSessionService,
|
|
6077
6047
|
cloneSession: () => cloneSession,
|
|
6078
6048
|
generateSessionId: () => generateSessionId,
|
|
6079
|
-
sessionsSchema: () => sessionsSchema2,
|
|
6080
6049
|
validateSession: () => validateSession
|
|
6081
6050
|
});
|
|
6082
6051
|
|
|
@@ -6140,17 +6109,17 @@ var InMemorySessionService = class {
|
|
|
6140
6109
|
let sessions = Array.from(this.sessions.values()).filter(
|
|
6141
6110
|
(session) => session.userId === userId
|
|
6142
6111
|
);
|
|
6143
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6112
|
+
if (_optionalChain([options, 'optionalAccess', _175 => _175.createdAfter])) {
|
|
6144
6113
|
sessions = sessions.filter(
|
|
6145
6114
|
(session) => session.createdAt >= options.createdAfter
|
|
6146
6115
|
);
|
|
6147
6116
|
}
|
|
6148
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6117
|
+
if (_optionalChain([options, 'optionalAccess', _176 => _176.updatedAfter])) {
|
|
6149
6118
|
sessions = sessions.filter(
|
|
6150
6119
|
(session) => session.updatedAt >= options.updatedAfter
|
|
6151
6120
|
);
|
|
6152
6121
|
}
|
|
6153
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6122
|
+
if (_optionalChain([options, 'optionalAccess', _177 => _177.metadataFilter])) {
|
|
6154
6123
|
sessions = sessions.filter((session) => {
|
|
6155
6124
|
for (const [key, value] of Object.entries(options.metadataFilter)) {
|
|
6156
6125
|
if (session.metadata[key] !== value) {
|
|
@@ -6161,7 +6130,7 @@ var InMemorySessionService = class {
|
|
|
6161
6130
|
});
|
|
6162
6131
|
}
|
|
6163
6132
|
sessions.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
6164
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6133
|
+
if (_optionalChain([options, 'optionalAccess', _178 => _178.limit]) !== void 0 && options.limit > 0) {
|
|
6165
6134
|
sessions = sessions.slice(0, options.limit);
|
|
6166
6135
|
}
|
|
6167
6136
|
return sessions;
|
|
@@ -6196,7 +6165,7 @@ var InMemorySessionService = class {
|
|
|
6196
6165
|
if (event.is_partial) {
|
|
6197
6166
|
return event;
|
|
6198
6167
|
}
|
|
6199
|
-
if (_optionalChain([event, 'access',
|
|
6168
|
+
if (_optionalChain([event, 'access', _179 => _179.actions, 'optionalAccess', _180 => _180.stateDelta])) {
|
|
6200
6169
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6201
6170
|
if (key.startsWith("_temp_")) {
|
|
6202
6171
|
continue;
|
|
@@ -6302,7 +6271,7 @@ var PostgresSessionService = class {
|
|
|
6302
6271
|
}
|
|
6303
6272
|
async listSessions(userId, options) {
|
|
6304
6273
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6305
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6274
|
+
if (_optionalChain([options, 'optionalAccess', _181 => _181.limit]) !== void 0 && options.limit > 0) {
|
|
6306
6275
|
query = query.limit(options.limit);
|
|
6307
6276
|
}
|
|
6308
6277
|
const results = await query;
|
|
@@ -6329,12 +6298,12 @@ var PostgresSessionService = class {
|
|
|
6329
6298
|
if (event.is_partial) {
|
|
6330
6299
|
return event;
|
|
6331
6300
|
}
|
|
6332
|
-
if (_optionalChain([event, 'access',
|
|
6301
|
+
if (_optionalChain([event, 'access', _182 => _182.actions, 'optionalAccess', _183 => _183.stateDelta])) {
|
|
6333
6302
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6334
6303
|
if (key.startsWith("_temp_")) {
|
|
6335
6304
|
continue;
|
|
6336
6305
|
}
|
|
6337
|
-
_optionalChain([session, 'access',
|
|
6306
|
+
_optionalChain([session, 'access', _184 => _184.state, 'optionalAccess', _185 => _185.set, 'call', _186 => _186(key, value)]);
|
|
6338
6307
|
}
|
|
6339
6308
|
}
|
|
6340
6309
|
if (!session.events) {
|
|
@@ -6365,11 +6334,11 @@ var sessionsSchema2 = _pgcore.pgTable.call(void 0, "sessions", {
|
|
|
6365
6334
|
updatedAt: _pgcore.timestamp.call(void 0, "updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
6366
6335
|
state: _pgcore.jsonb.call(void 0, "state").default("{}").$type()
|
|
6367
6336
|
});
|
|
6368
|
-
var PgLiteSessionService = (
|
|
6337
|
+
var PgLiteSessionService = (_class26 = class {
|
|
6369
6338
|
|
|
6370
6339
|
|
|
6371
|
-
|
|
6372
|
-
constructor(config) {;
|
|
6340
|
+
__init37() {this.initialized = false}
|
|
6341
|
+
constructor(config) {;_class26.prototype.__init37.call(this);
|
|
6373
6342
|
this.db = _pglite.drizzle.call(void 0, config.pglite, {
|
|
6374
6343
|
schema: { sessions: sessionsSchema2 }
|
|
6375
6344
|
});
|
|
@@ -6478,7 +6447,7 @@ var PgLiteSessionService = (_class12 = class {
|
|
|
6478
6447
|
async listSessions(userId, options) {
|
|
6479
6448
|
await this.ensureInitialized();
|
|
6480
6449
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6481
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6450
|
+
if (_optionalChain([options, 'optionalAccess', _187 => _187.limit]) !== void 0 && options.limit > 0) {
|
|
6482
6451
|
query = query.limit(options.limit);
|
|
6483
6452
|
}
|
|
6484
6453
|
const results = await query;
|
|
@@ -6501,12 +6470,12 @@ var PgLiteSessionService = (_class12 = class {
|
|
|
6501
6470
|
if (event.is_partial) {
|
|
6502
6471
|
return event;
|
|
6503
6472
|
}
|
|
6504
|
-
if (_optionalChain([event, 'access',
|
|
6473
|
+
if (_optionalChain([event, 'access', _188 => _188.actions, 'optionalAccess', _189 => _189.stateDelta])) {
|
|
6505
6474
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6506
6475
|
if (key.startsWith("_temp_")) {
|
|
6507
6476
|
continue;
|
|
6508
6477
|
}
|
|
6509
|
-
_optionalChain([session, 'access',
|
|
6478
|
+
_optionalChain([session, 'access', _190 => _190.state, 'optionalAccess', _191 => _191.set, 'call', _192 => _192(key, value)]);
|
|
6510
6479
|
}
|
|
6511
6480
|
}
|
|
6512
6481
|
if (!session.events) {
|
|
@@ -6517,7 +6486,192 @@ var PgLiteSessionService = (_class12 = class {
|
|
|
6517
6486
|
await this.updateSession(session);
|
|
6518
6487
|
return event;
|
|
6519
6488
|
}
|
|
6520
|
-
},
|
|
6489
|
+
}, _class26);
|
|
6490
|
+
|
|
6491
|
+
// src/sessions/sqlite-session-service.ts
|
|
6492
|
+
|
|
6493
|
+
|
|
6494
|
+
|
|
6495
|
+
|
|
6496
|
+
|
|
6497
|
+
var _bettersqlite3 = require('drizzle-orm/better-sqlite3');
|
|
6498
|
+
var _sqlitecore = require('drizzle-orm/sqlite-core');
|
|
6499
|
+
|
|
6500
|
+
var sessionsSchema3 = _sqlitecore.sqliteTable.call(void 0, "sessions", {
|
|
6501
|
+
id: _sqlitecore.text.call(void 0, "id").primaryKey(),
|
|
6502
|
+
userId: _sqlitecore.text.call(void 0, "user_id").notNull(),
|
|
6503
|
+
messages: _sqlitecore.text.call(void 0, "messages", { mode: "json" }).default("[]").$type(),
|
|
6504
|
+
metadata: _sqlitecore.text.call(void 0, "metadata", { mode: "json" }).default("{}").$type(),
|
|
6505
|
+
createdAt: _sqlitecore.integer.call(void 0, "created_at", { mode: "timestamp" }).notNull(),
|
|
6506
|
+
updatedAt: _sqlitecore.integer.call(void 0, "updated_at", { mode: "timestamp" }).notNull(),
|
|
6507
|
+
state: _sqlitecore.text.call(void 0, "state", { mode: "json" }).default("{}").$type()
|
|
6508
|
+
});
|
|
6509
|
+
var SqliteSessionService = (_class27 = class {
|
|
6510
|
+
|
|
6511
|
+
|
|
6512
|
+
__init38() {this.initialized = false}
|
|
6513
|
+
|
|
6514
|
+
constructor(config) {;_class27.prototype.__init38.call(this);
|
|
6515
|
+
this.sqliteInstance = config.sqlite;
|
|
6516
|
+
const dbPath = this.sqliteInstance.name;
|
|
6517
|
+
if (dbPath && dbPath !== ":memory:") {
|
|
6518
|
+
const dbDir = path3.dirname(dbPath);
|
|
6519
|
+
if (!fs3.existsSync(dbDir)) {
|
|
6520
|
+
fs3.mkdirSync(dbDir, { recursive: true });
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
this.db = _bettersqlite3.drizzle.call(void 0, config.sqlite, {
|
|
6524
|
+
schema: { sessions: sessionsSchema3 }
|
|
6525
|
+
});
|
|
6526
|
+
this.sessionsTable = sessionsSchema3;
|
|
6527
|
+
if (!config.skipTableCreation) {
|
|
6528
|
+
this.initializeDatabase().catch((error) => {
|
|
6529
|
+
console.error("Failed to initialize SQLite database:", error);
|
|
6530
|
+
});
|
|
6531
|
+
}
|
|
6532
|
+
}
|
|
6533
|
+
/**
|
|
6534
|
+
* Initialize the database by creating required tables if they don't exist
|
|
6535
|
+
*/
|
|
6536
|
+
async initializeDatabase() {
|
|
6537
|
+
if (this.initialized) {
|
|
6538
|
+
return;
|
|
6539
|
+
}
|
|
6540
|
+
try {
|
|
6541
|
+
this.sqliteInstance.pragma("journal_mode = WAL");
|
|
6542
|
+
this.sqliteInstance.exec(`
|
|
6543
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
6544
|
+
id TEXT PRIMARY KEY,
|
|
6545
|
+
user_id TEXT NOT NULL,
|
|
6546
|
+
messages TEXT DEFAULT '[]',
|
|
6547
|
+
metadata TEXT DEFAULT '{}',
|
|
6548
|
+
created_at INTEGER NOT NULL,
|
|
6549
|
+
updated_at INTEGER NOT NULL,
|
|
6550
|
+
state TEXT DEFAULT '{}'
|
|
6551
|
+
);
|
|
6552
|
+
`);
|
|
6553
|
+
this.sqliteInstance.exec(`
|
|
6554
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
|
|
6555
|
+
`);
|
|
6556
|
+
this.initialized = true;
|
|
6557
|
+
} catch (error) {
|
|
6558
|
+
console.error("Error initializing SQLite database:", error);
|
|
6559
|
+
throw error;
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
/**
|
|
6563
|
+
* Ensure database is initialized before any operation
|
|
6564
|
+
*/
|
|
6565
|
+
async ensureInitialized() {
|
|
6566
|
+
if (!this.initialized) {
|
|
6567
|
+
await this.initializeDatabase();
|
|
6568
|
+
}
|
|
6569
|
+
}
|
|
6570
|
+
generateSessionId() {
|
|
6571
|
+
return `session-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
6572
|
+
}
|
|
6573
|
+
async createSession(userId, metadata = {}) {
|
|
6574
|
+
await this.ensureInitialized();
|
|
6575
|
+
const sessionId = this.generateSessionId();
|
|
6576
|
+
const now = /* @__PURE__ */ new Date();
|
|
6577
|
+
const sessionState = new SessionState();
|
|
6578
|
+
const newSessionData = {
|
|
6579
|
+
id: sessionId,
|
|
6580
|
+
userId,
|
|
6581
|
+
messages: [],
|
|
6582
|
+
metadata,
|
|
6583
|
+
createdAt: now,
|
|
6584
|
+
updatedAt: now,
|
|
6585
|
+
state: sessionState.toObject()
|
|
6586
|
+
};
|
|
6587
|
+
const results = await this.db.insert(this.sessionsTable).values(newSessionData).returning();
|
|
6588
|
+
const result = results[0];
|
|
6589
|
+
if (!result) {
|
|
6590
|
+
throw new Error(
|
|
6591
|
+
"Failed to create session, no data returned from insert."
|
|
6592
|
+
);
|
|
6593
|
+
}
|
|
6594
|
+
return {
|
|
6595
|
+
id: result.id,
|
|
6596
|
+
userId: result.userId,
|
|
6597
|
+
messages: Array.isArray(result.messages) ? result.messages : [],
|
|
6598
|
+
metadata: result.metadata || {},
|
|
6599
|
+
state: SessionState.fromObject(result.state || {}),
|
|
6600
|
+
createdAt: result.createdAt,
|
|
6601
|
+
updatedAt: result.updatedAt
|
|
6602
|
+
};
|
|
6603
|
+
}
|
|
6604
|
+
async getSession(sessionId) {
|
|
6605
|
+
await this.ensureInitialized();
|
|
6606
|
+
const results = await this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.id, sessionId)).limit(1);
|
|
6607
|
+
const sessionData = results[0];
|
|
6608
|
+
if (!sessionData) {
|
|
6609
|
+
return void 0;
|
|
6610
|
+
}
|
|
6611
|
+
return {
|
|
6612
|
+
id: sessionData.id,
|
|
6613
|
+
userId: sessionData.userId,
|
|
6614
|
+
messages: Array.isArray(sessionData.messages) ? sessionData.messages : [],
|
|
6615
|
+
metadata: sessionData.metadata || {},
|
|
6616
|
+
state: SessionState.fromObject(sessionData.state || {}),
|
|
6617
|
+
createdAt: sessionData.createdAt,
|
|
6618
|
+
updatedAt: sessionData.updatedAt
|
|
6619
|
+
};
|
|
6620
|
+
}
|
|
6621
|
+
async updateSession(session) {
|
|
6622
|
+
await this.ensureInitialized();
|
|
6623
|
+
const updateData = {
|
|
6624
|
+
userId: session.userId,
|
|
6625
|
+
messages: session.messages,
|
|
6626
|
+
metadata: session.metadata,
|
|
6627
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
6628
|
+
state: session.state.toObject()
|
|
6629
|
+
};
|
|
6630
|
+
await this.db.update(this.sessionsTable).set(updateData).where(_drizzleorm.eq.call(void 0, this.sessionsTable.id, session.id));
|
|
6631
|
+
}
|
|
6632
|
+
async listSessions(userId, options) {
|
|
6633
|
+
await this.ensureInitialized();
|
|
6634
|
+
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6635
|
+
if (_optionalChain([options, 'optionalAccess', _193 => _193.limit]) !== void 0 && options.limit > 0) {
|
|
6636
|
+
query = query.limit(options.limit);
|
|
6637
|
+
}
|
|
6638
|
+
const results = await query;
|
|
6639
|
+
return results.map((sessionData) => ({
|
|
6640
|
+
id: sessionData.id,
|
|
6641
|
+
userId: sessionData.userId,
|
|
6642
|
+
messages: Array.isArray(sessionData.messages) ? sessionData.messages : [],
|
|
6643
|
+
metadata: sessionData.metadata || {},
|
|
6644
|
+
state: SessionState.fromObject(sessionData.state || {}),
|
|
6645
|
+
createdAt: sessionData.createdAt,
|
|
6646
|
+
updatedAt: sessionData.updatedAt
|
|
6647
|
+
}));
|
|
6648
|
+
}
|
|
6649
|
+
async deleteSession(sessionId) {
|
|
6650
|
+
await this.ensureInitialized();
|
|
6651
|
+
await this.db.delete(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.id, sessionId));
|
|
6652
|
+
}
|
|
6653
|
+
async appendEvent(session, event) {
|
|
6654
|
+
await this.ensureInitialized();
|
|
6655
|
+
if (event.is_partial) {
|
|
6656
|
+
return event;
|
|
6657
|
+
}
|
|
6658
|
+
if (_optionalChain([event, 'access', _194 => _194.actions, 'optionalAccess', _195 => _195.stateDelta])) {
|
|
6659
|
+
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6660
|
+
if (key.startsWith("_temp_")) {
|
|
6661
|
+
continue;
|
|
6662
|
+
}
|
|
6663
|
+
_optionalChain([session, 'access', _196 => _196.state, 'optionalAccess', _197 => _197.set, 'call', _198 => _198(key, value)]);
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
if (!session.events) {
|
|
6667
|
+
session.events = [];
|
|
6668
|
+
}
|
|
6669
|
+
session.events.push(event);
|
|
6670
|
+
session.updatedAt = /* @__PURE__ */ new Date();
|
|
6671
|
+
await this.updateSession(session);
|
|
6672
|
+
return event;
|
|
6673
|
+
}
|
|
6674
|
+
}, _class27);
|
|
6521
6675
|
|
|
6522
6676
|
// src/sessions/session-util.ts
|
|
6523
6677
|
function generateSessionId() {
|
|
@@ -6553,7 +6707,7 @@ function cloneSession(session) {
|
|
|
6553
6707
|
var _uuid = require('uuid');
|
|
6554
6708
|
|
|
6555
6709
|
// src/events/event-actions.ts
|
|
6556
|
-
var EventActions = (
|
|
6710
|
+
var EventActions = (_class28 = class {
|
|
6557
6711
|
/**
|
|
6558
6712
|
* If true, it won't call model to summarize function response.
|
|
6559
6713
|
* Only used for function_response event.
|
|
@@ -6562,12 +6716,12 @@ var EventActions = (_class13 = class {
|
|
|
6562
6716
|
/**
|
|
6563
6717
|
* Indicates that the event is updating the state with the given delta.
|
|
6564
6718
|
*/
|
|
6565
|
-
|
|
6719
|
+
__init39() {this.stateDelta = {}}
|
|
6566
6720
|
/**
|
|
6567
6721
|
* Indicates that the event is updating an artifact. key is the filename,
|
|
6568
6722
|
* value is the version.
|
|
6569
6723
|
*/
|
|
6570
|
-
|
|
6724
|
+
__init40() {this.artifactDelta = {}}
|
|
6571
6725
|
/**
|
|
6572
6726
|
* If set, the event transfers to the specified agent.
|
|
6573
6727
|
*/
|
|
@@ -6579,21 +6733,21 @@ var EventActions = (_class13 = class {
|
|
|
6579
6733
|
/**
|
|
6580
6734
|
* Constructor for EventActions
|
|
6581
6735
|
*/
|
|
6582
|
-
constructor(options = {}) {;
|
|
6736
|
+
constructor(options = {}) {;_class28.prototype.__init39.call(this);_class28.prototype.__init40.call(this);
|
|
6583
6737
|
this.skipSummarization = options.skipSummarization;
|
|
6584
6738
|
this.stateDelta = options.stateDelta || {};
|
|
6585
6739
|
this.artifactDelta = options.artifactDelta || {};
|
|
6586
6740
|
this.transferToAgent = options.transferToAgent;
|
|
6587
6741
|
this.escalate = options.escalate;
|
|
6588
6742
|
}
|
|
6589
|
-
},
|
|
6743
|
+
}, _class28);
|
|
6590
6744
|
|
|
6591
6745
|
// src/events/event.ts
|
|
6592
|
-
var Event = (
|
|
6746
|
+
var Event = (_class29 = class _Event extends LLMResponse {
|
|
6593
6747
|
/**
|
|
6594
6748
|
* The invocation ID of the event.
|
|
6595
6749
|
*/
|
|
6596
|
-
|
|
6750
|
+
__init41() {this.invocationId = ""}
|
|
6597
6751
|
/**
|
|
6598
6752
|
* 'user' or the name of the agent, indicating who appended the event to the session.
|
|
6599
6753
|
*/
|
|
@@ -6601,7 +6755,7 @@ var Event = (_class14 = class _Event extends LLMResponse {
|
|
|
6601
6755
|
/**
|
|
6602
6756
|
* The actions taken by the agent.
|
|
6603
6757
|
*/
|
|
6604
|
-
|
|
6758
|
+
__init42() {this.actions = new EventActions()}
|
|
6605
6759
|
/**
|
|
6606
6760
|
* Set of ids of the long running function calls.
|
|
6607
6761
|
* Agent client will know from this field about which function call is long running.
|
|
@@ -6619,7 +6773,7 @@ var Event = (_class14 = class _Event extends LLMResponse {
|
|
|
6619
6773
|
/**
|
|
6620
6774
|
* The unique identifier of the event.
|
|
6621
6775
|
*/
|
|
6622
|
-
|
|
6776
|
+
__init43() {this.id = ""}
|
|
6623
6777
|
/**
|
|
6624
6778
|
* The timestamp of the event.
|
|
6625
6779
|
*/
|
|
@@ -6649,7 +6803,7 @@ var Event = (_class14 = class _Event extends LLMResponse {
|
|
|
6649
6803
|
role,
|
|
6650
6804
|
is_partial: partial,
|
|
6651
6805
|
raw_response
|
|
6652
|
-
});
|
|
6806
|
+
});_class29.prototype.__init41.call(this);_class29.prototype.__init42.call(this);_class29.prototype.__init43.call(this);;
|
|
6653
6807
|
this.invocationId = invocationId;
|
|
6654
6808
|
this.author = author;
|
|
6655
6809
|
this.actions = actions;
|
|
@@ -6683,7 +6837,7 @@ var Event = (_class14 = class _Event extends LLMResponse {
|
|
|
6683
6837
|
static newId() {
|
|
6684
6838
|
return _uuid.v4.call(void 0, ).substring(0, 8);
|
|
6685
6839
|
}
|
|
6686
|
-
},
|
|
6840
|
+
}, _class29);
|
|
6687
6841
|
|
|
6688
6842
|
// src/runners.ts
|
|
6689
6843
|
var Runner = class {
|
|
@@ -6904,4 +7058,4 @@ var VERSION = "0.1.0";
|
|
|
6904
7058
|
|
|
6905
7059
|
|
|
6906
7060
|
|
|
6907
|
-
exports.Agent = Agent; exports.Agents = agents_exports; exports.AnthropicLLM = AnthropicLLM; exports.AnthropicLLMConnection = AnthropicLLMConnection; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.BaseAgent = BaseAgent; exports.BaseLLM = BaseLLM; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FunctionTool = FunctionTool; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLLM = GoogleLLM; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LLMRequest = LLMRequest; exports.LLMResponse = LLMResponse; exports.LangGraphAgent = LangGraphAgent; exports.LoadMemoryTool = LoadMemoryTool; exports.LoopAgent = LoopAgent; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpToolset = McpToolset; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAILLM = OpenAILLM; exports.OpenAILLMConnection = OpenAILLMConnection; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PersistentMemoryService = PersistentMemoryService; exports.PgLiteSessionService = PgLiteSessionService; exports.PostgresSessionService = PostgresSessionService; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SequentialAgent = SequentialAgent; exports.SessionState = SessionState; exports.Sessions = sessions_exports; exports.StreamingMode = StreamingMode; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.adkToMcpToolType = adkToMcpToolType; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.cloneSession = cloneSession; exports.createFunctionTool = createFunctionTool; exports.generateSessionId = generateSessionId; exports.getMcpTools = getMcpTools; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.normalizeJsonSchema = normalizeJsonSchema; exports.registerProviders = registerProviders; exports.
|
|
7061
|
+
exports.Agent = Agent; exports.Agents = agents_exports; exports.AnthropicLLM = AnthropicLLM; exports.AnthropicLLMConnection = AnthropicLLMConnection; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.BaseAgent = BaseAgent; exports.BaseLLM = BaseLLM; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FunctionTool = FunctionTool; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLLM = GoogleLLM; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LLMRequest = LLMRequest; exports.LLMResponse = LLMResponse; exports.LangGraphAgent = LangGraphAgent; exports.LoadMemoryTool = LoadMemoryTool; exports.LoopAgent = LoopAgent; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpToolset = McpToolset; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAILLM = OpenAILLM; exports.OpenAILLMConnection = OpenAILLMConnection; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PersistentMemoryService = PersistentMemoryService; exports.PgLiteSessionService = PgLiteSessionService; exports.PostgresSessionService = PostgresSessionService; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SequentialAgent = SequentialAgent; exports.SessionState = SessionState; exports.Sessions = sessions_exports; exports.SqliteSessionService = SqliteSessionService; exports.StreamingMode = StreamingMode; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.adkToMcpToolType = adkToMcpToolType; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.cloneSession = cloneSession; exports.createFunctionTool = createFunctionTool; exports.generateSessionId = generateSessionId; exports.getMcpTools = getMcpTools; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.normalizeJsonSchema = normalizeJsonSchema; exports.registerProviders = registerProviders; exports.validateSession = validateSession;
|