@inkeep/agents-run-api 0.0.0-dev-20251209035832 → 0.0.0-dev-20251211233416
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/dist/index.cjs +281 -268
- package/dist/index.js +217 -201
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1240,7 +1240,7 @@ var init_chunk_VBDAOXYI = __esm({
|
|
|
1240
1240
|
}], ["modifyTime", 12, 136, function(r, e) {
|
|
1241
1241
|
return k4(r[e[0]], e[1]);
|
|
1242
1242
|
}, function(r, e, t2) {
|
|
1243
|
-
return
|
|
1243
|
+
return z13(r.slice(e, e + t2[1]));
|
|
1244
1244
|
}], ["checksum", 8, 148, function(r, e) {
|
|
1245
1245
|
return " ";
|
|
1246
1246
|
}, function(r, e, t2) {
|
|
@@ -1282,11 +1282,11 @@ var init_chunk_VBDAOXYI = __esm({
|
|
|
1282
1282
|
}], ["accessTime", 12, 476, function(r, e) {
|
|
1283
1283
|
return k4(r[e[0]], e[1]);
|
|
1284
1284
|
}, function(r, e, t2) {
|
|
1285
|
-
return
|
|
1285
|
+
return z13(r.slice(e, e + t2[1]));
|
|
1286
1286
|
}], ["createTime", 12, 488, function(r, e) {
|
|
1287
1287
|
return k4(r[e[0]], e[1]);
|
|
1288
1288
|
}, function(r, e, t2) {
|
|
1289
|
-
return
|
|
1289
|
+
return z13(r.slice(e, e + t2[1]));
|
|
1290
1290
|
}]], $4 = (function(r) {
|
|
1291
1291
|
var e = r[r.length - 1];
|
|
1292
1292
|
return e[2] + e[1];
|
|
@@ -1323,7 +1323,7 @@ var init_chunk_VBDAOXYI = __esm({
|
|
|
1323
1323
|
var e = String.fromCharCode.apply(null, r);
|
|
1324
1324
|
return parseInt(e.replace(/^0+$/g, ""), 8) || 0;
|
|
1325
1325
|
}
|
|
1326
|
-
function
|
|
1326
|
+
function z13(r) {
|
|
1327
1327
|
return r.length == 0 || r[0] == 0 ? null : new Date(1e3 * S3(r));
|
|
1328
1328
|
}
|
|
1329
1329
|
function Tr2(r, e, t2) {
|
|
@@ -1349,7 +1349,7 @@ var init_chunk_VBDAOXYI = __esm({
|
|
|
1349
1349
|
f3.exports.formatTarDateTime = k4;
|
|
1350
1350
|
f3.exports.parseTarString = A2;
|
|
1351
1351
|
f3.exports.parseTarNumber = S3;
|
|
1352
|
-
f3.exports.parseTarDateTime =
|
|
1352
|
+
f3.exports.parseTarDateTime = z13;
|
|
1353
1353
|
});
|
|
1354
1354
|
er = D((ne3, rr) => {
|
|
1355
1355
|
u();
|
|
@@ -6530,8 +6530,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
6530
6530
|
});
|
|
6531
6531
|
referenceArtifacts.push(...artifacts);
|
|
6532
6532
|
}
|
|
6533
|
-
const
|
|
6534
|
-
|
|
6533
|
+
const logger28 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
6534
|
+
logger28.debug(
|
|
6535
6535
|
{
|
|
6536
6536
|
conversationId,
|
|
6537
6537
|
visibleMessages: visibleMessages.length,
|
|
@@ -6543,8 +6543,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
6543
6543
|
);
|
|
6544
6544
|
return referenceArtifacts;
|
|
6545
6545
|
} catch (error) {
|
|
6546
|
-
const
|
|
6547
|
-
|
|
6546
|
+
const logger28 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
6547
|
+
logger28.error(
|
|
6548
6548
|
{
|
|
6549
6549
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
6550
6550
|
conversationId
|
|
@@ -6586,14 +6586,14 @@ const execute = ${executeCode}
|
|
|
6586
6586
|
})();
|
|
6587
6587
|
`;
|
|
6588
6588
|
}
|
|
6589
|
-
function parseExecutionResult(stdout, functionId,
|
|
6589
|
+
function parseExecutionResult(stdout, functionId, logger28) {
|
|
6590
6590
|
try {
|
|
6591
6591
|
const outputLines = stdout.split("\n").filter((line) => line.trim());
|
|
6592
6592
|
const resultLine = outputLines[outputLines.length - 1];
|
|
6593
6593
|
return JSON.parse(resultLine);
|
|
6594
6594
|
} catch (parseError) {
|
|
6595
|
-
if (
|
|
6596
|
-
|
|
6595
|
+
if (logger28) {
|
|
6596
|
+
logger28.warn(
|
|
6597
6597
|
{
|
|
6598
6598
|
functionId,
|
|
6599
6599
|
stdout,
|
|
@@ -6609,13 +6609,13 @@ var init_sandbox_utils = __esm({
|
|
|
6609
6609
|
"src/tools/sandbox-utils.ts"() {
|
|
6610
6610
|
}
|
|
6611
6611
|
});
|
|
6612
|
-
var
|
|
6612
|
+
var logger15, ExecutionSemaphore, NativeSandboxExecutor;
|
|
6613
6613
|
var init_NativeSandboxExecutor = __esm({
|
|
6614
6614
|
"src/tools/NativeSandboxExecutor.ts"() {
|
|
6615
6615
|
init_execution_limits();
|
|
6616
6616
|
init_logger();
|
|
6617
6617
|
init_sandbox_utils();
|
|
6618
|
-
|
|
6618
|
+
logger15 = agentsCore.getLogger("native-sandbox-executor");
|
|
6619
6619
|
ExecutionSemaphore = class {
|
|
6620
6620
|
permits;
|
|
6621
6621
|
waitQueue = [];
|
|
@@ -6687,7 +6687,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6687
6687
|
getSemaphore(vcpus) {
|
|
6688
6688
|
const effectiveVcpus = Math.max(1, vcpus || 1);
|
|
6689
6689
|
if (!this.executionSemaphores.has(effectiveVcpus)) {
|
|
6690
|
-
|
|
6690
|
+
logger15.debug({ vcpus: effectiveVcpus }, "Creating new execution semaphore");
|
|
6691
6691
|
this.executionSemaphores.set(effectiveVcpus, new ExecutionSemaphore(effectiveVcpus));
|
|
6692
6692
|
}
|
|
6693
6693
|
const semaphore = this.executionSemaphores.get(effectiveVcpus);
|
|
@@ -6724,7 +6724,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6724
6724
|
if (now - sandbox.lastUsed < FUNCTION_TOOL_SANDBOX_POOL_TTL_MS && sandbox.useCount < FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
6725
6725
|
sandbox.lastUsed = now;
|
|
6726
6726
|
sandbox.useCount++;
|
|
6727
|
-
|
|
6727
|
+
logger15.debug(
|
|
6728
6728
|
{
|
|
6729
6729
|
poolKey,
|
|
6730
6730
|
useCount: sandbox.useCount,
|
|
@@ -6751,14 +6751,14 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6751
6751
|
useCount: 1,
|
|
6752
6752
|
dependencies
|
|
6753
6753
|
};
|
|
6754
|
-
|
|
6754
|
+
logger15.debug({ poolKey, sandboxDir }, "Added sandbox to pool");
|
|
6755
6755
|
}
|
|
6756
6756
|
cleanupSandbox(sandboxDir) {
|
|
6757
6757
|
try {
|
|
6758
6758
|
s3.rmSync(sandboxDir, { recursive: true, force: true });
|
|
6759
|
-
|
|
6759
|
+
logger15.debug({ sandboxDir }, "Cleaned up sandbox");
|
|
6760
6760
|
} catch (error) {
|
|
6761
|
-
|
|
6761
|
+
logger15.warn({ sandboxDir, error }, "Failed to clean up sandbox");
|
|
6762
6762
|
}
|
|
6763
6763
|
}
|
|
6764
6764
|
startPoolCleanup() {
|
|
@@ -6775,7 +6775,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6775
6775
|
delete this.sandboxPool[key];
|
|
6776
6776
|
});
|
|
6777
6777
|
if (keysToDelete.length > 0) {
|
|
6778
|
-
|
|
6778
|
+
logger15.debug({ cleanedCount: keysToDelete.length }, "Cleaned up expired sandboxes");
|
|
6779
6779
|
}
|
|
6780
6780
|
}, FUNCTION_TOOL_SANDBOX_CLEANUP_INTERVAL_MS);
|
|
6781
6781
|
}
|
|
@@ -6804,7 +6804,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6804
6804
|
return hasCjsSyntax ? "cjs" : "esm";
|
|
6805
6805
|
}
|
|
6806
6806
|
if (hasEsmSyntax && hasCjsSyntax) {
|
|
6807
|
-
|
|
6807
|
+
logger15.warn(
|
|
6808
6808
|
{ executeCode: `${executeCode.substring(0, 100)}...` },
|
|
6809
6809
|
"Both ESM and CommonJS syntax detected, defaulting to ESM"
|
|
6810
6810
|
);
|
|
@@ -6821,7 +6821,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6821
6821
|
async executeFunctionTool(toolId, args2, config) {
|
|
6822
6822
|
const vcpus = config.sandboxConfig?.vcpus || 1;
|
|
6823
6823
|
const semaphore = this.getSemaphore(vcpus);
|
|
6824
|
-
|
|
6824
|
+
logger15.debug(
|
|
6825
6825
|
{
|
|
6826
6826
|
toolId,
|
|
6827
6827
|
vcpus,
|
|
@@ -6839,7 +6839,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6839
6839
|
async executeInSandbox_Internal(toolId, args2, config) {
|
|
6840
6840
|
const dependencies = config.dependencies || {};
|
|
6841
6841
|
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
6842
|
-
|
|
6842
|
+
logger15.debug(
|
|
6843
6843
|
{
|
|
6844
6844
|
toolId,
|
|
6845
6845
|
dependencies,
|
|
@@ -6855,7 +6855,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6855
6855
|
sandboxDir = o3.join(this.tempDir, `sandbox-${dependencyHash}-${Date.now()}`);
|
|
6856
6856
|
s3.mkdirSync(sandboxDir, { recursive: true });
|
|
6857
6857
|
isNewSandbox = true;
|
|
6858
|
-
|
|
6858
|
+
logger15.debug(
|
|
6859
6859
|
{
|
|
6860
6860
|
toolId,
|
|
6861
6861
|
dependencyHash,
|
|
@@ -6926,15 +6926,15 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6926
6926
|
});
|
|
6927
6927
|
npm.on("close", (code) => {
|
|
6928
6928
|
if (code === 0) {
|
|
6929
|
-
|
|
6929
|
+
logger15.debug({ sandboxDir }, "Dependencies installed successfully");
|
|
6930
6930
|
resolve2();
|
|
6931
6931
|
} else {
|
|
6932
|
-
|
|
6932
|
+
logger15.error({ sandboxDir, code, stderr }, "Failed to install dependencies");
|
|
6933
6933
|
reject(new Error(`npm install failed with code ${code}: ${stderr}`));
|
|
6934
6934
|
}
|
|
6935
6935
|
});
|
|
6936
6936
|
npm.on("error", (err2) => {
|
|
6937
|
-
|
|
6937
|
+
logger15.error({ sandboxDir, error: err2 }, "Failed to spawn npm install");
|
|
6938
6938
|
reject(err2);
|
|
6939
6939
|
});
|
|
6940
6940
|
});
|
|
@@ -6981,7 +6981,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6981
6981
|
stderr += dataStr;
|
|
6982
6982
|
});
|
|
6983
6983
|
const timeoutId = setTimeout(() => {
|
|
6984
|
-
|
|
6984
|
+
logger15.warn({ sandboxDir, timeout }, "Function execution timed out, killing process");
|
|
6985
6985
|
node.kill("SIGTERM");
|
|
6986
6986
|
const forceKillTimeout = Math.min(Math.max(timeout / 10, 2e3), 5e3);
|
|
6987
6987
|
setTimeout(() => {
|
|
@@ -6996,7 +6996,7 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
6996
6996
|
clearTimeout(timeoutId);
|
|
6997
6997
|
if (code === 0) {
|
|
6998
6998
|
try {
|
|
6999
|
-
const result = parseExecutionResult(stdout, "function",
|
|
6999
|
+
const result = parseExecutionResult(stdout, "function", logger15);
|
|
7000
7000
|
if (typeof result === "object" && result !== null && "success" in result) {
|
|
7001
7001
|
const parsed = result;
|
|
7002
7002
|
if (parsed.success) {
|
|
@@ -7008,18 +7008,18 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
7008
7008
|
resolve2(result);
|
|
7009
7009
|
}
|
|
7010
7010
|
} catch (parseError) {
|
|
7011
|
-
|
|
7011
|
+
logger15.error({ stdout, stderr, parseError }, "Failed to parse function result");
|
|
7012
7012
|
reject(new Error(`Invalid function result: ${stdout}`));
|
|
7013
7013
|
}
|
|
7014
7014
|
} else {
|
|
7015
7015
|
const errorMsg = signal ? `Function execution killed by signal ${signal}: ${stderr}` : `Function execution failed with code ${code}: ${stderr}`;
|
|
7016
|
-
|
|
7016
|
+
logger15.error({ code, signal, stderr }, "Function execution failed");
|
|
7017
7017
|
reject(new Error(errorMsg));
|
|
7018
7018
|
}
|
|
7019
7019
|
});
|
|
7020
7020
|
node.on("error", (error) => {
|
|
7021
7021
|
clearTimeout(timeoutId);
|
|
7022
|
-
|
|
7022
|
+
logger15.error({ sandboxDir, error }, "Failed to spawn node process");
|
|
7023
7023
|
reject(error);
|
|
7024
7024
|
});
|
|
7025
7025
|
});
|
|
@@ -7027,13 +7027,13 @@ var init_NativeSandboxExecutor = __esm({
|
|
|
7027
7027
|
};
|
|
7028
7028
|
}
|
|
7029
7029
|
});
|
|
7030
|
-
var
|
|
7030
|
+
var logger16, VercelSandboxExecutor;
|
|
7031
7031
|
var init_VercelSandboxExecutor = __esm({
|
|
7032
7032
|
"src/tools/VercelSandboxExecutor.ts"() {
|
|
7033
7033
|
init_execution_limits();
|
|
7034
7034
|
init_logger();
|
|
7035
7035
|
init_sandbox_utils();
|
|
7036
|
-
|
|
7036
|
+
logger16 = agentsCore.getLogger("VercelSandboxExecutor");
|
|
7037
7037
|
VercelSandboxExecutor = class _VercelSandboxExecutor {
|
|
7038
7038
|
static instance;
|
|
7039
7039
|
config;
|
|
@@ -7041,7 +7041,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7041
7041
|
cleanupInterval = null;
|
|
7042
7042
|
constructor(config) {
|
|
7043
7043
|
this.config = config;
|
|
7044
|
-
|
|
7044
|
+
logger16.info(
|
|
7045
7045
|
{
|
|
7046
7046
|
teamId: config.teamId,
|
|
7047
7047
|
projectId: config.projectId,
|
|
@@ -7078,7 +7078,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7078
7078
|
const now = Date.now();
|
|
7079
7079
|
const age = now - cached.createdAt;
|
|
7080
7080
|
if (age > FUNCTION_TOOL_SANDBOX_POOL_TTL_MS || cached.useCount >= FUNCTION_TOOL_SANDBOX_MAX_USE_COUNT) {
|
|
7081
|
-
|
|
7081
|
+
logger16.debug(
|
|
7082
7082
|
{
|
|
7083
7083
|
dependencyHash,
|
|
7084
7084
|
age,
|
|
@@ -7091,7 +7091,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7091
7091
|
this.removeSandbox(dependencyHash);
|
|
7092
7092
|
return null;
|
|
7093
7093
|
}
|
|
7094
|
-
|
|
7094
|
+
logger16.debug(
|
|
7095
7095
|
{
|
|
7096
7096
|
dependencyHash,
|
|
7097
7097
|
useCount: cached.useCount,
|
|
@@ -7111,7 +7111,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7111
7111
|
useCount: 0,
|
|
7112
7112
|
dependencies
|
|
7113
7113
|
});
|
|
7114
|
-
|
|
7114
|
+
logger16.debug(
|
|
7115
7115
|
{
|
|
7116
7116
|
dependencyHash,
|
|
7117
7117
|
poolSize: this.sandboxPool.size
|
|
@@ -7136,9 +7136,9 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7136
7136
|
if (cached) {
|
|
7137
7137
|
try {
|
|
7138
7138
|
await cached.sandbox.stop();
|
|
7139
|
-
|
|
7139
|
+
logger16.debug({ dependencyHash }, "Sandbox stopped");
|
|
7140
7140
|
} catch (error) {
|
|
7141
|
-
|
|
7141
|
+
logger16.warn({ error, dependencyHash }, "Error stopping sandbox");
|
|
7142
7142
|
}
|
|
7143
7143
|
this.sandboxPool.delete(dependencyHash);
|
|
7144
7144
|
}
|
|
@@ -7157,7 +7157,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7157
7157
|
}
|
|
7158
7158
|
}
|
|
7159
7159
|
if (toRemove.length > 0) {
|
|
7160
|
-
|
|
7160
|
+
logger16.info(
|
|
7161
7161
|
{
|
|
7162
7162
|
count: toRemove.length,
|
|
7163
7163
|
poolSize: this.sandboxPool.size
|
|
@@ -7178,7 +7178,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7178
7178
|
clearInterval(this.cleanupInterval);
|
|
7179
7179
|
this.cleanupInterval = null;
|
|
7180
7180
|
}
|
|
7181
|
-
|
|
7181
|
+
logger16.info(
|
|
7182
7182
|
{
|
|
7183
7183
|
poolSize: this.sandboxPool.size
|
|
7184
7184
|
},
|
|
@@ -7215,7 +7215,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7215
7215
|
const envLines = [];
|
|
7216
7216
|
for (const varName of envVarNames) {
|
|
7217
7217
|
envLines.push(`${varName}=""`);
|
|
7218
|
-
|
|
7218
|
+
logger16.debug({ varName }, "Adding environment variable placeholder to sandbox");
|
|
7219
7219
|
}
|
|
7220
7220
|
return envLines.join("\n");
|
|
7221
7221
|
}
|
|
@@ -7228,7 +7228,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7228
7228
|
const dependencies = toolConfig.dependencies || {};
|
|
7229
7229
|
const dependencyHash = this.generateDependencyHash(dependencies);
|
|
7230
7230
|
try {
|
|
7231
|
-
|
|
7231
|
+
logger16.info(
|
|
7232
7232
|
{
|
|
7233
7233
|
functionId,
|
|
7234
7234
|
functionName: toolConfig.name,
|
|
@@ -7251,7 +7251,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7251
7251
|
},
|
|
7252
7252
|
runtime: this.config.runtime
|
|
7253
7253
|
});
|
|
7254
|
-
|
|
7254
|
+
logger16.info(
|
|
7255
7255
|
{
|
|
7256
7256
|
functionId,
|
|
7257
7257
|
sandboxId: sandbox$1.sandboxId,
|
|
@@ -7261,7 +7261,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7261
7261
|
);
|
|
7262
7262
|
this.addToPool(dependencyHash, sandbox$1, dependencies);
|
|
7263
7263
|
} else {
|
|
7264
|
-
|
|
7264
|
+
logger16.info(
|
|
7265
7265
|
{
|
|
7266
7266
|
functionId,
|
|
7267
7267
|
sandboxId: sandbox$1.sandboxId,
|
|
@@ -7273,7 +7273,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7273
7273
|
this.incrementUseCount(dependencyHash);
|
|
7274
7274
|
try {
|
|
7275
7275
|
if (isNewSandbox && toolConfig.dependencies && Object.keys(toolConfig.dependencies).length > 0) {
|
|
7276
|
-
|
|
7276
|
+
logger16.debug(
|
|
7277
7277
|
{
|
|
7278
7278
|
functionId,
|
|
7279
7279
|
functionName: toolConfig.name,
|
|
@@ -7306,7 +7306,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7306
7306
|
if (installCmd.exitCode !== 0) {
|
|
7307
7307
|
throw new Error(`Failed to install dependencies: ${installStderr}`);
|
|
7308
7308
|
}
|
|
7309
|
-
|
|
7309
|
+
logger16.info(
|
|
7310
7310
|
{
|
|
7311
7311
|
functionId,
|
|
7312
7312
|
dependencyHash
|
|
@@ -7329,7 +7329,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7329
7329
|
path: ".env",
|
|
7330
7330
|
content: Buffer.from(envFileContent, "utf-8")
|
|
7331
7331
|
});
|
|
7332
|
-
|
|
7332
|
+
logger16.info(
|
|
7333
7333
|
{
|
|
7334
7334
|
functionId,
|
|
7335
7335
|
envVarCount: envVars.size,
|
|
@@ -7340,7 +7340,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7340
7340
|
}
|
|
7341
7341
|
}
|
|
7342
7342
|
await sandbox$1.writeFiles(filesToWrite);
|
|
7343
|
-
|
|
7343
|
+
logger16.info(
|
|
7344
7344
|
{
|
|
7345
7345
|
functionId,
|
|
7346
7346
|
runtime: this.config.runtime === "typescript" ? "tsx" : "node",
|
|
@@ -7371,7 +7371,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7371
7371
|
}
|
|
7372
7372
|
const executionTime = Date.now() - startTime;
|
|
7373
7373
|
if (executeCmd.exitCode !== 0) {
|
|
7374
|
-
|
|
7374
|
+
logger16.error(
|
|
7375
7375
|
{
|
|
7376
7376
|
functionId,
|
|
7377
7377
|
exitCode: executeCmd.exitCode,
|
|
@@ -7386,8 +7386,8 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7386
7386
|
executionTime
|
|
7387
7387
|
};
|
|
7388
7388
|
}
|
|
7389
|
-
const result = parseExecutionResult(executeStdout, functionId,
|
|
7390
|
-
|
|
7389
|
+
const result = parseExecutionResult(executeStdout, functionId, logger16);
|
|
7390
|
+
logger16.info(
|
|
7391
7391
|
{
|
|
7392
7392
|
functionId,
|
|
7393
7393
|
executionTime
|
|
@@ -7407,7 +7407,7 @@ var init_VercelSandboxExecutor = __esm({
|
|
|
7407
7407
|
} catch (error) {
|
|
7408
7408
|
const executionTime = Date.now() - startTime;
|
|
7409
7409
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
7410
|
-
|
|
7410
|
+
logger16.error(
|
|
7411
7411
|
{
|
|
7412
7412
|
functionId,
|
|
7413
7413
|
error: errorMessage,
|
|
@@ -7432,19 +7432,19 @@ var SandboxExecutorFactory_exports = {};
|
|
|
7432
7432
|
__export(SandboxExecutorFactory_exports, {
|
|
7433
7433
|
SandboxExecutorFactory: () => SandboxExecutorFactory
|
|
7434
7434
|
});
|
|
7435
|
-
var
|
|
7435
|
+
var logger17, SandboxExecutorFactory;
|
|
7436
7436
|
var init_SandboxExecutorFactory = __esm({
|
|
7437
7437
|
"src/tools/SandboxExecutorFactory.ts"() {
|
|
7438
7438
|
init_logger();
|
|
7439
7439
|
init_NativeSandboxExecutor();
|
|
7440
7440
|
init_VercelSandboxExecutor();
|
|
7441
|
-
|
|
7441
|
+
logger17 = agentsCore.getLogger("SandboxExecutorFactory");
|
|
7442
7442
|
SandboxExecutorFactory = class _SandboxExecutorFactory {
|
|
7443
7443
|
static instance;
|
|
7444
7444
|
nativeExecutor = null;
|
|
7445
7445
|
vercelExecutors = /* @__PURE__ */ new Map();
|
|
7446
7446
|
constructor() {
|
|
7447
|
-
|
|
7447
|
+
logger17.info({}, "SandboxExecutorFactory initialized");
|
|
7448
7448
|
}
|
|
7449
7449
|
/**
|
|
7450
7450
|
* Get singleton instance of SandboxExecutorFactory
|
|
@@ -7477,7 +7477,7 @@ var init_SandboxExecutorFactory = __esm({
|
|
|
7477
7477
|
async executeInNativeSandbox(functionId, args2, config) {
|
|
7478
7478
|
if (!this.nativeExecutor) {
|
|
7479
7479
|
this.nativeExecutor = NativeSandboxExecutor.getInstance();
|
|
7480
|
-
|
|
7480
|
+
logger17.info({}, "Native sandbox executor created");
|
|
7481
7481
|
}
|
|
7482
7482
|
return this.nativeExecutor.executeFunctionTool(functionId, args2, config);
|
|
7483
7483
|
}
|
|
@@ -7490,7 +7490,7 @@ var init_SandboxExecutorFactory = __esm({
|
|
|
7490
7490
|
if (!this.vercelExecutors.has(configKey)) {
|
|
7491
7491
|
const executor2 = VercelSandboxExecutor.getInstance(vercelConfig);
|
|
7492
7492
|
this.vercelExecutors.set(configKey, executor2);
|
|
7493
|
-
|
|
7493
|
+
logger17.info(
|
|
7494
7494
|
{
|
|
7495
7495
|
teamId: vercelConfig.teamId,
|
|
7496
7496
|
projectId: vercelConfig.projectId
|
|
@@ -7512,13 +7512,13 @@ var init_SandboxExecutorFactory = __esm({
|
|
|
7512
7512
|
* Clean up all sandbox executors
|
|
7513
7513
|
*/
|
|
7514
7514
|
async cleanup() {
|
|
7515
|
-
|
|
7515
|
+
logger17.info({}, "Cleaning up sandbox executors");
|
|
7516
7516
|
this.nativeExecutor = null;
|
|
7517
7517
|
for (const [key, executor] of this.vercelExecutors.entries()) {
|
|
7518
7518
|
await executor.cleanup();
|
|
7519
7519
|
this.vercelExecutors.delete(key);
|
|
7520
7520
|
}
|
|
7521
|
-
|
|
7521
|
+
logger17.info({}, "Sandbox executor cleanup completed");
|
|
7522
7522
|
}
|
|
7523
7523
|
};
|
|
7524
7524
|
}
|
|
@@ -7619,6 +7619,10 @@ init_env();
|
|
|
7619
7619
|
init_logger();
|
|
7620
7620
|
|
|
7621
7621
|
// src/types/execution-context.ts
|
|
7622
|
+
function getUserIdFromContext(ctx) {
|
|
7623
|
+
const metadata2 = ctx.metadata;
|
|
7624
|
+
return metadata2?.initiatedBy?.type === "user" ? metadata2.initiatedBy.id : void 0;
|
|
7625
|
+
}
|
|
7622
7626
|
function createExecutionContext(params) {
|
|
7623
7627
|
return {
|
|
7624
7628
|
apiKey: params.apiKey,
|
|
@@ -12121,49 +12125,6 @@ function generateToolId() {
|
|
|
12121
12125
|
// src/utils/artifact-component-schema.ts
|
|
12122
12126
|
init_logger();
|
|
12123
12127
|
|
|
12124
|
-
// src/utils/data-component-schema.ts
|
|
12125
|
-
init_logger();
|
|
12126
|
-
var logger12 = agentsCore.getLogger("DataComponentSchema");
|
|
12127
|
-
function jsonSchemaToZod(jsonSchema) {
|
|
12128
|
-
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
12129
|
-
logger12.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
12130
|
-
return zodOpenapi.z.string();
|
|
12131
|
-
}
|
|
12132
|
-
switch (jsonSchema.type) {
|
|
12133
|
-
case "object":
|
|
12134
|
-
if (jsonSchema.properties) {
|
|
12135
|
-
const shape = {};
|
|
12136
|
-
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
12137
|
-
shape[key] = jsonSchemaToZod(prop);
|
|
12138
|
-
}
|
|
12139
|
-
return zodOpenapi.z.object(shape);
|
|
12140
|
-
}
|
|
12141
|
-
return zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown());
|
|
12142
|
-
case "array": {
|
|
12143
|
-
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : zodOpenapi.z.unknown();
|
|
12144
|
-
return zodOpenapi.z.array(itemSchema);
|
|
12145
|
-
}
|
|
12146
|
-
case "string":
|
|
12147
|
-
return zodOpenapi.z.string();
|
|
12148
|
-
case "number":
|
|
12149
|
-
case "integer":
|
|
12150
|
-
return zodOpenapi.z.number();
|
|
12151
|
-
case "boolean":
|
|
12152
|
-
return zodOpenapi.z.boolean();
|
|
12153
|
-
case "null":
|
|
12154
|
-
return zodOpenapi.z.null();
|
|
12155
|
-
default:
|
|
12156
|
-
logger12.warn(
|
|
12157
|
-
{
|
|
12158
|
-
unsupportedType: jsonSchema.type,
|
|
12159
|
-
schema: jsonSchema
|
|
12160
|
-
},
|
|
12161
|
-
"Unsupported JSON schema type, using unknown validation"
|
|
12162
|
-
);
|
|
12163
|
-
return zodOpenapi.z.unknown();
|
|
12164
|
-
}
|
|
12165
|
-
}
|
|
12166
|
-
|
|
12167
12128
|
// src/utils/SchemaProcessor.ts
|
|
12168
12129
|
init_logger();
|
|
12169
12130
|
var SchemaProcessor = class _SchemaProcessor {
|
|
@@ -12410,7 +12371,7 @@ var ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
|
12410
12371
|
return zodOpenapi.z.object({
|
|
12411
12372
|
id: zodOpenapi.z.string(),
|
|
12412
12373
|
name: zodOpenapi.z.literal("Artifact"),
|
|
12413
|
-
props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
|
|
12374
|
+
props: agentsCore.jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
|
|
12414
12375
|
});
|
|
12415
12376
|
}
|
|
12416
12377
|
/**
|
|
@@ -12463,7 +12424,7 @@ var ArtifactCreateSchema = class {
|
|
|
12463
12424
|
return zodOpenapi.z.object({
|
|
12464
12425
|
id: zodOpenapi.z.string(),
|
|
12465
12426
|
name: zodOpenapi.z.literal(`ArtifactCreate_${component.name}`),
|
|
12466
|
-
props: jsonSchemaToZod(propsSchema)
|
|
12427
|
+
props: agentsCore.jsonSchemaToZod(propsSchema)
|
|
12467
12428
|
});
|
|
12468
12429
|
});
|
|
12469
12430
|
}
|
|
@@ -12523,7 +12484,7 @@ function parseEmbeddedJson(data) {
|
|
|
12523
12484
|
|
|
12524
12485
|
// src/a2a/client.ts
|
|
12525
12486
|
init_logger();
|
|
12526
|
-
var
|
|
12487
|
+
var logger12 = agentsCore.getLogger("a2aClient");
|
|
12527
12488
|
var DEFAULT_BACKOFF = {
|
|
12528
12489
|
initialInterval: 500,
|
|
12529
12490
|
maxInterval: 6e4,
|
|
@@ -12730,7 +12691,7 @@ var A2AClient = class {
|
|
|
12730
12691
|
try {
|
|
12731
12692
|
const res = await fn2();
|
|
12732
12693
|
if (attempt > 0) {
|
|
12733
|
-
|
|
12694
|
+
logger12.info(
|
|
12734
12695
|
{
|
|
12735
12696
|
attempts: attempt + 1,
|
|
12736
12697
|
elapsedTime: Date.now() - start2
|
|
@@ -12745,7 +12706,7 @@ var A2AClient = class {
|
|
|
12745
12706
|
}
|
|
12746
12707
|
const elapsed = Date.now() - start2;
|
|
12747
12708
|
if (elapsed > maxElapsedTime) {
|
|
12748
|
-
|
|
12709
|
+
logger12.warn(
|
|
12749
12710
|
{
|
|
12750
12711
|
attempts: attempt + 1,
|
|
12751
12712
|
elapsedTime: elapsed,
|
|
@@ -12766,7 +12727,7 @@ var A2AClient = class {
|
|
|
12766
12727
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
12767
12728
|
}
|
|
12768
12729
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
12769
|
-
|
|
12730
|
+
logger12.info(
|
|
12770
12731
|
{
|
|
12771
12732
|
attempt: attempt + 1,
|
|
12772
12733
|
delayMs,
|
|
@@ -12857,7 +12818,7 @@ var A2AClient = class {
|
|
|
12857
12818
|
});
|
|
12858
12819
|
}
|
|
12859
12820
|
if (rpcResponse.id !== requestId2) {
|
|
12860
|
-
|
|
12821
|
+
logger12.warn(
|
|
12861
12822
|
{
|
|
12862
12823
|
method,
|
|
12863
12824
|
expectedId: requestId2,
|
|
@@ -13054,7 +13015,7 @@ var A2AClient = class {
|
|
|
13054
13015
|
try {
|
|
13055
13016
|
while (true) {
|
|
13056
13017
|
const { done, value } = await reader.read();
|
|
13057
|
-
|
|
13018
|
+
logger12.info({ done, value }, "parseA2ASseStream");
|
|
13058
13019
|
if (done) {
|
|
13059
13020
|
if (eventDataBuffer.trim()) {
|
|
13060
13021
|
const result = this._processSseEventData(
|
|
@@ -13145,7 +13106,7 @@ init_execution_limits();
|
|
|
13145
13106
|
init_conversations();
|
|
13146
13107
|
init_dbClient();
|
|
13147
13108
|
init_logger();
|
|
13148
|
-
var
|
|
13109
|
+
var logger13 = agentsCore.getLogger("relationships Tools");
|
|
13149
13110
|
var A2A_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
|
|
13150
13111
|
var generateTransferToolDescription = (config) => {
|
|
13151
13112
|
let toolsSection = "";
|
|
@@ -13256,7 +13217,7 @@ var createTransferToAgentTool = ({
|
|
|
13256
13217
|
[agentsCore.SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
|
|
13257
13218
|
});
|
|
13258
13219
|
}
|
|
13259
|
-
|
|
13220
|
+
logger13.info(
|
|
13260
13221
|
{
|
|
13261
13222
|
transferTo: transferConfig.id ?? "unknown",
|
|
13262
13223
|
fromSubAgent: callingAgentId
|
|
@@ -13277,7 +13238,7 @@ var createTransferToAgentTool = ({
|
|
|
13277
13238
|
fromSubAgentId: callingAgentId
|
|
13278
13239
|
// Include the calling agent ID for tracking
|
|
13279
13240
|
};
|
|
13280
|
-
|
|
13241
|
+
logger13.info(
|
|
13281
13242
|
{
|
|
13282
13243
|
transferResult,
|
|
13283
13244
|
transferResultKeys: Object.keys(transferResult)
|
|
@@ -13424,7 +13385,7 @@ function createDelegateToAgentTool({
|
|
|
13424
13385
|
...isInternal ? { fromSubAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
13425
13386
|
}
|
|
13426
13387
|
};
|
|
13427
|
-
|
|
13388
|
+
logger13.info({ messageToSend }, "messageToSend");
|
|
13428
13389
|
await agentsCore.createMessage(dbClient_default)({
|
|
13429
13390
|
id: agentsCore.generateId(),
|
|
13430
13391
|
tenantId,
|
|
@@ -13487,7 +13448,7 @@ function createDelegateToAgentTool({
|
|
|
13487
13448
|
|
|
13488
13449
|
// src/agents/SystemPromptBuilder.ts
|
|
13489
13450
|
init_logger();
|
|
13490
|
-
var
|
|
13451
|
+
var logger14 = agentsCore.getLogger("SystemPromptBuilder");
|
|
13491
13452
|
var SystemPromptBuilder = class {
|
|
13492
13453
|
constructor(version, versionConfig) {
|
|
13493
13454
|
this.version = version;
|
|
@@ -13503,12 +13464,12 @@ var SystemPromptBuilder = class {
|
|
|
13503
13464
|
this.templates.set(name2, content);
|
|
13504
13465
|
}
|
|
13505
13466
|
this.loaded = true;
|
|
13506
|
-
|
|
13467
|
+
logger14.debug(
|
|
13507
13468
|
{ templateCount: this.templates.size, version: this.version },
|
|
13508
13469
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
13509
13470
|
);
|
|
13510
13471
|
} catch (error) {
|
|
13511
|
-
|
|
13472
|
+
logger14.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
13512
13473
|
throw new Error(`Template loading failed: ${error}`);
|
|
13513
13474
|
}
|
|
13514
13475
|
}
|
|
@@ -14599,7 +14560,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
14599
14560
|
return false;
|
|
14600
14561
|
};
|
|
14601
14562
|
}
|
|
14602
|
-
var
|
|
14563
|
+
var logger18 = agentsCore.getLogger("Agent");
|
|
14603
14564
|
function validateModel(modelString, modelType) {
|
|
14604
14565
|
if (!modelString?.trim()) {
|
|
14605
14566
|
throw new Error(
|
|
@@ -14872,7 +14833,7 @@ var Agent = class {
|
|
|
14872
14833
|
};
|
|
14873
14834
|
await agentsCore.createMessage(dbClient_default)(messagePayload);
|
|
14874
14835
|
} catch (error) {
|
|
14875
|
-
|
|
14836
|
+
logger18.warn(
|
|
14876
14837
|
{ error, toolName, toolCallId, conversationId: toolResultConversationId },
|
|
14877
14838
|
"Failed to store tool result in conversation history"
|
|
14878
14839
|
);
|
|
@@ -14988,11 +14949,11 @@ var Agent = class {
|
|
|
14988
14949
|
for (const toolResult of tools) {
|
|
14989
14950
|
for (const [toolName, originalTool] of Object.entries(toolResult.tools)) {
|
|
14990
14951
|
if (!isValidTool(originalTool)) {
|
|
14991
|
-
|
|
14952
|
+
logger18.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
14992
14953
|
continue;
|
|
14993
14954
|
}
|
|
14994
14955
|
const needsApproval = toolResult.toolPolicies?.[toolName]?.needsApproval || false;
|
|
14995
|
-
|
|
14956
|
+
logger18.debug(
|
|
14996
14957
|
{
|
|
14997
14958
|
toolName,
|
|
14998
14959
|
toolPolicies: toolResult.toolPolicies,
|
|
@@ -15006,7 +14967,7 @@ var Agent = class {
|
|
|
15006
14967
|
inputSchema: originalTool.inputSchema,
|
|
15007
14968
|
execute: async (args2, { toolCallId }) => {
|
|
15008
14969
|
if (needsApproval) {
|
|
15009
|
-
|
|
14970
|
+
logger18.info(
|
|
15010
14971
|
{ toolName, toolCallId, args: args2 },
|
|
15011
14972
|
"Tool requires approval - waiting for user response"
|
|
15012
14973
|
);
|
|
@@ -15052,7 +15013,7 @@ var Agent = class {
|
|
|
15052
15013
|
}
|
|
15053
15014
|
},
|
|
15054
15015
|
(denialSpan) => {
|
|
15055
|
-
|
|
15016
|
+
logger18.info(
|
|
15056
15017
|
{ toolName, toolCallId, reason: approvalResult.reason },
|
|
15057
15018
|
"Tool execution denied by user"
|
|
15058
15019
|
);
|
|
@@ -15073,18 +15034,18 @@ var Agent = class {
|
|
|
15073
15034
|
}
|
|
15074
15035
|
},
|
|
15075
15036
|
(approvedSpan) => {
|
|
15076
|
-
|
|
15037
|
+
logger18.info({ toolName, toolCallId }, "Tool approved, continuing with execution");
|
|
15077
15038
|
approvedSpan.setStatus({ code: api.SpanStatusCode.OK });
|
|
15078
15039
|
approvedSpan.end();
|
|
15079
15040
|
}
|
|
15080
15041
|
);
|
|
15081
15042
|
}
|
|
15082
|
-
|
|
15043
|
+
logger18.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
15083
15044
|
try {
|
|
15084
15045
|
const rawResult = await originalTool.execute(args2, { toolCallId });
|
|
15085
15046
|
if (rawResult && typeof rawResult === "object" && rawResult.isError) {
|
|
15086
15047
|
const errorMessage = rawResult.content?.[0]?.text || "MCP tool returned an error";
|
|
15087
|
-
|
|
15048
|
+
logger18.error(
|
|
15088
15049
|
{ toolName, toolCallId, errorMessage, rawResult },
|
|
15089
15050
|
"MCP tool returned error status"
|
|
15090
15051
|
);
|
|
@@ -15135,7 +15096,7 @@ var Agent = class {
|
|
|
15135
15096
|
});
|
|
15136
15097
|
return { result: enhancedResult, toolCallId };
|
|
15137
15098
|
} catch (error) {
|
|
15138
|
-
|
|
15099
|
+
logger18.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
15139
15100
|
throw error;
|
|
15140
15101
|
}
|
|
15141
15102
|
}
|
|
@@ -15189,7 +15150,51 @@ var Agent = class {
|
|
|
15189
15150
|
const selectedTools = toolRelation?.selectedTools || void 0;
|
|
15190
15151
|
const toolPolicies = toolRelation?.toolPolicies || {};
|
|
15191
15152
|
let serverConfig;
|
|
15192
|
-
|
|
15153
|
+
const isUserScoped = tool3.credentialScope === "user";
|
|
15154
|
+
const userId = this.config.userId;
|
|
15155
|
+
if (isUserScoped && userId && this.credentialStuffer) {
|
|
15156
|
+
const userCredentialReference = await agentsCore.getUserScopedCredentialReference(dbClient_default)({
|
|
15157
|
+
scopes: {
|
|
15158
|
+
tenantId: this.config.tenantId,
|
|
15159
|
+
projectId: this.config.projectId
|
|
15160
|
+
},
|
|
15161
|
+
toolId: tool3.id,
|
|
15162
|
+
userId
|
|
15163
|
+
});
|
|
15164
|
+
if (userCredentialReference) {
|
|
15165
|
+
const storeReference = {
|
|
15166
|
+
credentialStoreId: userCredentialReference.credentialStoreId,
|
|
15167
|
+
retrievalParams: userCredentialReference.retrievalParams || {}
|
|
15168
|
+
};
|
|
15169
|
+
serverConfig = await this.credentialStuffer.buildMcpServerConfig(
|
|
15170
|
+
{
|
|
15171
|
+
tenantId: this.config.tenantId,
|
|
15172
|
+
projectId: this.config.projectId,
|
|
15173
|
+
contextConfigId: this.config.contextConfigId || void 0,
|
|
15174
|
+
conversationId: this.conversationId || void 0
|
|
15175
|
+
},
|
|
15176
|
+
this.convertToMCPToolConfig(tool3, agentToolRelationHeaders),
|
|
15177
|
+
storeReference,
|
|
15178
|
+
selectedTools
|
|
15179
|
+
);
|
|
15180
|
+
} else {
|
|
15181
|
+
logger18.warn(
|
|
15182
|
+
{ toolId: tool3.id, userId },
|
|
15183
|
+
"User-scoped tool has no credential connected for this user"
|
|
15184
|
+
);
|
|
15185
|
+
serverConfig = await this.credentialStuffer.buildMcpServerConfig(
|
|
15186
|
+
{
|
|
15187
|
+
tenantId: this.config.tenantId,
|
|
15188
|
+
projectId: this.config.projectId,
|
|
15189
|
+
contextConfigId: this.config.contextConfigId || void 0,
|
|
15190
|
+
conversationId: this.conversationId || void 0
|
|
15191
|
+
},
|
|
15192
|
+
this.convertToMCPToolConfig(tool3, agentToolRelationHeaders),
|
|
15193
|
+
void 0,
|
|
15194
|
+
selectedTools
|
|
15195
|
+
);
|
|
15196
|
+
}
|
|
15197
|
+
} else if (credentialReferenceId && this.credentialStuffer) {
|
|
15193
15198
|
const credentialReference = await agentsCore.getCredentialReference(dbClient_default)({
|
|
15194
15199
|
scopes: {
|
|
15195
15200
|
tenantId: this.config.tenantId,
|
|
@@ -15239,7 +15244,7 @@ var Agent = class {
|
|
|
15239
15244
|
headers: agentToolRelationHeaders
|
|
15240
15245
|
};
|
|
15241
15246
|
}
|
|
15242
|
-
|
|
15247
|
+
logger18.info(
|
|
15243
15248
|
{
|
|
15244
15249
|
toolName: tool3.name,
|
|
15245
15250
|
credentialReferenceId,
|
|
@@ -15264,7 +15269,7 @@ var Agent = class {
|
|
|
15264
15269
|
this.mcpClientCache.set(cacheKey, client);
|
|
15265
15270
|
} catch (error) {
|
|
15266
15271
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
15267
|
-
|
|
15272
|
+
logger18.error(
|
|
15268
15273
|
{
|
|
15269
15274
|
toolName: tool3.name,
|
|
15270
15275
|
subAgentId: this.config.id,
|
|
@@ -15329,7 +15334,7 @@ var Agent = class {
|
|
|
15329
15334
|
await client.connect();
|
|
15330
15335
|
return client;
|
|
15331
15336
|
} catch (error) {
|
|
15332
|
-
|
|
15337
|
+
logger18.error(
|
|
15333
15338
|
{
|
|
15334
15339
|
toolName: tool3.name,
|
|
15335
15340
|
subAgentId: this.config.id,
|
|
@@ -15371,7 +15376,7 @@ var Agent = class {
|
|
|
15371
15376
|
for (const functionToolDef of functionToolsData) {
|
|
15372
15377
|
const functionId = functionToolDef.functionId;
|
|
15373
15378
|
if (!functionId) {
|
|
15374
|
-
|
|
15379
|
+
logger18.warn(
|
|
15375
15380
|
{ functionToolId: functionToolDef.id },
|
|
15376
15381
|
"Function tool missing functionId reference"
|
|
15377
15382
|
);
|
|
@@ -15385,18 +15390,18 @@ var Agent = class {
|
|
|
15385
15390
|
}
|
|
15386
15391
|
});
|
|
15387
15392
|
if (!functionData) {
|
|
15388
|
-
|
|
15393
|
+
logger18.warn(
|
|
15389
15394
|
{ functionId, functionToolId: functionToolDef.id },
|
|
15390
15395
|
"Function not found in functions table"
|
|
15391
15396
|
);
|
|
15392
15397
|
continue;
|
|
15393
15398
|
}
|
|
15394
|
-
const zodSchema = jsonSchemaToZod(functionData.inputSchema);
|
|
15399
|
+
const zodSchema = agentsCore.jsonSchemaToZod(functionData.inputSchema);
|
|
15395
15400
|
const aiTool = ai.tool({
|
|
15396
15401
|
description: functionToolDef.description || functionToolDef.name,
|
|
15397
15402
|
inputSchema: zodSchema,
|
|
15398
15403
|
execute: async (args2, { toolCallId }) => {
|
|
15399
|
-
|
|
15404
|
+
logger18.debug(
|
|
15400
15405
|
{ toolName: functionToolDef.name, toolCallId, args: args2 },
|
|
15401
15406
|
"Function Tool Called"
|
|
15402
15407
|
);
|
|
@@ -15423,7 +15428,7 @@ var Agent = class {
|
|
|
15423
15428
|
});
|
|
15424
15429
|
return { result, toolCallId };
|
|
15425
15430
|
} catch (error) {
|
|
15426
|
-
|
|
15431
|
+
logger18.error(
|
|
15427
15432
|
{
|
|
15428
15433
|
toolName: functionToolDef.name,
|
|
15429
15434
|
toolCallId,
|
|
@@ -15443,7 +15448,7 @@ var Agent = class {
|
|
|
15443
15448
|
);
|
|
15444
15449
|
}
|
|
15445
15450
|
} catch (error) {
|
|
15446
|
-
|
|
15451
|
+
logger18.error({ error }, "Failed to load function tools from database");
|
|
15447
15452
|
}
|
|
15448
15453
|
return functionTools;
|
|
15449
15454
|
}
|
|
@@ -15453,7 +15458,7 @@ var Agent = class {
|
|
|
15453
15458
|
async getResolvedContext(conversationId, headers2) {
|
|
15454
15459
|
try {
|
|
15455
15460
|
if (!this.config.contextConfigId) {
|
|
15456
|
-
|
|
15461
|
+
logger18.debug({ agentId: this.config.agentId }, "No context config found for agent");
|
|
15457
15462
|
return null;
|
|
15458
15463
|
}
|
|
15459
15464
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -15465,7 +15470,7 @@ var Agent = class {
|
|
|
15465
15470
|
id: this.config.contextConfigId
|
|
15466
15471
|
});
|
|
15467
15472
|
if (!contextConfig) {
|
|
15468
|
-
|
|
15473
|
+
logger18.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
15469
15474
|
return null;
|
|
15470
15475
|
}
|
|
15471
15476
|
if (!this.contextResolver) {
|
|
@@ -15481,7 +15486,7 @@ var Agent = class {
|
|
|
15481
15486
|
...result.resolvedContext,
|
|
15482
15487
|
$env: process.env
|
|
15483
15488
|
};
|
|
15484
|
-
|
|
15489
|
+
logger18.debug(
|
|
15485
15490
|
{
|
|
15486
15491
|
conversationId,
|
|
15487
15492
|
contextConfigId: contextConfig.id,
|
|
@@ -15495,7 +15500,7 @@ var Agent = class {
|
|
|
15495
15500
|
);
|
|
15496
15501
|
return contextWithBuiltins;
|
|
15497
15502
|
} catch (error) {
|
|
15498
|
-
|
|
15503
|
+
logger18.error(
|
|
15499
15504
|
{
|
|
15500
15505
|
conversationId,
|
|
15501
15506
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -15519,7 +15524,7 @@ var Agent = class {
|
|
|
15519
15524
|
});
|
|
15520
15525
|
return agentDefinition?.prompt || void 0;
|
|
15521
15526
|
} catch (error) {
|
|
15522
|
-
|
|
15527
|
+
logger18.warn(
|
|
15523
15528
|
{
|
|
15524
15529
|
agentId: this.config.agentId,
|
|
15525
15530
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -15548,7 +15553,7 @@ var Agent = class {
|
|
|
15548
15553
|
(subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
|
|
15549
15554
|
);
|
|
15550
15555
|
} catch (error) {
|
|
15551
|
-
|
|
15556
|
+
logger18.warn(
|
|
15552
15557
|
{
|
|
15553
15558
|
agentId: this.config.agentId,
|
|
15554
15559
|
tenantId: this.config.tenantId,
|
|
@@ -15577,7 +15582,7 @@ var Agent = class {
|
|
|
15577
15582
|
preserveUnresolved: false
|
|
15578
15583
|
});
|
|
15579
15584
|
} catch (error) {
|
|
15580
|
-
|
|
15585
|
+
logger18.error(
|
|
15581
15586
|
{
|
|
15582
15587
|
conversationId,
|
|
15583
15588
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -15624,7 +15629,7 @@ var Agent = class {
|
|
|
15624
15629
|
preserveUnresolved: false
|
|
15625
15630
|
});
|
|
15626
15631
|
} catch (error) {
|
|
15627
|
-
|
|
15632
|
+
logger18.error(
|
|
15628
15633
|
{
|
|
15629
15634
|
conversationId,
|
|
15630
15635
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -15639,7 +15644,7 @@ var Agent = class {
|
|
|
15639
15644
|
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
15640
15645
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
15641
15646
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
15642
|
-
|
|
15647
|
+
logger18.info(
|
|
15643
15648
|
{
|
|
15644
15649
|
mcpTools: Object.keys(mcpTools),
|
|
15645
15650
|
functionTools: Object.keys(functionTools),
|
|
@@ -15678,7 +15683,7 @@ var Agent = class {
|
|
|
15678
15683
|
preserveUnresolved: false
|
|
15679
15684
|
});
|
|
15680
15685
|
} catch (error) {
|
|
15681
|
-
|
|
15686
|
+
logger18.error(
|
|
15682
15687
|
{
|
|
15683
15688
|
conversationId,
|
|
15684
15689
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -15711,7 +15716,7 @@ var Agent = class {
|
|
|
15711
15716
|
toolCallId: zodOpenapi.z.string().describe("The tool call ID associated with this artifact.")
|
|
15712
15717
|
}),
|
|
15713
15718
|
execute: async ({ artifactId, toolCallId }) => {
|
|
15714
|
-
|
|
15719
|
+
logger18.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
15715
15720
|
const streamRequestId = this.getStreamRequestId();
|
|
15716
15721
|
const artifactService = agentSessionManager.getArtifactService(streamRequestId);
|
|
15717
15722
|
if (!artifactService) {
|
|
@@ -16007,7 +16012,7 @@ ${output}`;
|
|
|
16007
16012
|
};
|
|
16008
16013
|
return enhanced;
|
|
16009
16014
|
} catch (error) {
|
|
16010
|
-
|
|
16015
|
+
logger18.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
16011
16016
|
return result;
|
|
16012
16017
|
}
|
|
16013
16018
|
}
|
|
@@ -16022,7 +16027,7 @@ ${output}`;
|
|
|
16022
16027
|
}
|
|
16023
16028
|
});
|
|
16024
16029
|
} catch (error) {
|
|
16025
|
-
|
|
16030
|
+
logger18.error(
|
|
16026
16031
|
{ error, agentId: this.config.agentId },
|
|
16027
16032
|
"Failed to check agent artifact components"
|
|
16028
16033
|
);
|
|
@@ -16139,7 +16144,7 @@ ${output}`;
|
|
|
16139
16144
|
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING : LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING;
|
|
16140
16145
|
const timeoutMs = Math.min(configuredTimeout, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS);
|
|
16141
16146
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
16142
|
-
|
|
16147
|
+
logger18.warn(
|
|
16143
16148
|
{
|
|
16144
16149
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
16145
16150
|
appliedTimeout: timeoutMs,
|
|
@@ -16181,7 +16186,7 @@ ${output}`;
|
|
|
16181
16186
|
}
|
|
16182
16187
|
);
|
|
16183
16188
|
} catch (error) {
|
|
16184
|
-
|
|
16189
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
16185
16190
|
}
|
|
16186
16191
|
}
|
|
16187
16192
|
if (last && last["content"] && last["content"].length > 0) {
|
|
@@ -16316,7 +16321,7 @@ ${output}`;
|
|
|
16316
16321
|
}
|
|
16317
16322
|
);
|
|
16318
16323
|
} catch (error) {
|
|
16319
|
-
|
|
16324
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
16320
16325
|
}
|
|
16321
16326
|
}
|
|
16322
16327
|
if (steps.length >= 2) {
|
|
@@ -16426,7 +16431,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
16426
16431
|
const componentSchemas = [];
|
|
16427
16432
|
if (this.config.dataComponents && this.config.dataComponents.length > 0) {
|
|
16428
16433
|
this.config.dataComponents.forEach((dc) => {
|
|
16429
|
-
const propsSchema = jsonSchemaToZod(dc.props);
|
|
16434
|
+
const propsSchema = agentsCore.jsonSchemaToZod(dc.props);
|
|
16430
16435
|
componentSchemas.push(
|
|
16431
16436
|
zodOpenapi.z.object({
|
|
16432
16437
|
id: zodOpenapi.z.string(),
|
|
@@ -16463,7 +16468,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
16463
16468
|
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
16464
16469
|
);
|
|
16465
16470
|
if (structuredModelSettings.maxDuration && structuredModelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
16466
|
-
|
|
16471
|
+
logger18.warn(
|
|
16467
16472
|
{
|
|
16468
16473
|
requestedTimeout: structuredModelSettings.maxDuration * 1e3,
|
|
16469
16474
|
appliedTimeout: phase2TimeoutMs,
|
|
@@ -16639,7 +16644,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
16639
16644
|
};
|
|
16640
16645
|
|
|
16641
16646
|
// src/agents/generateTaskHandler.ts
|
|
16642
|
-
var
|
|
16647
|
+
var logger19 = agentsCore.getLogger("generateTaskHandler");
|
|
16643
16648
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
16644
16649
|
return async (task) => {
|
|
16645
16650
|
try {
|
|
@@ -16757,7 +16762,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
16757
16762
|
return { ...relation, description: enhancedDescription };
|
|
16758
16763
|
}
|
|
16759
16764
|
} catch (error) {
|
|
16760
|
-
|
|
16765
|
+
logger19.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
|
|
16761
16766
|
}
|
|
16762
16767
|
return relation;
|
|
16763
16768
|
})
|
|
@@ -16815,7 +16820,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
16815
16820
|
};
|
|
16816
16821
|
}
|
|
16817
16822
|
} catch (error) {
|
|
16818
|
-
|
|
16823
|
+
logger19.warn(
|
|
16819
16824
|
{ targetAgentId: relation.targetAgentId, error },
|
|
16820
16825
|
"Failed to enhance team agent description"
|
|
16821
16826
|
);
|
|
@@ -16832,7 +16837,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
16832
16837
|
item.tool,
|
|
16833
16838
|
dbClient_default,
|
|
16834
16839
|
credentialStoreRegistry,
|
|
16835
|
-
item.id
|
|
16840
|
+
item.id,
|
|
16841
|
+
config.userId
|
|
16836
16842
|
);
|
|
16837
16843
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
16838
16844
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
@@ -16849,6 +16855,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
16849
16855
|
agentId: config.agentId,
|
|
16850
16856
|
baseUrl: config.baseUrl,
|
|
16851
16857
|
apiKey: config.apiKey,
|
|
16858
|
+
userId: config.userId,
|
|
16852
16859
|
name: config.name,
|
|
16853
16860
|
description: config.description || "",
|
|
16854
16861
|
prompt,
|
|
@@ -16902,7 +16909,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
16902
16909
|
targetTransferRelations = transferRel;
|
|
16903
16910
|
targetDelegateRelations = delegateRel;
|
|
16904
16911
|
} catch (err2) {
|
|
16905
|
-
|
|
16912
|
+
logger19.info(
|
|
16906
16913
|
{
|
|
16907
16914
|
agentId: relation.id,
|
|
16908
16915
|
error: err2?.message || "Unknown error"
|
|
@@ -16916,7 +16923,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
16916
16923
|
item.tool,
|
|
16917
16924
|
dbClient_default,
|
|
16918
16925
|
credentialStoreRegistry,
|
|
16919
|
-
item.id
|
|
16926
|
+
item.id,
|
|
16927
|
+
config.userId
|
|
16920
16928
|
);
|
|
16921
16929
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
16922
16930
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
@@ -17042,7 +17050,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17042
17050
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
17043
17051
|
if (taskIdMatch) {
|
|
17044
17052
|
contextId = taskIdMatch[1];
|
|
17045
|
-
|
|
17053
|
+
logger19.info(
|
|
17046
17054
|
{
|
|
17047
17055
|
taskId: task.id,
|
|
17048
17056
|
extractedContextId: contextId,
|
|
@@ -17060,7 +17068,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17060
17068
|
agent.setDelegationStatus(isDelegation);
|
|
17061
17069
|
agent.setDelegationId(delegationId);
|
|
17062
17070
|
if (isDelegation) {
|
|
17063
|
-
|
|
17071
|
+
logger19.info(
|
|
17064
17072
|
{ subAgentId: config.subAgentId, taskId: task.id, delegationId },
|
|
17065
17073
|
"Delegated agent - streaming disabled"
|
|
17066
17074
|
);
|
|
@@ -17097,7 +17105,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17097
17105
|
const toolResult = allToolResults.find(
|
|
17098
17106
|
(result) => result.toolCallId === toolCall.toolCallId
|
|
17099
17107
|
);
|
|
17100
|
-
|
|
17108
|
+
logger19.info(
|
|
17101
17109
|
{
|
|
17102
17110
|
toolCallName: toolCall.toolName,
|
|
17103
17111
|
toolCallId: toolCall.toolCallId,
|
|
@@ -17114,7 +17122,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17114
17122
|
const transferReason = responseText || allThoughts[allThoughts.length - 1]?.text || "Agent requested transfer. No reason provided.";
|
|
17115
17123
|
if (toolResult?.output && isValidTransferResult(toolResult.output)) {
|
|
17116
17124
|
const transferResult = toolResult.output;
|
|
17117
|
-
|
|
17125
|
+
logger19.info(
|
|
17118
17126
|
{
|
|
17119
17127
|
validationPassed: true,
|
|
17120
17128
|
transferResult,
|
|
@@ -17131,7 +17139,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17131
17139
|
reason: transferReason,
|
|
17132
17140
|
original_message: userMessage
|
|
17133
17141
|
};
|
|
17134
|
-
|
|
17142
|
+
logger19.info(
|
|
17135
17143
|
{
|
|
17136
17144
|
artifactData,
|
|
17137
17145
|
artifactDataKeys: Object.keys(artifactData)
|
|
@@ -17156,7 +17164,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
17156
17164
|
]
|
|
17157
17165
|
};
|
|
17158
17166
|
}
|
|
17159
|
-
|
|
17167
|
+
logger19.warn(
|
|
17160
17168
|
{
|
|
17161
17169
|
hasToolResult: !!toolResult,
|
|
17162
17170
|
hasOutput: !!toolResult?.output,
|
|
@@ -17242,14 +17250,15 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
17242
17250
|
description: subAgent.description || void 0,
|
|
17243
17251
|
conversationHistoryConfig: effectiveConversationHistoryConfig,
|
|
17244
17252
|
contextConfigId: agent?.contextConfigId || void 0,
|
|
17245
|
-
sandboxConfig: params.sandboxConfig
|
|
17253
|
+
sandboxConfig: params.sandboxConfig,
|
|
17254
|
+
userId: params.userId
|
|
17246
17255
|
};
|
|
17247
17256
|
};
|
|
17248
17257
|
|
|
17249
17258
|
// src/data/agents.ts
|
|
17250
17259
|
init_logger();
|
|
17251
17260
|
init_dbClient();
|
|
17252
|
-
var
|
|
17261
|
+
var logger20 = agentsCore.getLogger("agents");
|
|
17253
17262
|
function createAgentCard({
|
|
17254
17263
|
dbAgent,
|
|
17255
17264
|
baseUrl
|
|
@@ -17319,7 +17328,8 @@ async function hydrateAgent({
|
|
|
17319
17328
|
baseUrl,
|
|
17320
17329
|
apiKey,
|
|
17321
17330
|
credentialStoreRegistry,
|
|
17322
|
-
sandboxConfig
|
|
17331
|
+
sandboxConfig,
|
|
17332
|
+
userId
|
|
17323
17333
|
}) {
|
|
17324
17334
|
try {
|
|
17325
17335
|
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
@@ -17329,7 +17339,8 @@ async function hydrateAgent({
|
|
|
17329
17339
|
subAgentId: dbAgent.id,
|
|
17330
17340
|
baseUrl,
|
|
17331
17341
|
apiKey,
|
|
17332
|
-
sandboxConfig
|
|
17342
|
+
sandboxConfig,
|
|
17343
|
+
userId
|
|
17333
17344
|
});
|
|
17334
17345
|
const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
|
|
17335
17346
|
const agentCard = createAgentCard({
|
|
@@ -17352,12 +17363,13 @@ async function hydrateAgent({
|
|
|
17352
17363
|
async function getRegisteredAgent(params) {
|
|
17353
17364
|
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
17354
17365
|
const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
17366
|
+
const userId = getUserIdFromContext(executionContext);
|
|
17355
17367
|
let dbAgent;
|
|
17356
17368
|
if (!subAgentId) {
|
|
17357
17369
|
const agent = await agentsCore.getAgentWithDefaultSubAgent(dbClient_default)({
|
|
17358
17370
|
scopes: { tenantId, projectId, agentId }
|
|
17359
17371
|
});
|
|
17360
|
-
|
|
17372
|
+
logger20.info({ agent }, "agent with default sub agent");
|
|
17361
17373
|
if (!agent || !agent.defaultSubAgent) {
|
|
17362
17374
|
return null;
|
|
17363
17375
|
}
|
|
@@ -17382,7 +17394,8 @@ async function getRegisteredAgent(params) {
|
|
|
17382
17394
|
baseUrl: agentFrameworkBaseUrl,
|
|
17383
17395
|
credentialStoreRegistry,
|
|
17384
17396
|
apiKey,
|
|
17385
|
-
sandboxConfig
|
|
17397
|
+
sandboxConfig,
|
|
17398
|
+
userId
|
|
17386
17399
|
});
|
|
17387
17400
|
}
|
|
17388
17401
|
|
|
@@ -17390,7 +17403,7 @@ async function getRegisteredAgent(params) {
|
|
|
17390
17403
|
init_dbClient();
|
|
17391
17404
|
init_logger();
|
|
17392
17405
|
var app = new zodOpenapi.OpenAPIHono();
|
|
17393
|
-
var
|
|
17406
|
+
var logger21 = agentsCore.getLogger("agents");
|
|
17394
17407
|
app.openapi(
|
|
17395
17408
|
zodOpenapi.createRoute({
|
|
17396
17409
|
method: "get",
|
|
@@ -17428,7 +17441,7 @@ app.openapi(
|
|
|
17428
17441
|
tracestate: c2.req.header("tracestate"),
|
|
17429
17442
|
baggage: c2.req.header("baggage")
|
|
17430
17443
|
};
|
|
17431
|
-
|
|
17444
|
+
logger21.info(
|
|
17432
17445
|
{
|
|
17433
17446
|
otelHeaders,
|
|
17434
17447
|
path: c2.req.path,
|
|
@@ -17438,8 +17451,8 @@ app.openapi(
|
|
|
17438
17451
|
);
|
|
17439
17452
|
const executionContext = agentsCore.getRequestExecutionContext(c2);
|
|
17440
17453
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
17441
|
-
|
|
17442
|
-
|
|
17454
|
+
logger21.info({ executionContext }, "executionContext");
|
|
17455
|
+
logger21.info(
|
|
17443
17456
|
{
|
|
17444
17457
|
message: "getRegisteredAgent (agent-level)",
|
|
17445
17458
|
tenantId,
|
|
@@ -17456,7 +17469,7 @@ app.openapi(
|
|
|
17456
17469
|
credentialStoreRegistry: credentialStores,
|
|
17457
17470
|
sandboxConfig
|
|
17458
17471
|
});
|
|
17459
|
-
|
|
17472
|
+
logger21.info({ agent }, "agent registered: well-known agent.json");
|
|
17460
17473
|
if (!agent) {
|
|
17461
17474
|
throw agentsCore.createApiError({
|
|
17462
17475
|
code: "not_found",
|
|
@@ -17472,7 +17485,7 @@ app.post("/a2a", async (c2) => {
|
|
|
17472
17485
|
tracestate: c2.req.header("tracestate"),
|
|
17473
17486
|
baggage: c2.req.header("baggage")
|
|
17474
17487
|
};
|
|
17475
|
-
|
|
17488
|
+
logger21.info(
|
|
17476
17489
|
{
|
|
17477
17490
|
otelHeaders,
|
|
17478
17491
|
path: c2.req.path,
|
|
@@ -17483,7 +17496,7 @@ app.post("/a2a", async (c2) => {
|
|
|
17483
17496
|
const executionContext = agentsCore.getRequestExecutionContext(c2);
|
|
17484
17497
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
17485
17498
|
if (subAgentId) {
|
|
17486
|
-
|
|
17499
|
+
logger21.info(
|
|
17487
17500
|
{
|
|
17488
17501
|
message: "a2a (agent-level)",
|
|
17489
17502
|
tenantId,
|
|
@@ -17512,7 +17525,7 @@ app.post("/a2a", async (c2) => {
|
|
|
17512
17525
|
}
|
|
17513
17526
|
return a2aHandler(c2, agent2);
|
|
17514
17527
|
}
|
|
17515
|
-
|
|
17528
|
+
logger21.info(
|
|
17516
17529
|
{
|
|
17517
17530
|
message: "a2a (agent-level)",
|
|
17518
17531
|
tenantId,
|
|
@@ -17597,14 +17610,14 @@ function extractTransferData(task) {
|
|
|
17597
17610
|
}
|
|
17598
17611
|
|
|
17599
17612
|
// src/a2a/transfer.ts
|
|
17600
|
-
var
|
|
17613
|
+
var logger22 = agentsCore.getLogger("Transfer");
|
|
17601
17614
|
async function executeTransfer({
|
|
17602
17615
|
tenantId,
|
|
17603
17616
|
threadId,
|
|
17604
17617
|
projectId,
|
|
17605
17618
|
targetSubAgentId
|
|
17606
17619
|
}) {
|
|
17607
|
-
|
|
17620
|
+
logger22.info(
|
|
17608
17621
|
{
|
|
17609
17622
|
targetAgent: targetSubAgentId,
|
|
17610
17623
|
threadId,
|
|
@@ -17619,12 +17632,12 @@ async function executeTransfer({
|
|
|
17619
17632
|
threadId,
|
|
17620
17633
|
subAgentId: targetSubAgentId
|
|
17621
17634
|
});
|
|
17622
|
-
|
|
17635
|
+
logger22.info(
|
|
17623
17636
|
{ targetAgent: targetSubAgentId, threadId },
|
|
17624
17637
|
"Successfully updated active_sub_agent_id in database"
|
|
17625
17638
|
);
|
|
17626
17639
|
} catch (error) {
|
|
17627
|
-
|
|
17640
|
+
logger22.error(
|
|
17628
17641
|
{ error, targetAgent: targetSubAgentId, threadId },
|
|
17629
17642
|
"Failed to update active_sub_agent_id"
|
|
17630
17643
|
);
|
|
@@ -18196,7 +18209,7 @@ function createBufferingStreamHelper() {
|
|
|
18196
18209
|
var createMCPStreamHelper = createBufferingStreamHelper;
|
|
18197
18210
|
|
|
18198
18211
|
// src/handlers/executionHandler.ts
|
|
18199
|
-
var
|
|
18212
|
+
var logger23 = agentsCore.getLogger("ExecutionHandler");
|
|
18200
18213
|
var ExecutionHandler = class {
|
|
18201
18214
|
MAX_ERRORS = AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS;
|
|
18202
18215
|
/**
|
|
@@ -18229,7 +18242,7 @@ var ExecutionHandler = class {
|
|
|
18229
18242
|
if (emitOperations) {
|
|
18230
18243
|
agentSessionManager.enableEmitOperations(requestId2);
|
|
18231
18244
|
}
|
|
18232
|
-
|
|
18245
|
+
logger23.info(
|
|
18233
18246
|
{ sessionId: requestId2, agentId, conversationId, emitOperations },
|
|
18234
18247
|
"Created AgentSession for message execution"
|
|
18235
18248
|
);
|
|
@@ -18262,7 +18275,7 @@ var ExecutionHandler = class {
|
|
|
18262
18275
|
);
|
|
18263
18276
|
}
|
|
18264
18277
|
} catch (modelError) {
|
|
18265
|
-
|
|
18278
|
+
logger23.warn(
|
|
18266
18279
|
{
|
|
18267
18280
|
error: modelError instanceof Error ? modelError.message : "Unknown error",
|
|
18268
18281
|
agentId
|
|
@@ -18277,7 +18290,7 @@ var ExecutionHandler = class {
|
|
|
18277
18290
|
}
|
|
18278
18291
|
}
|
|
18279
18292
|
} catch (error) {
|
|
18280
|
-
|
|
18293
|
+
logger23.error(
|
|
18281
18294
|
{
|
|
18282
18295
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
18283
18296
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -18293,7 +18306,7 @@ var ExecutionHandler = class {
|
|
|
18293
18306
|
try {
|
|
18294
18307
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
|
|
18295
18308
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
18296
|
-
|
|
18309
|
+
logger23.info(
|
|
18297
18310
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
18298
18311
|
"Attempting to create or reuse existing task"
|
|
18299
18312
|
);
|
|
@@ -18317,7 +18330,7 @@ var ExecutionHandler = class {
|
|
|
18317
18330
|
sub_agent_id: currentAgentId
|
|
18318
18331
|
}
|
|
18319
18332
|
});
|
|
18320
|
-
|
|
18333
|
+
logger23.info(
|
|
18321
18334
|
{
|
|
18322
18335
|
taskId,
|
|
18323
18336
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -18326,27 +18339,27 @@ var ExecutionHandler = class {
|
|
|
18326
18339
|
);
|
|
18327
18340
|
} catch (error) {
|
|
18328
18341
|
if (error?.cause?.code === "23505") {
|
|
18329
|
-
|
|
18342
|
+
logger23.info(
|
|
18330
18343
|
{ taskId, error: error.message },
|
|
18331
18344
|
"Task already exists, fetching existing task"
|
|
18332
18345
|
);
|
|
18333
18346
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
18334
18347
|
if (existingTask) {
|
|
18335
18348
|
task = existingTask;
|
|
18336
|
-
|
|
18349
|
+
logger23.info(
|
|
18337
18350
|
{ taskId, existingTask },
|
|
18338
18351
|
"Successfully reused existing task from race condition"
|
|
18339
18352
|
);
|
|
18340
18353
|
} else {
|
|
18341
|
-
|
|
18354
|
+
logger23.error({ taskId, error }, "Task constraint failed but task not found");
|
|
18342
18355
|
throw error;
|
|
18343
18356
|
}
|
|
18344
18357
|
} else {
|
|
18345
|
-
|
|
18358
|
+
logger23.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
18346
18359
|
throw error;
|
|
18347
18360
|
}
|
|
18348
18361
|
}
|
|
18349
|
-
|
|
18362
|
+
logger23.debug(
|
|
18350
18363
|
{
|
|
18351
18364
|
timestamp: /* @__PURE__ */ new Date(),
|
|
18352
18365
|
executionType: "create_initial_task",
|
|
@@ -18365,7 +18378,7 @@ var ExecutionHandler = class {
|
|
|
18365
18378
|
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? agentsCore.AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT;
|
|
18366
18379
|
while (iterations < maxTransfers) {
|
|
18367
18380
|
iterations++;
|
|
18368
|
-
|
|
18381
|
+
logger23.info(
|
|
18369
18382
|
{ iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
|
|
18370
18383
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
|
|
18371
18384
|
);
|
|
@@ -18373,10 +18386,10 @@ var ExecutionHandler = class {
|
|
|
18373
18386
|
scopes: { tenantId, projectId },
|
|
18374
18387
|
conversationId
|
|
18375
18388
|
});
|
|
18376
|
-
|
|
18389
|
+
logger23.info({ activeAgent }, "activeAgent");
|
|
18377
18390
|
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
18378
18391
|
currentAgentId = activeAgent.activeSubAgentId;
|
|
18379
|
-
|
|
18392
|
+
logger23.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
18380
18393
|
}
|
|
18381
18394
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
18382
18395
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -18417,13 +18430,13 @@ var ExecutionHandler = class {
|
|
|
18417
18430
|
});
|
|
18418
18431
|
if (!messageResponse?.result) {
|
|
18419
18432
|
errorCount++;
|
|
18420
|
-
|
|
18433
|
+
logger23.error(
|
|
18421
18434
|
{ currentAgentId, iterations, errorCount },
|
|
18422
18435
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
18423
18436
|
);
|
|
18424
18437
|
if (errorCount >= this.MAX_ERRORS) {
|
|
18425
18438
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
18426
|
-
|
|
18439
|
+
logger23.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
18427
18440
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
18428
18441
|
if (task) {
|
|
18429
18442
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -18447,7 +18460,7 @@ var ExecutionHandler = class {
|
|
|
18447
18460
|
if (isTransferTask(messageResponse.result)) {
|
|
18448
18461
|
const transferData = extractTransferData(messageResponse.result);
|
|
18449
18462
|
if (!transferData) {
|
|
18450
|
-
|
|
18463
|
+
logger23.error(
|
|
18451
18464
|
{ result: messageResponse.result },
|
|
18452
18465
|
"Transfer detected but no transfer data found"
|
|
18453
18466
|
);
|
|
@@ -18456,7 +18469,7 @@ var ExecutionHandler = class {
|
|
|
18456
18469
|
const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
|
|
18457
18470
|
const firstArtifact = messageResponse.result.artifacts[0];
|
|
18458
18471
|
const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
|
|
18459
|
-
|
|
18472
|
+
logger23.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
|
|
18460
18473
|
await agentsCore.createMessage(dbClient_default)({
|
|
18461
18474
|
id: agentsCore.generateId(),
|
|
18462
18475
|
tenantId,
|
|
@@ -18487,7 +18500,7 @@ var ExecutionHandler = class {
|
|
|
18487
18500
|
if (success) {
|
|
18488
18501
|
fromSubAgentId = currentAgentId;
|
|
18489
18502
|
currentAgentId = newAgentId;
|
|
18490
|
-
|
|
18503
|
+
logger23.info(
|
|
18491
18504
|
{
|
|
18492
18505
|
transferFrom: fromSubAgentId,
|
|
18493
18506
|
transferTo: currentAgentId,
|
|
@@ -18501,7 +18514,7 @@ var ExecutionHandler = class {
|
|
|
18501
18514
|
let responseParts = [];
|
|
18502
18515
|
if (messageResponse.result.streamedContent?.parts) {
|
|
18503
18516
|
responseParts = messageResponse.result.streamedContent.parts;
|
|
18504
|
-
|
|
18517
|
+
logger23.info(
|
|
18505
18518
|
{ partsCount: responseParts.length },
|
|
18506
18519
|
"Using streamed content for conversation history"
|
|
18507
18520
|
);
|
|
@@ -18509,7 +18522,7 @@ var ExecutionHandler = class {
|
|
|
18509
18522
|
responseParts = messageResponse.result.artifacts?.flatMap(
|
|
18510
18523
|
(artifact) => artifact.parts || []
|
|
18511
18524
|
) || [];
|
|
18512
|
-
|
|
18525
|
+
logger23.info(
|
|
18513
18526
|
{ partsCount: responseParts.length },
|
|
18514
18527
|
"Using artifacts for conversation history (fallback)"
|
|
18515
18528
|
);
|
|
@@ -18518,7 +18531,7 @@ var ExecutionHandler = class {
|
|
|
18518
18531
|
const agentSessionData = agentSessionManager.getSession(requestId2);
|
|
18519
18532
|
if (agentSessionData) {
|
|
18520
18533
|
const sessionSummary = agentSessionData.getSummary();
|
|
18521
|
-
|
|
18534
|
+
logger23.info(sessionSummary, "AgentSession data after completion");
|
|
18522
18535
|
}
|
|
18523
18536
|
let textContent = "";
|
|
18524
18537
|
for (const part of responseParts) {
|
|
@@ -18572,22 +18585,22 @@ var ExecutionHandler = class {
|
|
|
18572
18585
|
}
|
|
18573
18586
|
});
|
|
18574
18587
|
const updateTaskEnd = Date.now();
|
|
18575
|
-
|
|
18588
|
+
logger23.info(
|
|
18576
18589
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
18577
18590
|
"Completed updateTask operation"
|
|
18578
18591
|
);
|
|
18579
18592
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
18580
18593
|
await sseHelper.complete();
|
|
18581
|
-
|
|
18594
|
+
logger23.info({}, "Ending AgentSession and cleaning up");
|
|
18582
18595
|
await agentSessionManager.endSession(requestId2);
|
|
18583
|
-
|
|
18596
|
+
logger23.info({}, "Cleaning up streamHelper");
|
|
18584
18597
|
unregisterStreamHelper(requestId2);
|
|
18585
18598
|
let response;
|
|
18586
18599
|
if (sseHelper instanceof BufferingStreamHelper) {
|
|
18587
18600
|
const captured = sseHelper.getCapturedResponse();
|
|
18588
18601
|
response = captured.text || "No response content";
|
|
18589
18602
|
}
|
|
18590
|
-
|
|
18603
|
+
logger23.info({}, "ExecutionHandler returning success");
|
|
18591
18604
|
return { success: true, iterations, response };
|
|
18592
18605
|
} catch (error) {
|
|
18593
18606
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -18598,13 +18611,13 @@ var ExecutionHandler = class {
|
|
|
18598
18611
|
});
|
|
18599
18612
|
}
|
|
18600
18613
|
errorCount++;
|
|
18601
|
-
|
|
18614
|
+
logger23.warn(
|
|
18602
18615
|
{ iterations, errorCount },
|
|
18603
18616
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
18604
18617
|
);
|
|
18605
18618
|
if (errorCount >= this.MAX_ERRORS) {
|
|
18606
18619
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
18607
|
-
|
|
18620
|
+
logger23.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
18608
18621
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
18609
18622
|
if (task) {
|
|
18610
18623
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -18625,7 +18638,7 @@ var ExecutionHandler = class {
|
|
|
18625
18638
|
}
|
|
18626
18639
|
}
|
|
18627
18640
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
18628
|
-
|
|
18641
|
+
logger23.error({ maxTransfers, iterations }, errorMessage);
|
|
18629
18642
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
18630
18643
|
if (task) {
|
|
18631
18644
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -18644,7 +18657,7 @@ var ExecutionHandler = class {
|
|
|
18644
18657
|
unregisterStreamHelper(requestId2);
|
|
18645
18658
|
return { success: false, error: errorMessage, iterations };
|
|
18646
18659
|
} catch (error) {
|
|
18647
|
-
|
|
18660
|
+
logger23.error({ error }, "Error in execution handler");
|
|
18648
18661
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
18649
18662
|
await sseHelper.writeOperation(
|
|
18650
18663
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -18672,7 +18685,7 @@ var ExecutionHandler = class {
|
|
|
18672
18685
|
// src/routes/chat.ts
|
|
18673
18686
|
init_logger();
|
|
18674
18687
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
18675
|
-
var
|
|
18688
|
+
var logger24 = agentsCore.getLogger("completionsHandler");
|
|
18676
18689
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
18677
18690
|
method: "post",
|
|
18678
18691
|
path: "/completions",
|
|
@@ -18790,7 +18803,7 @@ app2.openapi(chatCompletionsRoute, async (c2) => {
|
|
|
18790
18803
|
tracestate: c2.req.header("tracestate"),
|
|
18791
18804
|
baggage: c2.req.header("baggage")
|
|
18792
18805
|
};
|
|
18793
|
-
|
|
18806
|
+
logger24.info(
|
|
18794
18807
|
{
|
|
18795
18808
|
otelHeaders,
|
|
18796
18809
|
path: c2.req.path,
|
|
@@ -18899,7 +18912,7 @@ app2.openapi(chatCompletionsRoute, async (c2) => {
|
|
|
18899
18912
|
dbClient: dbClient_default,
|
|
18900
18913
|
credentialStores
|
|
18901
18914
|
});
|
|
18902
|
-
|
|
18915
|
+
logger24.info(
|
|
18903
18916
|
{
|
|
18904
18917
|
tenantId,
|
|
18905
18918
|
projectId,
|
|
@@ -18947,7 +18960,7 @@ app2.openapi(chatCompletionsRoute, async (c2) => {
|
|
|
18947
18960
|
try {
|
|
18948
18961
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
18949
18962
|
await sseHelper.writeRole();
|
|
18950
|
-
|
|
18963
|
+
logger24.info({ subAgentId }, "Starting execution");
|
|
18951
18964
|
const emitOperationsHeader = c2.req.header("x-emit-operations");
|
|
18952
18965
|
const emitOperations = emitOperationsHeader === "true";
|
|
18953
18966
|
const executionHandler = new ExecutionHandler();
|
|
@@ -18960,7 +18973,7 @@ app2.openapi(chatCompletionsRoute, async (c2) => {
|
|
|
18960
18973
|
sseHelper,
|
|
18961
18974
|
emitOperations
|
|
18962
18975
|
});
|
|
18963
|
-
|
|
18976
|
+
logger24.info(
|
|
18964
18977
|
{ result },
|
|
18965
18978
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
18966
18979
|
);
|
|
@@ -18974,7 +18987,7 @@ app2.openapi(chatCompletionsRoute, async (c2) => {
|
|
|
18974
18987
|
}
|
|
18975
18988
|
await sseHelper.complete();
|
|
18976
18989
|
} catch (error) {
|
|
18977
|
-
|
|
18990
|
+
logger24.error(
|
|
18978
18991
|
{
|
|
18979
18992
|
error: error instanceof Error ? error.message : error,
|
|
18980
18993
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -18991,13 +19004,13 @@ app2.openapi(chatCompletionsRoute, async (c2) => {
|
|
|
18991
19004
|
);
|
|
18992
19005
|
await sseHelper.complete();
|
|
18993
19006
|
} catch (streamError) {
|
|
18994
|
-
|
|
19007
|
+
logger24.error({ streamError }, "Failed to write error to stream");
|
|
18995
19008
|
}
|
|
18996
19009
|
}
|
|
18997
19010
|
});
|
|
18998
19011
|
});
|
|
18999
19012
|
} catch (error) {
|
|
19000
|
-
|
|
19013
|
+
logger24.error(
|
|
19001
19014
|
{
|
|
19002
19015
|
error: error instanceof Error ? error.message : error,
|
|
19003
19016
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -19025,7 +19038,7 @@ var chat_default = app2;
|
|
|
19025
19038
|
init_dbClient();
|
|
19026
19039
|
init_logger();
|
|
19027
19040
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
19028
|
-
var
|
|
19041
|
+
var logger25 = agentsCore.getLogger("chatDataStream");
|
|
19029
19042
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
19030
19043
|
method: "post",
|
|
19031
19044
|
path: "/chat",
|
|
@@ -19152,7 +19165,7 @@ app3.openapi(chatDataStreamRoute, async (c2) => {
|
|
|
19152
19165
|
});
|
|
19153
19166
|
const lastUserMessage = body2.messages.filter((m4) => m4.role === "user").slice(-1)[0];
|
|
19154
19167
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p4) => p4.text).join("") || "";
|
|
19155
|
-
|
|
19168
|
+
logger25.info({ userText, lastUserMessage }, "userText");
|
|
19156
19169
|
const messageSpan = api.trace.getActiveSpan();
|
|
19157
19170
|
if (messageSpan) {
|
|
19158
19171
|
messageSpan.setAttributes({
|
|
@@ -19235,7 +19248,7 @@ app3.openapi(chatDataStreamRoute, async (c2) => {
|
|
|
19235
19248
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
19236
19249
|
}
|
|
19237
19250
|
} catch (err2) {
|
|
19238
|
-
|
|
19251
|
+
logger25.error({ err: err2 }, "Streaming error");
|
|
19239
19252
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
19240
19253
|
} finally {
|
|
19241
19254
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -19257,7 +19270,7 @@ app3.openapi(chatDataStreamRoute, async (c2) => {
|
|
|
19257
19270
|
);
|
|
19258
19271
|
});
|
|
19259
19272
|
} catch (error) {
|
|
19260
|
-
|
|
19273
|
+
logger25.error(
|
|
19261
19274
|
{
|
|
19262
19275
|
error,
|
|
19263
19276
|
errorMessage: error instanceof Error ? error.message : String(error),
|
|
@@ -19346,7 +19359,7 @@ app3.openapi(toolApprovalRoute, async (c2) => {
|
|
|
19346
19359
|
const { tenantId, projectId } = executionContext;
|
|
19347
19360
|
const requestBody = await c2.req.json();
|
|
19348
19361
|
const { conversationId, toolCallId, approved, reason } = requestBody;
|
|
19349
|
-
|
|
19362
|
+
logger25.info(
|
|
19350
19363
|
{
|
|
19351
19364
|
conversationId,
|
|
19352
19365
|
toolCallId,
|
|
@@ -19375,7 +19388,7 @@ app3.openapi(toolApprovalRoute, async (c2) => {
|
|
|
19375
19388
|
span.setStatus({ code: 1, message: "Tool call not found" });
|
|
19376
19389
|
return c2.json({ error: "Tool call not found or already processed" }, 404);
|
|
19377
19390
|
}
|
|
19378
|
-
|
|
19391
|
+
logger25.info({ conversationId, toolCallId, approved }, "Tool approval processed successfully");
|
|
19379
19392
|
span.setStatus({ code: 1, message: "Success" });
|
|
19380
19393
|
return c2.json({
|
|
19381
19394
|
success: true,
|
|
@@ -19383,7 +19396,7 @@ app3.openapi(toolApprovalRoute, async (c2) => {
|
|
|
19383
19396
|
});
|
|
19384
19397
|
} catch (error) {
|
|
19385
19398
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
19386
|
-
|
|
19399
|
+
logger25.error(
|
|
19387
19400
|
{
|
|
19388
19401
|
error: errorMessage,
|
|
19389
19402
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -19408,7 +19421,7 @@ var chatDataStream_default = app3;
|
|
|
19408
19421
|
// src/routes/mcp.ts
|
|
19409
19422
|
init_dbClient();
|
|
19410
19423
|
init_logger();
|
|
19411
|
-
var
|
|
19424
|
+
var logger26 = agentsCore.getLogger("mcp");
|
|
19412
19425
|
var MockResponseSingleton = class _MockResponseSingleton {
|
|
19413
19426
|
static instance;
|
|
19414
19427
|
mockRes;
|
|
@@ -19462,21 +19475,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
19462
19475
|
id: 0
|
|
19463
19476
|
});
|
|
19464
19477
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
19465
|
-
|
|
19478
|
+
logger26.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
19466
19479
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
19467
19480
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
19468
19481
|
try {
|
|
19469
19482
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
19470
|
-
|
|
19483
|
+
logger26.info({ sessionId }, "Successfully spoofed initialization");
|
|
19471
19484
|
} catch (spoofError) {
|
|
19472
|
-
|
|
19485
|
+
logger26.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
19473
19486
|
}
|
|
19474
19487
|
};
|
|
19475
19488
|
var validateSession = async (req, res, body2, tenantId, projectId, agentId) => {
|
|
19476
19489
|
const sessionId = req.headers["mcp-session-id"];
|
|
19477
|
-
|
|
19490
|
+
logger26.info({ sessionId }, "Received MCP session ID");
|
|
19478
19491
|
if (!sessionId) {
|
|
19479
|
-
|
|
19492
|
+
logger26.info({ body: body2 }, "Missing session ID");
|
|
19480
19493
|
res.writeHead(400).end(
|
|
19481
19494
|
JSON.stringify({
|
|
19482
19495
|
jsonrpc: "2.0",
|
|
@@ -19503,7 +19516,7 @@ var validateSession = async (req, res, body2, tenantId, projectId, agentId) => {
|
|
|
19503
19516
|
scopes: { tenantId, projectId },
|
|
19504
19517
|
conversationId: sessionId
|
|
19505
19518
|
});
|
|
19506
|
-
|
|
19519
|
+
logger26.info(
|
|
19507
19520
|
{
|
|
19508
19521
|
sessionId,
|
|
19509
19522
|
conversationFound: !!conversation,
|
|
@@ -19514,7 +19527,7 @@ var validateSession = async (req, res, body2, tenantId, projectId, agentId) => {
|
|
|
19514
19527
|
"Conversation lookup result"
|
|
19515
19528
|
);
|
|
19516
19529
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
|
|
19517
|
-
|
|
19530
|
+
logger26.info(
|
|
19518
19531
|
{ sessionId, conversationId: conversation?.id },
|
|
19519
19532
|
"MCP session not found or invalid"
|
|
19520
19533
|
);
|
|
@@ -19575,7 +19588,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
19575
19588
|
requestId: requestId2,
|
|
19576
19589
|
sseHelper: mcpStreamHelper
|
|
19577
19590
|
});
|
|
19578
|
-
|
|
19591
|
+
logger26.info(
|
|
19579
19592
|
{ result },
|
|
19580
19593
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
19581
19594
|
);
|
|
@@ -19659,7 +19672,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
19659
19672
|
dbClient: dbClient_default,
|
|
19660
19673
|
credentialStores
|
|
19661
19674
|
});
|
|
19662
|
-
|
|
19675
|
+
logger26.info(
|
|
19663
19676
|
{
|
|
19664
19677
|
tenantId,
|
|
19665
19678
|
projectId,
|
|
@@ -19721,7 +19734,7 @@ var validateRequestParameters = (c2) => {
|
|
|
19721
19734
|
};
|
|
19722
19735
|
var handleInitializationRequest = async (body2, executionContext, validatedContext, req, res, c2, credentialStores) => {
|
|
19723
19736
|
const { tenantId, projectId, agentId } = executionContext;
|
|
19724
|
-
|
|
19737
|
+
logger26.info({ body: body2 }, "Received initialization request");
|
|
19725
19738
|
const sessionId = agentsCore.getConversationId();
|
|
19726
19739
|
const activeSpan = api.trace.getActiveSpan();
|
|
19727
19740
|
if (activeSpan) {
|
|
@@ -19777,7 +19790,7 @@ var handleInitializationRequest = async (body2, executionContext, validatedConte
|
|
|
19777
19790
|
}
|
|
19778
19791
|
}
|
|
19779
19792
|
});
|
|
19780
|
-
|
|
19793
|
+
logger26.info(
|
|
19781
19794
|
{ sessionId, conversationId: conversation.id },
|
|
19782
19795
|
"Created MCP session as conversation"
|
|
19783
19796
|
);
|
|
@@ -19786,9 +19799,9 @@ var handleInitializationRequest = async (body2, executionContext, validatedConte
|
|
|
19786
19799
|
});
|
|
19787
19800
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
19788
19801
|
await server.connect(transport);
|
|
19789
|
-
|
|
19802
|
+
logger26.info({ sessionId }, "Server connected for initialization");
|
|
19790
19803
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
19791
|
-
|
|
19804
|
+
logger26.info(
|
|
19792
19805
|
{
|
|
19793
19806
|
sessionId,
|
|
19794
19807
|
bodyMethod: body2?.method,
|
|
@@ -19797,7 +19810,7 @@ var handleInitializationRequest = async (body2, executionContext, validatedConte
|
|
|
19797
19810
|
"About to handle initialization request"
|
|
19798
19811
|
);
|
|
19799
19812
|
await transport.handleRequest(req, res, body2);
|
|
19800
|
-
|
|
19813
|
+
logger26.info({ sessionId }, "Successfully handled initialization request");
|
|
19801
19814
|
return fetchToNode.toFetchResponse(res);
|
|
19802
19815
|
});
|
|
19803
19816
|
};
|
|
@@ -19824,8 +19837,8 @@ var handleExistingSessionRequest = async (body2, executionContext, validatedCont
|
|
|
19824
19837
|
sessionId,
|
|
19825
19838
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
19826
19839
|
);
|
|
19827
|
-
|
|
19828
|
-
|
|
19840
|
+
logger26.info({ sessionId }, "Server connected and transport initialized");
|
|
19841
|
+
logger26.info(
|
|
19829
19842
|
{
|
|
19830
19843
|
sessionId,
|
|
19831
19844
|
bodyKeys: Object.keys(body2 || {}),
|
|
@@ -19839,9 +19852,9 @@ var handleExistingSessionRequest = async (body2, executionContext, validatedCont
|
|
|
19839
19852
|
);
|
|
19840
19853
|
try {
|
|
19841
19854
|
await transport.handleRequest(req, res, body2);
|
|
19842
|
-
|
|
19855
|
+
logger26.info({ sessionId }, "Successfully handled MCP request");
|
|
19843
19856
|
} catch (transportError) {
|
|
19844
|
-
|
|
19857
|
+
logger26.error(
|
|
19845
19858
|
{
|
|
19846
19859
|
sessionId,
|
|
19847
19860
|
error: transportError,
|
|
@@ -19892,13 +19905,13 @@ app4.openapi(
|
|
|
19892
19905
|
}
|
|
19893
19906
|
const { executionContext } = paramValidation;
|
|
19894
19907
|
const body2 = c2.get("requestBody") || {};
|
|
19895
|
-
|
|
19908
|
+
logger26.info({ body: body2, bodyKeys: Object.keys(body2 || {}) }, "Parsed request body");
|
|
19896
19909
|
const isInitRequest = body2.method === "initialize";
|
|
19897
19910
|
const { req, res } = fetchToNode.toReqRes(c2.req.raw);
|
|
19898
19911
|
const validatedContext = c2.get("validatedContext") || {};
|
|
19899
19912
|
const credentialStores = c2.get("credentialStores");
|
|
19900
|
-
|
|
19901
|
-
|
|
19913
|
+
logger26.info({ validatedContext }, "Validated context");
|
|
19914
|
+
logger26.info({ req }, "request");
|
|
19902
19915
|
if (isInitRequest) {
|
|
19903
19916
|
return await handleInitializationRequest(
|
|
19904
19917
|
body2,
|
|
@@ -19919,7 +19932,7 @@ app4.openapi(
|
|
|
19919
19932
|
credentialStores
|
|
19920
19933
|
);
|
|
19921
19934
|
} catch (e) {
|
|
19922
|
-
|
|
19935
|
+
logger26.error(
|
|
19923
19936
|
{
|
|
19924
19937
|
error: e instanceof Error ? e.message : e,
|
|
19925
19938
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -19931,7 +19944,7 @@ app4.openapi(
|
|
|
19931
19944
|
}
|
|
19932
19945
|
);
|
|
19933
19946
|
app4.get("/", async (c2) => {
|
|
19934
|
-
|
|
19947
|
+
logger26.info({}, "Received GET MCP request");
|
|
19935
19948
|
return c2.json(
|
|
19936
19949
|
{
|
|
19937
19950
|
jsonrpc: "2.0",
|
|
@@ -19945,7 +19958,7 @@ app4.get("/", async (c2) => {
|
|
|
19945
19958
|
);
|
|
19946
19959
|
});
|
|
19947
19960
|
app4.delete("/", async (c2) => {
|
|
19948
|
-
|
|
19961
|
+
logger26.info({}, "Received DELETE MCP request");
|
|
19949
19962
|
return c2.json(
|
|
19950
19963
|
{
|
|
19951
19964
|
jsonrpc: "2.0",
|
|
@@ -19958,7 +19971,7 @@ app4.delete("/", async (c2) => {
|
|
|
19958
19971
|
var mcp_default = app4;
|
|
19959
19972
|
|
|
19960
19973
|
// src/app.ts
|
|
19961
|
-
var
|
|
19974
|
+
var logger27 = agentsCore.getLogger("agents-run-api");
|
|
19962
19975
|
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
19963
19976
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
19964
19977
|
app6.use("*", otel.otel());
|
|
@@ -19977,7 +19990,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
19977
19990
|
const body2 = await c2.req.json();
|
|
19978
19991
|
c2.set("requestBody", body2);
|
|
19979
19992
|
} catch (error) {
|
|
19980
|
-
|
|
19993
|
+
logger27.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
19981
19994
|
}
|
|
19982
19995
|
}
|
|
19983
19996
|
return next();
|
|
@@ -20028,8 +20041,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
20028
20041
|
if (!isExpectedError) {
|
|
20029
20042
|
const errorMessage = err2 instanceof Error ? err2.message : String(err2);
|
|
20030
20043
|
const errorStack = err2 instanceof Error ? err2.stack : void 0;
|
|
20031
|
-
if (
|
|
20032
|
-
|
|
20044
|
+
if (logger27) {
|
|
20045
|
+
logger27.error(
|
|
20033
20046
|
{
|
|
20034
20047
|
error: err2,
|
|
20035
20048
|
message: errorMessage,
|
|
@@ -20041,8 +20054,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
20041
20054
|
);
|
|
20042
20055
|
}
|
|
20043
20056
|
} else {
|
|
20044
|
-
if (
|
|
20045
|
-
|
|
20057
|
+
if (logger27) {
|
|
20058
|
+
logger27.error(
|
|
20046
20059
|
{
|
|
20047
20060
|
error: err2,
|
|
20048
20061
|
path: c2.req.path,
|
|
@@ -20059,8 +20072,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
20059
20072
|
const response = err2.getResponse();
|
|
20060
20073
|
return response;
|
|
20061
20074
|
} catch (responseError) {
|
|
20062
|
-
if (
|
|
20063
|
-
|
|
20075
|
+
if (logger27) {
|
|
20076
|
+
logger27.error({ error: responseError }, "Error while handling HTTPException response");
|
|
20064
20077
|
}
|
|
20065
20078
|
}
|
|
20066
20079
|
}
|
|
@@ -20094,7 +20107,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
20094
20107
|
app6.use("*", async (c2, next) => {
|
|
20095
20108
|
const executionContext = c2.get("executionContext");
|
|
20096
20109
|
if (!executionContext) {
|
|
20097
|
-
|
|
20110
|
+
logger27.debug({}, "Empty execution context");
|
|
20098
20111
|
return next();
|
|
20099
20112
|
}
|
|
20100
20113
|
const { tenantId, projectId, agentId } = executionContext;
|
|
@@ -20103,7 +20116,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
20103
20116
|
if (requestBody) {
|
|
20104
20117
|
conversationId = requestBody.conversationId;
|
|
20105
20118
|
if (!conversationId) {
|
|
20106
|
-
|
|
20119
|
+
logger27.debug({ requestBody }, "No conversation ID found in request body");
|
|
20107
20120
|
}
|
|
20108
20121
|
}
|
|
20109
20122
|
const entries = Object.fromEntries(
|
|
@@ -20118,7 +20131,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
20118
20131
|
})
|
|
20119
20132
|
);
|
|
20120
20133
|
if (!Object.keys(entries).length) {
|
|
20121
|
-
|
|
20134
|
+
logger27.debug({}, "Empty entries for baggage");
|
|
20122
20135
|
return next();
|
|
20123
20136
|
}
|
|
20124
20137
|
const bag = Object.entries(entries).reduce(
|