@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.js
CHANGED
|
@@ -4,7 +4,7 @@ import { dbClient_default } from './chunk-EVOISBFH.js';
|
|
|
4
4
|
import { env } from './chunk-KBZIYCPJ.js';
|
|
5
5
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
6
6
|
import { SESSION_CLEANUP_INTERVAL_MS, AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS, SESSION_TOOL_RESULT_CACHE_TIMEOUT_MS, STREAM_MAX_LIFETIME_MS, STREAM_BUFFER_MAX_SIZE_BYTES, STREAM_TEXT_GAP_THRESHOLD_MS, ARTIFACT_GENERATION_MAX_RETRIES, ARTIFACT_SESSION_MAX_PENDING, STATUS_UPDATE_DEFAULT_INTERVAL_SECONDS, STATUS_UPDATE_DEFAULT_NUM_EVENTS, ARTIFACT_SESSION_MAX_PREVIOUS_SUMMARIES, AGENT_EXECUTION_MAX_GENERATION_STEPS, FUNCTION_TOOL_SANDBOX_VCPUS_DEFAULT, FUNCTION_TOOL_EXECUTION_TIMEOUT_MS_DEFAULT, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS, ARTIFACT_GENERATION_BACKOFF_INITIAL_MS, ARTIFACT_GENERATION_BACKOFF_MAX_MS, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_STREAMING, LLM_GENERATION_FIRST_CALL_TIMEOUT_MS_NON_STREAMING, LLM_GENERATION_SUBSEQUENT_CALL_TIMEOUT_MS, DELEGATION_TOOL_BACKOFF_MAX_ELAPSED_TIME_MS, DELEGATION_TOOL_BACKOFF_EXPONENT, DELEGATION_TOOL_BACKOFF_MAX_INTERVAL_MS, DELEGATION_TOOL_BACKOFF_INITIAL_INTERVAL_MS, STREAM_PARSER_MAX_SNAPSHOT_SIZE, STREAM_PARSER_MAX_STREAMED_SIZE, STREAM_PARSER_MAX_COLLECTED_PARTS } from './chunk-THWNUGWP.js';
|
|
7
|
-
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, getConversation, createDefaultCredentialStores, CredentialStoreRegistry, createTask, getTask, updateTask, setSpanWithError, AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT, updateConversation, handleApiError, TaskState, getAgentById, getProject, setActiveAgentForThread, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, CONVERSATION_HISTORY_DEFAULT_LIMIT, ModelFactory, verifyTempToken, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, listTaskIdsByContextId, getLedgerArtifacts, agentHasArtifactComponents, upsertLedgerArtifact, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
7
|
+
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, getConversation, createDefaultCredentialStores, CredentialStoreRegistry, createTask, getTask, updateTask, setSpanWithError, AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT, updateConversation, handleApiError, TaskState, getAgentById, getProject, setActiveAgentForThread, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT, CONVERSATION_HISTORY_DEFAULT_LIMIT, ModelFactory, verifyTempToken, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, ContextResolver, CredentialStuffer, MCPServerType, getUserScopedCredentialReference, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, jsonSchemaToZod, getContextConfigById, getFullAgentDefinition, TemplateEngine, listTaskIdsByContextId, getLedgerArtifacts, agentHasArtifactComponents, upsertLedgerArtifact, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
8
8
|
import { otel } from '@hono/otel';
|
|
9
9
|
import { OpenAPIHono, createRoute, z } from '@hono/zod-openapi';
|
|
10
10
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -25,6 +25,10 @@ import { StreamableHTTPServerTransport } from '@alcyone-labs/modelcontextprotoco
|
|
|
25
25
|
import { toReqRes, toFetchResponse } from 'fetch-to-node';
|
|
26
26
|
|
|
27
27
|
// src/types/execution-context.ts
|
|
28
|
+
function getUserIdFromContext(ctx) {
|
|
29
|
+
const metadata = ctx.metadata;
|
|
30
|
+
return metadata?.initiatedBy?.type === "user" ? metadata.initiatedBy.id : void 0;
|
|
31
|
+
}
|
|
28
32
|
function createExecutionContext(params) {
|
|
29
33
|
return {
|
|
30
34
|
apiKey: params.apiKey,
|
|
@@ -4483,46 +4487,6 @@ function errorOp(message, subAgentId, severity = "error", code) {
|
|
|
4483
4487
|
function generateToolId() {
|
|
4484
4488
|
return `tool_${generateId(8)}`;
|
|
4485
4489
|
}
|
|
4486
|
-
var logger11 = getLogger("DataComponentSchema");
|
|
4487
|
-
function jsonSchemaToZod(jsonSchema) {
|
|
4488
|
-
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
4489
|
-
logger11.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
4490
|
-
return z.string();
|
|
4491
|
-
}
|
|
4492
|
-
switch (jsonSchema.type) {
|
|
4493
|
-
case "object":
|
|
4494
|
-
if (jsonSchema.properties) {
|
|
4495
|
-
const shape = {};
|
|
4496
|
-
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
4497
|
-
shape[key] = jsonSchemaToZod(prop);
|
|
4498
|
-
}
|
|
4499
|
-
return z.object(shape);
|
|
4500
|
-
}
|
|
4501
|
-
return z.record(z.string(), z.unknown());
|
|
4502
|
-
case "array": {
|
|
4503
|
-
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z.unknown();
|
|
4504
|
-
return z.array(itemSchema);
|
|
4505
|
-
}
|
|
4506
|
-
case "string":
|
|
4507
|
-
return z.string();
|
|
4508
|
-
case "number":
|
|
4509
|
-
case "integer":
|
|
4510
|
-
return z.number();
|
|
4511
|
-
case "boolean":
|
|
4512
|
-
return z.boolean();
|
|
4513
|
-
case "null":
|
|
4514
|
-
return z.null();
|
|
4515
|
-
default:
|
|
4516
|
-
logger11.warn(
|
|
4517
|
-
{
|
|
4518
|
-
unsupportedType: jsonSchema.type,
|
|
4519
|
-
schema: jsonSchema
|
|
4520
|
-
},
|
|
4521
|
-
"Unsupported JSON schema type, using unknown validation"
|
|
4522
|
-
);
|
|
4523
|
-
return z.unknown();
|
|
4524
|
-
}
|
|
4525
|
-
}
|
|
4526
4490
|
var SchemaProcessor = class _SchemaProcessor {
|
|
4527
4491
|
static logger = getLogger("SchemaProcessor");
|
|
4528
4492
|
/**
|
|
@@ -4879,7 +4843,7 @@ function parseEmbeddedJson(data) {
|
|
|
4879
4843
|
}
|
|
4880
4844
|
|
|
4881
4845
|
// src/a2a/client.ts
|
|
4882
|
-
var
|
|
4846
|
+
var logger11 = getLogger("a2aClient");
|
|
4883
4847
|
var DEFAULT_BACKOFF = {
|
|
4884
4848
|
initialInterval: 500,
|
|
4885
4849
|
maxInterval: 6e4,
|
|
@@ -5086,7 +5050,7 @@ var A2AClient = class {
|
|
|
5086
5050
|
try {
|
|
5087
5051
|
const res = await fn();
|
|
5088
5052
|
if (attempt > 0) {
|
|
5089
|
-
|
|
5053
|
+
logger11.info(
|
|
5090
5054
|
{
|
|
5091
5055
|
attempts: attempt + 1,
|
|
5092
5056
|
elapsedTime: Date.now() - start
|
|
@@ -5101,7 +5065,7 @@ var A2AClient = class {
|
|
|
5101
5065
|
}
|
|
5102
5066
|
const elapsed = Date.now() - start;
|
|
5103
5067
|
if (elapsed > maxElapsedTime) {
|
|
5104
|
-
|
|
5068
|
+
logger11.warn(
|
|
5105
5069
|
{
|
|
5106
5070
|
attempts: attempt + 1,
|
|
5107
5071
|
elapsedTime: elapsed,
|
|
@@ -5122,7 +5086,7 @@ var A2AClient = class {
|
|
|
5122
5086
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
5123
5087
|
}
|
|
5124
5088
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
5125
|
-
|
|
5089
|
+
logger11.info(
|
|
5126
5090
|
{
|
|
5127
5091
|
attempt: attempt + 1,
|
|
5128
5092
|
delayMs,
|
|
@@ -5213,7 +5177,7 @@ var A2AClient = class {
|
|
|
5213
5177
|
});
|
|
5214
5178
|
}
|
|
5215
5179
|
if (rpcResponse.id !== requestId2) {
|
|
5216
|
-
|
|
5180
|
+
logger11.warn(
|
|
5217
5181
|
{
|
|
5218
5182
|
method,
|
|
5219
5183
|
expectedId: requestId2,
|
|
@@ -5410,7 +5374,7 @@ var A2AClient = class {
|
|
|
5410
5374
|
try {
|
|
5411
5375
|
while (true) {
|
|
5412
5376
|
const { done, value } = await reader.read();
|
|
5413
|
-
|
|
5377
|
+
logger11.info({ done, value }, "parseA2ASseStream");
|
|
5414
5378
|
if (done) {
|
|
5415
5379
|
if (eventDataBuffer.trim()) {
|
|
5416
5380
|
const result = this._processSseEventData(
|
|
@@ -5497,7 +5461,7 @@ var A2AClient = class {
|
|
|
5497
5461
|
};
|
|
5498
5462
|
|
|
5499
5463
|
// src/agents/relationTools.ts
|
|
5500
|
-
var
|
|
5464
|
+
var logger12 = getLogger("relationships Tools");
|
|
5501
5465
|
var A2A_RETRY_STATUS_CODES = ["429", "500", "502", "503", "504"];
|
|
5502
5466
|
var generateTransferToolDescription = (config) => {
|
|
5503
5467
|
let toolsSection = "";
|
|
@@ -5608,7 +5572,7 @@ var createTransferToAgentTool = ({
|
|
|
5608
5572
|
[SPAN_KEYS.TRANSFER_TO_SUB_AGENT_ID]: transferConfig.id ?? "unknown"
|
|
5609
5573
|
});
|
|
5610
5574
|
}
|
|
5611
|
-
|
|
5575
|
+
logger12.info(
|
|
5612
5576
|
{
|
|
5613
5577
|
transferTo: transferConfig.id ?? "unknown",
|
|
5614
5578
|
fromSubAgent: callingAgentId
|
|
@@ -5629,7 +5593,7 @@ var createTransferToAgentTool = ({
|
|
|
5629
5593
|
fromSubAgentId: callingAgentId
|
|
5630
5594
|
// Include the calling agent ID for tracking
|
|
5631
5595
|
};
|
|
5632
|
-
|
|
5596
|
+
logger12.info(
|
|
5633
5597
|
{
|
|
5634
5598
|
transferResult,
|
|
5635
5599
|
transferResultKeys: Object.keys(transferResult)
|
|
@@ -5776,7 +5740,7 @@ function createDelegateToAgentTool({
|
|
|
5776
5740
|
...isInternal ? { fromSubAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
5777
5741
|
}
|
|
5778
5742
|
};
|
|
5779
|
-
|
|
5743
|
+
logger12.info({ messageToSend }, "messageToSend");
|
|
5780
5744
|
await createMessage(dbClient_default)({
|
|
5781
5745
|
id: generateId(),
|
|
5782
5746
|
tenantId,
|
|
@@ -5838,7 +5802,7 @@ function createDelegateToAgentTool({
|
|
|
5838
5802
|
}
|
|
5839
5803
|
|
|
5840
5804
|
// src/agents/SystemPromptBuilder.ts
|
|
5841
|
-
var
|
|
5805
|
+
var logger13 = getLogger("SystemPromptBuilder");
|
|
5842
5806
|
var SystemPromptBuilder = class {
|
|
5843
5807
|
constructor(version, versionConfig) {
|
|
5844
5808
|
this.version = version;
|
|
@@ -5854,12 +5818,12 @@ var SystemPromptBuilder = class {
|
|
|
5854
5818
|
this.templates.set(name, content);
|
|
5855
5819
|
}
|
|
5856
5820
|
this.loaded = true;
|
|
5857
|
-
|
|
5821
|
+
logger13.debug(
|
|
5858
5822
|
{ templateCount: this.templates.size, version: this.version },
|
|
5859
5823
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
5860
5824
|
);
|
|
5861
5825
|
} catch (error) {
|
|
5862
|
-
|
|
5826
|
+
logger13.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
5863
5827
|
throw new Error(`Template loading failed: ${error}`);
|
|
5864
5828
|
}
|
|
5865
5829
|
}
|
|
@@ -6949,7 +6913,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
6949
6913
|
return false;
|
|
6950
6914
|
};
|
|
6951
6915
|
}
|
|
6952
|
-
var
|
|
6916
|
+
var logger14 = getLogger("Agent");
|
|
6953
6917
|
function validateModel(modelString, modelType) {
|
|
6954
6918
|
if (!modelString?.trim()) {
|
|
6955
6919
|
throw new Error(
|
|
@@ -7222,7 +7186,7 @@ var Agent = class {
|
|
|
7222
7186
|
};
|
|
7223
7187
|
await createMessage(dbClient_default)(messagePayload);
|
|
7224
7188
|
} catch (error) {
|
|
7225
|
-
|
|
7189
|
+
logger14.warn(
|
|
7226
7190
|
{ error, toolName, toolCallId, conversationId: toolResultConversationId },
|
|
7227
7191
|
"Failed to store tool result in conversation history"
|
|
7228
7192
|
);
|
|
@@ -7338,11 +7302,11 @@ var Agent = class {
|
|
|
7338
7302
|
for (const toolResult of tools) {
|
|
7339
7303
|
for (const [toolName, originalTool] of Object.entries(toolResult.tools)) {
|
|
7340
7304
|
if (!isValidTool(originalTool)) {
|
|
7341
|
-
|
|
7305
|
+
logger14.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
7342
7306
|
continue;
|
|
7343
7307
|
}
|
|
7344
7308
|
const needsApproval = toolResult.toolPolicies?.[toolName]?.needsApproval || false;
|
|
7345
|
-
|
|
7309
|
+
logger14.debug(
|
|
7346
7310
|
{
|
|
7347
7311
|
toolName,
|
|
7348
7312
|
toolPolicies: toolResult.toolPolicies,
|
|
@@ -7356,7 +7320,7 @@ var Agent = class {
|
|
|
7356
7320
|
inputSchema: originalTool.inputSchema,
|
|
7357
7321
|
execute: async (args, { toolCallId }) => {
|
|
7358
7322
|
if (needsApproval) {
|
|
7359
|
-
|
|
7323
|
+
logger14.info(
|
|
7360
7324
|
{ toolName, toolCallId, args },
|
|
7361
7325
|
"Tool requires approval - waiting for user response"
|
|
7362
7326
|
);
|
|
@@ -7402,7 +7366,7 @@ var Agent = class {
|
|
|
7402
7366
|
}
|
|
7403
7367
|
},
|
|
7404
7368
|
(denialSpan) => {
|
|
7405
|
-
|
|
7369
|
+
logger14.info(
|
|
7406
7370
|
{ toolName, toolCallId, reason: approvalResult.reason },
|
|
7407
7371
|
"Tool execution denied by user"
|
|
7408
7372
|
);
|
|
@@ -7423,18 +7387,18 @@ var Agent = class {
|
|
|
7423
7387
|
}
|
|
7424
7388
|
},
|
|
7425
7389
|
(approvedSpan) => {
|
|
7426
|
-
|
|
7390
|
+
logger14.info({ toolName, toolCallId }, "Tool approved, continuing with execution");
|
|
7427
7391
|
approvedSpan.setStatus({ code: SpanStatusCode.OK });
|
|
7428
7392
|
approvedSpan.end();
|
|
7429
7393
|
}
|
|
7430
7394
|
);
|
|
7431
7395
|
}
|
|
7432
|
-
|
|
7396
|
+
logger14.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7433
7397
|
try {
|
|
7434
7398
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7435
7399
|
if (rawResult && typeof rawResult === "object" && rawResult.isError) {
|
|
7436
7400
|
const errorMessage = rawResult.content?.[0]?.text || "MCP tool returned an error";
|
|
7437
|
-
|
|
7401
|
+
logger14.error(
|
|
7438
7402
|
{ toolName, toolCallId, errorMessage, rawResult },
|
|
7439
7403
|
"MCP tool returned error status"
|
|
7440
7404
|
);
|
|
@@ -7485,7 +7449,7 @@ var Agent = class {
|
|
|
7485
7449
|
});
|
|
7486
7450
|
return { result: enhancedResult, toolCallId };
|
|
7487
7451
|
} catch (error) {
|
|
7488
|
-
|
|
7452
|
+
logger14.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
7489
7453
|
throw error;
|
|
7490
7454
|
}
|
|
7491
7455
|
}
|
|
@@ -7539,7 +7503,51 @@ var Agent = class {
|
|
|
7539
7503
|
const selectedTools = toolRelation?.selectedTools || void 0;
|
|
7540
7504
|
const toolPolicies = toolRelation?.toolPolicies || {};
|
|
7541
7505
|
let serverConfig;
|
|
7542
|
-
|
|
7506
|
+
const isUserScoped = tool3.credentialScope === "user";
|
|
7507
|
+
const userId = this.config.userId;
|
|
7508
|
+
if (isUserScoped && userId && this.credentialStuffer) {
|
|
7509
|
+
const userCredentialReference = await getUserScopedCredentialReference(dbClient_default)({
|
|
7510
|
+
scopes: {
|
|
7511
|
+
tenantId: this.config.tenantId,
|
|
7512
|
+
projectId: this.config.projectId
|
|
7513
|
+
},
|
|
7514
|
+
toolId: tool3.id,
|
|
7515
|
+
userId
|
|
7516
|
+
});
|
|
7517
|
+
if (userCredentialReference) {
|
|
7518
|
+
const storeReference = {
|
|
7519
|
+
credentialStoreId: userCredentialReference.credentialStoreId,
|
|
7520
|
+
retrievalParams: userCredentialReference.retrievalParams || {}
|
|
7521
|
+
};
|
|
7522
|
+
serverConfig = await this.credentialStuffer.buildMcpServerConfig(
|
|
7523
|
+
{
|
|
7524
|
+
tenantId: this.config.tenantId,
|
|
7525
|
+
projectId: this.config.projectId,
|
|
7526
|
+
contextConfigId: this.config.contextConfigId || void 0,
|
|
7527
|
+
conversationId: this.conversationId || void 0
|
|
7528
|
+
},
|
|
7529
|
+
this.convertToMCPToolConfig(tool3, agentToolRelationHeaders),
|
|
7530
|
+
storeReference,
|
|
7531
|
+
selectedTools
|
|
7532
|
+
);
|
|
7533
|
+
} else {
|
|
7534
|
+
logger14.warn(
|
|
7535
|
+
{ toolId: tool3.id, userId },
|
|
7536
|
+
"User-scoped tool has no credential connected for this user"
|
|
7537
|
+
);
|
|
7538
|
+
serverConfig = await this.credentialStuffer.buildMcpServerConfig(
|
|
7539
|
+
{
|
|
7540
|
+
tenantId: this.config.tenantId,
|
|
7541
|
+
projectId: this.config.projectId,
|
|
7542
|
+
contextConfigId: this.config.contextConfigId || void 0,
|
|
7543
|
+
conversationId: this.conversationId || void 0
|
|
7544
|
+
},
|
|
7545
|
+
this.convertToMCPToolConfig(tool3, agentToolRelationHeaders),
|
|
7546
|
+
void 0,
|
|
7547
|
+
selectedTools
|
|
7548
|
+
);
|
|
7549
|
+
}
|
|
7550
|
+
} else if (credentialReferenceId && this.credentialStuffer) {
|
|
7543
7551
|
const credentialReference = await getCredentialReference(dbClient_default)({
|
|
7544
7552
|
scopes: {
|
|
7545
7553
|
tenantId: this.config.tenantId,
|
|
@@ -7589,7 +7597,7 @@ var Agent = class {
|
|
|
7589
7597
|
headers: agentToolRelationHeaders
|
|
7590
7598
|
};
|
|
7591
7599
|
}
|
|
7592
|
-
|
|
7600
|
+
logger14.info(
|
|
7593
7601
|
{
|
|
7594
7602
|
toolName: tool3.name,
|
|
7595
7603
|
credentialReferenceId,
|
|
@@ -7614,7 +7622,7 @@ var Agent = class {
|
|
|
7614
7622
|
this.mcpClientCache.set(cacheKey, client);
|
|
7615
7623
|
} catch (error) {
|
|
7616
7624
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7617
|
-
|
|
7625
|
+
logger14.error(
|
|
7618
7626
|
{
|
|
7619
7627
|
toolName: tool3.name,
|
|
7620
7628
|
subAgentId: this.config.id,
|
|
@@ -7679,7 +7687,7 @@ var Agent = class {
|
|
|
7679
7687
|
await client.connect();
|
|
7680
7688
|
return client;
|
|
7681
7689
|
} catch (error) {
|
|
7682
|
-
|
|
7690
|
+
logger14.error(
|
|
7683
7691
|
{
|
|
7684
7692
|
toolName: tool3.name,
|
|
7685
7693
|
subAgentId: this.config.id,
|
|
@@ -7721,7 +7729,7 @@ var Agent = class {
|
|
|
7721
7729
|
for (const functionToolDef of functionToolsData) {
|
|
7722
7730
|
const functionId = functionToolDef.functionId;
|
|
7723
7731
|
if (!functionId) {
|
|
7724
|
-
|
|
7732
|
+
logger14.warn(
|
|
7725
7733
|
{ functionToolId: functionToolDef.id },
|
|
7726
7734
|
"Function tool missing functionId reference"
|
|
7727
7735
|
);
|
|
@@ -7735,7 +7743,7 @@ var Agent = class {
|
|
|
7735
7743
|
}
|
|
7736
7744
|
});
|
|
7737
7745
|
if (!functionData) {
|
|
7738
|
-
|
|
7746
|
+
logger14.warn(
|
|
7739
7747
|
{ functionId, functionToolId: functionToolDef.id },
|
|
7740
7748
|
"Function not found in functions table"
|
|
7741
7749
|
);
|
|
@@ -7746,7 +7754,7 @@ var Agent = class {
|
|
|
7746
7754
|
description: functionToolDef.description || functionToolDef.name,
|
|
7747
7755
|
inputSchema: zodSchema,
|
|
7748
7756
|
execute: async (args, { toolCallId }) => {
|
|
7749
|
-
|
|
7757
|
+
logger14.debug(
|
|
7750
7758
|
{ toolName: functionToolDef.name, toolCallId, args },
|
|
7751
7759
|
"Function Tool Called"
|
|
7752
7760
|
);
|
|
@@ -7773,7 +7781,7 @@ var Agent = class {
|
|
|
7773
7781
|
});
|
|
7774
7782
|
return { result, toolCallId };
|
|
7775
7783
|
} catch (error) {
|
|
7776
|
-
|
|
7784
|
+
logger14.error(
|
|
7777
7785
|
{
|
|
7778
7786
|
toolName: functionToolDef.name,
|
|
7779
7787
|
toolCallId,
|
|
@@ -7793,7 +7801,7 @@ var Agent = class {
|
|
|
7793
7801
|
);
|
|
7794
7802
|
}
|
|
7795
7803
|
} catch (error) {
|
|
7796
|
-
|
|
7804
|
+
logger14.error({ error }, "Failed to load function tools from database");
|
|
7797
7805
|
}
|
|
7798
7806
|
return functionTools;
|
|
7799
7807
|
}
|
|
@@ -7803,7 +7811,7 @@ var Agent = class {
|
|
|
7803
7811
|
async getResolvedContext(conversationId, headers2) {
|
|
7804
7812
|
try {
|
|
7805
7813
|
if (!this.config.contextConfigId) {
|
|
7806
|
-
|
|
7814
|
+
logger14.debug({ agentId: this.config.agentId }, "No context config found for agent");
|
|
7807
7815
|
return null;
|
|
7808
7816
|
}
|
|
7809
7817
|
const contextConfig = await getContextConfigById(dbClient_default)({
|
|
@@ -7815,7 +7823,7 @@ var Agent = class {
|
|
|
7815
7823
|
id: this.config.contextConfigId
|
|
7816
7824
|
});
|
|
7817
7825
|
if (!contextConfig) {
|
|
7818
|
-
|
|
7826
|
+
logger14.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7819
7827
|
return null;
|
|
7820
7828
|
}
|
|
7821
7829
|
if (!this.contextResolver) {
|
|
@@ -7831,7 +7839,7 @@ var Agent = class {
|
|
|
7831
7839
|
...result.resolvedContext,
|
|
7832
7840
|
$env: process.env
|
|
7833
7841
|
};
|
|
7834
|
-
|
|
7842
|
+
logger14.debug(
|
|
7835
7843
|
{
|
|
7836
7844
|
conversationId,
|
|
7837
7845
|
contextConfigId: contextConfig.id,
|
|
@@ -7845,7 +7853,7 @@ var Agent = class {
|
|
|
7845
7853
|
);
|
|
7846
7854
|
return contextWithBuiltins;
|
|
7847
7855
|
} catch (error) {
|
|
7848
|
-
|
|
7856
|
+
logger14.error(
|
|
7849
7857
|
{
|
|
7850
7858
|
conversationId,
|
|
7851
7859
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7869,7 +7877,7 @@ var Agent = class {
|
|
|
7869
7877
|
});
|
|
7870
7878
|
return agentDefinition?.prompt || void 0;
|
|
7871
7879
|
} catch (error) {
|
|
7872
|
-
|
|
7880
|
+
logger14.warn(
|
|
7873
7881
|
{
|
|
7874
7882
|
agentId: this.config.agentId,
|
|
7875
7883
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7898,7 +7906,7 @@ var Agent = class {
|
|
|
7898
7906
|
(subAgent) => "artifactComponents" in subAgent && subAgent.artifactComponents && subAgent.artifactComponents.length > 0
|
|
7899
7907
|
);
|
|
7900
7908
|
} catch (error) {
|
|
7901
|
-
|
|
7909
|
+
logger14.warn(
|
|
7902
7910
|
{
|
|
7903
7911
|
agentId: this.config.agentId,
|
|
7904
7912
|
tenantId: this.config.tenantId,
|
|
@@ -7927,7 +7935,7 @@ var Agent = class {
|
|
|
7927
7935
|
preserveUnresolved: false
|
|
7928
7936
|
});
|
|
7929
7937
|
} catch (error) {
|
|
7930
|
-
|
|
7938
|
+
logger14.error(
|
|
7931
7939
|
{
|
|
7932
7940
|
conversationId,
|
|
7933
7941
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7974,7 +7982,7 @@ var Agent = class {
|
|
|
7974
7982
|
preserveUnresolved: false
|
|
7975
7983
|
});
|
|
7976
7984
|
} catch (error) {
|
|
7977
|
-
|
|
7985
|
+
logger14.error(
|
|
7978
7986
|
{
|
|
7979
7987
|
conversationId,
|
|
7980
7988
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7989,7 +7997,7 @@ var Agent = class {
|
|
|
7989
7997
|
const functionTools = await this.getFunctionTools(streamRequestId || "");
|
|
7990
7998
|
const relationTools = this.getRelationTools(runtimeContext);
|
|
7991
7999
|
const allTools = { ...mcpTools, ...functionTools, ...relationTools };
|
|
7992
|
-
|
|
8000
|
+
logger14.info(
|
|
7993
8001
|
{
|
|
7994
8002
|
mcpTools: Object.keys(mcpTools),
|
|
7995
8003
|
functionTools: Object.keys(functionTools),
|
|
@@ -8028,7 +8036,7 @@ var Agent = class {
|
|
|
8028
8036
|
preserveUnresolved: false
|
|
8029
8037
|
});
|
|
8030
8038
|
} catch (error) {
|
|
8031
|
-
|
|
8039
|
+
logger14.error(
|
|
8032
8040
|
{
|
|
8033
8041
|
conversationId,
|
|
8034
8042
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -8061,7 +8069,7 @@ var Agent = class {
|
|
|
8061
8069
|
toolCallId: z.string().describe("The tool call ID associated with this artifact.")
|
|
8062
8070
|
}),
|
|
8063
8071
|
execute: async ({ artifactId, toolCallId }) => {
|
|
8064
|
-
|
|
8072
|
+
logger14.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
8065
8073
|
const streamRequestId = this.getStreamRequestId();
|
|
8066
8074
|
const artifactService = agentSessionManager.getArtifactService(streamRequestId);
|
|
8067
8075
|
if (!artifactService) {
|
|
@@ -8357,7 +8365,7 @@ ${output}`;
|
|
|
8357
8365
|
};
|
|
8358
8366
|
return enhanced;
|
|
8359
8367
|
} catch (error) {
|
|
8360
|
-
|
|
8368
|
+
logger14.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
8361
8369
|
return result;
|
|
8362
8370
|
}
|
|
8363
8371
|
}
|
|
@@ -8372,7 +8380,7 @@ ${output}`;
|
|
|
8372
8380
|
}
|
|
8373
8381
|
});
|
|
8374
8382
|
} catch (error) {
|
|
8375
|
-
|
|
8383
|
+
logger14.error(
|
|
8376
8384
|
{ error, agentId: this.config.agentId },
|
|
8377
8385
|
"Failed to check agent artifact components"
|
|
8378
8386
|
);
|
|
@@ -8489,7 +8497,7 @@ ${output}`;
|
|
|
8489
8497
|
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;
|
|
8490
8498
|
const timeoutMs = Math.min(configuredTimeout, LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS);
|
|
8491
8499
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
8492
|
-
|
|
8500
|
+
logger14.warn(
|
|
8493
8501
|
{
|
|
8494
8502
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
8495
8503
|
appliedTimeout: timeoutMs,
|
|
@@ -8531,7 +8539,7 @@ ${output}`;
|
|
|
8531
8539
|
}
|
|
8532
8540
|
);
|
|
8533
8541
|
} catch (error) {
|
|
8534
|
-
|
|
8542
|
+
logger14.debug({ error }, "Failed to track agent reasoning");
|
|
8535
8543
|
}
|
|
8536
8544
|
}
|
|
8537
8545
|
if (last && last["content"] && last["content"].length > 0) {
|
|
@@ -8666,7 +8674,7 @@ ${output}`;
|
|
|
8666
8674
|
}
|
|
8667
8675
|
);
|
|
8668
8676
|
} catch (error) {
|
|
8669
|
-
|
|
8677
|
+
logger14.debug({ error }, "Failed to track agent reasoning");
|
|
8670
8678
|
}
|
|
8671
8679
|
}
|
|
8672
8680
|
if (steps.length >= 2) {
|
|
@@ -8813,7 +8821,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8813
8821
|
LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS
|
|
8814
8822
|
);
|
|
8815
8823
|
if (structuredModelSettings.maxDuration && structuredModelSettings.maxDuration * 1e3 > LLM_GENERATION_MAX_ALLOWED_TIMEOUT_MS) {
|
|
8816
|
-
|
|
8824
|
+
logger14.warn(
|
|
8817
8825
|
{
|
|
8818
8826
|
requestedTimeout: structuredModelSettings.maxDuration * 1e3,
|
|
8819
8827
|
appliedTimeout: phase2TimeoutMs,
|
|
@@ -8989,7 +8997,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8989
8997
|
};
|
|
8990
8998
|
|
|
8991
8999
|
// src/agents/generateTaskHandler.ts
|
|
8992
|
-
var
|
|
9000
|
+
var logger15 = getLogger("generateTaskHandler");
|
|
8993
9001
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
8994
9002
|
return async (task) => {
|
|
8995
9003
|
try {
|
|
@@ -9107,7 +9115,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9107
9115
|
return { ...relation, description: enhancedDescription };
|
|
9108
9116
|
}
|
|
9109
9117
|
} catch (error) {
|
|
9110
|
-
|
|
9118
|
+
logger15.warn({ subAgentId: relation.id, error }, "Failed to enhance agent description");
|
|
9111
9119
|
}
|
|
9112
9120
|
return relation;
|
|
9113
9121
|
})
|
|
@@ -9165,7 +9173,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9165
9173
|
};
|
|
9166
9174
|
}
|
|
9167
9175
|
} catch (error) {
|
|
9168
|
-
|
|
9176
|
+
logger15.warn(
|
|
9169
9177
|
{ targetAgentId: relation.targetAgentId, error },
|
|
9170
9178
|
"Failed to enhance team agent description"
|
|
9171
9179
|
);
|
|
@@ -9182,7 +9190,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9182
9190
|
item.tool,
|
|
9183
9191
|
dbClient_default,
|
|
9184
9192
|
credentialStoreRegistry,
|
|
9185
|
-
item.id
|
|
9193
|
+
item.id,
|
|
9194
|
+
config.userId
|
|
9186
9195
|
);
|
|
9187
9196
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
9188
9197
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
@@ -9199,6 +9208,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9199
9208
|
agentId: config.agentId,
|
|
9200
9209
|
baseUrl: config.baseUrl,
|
|
9201
9210
|
apiKey: config.apiKey,
|
|
9211
|
+
userId: config.userId,
|
|
9202
9212
|
name: config.name,
|
|
9203
9213
|
description: config.description || "",
|
|
9204
9214
|
prompt,
|
|
@@ -9252,7 +9262,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9252
9262
|
targetTransferRelations = transferRel;
|
|
9253
9263
|
targetDelegateRelations = delegateRel;
|
|
9254
9264
|
} catch (err) {
|
|
9255
|
-
|
|
9265
|
+
logger15.info(
|
|
9256
9266
|
{
|
|
9257
9267
|
agentId: relation.id,
|
|
9258
9268
|
error: err?.message || "Unknown error"
|
|
@@ -9266,7 +9276,8 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9266
9276
|
item.tool,
|
|
9267
9277
|
dbClient_default,
|
|
9268
9278
|
credentialStoreRegistry,
|
|
9269
|
-
item.id
|
|
9279
|
+
item.id,
|
|
9280
|
+
config.userId
|
|
9270
9281
|
);
|
|
9271
9282
|
if (item.selectedTools && item.selectedTools.length > 0) {
|
|
9272
9283
|
const selectedToolsSet = new Set(item.selectedTools);
|
|
@@ -9392,7 +9403,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9392
9403
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
9393
9404
|
if (taskIdMatch) {
|
|
9394
9405
|
contextId = taskIdMatch[1];
|
|
9395
|
-
|
|
9406
|
+
logger15.info(
|
|
9396
9407
|
{
|
|
9397
9408
|
taskId: task.id,
|
|
9398
9409
|
extractedContextId: contextId,
|
|
@@ -9410,7 +9421,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9410
9421
|
agent.setDelegationStatus(isDelegation);
|
|
9411
9422
|
agent.setDelegationId(delegationId);
|
|
9412
9423
|
if (isDelegation) {
|
|
9413
|
-
|
|
9424
|
+
logger15.info(
|
|
9414
9425
|
{ subAgentId: config.subAgentId, taskId: task.id, delegationId },
|
|
9415
9426
|
"Delegated agent - streaming disabled"
|
|
9416
9427
|
);
|
|
@@ -9447,7 +9458,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9447
9458
|
const toolResult = allToolResults.find(
|
|
9448
9459
|
(result) => result.toolCallId === toolCall.toolCallId
|
|
9449
9460
|
);
|
|
9450
|
-
|
|
9461
|
+
logger15.info(
|
|
9451
9462
|
{
|
|
9452
9463
|
toolCallName: toolCall.toolName,
|
|
9453
9464
|
toolCallId: toolCall.toolCallId,
|
|
@@ -9464,7 +9475,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9464
9475
|
const transferReason = responseText || allThoughts[allThoughts.length - 1]?.text || "Agent requested transfer. No reason provided.";
|
|
9465
9476
|
if (toolResult?.output && isValidTransferResult(toolResult.output)) {
|
|
9466
9477
|
const transferResult = toolResult.output;
|
|
9467
|
-
|
|
9478
|
+
logger15.info(
|
|
9468
9479
|
{
|
|
9469
9480
|
validationPassed: true,
|
|
9470
9481
|
transferResult,
|
|
@@ -9481,7 +9492,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9481
9492
|
reason: transferReason,
|
|
9482
9493
|
original_message: userMessage
|
|
9483
9494
|
};
|
|
9484
|
-
|
|
9495
|
+
logger15.info(
|
|
9485
9496
|
{
|
|
9486
9497
|
artifactData,
|
|
9487
9498
|
artifactDataKeys: Object.keys(artifactData)
|
|
@@ -9506,7 +9517,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9506
9517
|
]
|
|
9507
9518
|
};
|
|
9508
9519
|
}
|
|
9509
|
-
|
|
9520
|
+
logger15.warn(
|
|
9510
9521
|
{
|
|
9511
9522
|
hasToolResult: !!toolResult,
|
|
9512
9523
|
hasOutput: !!toolResult?.output,
|
|
@@ -9592,12 +9603,13 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9592
9603
|
description: subAgent.description || void 0,
|
|
9593
9604
|
conversationHistoryConfig: effectiveConversationHistoryConfig,
|
|
9594
9605
|
contextConfigId: agent?.contextConfigId || void 0,
|
|
9595
|
-
sandboxConfig: params.sandboxConfig
|
|
9606
|
+
sandboxConfig: params.sandboxConfig,
|
|
9607
|
+
userId: params.userId
|
|
9596
9608
|
};
|
|
9597
9609
|
};
|
|
9598
9610
|
|
|
9599
9611
|
// src/data/agents.ts
|
|
9600
|
-
var
|
|
9612
|
+
var logger16 = getLogger("agents");
|
|
9601
9613
|
function createAgentCard({
|
|
9602
9614
|
dbAgent,
|
|
9603
9615
|
baseUrl
|
|
@@ -9667,7 +9679,8 @@ async function hydrateAgent({
|
|
|
9667
9679
|
baseUrl,
|
|
9668
9680
|
apiKey,
|
|
9669
9681
|
credentialStoreRegistry,
|
|
9670
|
-
sandboxConfig
|
|
9682
|
+
sandboxConfig,
|
|
9683
|
+
userId
|
|
9671
9684
|
}) {
|
|
9672
9685
|
try {
|
|
9673
9686
|
const taskHandlerConfig = await createTaskHandlerConfig({
|
|
@@ -9677,7 +9690,8 @@ async function hydrateAgent({
|
|
|
9677
9690
|
subAgentId: dbAgent.id,
|
|
9678
9691
|
baseUrl,
|
|
9679
9692
|
apiKey,
|
|
9680
|
-
sandboxConfig
|
|
9693
|
+
sandboxConfig,
|
|
9694
|
+
userId
|
|
9681
9695
|
});
|
|
9682
9696
|
const taskHandler = createTaskHandler(taskHandlerConfig, credentialStoreRegistry);
|
|
9683
9697
|
const agentCard = createAgentCard({
|
|
@@ -9700,12 +9714,13 @@ async function hydrateAgent({
|
|
|
9700
9714
|
async function getRegisteredAgent(params) {
|
|
9701
9715
|
const { executionContext, credentialStoreRegistry, sandboxConfig } = params;
|
|
9702
9716
|
const { tenantId, projectId, agentId, subAgentId, baseUrl, apiKey } = executionContext;
|
|
9717
|
+
const userId = getUserIdFromContext(executionContext);
|
|
9703
9718
|
let dbAgent;
|
|
9704
9719
|
if (!subAgentId) {
|
|
9705
9720
|
const agent = await getAgentWithDefaultSubAgent(dbClient_default)({
|
|
9706
9721
|
scopes: { tenantId, projectId, agentId }
|
|
9707
9722
|
});
|
|
9708
|
-
|
|
9723
|
+
logger16.info({ agent }, "agent with default sub agent");
|
|
9709
9724
|
if (!agent || !agent.defaultSubAgent) {
|
|
9710
9725
|
return null;
|
|
9711
9726
|
}
|
|
@@ -9730,13 +9745,14 @@ async function getRegisteredAgent(params) {
|
|
|
9730
9745
|
baseUrl: agentFrameworkBaseUrl,
|
|
9731
9746
|
credentialStoreRegistry,
|
|
9732
9747
|
apiKey,
|
|
9733
|
-
sandboxConfig
|
|
9748
|
+
sandboxConfig,
|
|
9749
|
+
userId
|
|
9734
9750
|
});
|
|
9735
9751
|
}
|
|
9736
9752
|
|
|
9737
9753
|
// src/routes/agents.ts
|
|
9738
9754
|
var app = new OpenAPIHono();
|
|
9739
|
-
var
|
|
9755
|
+
var logger17 = getLogger("agents");
|
|
9740
9756
|
app.openapi(
|
|
9741
9757
|
createRoute({
|
|
9742
9758
|
method: "get",
|
|
@@ -9774,7 +9790,7 @@ app.openapi(
|
|
|
9774
9790
|
tracestate: c.req.header("tracestate"),
|
|
9775
9791
|
baggage: c.req.header("baggage")
|
|
9776
9792
|
};
|
|
9777
|
-
|
|
9793
|
+
logger17.info(
|
|
9778
9794
|
{
|
|
9779
9795
|
otelHeaders,
|
|
9780
9796
|
path: c.req.path,
|
|
@@ -9784,8 +9800,8 @@ app.openapi(
|
|
|
9784
9800
|
);
|
|
9785
9801
|
const executionContext = getRequestExecutionContext(c);
|
|
9786
9802
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
9787
|
-
|
|
9788
|
-
|
|
9803
|
+
logger17.info({ executionContext }, "executionContext");
|
|
9804
|
+
logger17.info(
|
|
9789
9805
|
{
|
|
9790
9806
|
message: "getRegisteredAgent (agent-level)",
|
|
9791
9807
|
tenantId,
|
|
@@ -9802,7 +9818,7 @@ app.openapi(
|
|
|
9802
9818
|
credentialStoreRegistry: credentialStores,
|
|
9803
9819
|
sandboxConfig
|
|
9804
9820
|
});
|
|
9805
|
-
|
|
9821
|
+
logger17.info({ agent }, "agent registered: well-known agent.json");
|
|
9806
9822
|
if (!agent) {
|
|
9807
9823
|
throw createApiError({
|
|
9808
9824
|
code: "not_found",
|
|
@@ -9818,7 +9834,7 @@ app.post("/a2a", async (c) => {
|
|
|
9818
9834
|
tracestate: c.req.header("tracestate"),
|
|
9819
9835
|
baggage: c.req.header("baggage")
|
|
9820
9836
|
};
|
|
9821
|
-
|
|
9837
|
+
logger17.info(
|
|
9822
9838
|
{
|
|
9823
9839
|
otelHeaders,
|
|
9824
9840
|
path: c.req.path,
|
|
@@ -9829,7 +9845,7 @@ app.post("/a2a", async (c) => {
|
|
|
9829
9845
|
const executionContext = getRequestExecutionContext(c);
|
|
9830
9846
|
const { tenantId, projectId, agentId, subAgentId } = executionContext;
|
|
9831
9847
|
if (subAgentId) {
|
|
9832
|
-
|
|
9848
|
+
logger17.info(
|
|
9833
9849
|
{
|
|
9834
9850
|
message: "a2a (agent-level)",
|
|
9835
9851
|
tenantId,
|
|
@@ -9858,7 +9874,7 @@ app.post("/a2a", async (c) => {
|
|
|
9858
9874
|
}
|
|
9859
9875
|
return a2aHandler(c, agent2);
|
|
9860
9876
|
}
|
|
9861
|
-
|
|
9877
|
+
logger17.info(
|
|
9862
9878
|
{
|
|
9863
9879
|
message: "a2a (agent-level)",
|
|
9864
9880
|
tenantId,
|
|
@@ -9936,14 +9952,14 @@ function extractTransferData(task) {
|
|
|
9936
9952
|
}
|
|
9937
9953
|
|
|
9938
9954
|
// src/a2a/transfer.ts
|
|
9939
|
-
var
|
|
9955
|
+
var logger18 = getLogger("Transfer");
|
|
9940
9956
|
async function executeTransfer({
|
|
9941
9957
|
tenantId,
|
|
9942
9958
|
threadId,
|
|
9943
9959
|
projectId,
|
|
9944
9960
|
targetSubAgentId
|
|
9945
9961
|
}) {
|
|
9946
|
-
|
|
9962
|
+
logger18.info(
|
|
9947
9963
|
{
|
|
9948
9964
|
targetAgent: targetSubAgentId,
|
|
9949
9965
|
threadId,
|
|
@@ -9958,12 +9974,12 @@ async function executeTransfer({
|
|
|
9958
9974
|
threadId,
|
|
9959
9975
|
subAgentId: targetSubAgentId
|
|
9960
9976
|
});
|
|
9961
|
-
|
|
9977
|
+
logger18.info(
|
|
9962
9978
|
{ targetAgent: targetSubAgentId, threadId },
|
|
9963
9979
|
"Successfully updated active_sub_agent_id in database"
|
|
9964
9980
|
);
|
|
9965
9981
|
} catch (error) {
|
|
9966
|
-
|
|
9982
|
+
logger18.error(
|
|
9967
9983
|
{ error, targetAgent: targetSubAgentId, threadId },
|
|
9968
9984
|
"Failed to update active_sub_agent_id"
|
|
9969
9985
|
);
|
|
@@ -10527,7 +10543,7 @@ function createBufferingStreamHelper() {
|
|
|
10527
10543
|
var createMCPStreamHelper = createBufferingStreamHelper;
|
|
10528
10544
|
|
|
10529
10545
|
// src/handlers/executionHandler.ts
|
|
10530
|
-
var
|
|
10546
|
+
var logger19 = getLogger("ExecutionHandler");
|
|
10531
10547
|
var ExecutionHandler = class {
|
|
10532
10548
|
MAX_ERRORS = AGENT_EXECUTION_MAX_CONSECUTIVE_ERRORS;
|
|
10533
10549
|
/**
|
|
@@ -10560,7 +10576,7 @@ var ExecutionHandler = class {
|
|
|
10560
10576
|
if (emitOperations) {
|
|
10561
10577
|
agentSessionManager.enableEmitOperations(requestId2);
|
|
10562
10578
|
}
|
|
10563
|
-
|
|
10579
|
+
logger19.info(
|
|
10564
10580
|
{ sessionId: requestId2, agentId, conversationId, emitOperations },
|
|
10565
10581
|
"Created AgentSession for message execution"
|
|
10566
10582
|
);
|
|
@@ -10593,7 +10609,7 @@ var ExecutionHandler = class {
|
|
|
10593
10609
|
);
|
|
10594
10610
|
}
|
|
10595
10611
|
} catch (modelError) {
|
|
10596
|
-
|
|
10612
|
+
logger19.warn(
|
|
10597
10613
|
{
|
|
10598
10614
|
error: modelError instanceof Error ? modelError.message : "Unknown error",
|
|
10599
10615
|
agentId
|
|
@@ -10608,7 +10624,7 @@ var ExecutionHandler = class {
|
|
|
10608
10624
|
}
|
|
10609
10625
|
}
|
|
10610
10626
|
} catch (error) {
|
|
10611
|
-
|
|
10627
|
+
logger19.error(
|
|
10612
10628
|
{
|
|
10613
10629
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
10614
10630
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10624,7 +10640,7 @@ var ExecutionHandler = class {
|
|
|
10624
10640
|
try {
|
|
10625
10641
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, agentId));
|
|
10626
10642
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
10627
|
-
|
|
10643
|
+
logger19.info(
|
|
10628
10644
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
10629
10645
|
"Attempting to create or reuse existing task"
|
|
10630
10646
|
);
|
|
@@ -10648,7 +10664,7 @@ var ExecutionHandler = class {
|
|
|
10648
10664
|
sub_agent_id: currentAgentId
|
|
10649
10665
|
}
|
|
10650
10666
|
});
|
|
10651
|
-
|
|
10667
|
+
logger19.info(
|
|
10652
10668
|
{
|
|
10653
10669
|
taskId,
|
|
10654
10670
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -10657,27 +10673,27 @@ var ExecutionHandler = class {
|
|
|
10657
10673
|
);
|
|
10658
10674
|
} catch (error) {
|
|
10659
10675
|
if (error?.cause?.code === "23505") {
|
|
10660
|
-
|
|
10676
|
+
logger19.info(
|
|
10661
10677
|
{ taskId, error: error.message },
|
|
10662
10678
|
"Task already exists, fetching existing task"
|
|
10663
10679
|
);
|
|
10664
10680
|
const existingTask = await getTask(dbClient_default)({ id: taskId });
|
|
10665
10681
|
if (existingTask) {
|
|
10666
10682
|
task = existingTask;
|
|
10667
|
-
|
|
10683
|
+
logger19.info(
|
|
10668
10684
|
{ taskId, existingTask },
|
|
10669
10685
|
"Successfully reused existing task from race condition"
|
|
10670
10686
|
);
|
|
10671
10687
|
} else {
|
|
10672
|
-
|
|
10688
|
+
logger19.error({ taskId, error }, "Task constraint failed but task not found");
|
|
10673
10689
|
throw error;
|
|
10674
10690
|
}
|
|
10675
10691
|
} else {
|
|
10676
|
-
|
|
10692
|
+
logger19.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
10677
10693
|
throw error;
|
|
10678
10694
|
}
|
|
10679
10695
|
}
|
|
10680
|
-
|
|
10696
|
+
logger19.debug(
|
|
10681
10697
|
{
|
|
10682
10698
|
timestamp: /* @__PURE__ */ new Date(),
|
|
10683
10699
|
executionType: "create_initial_task",
|
|
@@ -10696,7 +10712,7 @@ var ExecutionHandler = class {
|
|
|
10696
10712
|
const maxTransfers = agentConfig?.stopWhen?.transferCountIs ?? AGENT_EXECUTION_TRANSFER_COUNT_DEFAULT;
|
|
10697
10713
|
while (iterations < maxTransfers) {
|
|
10698
10714
|
iterations++;
|
|
10699
|
-
|
|
10715
|
+
logger19.info(
|
|
10700
10716
|
{ iterations, currentAgentId, agentId, conversationId, fromSubAgentId },
|
|
10701
10717
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromSubAgentId || "none"}`
|
|
10702
10718
|
);
|
|
@@ -10704,10 +10720,10 @@ var ExecutionHandler = class {
|
|
|
10704
10720
|
scopes: { tenantId, projectId },
|
|
10705
10721
|
conversationId
|
|
10706
10722
|
});
|
|
10707
|
-
|
|
10723
|
+
logger19.info({ activeAgent }, "activeAgent");
|
|
10708
10724
|
if (activeAgent && activeAgent.activeSubAgentId !== currentAgentId) {
|
|
10709
10725
|
currentAgentId = activeAgent.activeSubAgentId;
|
|
10710
|
-
|
|
10726
|
+
logger19.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
10711
10727
|
}
|
|
10712
10728
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
10713
10729
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -10748,13 +10764,13 @@ var ExecutionHandler = class {
|
|
|
10748
10764
|
});
|
|
10749
10765
|
if (!messageResponse?.result) {
|
|
10750
10766
|
errorCount++;
|
|
10751
|
-
|
|
10767
|
+
logger19.error(
|
|
10752
10768
|
{ currentAgentId, iterations, errorCount },
|
|
10753
10769
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10754
10770
|
);
|
|
10755
10771
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10756
10772
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10757
|
-
|
|
10773
|
+
logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10758
10774
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10759
10775
|
if (task) {
|
|
10760
10776
|
await updateTask(dbClient_default)({
|
|
@@ -10778,7 +10794,7 @@ var ExecutionHandler = class {
|
|
|
10778
10794
|
if (isTransferTask(messageResponse.result)) {
|
|
10779
10795
|
const transferData = extractTransferData(messageResponse.result);
|
|
10780
10796
|
if (!transferData) {
|
|
10781
|
-
|
|
10797
|
+
logger19.error(
|
|
10782
10798
|
{ result: messageResponse.result },
|
|
10783
10799
|
"Transfer detected but no transfer data found"
|
|
10784
10800
|
);
|
|
@@ -10787,7 +10803,7 @@ var ExecutionHandler = class {
|
|
|
10787
10803
|
const { targetSubAgentId, fromSubAgentId: transferFromAgent } = transferData;
|
|
10788
10804
|
const firstArtifact = messageResponse.result.artifacts[0];
|
|
10789
10805
|
const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
|
|
10790
|
-
|
|
10806
|
+
logger19.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
|
|
10791
10807
|
await createMessage(dbClient_default)({
|
|
10792
10808
|
id: generateId(),
|
|
10793
10809
|
tenantId,
|
|
@@ -10818,7 +10834,7 @@ var ExecutionHandler = class {
|
|
|
10818
10834
|
if (success) {
|
|
10819
10835
|
fromSubAgentId = currentAgentId;
|
|
10820
10836
|
currentAgentId = newAgentId;
|
|
10821
|
-
|
|
10837
|
+
logger19.info(
|
|
10822
10838
|
{
|
|
10823
10839
|
transferFrom: fromSubAgentId,
|
|
10824
10840
|
transferTo: currentAgentId,
|
|
@@ -10832,7 +10848,7 @@ var ExecutionHandler = class {
|
|
|
10832
10848
|
let responseParts = [];
|
|
10833
10849
|
if (messageResponse.result.streamedContent?.parts) {
|
|
10834
10850
|
responseParts = messageResponse.result.streamedContent.parts;
|
|
10835
|
-
|
|
10851
|
+
logger19.info(
|
|
10836
10852
|
{ partsCount: responseParts.length },
|
|
10837
10853
|
"Using streamed content for conversation history"
|
|
10838
10854
|
);
|
|
@@ -10840,7 +10856,7 @@ var ExecutionHandler = class {
|
|
|
10840
10856
|
responseParts = messageResponse.result.artifacts?.flatMap(
|
|
10841
10857
|
(artifact) => artifact.parts || []
|
|
10842
10858
|
) || [];
|
|
10843
|
-
|
|
10859
|
+
logger19.info(
|
|
10844
10860
|
{ partsCount: responseParts.length },
|
|
10845
10861
|
"Using artifacts for conversation history (fallback)"
|
|
10846
10862
|
);
|
|
@@ -10849,7 +10865,7 @@ var ExecutionHandler = class {
|
|
|
10849
10865
|
const agentSessionData = agentSessionManager.getSession(requestId2);
|
|
10850
10866
|
if (agentSessionData) {
|
|
10851
10867
|
const sessionSummary = agentSessionData.getSummary();
|
|
10852
|
-
|
|
10868
|
+
logger19.info(sessionSummary, "AgentSession data after completion");
|
|
10853
10869
|
}
|
|
10854
10870
|
let textContent = "";
|
|
10855
10871
|
for (const part of responseParts) {
|
|
@@ -10903,22 +10919,22 @@ var ExecutionHandler = class {
|
|
|
10903
10919
|
}
|
|
10904
10920
|
});
|
|
10905
10921
|
const updateTaskEnd = Date.now();
|
|
10906
|
-
|
|
10922
|
+
logger19.info(
|
|
10907
10923
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
10908
10924
|
"Completed updateTask operation"
|
|
10909
10925
|
);
|
|
10910
10926
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
10911
10927
|
await sseHelper.complete();
|
|
10912
|
-
|
|
10928
|
+
logger19.info({}, "Ending AgentSession and cleaning up");
|
|
10913
10929
|
await agentSessionManager.endSession(requestId2);
|
|
10914
|
-
|
|
10930
|
+
logger19.info({}, "Cleaning up streamHelper");
|
|
10915
10931
|
unregisterStreamHelper(requestId2);
|
|
10916
10932
|
let response;
|
|
10917
10933
|
if (sseHelper instanceof BufferingStreamHelper) {
|
|
10918
10934
|
const captured = sseHelper.getCapturedResponse();
|
|
10919
10935
|
response = captured.text || "No response content";
|
|
10920
10936
|
}
|
|
10921
|
-
|
|
10937
|
+
logger19.info({}, "ExecutionHandler returning success");
|
|
10922
10938
|
return { success: true, iterations, response };
|
|
10923
10939
|
} catch (error) {
|
|
10924
10940
|
setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -10929,13 +10945,13 @@ var ExecutionHandler = class {
|
|
|
10929
10945
|
});
|
|
10930
10946
|
}
|
|
10931
10947
|
errorCount++;
|
|
10932
|
-
|
|
10948
|
+
logger19.warn(
|
|
10933
10949
|
{ iterations, errorCount },
|
|
10934
10950
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
10935
10951
|
);
|
|
10936
10952
|
if (errorCount >= this.MAX_ERRORS) {
|
|
10937
10953
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
10938
|
-
|
|
10954
|
+
logger19.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
10939
10955
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
10940
10956
|
if (task) {
|
|
10941
10957
|
await updateTask(dbClient_default)({
|
|
@@ -10956,7 +10972,7 @@ var ExecutionHandler = class {
|
|
|
10956
10972
|
}
|
|
10957
10973
|
}
|
|
10958
10974
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
10959
|
-
|
|
10975
|
+
logger19.error({ maxTransfers, iterations }, errorMessage);
|
|
10960
10976
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
10961
10977
|
if (task) {
|
|
10962
10978
|
await updateTask(dbClient_default)({
|
|
@@ -10975,7 +10991,7 @@ var ExecutionHandler = class {
|
|
|
10975
10991
|
unregisterStreamHelper(requestId2);
|
|
10976
10992
|
return { success: false, error: errorMessage, iterations };
|
|
10977
10993
|
} catch (error) {
|
|
10978
|
-
|
|
10994
|
+
logger19.error({ error }, "Error in execution handler");
|
|
10979
10995
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
10980
10996
|
await sseHelper.writeOperation(
|
|
10981
10997
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -11002,7 +11018,7 @@ var ExecutionHandler = class {
|
|
|
11002
11018
|
|
|
11003
11019
|
// src/routes/chat.ts
|
|
11004
11020
|
var app2 = new OpenAPIHono();
|
|
11005
|
-
var
|
|
11021
|
+
var logger20 = getLogger("completionsHandler");
|
|
11006
11022
|
var chatCompletionsRoute = createRoute({
|
|
11007
11023
|
method: "post",
|
|
11008
11024
|
path: "/completions",
|
|
@@ -11120,7 +11136,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11120
11136
|
tracestate: c.req.header("tracestate"),
|
|
11121
11137
|
baggage: c.req.header("baggage")
|
|
11122
11138
|
};
|
|
11123
|
-
|
|
11139
|
+
logger20.info(
|
|
11124
11140
|
{
|
|
11125
11141
|
otelHeaders,
|
|
11126
11142
|
path: c.req.path,
|
|
@@ -11229,7 +11245,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11229
11245
|
dbClient: dbClient_default,
|
|
11230
11246
|
credentialStores
|
|
11231
11247
|
});
|
|
11232
|
-
|
|
11248
|
+
logger20.info(
|
|
11233
11249
|
{
|
|
11234
11250
|
tenantId,
|
|
11235
11251
|
projectId,
|
|
@@ -11277,7 +11293,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11277
11293
|
try {
|
|
11278
11294
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
11279
11295
|
await sseHelper.writeRole();
|
|
11280
|
-
|
|
11296
|
+
logger20.info({ subAgentId }, "Starting execution");
|
|
11281
11297
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
11282
11298
|
const emitOperations = emitOperationsHeader === "true";
|
|
11283
11299
|
const executionHandler = new ExecutionHandler();
|
|
@@ -11290,7 +11306,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11290
11306
|
sseHelper,
|
|
11291
11307
|
emitOperations
|
|
11292
11308
|
});
|
|
11293
|
-
|
|
11309
|
+
logger20.info(
|
|
11294
11310
|
{ result },
|
|
11295
11311
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11296
11312
|
);
|
|
@@ -11304,7 +11320,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11304
11320
|
}
|
|
11305
11321
|
await sseHelper.complete();
|
|
11306
11322
|
} catch (error) {
|
|
11307
|
-
|
|
11323
|
+
logger20.error(
|
|
11308
11324
|
{
|
|
11309
11325
|
error: error instanceof Error ? error.message : error,
|
|
11310
11326
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11321,13 +11337,13 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
11321
11337
|
);
|
|
11322
11338
|
await sseHelper.complete();
|
|
11323
11339
|
} catch (streamError) {
|
|
11324
|
-
|
|
11340
|
+
logger20.error({ streamError }, "Failed to write error to stream");
|
|
11325
11341
|
}
|
|
11326
11342
|
}
|
|
11327
11343
|
});
|
|
11328
11344
|
});
|
|
11329
11345
|
} catch (error) {
|
|
11330
|
-
|
|
11346
|
+
logger20.error(
|
|
11331
11347
|
{
|
|
11332
11348
|
error: error instanceof Error ? error.message : error,
|
|
11333
11349
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11351,7 +11367,7 @@ var getMessageText = (content) => {
|
|
|
11351
11367
|
};
|
|
11352
11368
|
var chat_default = app2;
|
|
11353
11369
|
var app3 = new OpenAPIHono();
|
|
11354
|
-
var
|
|
11370
|
+
var logger21 = getLogger("chatDataStream");
|
|
11355
11371
|
var chatDataStreamRoute = createRoute({
|
|
11356
11372
|
method: "post",
|
|
11357
11373
|
path: "/chat",
|
|
@@ -11478,7 +11494,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11478
11494
|
});
|
|
11479
11495
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
11480
11496
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
11481
|
-
|
|
11497
|
+
logger21.info({ userText, lastUserMessage }, "userText");
|
|
11482
11498
|
const messageSpan = trace.getActiveSpan();
|
|
11483
11499
|
if (messageSpan) {
|
|
11484
11500
|
messageSpan.setAttributes({
|
|
@@ -11561,7 +11577,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11561
11577
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
11562
11578
|
}
|
|
11563
11579
|
} catch (err) {
|
|
11564
|
-
|
|
11580
|
+
logger21.error({ err }, "Streaming error");
|
|
11565
11581
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
11566
11582
|
} finally {
|
|
11567
11583
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -11583,7 +11599,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
11583
11599
|
);
|
|
11584
11600
|
});
|
|
11585
11601
|
} catch (error) {
|
|
11586
|
-
|
|
11602
|
+
logger21.error(
|
|
11587
11603
|
{
|
|
11588
11604
|
error,
|
|
11589
11605
|
errorMessage: error instanceof Error ? error.message : String(error),
|
|
@@ -11672,7 +11688,7 @@ app3.openapi(toolApprovalRoute, async (c) => {
|
|
|
11672
11688
|
const { tenantId, projectId } = executionContext;
|
|
11673
11689
|
const requestBody = await c.req.json();
|
|
11674
11690
|
const { conversationId, toolCallId, approved, reason } = requestBody;
|
|
11675
|
-
|
|
11691
|
+
logger21.info(
|
|
11676
11692
|
{
|
|
11677
11693
|
conversationId,
|
|
11678
11694
|
toolCallId,
|
|
@@ -11701,7 +11717,7 @@ app3.openapi(toolApprovalRoute, async (c) => {
|
|
|
11701
11717
|
span.setStatus({ code: 1, message: "Tool call not found" });
|
|
11702
11718
|
return c.json({ error: "Tool call not found or already processed" }, 404);
|
|
11703
11719
|
}
|
|
11704
|
-
|
|
11720
|
+
logger21.info({ conversationId, toolCallId, approved }, "Tool approval processed successfully");
|
|
11705
11721
|
span.setStatus({ code: 1, message: "Success" });
|
|
11706
11722
|
return c.json({
|
|
11707
11723
|
success: true,
|
|
@@ -11709,7 +11725,7 @@ app3.openapi(toolApprovalRoute, async (c) => {
|
|
|
11709
11725
|
});
|
|
11710
11726
|
} catch (error) {
|
|
11711
11727
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
11712
|
-
|
|
11728
|
+
logger21.error(
|
|
11713
11729
|
{
|
|
11714
11730
|
error: errorMessage,
|
|
11715
11731
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -11730,7 +11746,7 @@ app3.openapi(toolApprovalRoute, async (c) => {
|
|
|
11730
11746
|
});
|
|
11731
11747
|
});
|
|
11732
11748
|
var chatDataStream_default = app3;
|
|
11733
|
-
var
|
|
11749
|
+
var logger22 = getLogger("mcp");
|
|
11734
11750
|
var MockResponseSingleton = class _MockResponseSingleton {
|
|
11735
11751
|
static instance;
|
|
11736
11752
|
mockRes;
|
|
@@ -11784,21 +11800,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
11784
11800
|
id: 0
|
|
11785
11801
|
});
|
|
11786
11802
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
11787
|
-
|
|
11803
|
+
logger22.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
11788
11804
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
11789
11805
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
11790
11806
|
try {
|
|
11791
11807
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
11792
|
-
|
|
11808
|
+
logger22.info({ sessionId }, "Successfully spoofed initialization");
|
|
11793
11809
|
} catch (spoofError) {
|
|
11794
|
-
|
|
11810
|
+
logger22.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
11795
11811
|
}
|
|
11796
11812
|
};
|
|
11797
11813
|
var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
11798
11814
|
const sessionId = req.headers["mcp-session-id"];
|
|
11799
|
-
|
|
11815
|
+
logger22.info({ sessionId }, "Received MCP session ID");
|
|
11800
11816
|
if (!sessionId) {
|
|
11801
|
-
|
|
11817
|
+
logger22.info({ body }, "Missing session ID");
|
|
11802
11818
|
res.writeHead(400).end(
|
|
11803
11819
|
JSON.stringify({
|
|
11804
11820
|
jsonrpc: "2.0",
|
|
@@ -11825,7 +11841,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
11825
11841
|
scopes: { tenantId, projectId },
|
|
11826
11842
|
conversationId: sessionId
|
|
11827
11843
|
});
|
|
11828
|
-
|
|
11844
|
+
logger22.info(
|
|
11829
11845
|
{
|
|
11830
11846
|
sessionId,
|
|
11831
11847
|
conversationFound: !!conversation,
|
|
@@ -11836,7 +11852,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
11836
11852
|
"Conversation lookup result"
|
|
11837
11853
|
);
|
|
11838
11854
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
|
|
11839
|
-
|
|
11855
|
+
logger22.info(
|
|
11840
11856
|
{ sessionId, conversationId: conversation?.id },
|
|
11841
11857
|
"MCP session not found or invalid"
|
|
11842
11858
|
);
|
|
@@ -11897,7 +11913,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
11897
11913
|
requestId: requestId2,
|
|
11898
11914
|
sseHelper: mcpStreamHelper
|
|
11899
11915
|
});
|
|
11900
|
-
|
|
11916
|
+
logger22.info(
|
|
11901
11917
|
{ result },
|
|
11902
11918
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11903
11919
|
);
|
|
@@ -11981,7 +11997,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
11981
11997
|
dbClient: dbClient_default,
|
|
11982
11998
|
credentialStores
|
|
11983
11999
|
});
|
|
11984
|
-
|
|
12000
|
+
logger22.info(
|
|
11985
12001
|
{
|
|
11986
12002
|
tenantId,
|
|
11987
12003
|
projectId,
|
|
@@ -12043,7 +12059,7 @@ var validateRequestParameters = (c) => {
|
|
|
12043
12059
|
};
|
|
12044
12060
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
12045
12061
|
const { tenantId, projectId, agentId } = executionContext;
|
|
12046
|
-
|
|
12062
|
+
logger22.info({ body }, "Received initialization request");
|
|
12047
12063
|
const sessionId = getConversationId();
|
|
12048
12064
|
const activeSpan = trace.getActiveSpan();
|
|
12049
12065
|
if (activeSpan) {
|
|
@@ -12099,7 +12115,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12099
12115
|
}
|
|
12100
12116
|
}
|
|
12101
12117
|
});
|
|
12102
|
-
|
|
12118
|
+
logger22.info(
|
|
12103
12119
|
{ sessionId, conversationId: conversation.id },
|
|
12104
12120
|
"Created MCP session as conversation"
|
|
12105
12121
|
);
|
|
@@ -12108,9 +12124,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12108
12124
|
});
|
|
12109
12125
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
12110
12126
|
await server.connect(transport);
|
|
12111
|
-
|
|
12127
|
+
logger22.info({ sessionId }, "Server connected for initialization");
|
|
12112
12128
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
12113
|
-
|
|
12129
|
+
logger22.info(
|
|
12114
12130
|
{
|
|
12115
12131
|
sessionId,
|
|
12116
12132
|
bodyMethod: body?.method,
|
|
@@ -12119,7 +12135,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
12119
12135
|
"About to handle initialization request"
|
|
12120
12136
|
);
|
|
12121
12137
|
await transport.handleRequest(req, res, body);
|
|
12122
|
-
|
|
12138
|
+
logger22.info({ sessionId }, "Successfully handled initialization request");
|
|
12123
12139
|
return toFetchResponse(res);
|
|
12124
12140
|
});
|
|
12125
12141
|
};
|
|
@@ -12146,8 +12162,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
12146
12162
|
sessionId,
|
|
12147
12163
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
12148
12164
|
);
|
|
12149
|
-
|
|
12150
|
-
|
|
12165
|
+
logger22.info({ sessionId }, "Server connected and transport initialized");
|
|
12166
|
+
logger22.info(
|
|
12151
12167
|
{
|
|
12152
12168
|
sessionId,
|
|
12153
12169
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -12161,9 +12177,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
12161
12177
|
);
|
|
12162
12178
|
try {
|
|
12163
12179
|
await transport.handleRequest(req, res, body);
|
|
12164
|
-
|
|
12180
|
+
logger22.info({ sessionId }, "Successfully handled MCP request");
|
|
12165
12181
|
} catch (transportError) {
|
|
12166
|
-
|
|
12182
|
+
logger22.error(
|
|
12167
12183
|
{
|
|
12168
12184
|
sessionId,
|
|
12169
12185
|
error: transportError,
|
|
@@ -12214,13 +12230,13 @@ app4.openapi(
|
|
|
12214
12230
|
}
|
|
12215
12231
|
const { executionContext } = paramValidation;
|
|
12216
12232
|
const body = c.get("requestBody") || {};
|
|
12217
|
-
|
|
12233
|
+
logger22.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
12218
12234
|
const isInitRequest = body.method === "initialize";
|
|
12219
12235
|
const { req, res } = toReqRes(c.req.raw);
|
|
12220
12236
|
const validatedContext = c.get("validatedContext") || {};
|
|
12221
12237
|
const credentialStores = c.get("credentialStores");
|
|
12222
|
-
|
|
12223
|
-
|
|
12238
|
+
logger22.info({ validatedContext }, "Validated context");
|
|
12239
|
+
logger22.info({ req }, "request");
|
|
12224
12240
|
if (isInitRequest) {
|
|
12225
12241
|
return await handleInitializationRequest(
|
|
12226
12242
|
body,
|
|
@@ -12241,7 +12257,7 @@ app4.openapi(
|
|
|
12241
12257
|
credentialStores
|
|
12242
12258
|
);
|
|
12243
12259
|
} catch (e) {
|
|
12244
|
-
|
|
12260
|
+
logger22.error(
|
|
12245
12261
|
{
|
|
12246
12262
|
error: e instanceof Error ? e.message : e,
|
|
12247
12263
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -12253,7 +12269,7 @@ app4.openapi(
|
|
|
12253
12269
|
}
|
|
12254
12270
|
);
|
|
12255
12271
|
app4.get("/", async (c) => {
|
|
12256
|
-
|
|
12272
|
+
logger22.info({}, "Received GET MCP request");
|
|
12257
12273
|
return c.json(
|
|
12258
12274
|
{
|
|
12259
12275
|
jsonrpc: "2.0",
|
|
@@ -12267,7 +12283,7 @@ app4.get("/", async (c) => {
|
|
|
12267
12283
|
);
|
|
12268
12284
|
});
|
|
12269
12285
|
app4.delete("/", async (c) => {
|
|
12270
|
-
|
|
12286
|
+
logger22.info({}, "Received DELETE MCP request");
|
|
12271
12287
|
return c.json(
|
|
12272
12288
|
{
|
|
12273
12289
|
jsonrpc: "2.0",
|
|
@@ -12280,7 +12296,7 @@ app4.delete("/", async (c) => {
|
|
|
12280
12296
|
var mcp_default = app4;
|
|
12281
12297
|
|
|
12282
12298
|
// src/app.ts
|
|
12283
|
-
var
|
|
12299
|
+
var logger23 = getLogger("agents-run-api");
|
|
12284
12300
|
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
12285
12301
|
const app6 = new OpenAPIHono();
|
|
12286
12302
|
app6.use("*", otel());
|
|
@@ -12299,7 +12315,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12299
12315
|
const body = await c.req.json();
|
|
12300
12316
|
c.set("requestBody", body);
|
|
12301
12317
|
} catch (error) {
|
|
12302
|
-
|
|
12318
|
+
logger23.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
12303
12319
|
}
|
|
12304
12320
|
}
|
|
12305
12321
|
return next();
|
|
@@ -12350,8 +12366,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12350
12366
|
if (!isExpectedError) {
|
|
12351
12367
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
12352
12368
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
12353
|
-
if (
|
|
12354
|
-
|
|
12369
|
+
if (logger23) {
|
|
12370
|
+
logger23.error(
|
|
12355
12371
|
{
|
|
12356
12372
|
error: err,
|
|
12357
12373
|
message: errorMessage,
|
|
@@ -12363,8 +12379,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12363
12379
|
);
|
|
12364
12380
|
}
|
|
12365
12381
|
} else {
|
|
12366
|
-
if (
|
|
12367
|
-
|
|
12382
|
+
if (logger23) {
|
|
12383
|
+
logger23.error(
|
|
12368
12384
|
{
|
|
12369
12385
|
error: err,
|
|
12370
12386
|
path: c.req.path,
|
|
@@ -12381,8 +12397,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12381
12397
|
const response = err.getResponse();
|
|
12382
12398
|
return response;
|
|
12383
12399
|
} catch (responseError) {
|
|
12384
|
-
if (
|
|
12385
|
-
|
|
12400
|
+
if (logger23) {
|
|
12401
|
+
logger23.error({ error: responseError }, "Error while handling HTTPException response");
|
|
12386
12402
|
}
|
|
12387
12403
|
}
|
|
12388
12404
|
}
|
|
@@ -12416,7 +12432,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12416
12432
|
app6.use("*", async (c, next) => {
|
|
12417
12433
|
const executionContext = c.get("executionContext");
|
|
12418
12434
|
if (!executionContext) {
|
|
12419
|
-
|
|
12435
|
+
logger23.debug({}, "Empty execution context");
|
|
12420
12436
|
return next();
|
|
12421
12437
|
}
|
|
12422
12438
|
const { tenantId, projectId, agentId } = executionContext;
|
|
@@ -12425,7 +12441,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12425
12441
|
if (requestBody) {
|
|
12426
12442
|
conversationId = requestBody.conversationId;
|
|
12427
12443
|
if (!conversationId) {
|
|
12428
|
-
|
|
12444
|
+
logger23.debug({ requestBody }, "No conversation ID found in request body");
|
|
12429
12445
|
}
|
|
12430
12446
|
}
|
|
12431
12447
|
const entries = Object.fromEntries(
|
|
@@ -12440,7 +12456,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
12440
12456
|
})
|
|
12441
12457
|
);
|
|
12442
12458
|
if (!Object.keys(entries).length) {
|
|
12443
|
-
|
|
12459
|
+
logger23.debug({}, "Empty entries for baggage");
|
|
12444
12460
|
return next();
|
|
12445
12461
|
}
|
|
12446
12462
|
const bag = Object.entries(entries).reduce(
|