@inkeep/agents-sdk 0.0.0-dev-20250911175803 → 0.0.0-dev-20250911195722
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 +252 -256
- package/dist/index.d.cts +249 -293
- package/dist/index.d.ts +249 -293
- package/dist/index.js +346 -188
- package/package.json +2 -2
- package/dist/chunk-BCJFVUMJ.js +0 -145
- package/dist/tool-6K5MVNKA.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -4,165 +4,8 @@ var agentsCore = require('@inkeep/agents-core');
|
|
|
4
4
|
var zod = require('zod');
|
|
5
5
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __esm = (fn, res) => function __init() {
|
|
10
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
-
};
|
|
12
|
-
var __export = (target, all) => {
|
|
13
|
-
for (var name in all)
|
|
14
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
-
};
|
|
16
8
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
17
|
-
|
|
18
|
-
// src/tool.ts
|
|
19
|
-
var tool_exports = {};
|
|
20
|
-
__export(tool_exports, {
|
|
21
|
-
Tool: () => exports.Tool
|
|
22
|
-
});
|
|
23
|
-
var logger3; exports.Tool = void 0;
|
|
24
|
-
var init_tool = __esm({
|
|
25
|
-
"src/tool.ts"() {
|
|
26
|
-
logger3 = agentsCore.getLogger("tool");
|
|
27
|
-
exports.Tool = class {
|
|
28
|
-
constructor(config) {
|
|
29
|
-
__publicField(this, "config");
|
|
30
|
-
__publicField(this, "baseURL");
|
|
31
|
-
__publicField(this, "tenantId");
|
|
32
|
-
__publicField(this, "initialized", false);
|
|
33
|
-
__publicField(this, "projectId");
|
|
34
|
-
this.config = config;
|
|
35
|
-
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
36
|
-
this.tenantId = config.tenantId || "default";
|
|
37
|
-
this.projectId = config.projectId || "default";
|
|
38
|
-
logger3.info(
|
|
39
|
-
{
|
|
40
|
-
Id: this.getId(),
|
|
41
|
-
Name: config.name
|
|
42
|
-
},
|
|
43
|
-
"Tool constructor initialized"
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
// Compute ID from name using same slug transformation as agents
|
|
47
|
-
getId() {
|
|
48
|
-
return this.config.id;
|
|
49
|
-
}
|
|
50
|
-
getName() {
|
|
51
|
-
return this.config.name;
|
|
52
|
-
}
|
|
53
|
-
getDescription() {
|
|
54
|
-
return this.config.description || "";
|
|
55
|
-
}
|
|
56
|
-
getServerUrl() {
|
|
57
|
-
return this.config.serverUrl;
|
|
58
|
-
}
|
|
59
|
-
getActiveTools() {
|
|
60
|
-
return this.config.activeTools;
|
|
61
|
-
}
|
|
62
|
-
getCredentialReferenceId() {
|
|
63
|
-
return this.config.credential?.id;
|
|
64
|
-
}
|
|
65
|
-
// Public method to ensure tool exists in backend (with upsert behavior)
|
|
66
|
-
async init(options) {
|
|
67
|
-
if (this.initialized) return;
|
|
68
|
-
try {
|
|
69
|
-
if (!options?.skipDatabaseRegistration) {
|
|
70
|
-
await this.upsertTool();
|
|
71
|
-
}
|
|
72
|
-
logger3.info(
|
|
73
|
-
{
|
|
74
|
-
toolId: this.getId()
|
|
75
|
-
},
|
|
76
|
-
"Tool initialized successfully"
|
|
77
|
-
);
|
|
78
|
-
this.initialized = true;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
logger3.error(
|
|
81
|
-
{
|
|
82
|
-
toolId: this.getId(),
|
|
83
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
84
|
-
},
|
|
85
|
-
"Failed to initialize tool"
|
|
86
|
-
);
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Private method to upsert tool (create or update)
|
|
91
|
-
async upsertTool() {
|
|
92
|
-
const toolDataForUpdate = {
|
|
93
|
-
id: this.getId(),
|
|
94
|
-
name: this.config.name,
|
|
95
|
-
credentialReferenceId: this.config.credential?.id ?? null,
|
|
96
|
-
headers: this.config.headers ?? null,
|
|
97
|
-
imageUrl: this.config.imageUrl,
|
|
98
|
-
config: {
|
|
99
|
-
type: "mcp",
|
|
100
|
-
mcp: {
|
|
101
|
-
server: {
|
|
102
|
-
url: this.config.serverUrl
|
|
103
|
-
},
|
|
104
|
-
transport: this.config.transport,
|
|
105
|
-
activeTools: this.config.activeTools
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const toolDataForCreate = {
|
|
110
|
-
...toolDataForUpdate
|
|
111
|
-
};
|
|
112
|
-
logger3.info({ toolDataForCreate }, "toolDataForCreate");
|
|
113
|
-
const updateResponse = await fetch(
|
|
114
|
-
`${this.baseURL}/tenants/${this.tenantId}/crud/projects/${this.projectId}/tools/${this.getId()}`,
|
|
115
|
-
{
|
|
116
|
-
method: "PUT",
|
|
117
|
-
headers: {
|
|
118
|
-
"Content-Type": "application/json"
|
|
119
|
-
},
|
|
120
|
-
body: JSON.stringify(toolDataForUpdate)
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
logger3.info({ updateResponse }, "tool updateResponse");
|
|
124
|
-
if (updateResponse.ok) {
|
|
125
|
-
logger3.info(
|
|
126
|
-
{
|
|
127
|
-
toolId: this.getId()
|
|
128
|
-
},
|
|
129
|
-
"Tool updated successfully"
|
|
130
|
-
);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (updateResponse.status === 404) {
|
|
134
|
-
logger3.info(
|
|
135
|
-
{
|
|
136
|
-
toolId: this.getId()
|
|
137
|
-
},
|
|
138
|
-
"Tool not found, creating new tool"
|
|
139
|
-
);
|
|
140
|
-
const createResponse = await fetch(
|
|
141
|
-
`${this.baseURL}/tenants/${this.tenantId}/crud/projects/${this.projectId}/tools`,
|
|
142
|
-
{
|
|
143
|
-
method: "POST",
|
|
144
|
-
headers: {
|
|
145
|
-
"Content-Type": "application/json"
|
|
146
|
-
},
|
|
147
|
-
body: JSON.stringify(toolDataForCreate)
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
if (!createResponse.ok) {
|
|
151
|
-
throw new Error(`Failed to create tool: ${createResponse.status}`);
|
|
152
|
-
}
|
|
153
|
-
logger3.info(
|
|
154
|
-
{
|
|
155
|
-
toolId: this.getId()
|
|
156
|
-
},
|
|
157
|
-
"Tool created successfully"
|
|
158
|
-
);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
throw new Error(`Failed to update tool: ${updateResponse.status}`);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
9
|
var logger = agentsCore.getLogger("artifactComponent");
|
|
167
10
|
var ArtifactComponent = class {
|
|
168
11
|
constructor(config) {
|
|
@@ -440,6 +283,144 @@ var DataComponent = class {
|
|
|
440
283
|
);
|
|
441
284
|
}
|
|
442
285
|
};
|
|
286
|
+
var logger3 = agentsCore.getLogger("tool");
|
|
287
|
+
var Tool = class {
|
|
288
|
+
constructor(config) {
|
|
289
|
+
__publicField(this, "config");
|
|
290
|
+
__publicField(this, "baseURL");
|
|
291
|
+
__publicField(this, "tenantId");
|
|
292
|
+
__publicField(this, "initialized", false);
|
|
293
|
+
__publicField(this, "projectId");
|
|
294
|
+
this.config = config;
|
|
295
|
+
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
296
|
+
this.tenantId = config.tenantId || "default";
|
|
297
|
+
this.projectId = config.projectId || "default";
|
|
298
|
+
logger3.info(
|
|
299
|
+
{
|
|
300
|
+
Id: this.getId(),
|
|
301
|
+
Name: config.name
|
|
302
|
+
},
|
|
303
|
+
"Tool constructor initialized"
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
// Compute ID from name using same slug transformation as agents
|
|
307
|
+
getId() {
|
|
308
|
+
return this.config.id;
|
|
309
|
+
}
|
|
310
|
+
getName() {
|
|
311
|
+
return this.config.name;
|
|
312
|
+
}
|
|
313
|
+
getDescription() {
|
|
314
|
+
return this.config.description || "";
|
|
315
|
+
}
|
|
316
|
+
getServerUrl() {
|
|
317
|
+
return this.config.serverUrl;
|
|
318
|
+
}
|
|
319
|
+
getActiveTools() {
|
|
320
|
+
return this.config.activeTools;
|
|
321
|
+
}
|
|
322
|
+
getCredentialReferenceId() {
|
|
323
|
+
return this.config.credential?.id;
|
|
324
|
+
}
|
|
325
|
+
// Public method to ensure tool exists in backend (with upsert behavior)
|
|
326
|
+
async init(options) {
|
|
327
|
+
if (this.initialized) return;
|
|
328
|
+
try {
|
|
329
|
+
if (!options?.skipDatabaseRegistration) {
|
|
330
|
+
await this.upsertTool();
|
|
331
|
+
}
|
|
332
|
+
logger3.info(
|
|
333
|
+
{
|
|
334
|
+
toolId: this.getId()
|
|
335
|
+
},
|
|
336
|
+
"Tool initialized successfully"
|
|
337
|
+
);
|
|
338
|
+
this.initialized = true;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
logger3.error(
|
|
341
|
+
{
|
|
342
|
+
toolId: this.getId(),
|
|
343
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
344
|
+
},
|
|
345
|
+
"Failed to initialize tool"
|
|
346
|
+
);
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
// Private method to upsert tool (create or update)
|
|
351
|
+
async upsertTool() {
|
|
352
|
+
const toolDataForUpdate = {
|
|
353
|
+
id: this.getId(),
|
|
354
|
+
name: this.config.name,
|
|
355
|
+
credentialReferenceId: this.config.credential?.id ?? null,
|
|
356
|
+
headers: this.config.headers ?? null,
|
|
357
|
+
imageUrl: this.config.imageUrl,
|
|
358
|
+
config: {
|
|
359
|
+
type: "mcp",
|
|
360
|
+
mcp: {
|
|
361
|
+
server: {
|
|
362
|
+
url: this.config.serverUrl
|
|
363
|
+
},
|
|
364
|
+
transport: this.config.transport,
|
|
365
|
+
activeTools: this.config.activeTools
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
const toolDataForCreate = {
|
|
370
|
+
...toolDataForUpdate
|
|
371
|
+
};
|
|
372
|
+
logger3.info({ toolDataForCreate }, "toolDataForCreate");
|
|
373
|
+
const updateResponse = await fetch(
|
|
374
|
+
`${this.baseURL}/tenants/${this.tenantId}/crud/projects/${this.projectId}/tools/${this.getId()}`,
|
|
375
|
+
{
|
|
376
|
+
method: "PUT",
|
|
377
|
+
headers: {
|
|
378
|
+
"Content-Type": "application/json"
|
|
379
|
+
},
|
|
380
|
+
body: JSON.stringify(toolDataForUpdate)
|
|
381
|
+
}
|
|
382
|
+
);
|
|
383
|
+
logger3.info({ updateResponse }, "tool updateResponse");
|
|
384
|
+
if (updateResponse.ok) {
|
|
385
|
+
logger3.info(
|
|
386
|
+
{
|
|
387
|
+
toolId: this.getId()
|
|
388
|
+
},
|
|
389
|
+
"Tool updated successfully"
|
|
390
|
+
);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (updateResponse.status === 404) {
|
|
394
|
+
logger3.info(
|
|
395
|
+
{
|
|
396
|
+
toolId: this.getId()
|
|
397
|
+
},
|
|
398
|
+
"Tool not found, creating new tool"
|
|
399
|
+
);
|
|
400
|
+
const createResponse = await fetch(
|
|
401
|
+
`${this.baseURL}/tenants/${this.tenantId}/crud/projects/${this.projectId}/tools`,
|
|
402
|
+
{
|
|
403
|
+
method: "POST",
|
|
404
|
+
headers: {
|
|
405
|
+
"Content-Type": "application/json"
|
|
406
|
+
},
|
|
407
|
+
body: JSON.stringify(toolDataForCreate)
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
if (!createResponse.ok) {
|
|
411
|
+
throw new Error(`Failed to create tool: ${createResponse.status}`);
|
|
412
|
+
}
|
|
413
|
+
logger3.info(
|
|
414
|
+
{
|
|
415
|
+
toolId: this.getId()
|
|
416
|
+
},
|
|
417
|
+
"Tool created successfully"
|
|
418
|
+
);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
throw new Error(`Failed to update tool: ${updateResponse.status}`);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
443
424
|
|
|
444
425
|
// src/agent.ts
|
|
445
426
|
var logger4 = agentsCore.getLogger("agent");
|
|
@@ -481,8 +462,9 @@ var Agent = class {
|
|
|
481
462
|
getInstructions() {
|
|
482
463
|
return this.config.prompt;
|
|
483
464
|
}
|
|
465
|
+
// adjust
|
|
484
466
|
getTools() {
|
|
485
|
-
const tools = resolveGetter(this.config.
|
|
467
|
+
const tools = resolveGetter(this.config.canUse);
|
|
486
468
|
if (!tools) {
|
|
487
469
|
return {};
|
|
488
470
|
}
|
|
@@ -492,9 +474,19 @@ var Agent = class {
|
|
|
492
474
|
const toolRecord = {};
|
|
493
475
|
for (const tool of tools) {
|
|
494
476
|
if (tool && typeof tool === "object") {
|
|
495
|
-
|
|
477
|
+
let id;
|
|
478
|
+
let toolInstance;
|
|
479
|
+
if ("server" in tool && "selectedTools" in tool) {
|
|
480
|
+
const agentMcpConfig = tool;
|
|
481
|
+
id = agentMcpConfig.server.getId();
|
|
482
|
+
toolInstance = agentMcpConfig.server;
|
|
483
|
+
toolInstance.selectedTools = agentMcpConfig.selectedTools;
|
|
484
|
+
} else {
|
|
485
|
+
id = tool.id || tool.getId?.() || tool.name;
|
|
486
|
+
toolInstance = tool;
|
|
487
|
+
}
|
|
496
488
|
if (id) {
|
|
497
|
-
toolRecord[id] =
|
|
489
|
+
toolRecord[id] = toolInstance;
|
|
498
490
|
}
|
|
499
491
|
}
|
|
500
492
|
}
|
|
@@ -518,9 +510,10 @@ var Agent = class {
|
|
|
518
510
|
getArtifactComponents() {
|
|
519
511
|
return resolveGetter(this.config.artifactComponents) || [];
|
|
520
512
|
}
|
|
513
|
+
// adjust
|
|
521
514
|
addTool(_name, tool) {
|
|
522
|
-
const existingTools = this.config.
|
|
523
|
-
this.config.
|
|
515
|
+
const existingTools = this.config.canUse ? this.config.canUse() : [];
|
|
516
|
+
this.config.canUse = () => [...existingTools, tool];
|
|
524
517
|
}
|
|
525
518
|
addTransfer(...agents) {
|
|
526
519
|
if (typeof this.config.canTransferTo === "function") {
|
|
@@ -633,18 +626,32 @@ var Agent = class {
|
|
|
633
626
|
);
|
|
634
627
|
}
|
|
635
628
|
async saveToolsAndRelations() {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
629
|
+
if (this.config.canUse) {
|
|
630
|
+
const tools = resolveGetter(this.config.canUse);
|
|
631
|
+
if (tools && Array.isArray(tools)) {
|
|
632
|
+
for (let i = 0; i < tools.length; i++) {
|
|
633
|
+
const toolConfig = tools[i];
|
|
634
|
+
let toolId;
|
|
635
|
+
if (toolConfig instanceof Tool) {
|
|
636
|
+
toolId = toolConfig.getId();
|
|
637
|
+
} else if (toolConfig && typeof toolConfig === "object" && "server" in toolConfig) {
|
|
638
|
+
toolId = toolConfig.server.getId();
|
|
639
|
+
} else {
|
|
640
|
+
toolId = `tool-${i}`;
|
|
641
|
+
}
|
|
642
|
+
try {
|
|
643
|
+
await this.createTool(toolId, toolConfig);
|
|
644
|
+
} catch (error) {
|
|
645
|
+
logger4.error(
|
|
646
|
+
{
|
|
647
|
+
toolId,
|
|
648
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
649
|
+
},
|
|
650
|
+
"Tool creation failed"
|
|
651
|
+
);
|
|
652
|
+
throw error;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
648
655
|
}
|
|
649
656
|
}
|
|
650
657
|
}
|
|
@@ -767,36 +774,24 @@ var Agent = class {
|
|
|
767
774
|
logger4.info(
|
|
768
775
|
{
|
|
769
776
|
agentId: this.getId(),
|
|
770
|
-
toolId
|
|
771
|
-
toolType: "function"
|
|
777
|
+
toolId
|
|
772
778
|
},
|
|
773
779
|
"Skipping function tool creation - will be handled at runtime"
|
|
774
780
|
);
|
|
775
781
|
return;
|
|
776
782
|
}
|
|
777
|
-
const { Tool: Tool2 } = await Promise.resolve().then(() => (init_tool(), tool_exports));
|
|
778
783
|
let tool;
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
"Initializing Tool instance"
|
|
787
|
-
);
|
|
784
|
+
let selectedTools;
|
|
785
|
+
if (toolConfig && typeof toolConfig === "object" && "server" in toolConfig && "selectedTools" in toolConfig) {
|
|
786
|
+
const mcpConfig = toolConfig;
|
|
787
|
+
tool = mcpConfig.server;
|
|
788
|
+
selectedTools = mcpConfig.selectedTools;
|
|
789
|
+
await tool.init();
|
|
790
|
+
} else if (toolConfig instanceof Tool) {
|
|
788
791
|
tool = toolConfig;
|
|
789
792
|
await tool.init();
|
|
790
793
|
} else {
|
|
791
|
-
|
|
792
|
-
{
|
|
793
|
-
agentId: this.getId(),
|
|
794
|
-
toolId,
|
|
795
|
-
toolType: "legacy-config"
|
|
796
|
-
},
|
|
797
|
-
"Creating Tool from config"
|
|
798
|
-
);
|
|
799
|
-
tool = new Tool2({
|
|
794
|
+
tool = new Tool({
|
|
800
795
|
id: toolId,
|
|
801
796
|
tenantId: this.tenantId,
|
|
802
797
|
name: toolConfig.name || toolId,
|
|
@@ -807,7 +802,7 @@ var Agent = class {
|
|
|
807
802
|
});
|
|
808
803
|
await tool.init();
|
|
809
804
|
}
|
|
810
|
-
await this.createAgentToolRelation(tool.getId());
|
|
805
|
+
await this.createAgentToolRelation(tool.getId(), selectedTools);
|
|
811
806
|
logger4.info(
|
|
812
807
|
{
|
|
813
808
|
agentId: this.getId(),
|
|
@@ -824,6 +819,7 @@ var Agent = class {
|
|
|
824
819
|
},
|
|
825
820
|
"Failed to create tool"
|
|
826
821
|
);
|
|
822
|
+
throw error;
|
|
827
823
|
}
|
|
828
824
|
}
|
|
829
825
|
async createDataComponent(dataComponent2) {
|
|
@@ -945,20 +941,25 @@ var Agent = class {
|
|
|
945
941
|
"Created agent-artifactComponent relation"
|
|
946
942
|
);
|
|
947
943
|
}
|
|
948
|
-
async createAgentToolRelation(toolId) {
|
|
944
|
+
async createAgentToolRelation(toolId, selectedTools) {
|
|
945
|
+
const relationData = {
|
|
946
|
+
id: `${this.getId()}-tool-${toolId}`,
|
|
947
|
+
tenantId: this.tenantId,
|
|
948
|
+
projectId: this.projectId,
|
|
949
|
+
agentId: this.getId(),
|
|
950
|
+
toolId
|
|
951
|
+
};
|
|
952
|
+
if (selectedTools !== void 0) {
|
|
953
|
+
relationData.selectedTools = selectedTools;
|
|
954
|
+
}
|
|
949
955
|
const relationResponse = await fetch(
|
|
950
|
-
`${this.baseURL}/tenants/${this.tenantId}/crud/agent-tool-relations`,
|
|
956
|
+
`${this.baseURL}/tenants/${this.tenantId}/crud/projects/${this.projectId}/agent-tool-relations`,
|
|
951
957
|
{
|
|
952
958
|
method: "POST",
|
|
953
959
|
headers: {
|
|
954
960
|
"Content-Type": "application/json"
|
|
955
961
|
},
|
|
956
|
-
body: JSON.stringify(
|
|
957
|
-
id: `${this.getId()}-tool-${toolId}`,
|
|
958
|
-
tenantId: this.tenantId,
|
|
959
|
-
agentId: this.getId(),
|
|
960
|
-
toolId
|
|
961
|
-
})
|
|
962
|
+
body: JSON.stringify(relationData)
|
|
962
963
|
}
|
|
963
964
|
);
|
|
964
965
|
if (!relationResponse.ok) {
|
|
@@ -969,14 +970,10 @@ var Agent = class {
|
|
|
969
970
|
}
|
|
970
971
|
}
|
|
971
972
|
};
|
|
972
|
-
init_tool();
|
|
973
973
|
var TransferConfigSchema = zod.z.object({
|
|
974
974
|
agent: zod.z.instanceof(Agent),
|
|
975
975
|
description: zod.z.string().optional()
|
|
976
976
|
});
|
|
977
|
-
function generateIdFromName3(name) {
|
|
978
|
-
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
979
|
-
}
|
|
980
977
|
function validateFunction(value, name) {
|
|
981
978
|
if (typeof value !== "function") {
|
|
982
979
|
throw new Error(`${name} must be a function`);
|
|
@@ -990,27 +987,9 @@ function agent(config) {
|
|
|
990
987
|
}
|
|
991
988
|
return new Agent(config);
|
|
992
989
|
}
|
|
993
|
-
function mcpServer(config) {
|
|
994
|
-
if (!config.serverUrl) {
|
|
995
|
-
throw new Error("MCP server requires a serverUrl");
|
|
996
|
-
}
|
|
997
|
-
const id = config.id || generateIdFromName3(config.name);
|
|
998
|
-
return new exports.Tool({
|
|
999
|
-
id,
|
|
1000
|
-
name: config.name,
|
|
1001
|
-
description: config.description,
|
|
1002
|
-
serverUrl: config.serverUrl,
|
|
1003
|
-
tenantId: config.tenantId,
|
|
1004
|
-
credential: config.credential,
|
|
1005
|
-
activeTools: config.activeTools,
|
|
1006
|
-
headers: config.headers,
|
|
1007
|
-
imageUrl: config.imageUrl,
|
|
1008
|
-
transport: config.transport ? { type: config.transport } : void 0
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
990
|
function mcpTool(config) {
|
|
1012
991
|
const validatedConfig = agentsCore.MCPToolConfigSchema.parse(config);
|
|
1013
|
-
return new
|
|
992
|
+
return new Tool(validatedConfig);
|
|
1014
993
|
}
|
|
1015
994
|
function credential(config) {
|
|
1016
995
|
return agentsCore.CredentialReferenceApiInsertSchema.parse(config);
|
|
@@ -1398,10 +1377,20 @@ var AgentGraph = class {
|
|
|
1398
1377
|
const transfers = internalAgent.getTransfers();
|
|
1399
1378
|
const delegates = internalAgent.getDelegates();
|
|
1400
1379
|
const tools = [];
|
|
1380
|
+
const selectedToolsMapping = {};
|
|
1401
1381
|
const agentTools = internalAgent.getTools();
|
|
1402
1382
|
for (const [toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1403
1383
|
if (toolInstance && typeof toolInstance === "object") {
|
|
1404
|
-
|
|
1384
|
+
let toolId;
|
|
1385
|
+
if ("server" in toolInstance && "selectedTools" in toolInstance) {
|
|
1386
|
+
const mcpConfig = toolInstance;
|
|
1387
|
+
toolId = mcpConfig.server.getId();
|
|
1388
|
+
if (mcpConfig.selectedTools !== void 0) {
|
|
1389
|
+
selectedToolsMapping[toolId] = mcpConfig.selectedTools;
|
|
1390
|
+
}
|
|
1391
|
+
} else {
|
|
1392
|
+
toolId = toolInstance.getId?.() || toolInstance.id || toolName;
|
|
1393
|
+
}
|
|
1405
1394
|
tools.push(toolId);
|
|
1406
1395
|
}
|
|
1407
1396
|
}
|
|
@@ -1430,6 +1419,7 @@ var AgentGraph = class {
|
|
|
1430
1419
|
canTransferTo: transfers.map((h) => h.getId()),
|
|
1431
1420
|
canDelegateTo: delegates.map((d) => d.getId()),
|
|
1432
1421
|
tools,
|
|
1422
|
+
selectedTools: Object.keys(selectedToolsMapping).length > 0 ? selectedToolsMapping : void 0,
|
|
1433
1423
|
dataComponents: dataComponents.length > 0 ? dataComponents : void 0,
|
|
1434
1424
|
artifactComponents: artifactComponents.length > 0 ? artifactComponents : void 0,
|
|
1435
1425
|
type: "internal"
|
|
@@ -1458,55 +1448,64 @@ var AgentGraph = class {
|
|
|
1458
1448
|
const agentTools = internalAgent.getTools();
|
|
1459
1449
|
for (const [toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1460
1450
|
if (toolInstance && typeof toolInstance === "object") {
|
|
1461
|
-
|
|
1451
|
+
let actualTool;
|
|
1452
|
+
let toolId;
|
|
1453
|
+
if ("server" in toolInstance && "selectedTools" in toolInstance) {
|
|
1454
|
+
const mcpConfig = toolInstance;
|
|
1455
|
+
actualTool = mcpConfig.server;
|
|
1456
|
+
toolId = actualTool.getId();
|
|
1457
|
+
} else {
|
|
1458
|
+
actualTool = toolInstance;
|
|
1459
|
+
toolId = actualTool.getId?.() || actualTool.id || toolName;
|
|
1460
|
+
}
|
|
1462
1461
|
if (!toolsObject[toolId]) {
|
|
1463
1462
|
let toolConfig;
|
|
1464
|
-
if (
|
|
1463
|
+
if (actualTool.config?.serverUrl) {
|
|
1465
1464
|
toolConfig = {
|
|
1466
1465
|
type: "mcp",
|
|
1467
1466
|
mcp: {
|
|
1468
1467
|
server: {
|
|
1469
|
-
url:
|
|
1468
|
+
url: actualTool.config.serverUrl
|
|
1470
1469
|
}
|
|
1471
1470
|
}
|
|
1472
1471
|
};
|
|
1473
|
-
} else if (
|
|
1474
|
-
toolConfig =
|
|
1472
|
+
} else if (actualTool.config?.type === "mcp") {
|
|
1473
|
+
toolConfig = actualTool.config;
|
|
1475
1474
|
} else {
|
|
1476
1475
|
toolConfig = {
|
|
1477
1476
|
type: "function",
|
|
1478
|
-
parameters:
|
|
1477
|
+
parameters: actualTool.parameters || {}
|
|
1479
1478
|
};
|
|
1480
1479
|
}
|
|
1481
1480
|
const toolData = {
|
|
1482
1481
|
id: toolId,
|
|
1483
|
-
name:
|
|
1482
|
+
name: actualTool.config?.name || actualTool.name || toolName,
|
|
1484
1483
|
config: toolConfig,
|
|
1485
|
-
status:
|
|
1484
|
+
status: actualTool.getStatus?.() || actualTool.status || "unknown"
|
|
1486
1485
|
};
|
|
1487
|
-
if (
|
|
1488
|
-
toolData.imageUrl =
|
|
1486
|
+
if (actualTool.config?.imageUrl) {
|
|
1487
|
+
toolData.imageUrl = actualTool.config.imageUrl;
|
|
1489
1488
|
}
|
|
1490
|
-
if (
|
|
1491
|
-
toolData.headers =
|
|
1489
|
+
if (actualTool.config?.headers) {
|
|
1490
|
+
toolData.headers = actualTool.config.headers;
|
|
1492
1491
|
}
|
|
1493
|
-
if (
|
|
1494
|
-
toolData.capabilities =
|
|
1492
|
+
if (actualTool.capabilities) {
|
|
1493
|
+
toolData.capabilities = actualTool.capabilities;
|
|
1495
1494
|
}
|
|
1496
|
-
if (
|
|
1497
|
-
toolData.lastHealthCheck =
|
|
1495
|
+
if (actualTool.lastHealthCheck) {
|
|
1496
|
+
toolData.lastHealthCheck = actualTool.lastHealthCheck;
|
|
1498
1497
|
}
|
|
1499
|
-
if (
|
|
1500
|
-
toolData.availableTools =
|
|
1498
|
+
if (actualTool.availableTools) {
|
|
1499
|
+
toolData.availableTools = actualTool.availableTools;
|
|
1501
1500
|
}
|
|
1502
|
-
if (
|
|
1503
|
-
toolData.lastError =
|
|
1501
|
+
if (actualTool.lastError) {
|
|
1502
|
+
toolData.lastError = actualTool.lastError;
|
|
1504
1503
|
}
|
|
1505
|
-
if (
|
|
1506
|
-
toolData.lastToolsSync =
|
|
1504
|
+
if (actualTool.lastToolsSync) {
|
|
1505
|
+
toolData.lastToolsSync = actualTool.lastToolsSync;
|
|
1507
1506
|
}
|
|
1508
|
-
if (
|
|
1509
|
-
toolData.credentialReferenceId =
|
|
1507
|
+
if (actualTool.getCredentialReferenceId?.()) {
|
|
1508
|
+
toolData.credentialReferenceId = actualTool.getCredentialReferenceId();
|
|
1510
1509
|
}
|
|
1511
1510
|
toolsObject[toolId] = toolData;
|
|
1512
1511
|
}
|
|
@@ -2828,15 +2827,13 @@ var run = Runner.run.bind(Runner);
|
|
|
2828
2827
|
var stream = Runner.stream.bind(Runner);
|
|
2829
2828
|
var raceGraphs = Runner.raceGraphs.bind(Runner);
|
|
2830
2829
|
|
|
2831
|
-
// src/index.ts
|
|
2832
|
-
init_tool();
|
|
2833
|
-
|
|
2834
2830
|
exports.Agent = Agent;
|
|
2835
2831
|
exports.AgentGraph = AgentGraph;
|
|
2836
2832
|
exports.ArtifactComponent = ArtifactComponent;
|
|
2837
2833
|
exports.DataComponent = DataComponent;
|
|
2838
2834
|
exports.ExternalAgent = ExternalAgent;
|
|
2839
2835
|
exports.Runner = Runner;
|
|
2836
|
+
exports.Tool = Tool;
|
|
2840
2837
|
exports.agent = agent;
|
|
2841
2838
|
exports.agentGraph = agentGraph;
|
|
2842
2839
|
exports.artifactComponent = artifactComponent;
|
|
@@ -2846,7 +2843,6 @@ exports.dataComponent = dataComponent;
|
|
|
2846
2843
|
exports.externalAgent = externalAgent;
|
|
2847
2844
|
exports.externalAgents = externalAgents;
|
|
2848
2845
|
exports.generateGraph = generateGraph;
|
|
2849
|
-
exports.mcpServer = mcpServer;
|
|
2850
2846
|
exports.mcpTool = mcpTool;
|
|
2851
2847
|
exports.raceGraphs = raceGraphs;
|
|
2852
2848
|
exports.registerEnvironmentSettings = registerEnvironmentSettings;
|