@inkeep/agents-sdk 0.39.5 → 0.41.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/_virtual/rolldown_runtime.js +7 -0
- package/dist/agent.d.ts +186 -0
- package/dist/agent.js +720 -0
- package/dist/agentFullClient.d.ts +22 -0
- package/dist/agentFullClient.js +120 -0
- package/dist/artifact-component.d.ts +34 -0
- package/dist/artifact-component.js +104 -0
- package/dist/builderFunctions.d.ts +283 -0
- package/dist/builderFunctions.js +327 -0
- package/dist/builderFunctionsExperimental.d.ts +24 -0
- package/dist/builderFunctionsExperimental.js +27 -0
- package/dist/builders.d.ts +111 -0
- package/dist/builders.js +52 -0
- package/dist/credential-provider.d.ts +176 -0
- package/dist/credential-provider.js +237 -0
- package/dist/credential-ref.d.ts +60 -0
- package/dist/credential-ref.js +33 -0
- package/dist/data-component.d.ts +39 -0
- package/dist/data-component.js +109 -0
- package/dist/environment-settings.d.ts +27 -0
- package/dist/environment-settings.js +41 -0
- package/dist/external-agent.d.ts +64 -0
- package/dist/external-agent.js +156 -0
- package/dist/function-tool.d.ts +37 -0
- package/dist/function-tool.js +66 -0
- package/dist/index.d.ts +19 -1825
- package/dist/index.js +19 -4058
- package/dist/module-hosted-tool-manager.d.ts +40 -0
- package/dist/module-hosted-tool-manager.js +359 -0
- package/dist/project.d.ts +214 -0
- package/dist/project.js +615 -0
- package/dist/projectFullClient.d.ts +23 -0
- package/dist/projectFullClient.js +162 -0
- package/dist/runner.d.ts +41 -0
- package/dist/runner.js +145 -0
- package/dist/status-component.d.ts +22 -0
- package/dist/status-component.js +36 -0
- package/dist/subAgent.d.ts +52 -0
- package/dist/subAgent.js +616 -0
- package/dist/telemetry-provider.d.ts +218 -0
- package/dist/telemetry-provider.js +390 -0
- package/dist/tool.d.ts +53 -0
- package/dist/tool.js +130 -0
- package/dist/types.d.ts +296 -0
- package/dist/types.js +39 -0
- package/dist/utils/generateIdFromName.d.ts +9 -0
- package/dist/utils/generateIdFromName.js +12 -0
- package/dist/utils/getFunctionToolDeps.d.ts +17 -0
- package/dist/utils/getFunctionToolDeps.js +131 -0
- package/dist/utils/tool-normalization.d.ts +42 -0
- package/dist/utils/tool-normalization.js +41 -0
- package/dist/utils/validateFunction.d.ts +10 -0
- package/dist/utils/validateFunction.js +13 -0
- package/package.json +11 -16
- package/dist/index.cjs +0 -4147
- package/dist/index.d.cts +0 -1825
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/project.js
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import { updateFullProjectViaAPI } from "./projectFullClient.js";
|
|
2
|
+
import { FunctionTool } from "./function-tool.js";
|
|
3
|
+
import { getLogger } from "@inkeep/agents-core";
|
|
4
|
+
|
|
5
|
+
//#region src/project.ts
|
|
6
|
+
const logger = getLogger("project");
|
|
7
|
+
/**
|
|
8
|
+
* Project class for managing agent projects
|
|
9
|
+
*
|
|
10
|
+
* Projects are the top-level organizational unit that contains Agents, Sub Agents, and shared configurations.
|
|
11
|
+
* They provide model inheritance and execution limits that cascade down to Agents and Sub Agents.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const myProject = new Project({
|
|
16
|
+
* id: 'customer-support-project',
|
|
17
|
+
* name: 'Customer Support System',
|
|
18
|
+
* description: 'Multi-agent customer support system',
|
|
19
|
+
* models: {
|
|
20
|
+
* base: { model: 'gpt-4.1-mini' },
|
|
21
|
+
* structuredOutput: { model: 'gpt-4.1' }
|
|
22
|
+
* },
|
|
23
|
+
* stopWhen: {
|
|
24
|
+
* transferCountIs: 10,
|
|
25
|
+
* stepCountIs: 50
|
|
26
|
+
* }
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* await myProject.init();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var Project = class {
|
|
33
|
+
__type = "project";
|
|
34
|
+
projectId;
|
|
35
|
+
projectName;
|
|
36
|
+
projectDescription;
|
|
37
|
+
tenantId;
|
|
38
|
+
baseURL;
|
|
39
|
+
apiKey;
|
|
40
|
+
initialized = false;
|
|
41
|
+
models;
|
|
42
|
+
stopWhen;
|
|
43
|
+
agents = [];
|
|
44
|
+
agentMap = /* @__PURE__ */ new Map();
|
|
45
|
+
credentialReferences = [];
|
|
46
|
+
projectTools = [];
|
|
47
|
+
projectDataComponents = [];
|
|
48
|
+
projectArtifactComponents = [];
|
|
49
|
+
projectExternalAgents = [];
|
|
50
|
+
externalAgentMap = /* @__PURE__ */ new Map();
|
|
51
|
+
constructor(config) {
|
|
52
|
+
this.projectId = config.id;
|
|
53
|
+
this.projectName = config.name;
|
|
54
|
+
this.projectDescription = config.description;
|
|
55
|
+
this.tenantId = process.env.INKEEP_TENANT_ID || "default";
|
|
56
|
+
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
57
|
+
this.models = config.models;
|
|
58
|
+
this.stopWhen = config.stopWhen;
|
|
59
|
+
if (config.agents) {
|
|
60
|
+
this.agents = config.agents();
|
|
61
|
+
this.agentMap = new Map(this.agents.map((agent) => [agent.getId(), agent]));
|
|
62
|
+
for (const agent of this.agents) agent.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
63
|
+
}
|
|
64
|
+
if (config.tools) this.projectTools = config.tools();
|
|
65
|
+
if (config.dataComponents) this.projectDataComponents = config.dataComponents();
|
|
66
|
+
if (config.artifactComponents) this.projectArtifactComponents = config.artifactComponents();
|
|
67
|
+
if (config.credentialReferences) this.credentialReferences = config.credentialReferences();
|
|
68
|
+
if (config.externalAgents) {
|
|
69
|
+
this.projectExternalAgents = config.externalAgents();
|
|
70
|
+
this.externalAgentMap = new Map(this.projectExternalAgents.map((externalAgent) => [externalAgent.getId(), externalAgent]));
|
|
71
|
+
}
|
|
72
|
+
logger.info({
|
|
73
|
+
projectId: this.projectId,
|
|
74
|
+
tenantId: this.tenantId,
|
|
75
|
+
agentCount: this.agents.length
|
|
76
|
+
}, "Project created");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Set or update the configuration (tenantId and apiUrl)
|
|
80
|
+
* This is used by the CLI to inject configuration from inkeep.config.ts
|
|
81
|
+
*/
|
|
82
|
+
setConfig(tenantId, apiUrl, models, apiKey) {
|
|
83
|
+
if (this.initialized) throw new Error("Cannot set config after project has been initialized");
|
|
84
|
+
this.tenantId = tenantId;
|
|
85
|
+
this.baseURL = apiUrl;
|
|
86
|
+
this.apiKey = apiKey;
|
|
87
|
+
if (models) this.models = models;
|
|
88
|
+
for (const agent of this.agents) agent.setConfig(tenantId, this.projectId, apiUrl);
|
|
89
|
+
logger.info({
|
|
90
|
+
projectId: this.projectId,
|
|
91
|
+
tenantId: this.tenantId,
|
|
92
|
+
apiUrl: this.baseURL,
|
|
93
|
+
hasModels: !!this.models,
|
|
94
|
+
hasApiKey: !!this.apiKey
|
|
95
|
+
}, "Project configuration updated");
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Set credential references for the project
|
|
99
|
+
* This is used by the CLI to inject environment-specific credentials
|
|
100
|
+
*/
|
|
101
|
+
setCredentials(credentials) {
|
|
102
|
+
this.credentialReferences = Object.values(credentials);
|
|
103
|
+
logger.info({
|
|
104
|
+
projectId: this.projectId,
|
|
105
|
+
credentialCount: this.credentialReferences?.length || 0
|
|
106
|
+
}, "Project credentials updated");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Initialize the project and create/update it in the backend using full project approach
|
|
110
|
+
*/
|
|
111
|
+
async init() {
|
|
112
|
+
if (this.initialized) {
|
|
113
|
+
logger.info({ projectId: this.projectId }, "Project already initialized");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
logger.info({
|
|
117
|
+
projectId: this.projectId,
|
|
118
|
+
tenantId: this.tenantId,
|
|
119
|
+
agentCount: this.agents.length
|
|
120
|
+
}, "Initializing project using full project endpoint");
|
|
121
|
+
try {
|
|
122
|
+
const projectDefinition = await this.toFullProjectDefinition();
|
|
123
|
+
logger.info({
|
|
124
|
+
projectId: this.projectId,
|
|
125
|
+
mode: "api-client",
|
|
126
|
+
apiUrl: this.baseURL
|
|
127
|
+
}, "Using API client to create/update full project");
|
|
128
|
+
const createdProject = await updateFullProjectViaAPI(this.tenantId, this.baseURL, this.projectId, projectDefinition, this.apiKey);
|
|
129
|
+
this.initialized = true;
|
|
130
|
+
logger.info({
|
|
131
|
+
projectId: this.projectId,
|
|
132
|
+
tenantId: this.tenantId,
|
|
133
|
+
agentCount: Object.keys(createdProject.agent || {}).length
|
|
134
|
+
}, "Project initialized successfully using full project endpoint");
|
|
135
|
+
} catch (error) {
|
|
136
|
+
logger.error({
|
|
137
|
+
projectId: this.projectId,
|
|
138
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
139
|
+
}, "Failed to initialize project using full project endpoint");
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get the project ID
|
|
145
|
+
*/
|
|
146
|
+
getId() {
|
|
147
|
+
return this.projectId;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get the project name
|
|
151
|
+
*/
|
|
152
|
+
getName() {
|
|
153
|
+
return this.projectName;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get the project description
|
|
157
|
+
*/
|
|
158
|
+
getDescription() {
|
|
159
|
+
return this.projectDescription;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the tenant ID
|
|
163
|
+
*/
|
|
164
|
+
getTenantId() {
|
|
165
|
+
return this.tenantId;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get the project's model configuration
|
|
169
|
+
*/
|
|
170
|
+
getModels() {
|
|
171
|
+
return this.models;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Set the project's model configuration
|
|
175
|
+
*/
|
|
176
|
+
setModels(models) {
|
|
177
|
+
this.models = models;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get the project's stopWhen configuration
|
|
181
|
+
*/
|
|
182
|
+
getStopWhen() {
|
|
183
|
+
return this.stopWhen;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Set the project's stopWhen configuration
|
|
187
|
+
*/
|
|
188
|
+
setStopWhen(stopWhen) {
|
|
189
|
+
this.stopWhen = stopWhen;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get credential tracking information
|
|
193
|
+
*/
|
|
194
|
+
async getCredentialTracking() {
|
|
195
|
+
const credentials = (await this.toFullProjectDefinition()).credentialReferences || {};
|
|
196
|
+
const usage = {};
|
|
197
|
+
for (const [credId, credData] of Object.entries(credentials)) if (credData.usedBy) usage[credId] = credData.usedBy;
|
|
198
|
+
return {
|
|
199
|
+
credentials,
|
|
200
|
+
usage
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
async getFullDefinition() {
|
|
204
|
+
return await this.toFullProjectDefinition();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get all agent in the project
|
|
208
|
+
*/
|
|
209
|
+
getAgents() {
|
|
210
|
+
return this.agents;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get all external agents in the project
|
|
214
|
+
*/
|
|
215
|
+
getExternalAgents() {
|
|
216
|
+
return this.projectExternalAgents;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get an external agent by ID
|
|
220
|
+
*/
|
|
221
|
+
getExternalAgent(id) {
|
|
222
|
+
return this.externalAgentMap.get(id);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Add an external agent to the project
|
|
226
|
+
*/
|
|
227
|
+
addExternalAgent(externalAgent) {
|
|
228
|
+
this.projectExternalAgents.push(externalAgent);
|
|
229
|
+
this.externalAgentMap.set(externalAgent.getId(), externalAgent);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Remove an external agent from the project
|
|
233
|
+
*/
|
|
234
|
+
removeExternalAgent(id) {
|
|
235
|
+
if (this.externalAgentMap.get(id)) {
|
|
236
|
+
this.externalAgentMap.delete(id);
|
|
237
|
+
this.projectExternalAgents = this.projectExternalAgents.filter((externalAgent) => externalAgent.getId() !== id);
|
|
238
|
+
logger.info({
|
|
239
|
+
projectId: this.projectId,
|
|
240
|
+
externalAgentId: id
|
|
241
|
+
}, "External agent removed from project");
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get an agent by ID
|
|
248
|
+
*/
|
|
249
|
+
getAgent(id) {
|
|
250
|
+
return this.agentMap.get(id);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Add an agent to the project
|
|
254
|
+
*/
|
|
255
|
+
addAgent(agent) {
|
|
256
|
+
this.agents.push(agent);
|
|
257
|
+
this.agentMap.set(agent.getId(), agent);
|
|
258
|
+
agent.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
259
|
+
logger.info({
|
|
260
|
+
projectId: this.projectId,
|
|
261
|
+
agentId: agent.getId()
|
|
262
|
+
}, "Agent added to project");
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Remove an agent from the project
|
|
266
|
+
*/
|
|
267
|
+
removeAgent(id) {
|
|
268
|
+
if (this.agentMap.get(id)) {
|
|
269
|
+
this.agentMap.delete(id);
|
|
270
|
+
this.agents = this.agents.filter((agent) => agent.getId() !== id);
|
|
271
|
+
logger.info({
|
|
272
|
+
projectId: this.projectId,
|
|
273
|
+
agentId: id
|
|
274
|
+
}, "Agent removed from project");
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Get project statistics
|
|
281
|
+
*/
|
|
282
|
+
getStats() {
|
|
283
|
+
return {
|
|
284
|
+
projectId: this.projectId,
|
|
285
|
+
tenantId: this.tenantId,
|
|
286
|
+
agentCount: this.agents.length,
|
|
287
|
+
initialized: this.initialized
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Validate the project configuration
|
|
292
|
+
*/
|
|
293
|
+
validate() {
|
|
294
|
+
const errors = [];
|
|
295
|
+
if (!this.projectId) errors.push("Project must have an ID");
|
|
296
|
+
if (!this.projectName) errors.push("Project must have a name");
|
|
297
|
+
const agentIds = /* @__PURE__ */ new Set();
|
|
298
|
+
for (const agent of this.agents) {
|
|
299
|
+
const id = agent.getId();
|
|
300
|
+
if (agentIds.has(id)) errors.push(`Duplicate agent ID: ${id}`);
|
|
301
|
+
agentIds.add(id);
|
|
302
|
+
}
|
|
303
|
+
for (const agent of this.agents) {
|
|
304
|
+
const agentValidation = agent.validate();
|
|
305
|
+
if (!agentValidation.valid) errors.push(...agentValidation.errors.map((error) => `Agent '${agent.getId()}': ${error}`));
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
valid: errors.length === 0,
|
|
309
|
+
errors
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Convert the Project to FullProjectDefinition format
|
|
314
|
+
*/
|
|
315
|
+
async toFullProjectDefinition() {
|
|
316
|
+
const agentsObject = {};
|
|
317
|
+
const toolsObject = {};
|
|
318
|
+
const functionToolsObject = {};
|
|
319
|
+
const functionsObject = {};
|
|
320
|
+
const dataComponentsObject = {};
|
|
321
|
+
const artifactComponentsObject = {};
|
|
322
|
+
const credentialReferencesObject = {};
|
|
323
|
+
const externalAgentsObject = {};
|
|
324
|
+
const credentialUsageMap = {};
|
|
325
|
+
for (const agent of this.agents) {
|
|
326
|
+
logger.info({ agentId: agent.getId() }, "Agent id");
|
|
327
|
+
const agentDefinition = await agent.toFullAgentDefinition();
|
|
328
|
+
agentsObject[agent.getId()] = agentDefinition;
|
|
329
|
+
const agentCredentials = agent.credentials;
|
|
330
|
+
if (agentCredentials && Array.isArray(agentCredentials)) for (const credential of agentCredentials) {
|
|
331
|
+
if (credential?.__type === "credential-ref") continue;
|
|
332
|
+
if (credential?.id) {
|
|
333
|
+
if (!credentialReferencesObject[credential.id]) {
|
|
334
|
+
credentialReferencesObject[credential.id] = {
|
|
335
|
+
id: credential.id,
|
|
336
|
+
name: credential.name,
|
|
337
|
+
type: credential.type,
|
|
338
|
+
credentialStoreId: credential.credentialStoreId,
|
|
339
|
+
retrievalParams: credential.retrievalParams
|
|
340
|
+
};
|
|
341
|
+
credentialUsageMap[credential.id] = [];
|
|
342
|
+
}
|
|
343
|
+
credentialUsageMap[credential.id].push({
|
|
344
|
+
type: "agent",
|
|
345
|
+
id: agent.getId()
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const agentContextConfig = agent.contextConfig;
|
|
350
|
+
if (agentContextConfig) {
|
|
351
|
+
const contextVariables = agentContextConfig.getContextVariables?.() || agentContextConfig.contextVariables;
|
|
352
|
+
if (contextVariables) {
|
|
353
|
+
for (const [key, variable] of Object.entries(contextVariables)) if (variable?.credential) {
|
|
354
|
+
const credential = variable.credential;
|
|
355
|
+
let credId;
|
|
356
|
+
if (credential.__type === "credential-ref") {
|
|
357
|
+
credId = credential.id;
|
|
358
|
+
if (credId && this.credentialReferences) {
|
|
359
|
+
const resolvedCred = this.credentialReferences.find((c) => c.id === credId);
|
|
360
|
+
if (resolvedCred && !credentialReferencesObject[credId]) {
|
|
361
|
+
credentialReferencesObject[credId] = resolvedCred;
|
|
362
|
+
credentialUsageMap[credId] = [];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
} else if (credential.id) {
|
|
366
|
+
credId = credential.id;
|
|
367
|
+
if (credId && !credentialReferencesObject[credId]) {
|
|
368
|
+
credentialReferencesObject[credId] = credential;
|
|
369
|
+
credentialUsageMap[credId] = [];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (credId) {
|
|
373
|
+
if (!credentialUsageMap[credId]) credentialUsageMap[credId] = [];
|
|
374
|
+
credentialUsageMap[credId].push({
|
|
375
|
+
type: "contextVariable",
|
|
376
|
+
id: key,
|
|
377
|
+
agentId: agent.getId()
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
} else if (variable?.credentialReferenceId) {
|
|
381
|
+
const credId = variable.credentialReferenceId;
|
|
382
|
+
if (!credentialUsageMap[credId]) credentialUsageMap[credId] = [];
|
|
383
|
+
credentialUsageMap[credId].push({
|
|
384
|
+
type: "contextVariable",
|
|
385
|
+
id: key,
|
|
386
|
+
agentId: agent.getId()
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
for (const subAgent of agent.getSubAgents()) {
|
|
392
|
+
const agentTools = subAgent.getTools();
|
|
393
|
+
for (const [, toolInstance] of Object.entries(agentTools)) {
|
|
394
|
+
const actualTool = toolInstance;
|
|
395
|
+
const toolId = actualTool.getId();
|
|
396
|
+
if (actualTool.constructor.name === "FunctionTool" && actualTool instanceof FunctionTool) {
|
|
397
|
+
if (!functionsObject[toolId]) functionsObject[toolId] = actualTool.serializeFunction();
|
|
398
|
+
if (!functionToolsObject[toolId]) {
|
|
399
|
+
const toolData = actualTool.serializeTool();
|
|
400
|
+
functionToolsObject[toolId] = {
|
|
401
|
+
id: toolData.id,
|
|
402
|
+
name: toolData.name,
|
|
403
|
+
description: toolData.description,
|
|
404
|
+
functionId: toolData.functionId
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
} else if (!toolsObject[toolId]) {
|
|
408
|
+
if ("config" in actualTool && "serverUrl" in actualTool.config) {
|
|
409
|
+
const mcpTool = actualTool;
|
|
410
|
+
const toolConfig = {
|
|
411
|
+
type: "mcp",
|
|
412
|
+
mcp: {
|
|
413
|
+
server: { url: mcpTool.config.serverUrl },
|
|
414
|
+
transport: mcpTool.config.transport,
|
|
415
|
+
activeTools: mcpTool.config.activeTools
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
const toolData = {
|
|
419
|
+
id: toolId,
|
|
420
|
+
name: actualTool.getName(),
|
|
421
|
+
config: toolConfig
|
|
422
|
+
};
|
|
423
|
+
if (mcpTool.config?.imageUrl) toolData.imageUrl = mcpTool.config.imageUrl;
|
|
424
|
+
if (mcpTool.config?.headers) toolData.headers = mcpTool.config.headers;
|
|
425
|
+
if ("getCredentialReferenceId" in actualTool) {
|
|
426
|
+
const credentialId = actualTool.getCredentialReferenceId();
|
|
427
|
+
if (credentialId) toolData.credentialReferenceId = credentialId;
|
|
428
|
+
}
|
|
429
|
+
if ("credential" in mcpTool.config && mcpTool.config.credential) {
|
|
430
|
+
const credential = mcpTool.config.credential;
|
|
431
|
+
if (credential?.id && credential.__type !== "credential-ref") {
|
|
432
|
+
if (!credentialReferencesObject[credential.id]) {
|
|
433
|
+
credentialReferencesObject[credential.id] = {
|
|
434
|
+
id: credential.id,
|
|
435
|
+
name: credential.name,
|
|
436
|
+
type: credential.type,
|
|
437
|
+
credentialStoreId: credential.credentialStoreId,
|
|
438
|
+
retrievalParams: credential.retrievalParams
|
|
439
|
+
};
|
|
440
|
+
credentialUsageMap[credential.id] = [];
|
|
441
|
+
}
|
|
442
|
+
credentialUsageMap[credential.id].push({
|
|
443
|
+
type: "tool",
|
|
444
|
+
id: toolId
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
toolsObject[toolId] = toolData;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const subAgentDataComponents = subAgent.getDataComponents?.();
|
|
453
|
+
if (subAgentDataComponents) for (const dataComponent of subAgentDataComponents) {
|
|
454
|
+
let dataComponentId;
|
|
455
|
+
let dataComponentName;
|
|
456
|
+
let dataComponentDescription;
|
|
457
|
+
let dataComponentProps;
|
|
458
|
+
let dataComponentRender;
|
|
459
|
+
if (dataComponent.getId) {
|
|
460
|
+
dataComponentId = dataComponent.getId();
|
|
461
|
+
dataComponentName = dataComponent.getName();
|
|
462
|
+
dataComponentDescription = dataComponent.getDescription() || "";
|
|
463
|
+
dataComponentProps = dataComponent.getProps() || {};
|
|
464
|
+
dataComponentRender = dataComponent.getRender?.() || null;
|
|
465
|
+
} else {
|
|
466
|
+
dataComponentId = dataComponent.id || (dataComponent.name ? dataComponent.name.toLowerCase().replace(/\s+/g, "-") : "");
|
|
467
|
+
dataComponentName = dataComponent.name || "";
|
|
468
|
+
dataComponentDescription = dataComponent.description || "";
|
|
469
|
+
dataComponentProps = dataComponent.props || {};
|
|
470
|
+
dataComponentRender = dataComponent.render || null;
|
|
471
|
+
}
|
|
472
|
+
if (!dataComponentsObject[dataComponentId] && dataComponentName) dataComponentsObject[dataComponentId] = {
|
|
473
|
+
id: dataComponentId,
|
|
474
|
+
name: dataComponentName,
|
|
475
|
+
description: dataComponentDescription,
|
|
476
|
+
props: dataComponentProps,
|
|
477
|
+
render: dataComponentRender
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
const subAgentArtifactComponents = subAgent.getArtifactComponents();
|
|
481
|
+
if (subAgentArtifactComponents) for (const artifactComponent of subAgentArtifactComponents) {
|
|
482
|
+
let artifactComponentId;
|
|
483
|
+
let artifactComponentName;
|
|
484
|
+
let artifactComponentDescription;
|
|
485
|
+
let artifactComponentProps;
|
|
486
|
+
if ("getId" in artifactComponent && typeof artifactComponent.getId === "function") {
|
|
487
|
+
const component = artifactComponent;
|
|
488
|
+
artifactComponentId = component.getId();
|
|
489
|
+
artifactComponentName = component.getName();
|
|
490
|
+
artifactComponentDescription = component.getDescription() || "";
|
|
491
|
+
artifactComponentProps = component.getProps() || {};
|
|
492
|
+
} else {
|
|
493
|
+
artifactComponentId = artifactComponent.id || (artifactComponent.name ? artifactComponent.name.toLowerCase().replace(/\s+/g, "-") : "");
|
|
494
|
+
artifactComponentName = artifactComponent.name || "";
|
|
495
|
+
artifactComponentDescription = artifactComponent.description || "";
|
|
496
|
+
artifactComponentProps = artifactComponent.props || {};
|
|
497
|
+
}
|
|
498
|
+
if (!artifactComponentsObject[artifactComponentId] && artifactComponentName) artifactComponentsObject[artifactComponentId] = {
|
|
499
|
+
id: artifactComponentId,
|
|
500
|
+
name: artifactComponentName,
|
|
501
|
+
description: artifactComponentDescription,
|
|
502
|
+
props: artifactComponentProps
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
const subAgentExternalAgents = subAgent.getExternalAgentDelegates();
|
|
506
|
+
if (subAgentExternalAgents) for (const externalAgentDelegate of subAgentExternalAgents) {
|
|
507
|
+
const externalAgent = externalAgentDelegate.externalAgent;
|
|
508
|
+
const credential = externalAgent.getCredentialReference();
|
|
509
|
+
if (credential) {
|
|
510
|
+
if (!credentialReferencesObject[credential.id]) {
|
|
511
|
+
credentialReferencesObject[credential.id] = {
|
|
512
|
+
id: credential.id,
|
|
513
|
+
name: credential.name,
|
|
514
|
+
type: credential.type,
|
|
515
|
+
credentialStoreId: credential.credentialStoreId,
|
|
516
|
+
retrievalParams: credential.retrievalParams
|
|
517
|
+
};
|
|
518
|
+
credentialUsageMap[credential.id] = [];
|
|
519
|
+
}
|
|
520
|
+
logger.info({ credentialId: credential.id }, "Credential id in external agent");
|
|
521
|
+
credentialUsageMap[credential.id].push({
|
|
522
|
+
type: "externalAgent",
|
|
523
|
+
id: externalAgent.getId()
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
logger.info({ externalAgentId: externalAgent.getId() }, "External agent id");
|
|
527
|
+
externalAgentsObject[externalAgent.getId()] = {
|
|
528
|
+
id: externalAgent.getId(),
|
|
529
|
+
name: externalAgent.getName(),
|
|
530
|
+
description: externalAgent.getDescription(),
|
|
531
|
+
baseUrl: externalAgent.getBaseUrl(),
|
|
532
|
+
credentialReferenceId: externalAgent.getCredentialReferenceId()
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
logger.info({ externalAgentsObject }, "External agents object");
|
|
538
|
+
for (const tool of this.projectTools) {
|
|
539
|
+
const toolId = tool.getId();
|
|
540
|
+
if (!toolsObject[toolId]) {
|
|
541
|
+
const toolConfig = {
|
|
542
|
+
type: "mcp",
|
|
543
|
+
mcp: {
|
|
544
|
+
server: { url: tool.config.serverUrl },
|
|
545
|
+
transport: tool.config.transport,
|
|
546
|
+
activeTools: tool.config.activeTools
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const toolData = {
|
|
550
|
+
id: toolId,
|
|
551
|
+
name: tool.getName(),
|
|
552
|
+
config: toolConfig
|
|
553
|
+
};
|
|
554
|
+
if (tool.config?.imageUrl) toolData.imageUrl = tool.config.imageUrl;
|
|
555
|
+
if (tool.config?.headers) toolData.headers = tool.config.headers;
|
|
556
|
+
const credentialId = tool.getCredentialReferenceId();
|
|
557
|
+
if (credentialId) toolData.credentialReferenceId = credentialId;
|
|
558
|
+
toolsObject[toolId] = toolData;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
for (const dataComponent of this.projectDataComponents) {
|
|
562
|
+
const dataComponentId = dataComponent.getId();
|
|
563
|
+
const dataComponentName = dataComponent.getName();
|
|
564
|
+
const dataComponentDescription = dataComponent.getDescription() || "";
|
|
565
|
+
const dataComponentProps = dataComponent.getProps() || {};
|
|
566
|
+
if (!dataComponentsObject[dataComponentId] && dataComponentName) dataComponentsObject[dataComponentId] = {
|
|
567
|
+
id: dataComponentId,
|
|
568
|
+
name: dataComponentName,
|
|
569
|
+
description: dataComponentDescription,
|
|
570
|
+
props: dataComponentProps
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
for (const artifactComponent of this.projectArtifactComponents) {
|
|
574
|
+
const artifactComponentId = artifactComponent.getId();
|
|
575
|
+
const artifactComponentName = artifactComponent.getName();
|
|
576
|
+
const artifactComponentDescription = artifactComponent.getDescription() || "";
|
|
577
|
+
const artifactComponentProps = artifactComponent.getProps() || {};
|
|
578
|
+
if (!artifactComponentsObject[artifactComponentId] && artifactComponentName) artifactComponentsObject[artifactComponentId] = {
|
|
579
|
+
id: artifactComponentId,
|
|
580
|
+
name: artifactComponentName,
|
|
581
|
+
description: artifactComponentDescription,
|
|
582
|
+
props: artifactComponentProps
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
if (this.credentialReferences && this.credentialReferences.length > 0) {
|
|
586
|
+
for (const credential of this.credentialReferences) if (credential.id) {
|
|
587
|
+
if (!credentialReferencesObject[credential.id]) {
|
|
588
|
+
credentialReferencesObject[credential.id] = credential;
|
|
589
|
+
credentialUsageMap[credential.id] = [];
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
for (const [credId, usages] of Object.entries(credentialUsageMap)) if (credentialReferencesObject[credId]) credentialReferencesObject[credId].usedBy = usages;
|
|
594
|
+
return {
|
|
595
|
+
id: this.projectId,
|
|
596
|
+
name: this.projectName,
|
|
597
|
+
description: this.projectDescription || "",
|
|
598
|
+
models: this.models,
|
|
599
|
+
stopWhen: this.stopWhen,
|
|
600
|
+
agents: agentsObject,
|
|
601
|
+
tools: toolsObject,
|
|
602
|
+
functionTools: Object.keys(functionToolsObject).length > 0 ? functionToolsObject : void 0,
|
|
603
|
+
functions: Object.keys(functionsObject).length > 0 ? functionsObject : void 0,
|
|
604
|
+
dataComponents: Object.keys(dataComponentsObject).length > 0 ? dataComponentsObject : void 0,
|
|
605
|
+
artifactComponents: Object.keys(artifactComponentsObject).length > 0 ? artifactComponentsObject : void 0,
|
|
606
|
+
externalAgents: Object.keys(externalAgentsObject).length > 0 ? externalAgentsObject : void 0,
|
|
607
|
+
credentialReferences: Object.keys(credentialReferencesObject).length > 0 ? credentialReferencesObject : void 0,
|
|
608
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
609
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
//#endregion
|
|
615
|
+
export { Project };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FullProjectDefinition } from "@inkeep/agents-core";
|
|
2
|
+
|
|
3
|
+
//#region src/projectFullClient.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a full project via HTTP API
|
|
7
|
+
*/
|
|
8
|
+
declare function createFullProjectViaAPI(tenantId: string, apiUrl: string, projectData: FullProjectDefinition, apiKey?: string): Promise<FullProjectDefinition>;
|
|
9
|
+
/**
|
|
10
|
+
* Update a full project via HTTP API (upsert behavior)
|
|
11
|
+
*/
|
|
12
|
+
declare function updateFullProjectViaAPI(tenantId: string, apiUrl: string, projectId: string, projectData: FullProjectDefinition, apiKey?: string): Promise<FullProjectDefinition>;
|
|
13
|
+
/**
|
|
14
|
+
* Get a full project via HTTP API
|
|
15
|
+
*/
|
|
16
|
+
declare function getFullProjectViaAPI(tenantId: string, apiUrl: string, projectId: string, apiKey?: string): Promise<FullProjectDefinition | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Delete a full project via HTTP API
|
|
19
|
+
*/
|
|
20
|
+
declare function deleteFullProjectViaAPI(tenantId: string, apiUrl: string, projectId: string, apiKey?: string): Promise<void>;
|
|
21
|
+
declare function parseError(errorText: string): string | undefined;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createFullProjectViaAPI, deleteFullProjectViaAPI, getFullProjectViaAPI, parseError, updateFullProjectViaAPI };
|