@inkeep/agents-run-api 0.0.0-dev-20251127053741 → 0.0.0-dev-20251201213206

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 CHANGED
@@ -14678,6 +14678,32 @@ var Agent = class {
14678
14678
  }
14679
14679
  return sanitizedTools;
14680
14680
  }
14681
+ #createRelationToolName(prefix, targetId) {
14682
+ return `${prefix}_to_${targetId.toLowerCase().replace(/\s+/g, "_")}`;
14683
+ }
14684
+ #getRelationshipIdForTool(toolName, toolType) {
14685
+ if (toolType === "mcp") {
14686
+ const matchingTool = this.config.tools?.find((tool3) => {
14687
+ if (tool3.config?.type !== "mcp") {
14688
+ return false;
14689
+ }
14690
+ if (tool3.availableTools?.some((available) => available.name === toolName)) {
14691
+ return true;
14692
+ }
14693
+ if (tool3.config.mcp.activeTools?.includes(toolName)) {
14694
+ return true;
14695
+ }
14696
+ return tool3.name === toolName;
14697
+ });
14698
+ return matchingTool?.relationshipId;
14699
+ }
14700
+ if (toolType === "delegation") {
14701
+ const relation = this.config.delegateRelations.find(
14702
+ (relation2) => this.#createRelationToolName("delegate", relation2.config.id) === toolName
14703
+ );
14704
+ return relation?.config.relationId;
14705
+ }
14706
+ }
14681
14707
  /**
14682
14708
  * Get the primary model settings for text generation and thinking
14683
14709
  * Requires model to be configured at project level
@@ -14746,10 +14772,11 @@ var Agent = class {
14746
14772
  /**
14747
14773
  * Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
14748
14774
  */
14749
- wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, relationshipId, options) {
14775
+ wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, options) {
14750
14776
  if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
14751
14777
  return toolDefinition;
14752
14778
  }
14779
+ const relationshipId = this.#getRelationshipIdForTool(toolName, toolType);
14753
14780
  const originalExecute = toolDefinition.execute;
