@inkeep/agents-sdk 0.1.6 → 0.1.7
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 +553 -82
- package/dist/index.d.cts +259 -47
- package/dist/index.d.ts +259 -47
- package/dist/index.js +548 -83
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -79,10 +79,7 @@ var ArtifactComponent = class {
|
|
|
79
79
|
summaryProps: this.config.summaryProps,
|
|
80
80
|
fullProps: this.config.fullProps
|
|
81
81
|
};
|
|
82
|
-
logger.info(
|
|
83
|
-
{ artifactComponentData },
|
|
84
|
-
"artifactComponentData for create/update"
|
|
85
|
-
);
|
|
82
|
+
logger.info({ artifactComponentData }, "artifactComponentData for create/update");
|
|
86
83
|
const updateResponse = await fetch(
|
|
87
84
|
`${this.baseURL}/tenants/${this.tenantId}/crud/artifact-components/${this.getId()}`,
|
|
88
85
|
{
|
|
@@ -594,16 +591,13 @@ var Agent = class {
|
|
|
594
591
|
},
|
|
595
592
|
"Agent not found, creating new agent"
|
|
596
593
|
);
|
|
597
|
-
const createResponse = await fetch(
|
|
598
|
-
|
|
599
|
-
{
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
body: JSON.stringify(agentData)
|
|
605
|
-
}
|
|
606
|
-
);
|
|
594
|
+
const createResponse = await fetch(`${this.baseURL}/tenants/${this.tenantId}/crud/agents`, {
|
|
595
|
+
method: "POST",
|
|
596
|
+
headers: {
|
|
597
|
+
"Content-Type": "application/json"
|
|
598
|
+
},
|
|
599
|
+
body: JSON.stringify(agentData)
|
|
600
|
+
});
|
|
607
601
|
if (!createResponse.ok) {
|
|
608
602
|
const errorText2 = await createResponse.text().catch(() => "Unknown error");
|
|
609
603
|
throw new Error(
|
|
@@ -654,10 +648,7 @@ var Agent = class {
|
|
|
654
648
|
}
|
|
655
649
|
}
|
|
656
650
|
async saveDataComponents() {
|
|
657
|
-
logger4.info(
|
|
658
|
-
{ dataComponents: this.config.dataComponents },
|
|
659
|
-
"dataComponents and config"
|
|
660
|
-
);
|
|
651
|
+
logger4.info({ dataComponents: this.config.dataComponents }, "dataComponents and config");
|
|
661
652
|
const components = resolveGetter(this.config.dataComponents);
|
|
662
653
|
if (components) {
|
|
663
654
|
for (const dataComponent2 of components) {
|
|
@@ -1302,14 +1293,10 @@ var AgentGraph = class {
|
|
|
1302
1293
|
for (const [toolName, toolInstance] of Object.entries(agentTools)) {
|
|
1303
1294
|
if (toolInstance && typeof toolInstance === "object") {
|
|
1304
1295
|
let toolId;
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
toolId
|
|
1308
|
-
|
|
1309
|
-
selectedToolsMapping[toolId] = mcpConfig.selectedTools;
|
|
1310
|
-
}
|
|
1311
|
-
} else {
|
|
1312
|
-
toolId = toolInstance.getId?.() || toolInstance.id || toolName;
|
|
1296
|
+
toolId = toolInstance.getId?.() || toolInstance.id;
|
|
1297
|
+
if ("selectedTools" in toolInstance && toolInstance.selectedTools !== void 0) {
|
|
1298
|
+
logger7.info({ toolId, selectedTools: toolInstance.selectedTools }, "Selected tools");
|
|
1299
|
+
selectedToolsMapping[toolId] = toolInstance.selectedTools;
|
|
1313
1300
|
}
|
|
1314
1301
|
tools.push(toolId);
|
|
1315
1302
|
}
|
|
@@ -1802,9 +1789,7 @@ var AgentGraph = class {
|
|
|
1802
1789
|
const agentToRemove = this.agentMap.get(id);
|
|
1803
1790
|
if (agentToRemove) {
|
|
1804
1791
|
this.agentMap.delete(agentToRemove.getId());
|
|
1805
|
-
this.agents = this.agents.filter(
|
|
1806
|
-
(agent2) => agent2.getId() !== agentToRemove.getId()
|
|
1807
|
-
);
|
|
1792
|
+
this.agents = this.agents.filter((agent2) => agent2.getId() !== agentToRemove.getId());
|
|
1808
1793
|
logger7.info(
|
|
1809
1794
|
{
|
|
1810
1795
|
graphId: this.graphId,
|
|
@@ -1971,10 +1956,10 @@ var AgentGraph = class {
|
|
|
1971
1956
|
*/
|
|
1972
1957
|
async getProjectModelDefaults() {
|
|
1973
1958
|
try {
|
|
1974
|
-
const
|
|
1959
|
+
const project2 = await getProject(this.dbClient)({
|
|
1975
1960
|
scopes: { tenantId: this.tenantId, projectId: this.projectId }
|
|
1976
1961
|
});
|
|
1977
|
-
return
|
|
1962
|
+
return project2?.models;
|
|
1978
1963
|
} catch (error) {
|
|
1979
1964
|
logger7.warn(
|
|
1980
1965
|
{
|
|
@@ -1992,10 +1977,10 @@ var AgentGraph = class {
|
|
|
1992
1977
|
*/
|
|
1993
1978
|
async getProjectStopWhenDefaults() {
|
|
1994
1979
|
try {
|
|
1995
|
-
const
|
|
1980
|
+
const project2 = await getProject(this.dbClient)({
|
|
1996
1981
|
scopes: { tenantId: this.tenantId, projectId: this.projectId }
|
|
1997
1982
|
});
|
|
1998
|
-
return
|
|
1983
|
+
return project2?.stopWhen;
|
|
1999
1984
|
} catch (error) {
|
|
2000
1985
|
logger7.warn(
|
|
2001
1986
|
{
|
|
@@ -2147,9 +2132,7 @@ var AgentGraph = class {
|
|
|
2147
2132
|
const data = JSON.parse(responseText);
|
|
2148
2133
|
return data.result || data.choices?.[0]?.message?.content || "";
|
|
2149
2134
|
} catch (error) {
|
|
2150
|
-
throw new Error(
|
|
2151
|
-
`Graph execution failed: ${error.message || "Unknown error"}`
|
|
2152
|
-
);
|
|
2135
|
+
throw new Error(`Graph execution failed: ${error.message || "Unknown error"}`);
|
|
2153
2136
|
}
|
|
2154
2137
|
}
|
|
2155
2138
|
/**
|
|
@@ -2182,9 +2165,7 @@ var AgentGraph = class {
|
|
|
2182
2165
|
return [{ role: "user", content: input }];
|
|
2183
2166
|
}
|
|
2184
2167
|
if (Array.isArray(input)) {
|
|
2185
|
-
return input.map(
|
|
2186
|
-
(msg) => typeof msg === "string" ? { role: "user", content: msg } : msg
|
|
2187
|
-
);
|
|
2168
|
+
return input.map((msg) => typeof msg === "string" ? { role: "user", content: msg } : msg);
|
|
2188
2169
|
}
|
|
2189
2170
|
return [input];
|
|
2190
2171
|
}
|
|
@@ -2199,16 +2180,11 @@ var AgentGraph = class {
|
|
|
2199
2180
|
}
|
|
2200
2181
|
});
|
|
2201
2182
|
if (getResponse.ok) {
|
|
2202
|
-
logger7.info(
|
|
2203
|
-
{ graphId: this.graphId },
|
|
2204
|
-
"Graph already exists in backend"
|
|
2205
|
-
);
|
|
2183
|
+
logger7.info({ graphId: this.graphId }, "Graph already exists in backend");
|
|
2206
2184
|
return;
|
|
2207
2185
|
}
|
|
2208
2186
|
if (getResponse.status !== 404) {
|
|
2209
|
-
throw new Error(
|
|
2210
|
-
`HTTP ${getResponse.status}: ${getResponse.statusText}`
|
|
2211
|
-
);
|
|
2187
|
+
throw new Error(`HTTP ${getResponse.status}: ${getResponse.statusText}`);
|
|
2212
2188
|
}
|
|
2213
2189
|
} catch (error) {
|
|
2214
2190
|
if (!error.message.includes("404")) {
|
|
@@ -2231,9 +2207,7 @@ var AgentGraph = class {
|
|
|
2231
2207
|
})
|
|
2232
2208
|
});
|
|
2233
2209
|
if (!createResponse.ok) {
|
|
2234
|
-
throw new Error(
|
|
2235
|
-
`HTTP ${createResponse.status}: ${createResponse.statusText}`
|
|
2236
|
-
);
|
|
2210
|
+
throw new Error(`HTTP ${createResponse.status}: ${createResponse.statusText}`);
|
|
2237
2211
|
}
|
|
2238
2212
|
const createData = await createResponse.json();
|
|
2239
2213
|
this.graphId = createData.data.id;
|
|
@@ -2260,9 +2234,7 @@ var AgentGraph = class {
|
|
|
2260
2234
|
})
|
|
2261
2235
|
});
|
|
2262
2236
|
if (!updateResponse.ok) {
|
|
2263
|
-
throw new Error(
|
|
2264
|
-
`HTTP ${updateResponse.status}: ${updateResponse.statusText}`
|
|
2265
|
-
);
|
|
2237
|
+
throw new Error(`HTTP ${updateResponse.status}: ${updateResponse.statusText}`);
|
|
2266
2238
|
}
|
|
2267
2239
|
logger7.debug(
|
|
2268
2240
|
{
|
|
@@ -2296,16 +2268,10 @@ var AgentGraph = class {
|
|
|
2296
2268
|
const delegates = agent2.getDelegates();
|
|
2297
2269
|
for (const delegate of delegates) {
|
|
2298
2270
|
if (delegate instanceof ExternalAgent) {
|
|
2299
|
-
allRelationPromises.push(
|
|
2300
|
-
this.createExternalAgentRelation(agent2, delegate, "delegate")
|
|
2301
|
-
);
|
|
2271
|
+
allRelationPromises.push(this.createExternalAgentRelation(agent2, delegate, "delegate"));
|
|
2302
2272
|
} else {
|
|
2303
2273
|
allRelationPromises.push(
|
|
2304
|
-
this.createInternalAgentRelation(
|
|
2305
|
-
agent2,
|
|
2306
|
-
delegate,
|
|
2307
|
-
"delegate"
|
|
2308
|
-
)
|
|
2274
|
+
this.createInternalAgentRelation(agent2, delegate, "delegate")
|
|
2309
2275
|
);
|
|
2310
2276
|
}
|
|
2311
2277
|
}
|
|
@@ -2372,9 +2338,7 @@ var AgentGraph = class {
|
|
|
2372
2338
|
);
|
|
2373
2339
|
return;
|
|
2374
2340
|
}
|
|
2375
|
-
throw new Error(
|
|
2376
|
-
`Failed to create agent relation: ${response.status} - ${errorText}`
|
|
2377
|
-
);
|
|
2341
|
+
throw new Error(`Failed to create agent relation: ${response.status} - ${errorText}`);
|
|
2378
2342
|
}
|
|
2379
2343
|
logger7.info(
|
|
2380
2344
|
{
|
|
@@ -2462,9 +2426,7 @@ var AgentGraph = class {
|
|
|
2462
2426
|
* Create external agents in the database
|
|
2463
2427
|
*/
|
|
2464
2428
|
async createExternalAgents() {
|
|
2465
|
-
const externalAgents2 = this.agents.filter(
|
|
2466
|
-
(agent2) => this.isExternalAgent(agent2)
|
|
2467
|
-
);
|
|
2429
|
+
const externalAgents2 = this.agents.filter((agent2) => this.isExternalAgent(agent2));
|
|
2468
2430
|
logger7.info(
|
|
2469
2431
|
{
|
|
2470
2432
|
graphId: this.graphId,
|
|
@@ -2515,6 +2477,511 @@ var AgentGraph = class {
|
|
|
2515
2477
|
}
|
|
2516
2478
|
}
|
|
2517
2479
|
};
|
|
2480
|
+
var logger8 = getLogger("projectFullClient");
|
|
2481
|
+
async function createFullProjectViaAPI(tenantId, apiUrl, projectData) {
|
|
2482
|
+
logger8.info(
|
|
2483
|
+
{
|
|
2484
|
+
tenantId,
|
|
2485
|
+
projectId: projectData.id,
|
|
2486
|
+
apiUrl
|
|
2487
|
+
},
|
|
2488
|
+
"Creating full project via API"
|
|
2489
|
+
);
|
|
2490
|
+
const url = `${apiUrl}/tenants/${tenantId}/project-full`;
|
|
2491
|
+
const response = await fetch(url, {
|
|
2492
|
+
method: "POST",
|
|
2493
|
+
headers: {
|
|
2494
|
+
"Content-Type": "application/json"
|
|
2495
|
+
},
|
|
2496
|
+
body: JSON.stringify(projectData)
|
|
2497
|
+
});
|
|
2498
|
+
if (!response.ok) {
|
|
2499
|
+
const errorText = await response.text();
|
|
2500
|
+
let errorMessage = `Failed to create project: ${response.status} ${response.statusText}`;
|
|
2501
|
+
try {
|
|
2502
|
+
const errorJson = JSON.parse(errorText);
|
|
2503
|
+
if (errorJson.error) {
|
|
2504
|
+
errorMessage = errorJson.error;
|
|
2505
|
+
}
|
|
2506
|
+
} catch {
|
|
2507
|
+
if (errorText) {
|
|
2508
|
+
errorMessage = errorText;
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
logger8.error(
|
|
2512
|
+
{
|
|
2513
|
+
status: response.status,
|
|
2514
|
+
error: errorMessage
|
|
2515
|
+
},
|
|
2516
|
+
"Failed to create project via API"
|
|
2517
|
+
);
|
|
2518
|
+
throw new Error(errorMessage);
|
|
2519
|
+
}
|
|
2520
|
+
const result = await response.json();
|
|
2521
|
+
logger8.info(
|
|
2522
|
+
{
|
|
2523
|
+
projectId: projectData.id
|
|
2524
|
+
},
|
|
2525
|
+
"Successfully created project via API"
|
|
2526
|
+
);
|
|
2527
|
+
return result.data;
|
|
2528
|
+
}
|
|
2529
|
+
async function updateFullProjectViaAPI(tenantId, apiUrl, projectId, projectData) {
|
|
2530
|
+
logger8.info(
|
|
2531
|
+
{
|
|
2532
|
+
tenantId,
|
|
2533
|
+
projectId,
|
|
2534
|
+
apiUrl
|
|
2535
|
+
},
|
|
2536
|
+
"Updating full project via API"
|
|
2537
|
+
);
|
|
2538
|
+
const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
|
|
2539
|
+
const response = await fetch(url, {
|
|
2540
|
+
method: "PUT",
|
|
2541
|
+
headers: {
|
|
2542
|
+
"Content-Type": "application/json"
|
|
2543
|
+
},
|
|
2544
|
+
body: JSON.stringify(projectData)
|
|
2545
|
+
});
|
|
2546
|
+
if (!response.ok) {
|
|
2547
|
+
const errorText = await response.text();
|
|
2548
|
+
let errorMessage = `Failed to update project: ${response.status} ${response.statusText}`;
|
|
2549
|
+
try {
|
|
2550
|
+
const errorJson = JSON.parse(errorText);
|
|
2551
|
+
if (errorJson.error) {
|
|
2552
|
+
errorMessage = errorJson.error;
|
|
2553
|
+
}
|
|
2554
|
+
} catch {
|
|
2555
|
+
if (errorText) {
|
|
2556
|
+
errorMessage = errorText;
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
logger8.error(
|
|
2560
|
+
{
|
|
2561
|
+
status: response.status,
|
|
2562
|
+
error: errorMessage
|
|
2563
|
+
},
|
|
2564
|
+
"Failed to update project via API"
|
|
2565
|
+
);
|
|
2566
|
+
throw new Error(errorMessage);
|
|
2567
|
+
}
|
|
2568
|
+
const result = await response.json();
|
|
2569
|
+
logger8.info(
|
|
2570
|
+
{
|
|
2571
|
+
projectId
|
|
2572
|
+
},
|
|
2573
|
+
"Successfully updated project via API"
|
|
2574
|
+
);
|
|
2575
|
+
return result.data;
|
|
2576
|
+
}
|
|
2577
|
+
async function getFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
2578
|
+
logger8.info(
|
|
2579
|
+
{
|
|
2580
|
+
tenantId,
|
|
2581
|
+
projectId,
|
|
2582
|
+
apiUrl
|
|
2583
|
+
},
|
|
2584
|
+
"Getting full project via API"
|
|
2585
|
+
);
|
|
2586
|
+
const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
|
|
2587
|
+
const response = await fetch(url, {
|
|
2588
|
+
method: "GET",
|
|
2589
|
+
headers: {
|
|
2590
|
+
"Content-Type": "application/json"
|
|
2591
|
+
}
|
|
2592
|
+
});
|
|
2593
|
+
if (!response.ok) {
|
|
2594
|
+
if (response.status === 404) {
|
|
2595
|
+
logger8.info(
|
|
2596
|
+
{
|
|
2597
|
+
projectId
|
|
2598
|
+
},
|
|
2599
|
+
"Project not found"
|
|
2600
|
+
);
|
|
2601
|
+
return null;
|
|
2602
|
+
}
|
|
2603
|
+
const errorText = await response.text();
|
|
2604
|
+
let errorMessage = `Failed to get project: ${response.status} ${response.statusText}`;
|
|
2605
|
+
try {
|
|
2606
|
+
const errorJson = JSON.parse(errorText);
|
|
2607
|
+
if (errorJson.error) {
|
|
2608
|
+
errorMessage = errorJson.error;
|
|
2609
|
+
}
|
|
2610
|
+
} catch {
|
|
2611
|
+
if (errorText) {
|
|
2612
|
+
errorMessage = errorText;
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
logger8.error(
|
|
2616
|
+
{
|
|
2617
|
+
status: response.status,
|
|
2618
|
+
error: errorMessage
|
|
2619
|
+
},
|
|
2620
|
+
"Failed to get project via API"
|
|
2621
|
+
);
|
|
2622
|
+
throw new Error(errorMessage);
|
|
2623
|
+
}
|
|
2624
|
+
const result = await response.json();
|
|
2625
|
+
logger8.info(
|
|
2626
|
+
{
|
|
2627
|
+
projectId
|
|
2628
|
+
},
|
|
2629
|
+
"Successfully retrieved project via API"
|
|
2630
|
+
);
|
|
2631
|
+
return result.data;
|
|
2632
|
+
}
|
|
2633
|
+
async function deleteFullProjectViaAPI(tenantId, apiUrl, projectId) {
|
|
2634
|
+
logger8.info(
|
|
2635
|
+
{
|
|
2636
|
+
tenantId,
|
|
2637
|
+
projectId,
|
|
2638
|
+
apiUrl
|
|
2639
|
+
},
|
|
2640
|
+
"Deleting full project via API"
|
|
2641
|
+
);
|
|
2642
|
+
const url = `${apiUrl}/tenants/${tenantId}/project-full/${projectId}`;
|
|
2643
|
+
const response = await fetch(url, {
|
|
2644
|
+
method: "DELETE",
|
|
2645
|
+
headers: {
|
|
2646
|
+
"Content-Type": "application/json"
|
|
2647
|
+
}
|
|
2648
|
+
});
|
|
2649
|
+
if (!response.ok) {
|
|
2650
|
+
const errorText = await response.text();
|
|
2651
|
+
let errorMessage = `Failed to delete project: ${response.status} ${response.statusText}`;
|
|
2652
|
+
try {
|
|
2653
|
+
const errorJson = JSON.parse(errorText);
|
|
2654
|
+
if (errorJson.error) {
|
|
2655
|
+
errorMessage = errorJson.error;
|
|
2656
|
+
}
|
|
2657
|
+
} catch {
|
|
2658
|
+
if (errorText) {
|
|
2659
|
+
errorMessage = errorText;
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
logger8.error(
|
|
2663
|
+
{
|
|
2664
|
+
status: response.status,
|
|
2665
|
+
error: errorMessage
|
|
2666
|
+
},
|
|
2667
|
+
"Failed to delete project via API"
|
|
2668
|
+
);
|
|
2669
|
+
throw new Error(errorMessage);
|
|
2670
|
+
}
|
|
2671
|
+
logger8.info(
|
|
2672
|
+
{
|
|
2673
|
+
projectId
|
|
2674
|
+
},
|
|
2675
|
+
"Successfully deleted project via API"
|
|
2676
|
+
);
|
|
2677
|
+
}
|
|
2678
|
+
|
|
2679
|
+
// src/project.ts
|
|
2680
|
+
var logger9 = getLogger("project");
|
|
2681
|
+
var Project = class {
|
|
2682
|
+
constructor(config) {
|
|
2683
|
+
__publicField(this, "projectId");
|
|
2684
|
+
__publicField(this, "projectName");
|
|
2685
|
+
__publicField(this, "projectDescription");
|
|
2686
|
+
__publicField(this, "tenantId");
|
|
2687
|
+
__publicField(this, "baseURL");
|
|
2688
|
+
__publicField(this, "initialized", false);
|
|
2689
|
+
__publicField(this, "models");
|
|
2690
|
+
__publicField(this, "stopWhen");
|
|
2691
|
+
__publicField(this, "graphs", []);
|
|
2692
|
+
__publicField(this, "graphMap", /* @__PURE__ */ new Map());
|
|
2693
|
+
this.projectId = config.id;
|
|
2694
|
+
this.projectName = config.name;
|
|
2695
|
+
this.projectDescription = config.description;
|
|
2696
|
+
this.tenantId = config.tenantId || "default";
|
|
2697
|
+
this.baseURL = process.env.INKEEP_API_URL || "http://localhost:3002";
|
|
2698
|
+
this.models = config.models;
|
|
2699
|
+
this.stopWhen = config.stopWhen;
|
|
2700
|
+
if (config.graphs) {
|
|
2701
|
+
this.graphs = config.graphs();
|
|
2702
|
+
this.graphMap = new Map(this.graphs.map((graph) => [graph.getId(), graph]));
|
|
2703
|
+
for (const graph of this.graphs) {
|
|
2704
|
+
graph.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
logger9.info(
|
|
2708
|
+
{
|
|
2709
|
+
projectId: this.projectId,
|
|
2710
|
+
tenantId: this.tenantId,
|
|
2711
|
+
graphCount: this.graphs.length
|
|
2712
|
+
},
|
|
2713
|
+
"Project created"
|
|
2714
|
+
);
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* Set or update the configuration (tenantId and apiUrl)
|
|
2718
|
+
* This is used by the CLI to inject configuration from inkeep.config.ts
|
|
2719
|
+
*/
|
|
2720
|
+
setConfig(tenantId, apiUrl) {
|
|
2721
|
+
if (this.initialized) {
|
|
2722
|
+
throw new Error("Cannot set config after project has been initialized");
|
|
2723
|
+
}
|
|
2724
|
+
this.tenantId = tenantId;
|
|
2725
|
+
this.baseURL = apiUrl;
|
|
2726
|
+
for (const graph of this.graphs) {
|
|
2727
|
+
graph.setConfig(tenantId, this.projectId, apiUrl);
|
|
2728
|
+
}
|
|
2729
|
+
logger9.info(
|
|
2730
|
+
{
|
|
2731
|
+
projectId: this.projectId,
|
|
2732
|
+
tenantId: this.tenantId,
|
|
2733
|
+
apiUrl: this.baseURL
|
|
2734
|
+
},
|
|
2735
|
+
"Project configuration updated"
|
|
2736
|
+
);
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Initialize the project and create/update it in the backend using full project approach
|
|
2740
|
+
*/
|
|
2741
|
+
async init() {
|
|
2742
|
+
if (this.initialized) {
|
|
2743
|
+
logger9.info({ projectId: this.projectId }, "Project already initialized");
|
|
2744
|
+
return;
|
|
2745
|
+
}
|
|
2746
|
+
logger9.info(
|
|
2747
|
+
{
|
|
2748
|
+
projectId: this.projectId,
|
|
2749
|
+
tenantId: this.tenantId,
|
|
2750
|
+
graphCount: this.graphs.length
|
|
2751
|
+
},
|
|
2752
|
+
"Initializing project using full project endpoint"
|
|
2753
|
+
);
|
|
2754
|
+
try {
|
|
2755
|
+
const initPromises = this.graphs.map(async (graph) => {
|
|
2756
|
+
try {
|
|
2757
|
+
await graph.init();
|
|
2758
|
+
logger9.debug(
|
|
2759
|
+
{
|
|
2760
|
+
projectId: this.projectId,
|
|
2761
|
+
graphId: graph.getId()
|
|
2762
|
+
},
|
|
2763
|
+
"Graph initialized in project"
|
|
2764
|
+
);
|
|
2765
|
+
} catch (error) {
|
|
2766
|
+
logger9.error(
|
|
2767
|
+
{
|
|
2768
|
+
projectId: this.projectId,
|
|
2769
|
+
graphId: graph.getId(),
|
|
2770
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
2771
|
+
},
|
|
2772
|
+
"Failed to initialize graph in project"
|
|
2773
|
+
);
|
|
2774
|
+
throw error;
|
|
2775
|
+
}
|
|
2776
|
+
});
|
|
2777
|
+
await Promise.all(initPromises);
|
|
2778
|
+
const projectDefinition = await this.toFullProjectDefinition();
|
|
2779
|
+
logger9.info(
|
|
2780
|
+
{
|
|
2781
|
+
projectId: this.projectId,
|
|
2782
|
+
mode: "api-client",
|
|
2783
|
+
apiUrl: this.baseURL
|
|
2784
|
+
},
|
|
2785
|
+
"Using API client to create/update full project"
|
|
2786
|
+
);
|
|
2787
|
+
const createdProject = await updateFullProjectViaAPI(
|
|
2788
|
+
this.tenantId,
|
|
2789
|
+
this.baseURL,
|
|
2790
|
+
this.projectId,
|
|
2791
|
+
projectDefinition
|
|
2792
|
+
);
|
|
2793
|
+
this.initialized = true;
|
|
2794
|
+
logger9.info(
|
|
2795
|
+
{
|
|
2796
|
+
projectId: this.projectId,
|
|
2797
|
+
tenantId: this.tenantId,
|
|
2798
|
+
graphCount: Object.keys(createdProject.graphs || {}).length
|
|
2799
|
+
},
|
|
2800
|
+
"Project initialized successfully using full project endpoint"
|
|
2801
|
+
);
|
|
2802
|
+
} catch (error) {
|
|
2803
|
+
logger9.error(
|
|
2804
|
+
{
|
|
2805
|
+
projectId: this.projectId,
|
|
2806
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
2807
|
+
},
|
|
2808
|
+
"Failed to initialize project using full project endpoint"
|
|
2809
|
+
);
|
|
2810
|
+
throw error;
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Get the project ID
|
|
2815
|
+
*/
|
|
2816
|
+
getId() {
|
|
2817
|
+
return this.projectId;
|
|
2818
|
+
}
|
|
2819
|
+
/**
|
|
2820
|
+
* Get the project name
|
|
2821
|
+
*/
|
|
2822
|
+
getName() {
|
|
2823
|
+
return this.projectName;
|
|
2824
|
+
}
|
|
2825
|
+
/**
|
|
2826
|
+
* Get the project description
|
|
2827
|
+
*/
|
|
2828
|
+
getDescription() {
|
|
2829
|
+
return this.projectDescription;
|
|
2830
|
+
}
|
|
2831
|
+
/**
|
|
2832
|
+
* Get the tenant ID
|
|
2833
|
+
*/
|
|
2834
|
+
getTenantId() {
|
|
2835
|
+
return this.tenantId;
|
|
2836
|
+
}
|
|
2837
|
+
/**
|
|
2838
|
+
* Get the project's model configuration
|
|
2839
|
+
*/
|
|
2840
|
+
getModels() {
|
|
2841
|
+
return this.models;
|
|
2842
|
+
}
|
|
2843
|
+
/**
|
|
2844
|
+
* Set the project's model configuration
|
|
2845
|
+
*/
|
|
2846
|
+
setModels(models) {
|
|
2847
|
+
this.models = models;
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Get the project's stopWhen configuration
|
|
2851
|
+
*/
|
|
2852
|
+
getStopWhen() {
|
|
2853
|
+
return this.stopWhen;
|
|
2854
|
+
}
|
|
2855
|
+
/**
|
|
2856
|
+
* Set the project's stopWhen configuration
|
|
2857
|
+
*/
|
|
2858
|
+
setStopWhen(stopWhen) {
|
|
2859
|
+
this.stopWhen = stopWhen;
|
|
2860
|
+
}
|
|
2861
|
+
/**
|
|
2862
|
+
* Get all graphs in the project
|
|
2863
|
+
*/
|
|
2864
|
+
getGraphs() {
|
|
2865
|
+
return this.graphs;
|
|
2866
|
+
}
|
|
2867
|
+
/**
|
|
2868
|
+
* Get a graph by ID
|
|
2869
|
+
*/
|
|
2870
|
+
getGraph(id) {
|
|
2871
|
+
return this.graphMap.get(id);
|
|
2872
|
+
}
|
|
2873
|
+
/**
|
|
2874
|
+
* Add a graph to the project
|
|
2875
|
+
*/
|
|
2876
|
+
addGraph(graph) {
|
|
2877
|
+
this.graphs.push(graph);
|
|
2878
|
+
this.graphMap.set(graph.getId(), graph);
|
|
2879
|
+
graph.setConfig(this.tenantId, this.projectId, this.baseURL);
|
|
2880
|
+
logger9.info(
|
|
2881
|
+
{
|
|
2882
|
+
projectId: this.projectId,
|
|
2883
|
+
graphId: graph.getId()
|
|
2884
|
+
},
|
|
2885
|
+
"Graph added to project"
|
|
2886
|
+
);
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* Remove a graph from the project
|
|
2890
|
+
*/
|
|
2891
|
+
removeGraph(id) {
|
|
2892
|
+
const graphToRemove = this.graphMap.get(id);
|
|
2893
|
+
if (graphToRemove) {
|
|
2894
|
+
this.graphMap.delete(id);
|
|
2895
|
+
this.graphs = this.graphs.filter((graph) => graph.getId() !== id);
|
|
2896
|
+
logger9.info(
|
|
2897
|
+
{
|
|
2898
|
+
projectId: this.projectId,
|
|
2899
|
+
graphId: id
|
|
2900
|
+
},
|
|
2901
|
+
"Graph removed from project"
|
|
2902
|
+
);
|
|
2903
|
+
return true;
|
|
2904
|
+
}
|
|
2905
|
+
return false;
|
|
2906
|
+
}
|
|
2907
|
+
/**
|
|
2908
|
+
* Get project statistics
|
|
2909
|
+
*/
|
|
2910
|
+
getStats() {
|
|
2911
|
+
return {
|
|
2912
|
+
projectId: this.projectId,
|
|
2913
|
+
tenantId: this.tenantId,
|
|
2914
|
+
graphCount: this.graphs.length,
|
|
2915
|
+
initialized: this.initialized
|
|
2916
|
+
};
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Validate the project configuration
|
|
2920
|
+
*/
|
|
2921
|
+
validate() {
|
|
2922
|
+
const errors = [];
|
|
2923
|
+
if (!this.projectId) {
|
|
2924
|
+
errors.push("Project must have an ID");
|
|
2925
|
+
}
|
|
2926
|
+
if (!this.projectName) {
|
|
2927
|
+
errors.push("Project must have a name");
|
|
2928
|
+
}
|
|
2929
|
+
const graphIds = /* @__PURE__ */ new Set();
|
|
2930
|
+
for (const graph of this.graphs) {
|
|
2931
|
+
const id = graph.getId();
|
|
2932
|
+
if (graphIds.has(id)) {
|
|
2933
|
+
errors.push(`Duplicate graph ID: ${id}`);
|
|
2934
|
+
}
|
|
2935
|
+
graphIds.add(id);
|
|
2936
|
+
}
|
|
2937
|
+
for (const graph of this.graphs) {
|
|
2938
|
+
const graphValidation = graph.validate();
|
|
2939
|
+
if (!graphValidation.valid) {
|
|
2940
|
+
errors.push(...graphValidation.errors.map((error) => `Graph '${graph.getId()}': ${error}`));
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
return {
|
|
2944
|
+
valid: errors.length === 0,
|
|
2945
|
+
errors
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2949
|
+
* Convert the Project to FullProjectDefinition format
|
|
2950
|
+
*/
|
|
2951
|
+
async toFullProjectDefinition() {
|
|
2952
|
+
const graphsObject = {};
|
|
2953
|
+
for (const graph of this.graphs) {
|
|
2954
|
+
const graphDefinition = await graph.toFullGraphDefinition();
|
|
2955
|
+
graphsObject[graph.getId()] = graphDefinition;
|
|
2956
|
+
}
|
|
2957
|
+
return {
|
|
2958
|
+
id: this.projectId,
|
|
2959
|
+
name: this.projectName,
|
|
2960
|
+
description: this.projectDescription || "",
|
|
2961
|
+
models: this.models,
|
|
2962
|
+
stopWhen: this.stopWhen,
|
|
2963
|
+
graphs: graphsObject,
|
|
2964
|
+
tools: {},
|
|
2965
|
+
// Empty tools object as SDK doesn't manage tools directly yet
|
|
2966
|
+
credentialReferences: void 0,
|
|
2967
|
+
// Projects don't directly hold credentials yet
|
|
2968
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2969
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2970
|
+
};
|
|
2971
|
+
}
|
|
2972
|
+
/**
|
|
2973
|
+
* Convert project configuration to API format
|
|
2974
|
+
*/
|
|
2975
|
+
toApiFormat() {
|
|
2976
|
+
return {
|
|
2977
|
+
id: this.projectId,
|
|
2978
|
+
name: this.projectName,
|
|
2979
|
+
description: this.projectDescription || "",
|
|
2980
|
+
models: this.models,
|
|
2981
|
+
stopWhen: this.stopWhen
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
};
|
|
2518
2985
|
|
|
2519
2986
|
// src/utils/generateIdFromName.ts
|
|
2520
2987
|
function generateIdFromName3(name) {
|
|
@@ -2525,6 +2992,9 @@ function generateIdFromName3(name) {
|
|
|
2525
2992
|
function agentGraph(config) {
|
|
2526
2993
|
return new AgentGraph(config);
|
|
2527
2994
|
}
|
|
2995
|
+
function project(config) {
|
|
2996
|
+
return new Project(config);
|
|
2997
|
+
}
|
|
2528
2998
|
function agent(config) {
|
|
2529
2999
|
if (!config.id) {
|
|
2530
3000
|
throw new Error(
|
|
@@ -2624,9 +3094,7 @@ function createEnvironmentSettings(environments) {
|
|
|
2624
3094
|
}
|
|
2625
3095
|
const credential2 = env.credentials?.[key];
|
|
2626
3096
|
if (!credential2) {
|
|
2627
|
-
throw new Error(
|
|
2628
|
-
`Credential '${String(key)}' not found in environment '${currentEnv}'`
|
|
2629
|
-
);
|
|
3097
|
+
throw new Error(`Credential '${String(key)}' not found in environment '${currentEnv}'`);
|
|
2630
3098
|
}
|
|
2631
3099
|
return credential2;
|
|
2632
3100
|
}
|
|
@@ -2655,7 +3123,7 @@ var MaxTurnsExceededError = class extends AgentError {
|
|
|
2655
3123
|
};
|
|
2656
3124
|
|
|
2657
3125
|
// src/runner.ts
|
|
2658
|
-
var
|
|
3126
|
+
var logger10 = getLogger("runner");
|
|
2659
3127
|
var Runner = class _Runner {
|
|
2660
3128
|
/**
|
|
2661
3129
|
* Run a graph until completion, handling transfers and tool calls
|
|
@@ -2667,7 +3135,7 @@ var Runner = class _Runner {
|
|
|
2667
3135
|
let turnCount = 0;
|
|
2668
3136
|
const messageHistory = _Runner.normalizeToMessageHistory(messages);
|
|
2669
3137
|
const allToolCalls = [];
|
|
2670
|
-
|
|
3138
|
+
logger10.info(
|
|
2671
3139
|
{
|
|
2672
3140
|
graphId: graph.getId(),
|
|
2673
3141
|
defaultAgent: graph.getDefaultAgent()?.getName(),
|
|
@@ -2677,7 +3145,7 @@ var Runner = class _Runner {
|
|
|
2677
3145
|
"Starting graph run"
|
|
2678
3146
|
);
|
|
2679
3147
|
while (turnCount < maxTurns) {
|
|
2680
|
-
|
|
3148
|
+
logger10.debug(
|
|
2681
3149
|
{
|
|
2682
3150
|
graphId: graph.getId(),
|
|
2683
3151
|
turnCount,
|
|
@@ -2687,7 +3155,7 @@ var Runner = class _Runner {
|
|
|
2687
3155
|
);
|
|
2688
3156
|
const response = await graph.generate(messageHistory, options);
|
|
2689
3157
|
turnCount++;
|
|
2690
|
-
|
|
3158
|
+
logger10.info(
|
|
2691
3159
|
{
|
|
2692
3160
|
graphId: graph.getId(),
|
|
2693
3161
|
turnCount,
|
|
@@ -2707,7 +3175,7 @@ var Runner = class _Runner {
|
|
|
2707
3175
|
}
|
|
2708
3176
|
};
|
|
2709
3177
|
}
|
|
2710
|
-
|
|
3178
|
+
logger10.error(
|
|
2711
3179
|
{
|
|
2712
3180
|
graphId: graph.getId(),
|
|
2713
3181
|
maxTurns,
|
|
@@ -2721,7 +3189,7 @@ var Runner = class _Runner {
|
|
|
2721
3189
|
* Stream a graph's response
|
|
2722
3190
|
*/
|
|
2723
3191
|
static async stream(graph, messages, options) {
|
|
2724
|
-
|
|
3192
|
+
logger10.info(
|
|
2725
3193
|
{
|
|
2726
3194
|
graphId: graph.getId(),
|
|
2727
3195
|
defaultAgent: graph.getDefaultAgent()?.getName()
|
|
@@ -2737,7 +3205,7 @@ var Runner = class _Runner {
|
|
|
2737
3205
|
if (graphs.length === 0) {
|
|
2738
3206
|
throw new Error("No graphs provided for race");
|
|
2739
3207
|
}
|
|
2740
|
-
|
|
3208
|
+
logger10.info(
|
|
2741
3209
|
{
|
|
2742
3210
|
graphCount: graphs.length,
|
|
2743
3211
|
graphIds: graphs.map((g) => g.getId())
|
|
@@ -2749,7 +3217,7 @@ var Runner = class _Runner {
|
|
|
2749
3217
|
const result2 = await _Runner.run(graph, messages, options);
|
|
2750
3218
|
return { ...result2, raceIndex: index };
|
|
2751
3219
|
} catch (error) {
|
|
2752
|
-
|
|
3220
|
+
logger10.error(
|
|
2753
3221
|
{
|
|
2754
3222
|
graphId: graph.getId(),
|
|
2755
3223
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2760,7 +3228,7 @@ var Runner = class _Runner {
|
|
|
2760
3228
|
}
|
|
2761
3229
|
});
|
|
2762
3230
|
const result = await Promise.race(promises);
|
|
2763
|
-
|
|
3231
|
+
logger10.info(
|
|
2764
3232
|
{
|
|
2765
3233
|
winningGraphId: result.graphId || "unknown",
|
|
2766
3234
|
raceIndex: result.raceIndex
|
|
@@ -2822,10 +3290,7 @@ var Runner = class _Runner {
|
|
|
2822
3290
|
const defaultAgent = graph.getDefaultAgent();
|
|
2823
3291
|
const messageCount = Array.isArray(messages) ? messages.length : 1;
|
|
2824
3292
|
return {
|
|
2825
|
-
estimatedTurns: Math.min(
|
|
2826
|
-
Math.max(messageCount, 1),
|
|
2827
|
-
options?.maxTurns || 10
|
|
2828
|
-
),
|
|
3293
|
+
estimatedTurns: Math.min(Math.max(messageCount, 1), options?.maxTurns || 10),
|
|
2829
3294
|
estimatedTokens: messageCount * 100,
|
|
2830
3295
|
// Rough estimate
|
|
2831
3296
|
agentCount: agents.length,
|
|
@@ -2837,4 +3302,4 @@ var run = Runner.run.bind(Runner);
|
|
|
2837
3302
|
var stream = Runner.stream.bind(Runner);
|
|
2838
3303
|
var raceGraphs = Runner.raceGraphs.bind(Runner);
|
|
2839
3304
|
|
|
2840
|
-
export { Agent, ArtifactComponent, DataComponent, ExternalAgent, Runner, Tool, agent, agentGraph, agentMcp, artifactComponent, createEnvironmentSettings, credential, dataComponent, externalAgent, externalAgents, mcpServer, mcpTool, raceGraphs, registerEnvironmentSettings, run, stream, transfer };
|
|
3305
|
+
export { Agent, ArtifactComponent, DataComponent, ExternalAgent, Project, Runner, Tool, agent, agentGraph, agentMcp, artifactComponent, createEnvironmentSettings, createFullProjectViaAPI, credential, dataComponent, deleteFullProjectViaAPI, externalAgent, externalAgents, getFullProjectViaAPI, mcpServer, mcpTool, project, raceGraphs, registerEnvironmentSettings, run, stream, transfer, updateFullProjectViaAPI };
|