@iqai/adk 0.0.6 → 0.0.8
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 +4 -4
- package/README.md +177 -0
- package/dist/index.d.mts +69 -5
- package/dist/index.d.ts +69 -5
- package/dist/index.js +585 -365
- package/dist/index.mjs +401 -181
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 __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 _class30;var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -19,28 +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/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}
|
|
33
40
|
}
|
|
34
|
-
|
|
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);
|
|
35
54
|
}
|
|
36
55
|
});
|
|
37
56
|
|
|
38
57
|
// src/tools/base/base-tool.ts
|
|
39
|
-
var BaseTool;
|
|
58
|
+
var logger2, BaseTool;
|
|
40
59
|
var init_base_tool = __esm({
|
|
41
60
|
"src/tools/base/base-tool.ts"() {
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
init_logger();
|
|
62
|
+
logger2 = new Logger({ name: "BaseTool" });
|
|
63
|
+
BaseTool = exports.BaseTool = (_class2 = class {
|
|
44
64
|
/**
|
|
45
65
|
* Name of the tool
|
|
46
66
|
*/
|
|
@@ -64,15 +84,15 @@ var init_base_tool = __esm({
|
|
|
64
84
|
/**
|
|
65
85
|
* Base delay for retry in ms (will be used with exponential backoff)
|
|
66
86
|
*/
|
|
67
|
-
|
|
87
|
+
__init3() {this.baseRetryDelay = 1e3}
|
|
68
88
|
/**
|
|
69
89
|
* Maximum delay for retry in ms
|
|
70
90
|
*/
|
|
71
|
-
|
|
91
|
+
__init4() {this.maxRetryDelay = 1e4}
|
|
72
92
|
/**
|
|
73
93
|
* Constructor for BaseTool
|
|
74
94
|
*/
|
|
75
|
-
constructor(config) {;
|
|
95
|
+
constructor(config) {;_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);
|
|
76
96
|
this.name = config.name;
|
|
77
97
|
this.description = config.description;
|
|
78
98
|
this.isLongRunning = config.isLongRunning || false;
|
|
@@ -129,8 +149,8 @@ var init_base_tool = __esm({
|
|
|
129
149
|
while (attempts <= (this.shouldRetryOnFailure ? this.maxRetryAttempts : 0)) {
|
|
130
150
|
try {
|
|
131
151
|
if (attempts > 0) {
|
|
132
|
-
|
|
133
|
-
`
|
|
152
|
+
logger2.debug(
|
|
153
|
+
`Retrying tool ${this.name} (attempt ${attempts} of ${this.maxRetryAttempts})...`
|
|
134
154
|
);
|
|
135
155
|
const delay = Math.min(
|
|
136
156
|
this.baseRetryDelay * 2 ** (attempts - 1) + Math.random() * 1e3,
|
|
@@ -152,7 +172,7 @@ var init_base_tool = __esm({
|
|
|
152
172
|
tool: this.name
|
|
153
173
|
};
|
|
154
174
|
}
|
|
155
|
-
},
|
|
175
|
+
}, _class2);
|
|
156
176
|
}
|
|
157
177
|
});
|
|
158
178
|
|
|
@@ -278,9 +298,9 @@ var init_function_tool = __esm({
|
|
|
278
298
|
"src/tools/function/function-tool.ts"() {
|
|
279
299
|
init_base_tool();
|
|
280
300
|
init_function_utils();
|
|
281
|
-
FunctionTool = exports.FunctionTool = (
|
|
301
|
+
FunctionTool = exports.FunctionTool = (_class3 = class extends BaseTool {
|
|
282
302
|
|
|
283
|
-
|
|
303
|
+
__init5() {this.mandatoryArgs = []}
|
|
284
304
|
/**
|
|
285
305
|
* Creates a new FunctionTool wrapping the provided function.
|
|
286
306
|
*
|
|
@@ -296,7 +316,7 @@ var init_function_tool = __esm({
|
|
|
296
316
|
isLongRunning: _optionalChain([options, 'optionalAccess', _8 => _8.isLongRunning]) || false,
|
|
297
317
|
shouldRetryOnFailure: _optionalChain([options, 'optionalAccess', _9 => _9.shouldRetryOnFailure]) || false,
|
|
298
318
|
maxRetryAttempts: _optionalChain([options, 'optionalAccess', _10 => _10.maxRetryAttempts]) || 3
|
|
299
|
-
});
|
|
319
|
+
});_class3.prototype.__init5.call(this);;
|
|
300
320
|
this.func = func;
|
|
301
321
|
this.mandatoryArgs = this.getMandatoryArgs(func);
|
|
302
322
|
}
|
|
@@ -372,7 +392,7 @@ You could retry calling this tool, but it is IMPORTANT for you to provide all th
|
|
|
372
392
|
getMissingMandatoryArgs(args) {
|
|
373
393
|
return this.mandatoryArgs.filter((arg) => !(arg in args));
|
|
374
394
|
}
|
|
375
|
-
},
|
|
395
|
+
}, _class3);
|
|
376
396
|
}
|
|
377
397
|
});
|
|
378
398
|
|
|
@@ -475,11 +495,12 @@ var BaseAgent = class {
|
|
|
475
495
|
};
|
|
476
496
|
|
|
477
497
|
// src/agents/llm-agent.ts
|
|
478
|
-
|
|
498
|
+
init_logger();
|
|
479
499
|
|
|
480
500
|
// src/models/llm-registry.ts
|
|
481
|
-
|
|
482
|
-
var
|
|
501
|
+
init_logger();
|
|
502
|
+
var logger = new Logger({ name: "LLMRegistry" });
|
|
503
|
+
var LLMRegistry = (_class4 = class _LLMRegistry {
|
|
483
504
|
/**
|
|
484
505
|
* Map of model name regex to LLM class
|
|
485
506
|
*/
|
|
@@ -535,12 +556,12 @@ var LLMRegistry = (_class3 = class _LLMRegistry {
|
|
|
535
556
|
* Logs all registered models for debugging
|
|
536
557
|
*/
|
|
537
558
|
static logRegisteredModels() {
|
|
538
|
-
|
|
559
|
+
logger.debug(
|
|
539
560
|
"Registered LLM models:",
|
|
540
561
|
[..._LLMRegistry.llmRegistry.entries()].map(([regex]) => regex.toString())
|
|
541
562
|
);
|
|
542
563
|
}
|
|
543
|
-
},
|
|
564
|
+
}, _class4.__initStatic(), _class4);
|
|
544
565
|
|
|
545
566
|
// src/models/llm-request.ts
|
|
546
567
|
var LLMRequest = class {
|
|
@@ -559,7 +580,7 @@ var LLMRequest = class {
|
|
|
559
580
|
};
|
|
560
581
|
|
|
561
582
|
// src/tools/tool-context.ts
|
|
562
|
-
var ToolContext = (
|
|
583
|
+
var ToolContext = (_class5 = class {
|
|
563
584
|
/**
|
|
564
585
|
* The parent invocation context
|
|
565
586
|
*/
|
|
@@ -575,11 +596,11 @@ var ToolContext = (_class4 = class {
|
|
|
575
596
|
/**
|
|
576
597
|
* Tool name
|
|
577
598
|
*/
|
|
578
|
-
|
|
599
|
+
__init6() {this.toolName = ""}
|
|
579
600
|
/**
|
|
580
601
|
* Tool ID
|
|
581
602
|
*/
|
|
582
|
-
|
|
603
|
+
__init7() {this.toolId = ""}
|
|
583
604
|
/**
|
|
584
605
|
* Variables stored in the context
|
|
585
606
|
*/
|
|
@@ -587,7 +608,7 @@ var ToolContext = (_class4 = class {
|
|
|
587
608
|
/**
|
|
588
609
|
* Constructor for ToolContext
|
|
589
610
|
*/
|
|
590
|
-
constructor(options) {;
|
|
611
|
+
constructor(options) {;_class5.prototype.__init6.call(this);_class5.prototype.__init7.call(this);
|
|
591
612
|
this.invocationContext = options.invocationContext;
|
|
592
613
|
this.auth = options.auth;
|
|
593
614
|
this.parameters = options.parameters || {};
|
|
@@ -653,7 +674,7 @@ var ToolContext = (_class4 = class {
|
|
|
653
674
|
async searchMemory(query, options) {
|
|
654
675
|
return this.invocationContext.searchMemory(query, options);
|
|
655
676
|
}
|
|
656
|
-
},
|
|
677
|
+
}, _class5);
|
|
657
678
|
|
|
658
679
|
// src/agents/run-config.ts
|
|
659
680
|
var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
@@ -705,7 +726,7 @@ var RunConfig = class {
|
|
|
705
726
|
};
|
|
706
727
|
|
|
707
728
|
// src/agents/invocation-context.ts
|
|
708
|
-
var InvocationContext = (
|
|
729
|
+
var InvocationContext = (_class6 = class _InvocationContext {
|
|
709
730
|
/**
|
|
710
731
|
* Unique session ID for the current conversation
|
|
711
732
|
*/
|
|
@@ -745,11 +766,11 @@ var InvocationContext = (_class5 = class _InvocationContext {
|
|
|
745
766
|
/**
|
|
746
767
|
* In-memory storage for node execution results
|
|
747
768
|
*/
|
|
748
|
-
|
|
769
|
+
__init8() {this.memory = /* @__PURE__ */ new Map()}
|
|
749
770
|
/**
|
|
750
771
|
* Constructor for InvocationContext
|
|
751
772
|
*/
|
|
752
|
-
constructor(options = {}) {;
|
|
773
|
+
constructor(options = {}) {;_class6.prototype.__init8.call(this);
|
|
753
774
|
this.sessionId = options.sessionId || this.generateSessionId();
|
|
754
775
|
this.messages = options.messages || [];
|
|
755
776
|
this.config = options.config || new RunConfig();
|
|
@@ -852,10 +873,10 @@ var InvocationContext = (_class5 = class _InvocationContext {
|
|
|
852
873
|
};
|
|
853
874
|
return await this.memoryService.searchMemory(query, searchOptions);
|
|
854
875
|
}
|
|
855
|
-
},
|
|
876
|
+
}, _class6);
|
|
856
877
|
|
|
857
878
|
// src/agents/llm-agent.ts
|
|
858
|
-
var Agent = class extends BaseAgent {
|
|
879
|
+
var Agent = (_class7 = class extends BaseAgent {
|
|
859
880
|
/**
|
|
860
881
|
* The LLM model to use
|
|
861
882
|
*/
|
|
@@ -904,6 +925,7 @@ var Agent = class extends BaseAgent {
|
|
|
904
925
|
* The minimum relevance score for memory augmentation (0-1)
|
|
905
926
|
*/
|
|
906
927
|
|
|
928
|
+
__init9() {this.logger = new Logger({ name: "LlmAgent" })}
|
|
907
929
|
/**
|
|
908
930
|
* Constructor for Agent
|
|
909
931
|
*/
|
|
@@ -911,7 +933,7 @@ var Agent = class extends BaseAgent {
|
|
|
911
933
|
super({
|
|
912
934
|
name: config.name,
|
|
913
935
|
description: config.description
|
|
914
|
-
});
|
|
936
|
+
});_class7.prototype.__init9.call(this);;
|
|
915
937
|
this.model = config.model;
|
|
916
938
|
this.instructions = config.instructions;
|
|
917
939
|
this.tools = config.tools || [];
|
|
@@ -936,7 +958,7 @@ var Agent = class extends BaseAgent {
|
|
|
936
958
|
*/
|
|
937
959
|
async executeTool(toolCall, context) {
|
|
938
960
|
const { name, arguments: argsString } = toolCall.function;
|
|
939
|
-
|
|
961
|
+
this.logger.debug(`Executing tool: ${name}`);
|
|
940
962
|
const tool = this.findTool(name);
|
|
941
963
|
if (!tool) {
|
|
942
964
|
console.warn(`Tool '${name}' not found`);
|
|
@@ -954,7 +976,7 @@ var Agent = class extends BaseAgent {
|
|
|
954
976
|
toolContext.toolName = name;
|
|
955
977
|
toolContext.toolId = toolCall.id;
|
|
956
978
|
const result = await tool.runAsync(args, toolContext);
|
|
957
|
-
|
|
979
|
+
this.logger.debug(`Tool ${name} execution complete`);
|
|
958
980
|
return {
|
|
959
981
|
name,
|
|
960
982
|
result: typeof result === "string" ? result : JSON.stringify(result)
|
|
@@ -1123,7 +1145,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1123
1145
|
let stepCount = 0;
|
|
1124
1146
|
while (stepCount < this.maxToolExecutionSteps) {
|
|
1125
1147
|
stepCount++;
|
|
1126
|
-
|
|
1148
|
+
this.logger.debug(`Step ${stepCount}: Thinking...`);
|
|
1127
1149
|
const llmRequest = new LLMRequest({
|
|
1128
1150
|
messages: context.messages,
|
|
1129
1151
|
config: {
|
|
@@ -1140,7 +1162,9 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1140
1162
|
throw new Error("No response from LLM");
|
|
1141
1163
|
}
|
|
1142
1164
|
if (currentResponse.tool_calls && currentResponse.tool_calls.length > 0) {
|
|
1143
|
-
|
|
1165
|
+
this.logger.debug(
|
|
1166
|
+
`Tool calls: ${JSON.stringify(currentResponse.tool_calls)}`
|
|
1167
|
+
);
|
|
1144
1168
|
context.addMessage({
|
|
1145
1169
|
role: "assistant",
|
|
1146
1170
|
content: currentResponse.content || "",
|
|
@@ -1159,7 +1183,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1159
1183
|
});
|
|
1160
1184
|
}
|
|
1161
1185
|
} else {
|
|
1162
|
-
|
|
1186
|
+
this.logger.debug("No tool calls, finishing...");
|
|
1163
1187
|
context.addMessage({
|
|
1164
1188
|
role: "assistant",
|
|
1165
1189
|
content: currentResponse.content || ""
|
|
@@ -1197,7 +1221,7 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1197
1221
|
let stepCount = 0;
|
|
1198
1222
|
let hadToolCalls = false;
|
|
1199
1223
|
while (stepCount < this.maxToolExecutionSteps) {
|
|
1200
|
-
|
|
1224
|
+
this.logger.debug(`Step ${stepCount}: Thinking...`);
|
|
1201
1225
|
const toolDeclarations = this.tools.map((tool) => tool.getDeclaration()).filter((declaration) => declaration !== null);
|
|
1202
1226
|
const request = {
|
|
1203
1227
|
messages: context.messages,
|
|
@@ -1226,10 +1250,10 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1226
1250
|
function_call: finalResponse.function_call
|
|
1227
1251
|
});
|
|
1228
1252
|
if (!hadToolCalls) {
|
|
1229
|
-
|
|
1253
|
+
this.logger.debug("No tool calls, finishing...");
|
|
1230
1254
|
break;
|
|
1231
1255
|
}
|
|
1232
|
-
|
|
1256
|
+
this.logger.debug(`Step ${stepCount + 1}: Executing tools...`);
|
|
1233
1257
|
stepCount++;
|
|
1234
1258
|
if (finalResponse.function_call) {
|
|
1235
1259
|
const toolCall = {
|
|
@@ -1246,8 +1270,8 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1246
1270
|
content: JSON.stringify(result.result)
|
|
1247
1271
|
});
|
|
1248
1272
|
} else if (finalResponse.tool_calls && finalResponse.tool_calls.length > 0) {
|
|
1249
|
-
|
|
1250
|
-
`
|
|
1273
|
+
this.logger.debug(
|
|
1274
|
+
`Step ${stepCount + 1}: Executing ${finalResponse.tool_calls.length} tool(s)...`
|
|
1251
1275
|
);
|
|
1252
1276
|
context.messages.pop();
|
|
1253
1277
|
context.addMessage({
|
|
@@ -1270,11 +1294,12 @@ ${relevantInfo.join("\n\n")}`
|
|
|
1270
1294
|
}
|
|
1271
1295
|
await this.saveToMemory(context);
|
|
1272
1296
|
}
|
|
1273
|
-
};
|
|
1297
|
+
}, _class7);
|
|
1274
1298
|
|
|
1275
1299
|
// src/agents/sequential-agent.ts
|
|
1276
|
-
|
|
1277
|
-
var SequentialAgent = class extends BaseAgent {
|
|
1300
|
+
init_logger();
|
|
1301
|
+
var SequentialAgent = (_class8 = class extends BaseAgent {
|
|
1302
|
+
__init10() {this.logger = new Logger({ name: "SequentialAgent" })}
|
|
1278
1303
|
/**
|
|
1279
1304
|
* Constructor for SequentialAgent
|
|
1280
1305
|
*/
|
|
@@ -1282,7 +1307,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1282
1307
|
super({
|
|
1283
1308
|
name: config.name,
|
|
1284
1309
|
description: config.description
|
|
1285
|
-
});
|
|
1310
|
+
});_class8.prototype.__init10.call(this);;
|
|
1286
1311
|
if (config.agents && config.agents.length > 0) {
|
|
1287
1312
|
for (const agent of config.agents) {
|
|
1288
1313
|
this.addSubAgent(agent);
|
|
@@ -1294,8 +1319,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1294
1319
|
* Executes sub-agents sequentially, passing output from one to the next
|
|
1295
1320
|
*/
|
|
1296
1321
|
async run(options) {
|
|
1297
|
-
|
|
1298
|
-
`
|
|
1322
|
+
this.logger.debug(
|
|
1323
|
+
`Running ${this.subAgents.length} sub-agents in sequence`
|
|
1299
1324
|
);
|
|
1300
1325
|
if (this.subAgents.length === 0) {
|
|
1301
1326
|
return {
|
|
@@ -1312,8 +1337,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1312
1337
|
let finalResponse = null;
|
|
1313
1338
|
for (let i = 0; i < this.subAgents.length; i++) {
|
|
1314
1339
|
const agent = this.subAgents[i];
|
|
1315
|
-
|
|
1316
|
-
`
|
|
1340
|
+
this.logger.debug(
|
|
1341
|
+
`Running sub-agent ${i + 1}/${this.subAgents.length}: ${agent.name}`
|
|
1317
1342
|
);
|
|
1318
1343
|
try {
|
|
1319
1344
|
const response = await agent.run({
|
|
@@ -1329,10 +1354,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1329
1354
|
});
|
|
1330
1355
|
}
|
|
1331
1356
|
} catch (error) {
|
|
1332
|
-
console.error(
|
|
1333
|
-
`[SequentialAgent] Error in sub-agent ${agent.name}:`,
|
|
1334
|
-
error
|
|
1335
|
-
);
|
|
1357
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1336
1358
|
return {
|
|
1337
1359
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1338
1360
|
role: "assistant",
|
|
@@ -1370,8 +1392,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1370
1392
|
* Streams responses from each sub-agent in sequence
|
|
1371
1393
|
*/
|
|
1372
1394
|
async *runStreaming(options) {
|
|
1373
|
-
|
|
1374
|
-
`
|
|
1395
|
+
this.logger.debug(
|
|
1396
|
+
`Streaming ${this.subAgents.length} sub-agents in sequence`
|
|
1375
1397
|
);
|
|
1376
1398
|
if (this.subAgents.length === 0) {
|
|
1377
1399
|
yield {
|
|
@@ -1388,8 +1410,8 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1388
1410
|
const currentMessages = [...options.messages];
|
|
1389
1411
|
for (let i = 0; i < this.subAgents.length; i++) {
|
|
1390
1412
|
const agent = this.subAgents[i];
|
|
1391
|
-
|
|
1392
|
-
`
|
|
1413
|
+
this.logger.debug(
|
|
1414
|
+
`Streaming sub-agent ${i + 1}/${this.subAgents.length}: ${agent.name}`
|
|
1393
1415
|
);
|
|
1394
1416
|
try {
|
|
1395
1417
|
const streamGenerator = agent.runStreaming({
|
|
@@ -1422,10 +1444,7 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1422
1444
|
});
|
|
1423
1445
|
}
|
|
1424
1446
|
} catch (error) {
|
|
1425
|
-
console.error(
|
|
1426
|
-
`[SequentialAgent] Error in streaming sub-agent ${agent.name}:`,
|
|
1427
|
-
error
|
|
1428
|
-
);
|
|
1447
|
+
console.error(`Error in streaming sub-agent ${agent.name}:`, error);
|
|
1429
1448
|
yield {
|
|
1430
1449
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1431
1450
|
role: "assistant",
|
|
@@ -1440,11 +1459,12 @@ var SequentialAgent = class extends BaseAgent {
|
|
|
1440
1459
|
}
|
|
1441
1460
|
}
|
|
1442
1461
|
}
|
|
1443
|
-
};
|
|
1462
|
+
}, _class8);
|
|
1444
1463
|
|
|
1445
1464
|
// src/agents/parallel-agent.ts
|
|
1446
|
-
|
|
1447
|
-
var ParallelAgent = class extends BaseAgent {
|
|
1465
|
+
init_logger();
|
|
1466
|
+
var ParallelAgent = (_class9 = class extends BaseAgent {
|
|
1467
|
+
__init11() {this.logger = new Logger({ name: "ParallelAgent" })}
|
|
1448
1468
|
/**
|
|
1449
1469
|
* Constructor for ParallelAgent
|
|
1450
1470
|
*/
|
|
@@ -1452,7 +1472,7 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1452
1472
|
super({
|
|
1453
1473
|
name: config.name,
|
|
1454
1474
|
description: config.description
|
|
1455
|
-
});
|
|
1475
|
+
});_class9.prototype.__init11.call(this);;
|
|
1456
1476
|
if (config.agents && config.agents.length > 0) {
|
|
1457
1477
|
for (const agent of config.agents) {
|
|
1458
1478
|
this.addSubAgent(agent);
|
|
@@ -1464,8 +1484,8 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1464
1484
|
* Executes all sub-agents in parallel
|
|
1465
1485
|
*/
|
|
1466
1486
|
async run(options) {
|
|
1467
|
-
|
|
1468
|
-
`
|
|
1487
|
+
this.logger.debug(
|
|
1488
|
+
`Running ${this.subAgents.length} sub-agents in parallel`
|
|
1469
1489
|
);
|
|
1470
1490
|
if (this.subAgents.length === 0) {
|
|
1471
1491
|
return {
|
|
@@ -1478,10 +1498,7 @@ var ParallelAgent = class extends BaseAgent {
|
|
|
1478
1498
|
messages: options.messages,
|
|
1479
1499
|
config: options.config
|
|
1480
1500
|
}).catch((error) => {
|
|
1481
|
-
console.error(
|
|
1482
|
-
`[ParallelAgent] Error in sub-agent ${agent.name}:`,
|
|
1483
|
-
error
|
|
1484
|
-
);
|
|
1501
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1485
1502
|
return {
|
|
1486
1503
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1487
1504
|
role: "assistant"
|
|
@@ -1509,8 +1526,8 @@ ${result.content || "No content"}
|
|
|
1509
1526
|
* Collects streaming responses from all sub-agents
|
|
1510
1527
|
*/
|
|
1511
1528
|
async *runStreaming(options) {
|
|
1512
|
-
|
|
1513
|
-
`
|
|
1529
|
+
this.logger.debug(
|
|
1530
|
+
`Streaming ${this.subAgents.length} sub-agents in parallel`
|
|
1514
1531
|
);
|
|
1515
1532
|
if (this.subAgents.length === 0) {
|
|
1516
1533
|
yield {
|
|
@@ -1524,10 +1541,7 @@ ${result.content || "No content"}
|
|
|
1524
1541
|
messages: options.messages,
|
|
1525
1542
|
config: options.config
|
|
1526
1543
|
}).catch((error) => {
|
|
1527
|
-
console.error(
|
|
1528
|
-
`[ParallelAgent] Error in sub-agent ${agent.name}:`,
|
|
1529
|
-
error
|
|
1530
|
-
);
|
|
1544
|
+
console.error(`Error in sub-agent ${agent.name}:`, error);
|
|
1531
1545
|
return {
|
|
1532
1546
|
content: `Error in sub-agent ${agent.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
1533
1547
|
role: "assistant"
|
|
@@ -1574,11 +1588,11 @@ ${response.content || "No content"}
|
|
|
1574
1588
|
};
|
|
1575
1589
|
}
|
|
1576
1590
|
}
|
|
1577
|
-
};
|
|
1591
|
+
}, _class9);
|
|
1578
1592
|
|
|
1579
1593
|
// src/agents/loop-agent.ts
|
|
1580
|
-
|
|
1581
|
-
var LoopAgent = class extends BaseAgent {
|
|
1594
|
+
init_logger();
|
|
1595
|
+
var LoopAgent = (_class10 = class extends BaseAgent {
|
|
1582
1596
|
/**
|
|
1583
1597
|
* Maximum number of iterations to prevent infinite loops
|
|
1584
1598
|
*/
|
|
@@ -1591,6 +1605,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1591
1605
|
* Custom condition check function
|
|
1592
1606
|
*/
|
|
1593
1607
|
|
|
1608
|
+
__init12() {this.logger = new Logger({ name: "LoopAgent" })}
|
|
1594
1609
|
/**
|
|
1595
1610
|
* Constructor for LoopAgent
|
|
1596
1611
|
*/
|
|
@@ -1598,7 +1613,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1598
1613
|
super({
|
|
1599
1614
|
name: config.name,
|
|
1600
1615
|
description: config.description
|
|
1601
|
-
});
|
|
1616
|
+
});_class10.prototype.__init12.call(this);;
|
|
1602
1617
|
this.maxIterations = config.maxIterations || 10;
|
|
1603
1618
|
this.conditionAgent = config.conditionAgent;
|
|
1604
1619
|
this.conditionCheck = config.conditionCheck;
|
|
@@ -1618,19 +1633,19 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1618
1633
|
*/
|
|
1619
1634
|
async shouldContinue(response, iterationCount, messages, config) {
|
|
1620
1635
|
if (iterationCount >= this.maxIterations) {
|
|
1621
|
-
|
|
1622
|
-
`
|
|
1636
|
+
this.logger.debug(
|
|
1637
|
+
`Maximum iterations (${this.maxIterations}) reached. Stopping loop.`
|
|
1623
1638
|
);
|
|
1624
1639
|
return false;
|
|
1625
1640
|
}
|
|
1626
1641
|
if (this.conditionCheck) {
|
|
1627
1642
|
const shouldContinue = await this.conditionCheck(response);
|
|
1628
|
-
|
|
1643
|
+
this.logger.debug(`Custom condition check result: ${shouldContinue}`);
|
|
1629
1644
|
return shouldContinue;
|
|
1630
1645
|
}
|
|
1631
1646
|
if (this.conditionAgent) {
|
|
1632
|
-
|
|
1633
|
-
`
|
|
1647
|
+
this.logger.debug(
|
|
1648
|
+
`Using condition agent ${this.conditionAgent.name} to check loop condition`
|
|
1634
1649
|
);
|
|
1635
1650
|
const conditionMessages = [
|
|
1636
1651
|
...messages,
|
|
@@ -1650,12 +1665,12 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1650
1665
|
});
|
|
1651
1666
|
const content = _optionalChain([conditionResponse, 'access', _21 => _21.content, 'optionalAccess', _22 => _22.toLowerCase, 'call', _23 => _23()]) || "";
|
|
1652
1667
|
const shouldContinue = content.includes("yes") && !content.includes("no");
|
|
1653
|
-
|
|
1654
|
-
`
|
|
1668
|
+
this.logger.debug(
|
|
1669
|
+
`Condition agent result: ${shouldContinue ? "Continue loop" : "Stop loop"}`
|
|
1655
1670
|
);
|
|
1656
1671
|
return shouldContinue;
|
|
1657
1672
|
} catch (error) {
|
|
1658
|
-
console.error("
|
|
1673
|
+
console.error("Error in condition agent:", error);
|
|
1659
1674
|
return false;
|
|
1660
1675
|
}
|
|
1661
1676
|
}
|
|
@@ -1666,8 +1681,8 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1666
1681
|
* Executes the sub-agent in a loop until the condition is met
|
|
1667
1682
|
*/
|
|
1668
1683
|
async run(options) {
|
|
1669
|
-
|
|
1670
|
-
`
|
|
1684
|
+
this.logger.debug(
|
|
1685
|
+
`Starting loop with max ${this.maxIterations} iterations`
|
|
1671
1686
|
);
|
|
1672
1687
|
if (this.subAgents.length === 0) {
|
|
1673
1688
|
return {
|
|
@@ -1682,8 +1697,8 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1682
1697
|
let shouldContinueLoop = true;
|
|
1683
1698
|
while (shouldContinueLoop && iterationCount < this.maxIterations) {
|
|
1684
1699
|
iterationCount++;
|
|
1685
|
-
|
|
1686
|
-
`
|
|
1700
|
+
this.logger.debug(
|
|
1701
|
+
`Running iteration ${iterationCount}/${this.maxIterations}`
|
|
1687
1702
|
);
|
|
1688
1703
|
try {
|
|
1689
1704
|
const response = await subAgent.run({
|
|
@@ -1708,10 +1723,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
1708
1723
|
});
|
|
1709
1724
|
}
|
|
1710
1725
|
} catch (error) {
|
|
1711
|
-
console.error(
|
|
1712
|
-
`[LoopAgent] Error in loop iteration ${iterationCount}:`,
|
|
1713
|
-
error
|
|
1714
|
-
);
|
|
1726
|
+
console.error(`Error in loop iteration ${iterationCount}:`, error);
|
|
1715
1727
|
break;
|
|
1716
1728
|
}
|
|
1717
1729
|
}
|
|
@@ -1732,8 +1744,8 @@ ${lastResponse.content || ""}`,
|
|
|
1732
1744
|
* Runs the agent with streaming support
|
|
1733
1745
|
*/
|
|
1734
1746
|
async *runStreaming(options) {
|
|
1735
|
-
|
|
1736
|
-
`
|
|
1747
|
+
this.logger.debug(
|
|
1748
|
+
`Starting loop with max ${this.maxIterations} iterations (streaming)`
|
|
1737
1749
|
);
|
|
1738
1750
|
if (this.subAgents.length === 0) {
|
|
1739
1751
|
yield {
|
|
@@ -1753,8 +1765,8 @@ ${lastResponse.content || ""}`,
|
|
|
1753
1765
|
};
|
|
1754
1766
|
while (shouldContinueLoop && iterationCount < this.maxIterations) {
|
|
1755
1767
|
iterationCount++;
|
|
1756
|
-
|
|
1757
|
-
`
|
|
1768
|
+
this.logger.debug(
|
|
1769
|
+
`Running iteration ${iterationCount}/${this.maxIterations} (streaming)`
|
|
1758
1770
|
);
|
|
1759
1771
|
yield {
|
|
1760
1772
|
content: `Running iteration ${iterationCount}/${this.maxIterations}...`,
|
|
@@ -1779,8 +1791,8 @@ ${lastResponse.content || ""}`,
|
|
|
1779
1791
|
}
|
|
1780
1792
|
}
|
|
1781
1793
|
if (!lastChunk) {
|
|
1782
|
-
|
|
1783
|
-
`
|
|
1794
|
+
this.logger.debug(
|
|
1795
|
+
`No complete chunk received from iteration ${iterationCount}`
|
|
1784
1796
|
);
|
|
1785
1797
|
shouldContinueLoop = false;
|
|
1786
1798
|
continue;
|
|
@@ -1807,8 +1819,8 @@ ${lastResponse.content || ""}`,
|
|
|
1807
1819
|
};
|
|
1808
1820
|
}
|
|
1809
1821
|
} catch (error) {
|
|
1810
|
-
|
|
1811
|
-
`
|
|
1822
|
+
this.logger.debug(
|
|
1823
|
+
`Error in loop iteration ${iterationCount}: ${error instanceof Error ? error.message : String(error)}`
|
|
1812
1824
|
);
|
|
1813
1825
|
yield {
|
|
1814
1826
|
content: `Error in loop iteration ${iterationCount}: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -1822,11 +1834,11 @@ ${lastResponse.content || ""}`,
|
|
|
1822
1834
|
role: "assistant"
|
|
1823
1835
|
};
|
|
1824
1836
|
}
|
|
1825
|
-
};
|
|
1837
|
+
}, _class10);
|
|
1826
1838
|
|
|
1827
1839
|
// src/agents/lang-graph-agent.ts
|
|
1828
|
-
|
|
1829
|
-
var LangGraphAgent = (
|
|
1840
|
+
init_logger();
|
|
1841
|
+
var LangGraphAgent = (_class11 = class extends BaseAgent {
|
|
1830
1842
|
/**
|
|
1831
1843
|
* Graph nodes (agents and their connections)
|
|
1832
1844
|
*/
|
|
@@ -1842,7 +1854,8 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1842
1854
|
/**
|
|
1843
1855
|
* Results from node executions
|
|
1844
1856
|
*/
|
|
1845
|
-
|
|
1857
|
+
__init13() {this.results = []}
|
|
1858
|
+
__init14() {this.logger = new Logger({ name: "LangGraphAgent" })}
|
|
1846
1859
|
/**
|
|
1847
1860
|
* Constructor for LangGraphAgent
|
|
1848
1861
|
*/
|
|
@@ -1850,7 +1863,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1850
1863
|
super({
|
|
1851
1864
|
name: config.name,
|
|
1852
1865
|
description: config.description
|
|
1853
|
-
});
|
|
1866
|
+
});_class11.prototype.__init13.call(this);_class11.prototype.__init14.call(this);;
|
|
1854
1867
|
this.nodes = /* @__PURE__ */ new Map();
|
|
1855
1868
|
for (const node of config.nodes) {
|
|
1856
1869
|
if (this.nodes.has(node.name)) {
|
|
@@ -1917,15 +1930,13 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1917
1930
|
for (const targetName of currentNode.targets) {
|
|
1918
1931
|
const targetNode = this.nodes.get(targetName);
|
|
1919
1932
|
if (!targetNode) {
|
|
1920
|
-
console.error(`
|
|
1933
|
+
console.error(`Target node "${targetName}" not found`);
|
|
1921
1934
|
continue;
|
|
1922
1935
|
}
|
|
1923
1936
|
if (targetNode.condition) {
|
|
1924
1937
|
const shouldExecute = await targetNode.condition(result, context);
|
|
1925
1938
|
if (!shouldExecute) {
|
|
1926
|
-
|
|
1927
|
-
`[LangGraphAgent] Skipping node "${targetName}" due to condition`
|
|
1928
|
-
);
|
|
1939
|
+
this.logger.debug(`Skipping node "${targetName}" due to condition`);
|
|
1929
1940
|
continue;
|
|
1930
1941
|
}
|
|
1931
1942
|
}
|
|
@@ -1950,9 +1961,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1950
1961
|
};
|
|
1951
1962
|
const shouldExecute = await node.condition(mockResponse, mockContext);
|
|
1952
1963
|
if (!shouldExecute) {
|
|
1953
|
-
|
|
1954
|
-
`[LangGraphAgent] Skipping node "${targetName}" due to condition`
|
|
1955
|
-
);
|
|
1964
|
+
this.logger.debug(`Skipping node "${targetName}" due to condition`);
|
|
1956
1965
|
}
|
|
1957
1966
|
return { shouldExecute };
|
|
1958
1967
|
}
|
|
@@ -1965,8 +1974,8 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1965
1974
|
messages: options.messages,
|
|
1966
1975
|
config: options.config
|
|
1967
1976
|
});
|
|
1968
|
-
|
|
1969
|
-
`
|
|
1977
|
+
this.logger.debug(
|
|
1978
|
+
`Starting graph execution from root node "${this.rootNode}"`
|
|
1970
1979
|
);
|
|
1971
1980
|
if (this.nodes.size === 0) {
|
|
1972
1981
|
return {
|
|
@@ -1987,9 +1996,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
1987
1996
|
while (nodesToExecute.length > 0 && stepCount < this.maxSteps) {
|
|
1988
1997
|
stepCount++;
|
|
1989
1998
|
const { node, messages } = nodesToExecute.shift();
|
|
1990
|
-
|
|
1991
|
-
`[LangGraphAgent] Step ${stepCount}: Executing node "${node.name}"`
|
|
1992
|
-
);
|
|
1999
|
+
this.logger.debug(`Step ${stepCount}: Executing node "${node.name}"`);
|
|
1993
2000
|
executedNodes.push(node.name);
|
|
1994
2001
|
try {
|
|
1995
2002
|
const result = await node.agent.run({
|
|
@@ -2037,7 +2044,7 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2037
2044
|
});
|
|
2038
2045
|
}
|
|
2039
2046
|
} catch (error) {
|
|
2040
|
-
console.error(`
|
|
2047
|
+
console.error(`Error in node "${node.name}":`, error);
|
|
2041
2048
|
return {
|
|
2042
2049
|
content: `Error in node "${node.name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
2043
2050
|
role: "assistant"
|
|
@@ -2061,8 +2068,8 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2061
2068
|
messages: options.messages,
|
|
2062
2069
|
config: options.config
|
|
2063
2070
|
});
|
|
2064
|
-
|
|
2065
|
-
`
|
|
2071
|
+
this.logger.debug(
|
|
2072
|
+
`Starting graph execution from root node "${this.rootNode}" (streaming)`
|
|
2066
2073
|
);
|
|
2067
2074
|
if (this.nodes.size === 0) {
|
|
2068
2075
|
yield {
|
|
@@ -2090,8 +2097,8 @@ var LangGraphAgent = (_class6 = class extends BaseAgent {
|
|
|
2090
2097
|
while (nodesToExecute.length > 0 && stepCount < this.maxSteps) {
|
|
2091
2098
|
stepCount++;
|
|
2092
2099
|
const { node, messages } = nodesToExecute.shift();
|
|
2093
|
-
|
|
2094
|
-
`
|
|
2100
|
+
this.logger.debug(
|
|
2101
|
+
`Step ${stepCount}: Executing node "${node.name}" (streaming)`
|
|
2095
2102
|
);
|
|
2096
2103
|
executedNodes.push(node.name);
|
|
2097
2104
|
try {
|
|
@@ -2146,7 +2153,7 @@ Node output: ${this.extractTextContent(result.content)}` : ""}`,
|
|
|
2146
2153
|
});
|
|
2147
2154
|
}
|
|
2148
2155
|
} catch (error) {
|
|
2149
|
-
console.error(`
|
|
2156
|
+
console.error(`Error in node "${node.name}":`, error);
|
|
2150
2157
|
yield {
|
|
2151
2158
|
content: `Error in node "${node.name}": ${error instanceof Error ? error.message : String(error)}`,
|
|
2152
2159
|
role: "assistant"
|
|
@@ -2164,7 +2171,7 @@ Node output: ${this.extractTextContent(result.content)}` : ""}`,
|
|
|
2164
2171
|
};
|
|
2165
2172
|
}
|
|
2166
2173
|
}
|
|
2167
|
-
},
|
|
2174
|
+
}, _class11);
|
|
2168
2175
|
|
|
2169
2176
|
// src/tools/index.ts
|
|
2170
2177
|
var tools_exports = {};
|
|
@@ -2206,9 +2213,10 @@ function createFunctionTool(func, options) {
|
|
|
2206
2213
|
init_function_utils();
|
|
2207
2214
|
|
|
2208
2215
|
// src/tools/common/google-search.ts
|
|
2209
|
-
|
|
2216
|
+
init_logger();
|
|
2210
2217
|
init_base_tool();
|
|
2211
|
-
var GoogleSearch = class extends BaseTool {
|
|
2218
|
+
var GoogleSearch = (_class12 = class extends BaseTool {
|
|
2219
|
+
__init15() {this.logger = new Logger({ name: "GoogleSearch" })}
|
|
2212
2220
|
/**
|
|
2213
2221
|
* Constructor for GoogleSearch
|
|
2214
2222
|
*/
|
|
@@ -2216,7 +2224,7 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2216
2224
|
super({
|
|
2217
2225
|
name: "google_search",
|
|
2218
2226
|
description: "Search the web using Google"
|
|
2219
|
-
});
|
|
2227
|
+
});_class12.prototype.__init15.call(this);;
|
|
2220
2228
|
}
|
|
2221
2229
|
/**
|
|
2222
2230
|
* Get the function declaration for the tool
|
|
@@ -2247,7 +2255,9 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2247
2255
|
* This is a simplified implementation that doesn't actually search, just returns mock results
|
|
2248
2256
|
*/
|
|
2249
2257
|
async runAsync(args, _context) {
|
|
2250
|
-
|
|
2258
|
+
this.logger.debug(
|
|
2259
|
+
`[GoogleSearch] Executing Google search for: ${args.query}`
|
|
2260
|
+
);
|
|
2251
2261
|
return {
|
|
2252
2262
|
results: [
|
|
2253
2263
|
{
|
|
@@ -2263,7 +2273,7 @@ var GoogleSearch = class extends BaseTool {
|
|
|
2263
2273
|
]
|
|
2264
2274
|
};
|
|
2265
2275
|
}
|
|
2266
|
-
};
|
|
2276
|
+
}, _class12);
|
|
2267
2277
|
|
|
2268
2278
|
// src/tools/common/http-request-tool.ts
|
|
2269
2279
|
init_base_tool();
|
|
@@ -2710,9 +2720,10 @@ var UserInteractionTool = class extends BaseTool {
|
|
|
2710
2720
|
};
|
|
2711
2721
|
|
|
2712
2722
|
// src/tools/common/exit-loop-tool.ts
|
|
2713
|
-
|
|
2723
|
+
init_logger();
|
|
2714
2724
|
init_base_tool();
|
|
2715
|
-
var ExitLoopTool = class extends BaseTool {
|
|
2725
|
+
var ExitLoopTool = (_class13 = class extends BaseTool {
|
|
2726
|
+
__init16() {this.logger = new Logger({ name: "ExitLoopTool" })}
|
|
2716
2727
|
/**
|
|
2717
2728
|
* Constructor for ExitLoopTool
|
|
2718
2729
|
*/
|
|
@@ -2720,7 +2731,7 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2720
2731
|
super({
|
|
2721
2732
|
name: "exit_loop",
|
|
2722
2733
|
description: "Exits the loop. Call this function only when you are instructed to do so."
|
|
2723
|
-
});
|
|
2734
|
+
});_class13.prototype.__init16.call(this);;
|
|
2724
2735
|
}
|
|
2725
2736
|
/**
|
|
2726
2737
|
* Get the function declaration for the tool
|
|
@@ -2740,7 +2751,7 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2740
2751
|
* Execute the exit loop action
|
|
2741
2752
|
*/
|
|
2742
2753
|
async runAsync(_args, context) {
|
|
2743
|
-
|
|
2754
|
+
this.logger.debug("Executing exit loop tool");
|
|
2744
2755
|
if (context.actions) {
|
|
2745
2756
|
context.actions.escalate = true;
|
|
2746
2757
|
} else {
|
|
@@ -2752,12 +2763,13 @@ var ExitLoopTool = class extends BaseTool {
|
|
|
2752
2763
|
message: "Loop exited successfully"
|
|
2753
2764
|
};
|
|
2754
2765
|
}
|
|
2755
|
-
};
|
|
2766
|
+
}, _class13);
|
|
2756
2767
|
|
|
2757
2768
|
// src/tools/common/get-user-choice-tool.ts
|
|
2758
|
-
|
|
2769
|
+
init_logger();
|
|
2759
2770
|
init_base_tool();
|
|
2760
|
-
var GetUserChoiceTool = class extends BaseTool {
|
|
2771
|
+
var GetUserChoiceTool = (_class14 = class extends BaseTool {
|
|
2772
|
+
__init17() {this.logger = new Logger({ name: "GetUserChoiceTool" })}
|
|
2761
2773
|
/**
|
|
2762
2774
|
* Constructor for GetUserChoiceTool
|
|
2763
2775
|
*/
|
|
@@ -2766,7 +2778,7 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2766
2778
|
name: "get_user_choice",
|
|
2767
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.",
|
|
2768
2780
|
isLongRunning: true
|
|
2769
|
-
});
|
|
2781
|
+
});_class14.prototype.__init17.call(this);;
|
|
2770
2782
|
}
|
|
2771
2783
|
/**
|
|
2772
2784
|
* Get the function declaration for the tool
|
|
@@ -2800,13 +2812,11 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2800
2812
|
* and the actual choice will be provided asynchronously
|
|
2801
2813
|
*/
|
|
2802
2814
|
async runAsync(args, context) {
|
|
2803
|
-
|
|
2804
|
-
`
|
|
2805
|
-
", "
|
|
2806
|
-
)}`
|
|
2815
|
+
this.logger.debug(
|
|
2816
|
+
`Executing get_user_choice with options: ${args.options.join(", ")}`
|
|
2807
2817
|
);
|
|
2808
2818
|
if (args.question) {
|
|
2809
|
-
|
|
2819
|
+
this.logger.debug(`Question: ${args.question}`);
|
|
2810
2820
|
}
|
|
2811
2821
|
if (context.actions) {
|
|
2812
2822
|
context.actions.skip_summarization = true;
|
|
@@ -2817,12 +2827,13 @@ var GetUserChoiceTool = class extends BaseTool {
|
|
|
2817
2827
|
}
|
|
2818
2828
|
return null;
|
|
2819
2829
|
}
|
|
2820
|
-
};
|
|
2830
|
+
}, _class14);
|
|
2821
2831
|
|
|
2822
2832
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
2823
|
-
|
|
2833
|
+
init_logger();
|
|
2824
2834
|
init_base_tool();
|
|
2825
|
-
var TransferToAgentTool = class extends BaseTool {
|
|
2835
|
+
var TransferToAgentTool = (_class15 = class extends BaseTool {
|
|
2836
|
+
__init18() {this.logger = new Logger({ name: "TransferToAgentTool" })}
|
|
2826
2837
|
/**
|
|
2827
2838
|
* Constructor for TransferToAgentTool
|
|
2828
2839
|
*/
|
|
@@ -2830,7 +2841,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2830
2841
|
super({
|
|
2831
2842
|
name: "transfer_to_agent",
|
|
2832
2843
|
description: "Transfer the question to another agent."
|
|
2833
|
-
});
|
|
2844
|
+
});_class15.prototype.__init18.call(this);;
|
|
2834
2845
|
}
|
|
2835
2846
|
/**
|
|
2836
2847
|
* Get the function declaration for the tool
|
|
@@ -2855,9 +2866,7 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2855
2866
|
* Execute the transfer to agent action
|
|
2856
2867
|
*/
|
|
2857
2868
|
async runAsync(args, context) {
|
|
2858
|
-
|
|
2859
|
-
`[TransferToAgentTool] Executing transfer to agent: ${args.agent_name}`
|
|
2860
|
-
);
|
|
2869
|
+
this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
|
|
2861
2870
|
if (context.actions) {
|
|
2862
2871
|
context.actions.transfer_to_agent = args.agent_name;
|
|
2863
2872
|
} else {
|
|
@@ -2869,12 +2878,13 @@ var TransferToAgentTool = class extends BaseTool {
|
|
|
2869
2878
|
message: `Transferred to agent: ${args.agent_name}`
|
|
2870
2879
|
};
|
|
2871
2880
|
}
|
|
2872
|
-
};
|
|
2881
|
+
}, _class15);
|
|
2873
2882
|
|
|
2874
2883
|
// src/tools/common/load-memory-tool.ts
|
|
2875
|
-
|
|
2884
|
+
init_logger();
|
|
2876
2885
|
init_base_tool();
|
|
2877
|
-
var LoadMemoryTool = class extends BaseTool {
|
|
2886
|
+
var LoadMemoryTool = (_class16 = class extends BaseTool {
|
|
2887
|
+
__init19() {this.logger = new Logger({ name: "LoadMemoryTool" })}
|
|
2878
2888
|
/**
|
|
2879
2889
|
* Constructor for LoadMemoryTool
|
|
2880
2890
|
*/
|
|
@@ -2882,7 +2892,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2882
2892
|
super({
|
|
2883
2893
|
name: "load_memory",
|
|
2884
2894
|
description: "Loads the memory for the current user based on a query."
|
|
2885
|
-
});
|
|
2895
|
+
});_class16.prototype.__init19.call(this);;
|
|
2886
2896
|
}
|
|
2887
2897
|
/**
|
|
2888
2898
|
* Get the function declaration for the tool
|
|
@@ -2907,9 +2917,7 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2907
2917
|
* Execute the memory loading action
|
|
2908
2918
|
*/
|
|
2909
2919
|
async runAsync(args, context) {
|
|
2910
|
-
|
|
2911
|
-
`[LoadMemoryTool] Executing load_memory with query: ${args.query}`
|
|
2912
|
-
);
|
|
2920
|
+
this.logger.debug(`Executing load_memory with query: ${args.query}`);
|
|
2913
2921
|
if (!context.memoryService) {
|
|
2914
2922
|
return {
|
|
2915
2923
|
error: "Memory service is not available",
|
|
@@ -2930,12 +2938,21 @@ var LoadMemoryTool = class extends BaseTool {
|
|
|
2930
2938
|
};
|
|
2931
2939
|
}
|
|
2932
2940
|
}
|
|
2933
|
-
};
|
|
2941
|
+
}, _class16);
|
|
2934
2942
|
|
|
2935
2943
|
// src/tools/mcp/client.ts
|
|
2944
|
+
init_logger();
|
|
2936
2945
|
var _indexjs = require('@modelcontextprotocol/sdk/client/index.js');
|
|
2937
2946
|
var _ssejs = require('@modelcontextprotocol/sdk/client/sse.js');
|
|
2938
2947
|
var _stdiojs = require('@modelcontextprotocol/sdk/client/stdio.js');
|
|
2948
|
+
var _typesjs = require('@modelcontextprotocol/sdk/types.js');
|
|
2949
|
+
|
|
2950
|
+
// src/tools/mcp/sampling-handler.ts
|
|
2951
|
+
init_logger();
|
|
2952
|
+
|
|
2953
|
+
|
|
2954
|
+
|
|
2955
|
+
|
|
2939
2956
|
|
|
2940
2957
|
// src/tools/mcp/types.ts
|
|
2941
2958
|
var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
@@ -2944,6 +2961,8 @@ var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
|
|
|
2944
2961
|
McpErrorType2["RESOURCE_CLOSED_ERROR"] = "resource_closed_error";
|
|
2945
2962
|
McpErrorType2["TIMEOUT_ERROR"] = "timeout_error";
|
|
2946
2963
|
McpErrorType2["INVALID_SCHEMA_ERROR"] = "invalid_schema_error";
|
|
2964
|
+
McpErrorType2["SAMPLING_ERROR"] = "SAMPLING_ERROR";
|
|
2965
|
+
McpErrorType2["INVALID_REQUEST_ERROR"] = "INVALID_REQUEST_ERROR";
|
|
2947
2966
|
return McpErrorType2;
|
|
2948
2967
|
})(McpErrorType || {});
|
|
2949
2968
|
var McpError = class extends Error {
|
|
@@ -2957,6 +2976,154 @@ var McpError = class extends Error {
|
|
|
2957
2976
|
}
|
|
2958
2977
|
};
|
|
2959
2978
|
|
|
2979
|
+
// src/tools/mcp/sampling-handler.ts
|
|
2980
|
+
var McpSamplingHandler = (_class17 = class {
|
|
2981
|
+
__init20() {this.logger = new Logger({ name: "McpSamplingHandler" })}
|
|
2982
|
+
|
|
2983
|
+
constructor(adkHandler) {;_class17.prototype.__init20.call(this);
|
|
2984
|
+
this.adkHandler = adkHandler;
|
|
2985
|
+
}
|
|
2986
|
+
/**
|
|
2987
|
+
* Handle MCP sampling request and convert between formats
|
|
2988
|
+
*/
|
|
2989
|
+
async handleSamplingRequest(request) {
|
|
2990
|
+
try {
|
|
2991
|
+
const validationResult = _typesjs.CreateMessageRequestSchema.safeParse(request);
|
|
2992
|
+
if (!validationResult.success) {
|
|
2993
|
+
this.logger.error(
|
|
2994
|
+
"Invalid MCP sampling request:",
|
|
2995
|
+
validationResult.error
|
|
2996
|
+
);
|
|
2997
|
+
throw new McpError(
|
|
2998
|
+
`Invalid sampling request: ${validationResult.error.message}`,
|
|
2999
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
const mcpParams = request.params;
|
|
3003
|
+
if (!mcpParams.messages || !Array.isArray(mcpParams.messages)) {
|
|
3004
|
+
throw new McpError(
|
|
3005
|
+
"Invalid sampling request: messages array is required",
|
|
3006
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3007
|
+
);
|
|
3008
|
+
}
|
|
3009
|
+
if (!mcpParams.maxTokens || mcpParams.maxTokens <= 0) {
|
|
3010
|
+
throw new McpError(
|
|
3011
|
+
"Invalid sampling request: maxTokens must be a positive number",
|
|
3012
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3013
|
+
);
|
|
3014
|
+
}
|
|
3015
|
+
this.logger.debug("Converting MCP request to ADK format");
|
|
3016
|
+
const adkMessages = this.convertMcpMessagesToADK(mcpParams.messages);
|
|
3017
|
+
const adkRequest = {
|
|
3018
|
+
messages: adkMessages,
|
|
3019
|
+
systemPrompt: mcpParams.systemPrompt,
|
|
3020
|
+
modelPreferences: mcpParams.modelPreferences,
|
|
3021
|
+
includeContext: mcpParams.includeContext,
|
|
3022
|
+
temperature: mcpParams.temperature,
|
|
3023
|
+
maxTokens: mcpParams.maxTokens,
|
|
3024
|
+
stopSequences: mcpParams.stopSequences,
|
|
3025
|
+
metadata: mcpParams.metadata
|
|
3026
|
+
};
|
|
3027
|
+
this.logger.debug("Calling ADK sampling handler");
|
|
3028
|
+
const adkResponse = await this.adkHandler(adkRequest);
|
|
3029
|
+
this.logger.debug("Converting ADK response to MCP format");
|
|
3030
|
+
const mcpResponse = this.convertADKResponseToMcp(adkResponse);
|
|
3031
|
+
const responseValidation = _typesjs.CreateMessageResultSchema.safeParse(mcpResponse);
|
|
3032
|
+
if (!responseValidation.success) {
|
|
3033
|
+
this.logger.error(
|
|
3034
|
+
"Invalid MCP response generated:",
|
|
3035
|
+
responseValidation.error
|
|
3036
|
+
);
|
|
3037
|
+
throw new McpError(
|
|
3038
|
+
`Invalid response generated: ${responseValidation.error.message}`,
|
|
3039
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
return mcpResponse;
|
|
3043
|
+
} catch (error) {
|
|
3044
|
+
this.logger.error("Error handling sampling request:", error);
|
|
3045
|
+
if (error instanceof McpError) {
|
|
3046
|
+
throw error;
|
|
3047
|
+
}
|
|
3048
|
+
throw new McpError(
|
|
3049
|
+
`Sampling request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3050
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */,
|
|
3051
|
+
error instanceof Error ? error : void 0
|
|
3052
|
+
);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
* Convert MCP messages to ADK message format
|
|
3057
|
+
*/
|
|
3058
|
+
convertMcpMessagesToADK(mcpMessages) {
|
|
3059
|
+
return mcpMessages.map((mcpMessage) => {
|
|
3060
|
+
const adkRole = mcpMessage.role === "assistant" ? "assistant" : "user";
|
|
3061
|
+
let adkContent;
|
|
3062
|
+
if (mcpMessage.content.type === "text") {
|
|
3063
|
+
adkContent = mcpMessage.content.text || "";
|
|
3064
|
+
} else if (mcpMessage.content.type === "image") {
|
|
3065
|
+
const contentParts = [];
|
|
3066
|
+
if (mcpMessage.content.text) {
|
|
3067
|
+
contentParts.push({
|
|
3068
|
+
type: "text",
|
|
3069
|
+
text: mcpMessage.content.text
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
if (mcpMessage.content.data) {
|
|
3073
|
+
const mimeType = mcpMessage.content.mimeType || "image/jpeg";
|
|
3074
|
+
const dataUrl = `data:${mimeType};base64,${mcpMessage.content.data}`;
|
|
3075
|
+
contentParts.push({
|
|
3076
|
+
type: "image",
|
|
3077
|
+
image_url: {
|
|
3078
|
+
url: dataUrl
|
|
3079
|
+
}
|
|
3080
|
+
});
|
|
3081
|
+
}
|
|
3082
|
+
adkContent = contentParts.length > 0 ? contentParts : "";
|
|
3083
|
+
} else {
|
|
3084
|
+
this.logger.warn(
|
|
3085
|
+
`Unknown MCP content type: ${mcpMessage.content.type}`
|
|
3086
|
+
);
|
|
3087
|
+
adkContent = mcpMessage.content.text || "";
|
|
3088
|
+
}
|
|
3089
|
+
const adkMessage = {
|
|
3090
|
+
role: adkRole,
|
|
3091
|
+
content: adkContent
|
|
3092
|
+
};
|
|
3093
|
+
this.logger.debug(
|
|
3094
|
+
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
3095
|
+
);
|
|
3096
|
+
return adkMessage;
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
3099
|
+
/**
|
|
3100
|
+
* Convert ADK response to MCP response format
|
|
3101
|
+
*/
|
|
3102
|
+
convertADKResponseToMcp(adkResponse) {
|
|
3103
|
+
const mcpResponse = {
|
|
3104
|
+
model: adkResponse.model,
|
|
3105
|
+
stopReason: adkResponse.stopReason,
|
|
3106
|
+
role: "assistant",
|
|
3107
|
+
// ADK responses are always from assistant
|
|
3108
|
+
content: {
|
|
3109
|
+
type: "text",
|
|
3110
|
+
text: adkResponse.content || ""
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
this.logger.debug(
|
|
3114
|
+
`Converted ADK response - model: ${adkResponse.model}, content length: ${_optionalChain([adkResponse, 'access', _39 => _39.content, 'optionalAccess', _40 => _40.length]) || 0}`
|
|
3115
|
+
);
|
|
3116
|
+
return mcpResponse;
|
|
3117
|
+
}
|
|
3118
|
+
/**
|
|
3119
|
+
* Update the ADK handler
|
|
3120
|
+
*/
|
|
3121
|
+
updateHandler(handler) {
|
|
3122
|
+
this.adkHandler = handler;
|
|
3123
|
+
this.logger.debug("ADK sampling handler updated");
|
|
3124
|
+
}
|
|
3125
|
+
}, _class17);
|
|
3126
|
+
|
|
2960
3127
|
// src/tools/mcp/utils.ts
|
|
2961
3128
|
function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
2962
3129
|
return async (...args) => {
|
|
@@ -2986,12 +3153,14 @@ function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
|
2986
3153
|
}
|
|
2987
3154
|
|
|
2988
3155
|
// src/tools/mcp/client.ts
|
|
2989
|
-
var McpClientService = (
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
3156
|
+
var McpClientService = (_class18 = class {
|
|
3157
|
+
|
|
3158
|
+
__init21() {this.client = null}
|
|
3159
|
+
__init22() {this.transport = null}
|
|
3160
|
+
__init23() {this.isClosing = false}
|
|
3161
|
+
__init24() {this.mcpSamplingHandler = null}
|
|
3162
|
+
__init25() {this.logger = new Logger({ name: "McpClientService" })}
|
|
3163
|
+
constructor(config) {;_class18.prototype.__init21.call(this);_class18.prototype.__init22.call(this);_class18.prototype.__init23.call(this);_class18.prototype.__init24.call(this);_class18.prototype.__init25.call(this);
|
|
2995
3164
|
this.config = config;
|
|
2996
3165
|
}
|
|
2997
3166
|
/**
|
|
@@ -3041,6 +3210,7 @@ var McpClientService = (_class7 = class {
|
|
|
3041
3210
|
} else {
|
|
3042
3211
|
await connectPromise;
|
|
3043
3212
|
}
|
|
3213
|
+
await this.setupSamplingHandler(client);
|
|
3044
3214
|
if (this.config.debug) {
|
|
3045
3215
|
console.log("\u2705 MCP client connected successfully");
|
|
3046
3216
|
}
|
|
@@ -3161,7 +3331,7 @@ var McpClientService = (_class7 = class {
|
|
|
3161
3331
|
},
|
|
3162
3332
|
this,
|
|
3163
3333
|
async (instance) => await instance.reinitialize(),
|
|
3164
|
-
_optionalChain([this, 'access',
|
|
3334
|
+
_optionalChain([this, 'access', _41 => _41.config, 'access', _42 => _42.retryOptions, 'optionalAccess', _43 => _43.maxRetries]) || 2
|
|
3165
3335
|
);
|
|
3166
3336
|
return await wrappedCall();
|
|
3167
3337
|
} catch (error) {
|
|
@@ -3192,10 +3362,67 @@ var McpClientService = (_class7 = class {
|
|
|
3192
3362
|
isConnected() {
|
|
3193
3363
|
return !!this.client && !this.isClosing;
|
|
3194
3364
|
}
|
|
3195
|
-
|
|
3365
|
+
async setupSamplingHandler(client) {
|
|
3366
|
+
if (!this.mcpSamplingHandler) {
|
|
3367
|
+
if (this.config.debug) {
|
|
3368
|
+
console.log(
|
|
3369
|
+
"\u26A0\uFE0F No sampling handler provided - sampling requests will be rejected"
|
|
3370
|
+
);
|
|
3371
|
+
}
|
|
3372
|
+
return;
|
|
3373
|
+
}
|
|
3374
|
+
client.setRequestHandler(_typesjs.CreateMessageRequestSchema, async (request) => {
|
|
3375
|
+
try {
|
|
3376
|
+
this.logger.debug("Received sampling request:", request);
|
|
3377
|
+
const response = await this.mcpSamplingHandler.handleSamplingRequest(request);
|
|
3378
|
+
if (this.config.debug) {
|
|
3379
|
+
console.log("\u2705 Sampling request completed successfully");
|
|
3380
|
+
}
|
|
3381
|
+
return response;
|
|
3382
|
+
} catch (error) {
|
|
3383
|
+
console.error("\u274C Error handling sampling request:", error);
|
|
3384
|
+
if (error instanceof McpError) {
|
|
3385
|
+
throw error;
|
|
3386
|
+
}
|
|
3387
|
+
throw new McpError(
|
|
3388
|
+
`Sampling request failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3389
|
+
"SAMPLING_ERROR" /* SAMPLING_ERROR */,
|
|
3390
|
+
error instanceof Error ? error : void 0
|
|
3391
|
+
);
|
|
3392
|
+
}
|
|
3393
|
+
});
|
|
3394
|
+
if (this.config.debug) {
|
|
3395
|
+
console.log("\u{1F3AF} Sampling handler registered successfully");
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Set an ADK sampling handler
|
|
3400
|
+
*/
|
|
3401
|
+
setSamplingHandler(handler) {
|
|
3402
|
+
this.mcpSamplingHandler = new McpSamplingHandler(handler);
|
|
3403
|
+
if (this.client) {
|
|
3404
|
+
this.setupSamplingHandler(this.client).catch((error) => {
|
|
3405
|
+
console.error("Failed to update sampling handler:", error);
|
|
3406
|
+
});
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
/**
|
|
3410
|
+
* Remove the sampling handler
|
|
3411
|
+
*/
|
|
3412
|
+
removeSamplingHandler() {
|
|
3413
|
+
this.mcpSamplingHandler = null;
|
|
3414
|
+
if (this.client) {
|
|
3415
|
+
try {
|
|
3416
|
+
_optionalChain([this, 'access', _44 => _44.client, 'access', _45 => _45.removeRequestHandler, 'optionalCall', _46 => _46("sampling/createMessage")]);
|
|
3417
|
+
} catch (error) {
|
|
3418
|
+
console.error("Failed to remove sampling handler:", error);
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
}, _class18);
|
|
3196
3423
|
|
|
3197
3424
|
// src/tools/mcp/create-tool.ts
|
|
3198
|
-
|
|
3425
|
+
init_logger();
|
|
3199
3426
|
init_base_tool();
|
|
3200
3427
|
|
|
3201
3428
|
// src/tools/mcp/schema-conversion.ts
|
|
@@ -3394,10 +3621,11 @@ async function createTool(mcpTool, client) {
|
|
|
3394
3621
|
throw error;
|
|
3395
3622
|
}
|
|
3396
3623
|
}
|
|
3397
|
-
var McpToolAdapter = (
|
|
3624
|
+
var McpToolAdapter = (_class19 = class extends BaseTool {
|
|
3398
3625
|
|
|
3399
3626
|
|
|
3400
|
-
|
|
3627
|
+
__init26() {this.clientService = null}
|
|
3628
|
+
__init27() {this.logger = new Logger({ name: "McpToolAdapter" })}
|
|
3401
3629
|
constructor(mcpTool, client) {
|
|
3402
3630
|
const metadata = mcpTool.metadata || {};
|
|
3403
3631
|
super({
|
|
@@ -3406,7 +3634,7 @@ var McpToolAdapter = (_class8 = class extends BaseTool {
|
|
|
3406
3634
|
isLongRunning: _nullishCoalesce(metadata.isLongRunning, () => ( false)),
|
|
3407
3635
|
shouldRetryOnFailure: _nullishCoalesce(metadata.shouldRetryOnFailure, () => ( false)),
|
|
3408
3636
|
maxRetryAttempts: _nullishCoalesce(metadata.maxRetryAttempts, () => ( 3))
|
|
3409
|
-
});
|
|
3637
|
+
});_class19.prototype.__init26.call(this);_class19.prototype.__init27.call(this);;
|
|
3410
3638
|
this.mcpTool = mcpTool;
|
|
3411
3639
|
this.client = client;
|
|
3412
3640
|
if (client.reinitialize && typeof client.reinitialize === "function") {
|
|
@@ -3430,10 +3658,7 @@ var McpToolAdapter = (_class8 = class extends BaseTool {
|
|
|
3430
3658
|
}
|
|
3431
3659
|
}
|
|
3432
3660
|
async runAsync(args, _context) {
|
|
3433
|
-
|
|
3434
|
-
`[McpToolAdapter] Executing MCP tool ${this.name} with args:`,
|
|
3435
|
-
args
|
|
3436
|
-
);
|
|
3661
|
+
this.logger.debug(`Executing MCP tool ${this.name} with args:`, args);
|
|
3437
3662
|
try {
|
|
3438
3663
|
if (typeof this.mcpTool.execute === "function") {
|
|
3439
3664
|
return await this.mcpTool.execute(args);
|
|
@@ -3482,16 +3707,16 @@ var McpToolAdapter = (_class8 = class extends BaseTool {
|
|
|
3482
3707
|
throw error;
|
|
3483
3708
|
}
|
|
3484
3709
|
}
|
|
3485
|
-
},
|
|
3710
|
+
}, _class19);
|
|
3486
3711
|
|
|
3487
3712
|
// src/tools/mcp/index.ts
|
|
3488
|
-
var McpToolset = (
|
|
3713
|
+
var McpToolset = (_class20 = class {
|
|
3489
3714
|
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
constructor(config, toolFilter = null) {;
|
|
3715
|
+
__init28() {this.clientService = null}
|
|
3716
|
+
__init29() {this.toolFilter = null}
|
|
3717
|
+
__init30() {this.tools = []}
|
|
3718
|
+
__init31() {this.isClosing = false}
|
|
3719
|
+
constructor(config, toolFilter = null) {;_class20.prototype.__init28.call(this);_class20.prototype.__init29.call(this);_class20.prototype.__init30.call(this);_class20.prototype.__init31.call(this);
|
|
3495
3720
|
this.config = config;
|
|
3496
3721
|
this.toolFilter = toolFilter;
|
|
3497
3722
|
this.clientService = new McpClientService(config);
|
|
@@ -3540,7 +3765,7 @@ var McpToolset = (_class9 = class {
|
|
|
3540
3765
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
3541
3766
|
);
|
|
3542
3767
|
}
|
|
3543
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
3768
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _47 => _47.config, 'access', _48 => _48.cacheConfig, 'optionalAccess', _49 => _49.enabled]) === false) {
|
|
3544
3769
|
return this.tools;
|
|
3545
3770
|
}
|
|
3546
3771
|
if (!this.clientService) {
|
|
@@ -3566,7 +3791,7 @@ var McpToolset = (_class9 = class {
|
|
|
3566
3791
|
}
|
|
3567
3792
|
}
|
|
3568
3793
|
}
|
|
3569
|
-
if (_optionalChain([this, 'access',
|
|
3794
|
+
if (_optionalChain([this, 'access', _50 => _50.config, 'access', _51 => _51.cacheConfig, 'optionalAccess', _52 => _52.enabled]) !== false) {
|
|
3570
3795
|
this.tools = tools;
|
|
3571
3796
|
}
|
|
3572
3797
|
return tools;
|
|
@@ -3626,7 +3851,7 @@ var McpToolset = (_class9 = class {
|
|
|
3626
3851
|
async dispose() {
|
|
3627
3852
|
await this.close();
|
|
3628
3853
|
}
|
|
3629
|
-
},
|
|
3854
|
+
}, _class20);
|
|
3630
3855
|
async function getMcpTools(config, toolFilter) {
|
|
3631
3856
|
const toolset = new McpToolset(config, toolFilter);
|
|
3632
3857
|
try {
|
|
@@ -3733,11 +3958,11 @@ var BaseLLM = class {
|
|
|
3733
3958
|
};
|
|
3734
3959
|
|
|
3735
3960
|
// src/models/base-llm-connection.ts
|
|
3736
|
-
var BaseLLMConnection = (
|
|
3961
|
+
var BaseLLMConnection = (_class21 = class {constructor() { _class21.prototype.__init32.call(this); }
|
|
3737
3962
|
/**
|
|
3738
3963
|
* Whether the connection is active
|
|
3739
3964
|
*/
|
|
3740
|
-
|
|
3965
|
+
__init32() {this._isActive = true}
|
|
3741
3966
|
/**
|
|
3742
3967
|
* Gets whether the connection is active
|
|
3743
3968
|
*/
|
|
@@ -3750,15 +3975,15 @@ var BaseLLMConnection = (_class10 = class {constructor() { _class10.prototype.__
|
|
|
3750
3975
|
close() {
|
|
3751
3976
|
this._isActive = false;
|
|
3752
3977
|
}
|
|
3753
|
-
},
|
|
3978
|
+
}, _class21);
|
|
3754
3979
|
|
|
3755
3980
|
// src/models/anthropic-llm.ts
|
|
3756
|
-
|
|
3981
|
+
init_logger();
|
|
3757
3982
|
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
3758
3983
|
|
|
3759
3984
|
// src/models/anthropic-llm-connection.ts
|
|
3760
|
-
|
|
3761
|
-
var AnthropicLLMConnection = class extends BaseLLMConnection {
|
|
3985
|
+
init_logger();
|
|
3986
|
+
var AnthropicLLMConnection = (_class22 = class extends BaseLLMConnection {
|
|
3762
3987
|
/**
|
|
3763
3988
|
* Axios instance for API calls
|
|
3764
3989
|
*/
|
|
@@ -3785,11 +4010,12 @@ var AnthropicLLMConnection = class extends BaseLLMConnection {
|
|
|
3785
4010
|
|
|
3786
4011
|
|
|
3787
4012
|
|
|
4013
|
+
__init33() {this.logger = new Logger({ name: "AnthropicLlmConnection" })}
|
|
3788
4014
|
/**
|
|
3789
4015
|
* Constructor
|
|
3790
4016
|
*/
|
|
3791
4017
|
constructor(client, model, initialRequest, defaultParams) {
|
|
3792
|
-
super();
|
|
4018
|
+
super();_class22.prototype.__init33.call(this);;
|
|
3793
4019
|
this.client = client;
|
|
3794
4020
|
this.model = model;
|
|
3795
4021
|
this.defaultParams = defaultParams;
|
|
@@ -3869,7 +4095,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3869
4095
|
* Convert Anthropic tool calls to ADK tool calls
|
|
3870
4096
|
*/
|
|
3871
4097
|
convertToolCalls(toolUses) {
|
|
3872
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4098
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _53 => _53.length])) {
|
|
3873
4099
|
return void 0;
|
|
3874
4100
|
}
|
|
3875
4101
|
return toolUses.map((toolUse) => ({
|
|
@@ -3884,15 +4110,13 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3884
4110
|
* Extract tool uses from response content
|
|
3885
4111
|
*/
|
|
3886
4112
|
extractToolUses(content) {
|
|
3887
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4113
|
+
if (!_optionalChain([content, 'optionalAccess', _54 => _54.length])) return [];
|
|
3888
4114
|
const toolUses = [];
|
|
3889
4115
|
for (const block of content) {
|
|
3890
|
-
|
|
3891
|
-
`[AnthropicLLMConnection] Processing content block of type: ${block.type}`
|
|
3892
|
-
);
|
|
4116
|
+
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
3893
4117
|
if (block.type === "tool_use") {
|
|
3894
|
-
|
|
3895
|
-
"
|
|
4118
|
+
this.logger.debug(
|
|
4119
|
+
"Found tool_use block:",
|
|
3896
4120
|
JSON.stringify(block, null, 2)
|
|
3897
4121
|
);
|
|
3898
4122
|
toolUses.push({
|
|
@@ -3902,12 +4126,10 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
3902
4126
|
});
|
|
3903
4127
|
}
|
|
3904
4128
|
}
|
|
3905
|
-
|
|
3906
|
-
`[AnthropicLLMConnection] Found ${toolUses.length} tool uses in content`
|
|
3907
|
-
);
|
|
4129
|
+
this.logger.debug(`Found ${toolUses.length} tool uses in content`);
|
|
3908
4130
|
if (toolUses.length > 0) {
|
|
3909
|
-
|
|
3910
|
-
"
|
|
4131
|
+
this.logger.debug(
|
|
4132
|
+
"Extracted tool uses:",
|
|
3911
4133
|
JSON.stringify(toolUses, null, 2)
|
|
3912
4134
|
);
|
|
3913
4135
|
}
|
|
@@ -4003,37 +4225,34 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4003
4225
|
}
|
|
4004
4226
|
const toolUses = this.extractToolUses(apiResponse.content);
|
|
4005
4227
|
const toolCalls = this.convertToolCalls(toolUses);
|
|
4006
|
-
|
|
4007
|
-
|
|
4228
|
+
this.logger.debug(
|
|
4229
|
+
`- Extracted ${toolUses.length} tool uses in content and converted ${_optionalChain([toolCalls, 'optionalAccess', _55 => _55.length]) || 0} tool calls`
|
|
4008
4230
|
);
|
|
4009
4231
|
const llmResponse = new LLMResponse({
|
|
4010
4232
|
role: "assistant",
|
|
4011
4233
|
content,
|
|
4012
|
-
tool_calls: _optionalChain([toolCalls, 'optionalAccess',
|
|
4234
|
+
tool_calls: _optionalChain([toolCalls, 'optionalAccess', _56 => _56.length]) ? toolCalls : void 0,
|
|
4013
4235
|
raw_response: apiResponse
|
|
4014
4236
|
});
|
|
4015
4237
|
const logObject = {
|
|
4016
4238
|
role: llmResponse.role,
|
|
4017
|
-
content: _optionalChain([llmResponse, 'access',
|
|
4239
|
+
content: _optionalChain([llmResponse, 'access', _57 => _57.content, 'optionalAccess', _58 => _58.substring, 'call', _59 => _59(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4018
4240
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4019
4241
|
};
|
|
4020
|
-
|
|
4021
|
-
"
|
|
4242
|
+
this.logger.debug(
|
|
4243
|
+
"Final LLMResponse object:",
|
|
4022
4244
|
JSON.stringify(logObject, null, 2)
|
|
4023
4245
|
);
|
|
4024
4246
|
return llmResponse;
|
|
4025
4247
|
} catch (error) {
|
|
4026
|
-
|
|
4027
|
-
"[AnthropicLLMConnection] Error sending message to Anthropic:",
|
|
4028
|
-
error
|
|
4029
|
-
);
|
|
4248
|
+
this.logger.debug("Error sending message to Anthropic:", error);
|
|
4030
4249
|
throw error;
|
|
4031
4250
|
}
|
|
4032
4251
|
}
|
|
4033
|
-
};
|
|
4252
|
+
}, _class22);
|
|
4034
4253
|
|
|
4035
4254
|
// src/models/anthropic-llm.ts
|
|
4036
|
-
var AnthropicLLM = class extends BaseLLM {
|
|
4255
|
+
var AnthropicLLM = (_class23 = class extends BaseLLM {
|
|
4037
4256
|
/**
|
|
4038
4257
|
* Anthropic API key
|
|
4039
4258
|
*/
|
|
@@ -4046,22 +4265,23 @@ var AnthropicLLM = class extends BaseLLM {
|
|
|
4046
4265
|
* Default parameters for requests
|
|
4047
4266
|
*/
|
|
4048
4267
|
|
|
4268
|
+
__init34() {this.logger = new Logger({ name: "AnthropicLLM" })}
|
|
4049
4269
|
/**
|
|
4050
4270
|
* Constructor for AnthropicLLM
|
|
4051
4271
|
*/
|
|
4052
4272
|
constructor(model, config) {
|
|
4053
|
-
super(model);
|
|
4054
|
-
this.apiKey = _optionalChain([config, 'optionalAccess',
|
|
4055
|
-
this.baseURL = _optionalChain([config, 'optionalAccess',
|
|
4273
|
+
super(model);_class23.prototype.__init34.call(this);;
|
|
4274
|
+
this.apiKey = _optionalChain([config, 'optionalAccess', _60 => _60.apiKey]) || process.env.ANTHROPIC_API_KEY || "";
|
|
4275
|
+
this.baseURL = _optionalChain([config, 'optionalAccess', _61 => _61.baseURL]) || "https://api.anthropic.com/v1";
|
|
4056
4276
|
if (!this.apiKey) {
|
|
4057
4277
|
throw new Error(
|
|
4058
4278
|
"Anthropic API key is required. Provide it in config or set ANTHROPIC_API_KEY environment variable."
|
|
4059
4279
|
);
|
|
4060
4280
|
}
|
|
4061
4281
|
this.defaultParams = {
|
|
4062
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4063
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4064
|
-
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4282
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _62 => _62.defaultParams, 'optionalAccess', _63 => _63.temperature]), () => ( 0.7)),
|
|
4283
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _64 => _64.defaultParams, 'optionalAccess', _65 => _65.top_p]), () => ( 1)),
|
|
4284
|
+
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _66 => _66.defaultParams, 'optionalAccess', _67 => _67.max_tokens]), () => ( 1024))
|
|
4065
4285
|
};
|
|
4066
4286
|
}
|
|
4067
4287
|
/**
|
|
@@ -4147,7 +4367,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4147
4367
|
* Convert ADK function declarations to Anthropic tool format
|
|
4148
4368
|
*/
|
|
4149
4369
|
convertFunctionsToTools(functions) {
|
|
4150
|
-
if (!_optionalChain([functions, 'optionalAccess',
|
|
4370
|
+
if (!_optionalChain([functions, 'optionalAccess', _68 => _68.length])) {
|
|
4151
4371
|
return [];
|
|
4152
4372
|
}
|
|
4153
4373
|
return functions.map((func) => ({
|
|
@@ -4160,7 +4380,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4160
4380
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4161
4381
|
*/
|
|
4162
4382
|
convertToolUses(toolUses) {
|
|
4163
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4383
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _69 => _69.length])) {
|
|
4164
4384
|
return [];
|
|
4165
4385
|
}
|
|
4166
4386
|
return toolUses.map((toolUse) => ({
|
|
@@ -4175,15 +4395,13 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4175
4395
|
* Extract tool uses from response content
|
|
4176
4396
|
*/
|
|
4177
4397
|
extractToolUses(content) {
|
|
4178
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4398
|
+
if (!_optionalChain([content, 'optionalAccess', _70 => _70.length])) return [];
|
|
4179
4399
|
const toolUses = [];
|
|
4180
4400
|
for (const block of content) {
|
|
4181
|
-
|
|
4182
|
-
`[AnthropicLLM] Processing content block of type: ${block.type}`
|
|
4183
|
-
);
|
|
4401
|
+
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
4184
4402
|
if (block.type === "tool_use") {
|
|
4185
|
-
|
|
4186
|
-
`
|
|
4403
|
+
this.logger.debug(
|
|
4404
|
+
`Found tool_use block: ${JSON.stringify(block, null, 2)}`
|
|
4187
4405
|
);
|
|
4188
4406
|
toolUses.push({
|
|
4189
4407
|
id: block.id || "unknown-id",
|
|
@@ -4192,8 +4410,8 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4192
4410
|
});
|
|
4193
4411
|
}
|
|
4194
4412
|
}
|
|
4195
|
-
|
|
4196
|
-
`
|
|
4413
|
+
this.logger.debug(
|
|
4414
|
+
`Found ${toolUses.length} tool uses in content`,
|
|
4197
4415
|
toolUses
|
|
4198
4416
|
);
|
|
4199
4417
|
return toolUses;
|
|
@@ -4217,12 +4435,12 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4217
4435
|
},
|
|
4218
4436
|
responseType: stream ? "stream" : "json"
|
|
4219
4437
|
});
|
|
4220
|
-
|
|
4221
|
-
`
|
|
4438
|
+
this.logger.debug(
|
|
4439
|
+
`API Response done with ${response.status}:`,
|
|
4222
4440
|
response.data
|
|
4223
4441
|
);
|
|
4224
|
-
|
|
4225
|
-
"
|
|
4442
|
+
this.logger.debug(
|
|
4443
|
+
"API Response content:",
|
|
4226
4444
|
response.data.content.map((block) => ({ type: block.type }))
|
|
4227
4445
|
);
|
|
4228
4446
|
return response.data;
|
|
@@ -4248,9 +4466,9 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4248
4466
|
temperature: _nullishCoalesce(llmRequest.config.temperature, () => ( this.defaultParams.temperature)),
|
|
4249
4467
|
max_tokens: _nullishCoalesce(llmRequest.config.max_tokens, () => ( this.defaultParams.max_tokens)),
|
|
4250
4468
|
top_p: _nullishCoalesce(llmRequest.config.top_p, () => ( this.defaultParams.top_p)),
|
|
4251
|
-
tools: _optionalChain([tools, 'optionalAccess',
|
|
4469
|
+
tools: _optionalChain([tools, 'optionalAccess', _71 => _71.length]) ? tools : void 0
|
|
4252
4470
|
};
|
|
4253
|
-
|
|
4471
|
+
this.logger.debug("API Request:", {
|
|
4254
4472
|
model: params.model,
|
|
4255
4473
|
messageCount: params.messages.length,
|
|
4256
4474
|
systemMessage: params.system ? "present" : "none",
|
|
@@ -4260,7 +4478,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4260
4478
|
throw new Error("Streaming is not supported in this implementation");
|
|
4261
4479
|
}
|
|
4262
4480
|
const response = await this.callAnthropicAPI(params);
|
|
4263
|
-
|
|
4481
|
+
this.logger.debug("Full Response Content:", response.content);
|
|
4264
4482
|
let content = "";
|
|
4265
4483
|
for (const block of response.content) {
|
|
4266
4484
|
if (block.type === "text") {
|
|
@@ -4269,8 +4487,8 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4269
4487
|
}
|
|
4270
4488
|
const toolUses = this.extractToolUses(response.content);
|
|
4271
4489
|
const toolCalls = this.convertToolUses(toolUses);
|
|
4272
|
-
|
|
4273
|
-
|
|
4490
|
+
this.logger.debug("Extracted Tool Uses:", toolUses);
|
|
4491
|
+
this.logger.debug("Converted Tool Calls:", toolCalls);
|
|
4274
4492
|
const llmResponse = new LLMResponse({
|
|
4275
4493
|
role: "assistant",
|
|
4276
4494
|
content,
|
|
@@ -4279,16 +4497,16 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4279
4497
|
});
|
|
4280
4498
|
const logObject = {
|
|
4281
4499
|
role: llmResponse.role,
|
|
4282
|
-
content: _optionalChain([llmResponse, 'access',
|
|
4500
|
+
content: _optionalChain([llmResponse, 'access', _72 => _72.content, 'optionalAccess', _73 => _73.substring, 'call', _74 => _74(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4283
4501
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4284
4502
|
};
|
|
4285
|
-
|
|
4286
|
-
"
|
|
4503
|
+
this.logger.debug(
|
|
4504
|
+
"Final LLMResponse object:",
|
|
4287
4505
|
JSON.stringify(logObject, null, 2)
|
|
4288
4506
|
);
|
|
4289
4507
|
yield llmResponse;
|
|
4290
4508
|
} catch (error) {
|
|
4291
|
-
|
|
4509
|
+
this.logger.debug("Error:", error);
|
|
4292
4510
|
throw error;
|
|
4293
4511
|
}
|
|
4294
4512
|
}
|
|
@@ -4311,7 +4529,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4311
4529
|
this.defaultParams
|
|
4312
4530
|
);
|
|
4313
4531
|
}
|
|
4314
|
-
};
|
|
4532
|
+
}, _class23);
|
|
4315
4533
|
|
|
4316
4534
|
// src/models/google-llm.ts
|
|
4317
4535
|
|
|
@@ -4332,9 +4550,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4332
4550
|
constructor(model, config) {
|
|
4333
4551
|
super(model);
|
|
4334
4552
|
const apiKey = process.env.GOOGLE_API_KEY;
|
|
4335
|
-
const projectId = _optionalChain([config, 'optionalAccess',
|
|
4336
|
-
const location = _optionalChain([config, 'optionalAccess',
|
|
4337
|
-
const useVertexAI = _optionalChain([process, 'access',
|
|
4553
|
+
const projectId = _optionalChain([config, 'optionalAccess', _75 => _75.projectId]) || process.env.GOOGLE_CLOUD_PROJECT;
|
|
4554
|
+
const location = _optionalChain([config, 'optionalAccess', _76 => _76.location]) || process.env.GOOGLE_CLOUD_LOCATION;
|
|
4555
|
+
const useVertexAI = _optionalChain([process, 'access', _77 => _77.env, 'access', _78 => _78.USE_VERTEX_AI, 'optionalAccess', _79 => _79.toLowerCase, 'call', _80 => _80()]) === "true";
|
|
4338
4556
|
if (!useVertexAI && !apiKey) {
|
|
4339
4557
|
throw new Error(
|
|
4340
4558
|
"Google API Key is required. Provide via config or GOOGLE_API_KEY env var."
|
|
@@ -4359,9 +4577,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4359
4577
|
}
|
|
4360
4578
|
this.ai = new (0, _genai.GoogleGenAI)(options);
|
|
4361
4579
|
this.defaultParams = {
|
|
4362
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4363
|
-
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4364
|
-
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4580
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _81 => _81.defaultParams, 'optionalAccess', _82 => _82.temperature]), () => ( 0.7)),
|
|
4581
|
+
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _83 => _83.defaultParams, 'optionalAccess', _84 => _84.top_p]), () => ( 1)),
|
|
4582
|
+
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _85 => _85.defaultParams, 'optionalAccess', _86 => _86.maxOutputTokens]), () => ( 1024))
|
|
4365
4583
|
};
|
|
4366
4584
|
}
|
|
4367
4585
|
/**
|
|
@@ -4499,7 +4717,7 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4499
4717
|
);
|
|
4500
4718
|
parts.push({ text: "" });
|
|
4501
4719
|
}
|
|
4502
|
-
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access',
|
|
4720
|
+
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access', _87 => _87[0], 'optionalAccess', _88 => _88.functionResponse]))) {
|
|
4503
4721
|
console.error(
|
|
4504
4722
|
`[GoogleLLM] convertMessage - Invalid parts for 'function' role. Expected 1 functionResponse part. Got:`,
|
|
4505
4723
|
JSON.stringify(parts),
|
|
@@ -4607,13 +4825,13 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4607
4825
|
role: "assistant",
|
|
4608
4826
|
content: null
|
|
4609
4827
|
});
|
|
4610
|
-
if (typeof _optionalChain([response, 'optionalAccess',
|
|
4828
|
+
if (typeof _optionalChain([response, 'optionalAccess', _89 => _89.candidates, 'optionalAccess', _90 => _90[0], 'optionalAccess', _91 => _91.content, 'optionalAccess', _92 => _92.parts, 'optionalAccess', _93 => _93[0], 'optionalAccess', _94 => _94.text]) === "string") {
|
|
4611
4829
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4612
4830
|
}
|
|
4613
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4831
|
+
if (_optionalChain([response, 'optionalAccess', _95 => _95.candidates, 'optionalAccess', _96 => _96[0], 'optionalAccess', _97 => _97.content, 'optionalAccess', _98 => _98.parts, 'optionalAccess', _99 => _99[0], 'optionalAccess', _100 => _100.text])) {
|
|
4614
4832
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4615
4833
|
}
|
|
4616
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4834
|
+
if (_optionalChain([response, 'optionalAccess', _101 => _101.candidates, 'optionalAccess', _102 => _102[0], 'optionalAccess', _103 => _103.content, 'optionalAccess', _104 => _104.parts, 'optionalAccess', _105 => _105[0], 'optionalAccess', _106 => _106.functionCall])) {
|
|
4617
4835
|
const functionCall = response.candidates[0].content.parts[0].functionCall;
|
|
4618
4836
|
result.function_call = {
|
|
4619
4837
|
name: functionCall.name,
|
|
@@ -4660,10 +4878,10 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4660
4878
|
if (stream) {
|
|
4661
4879
|
const streamingResult = await this.ai.models.generateContentStream(requestOptions);
|
|
4662
4880
|
for await (const chunk of streamingResult) {
|
|
4663
|
-
if (!_optionalChain([chunk, 'access',
|
|
4881
|
+
if (!_optionalChain([chunk, 'access', _107 => _107.candidates, 'optionalAccess', _108 => _108[0], 'optionalAccess', _109 => _109.content, 'optionalAccess', _110 => _110.parts, 'optionalAccess', _111 => _111[0], 'optionalAccess', _112 => _112.text])) {
|
|
4664
4882
|
continue;
|
|
4665
4883
|
}
|
|
4666
|
-
const partialText = _optionalChain([chunk, 'access',
|
|
4884
|
+
const partialText = _optionalChain([chunk, 'access', _113 => _113.candidates, 'access', _114 => _114[0], 'optionalAccess', _115 => _115.content, 'optionalAccess', _116 => _116.parts, 'access', _117 => _117[0], 'optionalAccess', _118 => _118.text]) || "";
|
|
4667
4885
|
const partialResponse = new LLMResponse({
|
|
4668
4886
|
content: partialText,
|
|
4669
4887
|
role: "assistant",
|
|
@@ -4683,11 +4901,11 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4683
4901
|
};
|
|
4684
4902
|
|
|
4685
4903
|
// src/models/openai-llm.ts
|
|
4686
|
-
|
|
4904
|
+
init_logger();
|
|
4687
4905
|
var _openai = require('openai'); var _openai2 = _interopRequireDefault(_openai);
|
|
4688
4906
|
|
|
4689
4907
|
// src/models/openai-llm-connection.ts
|
|
4690
|
-
var OpenAILLMConnection = (
|
|
4908
|
+
var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
4691
4909
|
/**
|
|
4692
4910
|
* OpenAI client
|
|
4693
4911
|
*/
|
|
@@ -4719,12 +4937,12 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4719
4937
|
/**
|
|
4720
4938
|
* Ongoing chat history
|
|
4721
4939
|
*/
|
|
4722
|
-
|
|
4940
|
+
__init35() {this.messages = []}
|
|
4723
4941
|
/**
|
|
4724
4942
|
* Constructor for OpenAILLMConnection
|
|
4725
4943
|
*/
|
|
4726
4944
|
constructor(client, model, initialRequest, defaultParams) {
|
|
4727
|
-
super();
|
|
4945
|
+
super();_class24.prototype.__init35.call(this);;
|
|
4728
4946
|
this.client = client;
|
|
4729
4947
|
this.model = model;
|
|
4730
4948
|
this.initialRequest = initialRequest;
|
|
@@ -4804,10 +5022,10 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4804
5022
|
for await (const chunk of stream) {
|
|
4805
5023
|
if (chunk.choices.length === 0) continue;
|
|
4806
5024
|
const delta = chunk.choices[0].delta;
|
|
4807
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5025
|
+
if (_optionalChain([delta, 'optionalAccess', _119 => _119.content])) {
|
|
4808
5026
|
responseContent += delta.content;
|
|
4809
5027
|
}
|
|
4810
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5028
|
+
if (_optionalChain([delta, 'optionalAccess', _120 => _120.function_call])) {
|
|
4811
5029
|
if (!functionCall) {
|
|
4812
5030
|
functionCall = {
|
|
4813
5031
|
name: delta.function_call.name || "",
|
|
@@ -4818,7 +5036,7 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4818
5036
|
functionCall.arguments += delta.function_call.arguments || "";
|
|
4819
5037
|
}
|
|
4820
5038
|
}
|
|
4821
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5039
|
+
if (_optionalChain([delta, 'optionalAccess', _121 => _121.tool_calls])) {
|
|
4822
5040
|
for (const toolDelta of delta.tool_calls) {
|
|
4823
5041
|
const id = toolDelta.id || "";
|
|
4824
5042
|
let tool = toolCalls.find((t) => t.id === id);
|
|
@@ -4826,20 +5044,20 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4826
5044
|
tool = {
|
|
4827
5045
|
id,
|
|
4828
5046
|
function: {
|
|
4829
|
-
name: _optionalChain([toolDelta, 'access',
|
|
4830
|
-
arguments: _optionalChain([toolDelta, 'access',
|
|
5047
|
+
name: _optionalChain([toolDelta, 'access', _122 => _122.function, 'optionalAccess', _123 => _123.name]) || "",
|
|
5048
|
+
arguments: _optionalChain([toolDelta, 'access', _124 => _124.function, 'optionalAccess', _125 => _125.arguments]) || ""
|
|
4831
5049
|
}
|
|
4832
5050
|
};
|
|
4833
5051
|
toolCalls.push(tool);
|
|
4834
5052
|
} else {
|
|
4835
|
-
tool.function.name += _optionalChain([toolDelta, 'access',
|
|
4836
|
-
tool.function.arguments += _optionalChain([toolDelta, 'access',
|
|
5053
|
+
tool.function.name += _optionalChain([toolDelta, 'access', _126 => _126.function, 'optionalAccess', _127 => _127.name]) || "";
|
|
5054
|
+
tool.function.arguments += _optionalChain([toolDelta, 'access', _128 => _128.function, 'optionalAccess', _129 => _129.arguments]) || "";
|
|
4837
5055
|
}
|
|
4838
5056
|
}
|
|
4839
5057
|
}
|
|
4840
5058
|
if (this.responseCallback) {
|
|
4841
5059
|
const response = new LLMResponse({
|
|
4842
|
-
content: _optionalChain([delta, 'optionalAccess',
|
|
5060
|
+
content: _optionalChain([delta, 'optionalAccess', _130 => _130.content]) || null,
|
|
4843
5061
|
role: "assistant",
|
|
4844
5062
|
function_call: functionCall,
|
|
4845
5063
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
@@ -4931,10 +5149,10 @@ var OpenAILLMConnection = (_class11 = class extends BaseLLMConnection {
|
|
|
4931
5149
|
onEnd(callback) {
|
|
4932
5150
|
this.endCallback = callback;
|
|
4933
5151
|
}
|
|
4934
|
-
},
|
|
5152
|
+
}, _class24);
|
|
4935
5153
|
|
|
4936
5154
|
// src/models/openai-llm.ts
|
|
4937
|
-
var OpenAILLM = class extends BaseLLM {
|
|
5155
|
+
var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
4938
5156
|
/**
|
|
4939
5157
|
* OpenAI client instance
|
|
4940
5158
|
*/
|
|
@@ -4943,22 +5161,23 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
4943
5161
|
* Default parameters for requests
|
|
4944
5162
|
*/
|
|
4945
5163
|
|
|
5164
|
+
__init36() {this.logger = new Logger({ name: "OpenAILLM" })}
|
|
4946
5165
|
/**
|
|
4947
5166
|
* Constructor for OpenAILLM
|
|
4948
5167
|
*/
|
|
4949
5168
|
constructor(model, config) {
|
|
4950
|
-
super(model);
|
|
5169
|
+
super(model);_class25.prototype.__init36.call(this);;
|
|
4951
5170
|
this.client = new (0, _openai2.default)({
|
|
4952
|
-
apiKey: _optionalChain([config, 'optionalAccess',
|
|
4953
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
4954
|
-
organization: _optionalChain([config, 'optionalAccess',
|
|
5171
|
+
apiKey: _optionalChain([config, 'optionalAccess', _131 => _131.apiKey]) || process.env.OPENAI_API_KEY,
|
|
5172
|
+
baseURL: _optionalChain([config, 'optionalAccess', _132 => _132.baseURL]),
|
|
5173
|
+
organization: _optionalChain([config, 'optionalAccess', _133 => _133.organization])
|
|
4955
5174
|
});
|
|
4956
5175
|
this.defaultParams = {
|
|
4957
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4958
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4959
|
-
max_tokens: _optionalChain([config, 'optionalAccess',
|
|
4960
|
-
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4961
|
-
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5176
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _134 => _134.defaultParams, 'optionalAccess', _135 => _135.temperature]), () => ( 0.7)),
|
|
5177
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _136 => _136.defaultParams, 'optionalAccess', _137 => _137.top_p]), () => ( 1)),
|
|
5178
|
+
max_tokens: _optionalChain([config, 'optionalAccess', _138 => _138.defaultParams, 'optionalAccess', _139 => _139.max_tokens]),
|
|
5179
|
+
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _140 => _140.defaultParams, 'optionalAccess', _141 => _141.frequency_penalty]), () => ( 0)),
|
|
5180
|
+
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _142 => _142.defaultParams, 'optionalAccess', _143 => _143.presence_penalty]), () => ( 0))
|
|
4962
5181
|
};
|
|
4963
5182
|
}
|
|
4964
5183
|
/**
|
|
@@ -5068,16 +5287,16 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5068
5287
|
*/
|
|
5069
5288
|
convertResponse(response) {
|
|
5070
5289
|
const result = new LLMResponse({
|
|
5071
|
-
content: _optionalChain([response, 'access',
|
|
5072
|
-
role: _optionalChain([response, 'access',
|
|
5290
|
+
content: _optionalChain([response, 'access', _144 => _144.message, 'optionalAccess', _145 => _145.content]) || null,
|
|
5291
|
+
role: _optionalChain([response, 'access', _146 => _146.message, 'optionalAccess', _147 => _147.role]) || "assistant"
|
|
5073
5292
|
});
|
|
5074
|
-
if (_optionalChain([response, 'access',
|
|
5293
|
+
if (_optionalChain([response, 'access', _148 => _148.message, 'optionalAccess', _149 => _149.function_call])) {
|
|
5075
5294
|
result.function_call = {
|
|
5076
5295
|
name: response.message.function_call.name,
|
|
5077
5296
|
arguments: response.message.function_call.arguments
|
|
5078
5297
|
};
|
|
5079
5298
|
}
|
|
5080
|
-
if (_optionalChain([response, 'access',
|
|
5299
|
+
if (_optionalChain([response, 'access', _150 => _150.message, 'optionalAccess', _151 => _151.tool_calls])) {
|
|
5081
5300
|
result.tool_calls = response.message.tool_calls.map((tool) => ({
|
|
5082
5301
|
id: tool.id,
|
|
5083
5302
|
function: {
|
|
@@ -5092,27 +5311,27 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5092
5311
|
* Convert OpenAI streaming chunk to LLMResponse
|
|
5093
5312
|
*/
|
|
5094
5313
|
convertChunk(chunk) {
|
|
5095
|
-
|
|
5096
|
-
`
|
|
5314
|
+
this.logger.debug(
|
|
5315
|
+
`Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
|
|
5097
5316
|
);
|
|
5098
|
-
const content = _optionalChain([chunk, 'access',
|
|
5317
|
+
const content = _optionalChain([chunk, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.content]);
|
|
5099
5318
|
const result = new LLMResponse({
|
|
5100
5319
|
content: content !== void 0 ? content : null,
|
|
5101
|
-
role: _optionalChain([chunk, 'access',
|
|
5320
|
+
role: _optionalChain([chunk, 'access', _154 => _154.delta, 'optionalAccess', _155 => _155.role]) || "assistant",
|
|
5102
5321
|
is_partial: true
|
|
5103
5322
|
});
|
|
5104
|
-
if (_optionalChain([chunk, 'access',
|
|
5323
|
+
if (_optionalChain([chunk, 'access', _156 => _156.delta, 'optionalAccess', _157 => _157.function_call])) {
|
|
5105
5324
|
result.function_call = {
|
|
5106
5325
|
name: chunk.delta.function_call.name || "",
|
|
5107
5326
|
arguments: chunk.delta.function_call.arguments || ""
|
|
5108
5327
|
};
|
|
5109
5328
|
}
|
|
5110
|
-
if (_optionalChain([chunk, 'access',
|
|
5329
|
+
if (_optionalChain([chunk, 'access', _158 => _158.delta, 'optionalAccess', _159 => _159.tool_calls])) {
|
|
5111
5330
|
result.tool_calls = chunk.delta.tool_calls.map((tool) => ({
|
|
5112
5331
|
id: tool.id || "",
|
|
5113
5332
|
function: {
|
|
5114
|
-
name: _optionalChain([tool, 'access',
|
|
5115
|
-
arguments: _optionalChain([tool, 'access',
|
|
5333
|
+
name: _optionalChain([tool, 'access', _160 => _160.function, 'optionalAccess', _161 => _161.name]) || "",
|
|
5334
|
+
arguments: _optionalChain([tool, 'access', _162 => _162.function, 'optionalAccess', _163 => _163.arguments]) || ""
|
|
5116
5335
|
}
|
|
5117
5336
|
}));
|
|
5118
5337
|
}
|
|
@@ -5135,24 +5354,24 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5135
5354
|
presence_penalty: _nullishCoalesce(llmRequest.config.presence_penalty, () => ( this.defaultParams.presence_penalty)),
|
|
5136
5355
|
stream: shouldStream
|
|
5137
5356
|
};
|
|
5138
|
-
|
|
5139
|
-
`
|
|
5357
|
+
this.logger.debug(
|
|
5358
|
+
`Request parameters - model: ${params.model}, messages: ${params.messages.length}, functions: ${params.tools ? params.tools.length : 0}, streaming: ${shouldStream}`
|
|
5140
5359
|
);
|
|
5141
5360
|
if (tools && tools.length > 0) {
|
|
5142
5361
|
params.tools = tools;
|
|
5143
5362
|
}
|
|
5144
5363
|
try {
|
|
5145
5364
|
if (shouldStream) {
|
|
5146
|
-
|
|
5365
|
+
this.logger.debug("Starting streaming request");
|
|
5147
5366
|
const streamResponse = await this.client.chat.completions.create(params);
|
|
5148
5367
|
let partialFunctionCall;
|
|
5149
5368
|
const partialToolCalls = /* @__PURE__ */ new Map();
|
|
5150
5369
|
let accumulatedContent = "";
|
|
5151
5370
|
const asyncIterable = streamResponse;
|
|
5152
|
-
|
|
5371
|
+
this.logger.debug("Stream response received, processing chunks");
|
|
5153
5372
|
for await (const chunk of asyncIterable) {
|
|
5154
5373
|
if (!chunk.choices || chunk.choices.length === 0) {
|
|
5155
|
-
|
|
5374
|
+
this.logger.debug("Empty chunk received, skipping");
|
|
5156
5375
|
continue;
|
|
5157
5376
|
}
|
|
5158
5377
|
const choice = chunk.choices[0];
|
|
@@ -5160,8 +5379,8 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5160
5379
|
if (responseChunk.content !== null) {
|
|
5161
5380
|
accumulatedContent += responseChunk.content;
|
|
5162
5381
|
}
|
|
5163
|
-
|
|
5164
|
-
`
|
|
5382
|
+
this.logger.debug(
|
|
5383
|
+
`Chunk received - delta: "${_optionalChain([choice, 'access', _164 => _164.delta, 'optionalAccess', _165 => _165.content]) || ""}"`,
|
|
5165
5384
|
`responseChunk content: "${responseChunk.content || ""}"`,
|
|
5166
5385
|
`is_partial: ${responseChunk.is_partial}`,
|
|
5167
5386
|
`accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
@@ -5190,12 +5409,12 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5190
5409
|
}
|
|
5191
5410
|
responseChunk.tool_calls = Array.from(partialToolCalls.values());
|
|
5192
5411
|
}
|
|
5193
|
-
|
|
5412
|
+
this.logger.debug("Yielding chunk to caller");
|
|
5194
5413
|
yield responseChunk;
|
|
5195
5414
|
}
|
|
5196
5415
|
if (accumulatedContent.length > 0) {
|
|
5197
|
-
|
|
5198
|
-
`
|
|
5416
|
+
this.logger.debug(
|
|
5417
|
+
`Yielding final accumulated content: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
5199
5418
|
);
|
|
5200
5419
|
yield new LLMResponse({
|
|
5201
5420
|
content: accumulatedContent,
|
|
@@ -5203,14 +5422,14 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5203
5422
|
is_partial: false
|
|
5204
5423
|
});
|
|
5205
5424
|
}
|
|
5206
|
-
|
|
5425
|
+
this.logger.debug("Finished processing all stream chunks");
|
|
5207
5426
|
} else {
|
|
5208
|
-
|
|
5427
|
+
this.logger.debug("Making non-streaming request");
|
|
5209
5428
|
const response = await this.client.chat.completions.create(params);
|
|
5210
5429
|
if (!response.choices || response.choices.length === 0) {
|
|
5211
5430
|
throw new Error("No response from OpenAI");
|
|
5212
5431
|
}
|
|
5213
|
-
|
|
5432
|
+
this.logger.debug("Non-streaming response received");
|
|
5214
5433
|
yield this.convertResponse(response.choices[0]);
|
|
5215
5434
|
}
|
|
5216
5435
|
} catch (error) {
|
|
@@ -5229,7 +5448,7 @@ var OpenAILLM = class extends BaseLLM {
|
|
|
5229
5448
|
this.defaultParams
|
|
5230
5449
|
);
|
|
5231
5450
|
}
|
|
5232
|
-
};
|
|
5451
|
+
}, _class25);
|
|
5233
5452
|
|
|
5234
5453
|
// src/models/registry.ts
|
|
5235
5454
|
function registerProviders() {
|
|
@@ -5427,7 +5646,7 @@ var OAuth2Credential = class extends AuthCredential {
|
|
|
5427
5646
|
"Cannot refresh token: no refresh token or refresh function"
|
|
5428
5647
|
);
|
|
5429
5648
|
}
|
|
5430
|
-
const result = await _optionalChain([this, 'access',
|
|
5649
|
+
const result = await _optionalChain([this, 'access', _166 => _166.refreshFunction, 'optionalCall', _167 => _167(this.refreshToken)]);
|
|
5431
5650
|
if (!result) {
|
|
5432
5651
|
throw new Error("Failed to refresh token");
|
|
5433
5652
|
}
|
|
@@ -5481,7 +5700,7 @@ var AuthHandler = class {
|
|
|
5481
5700
|
* Gets the authentication token
|
|
5482
5701
|
*/
|
|
5483
5702
|
getToken() {
|
|
5484
|
-
return _optionalChain([this, 'access',
|
|
5703
|
+
return _optionalChain([this, 'access', _168 => _168.credential, 'optionalAccess', _169 => _169.getToken, 'call', _170 => _170()]);
|
|
5485
5704
|
}
|
|
5486
5705
|
/**
|
|
5487
5706
|
* Gets headers for HTTP requests
|
|
@@ -5496,7 +5715,7 @@ var AuthHandler = class {
|
|
|
5496
5715
|
* Refreshes the token if necessary
|
|
5497
5716
|
*/
|
|
5498
5717
|
async refreshToken() {
|
|
5499
|
-
if (_optionalChain([this, 'access',
|
|
5718
|
+
if (_optionalChain([this, 'access', _171 => _171.credential, 'optionalAccess', _172 => _172.canRefresh, 'call', _173 => _173()])) {
|
|
5500
5719
|
await this.credential.refresh();
|
|
5501
5720
|
}
|
|
5502
5721
|
}
|
|
@@ -5722,7 +5941,7 @@ var InMemoryMemoryService = class {
|
|
|
5722
5941
|
};
|
|
5723
5942
|
const normalizedQuery = query.toLowerCase().trim();
|
|
5724
5943
|
const queryTerms = normalizedQuery.split(/\s+/);
|
|
5725
|
-
const sessionsToSearch = _optionalChain([options, 'optionalAccess',
|
|
5944
|
+
const sessionsToSearch = _optionalChain([options, 'optionalAccess', _174 => _174.sessionId]) ? this.sessions.has(options.sessionId) ? [this.sessions.get(options.sessionId)] : [] : Array.from(this.sessions.values());
|
|
5726
5945
|
for (const session of sessionsToSearch) {
|
|
5727
5946
|
const matchedEvents = [];
|
|
5728
5947
|
const scores = [];
|
|
@@ -5748,7 +5967,7 @@ var InMemoryMemoryService = class {
|
|
|
5748
5967
|
}
|
|
5749
5968
|
}
|
|
5750
5969
|
const score = queryTerms.length > 0 ? termMatches / queryTerms.length : 0;
|
|
5751
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5970
|
+
if (_optionalChain([options, 'optionalAccess', _175 => _175.threshold]) !== void 0 && score < options.threshold) {
|
|
5752
5971
|
continue;
|
|
5753
5972
|
}
|
|
5754
5973
|
if (score > 0) {
|
|
@@ -5768,7 +5987,7 @@ var InMemoryMemoryService = class {
|
|
|
5768
5987
|
response.memories.sort(
|
|
5769
5988
|
(a, b) => (_nullishCoalesce(b.relevanceScore, () => ( 0))) - (_nullishCoalesce(a.relevanceScore, () => ( 0)))
|
|
5770
5989
|
);
|
|
5771
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5990
|
+
if (_optionalChain([options, 'optionalAccess', _176 => _176.limit]) !== void 0 && options.limit > 0) {
|
|
5772
5991
|
response.memories = response.memories.slice(0, options.limit);
|
|
5773
5992
|
}
|
|
5774
5993
|
return response;
|
|
@@ -5797,10 +6016,10 @@ var InMemoryMemoryService = class {
|
|
|
5797
6016
|
};
|
|
5798
6017
|
|
|
5799
6018
|
// src/memory/persistent-memory-service.ts
|
|
5800
|
-
|
|
6019
|
+
init_logger();
|
|
5801
6020
|
var _fs = require('fs'); var fs3 = _interopRequireWildcard(_fs);
|
|
5802
6021
|
|
|
5803
|
-
var PersistentMemoryService = class {
|
|
6022
|
+
var PersistentMemoryService = (_class26 = class {
|
|
5804
6023
|
/**
|
|
5805
6024
|
* In-memory service used for search operations
|
|
5806
6025
|
*/
|
|
@@ -5813,10 +6032,11 @@ var PersistentMemoryService = class {
|
|
|
5813
6032
|
* File prefix for memory files
|
|
5814
6033
|
*/
|
|
5815
6034
|
|
|
6035
|
+
__init37() {this.logger = new Logger({ name: "PersistentMemoryService" })}
|
|
5816
6036
|
/**
|
|
5817
6037
|
* Constructor for PersistentMemoryService
|
|
5818
6038
|
*/
|
|
5819
|
-
constructor(config) {
|
|
6039
|
+
constructor(config) {;_class26.prototype.__init37.call(this);
|
|
5820
6040
|
this.inMemoryService = new InMemoryMemoryService();
|
|
5821
6041
|
this.storageDir = config.storageDir;
|
|
5822
6042
|
this.filePrefix = config.filePrefix || "memory";
|
|
@@ -5901,7 +6121,7 @@ var PersistentMemoryService = class {
|
|
|
5901
6121
|
}
|
|
5902
6122
|
}
|
|
5903
6123
|
}
|
|
5904
|
-
|
|
6124
|
+
this.logger.debug(
|
|
5905
6125
|
`Loaded ${this.inMemoryService.getAllSessions().length} sessions from persistent storage`
|
|
5906
6126
|
);
|
|
5907
6127
|
} catch (error) {
|
|
@@ -5958,7 +6178,7 @@ var PersistentMemoryService = class {
|
|
|
5958
6178
|
);
|
|
5959
6179
|
}
|
|
5960
6180
|
}
|
|
5961
|
-
};
|
|
6181
|
+
}, _class26);
|
|
5962
6182
|
|
|
5963
6183
|
// src/sessions/index.ts
|
|
5964
6184
|
var sessions_exports = {};
|
|
@@ -6033,17 +6253,17 @@ var InMemorySessionService = class {
|
|
|
6033
6253
|
let sessions = Array.from(this.sessions.values()).filter(
|
|
6034
6254
|
(session) => session.userId === userId
|
|
6035
6255
|
);
|
|
6036
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6256
|
+
if (_optionalChain([options, 'optionalAccess', _177 => _177.createdAfter])) {
|
|
6037
6257
|
sessions = sessions.filter(
|
|
6038
6258
|
(session) => session.createdAt >= options.createdAfter
|
|
6039
6259
|
);
|
|
6040
6260
|
}
|
|
6041
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6261
|
+
if (_optionalChain([options, 'optionalAccess', _178 => _178.updatedAfter])) {
|
|
6042
6262
|
sessions = sessions.filter(
|
|
6043
6263
|
(session) => session.updatedAt >= options.updatedAfter
|
|
6044
6264
|
);
|
|
6045
6265
|
}
|
|
6046
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6266
|
+
if (_optionalChain([options, 'optionalAccess', _179 => _179.metadataFilter])) {
|
|
6047
6267
|
sessions = sessions.filter((session) => {
|
|
6048
6268
|
for (const [key, value] of Object.entries(options.metadataFilter)) {
|
|
6049
6269
|
if (session.metadata[key] !== value) {
|
|
@@ -6054,7 +6274,7 @@ var InMemorySessionService = class {
|
|
|
6054
6274
|
});
|
|
6055
6275
|
}
|
|
6056
6276
|
sessions.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
6057
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6277
|
+
if (_optionalChain([options, 'optionalAccess', _180 => _180.limit]) !== void 0 && options.limit > 0) {
|
|
6058
6278
|
sessions = sessions.slice(0, options.limit);
|
|
6059
6279
|
}
|
|
6060
6280
|
return sessions;
|
|
@@ -6089,7 +6309,7 @@ var InMemorySessionService = class {
|
|
|
6089
6309
|
if (event.is_partial) {
|
|
6090
6310
|
return event;
|
|
6091
6311
|
}
|
|
6092
|
-
if (_optionalChain([event, 'access',
|
|
6312
|
+
if (_optionalChain([event, 'access', _181 => _181.actions, 'optionalAccess', _182 => _182.stateDelta])) {
|
|
6093
6313
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6094
6314
|
if (key.startsWith("_temp_")) {
|
|
6095
6315
|
continue;
|
|
@@ -6195,7 +6415,7 @@ var PostgresSessionService = class {
|
|
|
6195
6415
|
}
|
|
6196
6416
|
async listSessions(userId, options) {
|
|
6197
6417
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6198
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6418
|
+
if (_optionalChain([options, 'optionalAccess', _183 => _183.limit]) !== void 0 && options.limit > 0) {
|
|
6199
6419
|
query = query.limit(options.limit);
|
|
6200
6420
|
}
|
|
6201
6421
|
const results = await query;
|
|
@@ -6222,12 +6442,12 @@ var PostgresSessionService = class {
|
|
|
6222
6442
|
if (event.is_partial) {
|
|
6223
6443
|
return event;
|
|
6224
6444
|
}
|
|
6225
|
-
if (_optionalChain([event, 'access',
|
|
6445
|
+
if (_optionalChain([event, 'access', _184 => _184.actions, 'optionalAccess', _185 => _185.stateDelta])) {
|
|
6226
6446
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6227
6447
|
if (key.startsWith("_temp_")) {
|
|
6228
6448
|
continue;
|
|
6229
6449
|
}
|
|
6230
|
-
_optionalChain([session, 'access',
|
|
6450
|
+
_optionalChain([session, 'access', _186 => _186.state, 'optionalAccess', _187 => _187.set, 'call', _188 => _188(key, value)]);
|
|
6231
6451
|
}
|
|
6232
6452
|
}
|
|
6233
6453
|
if (!session.events) {
|
|
@@ -6258,11 +6478,11 @@ var sessionsSchema2 = _pgcore.pgTable.call(void 0, "sessions", {
|
|
|
6258
6478
|
updatedAt: _pgcore.timestamp.call(void 0, "updated_at", { withTimezone: true }).defaultNow().notNull(),
|
|
6259
6479
|
state: _pgcore.jsonb.call(void 0, "state").default("{}").$type()
|
|
6260
6480
|
});
|
|
6261
|
-
var PgLiteSessionService = (
|
|
6481
|
+
var PgLiteSessionService = (_class27 = class {
|
|
6262
6482
|
|
|
6263
6483
|
|
|
6264
|
-
|
|
6265
|
-
constructor(config) {;
|
|
6484
|
+
__init38() {this.initialized = false}
|
|
6485
|
+
constructor(config) {;_class27.prototype.__init38.call(this);
|
|
6266
6486
|
this.db = _pglite.drizzle.call(void 0, config.pglite, {
|
|
6267
6487
|
schema: { sessions: sessionsSchema2 }
|
|
6268
6488
|
});
|
|
@@ -6371,7 +6591,7 @@ var PgLiteSessionService = (_class12 = class {
|
|
|
6371
6591
|
async listSessions(userId, options) {
|
|
6372
6592
|
await this.ensureInitialized();
|
|
6373
6593
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6374
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6594
|
+
if (_optionalChain([options, 'optionalAccess', _189 => _189.limit]) !== void 0 && options.limit > 0) {
|
|
6375
6595
|
query = query.limit(options.limit);
|
|
6376
6596
|
}
|
|
6377
6597
|
const results = await query;
|
|
@@ -6394,12 +6614,12 @@ var PgLiteSessionService = (_class12 = class {
|
|
|
6394
6614
|
if (event.is_partial) {
|
|
6395
6615
|
return event;
|
|
6396
6616
|
}
|
|
6397
|
-
if (_optionalChain([event, 'access',
|
|
6617
|
+
if (_optionalChain([event, 'access', _190 => _190.actions, 'optionalAccess', _191 => _191.stateDelta])) {
|
|
6398
6618
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6399
6619
|
if (key.startsWith("_temp_")) {
|
|
6400
6620
|
continue;
|
|
6401
6621
|
}
|
|
6402
|
-
_optionalChain([session, 'access',
|
|
6622
|
+
_optionalChain([session, 'access', _192 => _192.state, 'optionalAccess', _193 => _193.set, 'call', _194 => _194(key, value)]);
|
|
6403
6623
|
}
|
|
6404
6624
|
}
|
|
6405
6625
|
if (!session.events) {
|
|
@@ -6410,7 +6630,7 @@ var PgLiteSessionService = (_class12 = class {
|
|
|
6410
6630
|
await this.updateSession(session);
|
|
6411
6631
|
return event;
|
|
6412
6632
|
}
|
|
6413
|
-
},
|
|
6633
|
+
}, _class27);
|
|
6414
6634
|
|
|
6415
6635
|
// src/sessions/sqlite-session-service.ts
|
|
6416
6636
|
|
|
@@ -6430,12 +6650,12 @@ var sessionsSchema3 = _sqlitecore.sqliteTable.call(void 0, "sessions", {
|
|
|
6430
6650
|
updatedAt: _sqlitecore.integer.call(void 0, "updated_at", { mode: "timestamp" }).notNull(),
|
|
6431
6651
|
state: _sqlitecore.text.call(void 0, "state", { mode: "json" }).default("{}").$type()
|
|
6432
6652
|
});
|
|
6433
|
-
var SqliteSessionService = (
|
|
6653
|
+
var SqliteSessionService = (_class28 = class {
|
|
6434
6654
|
|
|
6435
6655
|
|
|
6436
|
-
|
|
6656
|
+
__init39() {this.initialized = false}
|
|
6437
6657
|
|
|
6438
|
-
constructor(config) {;
|
|
6658
|
+
constructor(config) {;_class28.prototype.__init39.call(this);
|
|
6439
6659
|
this.sqliteInstance = config.sqlite;
|
|
6440
6660
|
const dbPath = this.sqliteInstance.name;
|
|
6441
6661
|
if (dbPath && dbPath !== ":memory:") {
|
|
@@ -6556,7 +6776,7 @@ var SqliteSessionService = (_class13 = class {
|
|
|
6556
6776
|
async listSessions(userId, options) {
|
|
6557
6777
|
await this.ensureInitialized();
|
|
6558
6778
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6559
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6779
|
+
if (_optionalChain([options, 'optionalAccess', _195 => _195.limit]) !== void 0 && options.limit > 0) {
|
|
6560
6780
|
query = query.limit(options.limit);
|
|
6561
6781
|
}
|
|
6562
6782
|
const results = await query;
|
|
@@ -6579,12 +6799,12 @@ var SqliteSessionService = (_class13 = class {
|
|
|
6579
6799
|
if (event.is_partial) {
|
|
6580
6800
|
return event;
|
|
6581
6801
|
}
|
|
6582
|
-
if (_optionalChain([event, 'access',
|
|
6802
|
+
if (_optionalChain([event, 'access', _196 => _196.actions, 'optionalAccess', _197 => _197.stateDelta])) {
|
|
6583
6803
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6584
6804
|
if (key.startsWith("_temp_")) {
|
|
6585
6805
|
continue;
|
|
6586
6806
|
}
|
|
6587
|
-
_optionalChain([session, 'access',
|
|
6807
|
+
_optionalChain([session, 'access', _198 => _198.state, 'optionalAccess', _199 => _199.set, 'call', _200 => _200(key, value)]);
|
|
6588
6808
|
}
|
|
6589
6809
|
}
|
|
6590
6810
|
if (!session.events) {
|
|
@@ -6595,7 +6815,7 @@ var SqliteSessionService = (_class13 = class {
|
|
|
6595
6815
|
await this.updateSession(session);
|
|
6596
6816
|
return event;
|
|
6597
6817
|
}
|
|
6598
|
-
},
|
|
6818
|
+
}, _class28);
|
|
6599
6819
|
|
|
6600
6820
|
// src/sessions/session-util.ts
|
|
6601
6821
|
function generateSessionId() {
|
|
@@ -6631,7 +6851,7 @@ function cloneSession(session) {
|
|
|
6631
6851
|
var _uuid = require('uuid');
|
|
6632
6852
|
|
|
6633
6853
|
// src/events/event-actions.ts
|
|
6634
|
-
var EventActions = (
|
|
6854
|
+
var EventActions = (_class29 = class {
|
|
6635
6855
|
/**
|
|
6636
6856
|
* If true, it won't call model to summarize function response.
|
|
6637
6857
|
* Only used for function_response event.
|
|
@@ -6640,12 +6860,12 @@ var EventActions = (_class14 = class {
|
|
|
6640
6860
|
/**
|
|
6641
6861
|
* Indicates that the event is updating the state with the given delta.
|
|
6642
6862
|
*/
|
|
6643
|
-
|
|
6863
|
+
__init40() {this.stateDelta = {}}
|
|
6644
6864
|
/**
|
|
6645
6865
|
* Indicates that the event is updating an artifact. key is the filename,
|
|
6646
6866
|
* value is the version.
|
|
6647
6867
|
*/
|
|
6648
|
-
|
|
6868
|
+
__init41() {this.artifactDelta = {}}
|
|
6649
6869
|
/**
|
|
6650
6870
|
* If set, the event transfers to the specified agent.
|
|
6651
6871
|
*/
|
|
@@ -6657,21 +6877,21 @@ var EventActions = (_class14 = class {
|
|
|
6657
6877
|
/**
|
|
6658
6878
|
* Constructor for EventActions
|
|
6659
6879
|
*/
|
|
6660
|
-
constructor(options = {}) {;
|
|
6880
|
+
constructor(options = {}) {;_class29.prototype.__init40.call(this);_class29.prototype.__init41.call(this);
|
|
6661
6881
|
this.skipSummarization = options.skipSummarization;
|
|
6662
6882
|
this.stateDelta = options.stateDelta || {};
|
|
6663
6883
|
this.artifactDelta = options.artifactDelta || {};
|
|
6664
6884
|
this.transferToAgent = options.transferToAgent;
|
|
6665
6885
|
this.escalate = options.escalate;
|
|
6666
6886
|
}
|
|
6667
|
-
},
|
|
6887
|
+
}, _class29);
|
|
6668
6888
|
|
|
6669
6889
|
// src/events/event.ts
|
|
6670
|
-
var Event = (
|
|
6890
|
+
var Event = (_class30 = class _Event extends LLMResponse {
|
|
6671
6891
|
/**
|
|
6672
6892
|
* The invocation ID of the event.
|
|
6673
6893
|
*/
|
|
6674
|
-
|
|
6894
|
+
__init42() {this.invocationId = ""}
|
|
6675
6895
|
/**
|
|
6676
6896
|
* 'user' or the name of the agent, indicating who appended the event to the session.
|
|
6677
6897
|
*/
|
|
@@ -6679,7 +6899,7 @@ var Event = (_class15 = class _Event extends LLMResponse {
|
|
|
6679
6899
|
/**
|
|
6680
6900
|
* The actions taken by the agent.
|
|
6681
6901
|
*/
|
|
6682
|
-
|
|
6902
|
+
__init43() {this.actions = new EventActions()}
|
|
6683
6903
|
/**
|
|
6684
6904
|
* Set of ids of the long running function calls.
|
|
6685
6905
|
* Agent client will know from this field about which function call is long running.
|
|
@@ -6697,7 +6917,7 @@ var Event = (_class15 = class _Event extends LLMResponse {
|
|
|
6697
6917
|
/**
|
|
6698
6918
|
* The unique identifier of the event.
|
|
6699
6919
|
*/
|
|
6700
|
-
|
|
6920
|
+
__init44() {this.id = ""}
|
|
6701
6921
|
/**
|
|
6702
6922
|
* The timestamp of the event.
|
|
6703
6923
|
*/
|
|
@@ -6727,7 +6947,7 @@ var Event = (_class15 = class _Event extends LLMResponse {
|
|
|
6727
6947
|
role,
|
|
6728
6948
|
is_partial: partial,
|
|
6729
6949
|
raw_response
|
|
6730
|
-
});
|
|
6950
|
+
});_class30.prototype.__init42.call(this);_class30.prototype.__init43.call(this);_class30.prototype.__init44.call(this);;
|
|
6731
6951
|
this.invocationId = invocationId;
|
|
6732
6952
|
this.author = author;
|
|
6733
6953
|
this.actions = actions;
|
|
@@ -6761,7 +6981,7 @@ var Event = (_class15 = class _Event extends LLMResponse {
|
|
|
6761
6981
|
static newId() {
|
|
6762
6982
|
return _uuid.v4.call(void 0, ).substring(0, 8);
|
|
6763
6983
|
}
|
|
6764
|
-
},
|
|
6984
|
+
}, _class30);
|
|
6765
6985
|
|
|
6766
6986
|
// src/runners.ts
|
|
6767
6987
|
var Runner = class {
|