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