14754
14781
  return {
14755
14782
  ...toolDefinition,
@@ -14856,10 +14883,9 @@ var Agent = class {
14856
14883
  }
14857
14884
  getRelationTools(runtimeContext, sessionId) {
14858
14885
  const { transferRelations = [], delegateRelations = [] } = this.config;
14859
- const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
14860
14886
  return Object.fromEntries([
14861
14887
  ...transferRelations.map((agentConfig) => {
14862
- const toolName = createToolName("transfer", agentConfig.id);
14888
+ const toolName = this.#createRelationToolName("transfer", agentConfig.id);
14863
14889
  return [
14864
14890
  toolName,
14865
14891
  this.wrapToolWithStreaming(
@@ -14876,7 +14902,7 @@ var Agent = class {
14876
14902
  ];
14877
14903
  }),
14878
14904
  ...delegateRelations.map((relation) => {
14879
- const toolName = createToolName("delegate", relation.config.id);
14905
+ const toolName = this.#createRelationToolName("delegate", relation.config.id);
14880
14906
  return [
14881
14907
  toolName,
14882
14908
  this.wrapToolWithStreaming(
@@ -14913,8 +14939,7 @@ var Agent = class {
14913
14939
  const tools = await Promise.all(mcpTools.map((tool3) => this.getMcpTool(tool3)) || []) || [];
14914
14940
  if (!sessionId) {
14915
14941
  const wrappedTools2 = {};
14916
- for (const [index, toolSet] of tools.entries()) {
14917
- const relationshipId = mcpTools[index]?.relationshipId;
14942
+ for (const toolSet of tools) {
14918
14943
  for (const [toolName, toolDef] of Object.entries(toolSet.tools)) {
14919
14944
  const needsApproval = toolSet.toolPolicies?.[toolName]?.needsApproval || false;
14920
14945
  const enhancedTool = {
@@ -14926,7 +14951,6 @@ var Agent = class {
14926
14951
  enhancedTool,
14927
14952
  streamRequestId,
14928
14953
  "mcp",
14929
- relationshipId,
14930
14954
  { needsApproval }
14931
14955
  );
14932
14956
  }
@@ -14934,8 +14958,7 @@ var Agent = class {
14934
14958
  return wrappedTools2;
14935
14959
  }
14936
14960
  const wrappedTools = {};
14937
- for (const [index, toolResult] of tools.entries()) {
14938
- const relationshipId = mcpTools[index]?.relationshipId;
14961
+ for (const toolResult of tools) {
14939
14962
  for (const [toolName, originalTool] of Object.entries(toolResult.tools)) {
14940
14963
  if (!isValidTool(originalTool)) {
14941
14964
  logger19.error({ toolName }, "Invalid MCP tool structure - missing required properties");
@@ -15046,6 +15069,7 @@ var Agent = class {
15046
15069
  timestamp: Date.now()
15047
15070
  });
15048
15071
  if (streamRequestId) {
15072
+ const relationshipId = this.#getRelationshipIdForTool(toolName, "mcp");
15049
15073
  agentSessionManager.recordEvent(streamRequestId, "error", this.config.id, {
15050
15074
  message: `MCP tool "${toolName}" failed: ${errorMessage}`,
15051
15075
  code: "mcp_tool_error",
@@ -15094,7 +15118,6 @@ var Agent = class {
15094
15118
  sessionWrappedTool,
15095
15119
  streamRequestId,
15096
15120
  "mcp",
15097
- relationshipId,
15098
15121
  { needsApproval }
15099
15122
  );
15100
15123
  }
@@ -16930,6 +16953,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
16930
16953
  type: "internal",
16931
16954
  config: {
16932
16955
  id: relation.id,
16956
+ relationId: relation.relationId,
16933
16957
  tenantId: config.tenantId,
16934
16958
  projectId: config.projectId,
16935
16959
  agentId: config.agentId,
package/dist/index.js CHANGED
@@ -7028,6 +7028,32 @@ var Agent = class {
7028
7028
  }
7029
7029
  return sanitizedTools;
7030
7030
  }
7031
+ #createRelationToolName(prefix, targetId) {
7032
+ return `${prefix}_to_${targetId.toLowerCase().replace(/\s+/g, "_")}`;
7033
+ }
7034
+ #getRelationshipIdForTool(toolName, toolType) {
7035
+ if (toolType === "mcp") {
7036
+ const matchingTool = this.config.tools?.find((tool3) => {
7037
+ if (tool3.config?.type !== "mcp") {
7038
+ return false;
7039
+ }
7040
+ if (tool3.availableTools?.some((available) => available.name === toolName)) {
7041
+ return true;
7042
+ }
7043
+ if (tool3.config.mcp.activeTools?.includes(toolName)) {
7044
+ return true;
7045
+ }
7046
+ return tool3.name === toolName;
7047
+ });
7048
+ return matchingTool?.relationshipId;
7049
+ }
7050
+ if (toolType === "delegation") {
7051
+ const relation = this.config.delegateRelations.find(
7052
+ (relation2) => this.#createRelationToolName("delegate", relation2.config.id) === toolName
7053
+ );
7054
+ return relation?.config.relationId;
7055
+ }
7056
+ }
7031
7057
  /**
7032
7058
  * Get the primary model settings for text generation and thinking
7033
7059
  * Requires model to be configured at project level
@@ -7096,10 +7122,11 @@ var Agent = class {
7096
7122
  /**
7097
7123
  * Wraps a tool with streaming lifecycle tracking (start, complete, error) and AgentSession recording
7098
7124
  */
7099
- wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, relationshipId, options) {
7125
+ wrapToolWithStreaming(toolName, toolDefinition, streamRequestId, toolType, options) {
7100
7126
  if (!toolDefinition || typeof toolDefinition !== "object" || !("execute" in toolDefinition)) {
7101
7127
  return toolDefinition;
7102
7128
  }
7129
+ const relationshipId = this.#getRelationshipIdForTool(toolName, toolType);
7103
7130
  const originalExecute = toolDefinition.execute;
7104
7131
  return {
7105
7132
  ...toolDefinition,
@@ -7206,10 +7233,9 @@ var Agent = class {
7206
7233
  }
7207
7234
  getRelationTools(runtimeContext, sessionId) {
7208
7235
  const { transferRelations = [], delegateRelations = [] } = this.config;
7209
- const createToolName = (prefix, subAgentId) => `${prefix}_to_${subAgentId.toLowerCase().replace(/\s+/g, "_")}`;
7210
7236
  return Object.fromEntries([
7211
7237
  ...transferRelations.map((agentConfig) => {
7212
- const toolName = createToolName("transfer", agentConfig.id);
7238
+ const toolName = this.#createRelationToolName("transfer", agentConfig.id);
7213
7239
  return [
7214
7240
  toolName,
7215
7241
  this.wrapToolWithStreaming(
@@ -7226,7 +7252,7 @@ var Agent = class {
7226
7252
  ];
7227
7253
  }),
7228
7254
  ...delegateRelations.map((relation) => {
7229
- const toolName = createToolName("delegate", relation.config.id);
7255
+ const toolName = this.#createRelationToolName("delegate", relation.config.id);
7230
7256
  return [
7231
7257
  toolName,
7232
7258
  this.wrapToolWithStreaming(
@@ -7263,8 +7289,7 @@ var Agent = class {
7263
7289
  const tools = await Promise.all(mcpTools.map((tool3) => this.getMcpTool(tool3)) || []) || [];
7264
7290
  if (!sessionId) {
7265
7291
  const wrappedTools2 = {};
7266
- for (const [index, toolSet] of tools.entries()) {
7267
- const relationshipId = mcpTools[index]?.relationshipId;
7292
+ for (const toolSet of tools) {
7268
7293
  for (const [toolName, toolDef] of Object.entries(toolSet.tools)) {
7269
7294
  const needsApproval = toolSet.toolPolicies?.[toolName]?.needsApproval || false;
7270
7295
  const enhancedTool = {
@@ -7276,7 +7301,6 @@ var Agent = class {
7276
7301
  enhancedTool,
7277
7302
  streamRequestId,
7278
7303
  "mcp",
7279
- relationshipId,
7280
7304
  { needsApproval }
7281
7305
  );
7282
7306
  }
@@ -7284,8 +7308,7 @@ var Agent = class {
7284
7308
  return wrappedTools2;
7285
7309
  }
7286
7310
  const wrappedTools = {};
7287
- for (const [index, toolResult] of tools.entries()) {
7288
- const relationshipId = mcpTools[index]?.relationshipId;
7311
+ for (const toolResult of tools) {
7289
7312
  for (const [toolName, originalTool] of Object.entries(toolResult.tools)) {
7290
7313
  if (!isValidTool(originalTool)) {
7291
7314
  logger15.error({ toolName }, "Invalid MCP tool structure - missing required properties");
@@ -7396,6 +7419,7 @@ var Agent = class {
7396
7419
  timestamp: Date.now()
7397
7420
  });
7398
7421
  if (streamRequestId) {
7422
+ const relationshipId = this.#getRelationshipIdForTool(toolName, "mcp");
7399
7423
  agentSessionManager.recordEvent(streamRequestId, "error", this.config.id, {
7400
7424
  message: `MCP tool "${toolName}" failed: ${errorMessage}`,
7401
7425
  code: "mcp_tool_error",
@@ -7444,7 +7468,6 @@ var Agent = class {
7444
7468
  sessionWrappedTool,
7445
7469
  streamRequestId,
7446
7470
  "mcp",
7447
- relationshipId,
7448
7471
  { needsApproval }
7449
7472
  );
7450
7473
  }
@@ -9280,6 +9303,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
9280
9303
  type: "internal",
9281
9304
  config: {
9282
9305
  id: relation.id,
9306
+ relationId: relation.relationId,
9283
9307
  tenantId: config.tenantId,
9284
9308
  projectId: config.projectId,
9285
9309
  agentId: config.agentId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.0.0-dev-20251127053741",
3
+ "version": "0.0.0-dev-20251201213206",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,7 +53,7 @@
53
53
  "pino": "^9.11.0",
54
54
  "traverse": "^0.6.11",
55
55
  "ts-pattern": "^5.7.1",
56
- "@inkeep/agents-core": "^0.0.0-dev-20251127053741"
56
+ "@inkeep/agents-core": "^0.0.0-dev-20251201213206"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@hono/zod-openapi": "^1.1.5",