@inkeep/agents-sdk 0.7.1 → 0.8.0
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 +52 -35
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +52 -35
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -439,7 +439,30 @@ var Tool = class {
|
|
|
439
439
|
|
|
440
440
|
// src/utils/tool-normalization.ts
|
|
441
441
|
function isAgentMcpConfig(value) {
|
|
442
|
-
return value !== null && typeof value === "object" && "server" in value &&
|
|
442
|
+
return value !== null && typeof value === "object" && "server" in value && value.server && typeof value.server === "object";
|
|
443
|
+
}
|
|
444
|
+
function isTool(value) {
|
|
445
|
+
return value !== null && typeof value === "object" && "config" in value && (typeof value.getId === "function" || "id" in value);
|
|
446
|
+
}
|
|
447
|
+
function normalizeAgentCanUseType(value, fallbackName) {
|
|
448
|
+
if (isAgentMcpConfig(value)) {
|
|
449
|
+
return {
|
|
450
|
+
tool: value.server,
|
|
451
|
+
toolId: value.server.getId(),
|
|
452
|
+
selectedTools: value.selectedTools,
|
|
453
|
+
headers: value.headers,
|
|
454
|
+
isWrapped: true
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
if (isTool(value)) {
|
|
458
|
+
const toolId = value.getId?.() || value.id || fallbackName || "unknown";
|
|
459
|
+
return {
|
|
460
|
+
tool: value,
|
|
461
|
+
toolId,
|
|
462
|
+
isWrapped: false
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
throw new Error(`Invalid AgentCanUseType: expected Tool or AgentMcpConfig, got ${typeof value}`);
|
|
443
466
|
}
|
|
444
467
|
|
|
445
468
|
// src/agent.ts
|
|
@@ -510,6 +533,7 @@ var Agent = class {
|
|
|
510
533
|
id = tool.server.getId();
|
|
511
534
|
toolInstance = tool.server;
|
|
512
535
|
toolInstance.selectedTools = tool.selectedTools;
|
|
536
|
+
toolInstance.headers = tool.headers;
|
|
513
537
|
} else {
|
|
514
538
|
toolInstance = tool;
|
|
515
539
|
id = toolInstance.getId();
|
|
@@ -680,20 +704,13 @@ var Agent = class {
|
|
|
680
704
|
if (tools && Array.isArray(tools)) {
|
|
681
705
|
for (let i = 0; i < tools.length; i++) {
|
|
682
706
|
const toolConfig = tools[i];
|
|
683
|
-
let toolId;
|
|
684
|
-
if (toolConfig instanceof Tool) {
|
|
685
|
-
toolId = toolConfig.getId();
|
|
686
|
-
} else if (toolConfig && typeof toolConfig === "object" && "server" in toolConfig) {
|
|
687
|
-
toolId = toolConfig.server.getId();
|
|
688
|
-
} else {
|
|
689
|
-
toolId = `tool-${i}`;
|
|
690
|
-
}
|
|
691
707
|
try {
|
|
692
|
-
|
|
708
|
+
const normalizedTool = normalizeAgentCanUseType(toolConfig, `tool-${i}`);
|
|
709
|
+
await this.createTool(normalizedTool.toolId, toolConfig);
|
|
693
710
|
} catch (error) {
|
|
694
711
|
logger4.error(
|
|
695
712
|
{
|
|
696
|
-
toolId,
|
|
713
|
+
toolId: isAgentMcpConfig(toolConfig) ? toolConfig.server.getId() : toolConfig.getId?.(),
|
|
697
714
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
698
715
|
},
|
|
699
716
|
"Tool creation failed"
|
|
@@ -868,17 +885,15 @@ var Agent = class {
|
|
|
868
885
|
}
|
|
869
886
|
let tool;
|
|
870
887
|
let selectedTools;
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
} else if (toolConfig instanceof Tool) {
|
|
878
|
-
tool = toolConfig;
|
|
888
|
+
let headers;
|
|
889
|
+
try {
|
|
890
|
+
const normalizedTool = normalizeAgentCanUseType(toolConfig, toolId);
|
|
891
|
+
tool = normalizedTool.tool;
|
|
892
|
+
selectedTools = normalizedTool.selectedTools;
|
|
893
|
+
headers = normalizedTool.headers;
|
|
879
894
|
tool.setContext(this.tenantId, this.projectId);
|
|
880
895
|
await tool.init();
|
|
881
|
-
}
|
|
896
|
+
} catch (_) {
|
|
882
897
|
tool = new Tool({
|
|
883
898
|
id: toolId,
|
|
884
899
|
name: toolConfig.name || toolId,
|
|
@@ -890,7 +905,7 @@ var Agent = class {
|
|
|
890
905
|
tool.setContext(this.tenantId, this.projectId);
|
|
891
906
|
await tool.init();
|
|
892
907
|
}
|
|
893
|
-
await this.createAgentToolRelation(tool.getId(), selectedTools);
|
|
908
|
+
await this.createAgentToolRelation(tool.getId(), selectedTools, headers);
|
|
894
909
|
logger4.info(
|
|
895
910
|
{
|
|
896
911
|
agentId: this.getId(),
|
|
@@ -1029,7 +1044,7 @@ var Agent = class {
|
|
|
1029
1044
|
"Created agent-artifactComponent relation"
|
|
1030
1045
|
);
|
|
1031
1046
|
}
|
|
1032
|
-
async createAgentToolRelation(toolId, selectedTools) {
|
|
1047
|
+
async createAgentToolRelation(toolId, selectedTools, headers) {
|
|
1033
1048
|
const relationData = {
|
|
1034
1049
|
id: `${this.getId()}-tool-${toolId}`,
|
|
1035
1050
|
tenantId: this.tenantId,
|
|
@@ -1040,6 +1055,9 @@ var Agent = class {
|
|
|
1040
1055
|
if (selectedTools !== void 0) {
|
|
1041
1056
|
relationData.selectedTools = selectedTools;
|
|
1042
1057
|
}
|
|
1058
|
+
if (headers !== void 0) {
|
|
1059
|
+
relationData.headers = headers;
|
|
1060
|
+
}
|
|
1043
1061
|
const relationResponse = await fetch(
|
|
1044
1062
|
`${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/agent-tool-relations`,
|
|
1045
1063
|
{
|
|
@@ -1227,20 +1245,17 @@ var AgentGraph = class {
|
|
|
1227
1245
|
const delegates = internalAgent.getDelegates();
|
|
1228
1246
|
const tools = [];
|
|
1229
1247
|
const selectedToolsMapping = {};
|
|
1248
|
+
const headersMapping = {};
|
|
1230
1249
|
const agentTools = internalAgent.getTools();
|
|
1231
1250
|
for (const [_toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
toolId = toolInstance.
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
"Selected tools"
|
|
1239
|
-
);
|
|
1240
|
-
selectedToolsMapping[toolId] = toolInstance.selectedTools;
|
|
1241
|
-
}
|
|
1242
|
-
tools.push(toolId);
|
|
1251
|
+
const toolId = toolInstance.getId();
|
|
1252
|
+
if (toolInstance.selectedTools) {
|
|
1253
|
+
selectedToolsMapping[toolId] = toolInstance.selectedTools;
|
|
1254
|
+
}
|
|
1255
|
+
if (toolInstance.headers) {
|
|
1256
|
+
headersMapping[toolId] = toolInstance.headers;
|
|
1243
1257
|
}
|
|
1258
|
+
tools.push(toolId);
|
|
1244
1259
|
}
|
|
1245
1260
|
const dataComponents = [];
|
|
1246
1261
|
const agentDataComponents = internalAgent.getDataComponents();
|
|
@@ -1260,7 +1275,8 @@ var AgentGraph = class {
|
|
|
1260
1275
|
}
|
|
1261
1276
|
const canUse = tools.map((toolId) => ({
|
|
1262
1277
|
toolId,
|
|
1263
|
-
toolSelection: selectedToolsMapping[toolId] || null
|
|
1278
|
+
toolSelection: selectedToolsMapping[toolId] || null,
|
|
1279
|
+
headers: headersMapping[toolId] || null
|
|
1264
1280
|
}));
|
|
1265
1281
|
agentsObject[internalAgent.getId()] = {
|
|
1266
1282
|
id: internalAgent.getId(),
|
|
@@ -3116,7 +3132,8 @@ function dataComponent(config) {
|
|
|
3116
3132
|
function agentMcp(config) {
|
|
3117
3133
|
return {
|
|
3118
3134
|
server: config.server,
|
|
3119
|
-
selectedTools: config.selectedTools
|
|
3135
|
+
selectedTools: config.selectedTools,
|
|
3136
|
+
headers: config.headers
|
|
3120
3137
|
};
|
|
3121
3138
|
}
|
|
3122
3139
|
|
package/dist/index.d.cts
CHANGED
|
@@ -95,7 +95,8 @@ interface DataComponentConfig extends ComponentConfig {
|
|
|
95
95
|
}
|
|
96
96
|
type AgentMcpConfig = {
|
|
97
97
|
server: Tool;
|
|
98
|
-
selectedTools
|
|
98
|
+
selectedTools?: string[];
|
|
99
|
+
headers?: Record<string, string>;
|
|
99
100
|
};
|
|
100
101
|
/**
|
|
101
102
|
* Creates a transfer configuration for agent handoffs.
|
|
@@ -206,6 +207,7 @@ declare function externalAgents(configs: Record<string, ExternalAgentConfig>): R
|
|
|
206
207
|
*/
|
|
207
208
|
type AgentTool = Tool & {
|
|
208
209
|
selectedTools?: string[];
|
|
210
|
+
headers?: Record<string, string>;
|
|
209
211
|
};
|
|
210
212
|
interface UserMessage {
|
|
211
213
|
role: 'user';
|
package/dist/index.d.ts
CHANGED
|
@@ -95,7 +95,8 @@ interface DataComponentConfig extends ComponentConfig {
|
|
|
95
95
|
}
|
|
96
96
|
type AgentMcpConfig = {
|
|
97
97
|
server: Tool;
|
|
98
|
-
selectedTools
|
|
98
|
+
selectedTools?: string[];
|
|
99
|
+
headers?: Record<string, string>;
|
|
99
100
|
};
|
|
100
101
|
/**
|
|
101
102
|
* Creates a transfer configuration for agent handoffs.
|
|
@@ -206,6 +207,7 @@ declare function externalAgents(configs: Record<string, ExternalAgentConfig>): R
|
|
|
206
207
|
*/
|
|
207
208
|
type AgentTool = Tool & {
|
|
208
209
|
selectedTools?: string[];
|
|
210
|
+
headers?: Record<string, string>;
|
|
209
211
|
};
|
|
210
212
|
interface UserMessage {
|
|
211
213
|
role: 'user';
|
package/dist/index.js
CHANGED
|
@@ -437,7 +437,30 @@ var Tool = class {
|
|
|
437
437
|
|
|
438
438
|
// src/utils/tool-normalization.ts
|
|
439
439
|
function isAgentMcpConfig(value) {
|
|
440
|
-
return value !== null && typeof value === "object" && "server" in value &&
|
|
440
|
+
return value !== null && typeof value === "object" && "server" in value && value.server && typeof value.server === "object";
|
|
441
|
+
}
|
|
442
|
+
function isTool(value) {
|
|
443
|
+
return value !== null && typeof value === "object" && "config" in value && (typeof value.getId === "function" || "id" in value);
|
|
444
|
+
}
|
|
445
|
+
function normalizeAgentCanUseType(value, fallbackName) {
|
|
446
|
+
if (isAgentMcpConfig(value)) {
|
|
447
|
+
return {
|
|
448
|
+
tool: value.server,
|
|
449
|
+
toolId: value.server.getId(),
|
|
450
|
+
selectedTools: value.selectedTools,
|
|
451
|
+
headers: value.headers,
|
|
452
|
+
isWrapped: true
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
if (isTool(value)) {
|
|
456
|
+
const toolId = value.getId?.() || value.id || fallbackName || "unknown";
|
|
457
|
+
return {
|
|
458
|
+
tool: value,
|
|
459
|
+
toolId,
|
|
460
|
+
isWrapped: false
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
throw new Error(`Invalid AgentCanUseType: expected Tool or AgentMcpConfig, got ${typeof value}`);
|
|
441
464
|
}
|
|
442
465
|
|
|
443
466
|
// src/agent.ts
|
|
@@ -508,6 +531,7 @@ var Agent = class {
|
|
|
508
531
|
id = tool.server.getId();
|
|
509
532
|
toolInstance = tool.server;
|
|
510
533
|
toolInstance.selectedTools = tool.selectedTools;
|
|
534
|
+
toolInstance.headers = tool.headers;
|
|
511
535
|
} else {
|
|
512
536
|
toolInstance = tool;
|
|
513
537
|
id = toolInstance.getId();
|
|
@@ -678,20 +702,13 @@ var Agent = class {
|
|
|
678
702
|
if (tools && Array.isArray(tools)) {
|
|
679
703
|
for (let i = 0; i < tools.length; i++) {
|
|
680
704
|
const toolConfig = tools[i];
|
|
681
|
-
let toolId;
|
|
682
|
-
if (toolConfig instanceof Tool) {
|
|
683
|
-
toolId = toolConfig.getId();
|
|
684
|
-
} else if (toolConfig && typeof toolConfig === "object" && "server" in toolConfig) {
|
|
685
|
-
toolId = toolConfig.server.getId();
|
|
686
|
-
} else {
|
|
687
|
-
toolId = `tool-${i}`;
|
|
688
|
-
}
|
|
689
705
|
try {
|
|
690
|
-
|
|
706
|
+
const normalizedTool = normalizeAgentCanUseType(toolConfig, `tool-${i}`);
|
|
707
|
+
await this.createTool(normalizedTool.toolId, toolConfig);
|
|
691
708
|
} catch (error) {
|
|
692
709
|
logger4.error(
|
|
693
710
|
{
|
|
694
|
-
toolId,
|
|
711
|
+
toolId: isAgentMcpConfig(toolConfig) ? toolConfig.server.getId() : toolConfig.getId?.(),
|
|
695
712
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
696
713
|
},
|
|
697
714
|
"Tool creation failed"
|
|
@@ -866,17 +883,15 @@ var Agent = class {
|
|
|
866
883
|
}
|
|
867
884
|
let tool;
|
|
868
885
|
let selectedTools;
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
} else if (toolConfig instanceof Tool) {
|
|
876
|
-
tool = toolConfig;
|
|
886
|
+
let headers;
|
|
887
|
+
try {
|
|
888
|
+
const normalizedTool = normalizeAgentCanUseType(toolConfig, toolId);
|
|
889
|
+
tool = normalizedTool.tool;
|
|
890
|
+
selectedTools = normalizedTool.selectedTools;
|
|
891
|
+
headers = normalizedTool.headers;
|
|
877
892
|
tool.setContext(this.tenantId, this.projectId);
|
|
878
893
|
await tool.init();
|
|
879
|
-
}
|
|
894
|
+
} catch (_) {
|
|
880
895
|
tool = new Tool({
|
|
881
896
|
id: toolId,
|
|
882
897
|
name: toolConfig.name || toolId,
|
|
@@ -888,7 +903,7 @@ var Agent = class {
|
|
|
888
903
|
tool.setContext(this.tenantId, this.projectId);
|
|
889
904
|
await tool.init();
|
|
890
905
|
}
|
|
891
|
-
await this.createAgentToolRelation(tool.getId(), selectedTools);
|
|
906
|
+
await this.createAgentToolRelation(tool.getId(), selectedTools, headers);
|
|
892
907
|
logger4.info(
|
|
893
908
|
{
|
|
894
909
|
agentId: this.getId(),
|
|
@@ -1027,7 +1042,7 @@ var Agent = class {
|
|
|
1027
1042
|
"Created agent-artifactComponent relation"
|
|
1028
1043
|
);
|
|
1029
1044
|
}
|
|
1030
|
-
async createAgentToolRelation(toolId, selectedTools) {
|
|
1045
|
+
async createAgentToolRelation(toolId, selectedTools, headers) {
|
|
1031
1046
|
const relationData = {
|
|
1032
1047
|
id: `${this.getId()}-tool-${toolId}`,
|
|
1033
1048
|
tenantId: this.tenantId,
|
|
@@ -1038,6 +1053,9 @@ var Agent = class {
|
|
|
1038
1053
|
if (selectedTools !== void 0) {
|
|
1039
1054
|
relationData.selectedTools = selectedTools;
|
|
1040
1055
|
}
|
|
1056
|
+
if (headers !== void 0) {
|
|
1057
|
+
relationData.headers = headers;
|
|
1058
|
+
}
|
|
1041
1059
|
const relationResponse = await fetch(
|
|
1042
1060
|
`${this.baseURL}/tenants/${this.tenantId}/projects/${this.projectId}/agent-tool-relations`,
|
|
1043
1061
|
{
|
|
@@ -1225,20 +1243,17 @@ var AgentGraph = class {
|
|
|
1225
1243
|
const delegates = internalAgent.getDelegates();
|
|
1226
1244
|
const tools = [];
|
|
1227
1245
|
const selectedToolsMapping = {};
|
|
1246
|
+
const headersMapping = {};
|
|
1228
1247
|
const agentTools = internalAgent.getTools();
|
|
1229
1248
|
for (const [_toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
toolId = toolInstance.
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
"Selected tools"
|
|
1237
|
-
);
|
|
1238
|
-
selectedToolsMapping[toolId] = toolInstance.selectedTools;
|
|
1239
|
-
}
|
|
1240
|
-
tools.push(toolId);
|
|
1249
|
+
const toolId = toolInstance.getId();
|
|
1250
|
+
if (toolInstance.selectedTools) {
|
|
1251
|
+
selectedToolsMapping[toolId] = toolInstance.selectedTools;
|
|
1252
|
+
}
|
|
1253
|
+
if (toolInstance.headers) {
|
|
1254
|
+
headersMapping[toolId] = toolInstance.headers;
|
|
1241
1255
|
}
|
|
1256
|
+
tools.push(toolId);
|
|
1242
1257
|
}
|
|
1243
1258
|
const dataComponents = [];
|
|
1244
1259
|
const agentDataComponents = internalAgent.getDataComponents();
|
|
@@ -1258,7 +1273,8 @@ var AgentGraph = class {
|
|
|
1258
1273
|
}
|
|
1259
1274
|
const canUse = tools.map((toolId) => ({
|
|
1260
1275
|
toolId,
|
|
1261
|
-
toolSelection: selectedToolsMapping[toolId] || null
|
|
1276
|
+
toolSelection: selectedToolsMapping[toolId] || null,
|
|
1277
|
+
headers: headersMapping[toolId] || null
|
|
1262
1278
|
}));
|
|
1263
1279
|
agentsObject[internalAgent.getId()] = {
|
|
1264
1280
|
id: internalAgent.getId(),
|
|
@@ -3114,7 +3130,8 @@ function dataComponent(config) {
|
|
|
3114
3130
|
function agentMcp(config) {
|
|
3115
3131
|
return {
|
|
3116
3132
|
server: config.server,
|
|
3117
|
-
selectedTools: config.selectedTools
|
|
3133
|
+
selectedTools: config.selectedTools,
|
|
3134
|
+
headers: config.headers
|
|
3118
3135
|
};
|
|
3119
3136
|
}
|
|
3120
3137
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Agents SDK for building and managing agents in the Inkeep Agent Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"nanoid": "^5.1.5",
|
|
10
10
|
"zod": "^4.1.5",
|
|
11
|
-
"@inkeep/agents-core": "^0.
|
|
11
|
+
"@inkeep/agents-core": "^0.8.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/node": "^20.11.24",
|