@inkeep/agents-core 0.2.2 → 0.5.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/{chunk-MXQKLGQK.js → chunk-LFWFXR4O.js} +123 -82
- package/dist/{chunk-KNC2AOJM.js → chunk-LPIKPCE5.js} +76 -29
- package/dist/{chunk-BAPMUHVN.js → chunk-XQRFKXVV.js} +20 -12
- package/dist/client-exports.cjs +195 -111
- package/dist/client-exports.js +4 -5
- package/dist/db/schema.cjs +121 -80
- package/dist/db/schema.js +1 -1
- package/dist/index.cjs +650 -644
- package/dist/index.js +436 -527
- package/dist/validation/index.cjs +213 -118
- package/dist/validation/index.js +2 -2
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
|
+
var pino = require('pino');
|
|
5
|
+
var pinoPretty = require('pino-pretty');
|
|
4
6
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
5
7
|
var drizzleZod = require('drizzle-zod');
|
|
6
8
|
var drizzleOrm = require('drizzle-orm');
|
|
@@ -32,6 +34,8 @@ var findUp = require('find-up');
|
|
|
32
34
|
|
|
33
35
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
34
36
|
|
|
37
|
+
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
38
|
+
var pinoPretty__default = /*#__PURE__*/_interopDefault(pinoPretty);
|
|
35
39
|
var jmespath__default = /*#__PURE__*/_interopDefault(jmespath);
|
|
36
40
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
37
41
|
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
@@ -47,33 +51,114 @@ var __export = (target, all) => {
|
|
|
47
51
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
48
52
|
};
|
|
49
53
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var ConsoleLogger = class {
|
|
53
|
-
constructor(name) {
|
|
54
|
+
var PinoLogger = class {
|
|
55
|
+
constructor(name, config = {}) {
|
|
54
56
|
this.name = name;
|
|
57
|
+
__publicField(this, "transportConfigs", []);
|
|
58
|
+
__publicField(this, "pinoInstance");
|
|
59
|
+
__publicField(this, "options");
|
|
60
|
+
this.options = {
|
|
61
|
+
name: this.name,
|
|
62
|
+
level: process.env.LOG_LEVEL || "info",
|
|
63
|
+
serializers: {
|
|
64
|
+
obj: (value) => ({ ...value })
|
|
65
|
+
},
|
|
66
|
+
redact: ["req.headers.authorization", 'req.headers["x-inkeep-admin-authentication"]'],
|
|
67
|
+
...config.options
|
|
68
|
+
};
|
|
69
|
+
if (config.transportConfigs) {
|
|
70
|
+
this.transportConfigs = config.transportConfigs;
|
|
71
|
+
}
|
|
72
|
+
if (this.transportConfigs.length > 0) {
|
|
73
|
+
this.pinoInstance = pino__default.default(this.options, pino__default.default.transport({ targets: this.transportConfigs }));
|
|
74
|
+
} else {
|
|
75
|
+
try {
|
|
76
|
+
const prettyStream = pinoPretty__default.default({
|
|
77
|
+
colorize: true,
|
|
78
|
+
translateTime: "HH:MM:ss",
|
|
79
|
+
ignore: "pid,hostname"
|
|
80
|
+
});
|
|
81
|
+
this.pinoInstance = pino__default.default(this.options, prettyStream);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.warn("Warning: pino-pretty failed, using standard JSON output:", error);
|
|
84
|
+
this.pinoInstance = pino__default.default(this.options);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
55
87
|
}
|
|
56
|
-
|
|
57
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Recreate the pino instance with current transports
|
|
90
|
+
*/
|
|
91
|
+
recreateInstance() {
|
|
92
|
+
if (this.pinoInstance && typeof this.pinoInstance.flush === "function") {
|
|
93
|
+
this.pinoInstance.flush();
|
|
94
|
+
}
|
|
95
|
+
if (this.transportConfigs.length === 0) {
|
|
96
|
+
try {
|
|
97
|
+
const prettyStream = pinoPretty__default.default({
|
|
98
|
+
colorize: true,
|
|
99
|
+
translateTime: "HH:MM:ss",
|
|
100
|
+
ignore: "pid,hostname"
|
|
101
|
+
});
|
|
102
|
+
this.pinoInstance = pino__default.default(this.options, prettyStream);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.warn("Warning: pino-pretty failed, using standard JSON output:", error);
|
|
105
|
+
this.pinoInstance = pino__default.default(this.options);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
const multiTransport = { targets: this.transportConfigs };
|
|
109
|
+
const pinoTransport = pino__default.default.transport(multiTransport);
|
|
110
|
+
this.pinoInstance = pino__default.default(this.options, pinoTransport);
|
|
111
|
+
}
|
|
58
112
|
}
|
|
59
|
-
|
|
60
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Add a new transport to the logger
|
|
115
|
+
*/
|
|
116
|
+
addTransport(transportConfig) {
|
|
117
|
+
this.transportConfigs.push(transportConfig);
|
|
118
|
+
this.recreateInstance();
|
|
61
119
|
}
|
|
62
|
-
|
|
63
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Remove a transport by index
|
|
122
|
+
*/
|
|
123
|
+
removeTransport(index2) {
|
|
124
|
+
if (index2 >= 0 && index2 < this.transportConfigs.length) {
|
|
125
|
+
this.transportConfigs.splice(index2, 1);
|
|
126
|
+
this.recreateInstance();
|
|
127
|
+
}
|
|
64
128
|
}
|
|
65
|
-
|
|
66
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Get current transports
|
|
131
|
+
*/
|
|
132
|
+
getTransports() {
|
|
133
|
+
return [...this.transportConfigs];
|
|
67
134
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Update logger options
|
|
137
|
+
*/
|
|
138
|
+
updateOptions(options) {
|
|
139
|
+
this.options = {
|
|
140
|
+
...this.options,
|
|
141
|
+
...options
|
|
142
|
+
};
|
|
143
|
+
this.recreateInstance();
|
|
71
144
|
}
|
|
72
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Get the underlying pino instance for advanced usage
|
|
147
|
+
*/
|
|
148
|
+
getPinoInstance() {
|
|
149
|
+
return this.pinoInstance;
|
|
73
150
|
}
|
|
74
|
-
|
|
151
|
+
error(data, message) {
|
|
152
|
+
this.pinoInstance.error(data, message);
|
|
75
153
|
}
|
|
76
|
-
|
|
154
|
+
warn(data, message) {
|
|
155
|
+
this.pinoInstance.warn(data, message);
|
|
156
|
+
}
|
|
157
|
+
info(data, message) {
|
|
158
|
+
this.pinoInstance.info(data, message);
|
|
159
|
+
}
|
|
160
|
+
debug(data, message) {
|
|
161
|
+
this.pinoInstance.debug(data, message);
|
|
77
162
|
}
|
|
78
163
|
};
|
|
79
164
|
var LoggerFactory = class {
|
|
@@ -105,7 +190,7 @@ var LoggerFactory = class {
|
|
|
105
190
|
} else if (this.config.defaultLogger) {
|
|
106
191
|
logger11 = this.config.defaultLogger;
|
|
107
192
|
} else {
|
|
108
|
-
logger11 = new
|
|
193
|
+
logger11 = new PinoLogger(name, this.config.pinoConfig);
|
|
109
194
|
}
|
|
110
195
|
this.loggers.set(name, logger11);
|
|
111
196
|
return logger11;
|
|
@@ -122,9 +207,6 @@ var loggerFactory = new LoggerFactory();
|
|
|
122
207
|
function getLogger(name) {
|
|
123
208
|
return loggerFactory.getLogger(name);
|
|
124
209
|
}
|
|
125
|
-
function configureLogging(config) {
|
|
126
|
-
loggerFactory.configure(config);
|
|
127
|
-
}
|
|
128
210
|
|
|
129
211
|
// src/db/schema.ts
|
|
130
212
|
var schema_exports = {};
|
|
@@ -132,6 +214,7 @@ __export(schema_exports, {
|
|
|
132
214
|
agentArtifactComponents: () => agentArtifactComponents,
|
|
133
215
|
agentArtifactComponentsRelations: () => agentArtifactComponentsRelations,
|
|
134
216
|
agentDataComponents: () => agentDataComponents,
|
|
217
|
+
agentDataComponentsRelations: () => agentDataComponentsRelations,
|
|
135
218
|
agentGraph: () => agentGraph,
|
|
136
219
|
agentGraphRelations: () => agentGraphRelations,
|
|
137
220
|
agentRelations: () => agentRelations,
|
|
@@ -153,10 +236,12 @@ __export(schema_exports, {
|
|
|
153
236
|
credentialReferences: () => credentialReferences,
|
|
154
237
|
credentialReferencesRelations: () => credentialReferencesRelations,
|
|
155
238
|
dataComponents: () => dataComponents,
|
|
239
|
+
dataComponentsRelations: () => dataComponentsRelations,
|
|
156
240
|
externalAgents: () => externalAgents,
|
|
157
241
|
externalAgentsRelations: () => externalAgentsRelations,
|
|
158
242
|
ledgerArtifacts: () => ledgerArtifacts,
|
|
159
243
|
ledgerArtifactsContextIdIdx: () => ledgerArtifactsContextIdIdx,
|
|
244
|
+
ledgerArtifactsRelations: () => ledgerArtifactsRelations,
|
|
160
245
|
ledgerArtifactsTaskContextNameUnique: () => ledgerArtifactsTaskContextNameUnique,
|
|
161
246
|
ledgerArtifactsTaskIdIdx: () => ledgerArtifactsTaskIdIdx,
|
|
162
247
|
messages: () => messages,
|
|
@@ -187,11 +272,44 @@ var projects = sqliteCore.sqliteTable(
|
|
|
187
272
|
},
|
|
188
273
|
(table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.id] })]
|
|
189
274
|
);
|
|
275
|
+
var agentGraph = sqliteCore.sqliteTable(
|
|
276
|
+
"agent_graph",
|
|
277
|
+
{
|
|
278
|
+
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
279
|
+
projectId: sqliteCore.text("project_id").notNull(),
|
|
280
|
+
id: sqliteCore.text("id").notNull(),
|
|
281
|
+
name: sqliteCore.text("name").notNull(),
|
|
282
|
+
description: sqliteCore.text("description"),
|
|
283
|
+
defaultAgentId: sqliteCore.text("default_agent_id"),
|
|
284
|
+
// Reference to shared context configuration for all agents in this graph
|
|
285
|
+
contextConfigId: sqliteCore.text("context_config_id"),
|
|
286
|
+
// add fk relationship
|
|
287
|
+
// Graph-level model settingsuration that can be inherited by agents
|
|
288
|
+
models: sqliteCore.text("models", { mode: "json" }).$type(),
|
|
289
|
+
// Status updates configuration for intelligent progress summaries
|
|
290
|
+
statusUpdates: sqliteCore.text("status_updates", { mode: "json" }).$type(),
|
|
291
|
+
// Graph-level prompt that can be used as additional context for agents
|
|
292
|
+
graphPrompt: sqliteCore.text("graph_prompt"),
|
|
293
|
+
// Graph-level stopWhen configuration that can be inherited by agents
|
|
294
|
+
stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
|
|
295
|
+
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
|
|
296
|
+
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
297
|
+
},
|
|
298
|
+
(table) => [
|
|
299
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
300
|
+
sqliteCore.foreignKey({
|
|
301
|
+
columns: [table.tenantId, table.projectId],
|
|
302
|
+
foreignColumns: [projects.tenantId, projects.id],
|
|
303
|
+
name: "agent_graph_project_fk"
|
|
304
|
+
}).onDelete("cascade")
|
|
305
|
+
]
|
|
306
|
+
);
|
|
190
307
|
var contextConfigs = sqliteCore.sqliteTable(
|
|
191
308
|
"context_configs",
|
|
192
309
|
{
|
|
193
310
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
194
311
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
312
|
+
// Add graph level scoping
|
|
195
313
|
id: sqliteCore.text("id").notNull(),
|
|
196
314
|
name: sqliteCore.text("name").notNull(),
|
|
197
315
|
description: sqliteCore.text("description").notNull(),
|
|
@@ -256,6 +374,7 @@ var agents = sqliteCore.sqliteTable(
|
|
|
256
374
|
{
|
|
257
375
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
258
376
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
377
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
259
378
|
id: sqliteCore.text("id").notNull(),
|
|
260
379
|
name: sqliteCore.text("name").notNull(),
|
|
261
380
|
description: sqliteCore.text("description").notNull(),
|
|
@@ -270,11 +389,11 @@ var agents = sqliteCore.sqliteTable(
|
|
|
270
389
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
271
390
|
},
|
|
272
391
|
(table) => [
|
|
273
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
392
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
274
393
|
sqliteCore.foreignKey({
|
|
275
|
-
columns: [table.tenantId, table.projectId],
|
|
276
|
-
foreignColumns: [
|
|
277
|
-
name: "
|
|
394
|
+
columns: [table.tenantId, table.projectId, table.graphId],
|
|
395
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
396
|
+
name: "agents_graph_fk"
|
|
278
397
|
}).onDelete("cascade")
|
|
279
398
|
]
|
|
280
399
|
);
|
|
@@ -283,8 +402,8 @@ var agentRelations = sqliteCore.sqliteTable(
|
|
|
283
402
|
{
|
|
284
403
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
285
404
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
286
|
-
id: sqliteCore.text("id").notNull(),
|
|
287
405
|
graphId: sqliteCore.text("graph_id").notNull(),
|
|
406
|
+
id: sqliteCore.text("id").notNull(),
|
|
288
407
|
sourceAgentId: sqliteCore.text("source_agent_id").notNull(),
|
|
289
408
|
// For internal relationships
|
|
290
409
|
targetAgentId: sqliteCore.text("target_agent_id"),
|
|
@@ -296,11 +415,11 @@ var agentRelations = sqliteCore.sqliteTable(
|
|
|
296
415
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
297
416
|
},
|
|
298
417
|
(table) => [
|
|
299
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
418
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
300
419
|
sqliteCore.foreignKey({
|
|
301
|
-
columns: [table.tenantId, table.projectId],
|
|
302
|
-
foreignColumns: [
|
|
303
|
-
name: "
|
|
420
|
+
columns: [table.tenantId, table.projectId, table.graphId],
|
|
421
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
422
|
+
name: "agent_relations_graph_fk"
|
|
304
423
|
}).onDelete("cascade")
|
|
305
424
|
]
|
|
306
425
|
);
|
|
@@ -309,6 +428,7 @@ var externalAgents = sqliteCore.sqliteTable(
|
|
|
309
428
|
{
|
|
310
429
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
311
430
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
431
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
312
432
|
id: sqliteCore.text("id").notNull(),
|
|
313
433
|
name: sqliteCore.text("name").notNull(),
|
|
314
434
|
description: sqliteCore.text("description").notNull(),
|
|
@@ -320,11 +440,11 @@ var externalAgents = sqliteCore.sqliteTable(
|
|
|
320
440
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
321
441
|
},
|
|
322
442
|
(table) => [
|
|
323
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
443
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
324
444
|
sqliteCore.foreignKey({
|
|
325
|
-
columns: [table.tenantId, table.projectId],
|
|
326
|
-
foreignColumns: [
|
|
327
|
-
name: "
|
|
445
|
+
columns: [table.tenantId, table.projectId, table.graphId],
|
|
446
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
447
|
+
name: "external_agents_graph_fk"
|
|
328
448
|
}).onDelete("cascade"),
|
|
329
449
|
sqliteCore.foreignKey({
|
|
330
450
|
columns: [table.tenantId, table.projectId, table.credentialReferenceId],
|
|
@@ -337,37 +457,6 @@ var externalAgents = sqliteCore.sqliteTable(
|
|
|
337
457
|
}).onDelete("set null")
|
|
338
458
|
]
|
|
339
459
|
);
|
|
340
|
-
var agentGraph = sqliteCore.sqliteTable(
|
|
341
|
-
"agent_graph",
|
|
342
|
-
{
|
|
343
|
-
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
344
|
-
projectId: sqliteCore.text("project_id").notNull(),
|
|
345
|
-
id: sqliteCore.text("id").notNull(),
|
|
346
|
-
name: sqliteCore.text("name").notNull(),
|
|
347
|
-
description: sqliteCore.text("description"),
|
|
348
|
-
defaultAgentId: sqliteCore.text("default_agent_id").notNull(),
|
|
349
|
-
// Reference to shared context configuration for all agents in this graph
|
|
350
|
-
contextConfigId: sqliteCore.text("context_config_id"),
|
|
351
|
-
// Graph-level model settingsuration that can be inherited by agents
|
|
352
|
-
models: sqliteCore.text("models", { mode: "json" }).$type(),
|
|
353
|
-
// Status updates configuration for intelligent progress summaries
|
|
354
|
-
statusUpdates: sqliteCore.text("status_updates", { mode: "json" }).$type(),
|
|
355
|
-
// Graph-level prompt that can be used as additional context for agents
|
|
356
|
-
graphPrompt: sqliteCore.text("graph_prompt"),
|
|
357
|
-
// Graph-level stopWhen configuration that can be inherited by agents
|
|
358
|
-
stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
|
|
359
|
-
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
|
|
360
|
-
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
361
|
-
},
|
|
362
|
-
(table) => [
|
|
363
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
364
|
-
sqliteCore.foreignKey({
|
|
365
|
-
columns: [table.tenantId, table.projectId],
|
|
366
|
-
foreignColumns: [projects.tenantId, projects.id],
|
|
367
|
-
name: "agent_graph_project_fk"
|
|
368
|
-
}).onDelete("cascade")
|
|
369
|
-
]
|
|
370
|
-
);
|
|
371
460
|
var tasks = sqliteCore.sqliteTable(
|
|
372
461
|
"tasks",
|
|
373
462
|
{
|
|
@@ -438,23 +527,18 @@ var agentDataComponents = sqliteCore.sqliteTable(
|
|
|
438
527
|
{
|
|
439
528
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
440
529
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
441
|
-
|
|
530
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
442
531
|
agentId: sqliteCore.text("agent_id").notNull(),
|
|
532
|
+
id: sqliteCore.text("id").notNull(),
|
|
443
533
|
dataComponentId: sqliteCore.text("data_component_id").notNull(),
|
|
444
534
|
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
445
535
|
},
|
|
446
536
|
(table) => [
|
|
447
537
|
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
448
|
-
// Foreign key constraint to
|
|
538
|
+
// Foreign key constraint to agents table (ensures graph and project exist via cascade)
|
|
449
539
|
sqliteCore.foreignKey({
|
|
450
|
-
columns: [table.tenantId, table.projectId],
|
|
451
|
-
foreignColumns: [
|
|
452
|
-
name: "agent_data_components_project_fk"
|
|
453
|
-
}).onDelete("cascade"),
|
|
454
|
-
// Foreign key constraint to agents table
|
|
455
|
-
sqliteCore.foreignKey({
|
|
456
|
-
columns: [table.tenantId, table.projectId, table.agentId],
|
|
457
|
-
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
540
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
|
|
541
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
|
|
458
542
|
name: "agent_data_components_agent_fk"
|
|
459
543
|
}).onDelete("cascade"),
|
|
460
544
|
// Foreign key constraint to data_components table
|
|
@@ -492,23 +576,20 @@ var agentArtifactComponents = sqliteCore.sqliteTable(
|
|
|
492
576
|
{
|
|
493
577
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
494
578
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
495
|
-
|
|
579
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
496
580
|
agentId: sqliteCore.text("agent_id").notNull(),
|
|
581
|
+
id: sqliteCore.text("id").notNull(),
|
|
497
582
|
artifactComponentId: sqliteCore.text("artifact_component_id").notNull(),
|
|
498
583
|
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
499
584
|
},
|
|
500
585
|
(table) => [
|
|
501
|
-
sqliteCore.primaryKey({
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
foreignColumns: [projects.tenantId, projects.id],
|
|
506
|
-
name: "agent_artifact_components_project_fk"
|
|
507
|
-
}).onDelete("cascade"),
|
|
508
|
-
// Foreign key constraint to agents table
|
|
586
|
+
sqliteCore.primaryKey({
|
|
587
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId, table.id]
|
|
588
|
+
}),
|
|
589
|
+
// Foreign key constraint to agents table (ensures graph and project exist via cascade)
|
|
509
590
|
sqliteCore.foreignKey({
|
|
510
|
-
columns: [table.tenantId, table.projectId, table.agentId],
|
|
511
|
-
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
591
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
|
|
592
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
|
|
512
593
|
name: "agent_artifact_components_agent_fk"
|
|
513
594
|
}).onDelete("cascade"),
|
|
514
595
|
// Foreign key constraint to artifact_components table
|
|
@@ -562,25 +643,20 @@ var agentToolRelations = sqliteCore.sqliteTable(
|
|
|
562
643
|
{
|
|
563
644
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
564
645
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
565
|
-
|
|
646
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
566
647
|
agentId: sqliteCore.text("agent_id").notNull(),
|
|
648
|
+
id: sqliteCore.text("id").notNull(),
|
|
567
649
|
toolId: sqliteCore.text("tool_id").notNull(),
|
|
568
650
|
selectedTools: sqliteCore.blob("selected_tools", { mode: "json" }).$type(),
|
|
569
651
|
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
|
|
570
652
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
571
653
|
},
|
|
572
654
|
(table) => [
|
|
573
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
574
|
-
// Foreign key constraint to
|
|
575
|
-
sqliteCore.foreignKey({
|
|
576
|
-
columns: [table.tenantId, table.projectId],
|
|
577
|
-
foreignColumns: [projects.tenantId, projects.id],
|
|
578
|
-
name: "agent_tool_relations_project_fk"
|
|
579
|
-
}).onDelete("cascade"),
|
|
580
|
-
// Foreign key constraint to agents table
|
|
655
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
656
|
+
// Foreign key constraint to agents table (which includes project and graph scope)
|
|
581
657
|
sqliteCore.foreignKey({
|
|
582
|
-
columns: [table.tenantId, table.projectId, table.agentId],
|
|
583
|
-
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
658
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
|
|
659
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
|
|
584
660
|
name: "agent_tool_relations_agent_fk"
|
|
585
661
|
}).onDelete("cascade"),
|
|
586
662
|
// Foreign key constraint to tools table
|
|
@@ -787,7 +863,9 @@ var tasksRelations = drizzleOrm.relations(tasks, ({ one, many }) => ({
|
|
|
787
863
|
references: [agents.id]
|
|
788
864
|
}),
|
|
789
865
|
// A task can have many messages associated with it
|
|
790
|
-
messages: many(messages)
|
|
866
|
+
messages: many(messages),
|
|
867
|
+
// A task can have many ledger artifacts
|
|
868
|
+
ledgerArtifacts: many(ledgerArtifacts)
|
|
791
869
|
}));
|
|
792
870
|
var projectsRelations = drizzleOrm.relations(projects, ({ many }) => ({
|
|
793
871
|
// A project can have many agents
|
|
@@ -803,7 +881,15 @@ var projectsRelations = drizzleOrm.relations(projects, ({ many }) => ({
|
|
|
803
881
|
// A project can have many conversations
|
|
804
882
|
conversations: many(conversations),
|
|
805
883
|
// A project can have many tasks
|
|
806
|
-
tasks: many(tasks)
|
|
884
|
+
tasks: many(tasks),
|
|
885
|
+
// A project can have many data components
|
|
886
|
+
dataComponents: many(dataComponents),
|
|
887
|
+
// A project can have many artifact components
|
|
888
|
+
artifactComponents: many(artifactComponents),
|
|
889
|
+
// A project can have many ledger artifacts
|
|
890
|
+
ledgerArtifacts: many(ledgerArtifacts),
|
|
891
|
+
// A project can have many credential references
|
|
892
|
+
credentialReferences: many(credentialReferences)
|
|
807
893
|
}));
|
|
808
894
|
var taskRelationsRelations = drizzleOrm.relations(taskRelations, ({ one }) => ({
|
|
809
895
|
// Each relation has one parent task
|
|
@@ -865,7 +951,11 @@ var agentsRelations = drizzleOrm.relations(agents, ({ many, one }) => ({
|
|
|
865
951
|
associatedMessages: many(messages, {
|
|
866
952
|
relationName: "associatedAgent"
|
|
867
953
|
}),
|
|
868
|
-
toolRelations: many(agentToolRelations)
|
|
954
|
+
toolRelations: many(agentToolRelations),
|
|
955
|
+
// Data component relations
|
|
956
|
+
dataComponentRelations: many(agentDataComponents),
|
|
957
|
+
// Artifact component relations
|
|
958
|
+
artifactComponentRelations: many(agentArtifactComponents)
|
|
869
959
|
}));
|
|
870
960
|
var agentGraphRelations = drizzleOrm.relations(agentGraph, ({ one }) => ({
|
|
871
961
|
// An agent graph belongs to one project
|
|
@@ -873,7 +963,7 @@ var agentGraphRelations = drizzleOrm.relations(agentGraph, ({ one }) => ({
|
|
|
873
963
|
fields: [agentGraph.tenantId, agentGraph.projectId],
|
|
874
964
|
references: [projects.tenantId, projects.id]
|
|
875
965
|
}),
|
|
876
|
-
// An agent graph
|
|
966
|
+
// An agent graph may have one default agent (optional)
|
|
877
967
|
defaultAgent: one(agents, {
|
|
878
968
|
fields: [agentGraph.defaultAgentId],
|
|
879
969
|
references: [agents.id]
|
|
@@ -1021,6 +1111,39 @@ var agentArtifactComponentsRelations = drizzleOrm.relations(agentArtifactCompone
|
|
|
1021
1111
|
references: [artifactComponents.id]
|
|
1022
1112
|
})
|
|
1023
1113
|
}));
|
|
1114
|
+
var dataComponentsRelations = drizzleOrm.relations(dataComponents, ({ many, one }) => ({
|
|
1115
|
+
// A data component belongs to one project
|
|
1116
|
+
project: one(projects, {
|
|
1117
|
+
fields: [dataComponents.tenantId, dataComponents.projectId],
|
|
1118
|
+
references: [projects.tenantId, projects.id]
|
|
1119
|
+
}),
|
|
1120
|
+
// A data component can be associated with many agents
|
|
1121
|
+
agentRelations: many(agentDataComponents)
|
|
1122
|
+
}));
|
|
1123
|
+
var agentDataComponentsRelations = drizzleOrm.relations(agentDataComponents, ({ one }) => ({
|
|
1124
|
+
// An agent-data component relation belongs to one agent
|
|
1125
|
+
agent: one(agents, {
|
|
1126
|
+
fields: [agentDataComponents.agentId],
|
|
1127
|
+
references: [agents.id]
|
|
1128
|
+
}),
|
|
1129
|
+
// An agent-data component relation belongs to one data component
|
|
1130
|
+
dataComponent: one(dataComponents, {
|
|
1131
|
+
fields: [agentDataComponents.dataComponentId],
|
|
1132
|
+
references: [dataComponents.id]
|
|
1133
|
+
})
|
|
1134
|
+
}));
|
|
1135
|
+
var ledgerArtifactsRelations = drizzleOrm.relations(ledgerArtifacts, ({ one }) => ({
|
|
1136
|
+
// A ledger artifact belongs to one project
|
|
1137
|
+
project: one(projects, {
|
|
1138
|
+
fields: [ledgerArtifacts.tenantId, ledgerArtifacts.projectId],
|
|
1139
|
+
references: [projects.tenantId, projects.id]
|
|
1140
|
+
}),
|
|
1141
|
+
// A ledger artifact may be associated with one task
|
|
1142
|
+
task: one(tasks, {
|
|
1143
|
+
fields: [ledgerArtifacts.taskId],
|
|
1144
|
+
references: [tasks.id]
|
|
1145
|
+
})
|
|
1146
|
+
}));
|
|
1024
1147
|
var agentRelationsRelations = drizzleOrm.relations(agentRelations, ({ one }) => ({
|
|
1025
1148
|
// An agent relation belongs to one graph
|
|
1026
1149
|
graph: one(agentGraph, {
|
|
@@ -1102,15 +1225,18 @@ var ProjectModelSchema = zodOpenapi.z.object({
|
|
|
1102
1225
|
var createApiSchema = (schema) => schema.omit({ tenantId: true, projectId: true });
|
|
1103
1226
|
var createApiInsertSchema = (schema) => schema.omit({ tenantId: true, projectId: true });
|
|
1104
1227
|
var createApiUpdateSchema = (schema) => schema.omit({ tenantId: true, projectId: true }).partial();
|
|
1228
|
+
var createGraphScopedApiSchema = (schema) => schema.omit({ tenantId: true, projectId: true, graphId: true });
|
|
1229
|
+
var createGraphScopedApiInsertSchema = (schema) => schema.omit({ tenantId: true, projectId: true, graphId: true });
|
|
1230
|
+
var createGraphScopedApiUpdateSchema = (schema) => schema.omit({ tenantId: true, projectId: true, graphId: true }).partial();
|
|
1105
1231
|
var AgentSelectSchema = drizzleZod.createSelectSchema(agents);
|
|
1106
1232
|
var AgentInsertSchema = drizzleZod.createInsertSchema(agents).extend({
|
|
1107
1233
|
id: resourceIdSchema,
|
|
1108
1234
|
models: ModelSchema.optional()
|
|
1109
1235
|
});
|
|
1110
1236
|
var AgentUpdateSchema = AgentInsertSchema.partial();
|
|
1111
|
-
var AgentApiSelectSchema =
|
|
1112
|
-
var AgentApiInsertSchema =
|
|
1113
|
-
var AgentApiUpdateSchema =
|
|
1237
|
+
var AgentApiSelectSchema = createGraphScopedApiSchema(AgentSelectSchema);
|
|
1238
|
+
var AgentApiInsertSchema = createGraphScopedApiInsertSchema(AgentInsertSchema);
|
|
1239
|
+
var AgentApiUpdateSchema = createGraphScopedApiUpdateSchema(AgentUpdateSchema);
|
|
1114
1240
|
var AgentRelationSelectSchema = drizzleZod.createSelectSchema(agentRelations);
|
|
1115
1241
|
var AgentRelationInsertSchema = drizzleZod.createInsertSchema(agentRelations).extend({
|
|
1116
1242
|
id: resourceIdSchema,
|
|
@@ -1120,8 +1246,10 @@ var AgentRelationInsertSchema = drizzleZod.createInsertSchema(agentRelations).ex
|
|
|
1120
1246
|
externalAgentId: resourceIdSchema.optional()
|
|
1121
1247
|
});
|
|
1122
1248
|
var AgentRelationUpdateSchema = AgentRelationInsertSchema.partial();
|
|
1123
|
-
var AgentRelationApiSelectSchema =
|
|
1124
|
-
var AgentRelationApiInsertSchema =
|
|
1249
|
+
var AgentRelationApiSelectSchema = createGraphScopedApiSchema(AgentRelationSelectSchema);
|
|
1250
|
+
var AgentRelationApiInsertSchema = createGraphScopedApiInsertSchema(
|
|
1251
|
+
AgentRelationInsertSchema
|
|
1252
|
+
).extend({
|
|
1125
1253
|
relationType: zodOpenapi.z.enum(VALID_RELATION_TYPES)
|
|
1126
1254
|
}).refine(
|
|
1127
1255
|
(data) => {
|
|
@@ -1134,7 +1262,9 @@ var AgentRelationApiInsertSchema = createApiInsertSchema(AgentRelationInsertSche
|
|
|
1134
1262
|
path: ["targetAgentId", "externalAgentId"]
|
|
1135
1263
|
}
|
|
1136
1264
|
);
|
|
1137
|
-
var AgentRelationApiUpdateSchema =
|
|
1265
|
+
var AgentRelationApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1266
|
+
AgentRelationUpdateSchema
|
|
1267
|
+
).extend({
|
|
1138
1268
|
relationType: zodOpenapi.z.enum(VALID_RELATION_TYPES).optional()
|
|
1139
1269
|
}).refine(
|
|
1140
1270
|
(data) => {
|
|
@@ -1171,7 +1301,7 @@ var AgentGraphInsertSchema = drizzleZod.createInsertSchema(agentGraph).extend({
|
|
|
1171
1301
|
var AgentGraphUpdateSchema = AgentGraphInsertSchema.partial();
|
|
1172
1302
|
var AgentGraphApiSelectSchema = createApiSchema(AgentGraphSelectSchema);
|
|
1173
1303
|
var AgentGraphApiInsertSchema = createApiInsertSchema(AgentGraphInsertSchema).extend({
|
|
1174
|
-
id: resourceIdSchema
|
|
1304
|
+
id: resourceIdSchema
|
|
1175
1305
|
});
|
|
1176
1306
|
var AgentGraphApiUpdateSchema = createApiUpdateSchema(AgentGraphUpdateSchema);
|
|
1177
1307
|
var TaskSelectSchema = drizzleZod.createSelectSchema(tasks);
|
|
@@ -1270,11 +1400,16 @@ var DataComponentApiUpdateSchema = createApiUpdateSchema(DataComponentUpdateSche
|
|
|
1270
1400
|
var AgentDataComponentSelectSchema = drizzleZod.createSelectSchema(agentDataComponents);
|
|
1271
1401
|
var AgentDataComponentInsertSchema = drizzleZod.createInsertSchema(agentDataComponents);
|
|
1272
1402
|
var AgentDataComponentUpdateSchema = AgentDataComponentInsertSchema.partial();
|
|
1273
|
-
var AgentDataComponentApiSelectSchema =
|
|
1274
|
-
|
|
1275
|
-
AgentDataComponentInsertSchema
|
|
1403
|
+
var AgentDataComponentApiSelectSchema = createGraphScopedApiSchema(
|
|
1404
|
+
AgentDataComponentSelectSchema
|
|
1276
1405
|
);
|
|
1277
|
-
var
|
|
1406
|
+
var AgentDataComponentApiInsertSchema = AgentDataComponentInsertSchema.omit({
|
|
1407
|
+
tenantId: true,
|
|
1408
|
+
projectId: true,
|
|
1409
|
+
id: true,
|
|
1410
|
+
createdAt: true
|
|
1411
|
+
});
|
|
1412
|
+
var AgentDataComponentApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1278
1413
|
AgentDataComponentUpdateSchema
|
|
1279
1414
|
);
|
|
1280
1415
|
var ArtifactComponentSelectSchema = drizzleZod.createSelectSchema(artifactComponents);
|
|
@@ -1303,7 +1438,7 @@ var AgentArtifactComponentInsertSchema = drizzleZod.createInsertSchema(
|
|
|
1303
1438
|
artifactComponentId: resourceIdSchema
|
|
1304
1439
|
});
|
|
1305
1440
|
var AgentArtifactComponentUpdateSchema = AgentArtifactComponentInsertSchema.partial();
|
|
1306
|
-
var AgentArtifactComponentApiSelectSchema =
|
|
1441
|
+
var AgentArtifactComponentApiSelectSchema = createGraphScopedApiSchema(
|
|
1307
1442
|
AgentArtifactComponentSelectSchema
|
|
1308
1443
|
);
|
|
1309
1444
|
var AgentArtifactComponentApiInsertSchema = AgentArtifactComponentInsertSchema.omit({
|
|
@@ -1312,7 +1447,7 @@ var AgentArtifactComponentApiInsertSchema = AgentArtifactComponentInsertSchema.o
|
|
|
1312
1447
|
id: true,
|
|
1313
1448
|
createdAt: true
|
|
1314
1449
|
});
|
|
1315
|
-
var AgentArtifactComponentApiUpdateSchema =
|
|
1450
|
+
var AgentArtifactComponentApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1316
1451
|
AgentArtifactComponentUpdateSchema
|
|
1317
1452
|
);
|
|
1318
1453
|
var ExternalAgentSelectSchema = drizzleZod.createSelectSchema(externalAgents).extend({
|
|
@@ -1323,9 +1458,9 @@ var ExternalAgentInsertSchema = drizzleZod.createInsertSchema(externalAgents).ex
|
|
|
1323
1458
|
id: resourceIdSchema
|
|
1324
1459
|
});
|
|
1325
1460
|
var ExternalAgentUpdateSchema = ExternalAgentInsertSchema.partial();
|
|
1326
|
-
var ExternalAgentApiSelectSchema =
|
|
1327
|
-
var ExternalAgentApiInsertSchema =
|
|
1328
|
-
var ExternalAgentApiUpdateSchema =
|
|
1461
|
+
var ExternalAgentApiSelectSchema = createGraphScopedApiSchema(ExternalAgentSelectSchema);
|
|
1462
|
+
var ExternalAgentApiInsertSchema = createGraphScopedApiInsertSchema(ExternalAgentInsertSchema);
|
|
1463
|
+
var ExternalAgentApiUpdateSchema = createGraphScopedApiUpdateSchema(ExternalAgentUpdateSchema);
|
|
1329
1464
|
var AllAgentSchema = zodOpenapi.z.discriminatedUnion("type", [
|
|
1330
1465
|
AgentApiSelectSchema.extend({ type: zodOpenapi.z.literal("internal") }),
|
|
1331
1466
|
ExternalAgentApiSelectSchema.extend({ type: zodOpenapi.z.literal("external") })
|
|
@@ -1381,10 +1516,8 @@ var CredentialReferenceSelectSchema = zodOpenapi.z.object({
|
|
|
1381
1516
|
createdAt: zodOpenapi.z.string(),
|
|
1382
1517
|
updatedAt: zodOpenapi.z.string()
|
|
1383
1518
|
});
|
|
1384
|
-
var CredentialReferenceInsertSchema =
|
|
1519
|
+
var CredentialReferenceInsertSchema = drizzleZod.createInsertSchema(credentialReferences).extend({
|
|
1385
1520
|
id: resourceIdSchema,
|
|
1386
|
-
tenantId: zodOpenapi.z.string(),
|
|
1387
|
-
projectId: zodOpenapi.z.string(),
|
|
1388
1521
|
type: zodOpenapi.z.string(),
|
|
1389
1522
|
credentialStoreId: resourceIdSchema,
|
|
1390
1523
|
retrievalParams: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown()).nullish()
|
|
@@ -1480,11 +1613,13 @@ var AgentToolRelationInsertSchema = drizzleZod.createInsertSchema(agentToolRelat
|
|
|
1480
1613
|
selectedTools: zodOpenapi.z.array(zodOpenapi.z.string()).nullish()
|
|
1481
1614
|
});
|
|
1482
1615
|
var AgentToolRelationUpdateSchema = AgentToolRelationInsertSchema.partial();
|
|
1483
|
-
var AgentToolRelationApiSelectSchema =
|
|
1484
|
-
|
|
1616
|
+
var AgentToolRelationApiSelectSchema = createGraphScopedApiSchema(
|
|
1617
|
+
AgentToolRelationSelectSchema
|
|
1618
|
+
);
|
|
1619
|
+
var AgentToolRelationApiInsertSchema = createGraphScopedApiInsertSchema(
|
|
1485
1620
|
AgentToolRelationInsertSchema
|
|
1486
1621
|
);
|
|
1487
|
-
var AgentToolRelationApiUpdateSchema =
|
|
1622
|
+
var AgentToolRelationApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1488
1623
|
AgentToolRelationUpdateSchema
|
|
1489
1624
|
);
|
|
1490
1625
|
var LedgerArtifactSelectSchema = drizzleZod.createSelectSchema(ledgerArtifacts);
|
|
@@ -1510,6 +1645,7 @@ var StatusUpdateSchema = zodOpenapi.z.object({
|
|
|
1510
1645
|
statusComponents: zodOpenapi.z.array(StatusComponentSchema).optional()
|
|
1511
1646
|
});
|
|
1512
1647
|
var FullGraphAgentInsertSchema = AgentApiInsertSchema.extend({
|
|
1648
|
+
type: zodOpenapi.z.literal("internal"),
|
|
1513
1649
|
tools: zodOpenapi.z.array(zodOpenapi.z.string()),
|
|
1514
1650
|
selectedTools: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.array(zodOpenapi.z.string())).optional(),
|
|
1515
1651
|
dataComponents: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
|
|
@@ -1519,10 +1655,9 @@ var FullGraphAgentInsertSchema = AgentApiInsertSchema.extend({
|
|
|
1519
1655
|
});
|
|
1520
1656
|
var FullGraphDefinitionSchema = AgentGraphApiInsertSchema.extend({
|
|
1521
1657
|
agents: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.union([FullGraphAgentInsertSchema, ExternalAgentApiInsertSchema])),
|
|
1522
|
-
|
|
1523
|
-
credentialReferences
|
|
1524
|
-
|
|
1525
|
-
artifactComponents: zodOpenapi.z.record(zodOpenapi.z.string(), ArtifactComponentApiInsertSchema).optional(),
|
|
1658
|
+
// Removed project-scoped resources - these are now managed at project level:
|
|
1659
|
+
// tools, credentialReferences, dataComponents, artifactComponents
|
|
1660
|
+
// Agent relationships to these resources are maintained via agent.tools, agent.dataComponents, etc.
|
|
1526
1661
|
contextConfig: zodOpenapi.z.optional(ContextConfigApiInsertSchema),
|
|
1527
1662
|
statusUpdates: zodOpenapi.z.optional(StatusUpdateSchema),
|
|
1528
1663
|
models: ModelSchema.optional(),
|
|
@@ -1530,7 +1665,13 @@ var FullGraphDefinitionSchema = AgentGraphApiInsertSchema.extend({
|
|
|
1530
1665
|
graphPrompt: zodOpenapi.z.string().max(5e3, "Graph prompt cannot exceed 5000 characters").optional()
|
|
1531
1666
|
});
|
|
1532
1667
|
var GraphWithinContextOfProjectSchema = AgentGraphApiInsertSchema.extend({
|
|
1533
|
-
agents: zodOpenapi.z.record(
|
|
1668
|
+
agents: zodOpenapi.z.record(
|
|
1669
|
+
zodOpenapi.z.string(),
|
|
1670
|
+
zodOpenapi.z.discriminatedUnion("type", [
|
|
1671
|
+
FullGraphAgentInsertSchema,
|
|
1672
|
+
ExternalAgentApiInsertSchema.extend({ type: zodOpenapi.z.literal("external") })
|
|
1673
|
+
])
|
|
1674
|
+
),
|
|
1534
1675
|
models: ModelSchema.optional(),
|
|
1535
1676
|
stopWhen: GraphStopWhenSchema.optional(),
|
|
1536
1677
|
graphPrompt: zodOpenapi.z.string().max(5e3, "Graph prompt cannot exceed 5000 characters").optional()
|
|
@@ -1613,6 +1754,35 @@ var TenantProjectParamsSchema = zodOpenapi.z.object({
|
|
|
1613
1754
|
example: "project_456"
|
|
1614
1755
|
})
|
|
1615
1756
|
}).openapi("TenantProjectParams");
|
|
1757
|
+
var TenantProjectGraphParamsSchema = zodOpenapi.z.object({
|
|
1758
|
+
tenantId: zodOpenapi.z.string().openapi({
|
|
1759
|
+
description: "Tenant identifier",
|
|
1760
|
+
example: "tenant_123"
|
|
1761
|
+
}),
|
|
1762
|
+
projectId: zodOpenapi.z.string().openapi({
|
|
1763
|
+
description: "Project identifier",
|
|
1764
|
+
example: "project_456"
|
|
1765
|
+
}),
|
|
1766
|
+
graphId: zodOpenapi.z.string().openapi({
|
|
1767
|
+
description: "Graph identifier",
|
|
1768
|
+
example: "graph_789"
|
|
1769
|
+
})
|
|
1770
|
+
}).openapi("TenantProjectGraphParams");
|
|
1771
|
+
var TenantProjectGraphIdParamsSchema = zodOpenapi.z.object({
|
|
1772
|
+
tenantId: zodOpenapi.z.string().openapi({
|
|
1773
|
+
description: "Tenant identifier",
|
|
1774
|
+
example: "tenant_123"
|
|
1775
|
+
}),
|
|
1776
|
+
projectId: zodOpenapi.z.string().openapi({
|
|
1777
|
+
description: "Project identifier",
|
|
1778
|
+
example: "project_456"
|
|
1779
|
+
}),
|
|
1780
|
+
graphId: zodOpenapi.z.string().openapi({
|
|
1781
|
+
description: "Graph identifier",
|
|
1782
|
+
example: "graph_789"
|
|
1783
|
+
}),
|
|
1784
|
+
id: resourceIdSchema
|
|
1785
|
+
}).openapi("TenantProjectGraphIdParams");
|
|
1616
1786
|
var TenantProjectIdParamsSchema = zodOpenapi.z.object({
|
|
1617
1787
|
tenantId: zodOpenapi.z.string().openapi({
|
|
1618
1788
|
description: "Tenant identifier",
|
|
@@ -2329,6 +2499,7 @@ var getAgentRelationById = (db) => async (params) => {
|
|
|
2329
2499
|
where: drizzleOrm.and(
|
|
2330
2500
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2331
2501
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2502
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2332
2503
|
drizzleOrm.eq(agentRelations.id, params.relationId)
|
|
2333
2504
|
)
|
|
2334
2505
|
});
|
|
@@ -2339,7 +2510,8 @@ var listAgentRelations = (db) => async (params) => {
|
|
|
2339
2510
|
const offset = (page - 1) * limit;
|
|
2340
2511
|
const whereClause = drizzleOrm.and(
|
|
2341
2512
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2342
|
-
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId)
|
|
2513
|
+
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2514
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
2343
2515
|
);
|
|
2344
2516
|
const [data, totalResult] = await Promise.all([
|
|
2345
2517
|
db.select().from(agentRelations).where(whereClause).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentRelations.createdAt)),
|
|
@@ -2354,8 +2526,8 @@ var getAgentRelations = (db) => async (params) => {
|
|
|
2354
2526
|
where: drizzleOrm.and(
|
|
2355
2527
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2356
2528
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2357
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2358
|
-
drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId)
|
|
2529
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2530
|
+
drizzleOrm.eq(agentRelations.sourceAgentId, params.scopes.agentId)
|
|
2359
2531
|
)
|
|
2360
2532
|
});
|
|
2361
2533
|
};
|
|
@@ -2364,7 +2536,7 @@ var getAgentRelationsByGraph = (db) => async (params) => {
|
|
|
2364
2536
|
where: drizzleOrm.and(
|
|
2365
2537
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2366
2538
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2367
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
2539
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
2368
2540
|
)
|
|
2369
2541
|
});
|
|
2370
2542
|
};
|
|
@@ -2375,6 +2547,7 @@ var getAgentRelationsBySource = (db) => async (params) => {
|
|
|
2375
2547
|
const whereClause = drizzleOrm.and(
|
|
2376
2548
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2377
2549
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2550
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2378
2551
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.sourceAgentId)
|
|
2379
2552
|
);
|
|
2380
2553
|
const [data, totalResult] = await Promise.all([
|
|
@@ -2395,6 +2568,7 @@ var getAgentRelationsByTarget = (db) => async (params) => {
|
|
|
2395
2568
|
const whereClause = drizzleOrm.and(
|
|
2396
2569
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2397
2570
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2571
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2398
2572
|
drizzleOrm.eq(agentRelations.targetAgentId, params.targetAgentId)
|
|
2399
2573
|
);
|
|
2400
2574
|
const [data, totalResult] = await Promise.all([
|
|
@@ -2415,6 +2589,7 @@ var getExternalAgentRelations = (db) => async (params) => {
|
|
|
2415
2589
|
const whereClause = drizzleOrm.and(
|
|
2416
2590
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2417
2591
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2592
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2418
2593
|
drizzleOrm.eq(agentRelations.externalAgentId, params.externalAgentId)
|
|
2419
2594
|
);
|
|
2420
2595
|
const [data, totalResult] = await Promise.all([
|
|
@@ -2438,11 +2613,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
2438
2613
|
drizzleOrm.and(
|
|
2439
2614
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2440
2615
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2441
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2616
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2442
2617
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId),
|
|
2443
2618
|
drizzleOrm.isNotNull(agentRelations.targetAgentId),
|
|
2444
2619
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2445
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId)
|
|
2620
|
+
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2621
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId)
|
|
2446
2622
|
)
|
|
2447
2623
|
);
|
|
2448
2624
|
const externalRelations = await db.select({
|
|
@@ -2458,11 +2634,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
2458
2634
|
drizzleOrm.and(
|
|
2459
2635
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2460
2636
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2461
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2637
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2462
2638
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId),
|
|
2463
2639
|
drizzleOrm.isNotNull(agentRelations.externalAgentId),
|
|
2464
2640
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
2465
|
-
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId)
|
|
2641
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
2642
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
2466
2643
|
)
|
|
2467
2644
|
);
|
|
2468
2645
|
return {
|
|
@@ -2488,7 +2665,7 @@ var getAgentRelationByParams = (db) => async (params) => {
|
|
|
2488
2665
|
const whereConditions = [
|
|
2489
2666
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2490
2667
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2491
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2668
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2492
2669
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.sourceAgentId),
|
|
2493
2670
|
drizzleOrm.eq(agentRelations.relationType, params.relationType)
|
|
2494
2671
|
];
|
|
@@ -2504,8 +2681,7 @@ var getAgentRelationByParams = (db) => async (params) => {
|
|
|
2504
2681
|
};
|
|
2505
2682
|
var upsertAgentRelation = (db) => async (params) => {
|
|
2506
2683
|
const existing = await getAgentRelationByParams(db)({
|
|
2507
|
-
scopes: { tenantId: params.tenantId, projectId: params.projectId },
|
|
2508
|
-
graphId: params.graphId,
|
|
2684
|
+
scopes: { tenantId: params.tenantId, projectId: params.projectId, graphId: params.graphId },
|
|
2509
2685
|
sourceAgentId: params.sourceAgentId,
|
|
2510
2686
|
targetAgentId: params.targetAgentId,
|
|
2511
2687
|
externalAgentId: params.externalAgentId,
|
|
@@ -2531,6 +2707,7 @@ var updateAgentRelation = (db) => async (params) => {
|
|
|
2531
2707
|
drizzleOrm.and(
|
|
2532
2708
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2533
2709
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2710
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2534
2711
|
drizzleOrm.eq(agentRelations.id, params.relationId)
|
|
2535
2712
|
)
|
|
2536
2713
|
).returning();
|
|
@@ -2541,6 +2718,7 @@ var deleteAgentRelation = (db) => async (params) => {
|
|
|
2541
2718
|
drizzleOrm.and(
|
|
2542
2719
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2543
2720
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2721
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2544
2722
|
drizzleOrm.eq(agentRelations.id, params.relationId)
|
|
2545
2723
|
)
|
|
2546
2724
|
);
|
|
@@ -2550,7 +2728,7 @@ var deleteAgentRelationsByGraph = (db) => async (params) => {
|
|
|
2550
2728
|
const result = await db.delete(agentRelations).where(
|
|
2551
2729
|
drizzleOrm.and(
|
|
2552
2730
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2553
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
2731
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
2554
2732
|
)
|
|
2555
2733
|
);
|
|
2556
2734
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -2561,6 +2739,7 @@ var createAgentToolRelation = (db) => async (params) => {
|
|
|
2561
2739
|
id: finalRelationId,
|
|
2562
2740
|
tenantId: params.scopes.tenantId,
|
|
2563
2741
|
projectId: params.scopes.projectId,
|
|
2742
|
+
graphId: params.scopes.graphId,
|
|
2564
2743
|
agentId: params.data.agentId,
|
|
2565
2744
|
toolId: params.data.toolId,
|
|
2566
2745
|
selectedTools: params.data.selectedTools
|
|
@@ -2576,6 +2755,7 @@ var updateAgentToolRelation = (db) => async (params) => {
|
|
|
2576
2755
|
drizzleOrm.and(
|
|
2577
2756
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2578
2757
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2758
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2579
2759
|
drizzleOrm.eq(agentToolRelations.id, params.relationId)
|
|
2580
2760
|
)
|
|
2581
2761
|
).returning();
|
|
@@ -2586,6 +2766,7 @@ var deleteAgentToolRelation = (db) => async (params) => {
|
|
|
2586
2766
|
drizzleOrm.and(
|
|
2587
2767
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2588
2768
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2769
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2589
2770
|
drizzleOrm.eq(agentToolRelations.id, params.relationId)
|
|
2590
2771
|
)
|
|
2591
2772
|
);
|
|
@@ -2595,7 +2776,9 @@ var deleteAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
2595
2776
|
const result = await db.delete(agentToolRelations).where(
|
|
2596
2777
|
drizzleOrm.and(
|
|
2597
2778
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2598
|
-
drizzleOrm.eq(agentToolRelations.
|
|
2779
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2780
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2781
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2599
2782
|
)
|
|
2600
2783
|
);
|
|
2601
2784
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -2605,6 +2788,7 @@ var getAgentToolRelationById = (db) => async (params) => {
|
|
|
2605
2788
|
where: drizzleOrm.and(
|
|
2606
2789
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2607
2790
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2791
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2608
2792
|
drizzleOrm.eq(agentToolRelations.id, params.relationId)
|
|
2609
2793
|
)
|
|
2610
2794
|
});
|
|
@@ -2618,14 +2802,14 @@ var getAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
2618
2802
|
drizzleOrm.and(
|
|
2619
2803
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2620
2804
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2621
|
-
drizzleOrm.eq(agentToolRelations.agentId, params.agentId)
|
|
2805
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2622
2806
|
)
|
|
2623
2807
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2624
2808
|
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(
|
|
2625
2809
|
drizzleOrm.and(
|
|
2626
2810
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2627
2811
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2628
|
-
drizzleOrm.eq(agentToolRelations.agentId, params.agentId)
|
|
2812
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2629
2813
|
)
|
|
2630
2814
|
)
|
|
2631
2815
|
]);
|
|
@@ -2645,6 +2829,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
2645
2829
|
drizzleOrm.and(
|
|
2646
2830
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2647
2831
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2832
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2648
2833
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2649
2834
|
)
|
|
2650
2835
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
@@ -2652,6 +2837,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
2652
2837
|
drizzleOrm.and(
|
|
2653
2838
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2654
2839
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2840
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2655
2841
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2656
2842
|
)
|
|
2657
2843
|
)
|
|
@@ -2671,13 +2857,15 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
2671
2857
|
db.select().from(agentToolRelations).where(
|
|
2672
2858
|
drizzleOrm.and(
|
|
2673
2859
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2674
|
-
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId)
|
|
2860
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2861
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId)
|
|
2675
2862
|
)
|
|
2676
2863
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2677
2864
|
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(
|
|
2678
2865
|
drizzleOrm.and(
|
|
2679
2866
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2680
|
-
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId)
|
|
2867
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2868
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId)
|
|
2681
2869
|
)
|
|
2682
2870
|
)
|
|
2683
2871
|
]);
|
|
@@ -2688,26 +2876,6 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
2688
2876
|
pagination: { page, limit, total, pages }
|
|
2689
2877
|
};
|
|
2690
2878
|
};
|
|
2691
|
-
var listAgentToolRelationsByAgent = (db) => async (params) => {
|
|
2692
|
-
const page = params.pagination?.page || 1;
|
|
2693
|
-
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
2694
|
-
const offset = (page - 1) * limit;
|
|
2695
|
-
const whereClause = drizzleOrm.and(
|
|
2696
|
-
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2697
|
-
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2698
|
-
drizzleOrm.eq(agentToolRelations.agentId, params.agentId)
|
|
2699
|
-
);
|
|
2700
|
-
const [data, totalResult] = await Promise.all([
|
|
2701
|
-
db.select().from(agentToolRelations).where(whereClause).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2702
|
-
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(whereClause)
|
|
2703
|
-
]);
|
|
2704
|
-
const total = totalResult[0]?.count || 0;
|
|
2705
|
-
const pages = Math.ceil(total / limit);
|
|
2706
|
-
return {
|
|
2707
|
-
data,
|
|
2708
|
-
pagination: { page, limit, total, pages }
|
|
2709
|
-
};
|
|
2710
|
-
};
|
|
2711
2879
|
var getToolsForAgent = (db) => async (params) => {
|
|
2712
2880
|
const page = params.pagination?.page || 1;
|
|
2713
2881
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
@@ -2738,14 +2906,16 @@ var getToolsForAgent = (db) => async (params) => {
|
|
|
2738
2906
|
drizzleOrm.and(
|
|
2739
2907
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2740
2908
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2741
|
-
drizzleOrm.eq(agentToolRelations.
|
|
2909
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2910
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2742
2911
|
)
|
|
2743
2912
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2744
2913
|
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(
|
|
2745
2914
|
drizzleOrm.and(
|
|
2746
2915
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2747
2916
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2748
|
-
drizzleOrm.eq(agentToolRelations.
|
|
2917
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2918
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2749
2919
|
)
|
|
2750
2920
|
)
|
|
2751
2921
|
]);
|
|
@@ -2774,6 +2944,9 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
2774
2944
|
name: agents.name,
|
|
2775
2945
|
description: agents.description,
|
|
2776
2946
|
prompt: agents.prompt,
|
|
2947
|
+
conversationHistoryConfig: agents.conversationHistoryConfig,
|
|
2948
|
+
models: agents.models,
|
|
2949
|
+
stopWhen: agents.stopWhen,
|
|
2777
2950
|
createdAt: agents.createdAt,
|
|
2778
2951
|
updatedAt: agents.updatedAt
|
|
2779
2952
|
}
|
|
@@ -2781,6 +2954,7 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
2781
2954
|
drizzleOrm.and(
|
|
2782
2955
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2783
2956
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2957
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2784
2958
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2785
2959
|
)
|
|
2786
2960
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
@@ -2788,6 +2962,7 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
2788
2962
|
drizzleOrm.and(
|
|
2789
2963
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2790
2964
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2965
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2791
2966
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2792
2967
|
)
|
|
2793
2968
|
)
|
|
@@ -2804,7 +2979,8 @@ var validateInternalAgent = (db) => async (params) => {
|
|
|
2804
2979
|
drizzleOrm.and(
|
|
2805
2980
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2806
2981
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2807
|
-
drizzleOrm.eq(agents.
|
|
2982
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2983
|
+
drizzleOrm.eq(agents.id, params.scopes.agentId)
|
|
2808
2984
|
)
|
|
2809
2985
|
).limit(1);
|
|
2810
2986
|
return result.length > 0;
|
|
@@ -2814,7 +2990,8 @@ var validateExternalAgent = (db) => async (params) => {
|
|
|
2814
2990
|
drizzleOrm.and(
|
|
2815
2991
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
2816
2992
|
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
2817
|
-
drizzleOrm.eq(externalAgents.
|
|
2993
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
2994
|
+
drizzleOrm.eq(externalAgents.id, params.scopes.agentId)
|
|
2818
2995
|
)
|
|
2819
2996
|
).limit(1);
|
|
2820
2997
|
return result.length > 0;
|
|
@@ -2824,6 +3001,7 @@ var getAgentById = (db) => async (params) => {
|
|
|
2824
3001
|
where: drizzleOrm.and(
|
|
2825
3002
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2826
3003
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3004
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2827
3005
|
drizzleOrm.eq(agents.id, params.agentId)
|
|
2828
3006
|
)
|
|
2829
3007
|
});
|
|
@@ -2833,7 +3011,8 @@ var listAgents = (db) => async (params) => {
|
|
|
2833
3011
|
return await db.query.agents.findMany({
|
|
2834
3012
|
where: drizzleOrm.and(
|
|
2835
3013
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2836
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId)
|
|
3014
|
+
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3015
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId)
|
|
2837
3016
|
)
|
|
2838
3017
|
});
|
|
2839
3018
|
};
|
|
@@ -2843,7 +3022,8 @@ var listAgentsPaginated = (db) => async (params) => {
|
|
|
2843
3022
|
const offset = (page - 1) * limit;
|
|
2844
3023
|
const whereClause = drizzleOrm.and(
|
|
2845
3024
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2846
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId)
|
|
3025
|
+
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3026
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId)
|
|
2847
3027
|
);
|
|
2848
3028
|
const [data, totalResult] = await Promise.all([
|
|
2849
3029
|
db.select().from(agents).where(whereClause).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agents.createdAt)),
|
|
@@ -2875,13 +3055,18 @@ var updateAgent = (db) => async (params) => {
|
|
|
2875
3055
|
drizzleOrm.and(
|
|
2876
3056
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2877
3057
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3058
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2878
3059
|
drizzleOrm.eq(agents.id, params.agentId)
|
|
2879
3060
|
)
|
|
2880
3061
|
).returning();
|
|
2881
3062
|
return agent[0] ?? null;
|
|
2882
3063
|
};
|
|
2883
3064
|
var upsertAgent = (db) => async (params) => {
|
|
2884
|
-
const scopes = {
|
|
3065
|
+
const scopes = {
|
|
3066
|
+
tenantId: params.data.tenantId,
|
|
3067
|
+
projectId: params.data.projectId,
|
|
3068
|
+
graphId: params.data.graphId
|
|
3069
|
+
};
|
|
2885
3070
|
const existing = await getAgentById(db)({
|
|
2886
3071
|
scopes,
|
|
2887
3072
|
agentId: params.data.id
|
|
@@ -2912,6 +3097,7 @@ var deleteAgent = (db) => async (params) => {
|
|
|
2912
3097
|
drizzleOrm.and(
|
|
2913
3098
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2914
3099
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3100
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2915
3101
|
drizzleOrm.eq(agents.id, params.agentId)
|
|
2916
3102
|
)
|
|
2917
3103
|
);
|
|
@@ -2929,36 +3115,11 @@ var getAgentsByIds = (db) => async (params) => {
|
|
|
2929
3115
|
drizzleOrm.and(
|
|
2930
3116
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2931
3117
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3118
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2932
3119
|
drizzleOrm.inArray(agents.id, params.agentIds)
|
|
2933
3120
|
)
|
|
2934
3121
|
);
|
|
2935
3122
|
};
|
|
2936
|
-
var getAgentInGraphContext = (db) => async (params) => {
|
|
2937
|
-
return await db.select({
|
|
2938
|
-
id: agents.id,
|
|
2939
|
-
name: agents.name,
|
|
2940
|
-
description: agents.description,
|
|
2941
|
-
prompt: agents.prompt,
|
|
2942
|
-
tenantId: agents.tenantId,
|
|
2943
|
-
graphId: agentRelations.graphId,
|
|
2944
|
-
sourceAgentId: agentRelations.sourceAgentId
|
|
2945
|
-
}).from(agents).innerJoin(
|
|
2946
|
-
agentRelations,
|
|
2947
|
-
drizzleOrm.and(
|
|
2948
|
-
drizzleOrm.eq(agents.tenantId, agentRelations.tenantId),
|
|
2949
|
-
drizzleOrm.eq(agents.projectId, agentRelations.projectId),
|
|
2950
|
-
drizzleOrm.eq(agents.id, agentRelations.sourceAgentId),
|
|
2951
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
2952
|
-
)
|
|
2953
|
-
).where(
|
|
2954
|
-
drizzleOrm.and(
|
|
2955
|
-
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2956
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2957
|
-
drizzleOrm.eq(agents.id, params.agentId),
|
|
2958
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
2959
|
-
)
|
|
2960
|
-
);
|
|
2961
|
-
};
|
|
2962
3123
|
var getContextConfigById = (db) => async (params) => {
|
|
2963
3124
|
return await db.query.contextConfigs.findFirst({
|
|
2964
3125
|
where: drizzleOrm.and(
|
|
@@ -3113,6 +3274,8 @@ var getExternalAgent = (db) => async (params) => {
|
|
|
3113
3274
|
const result = await db.query.externalAgents.findFirst({
|
|
3114
3275
|
where: drizzleOrm.and(
|
|
3115
3276
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3277
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3278
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3116
3279
|
drizzleOrm.eq(externalAgents.id, params.agentId)
|
|
3117
3280
|
)
|
|
3118
3281
|
});
|
|
@@ -3122,6 +3285,8 @@ var getExternalAgentByUrl = (db) => async (params) => {
|
|
|
3122
3285
|
const result = await db.query.externalAgents.findFirst({
|
|
3123
3286
|
where: drizzleOrm.and(
|
|
3124
3287
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3288
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3289
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3125
3290
|
drizzleOrm.eq(externalAgents.baseUrl, params.baseUrl)
|
|
3126
3291
|
)
|
|
3127
3292
|
});
|
|
@@ -3129,7 +3294,11 @@ var getExternalAgentByUrl = (db) => async (params) => {
|
|
|
3129
3294
|
};
|
|
3130
3295
|
var listExternalAgents = (db) => async (params) => {
|
|
3131
3296
|
return await db.query.externalAgents.findMany({
|
|
3132
|
-
where: drizzleOrm.
|
|
3297
|
+
where: drizzleOrm.and(
|
|
3298
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3299
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3300
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3301
|
+
),
|
|
3133
3302
|
orderBy: [drizzleOrm.asc(externalAgents.name)]
|
|
3134
3303
|
});
|
|
3135
3304
|
};
|
|
@@ -3138,8 +3307,20 @@ var listExternalAgentsPaginated = (db) => async (params) => {
|
|
|
3138
3307
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
3139
3308
|
const offset = (page - 1) * limit;
|
|
3140
3309
|
const [data, totalResult] = await Promise.all([
|
|
3141
|
-
db.select().from(externalAgents).where(
|
|
3142
|
-
|
|
3310
|
+
db.select().from(externalAgents).where(
|
|
3311
|
+
drizzleOrm.and(
|
|
3312
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3313
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3314
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3315
|
+
)
|
|
3316
|
+
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(externalAgents.createdAt)),
|
|
3317
|
+
db.select({ count: drizzleOrm.count() }).from(externalAgents).where(
|
|
3318
|
+
drizzleOrm.and(
|
|
3319
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3320
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3321
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3322
|
+
)
|
|
3323
|
+
)
|
|
3143
3324
|
]);
|
|
3144
3325
|
const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
|
|
3145
3326
|
const pages = Math.ceil(total / limit);
|
|
@@ -3165,13 +3346,19 @@ var updateExternalAgent = (db) => async (params) => {
|
|
|
3165
3346
|
const result = await db.update(externalAgents).set(updateData).where(
|
|
3166
3347
|
drizzleOrm.and(
|
|
3167
3348
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3349
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3350
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3168
3351
|
drizzleOrm.eq(externalAgents.id, params.agentId)
|
|
3169
3352
|
)
|
|
3170
3353
|
).returning();
|
|
3171
3354
|
return result[0] || null;
|
|
3172
3355
|
};
|
|
3173
3356
|
var upsertExternalAgent = (db) => async (params) => {
|
|
3174
|
-
const scopes = {
|
|
3357
|
+
const scopes = {
|
|
3358
|
+
tenantId: params.data.tenantId,
|
|
3359
|
+
projectId: params.data.projectId,
|
|
3360
|
+
graphId: params.data.graphId
|
|
3361
|
+
};
|
|
3175
3362
|
const existing = await getExternalAgent(db)({
|
|
3176
3363
|
scopes,
|
|
3177
3364
|
agentId: params.data.id
|
|
@@ -3201,6 +3388,8 @@ var deleteExternalAgent = (db) => async (params) => {
|
|
|
3201
3388
|
const result = await db.delete(externalAgents).where(
|
|
3202
3389
|
drizzleOrm.and(
|
|
3203
3390
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3391
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3392
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3204
3393
|
drizzleOrm.eq(externalAgents.id, params.agentId)
|
|
3205
3394
|
)
|
|
3206
3395
|
).returning();
|
|
@@ -3219,27 +3408,24 @@ var externalAgentUrlExists = (db) => async (params) => {
|
|
|
3219
3408
|
return agent !== null;
|
|
3220
3409
|
};
|
|
3221
3410
|
var countExternalAgents = (db) => async (params) => {
|
|
3222
|
-
const result = await db.select({ count: drizzleOrm.count() }).from(externalAgents).where(
|
|
3411
|
+
const result = await db.select({ count: drizzleOrm.count() }).from(externalAgents).where(
|
|
3412
|
+
drizzleOrm.and(
|
|
3413
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3414
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3415
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3416
|
+
)
|
|
3417
|
+
);
|
|
3223
3418
|
const countValue = result[0]?.count;
|
|
3224
3419
|
return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
|
|
3225
3420
|
};
|
|
3226
3421
|
|
|
3227
3422
|
// src/data-access/agentGraphs.ts
|
|
3228
|
-
var getAgentGraph = (db) => async (params) => {
|
|
3229
|
-
return await db.query.agentGraph.findFirst({
|
|
3230
|
-
where: drizzleOrm.and(
|
|
3231
|
-
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3232
|
-
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3233
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3234
|
-
)
|
|
3235
|
-
});
|
|
3236
|
-
};
|
|
3237
3423
|
var getAgentGraphById = (db) => async (params) => {
|
|
3238
3424
|
const result = await db.query.agentGraph.findFirst({
|
|
3239
3425
|
where: drizzleOrm.and(
|
|
3240
3426
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3241
3427
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3242
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3428
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3243
3429
|
)
|
|
3244
3430
|
});
|
|
3245
3431
|
return result ?? null;
|
|
@@ -3249,7 +3435,7 @@ var getAgentGraphWithDefaultAgent = (db) => async (params) => {
|
|
|
3249
3435
|
where: drizzleOrm.and(
|
|
3250
3436
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3251
3437
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3252
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3438
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3253
3439
|
),
|
|
3254
3440
|
with: {
|
|
3255
3441
|
defaultAgent: true
|
|
@@ -3342,7 +3528,7 @@ var updateAgentGraph = (db) => async (params) => {
|
|
|
3342
3528
|
drizzleOrm.and(
|
|
3343
3529
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3344
3530
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3345
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3531
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3346
3532
|
)
|
|
3347
3533
|
).returning();
|
|
3348
3534
|
return graph[0] ?? null;
|
|
@@ -3352,7 +3538,7 @@ var deleteAgentGraph = (db) => async (params) => {
|
|
|
3352
3538
|
drizzleOrm.and(
|
|
3353
3539
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3354
3540
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3355
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3541
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3356
3542
|
)
|
|
3357
3543
|
).returning();
|
|
3358
3544
|
return result.length > 0;
|
|
@@ -3379,17 +3565,14 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3379
3565
|
agentId
|
|
3380
3566
|
}) => {
|
|
3381
3567
|
const { tenantId, projectId } = scopes;
|
|
3382
|
-
const graph = await
|
|
3383
|
-
scopes: { tenantId, projectId }
|
|
3384
|
-
graphId
|
|
3568
|
+
const graph = await getAgentGraphById(db)({
|
|
3569
|
+
scopes: { tenantId, projectId, graphId }
|
|
3385
3570
|
});
|
|
3386
3571
|
if (!graph) {
|
|
3387
3572
|
throw new Error(`Agent graph with ID ${graphId} not found for tenant ${tenantId}`);
|
|
3388
3573
|
}
|
|
3389
3574
|
const relations2 = await getAgentRelations(db)({
|
|
3390
|
-
scopes: { tenantId, projectId }
|
|
3391
|
-
graphId,
|
|
3392
|
-
agentId
|
|
3575
|
+
scopes: { tenantId, projectId, graphId, agentId }
|
|
3393
3576
|
});
|
|
3394
3577
|
const targetAgentIds = relations2.map((relation) => relation.targetAgentId).filter((id) => id !== null);
|
|
3395
3578
|
if (targetAgentIds.length === 0) {
|
|
@@ -3398,7 +3581,7 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3398
3581
|
const agentInfos = await Promise.all(
|
|
3399
3582
|
targetAgentIds.map(async (targetAgentId) => {
|
|
3400
3583
|
const agent = await getAgentById(db)({
|
|
3401
|
-
scopes: { tenantId, projectId },
|
|
3584
|
+
scopes: { tenantId, projectId, graphId },
|
|
3402
3585
|
agentId: targetAgentId
|
|
3403
3586
|
});
|
|
3404
3587
|
if (agent !== void 0) {
|
|
@@ -3410,55 +3593,35 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3410
3593
|
return agentInfos.filter((agent) => agent !== null);
|
|
3411
3594
|
};
|
|
3412
3595
|
var getFullGraphDefinition = (db) => async ({
|
|
3413
|
-
scopes: { tenantId, projectId }
|
|
3414
|
-
graphId
|
|
3596
|
+
scopes: { tenantId, projectId, graphId }
|
|
3415
3597
|
}) => {
|
|
3416
3598
|
const graph = await getAgentGraphById(db)({
|
|
3417
|
-
scopes: { tenantId, projectId }
|
|
3418
|
-
graphId
|
|
3599
|
+
scopes: { tenantId, projectId, graphId }
|
|
3419
3600
|
});
|
|
3420
3601
|
if (!graph) {
|
|
3421
3602
|
return null;
|
|
3422
3603
|
}
|
|
3423
3604
|
const graphRelations = await getAgentRelationsByGraph(db)({
|
|
3424
|
-
scopes: { tenantId, projectId }
|
|
3425
|
-
|
|
3605
|
+
scopes: { tenantId, projectId, graphId }
|
|
3606
|
+
});
|
|
3607
|
+
const graphAgents = await db.query.agents.findMany({
|
|
3608
|
+
where: drizzleOrm.and(
|
|
3609
|
+
drizzleOrm.eq(agents.tenantId, tenantId),
|
|
3610
|
+
drizzleOrm.eq(agents.projectId, projectId),
|
|
3611
|
+
drizzleOrm.eq(agents.graphId, graphId)
|
|
3612
|
+
)
|
|
3426
3613
|
});
|
|
3427
|
-
const internalAgentIds = /* @__PURE__ */ new Set();
|
|
3428
3614
|
const externalAgentIds = /* @__PURE__ */ new Set();
|
|
3429
|
-
internalAgentIds.add(graph.defaultAgentId);
|
|
3430
3615
|
for (const relation of graphRelations) {
|
|
3431
|
-
if (relation.sourceAgentId) {
|
|
3432
|
-
internalAgentIds.add(relation.sourceAgentId);
|
|
3433
|
-
}
|
|
3434
|
-
if (relation.targetAgentId) {
|
|
3435
|
-
internalAgentIds.add(relation.targetAgentId);
|
|
3436
|
-
}
|
|
3437
3616
|
if (relation.externalAgentId) {
|
|
3438
3617
|
externalAgentIds.add(relation.externalAgentId);
|
|
3439
3618
|
}
|
|
3440
3619
|
}
|
|
3441
|
-
const
|
|
3442
|
-
|
|
3443
|
-
drizzleOrm.eq(agentToolRelations.tenantId, tenantId),
|
|
3444
|
-
drizzleOrm.eq(agentToolRelations.projectId, projectId),
|
|
3445
|
-
// We need to find tools that belong to this graph
|
|
3446
|
-
// Tools created as part of a graph have IDs that include the graph ID
|
|
3447
|
-
drizzleOrm.like(tools.id, `%${graphId}%`)
|
|
3448
|
-
)
|
|
3449
|
-
);
|
|
3450
|
-
for (const agentTool of agentsWithTools) {
|
|
3451
|
-
internalAgentIds.add(agentTool.agentId);
|
|
3452
|
-
}
|
|
3453
|
-
const graphAgents = await Promise.all(
|
|
3454
|
-
Array.from(internalAgentIds).map(async (agentId) => {
|
|
3455
|
-
const agent = await getAgentById(db)({
|
|
3456
|
-
scopes: { tenantId, projectId },
|
|
3457
|
-
agentId
|
|
3458
|
-
});
|
|
3620
|
+
const processedAgents = await Promise.all(
|
|
3621
|
+
graphAgents.map(async (agent) => {
|
|
3459
3622
|
if (!agent) return null;
|
|
3460
3623
|
const agentRelationsList = graphRelations.filter(
|
|
3461
|
-
(relation) => relation.sourceAgentId ===
|
|
3624
|
+
(relation) => relation.sourceAgentId === agent.id
|
|
3462
3625
|
);
|
|
3463
3626
|
const canTransferTo = agentRelationsList.filter((rel) => rel.relationType === "transfer" || rel.relationType === "transfer_to").map((rel) => rel.targetAgentId).filter((id) => id !== null);
|
|
3464
3627
|
const canDelegateTo = agentRelationsList.filter((rel) => rel.relationType === "delegate" || rel.relationType === "delegate_to").map((rel) => rel.targetAgentId || rel.externalAgentId).filter((id) => id !== null);
|
|
@@ -3475,19 +3638,19 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3475
3638
|
lastToolsSync: tools.lastToolsSync,
|
|
3476
3639
|
selectedTools: agentToolRelations.selectedTools
|
|
3477
3640
|
}).from(agentToolRelations).innerJoin(tools, drizzleOrm.eq(agentToolRelations.toolId, tools.id)).where(
|
|
3478
|
-
drizzleOrm.and(drizzleOrm.eq(agentToolRelations.tenantId, tenantId), drizzleOrm.eq(agentToolRelations.agentId,
|
|
3641
|
+
drizzleOrm.and(drizzleOrm.eq(agentToolRelations.tenantId, tenantId), drizzleOrm.eq(agentToolRelations.agentId, agent.id))
|
|
3479
3642
|
);
|
|
3480
3643
|
const agentDataComponentRelations = await db.query.agentDataComponents.findMany({
|
|
3481
3644
|
where: drizzleOrm.and(
|
|
3482
3645
|
drizzleOrm.eq(agentDataComponents.tenantId, tenantId),
|
|
3483
|
-
drizzleOrm.eq(agentDataComponents.agentId,
|
|
3646
|
+
drizzleOrm.eq(agentDataComponents.agentId, agent.id)
|
|
3484
3647
|
)
|
|
3485
3648
|
});
|
|
3486
3649
|
const agentDataComponentIds = agentDataComponentRelations.map((rel) => rel.dataComponentId);
|
|
3487
3650
|
const agentArtifactComponentRelations = await db.query.agentArtifactComponents.findMany({
|
|
3488
3651
|
where: drizzleOrm.and(
|
|
3489
3652
|
drizzleOrm.eq(agentArtifactComponents.tenantId, tenantId),
|
|
3490
|
-
drizzleOrm.eq(agentArtifactComponents.agentId,
|
|
3653
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, agent.id)
|
|
3491
3654
|
)
|
|
3492
3655
|
});
|
|
3493
3656
|
const agentArtifactComponentIds = agentArtifactComponentRelations.map(
|
|
@@ -3530,7 +3693,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3530
3693
|
const externalAgents2 = await Promise.all(
|
|
3531
3694
|
Array.from(externalAgentIds).map(async (agentId) => {
|
|
3532
3695
|
const agent = await getExternalAgent(db)({
|
|
3533
|
-
scopes: { tenantId, projectId },
|
|
3696
|
+
scopes: { tenantId, projectId, graphId },
|
|
3534
3697
|
agentId
|
|
3535
3698
|
});
|
|
3536
3699
|
if (!agent) return null;
|
|
@@ -3542,7 +3705,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3542
3705
|
};
|
|
3543
3706
|
})
|
|
3544
3707
|
);
|
|
3545
|
-
const validAgents = [...
|
|
3708
|
+
const validAgents = [...processedAgents, ...externalAgents2].filter(
|
|
3546
3709
|
(agent) => agent !== null
|
|
3547
3710
|
);
|
|
3548
3711
|
const agentsObject = {};
|
|
@@ -3588,6 +3751,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3588
3751
|
}
|
|
3589
3752
|
let dataComponentsObject = {};
|
|
3590
3753
|
try {
|
|
3754
|
+
const internalAgentIds = graphAgents.map((agent) => agent.id);
|
|
3591
3755
|
const agentIds = Array.from(internalAgentIds);
|
|
3592
3756
|
dataComponentsObject = await fetchComponentRelationships(db)(
|
|
3593
3757
|
{ tenantId, projectId },
|
|
@@ -3610,6 +3774,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3610
3774
|
}
|
|
3611
3775
|
let artifactComponentsObject = {};
|
|
3612
3776
|
try {
|
|
3777
|
+
const internalAgentIds = graphAgents.map((agent) => agent.id);
|
|
3613
3778
|
const agentIds = Array.from(internalAgentIds);
|
|
3614
3779
|
artifactComponentsObject = await fetchComponentRelationships(db)(
|
|
3615
3780
|
{ tenantId, projectId },
|
|
@@ -3716,16 +3881,14 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3716
3881
|
return result;
|
|
3717
3882
|
};
|
|
3718
3883
|
var upsertAgentGraph = (db) => async (params) => {
|
|
3719
|
-
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
|
|
3720
3884
|
const graphId = params.data.id || nanoid.nanoid();
|
|
3885
|
+
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId, graphId };
|
|
3721
3886
|
const existing = await getAgentGraphById(db)({
|
|
3722
|
-
scopes
|
|
3723
|
-
graphId
|
|
3887
|
+
scopes
|
|
3724
3888
|
});
|
|
3725
3889
|
if (existing) {
|
|
3726
3890
|
return await updateAgentGraph(db)({
|
|
3727
3891
|
scopes,
|
|
3728
|
-
graphId,
|
|
3729
3892
|
data: {
|
|
3730
3893
|
name: params.data.name,
|
|
3731
3894
|
defaultAgentId: params.data.defaultAgentId,
|
|
@@ -4071,7 +4234,8 @@ var getArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
4071
4234
|
drizzleOrm.and(
|
|
4072
4235
|
drizzleOrm.eq(artifactComponents.tenantId, params.scopes.tenantId),
|
|
4073
4236
|
drizzleOrm.eq(artifactComponents.projectId, params.scopes.projectId),
|
|
4074
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4237
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4238
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
4075
4239
|
)
|
|
4076
4240
|
).orderBy(drizzleOrm.desc(artifactComponents.createdAt));
|
|
4077
4241
|
};
|
|
@@ -4080,7 +4244,8 @@ var associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
|
4080
4244
|
id: nanoid.nanoid(),
|
|
4081
4245
|
tenantId: params.scopes.tenantId,
|
|
4082
4246
|
projectId: params.scopes.projectId,
|
|
4083
|
-
|
|
4247
|
+
graphId: params.scopes.graphId,
|
|
4248
|
+
agentId: params.scopes.agentId,
|
|
4084
4249
|
artifactComponentId: params.artifactComponentId,
|
|
4085
4250
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4086
4251
|
}).returning();
|
|
@@ -4092,7 +4257,8 @@ var removeArtifactComponentFromAgent = (db) => async (params) => {
|
|
|
4092
4257
|
drizzleOrm.and(
|
|
4093
4258
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4094
4259
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4095
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4260
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4261
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId),
|
|
4096
4262
|
drizzleOrm.eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
4097
4263
|
)
|
|
4098
4264
|
).returning();
|
|
@@ -4106,13 +4272,15 @@ var deleteAgentArtifactComponentRelationByAgent = (db) => async (params) => {
|
|
|
4106
4272
|
const result = await db.delete(agentArtifactComponents).where(
|
|
4107
4273
|
drizzleOrm.and(
|
|
4108
4274
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4109
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4275
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4276
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
4110
4277
|
)
|
|
4111
4278
|
);
|
|
4112
4279
|
return (result.rowsAffected || 0) > 0;
|
|
4113
4280
|
};
|
|
4114
4281
|
var getAgentsUsingArtifactComponent = (db) => async (params) => {
|
|
4115
4282
|
return await db.select({
|
|
4283
|
+
graphId: agentArtifactComponents.graphId,
|
|
4116
4284
|
agentId: agentArtifactComponents.agentId,
|
|
4117
4285
|
createdAt: agentArtifactComponents.createdAt
|
|
4118
4286
|
}).from(agentArtifactComponents).where(
|
|
@@ -4128,7 +4296,8 @@ var isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
|
|
|
4128
4296
|
drizzleOrm.and(
|
|
4129
4297
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4130
4298
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4131
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4299
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4300
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId),
|
|
4132
4301
|
drizzleOrm.eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
4133
4302
|
)
|
|
4134
4303
|
).limit(1);
|
|
@@ -4139,7 +4308,7 @@ var graphHasArtifactComponents = (db) => async (params) => {
|
|
|
4139
4308
|
drizzleOrm.and(
|
|
4140
4309
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4141
4310
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4142
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
4311
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
4143
4312
|
)
|
|
4144
4313
|
).limit(1);
|
|
4145
4314
|
const total = result[0]?.count || 0;
|
|
@@ -4161,7 +4330,8 @@ var countArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
4161
4330
|
drizzleOrm.and(
|
|
4162
4331
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4163
4332
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4164
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4333
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4334
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
4165
4335
|
)
|
|
4166
4336
|
);
|
|
4167
4337
|
const total = result[0]?.count || 0;
|
|
@@ -4781,7 +4951,8 @@ var getDataComponentsForAgent = (db) => async (params) => {
|
|
|
4781
4951
|
drizzleOrm.and(
|
|
4782
4952
|
drizzleOrm.eq(dataComponents.tenantId, params.scopes.tenantId),
|
|
4783
4953
|
drizzleOrm.eq(dataComponents.projectId, params.scopes.projectId),
|
|
4784
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4954
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4955
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId)
|
|
4785
4956
|
)
|
|
4786
4957
|
).orderBy(drizzleOrm.desc(dataComponents.createdAt));
|
|
4787
4958
|
};
|
|
@@ -4790,7 +4961,8 @@ var associateDataComponentWithAgent = (db) => async (params) => {
|
|
|
4790
4961
|
id: nanoid.nanoid(),
|
|
4791
4962
|
tenantId: params.scopes.tenantId,
|
|
4792
4963
|
projectId: params.scopes.projectId,
|
|
4793
|
-
|
|
4964
|
+
graphId: params.scopes.graphId,
|
|
4965
|
+
agentId: params.scopes.agentId,
|
|
4794
4966
|
dataComponentId: params.dataComponentId
|
|
4795
4967
|
}).returning();
|
|
4796
4968
|
return association[0];
|
|
@@ -4800,7 +4972,8 @@ var removeDataComponentFromAgent = (db) => async (params) => {
|
|
|
4800
4972
|
drizzleOrm.and(
|
|
4801
4973
|
drizzleOrm.eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
4802
4974
|
drizzleOrm.eq(agentDataComponents.projectId, params.scopes.projectId),
|
|
4803
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4975
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4976
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId),
|
|
4804
4977
|
drizzleOrm.eq(agentDataComponents.dataComponentId, params.dataComponentId)
|
|
4805
4978
|
)
|
|
4806
4979
|
).returning();
|
|
@@ -4810,7 +4983,8 @@ var deleteAgentDataComponentRelationByAgent = (db) => async (params) => {
|
|
|
4810
4983
|
const result = await db.delete(agentDataComponents).where(
|
|
4811
4984
|
drizzleOrm.and(
|
|
4812
4985
|
drizzleOrm.eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
4813
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4986
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4987
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId)
|
|
4814
4988
|
)
|
|
4815
4989
|
);
|
|
4816
4990
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -4832,7 +5006,8 @@ var isDataComponentAssociatedWithAgent = (db) => async (params) => {
|
|
|
4832
5006
|
drizzleOrm.and(
|
|
4833
5007
|
drizzleOrm.eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
4834
5008
|
drizzleOrm.eq(agentDataComponents.projectId, params.scopes.projectId),
|
|
4835
|
-
drizzleOrm.eq(agentDataComponents.
|
|
5009
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
5010
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId),
|
|
4836
5011
|
drizzleOrm.eq(agentDataComponents.dataComponentId, params.dataComponentId)
|
|
4837
5012
|
)
|
|
4838
5013
|
).limit(1);
|
|
@@ -4886,9 +5061,11 @@ function isExternalAgent(agent) {
|
|
|
4886
5061
|
function validateAndTypeGraphData(data) {
|
|
4887
5062
|
return FullGraphDefinitionSchema.parse(data);
|
|
4888
5063
|
}
|
|
4889
|
-
function validateToolReferences(graphData) {
|
|
5064
|
+
function validateToolReferences(graphData, availableToolIds) {
|
|
5065
|
+
if (!availableToolIds) {
|
|
5066
|
+
return;
|
|
5067
|
+
}
|
|
4890
5068
|
const errors = [];
|
|
4891
|
-
const availableToolIds = new Set(Object.keys(graphData.tools || {}));
|
|
4892
5069
|
for (const [agentId, agentData] of Object.entries(graphData.agents)) {
|
|
4893
5070
|
if (isInternalAgent(agentData) && agentData.tools && Array.isArray(agentData.tools)) {
|
|
4894
5071
|
for (const toolId of agentData.tools) {
|
|
@@ -4903,9 +5080,11 @@ function validateToolReferences(graphData) {
|
|
|
4903
5080
|
${errors.join("\n")}`);
|
|
4904
5081
|
}
|
|
4905
5082
|
}
|
|
4906
|
-
function validateDataComponentReferences(graphData) {
|
|
5083
|
+
function validateDataComponentReferences(graphData, availableDataComponentIds) {
|
|
5084
|
+
if (!availableDataComponentIds) {
|
|
5085
|
+
return;
|
|
5086
|
+
}
|
|
4907
5087
|
const errors = [];
|
|
4908
|
-
const availableDataComponentIds = new Set(Object.keys(graphData.dataComponents || {}));
|
|
4909
5088
|
for (const [agentId, agentData] of Object.entries(graphData.agents)) {
|
|
4910
5089
|
if (isInternalAgent(agentData) && agentData.dataComponents) {
|
|
4911
5090
|
for (const dataComponentId of agentData.dataComponents) {
|
|
@@ -4922,9 +5101,11 @@ function validateDataComponentReferences(graphData) {
|
|
|
4922
5101
|
${errors.join("\n")}`);
|
|
4923
5102
|
}
|
|
4924
5103
|
}
|
|
4925
|
-
function validateArtifactComponentReferences(graphData) {
|
|
5104
|
+
function validateArtifactComponentReferences(graphData, availableArtifactComponentIds) {
|
|
5105
|
+
if (!availableArtifactComponentIds) {
|
|
5106
|
+
return;
|
|
5107
|
+
}
|
|
4926
5108
|
const errors = [];
|
|
4927
|
-
const availableArtifactComponentIds = new Set(Object.keys(graphData.artifactComponents || {}));
|
|
4928
5109
|
for (const [agentId, agentData] of Object.entries(graphData.agents)) {
|
|
4929
5110
|
if (isInternalAgent(agentData) && agentData.artifactComponents) {
|
|
4930
5111
|
for (const artifactComponentId of agentData.artifactComponents) {
|
|
@@ -4971,13 +5152,15 @@ function validateAgentRelationships(graphData) {
|
|
|
4971
5152
|
${errors.join("\n")}`);
|
|
4972
5153
|
}
|
|
4973
5154
|
}
|
|
4974
|
-
function validateGraphStructure(graphData) {
|
|
4975
|
-
if (!graphData.agents[graphData.defaultAgentId]) {
|
|
5155
|
+
function validateGraphStructure(graphData, projectResources) {
|
|
5156
|
+
if (graphData.defaultAgentId && !graphData.agents[graphData.defaultAgentId]) {
|
|
4976
5157
|
throw new Error(`Default agent '${graphData.defaultAgentId}' does not exist in agents`);
|
|
4977
5158
|
}
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
5159
|
+
if (projectResources) {
|
|
5160
|
+
validateToolReferences(graphData, projectResources.toolIds);
|
|
5161
|
+
validateDataComponentReferences(graphData, projectResources.dataComponentIds);
|
|
5162
|
+
validateArtifactComponentReferences(graphData, projectResources.artifactComponentIds);
|
|
5163
|
+
}
|
|
4981
5164
|
validateAgentRelationships(graphData);
|
|
4982
5165
|
}
|
|
4983
5166
|
var dbResultToMcpTool = (dbResult) => {
|
|
@@ -5098,6 +5281,7 @@ var addToolToAgent = (db) => async (params) => {
|
|
|
5098
5281
|
id,
|
|
5099
5282
|
tenantId: params.scopes.tenantId,
|
|
5100
5283
|
projectId: params.scopes.projectId,
|
|
5284
|
+
graphId: params.scopes.graphId,
|
|
5101
5285
|
agentId: params.agentId,
|
|
5102
5286
|
toolId: params.toolId,
|
|
5103
5287
|
selectedTools: params.selectedTools,
|
|
@@ -5111,6 +5295,7 @@ var removeToolFromAgent = (db) => async (params) => {
|
|
|
5111
5295
|
drizzleOrm.and(
|
|
5112
5296
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
5113
5297
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
5298
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
5114
5299
|
drizzleOrm.eq(agentToolRelations.agentId, params.agentId),
|
|
5115
5300
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
5116
5301
|
)
|
|
@@ -5122,6 +5307,7 @@ var upsertAgentToolRelation = (db) => async (params) => {
|
|
|
5122
5307
|
where: drizzleOrm.and(
|
|
5123
5308
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
5124
5309
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
5310
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
5125
5311
|
drizzleOrm.eq(agentToolRelations.agentId, params.agentId),
|
|
5126
5312
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
5127
5313
|
)
|
|
@@ -5178,11 +5364,15 @@ var getHealthyToolsForAgent = (db) => async (params) => {
|
|
|
5178
5364
|
}).from(tools).innerJoin(
|
|
5179
5365
|
agentToolRelations,
|
|
5180
5366
|
drizzleOrm.and(
|
|
5181
|
-
drizzleOrm.eq(tools.
|
|
5182
|
-
drizzleOrm.eq(
|
|
5183
|
-
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId)
|
|
5367
|
+
drizzleOrm.eq(tools.tenantId, params.scopes.tenantId),
|
|
5368
|
+
drizzleOrm.eq(tools.projectId, params.scopes.projectId),
|
|
5369
|
+
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
5370
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
5371
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
5372
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId),
|
|
5373
|
+
drizzleOrm.eq(tools.id, agentToolRelations.toolId)
|
|
5184
5374
|
)
|
|
5185
|
-
).where(drizzleOrm.
|
|
5375
|
+
).where(drizzleOrm.eq(tools.status, "healthy"));
|
|
5186
5376
|
return healthyTools.map((row) => row.tool);
|
|
5187
5377
|
};
|
|
5188
5378
|
|
|
@@ -5277,59 +5467,37 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5277
5467
|
validateGraphStructure(typed);
|
|
5278
5468
|
await applyExecutionLimitsInheritance(db, logger11, { tenantId, projectId }, typed);
|
|
5279
5469
|
try {
|
|
5280
|
-
if (typed.credentialReferences && Object.keys(typed.credentialReferences).length > 0) {
|
|
5281
|
-
logger11.info(
|
|
5282
|
-
{ credentialReferencesCount: Object.keys(typed.credentialReferences).length },
|
|
5283
|
-
"Processing credential references"
|
|
5284
|
-
);
|
|
5285
|
-
const credentialRefPromises = Object.entries(typed.credentialReferences).map(
|
|
5286
|
-
async ([_credId, credData]) => {
|
|
5287
|
-
try {
|
|
5288
|
-
logger11.info({ credId: credData.id }, "Processing credential reference");
|
|
5289
|
-
await upsertCredentialReference(db)({
|
|
5290
|
-
data: {
|
|
5291
|
-
...credData,
|
|
5292
|
-
tenantId,
|
|
5293
|
-
projectId
|
|
5294
|
-
}
|
|
5295
|
-
});
|
|
5296
|
-
logger11.info({ credId: credData.id }, "Credential reference processed successfully");
|
|
5297
|
-
} catch (error) {
|
|
5298
|
-
logger11.error(
|
|
5299
|
-
{ credId: credData.id, error },
|
|
5300
|
-
"Failed to create/update credential reference"
|
|
5301
|
-
);
|
|
5302
|
-
throw error;
|
|
5303
|
-
}
|
|
5304
|
-
}
|
|
5305
|
-
);
|
|
5306
|
-
await Promise.all(credentialRefPromises);
|
|
5307
|
-
logger11.info(
|
|
5308
|
-
{ credentialReferencesCount: Object.keys(typed.credentialReferences).length },
|
|
5309
|
-
"All credential references created/updated successfully"
|
|
5310
|
-
);
|
|
5311
|
-
}
|
|
5312
|
-
const toolPromises = Object.entries(typed.tools || {}).map(async ([toolId, toolData]) => {
|
|
5313
|
-
try {
|
|
5314
|
-
logger11.info({ toolId }, "Processing tool");
|
|
5315
|
-
await upsertTool(db)({
|
|
5316
|
-
data: {
|
|
5317
|
-
tenantId,
|
|
5318
|
-
projectId,
|
|
5319
|
-
...toolData
|
|
5320
|
-
}
|
|
5321
|
-
});
|
|
5322
|
-
logger11.info({ toolId }, "Tool processed successfully");
|
|
5323
|
-
} catch (error) {
|
|
5324
|
-
logger11.error({ toolId, error }, "Failed to create/update tool");
|
|
5325
|
-
throw error;
|
|
5326
|
-
}
|
|
5327
|
-
});
|
|
5328
|
-
await Promise.all(toolPromises);
|
|
5329
5470
|
logger11.info(
|
|
5330
|
-
{
|
|
5331
|
-
"
|
|
5471
|
+
{},
|
|
5472
|
+
"CredentialReferences are project-scoped - skipping credential reference creation in graph"
|
|
5332
5473
|
);
|
|
5474
|
+
logger11.info({}, "Tools are project-scoped - skipping tool creation in graph");
|
|
5475
|
+
let finalGraphId;
|
|
5476
|
+
try {
|
|
5477
|
+
const graphId = typed.id || nanoid.nanoid();
|
|
5478
|
+
logger11.info({ graphId }, "Creating agent graph metadata");
|
|
5479
|
+
const agentGraph2 = await upsertAgentGraph(db)({
|
|
5480
|
+
data: {
|
|
5481
|
+
id: graphId,
|
|
5482
|
+
tenantId,
|
|
5483
|
+
projectId,
|
|
5484
|
+
name: typed.name,
|
|
5485
|
+
defaultAgentId: typed.defaultAgentId,
|
|
5486
|
+
description: typed.description,
|
|
5487
|
+
contextConfigId: void 0,
|
|
5488
|
+
// Will be updated later if context config exists
|
|
5489
|
+
models: typed.models,
|
|
5490
|
+
statusUpdates: typed.statusUpdates,
|
|
5491
|
+
graphPrompt: typed.graphPrompt,
|
|
5492
|
+
stopWhen: typed.stopWhen
|
|
5493
|
+
}
|
|
5494
|
+
});
|
|
5495
|
+
finalGraphId = agentGraph2.id;
|
|
5496
|
+
logger11.info({ graphId: finalGraphId }, "Agent graph metadata created successfully");
|
|
5497
|
+
} catch (error) {
|
|
5498
|
+
logger11.error({ graphId: typed.id, error }, "Failed to create/update graph metadata");
|
|
5499
|
+
throw error;
|
|
5500
|
+
}
|
|
5333
5501
|
let contextConfigId;
|
|
5334
5502
|
if (typed.contextConfig) {
|
|
5335
5503
|
try {
|
|
@@ -5351,66 +5519,14 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5351
5519
|
throw error;
|
|
5352
5520
|
}
|
|
5353
5521
|
}
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
tenantId,
|
|
5363
|
-
projectId,
|
|
5364
|
-
name: dataComponentData.name,
|
|
5365
|
-
description: dataComponentData.description || "",
|
|
5366
|
-
props: dataComponentData.props || {}
|
|
5367
|
-
}
|
|
5368
|
-
});
|
|
5369
|
-
logger11.info({ dataComponentId }, "Data component processed successfully");
|
|
5370
|
-
} catch (error) {
|
|
5371
|
-
logger11.error({ dataComponentId, error }, "Failed to create/update dataComponent");
|
|
5372
|
-
throw error;
|
|
5373
|
-
}
|
|
5374
|
-
}
|
|
5375
|
-
);
|
|
5376
|
-
await Promise.all(dataComponentPromises);
|
|
5377
|
-
logger11.info(
|
|
5378
|
-
{ dataComponentCount: Object.keys(typed.dataComponents).length },
|
|
5379
|
-
"All dataComponents created/updated successfully"
|
|
5380
|
-
);
|
|
5381
|
-
}
|
|
5382
|
-
if (typed.artifactComponents && Object.keys(typed.artifactComponents).length > 0) {
|
|
5383
|
-
const artifactComponentPromises = Object.entries(typed.artifactComponents).map(
|
|
5384
|
-
async ([artifactComponentId, artifactComponentData]) => {
|
|
5385
|
-
try {
|
|
5386
|
-
logger11.info({ artifactComponentId }, "Processing artifact component");
|
|
5387
|
-
await upsertArtifactComponent(db)({
|
|
5388
|
-
data: {
|
|
5389
|
-
id: artifactComponentId,
|
|
5390
|
-
tenantId,
|
|
5391
|
-
projectId,
|
|
5392
|
-
name: artifactComponentData.name,
|
|
5393
|
-
description: artifactComponentData.description || "",
|
|
5394
|
-
summaryProps: artifactComponentData.summaryProps || {},
|
|
5395
|
-
fullProps: artifactComponentData.fullProps || {}
|
|
5396
|
-
}
|
|
5397
|
-
});
|
|
5398
|
-
logger11.info({ artifactComponentId }, "Artifact component processed successfully");
|
|
5399
|
-
} catch (error) {
|
|
5400
|
-
logger11.error(
|
|
5401
|
-
{ artifactComponentId, error },
|
|
5402
|
-
"Failed to create/update artifactComponent"
|
|
5403
|
-
);
|
|
5404
|
-
throw error;
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
);
|
|
5408
|
-
await Promise.all(artifactComponentPromises);
|
|
5409
|
-
logger11.info(
|
|
5410
|
-
{ artifactComponentCount: Object.keys(typed.artifactComponents).length },
|
|
5411
|
-
"All artifactComponents created/updated successfully"
|
|
5412
|
-
);
|
|
5413
|
-
}
|
|
5522
|
+
logger11.info(
|
|
5523
|
+
{},
|
|
5524
|
+
"DataComponents are project-scoped - skipping dataComponent creation in graph"
|
|
5525
|
+
);
|
|
5526
|
+
logger11.info(
|
|
5527
|
+
{},
|
|
5528
|
+
"ArtifactComponents are project-scoped - skipping artifactComponent creation in graph"
|
|
5529
|
+
);
|
|
5414
5530
|
const internalAgentPromises = Object.entries(typed.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
|
|
5415
5531
|
const internalAgent = agentData;
|
|
5416
5532
|
try {
|
|
@@ -5420,6 +5536,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5420
5536
|
id: agentId,
|
|
5421
5537
|
tenantId,
|
|
5422
5538
|
projectId,
|
|
5539
|
+
graphId: finalGraphId,
|
|
5423
5540
|
name: internalAgent.name || "",
|
|
5424
5541
|
description: internalAgent.description || "",
|
|
5425
5542
|
prompt: internalAgent.prompt || "",
|
|
@@ -5448,6 +5565,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5448
5565
|
id: agentId,
|
|
5449
5566
|
tenantId,
|
|
5450
5567
|
projectId,
|
|
5568
|
+
graphId: finalGraphId,
|
|
5451
5569
|
name: externalAgent.name,
|
|
5452
5570
|
description: externalAgent.description || "",
|
|
5453
5571
|
baseUrl: externalAgent.baseUrl,
|
|
@@ -5466,29 +5584,24 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5466
5584
|
([_, agentData]) => isExternalAgent(agentData)
|
|
5467
5585
|
).length;
|
|
5468
5586
|
logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
projectId,
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
}
|
|
5487
|
-
finalGraphId = agentGraph2.id;
|
|
5488
|
-
logger11.info({ graphId: finalGraphId }, "Agent graph metadata processed successfully");
|
|
5489
|
-
} catch (error) {
|
|
5490
|
-
logger11.error({ graphId: typed.id, error }, "Failed to create/update graph metadata");
|
|
5491
|
-
throw error;
|
|
5587
|
+
if (contextConfigId) {
|
|
5588
|
+
try {
|
|
5589
|
+
logger11.info(
|
|
5590
|
+
{ graphId: finalGraphId, contextConfigId },
|
|
5591
|
+
"Updating graph with context config"
|
|
5592
|
+
);
|
|
5593
|
+
await updateAgentGraph(db)({
|
|
5594
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5595
|
+
data: { contextConfigId }
|
|
5596
|
+
});
|
|
5597
|
+
logger11.info({ graphId: finalGraphId }, "Graph updated with context config");
|
|
5598
|
+
} catch (error) {
|
|
5599
|
+
logger11.error(
|
|
5600
|
+
{ graphId: finalGraphId, error },
|
|
5601
|
+
"Failed to update graph with context config"
|
|
5602
|
+
);
|
|
5603
|
+
throw error;
|
|
5604
|
+
}
|
|
5492
5605
|
}
|
|
5493
5606
|
const agentToolPromises = [];
|
|
5494
5607
|
for (const [agentId, agentData] of Object.entries(typed.agents)) {
|
|
@@ -5500,7 +5613,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5500
5613
|
const selectedTools = agentData.selectedTools?.[toolId];
|
|
5501
5614
|
logger11.info({ agentId, toolId }, "Processing agent-tool relation");
|
|
5502
5615
|
await upsertAgentToolRelation(db)({
|
|
5503
|
-
scopes: { tenantId, projectId },
|
|
5616
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5504
5617
|
agentId,
|
|
5505
5618
|
toolId,
|
|
5506
5619
|
selectedTools
|
|
@@ -5531,8 +5644,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5531
5644
|
"Processing agent-data component relation"
|
|
5532
5645
|
);
|
|
5533
5646
|
await upsertAgentDataComponentRelation(db)({
|
|
5534
|
-
scopes: { tenantId, projectId },
|
|
5535
|
-
agentId,
|
|
5647
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
5536
5648
|
dataComponentId
|
|
5537
5649
|
});
|
|
5538
5650
|
logger11.info(
|
|
@@ -5564,8 +5676,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5564
5676
|
"Processing agent-artifact component relation"
|
|
5565
5677
|
);
|
|
5566
5678
|
await upsertAgentArtifactComponentRelation(db)({
|
|
5567
|
-
scopes: { tenantId, projectId },
|
|
5568
|
-
agentId,
|
|
5679
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
5569
5680
|
artifactComponentId
|
|
5570
5681
|
});
|
|
5571
5682
|
logger11.info(
|
|
@@ -5661,8 +5772,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5661
5772
|
"All agent relations created"
|
|
5662
5773
|
);
|
|
5663
5774
|
const createdGraph = await getFullGraphDefinition(db)({
|
|
5664
|
-
scopes: { tenantId, projectId }
|
|
5665
|
-
graphId: finalGraphId
|
|
5775
|
+
scopes: { tenantId, projectId, graphId: finalGraphId }
|
|
5666
5776
|
});
|
|
5667
5777
|
if (!createdGraph) {
|
|
5668
5778
|
throw new Error("Failed to retrieve created graph");
|
|
@@ -5685,8 +5795,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5685
5795
|
{
|
|
5686
5796
|
tenantId,
|
|
5687
5797
|
graphId: typedGraphDefinition.id,
|
|
5688
|
-
agentCount: Object.keys(typedGraphDefinition.agents).length
|
|
5689
|
-
toolCount: Object.keys(typedGraphDefinition.tools || {}).length
|
|
5798
|
+
agentCount: Object.keys(typedGraphDefinition.agents).length
|
|
5690
5799
|
},
|
|
5691
5800
|
"Updating full graph in database"
|
|
5692
5801
|
);
|
|
@@ -5699,8 +5808,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5699
5808
|
);
|
|
5700
5809
|
try {
|
|
5701
5810
|
const existingGraph = await getAgentGraphById(db)({
|
|
5702
|
-
scopes: { tenantId, projectId }
|
|
5703
|
-
graphId: typedGraphDefinition.id
|
|
5811
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
5704
5812
|
});
|
|
5705
5813
|
if (!existingGraph) {
|
|
5706
5814
|
logger11.info(
|
|
@@ -5710,65 +5818,40 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5710
5818
|
return createFullGraphServerSide(db)(scopes, graphData);
|
|
5711
5819
|
}
|
|
5712
5820
|
const existingGraphModels = existingGraph.models;
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
const
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
);
|
|
5737
|
-
throw error;
|
|
5738
|
-
}
|
|
5821
|
+
logger11.info(
|
|
5822
|
+
{},
|
|
5823
|
+
"CredentialReferences are project-scoped - skipping credential reference update in graph"
|
|
5824
|
+
);
|
|
5825
|
+
logger11.info({}, "Tools are project-scoped - skipping tool creation in graph update");
|
|
5826
|
+
let finalGraphId;
|
|
5827
|
+
try {
|
|
5828
|
+
const graphId = typedGraphDefinition.id || nanoid.nanoid();
|
|
5829
|
+
logger11.info({ graphId }, "Getting/creating agent graph metadata");
|
|
5830
|
+
const agentGraph2 = await upsertAgentGraph(db)({
|
|
5831
|
+
data: {
|
|
5832
|
+
id: graphId,
|
|
5833
|
+
tenantId,
|
|
5834
|
+
projectId,
|
|
5835
|
+
name: typedGraphDefinition.name,
|
|
5836
|
+
defaultAgentId: typedGraphDefinition.defaultAgentId,
|
|
5837
|
+
description: typedGraphDefinition.description,
|
|
5838
|
+
contextConfigId: void 0,
|
|
5839
|
+
// Will be updated later if context config exists
|
|
5840
|
+
models: typedGraphDefinition.models,
|
|
5841
|
+
statusUpdates: typedGraphDefinition.statusUpdates,
|
|
5842
|
+
graphPrompt: typedGraphDefinition.graphPrompt,
|
|
5843
|
+
stopWhen: typedGraphDefinition.stopWhen
|
|
5739
5844
|
}
|
|
5845
|
+
});
|
|
5846
|
+
finalGraphId = agentGraph2.id;
|
|
5847
|
+
logger11.info({ graphId: finalGraphId }, "Agent graph metadata ready");
|
|
5848
|
+
} catch (error) {
|
|
5849
|
+
logger11.error(
|
|
5850
|
+
{ graphId: typedGraphDefinition.id, error },
|
|
5851
|
+
"Failed to get/update graph metadata"
|
|
5740
5852
|
);
|
|
5741
|
-
|
|
5742
|
-
logger11.info(
|
|
5743
|
-
{
|
|
5744
|
-
credentialReferencesCount: Object.keys(typedGraphDefinition.credentialReferences).length
|
|
5745
|
-
},
|
|
5746
|
-
"All credential references created/updated successfully"
|
|
5747
|
-
);
|
|
5853
|
+
throw error;
|
|
5748
5854
|
}
|
|
5749
|
-
const toolPromises = Object.entries(typedGraphDefinition.tools || {}).map(
|
|
5750
|
-
async ([toolId, toolData]) => {
|
|
5751
|
-
try {
|
|
5752
|
-
logger11.info({ toolId }, "Processing tool");
|
|
5753
|
-
await upsertTool(db)({
|
|
5754
|
-
data: {
|
|
5755
|
-
tenantId,
|
|
5756
|
-
projectId,
|
|
5757
|
-
...toolData
|
|
5758
|
-
}
|
|
5759
|
-
});
|
|
5760
|
-
logger11.info({ toolId }, "Tool processed successfully");
|
|
5761
|
-
} catch (error) {
|
|
5762
|
-
logger11.error({ toolId, error }, "Failed to create/update tool");
|
|
5763
|
-
throw error;
|
|
5764
|
-
}
|
|
5765
|
-
}
|
|
5766
|
-
);
|
|
5767
|
-
await Promise.all(toolPromises);
|
|
5768
|
-
logger11.info(
|
|
5769
|
-
{ toolCount: Object.keys(typedGraphDefinition.tools || {}).length },
|
|
5770
|
-
"All tools created/updated successfully"
|
|
5771
|
-
);
|
|
5772
5855
|
let contextConfigId;
|
|
5773
5856
|
if (typedGraphDefinition.contextConfig) {
|
|
5774
5857
|
try {
|
|
@@ -5793,66 +5876,11 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5793
5876
|
throw error;
|
|
5794
5877
|
}
|
|
5795
5878
|
}
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
await upsertDataComponent(db)({
|
|
5802
|
-
data: {
|
|
5803
|
-
id: dataComponentId,
|
|
5804
|
-
tenantId,
|
|
5805
|
-
projectId,
|
|
5806
|
-
name: dataComponentData.name,
|
|
5807
|
-
description: dataComponentData.description || "",
|
|
5808
|
-
props: dataComponentData.props || {}
|
|
5809
|
-
}
|
|
5810
|
-
});
|
|
5811
|
-
logger11.info({ dataComponentId }, "Data component processed successfully");
|
|
5812
|
-
} catch (error) {
|
|
5813
|
-
logger11.error({ dataComponentId, error }, "Failed to create/update dataComponent");
|
|
5814
|
-
throw error;
|
|
5815
|
-
}
|
|
5816
|
-
}
|
|
5817
|
-
);
|
|
5818
|
-
await Promise.all(dataComponentPromises);
|
|
5819
|
-
logger11.info(
|
|
5820
|
-
{ dataComponentCount: Object.keys(typedGraphDefinition.dataComponents).length },
|
|
5821
|
-
"All dataComponents created/updated successfully"
|
|
5822
|
-
);
|
|
5823
|
-
}
|
|
5824
|
-
if (typedGraphDefinition.artifactComponents && Object.keys(typedGraphDefinition.artifactComponents).length > 0) {
|
|
5825
|
-
const artifactComponentPromises = Object.entries(
|
|
5826
|
-
typedGraphDefinition.artifactComponents
|
|
5827
|
-
).map(async ([artifactComponentId, artifactComponentData]) => {
|
|
5828
|
-
try {
|
|
5829
|
-
logger11.info({ artifactComponentId }, "Processing artifact component");
|
|
5830
|
-
await upsertArtifactComponent(db)({
|
|
5831
|
-
data: {
|
|
5832
|
-
id: artifactComponentId,
|
|
5833
|
-
tenantId,
|
|
5834
|
-
projectId,
|
|
5835
|
-
name: artifactComponentData.name,
|
|
5836
|
-
description: artifactComponentData.description || "",
|
|
5837
|
-
summaryProps: artifactComponentData.summaryProps || {},
|
|
5838
|
-
fullProps: artifactComponentData.fullProps || {}
|
|
5839
|
-
}
|
|
5840
|
-
});
|
|
5841
|
-
logger11.info({ artifactComponentId }, "Artifact component processed successfully");
|
|
5842
|
-
} catch (error) {
|
|
5843
|
-
logger11.error(
|
|
5844
|
-
{ artifactComponentId, error },
|
|
5845
|
-
"Failed to create/update artifactComponent"
|
|
5846
|
-
);
|
|
5847
|
-
throw error;
|
|
5848
|
-
}
|
|
5849
|
-
});
|
|
5850
|
-
await Promise.all(artifactComponentPromises);
|
|
5851
|
-
logger11.info(
|
|
5852
|
-
{ artifactComponentCount: Object.keys(typedGraphDefinition.artifactComponents).length },
|
|
5853
|
-
"All artifactComponents created/updated successfully"
|
|
5854
|
-
);
|
|
5855
|
-
}
|
|
5879
|
+
logger11.info({}, "DataComponents are project-scoped - skipping dataComponent update in graph");
|
|
5880
|
+
logger11.info(
|
|
5881
|
+
{},
|
|
5882
|
+
"ArtifactComponents are project-scoped - skipping artifactComponent update in graph"
|
|
5883
|
+
);
|
|
5856
5884
|
const internalAgentPromises = Object.entries(typedGraphDefinition.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
|
|
5857
5885
|
const internalAgent = agentData;
|
|
5858
5886
|
let existingAgent = null;
|
|
@@ -5876,17 +5904,17 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5876
5904
|
const modelTypes = ["base", "structuredOutput", "summarizer"];
|
|
5877
5905
|
const cascadedModels = { ...finalModelSettings };
|
|
5878
5906
|
for (const modelType of modelTypes) {
|
|
5879
|
-
if (agentModels[modelType]?.model && existingGraphModels?.[modelType]?.model && agentModels[modelType].model === existingGraphModels[modelType].model && graphModels[modelType]
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
};
|
|
5907
|
+
if (agentModels[modelType]?.model && existingGraphModels?.[modelType]?.model && agentModels[modelType].model === existingGraphModels[modelType].model && graphModels[modelType] && // Model name changed
|
|
5908
|
+
(graphModels[modelType].model !== existingGraphModels[modelType].model || // OR providerOptions changed
|
|
5909
|
+
JSON.stringify(graphModels[modelType].providerOptions) !== JSON.stringify(existingGraphModels[modelType].providerOptions))) {
|
|
5910
|
+
cascadedModels[modelType] = graphModels[modelType];
|
|
5884
5911
|
logger11.info(
|
|
5885
5912
|
{
|
|
5886
5913
|
agentId,
|
|
5887
5914
|
modelType,
|
|
5888
5915
|
oldModel: agentModels[modelType].model,
|
|
5889
|
-
newModel: graphModels[modelType].model
|
|
5916
|
+
newModel: graphModels[modelType].model,
|
|
5917
|
+
hasProviderOptions: !!graphModels[modelType].providerOptions
|
|
5890
5918
|
},
|
|
5891
5919
|
"Cascading model change from graph to agent"
|
|
5892
5920
|
);
|
|
@@ -5901,6 +5929,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5901
5929
|
id: agentId,
|
|
5902
5930
|
tenantId,
|
|
5903
5931
|
projectId,
|
|
5932
|
+
graphId: finalGraphId,
|
|
5904
5933
|
name: internalAgent.name || "",
|
|
5905
5934
|
description: internalAgent.description || "",
|
|
5906
5935
|
prompt: internalAgent.prompt || "",
|
|
@@ -5929,6 +5958,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5929
5958
|
id: agentId,
|
|
5930
5959
|
tenantId,
|
|
5931
5960
|
projectId,
|
|
5961
|
+
graphId: finalGraphId,
|
|
5932
5962
|
name: externalAgent.name,
|
|
5933
5963
|
description: externalAgent.description || "",
|
|
5934
5964
|
baseUrl: externalAgent.baseUrl,
|
|
@@ -5948,8 +5978,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5948
5978
|
).length;
|
|
5949
5979
|
logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
5950
5980
|
await updateAgentGraph(db)({
|
|
5951
|
-
scopes: { tenantId, projectId },
|
|
5952
|
-
graphId: typedGraphDefinition.id,
|
|
5981
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id },
|
|
5953
5982
|
data: {
|
|
5954
5983
|
name: typedGraphDefinition.name,
|
|
5955
5984
|
defaultAgentId: typedGraphDefinition.defaultAgentId,
|
|
@@ -5964,8 +5993,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5964
5993
|
logger11.info({ graphId: typedGraphDefinition.id }, "Graph metadata updated");
|
|
5965
5994
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
5966
5995
|
await deleteAgentToolRelationByAgent(db)({
|
|
5967
|
-
scopes: { tenantId, projectId }
|
|
5968
|
-
agentId
|
|
5996
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
5969
5997
|
});
|
|
5970
5998
|
}
|
|
5971
5999
|
const agentToolPromises = [];
|
|
@@ -5977,7 +6005,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5977
6005
|
try {
|
|
5978
6006
|
const selectedTools = agentData.selectedTools?.[toolId];
|
|
5979
6007
|
await createAgentToolRelation(db)({
|
|
5980
|
-
scopes: { tenantId, projectId },
|
|
6008
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5981
6009
|
data: {
|
|
5982
6010
|
agentId,
|
|
5983
6011
|
toolId,
|
|
@@ -6000,8 +6028,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6000
6028
|
);
|
|
6001
6029
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
6002
6030
|
await deleteAgentDataComponentRelationByAgent(db)({
|
|
6003
|
-
scopes: { tenantId, projectId }
|
|
6004
|
-
agentId
|
|
6031
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
6005
6032
|
});
|
|
6006
6033
|
}
|
|
6007
6034
|
const agentDataComponentPromises = [];
|
|
@@ -6012,8 +6039,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6012
6039
|
(async () => {
|
|
6013
6040
|
try {
|
|
6014
6041
|
await associateDataComponentWithAgent(db)({
|
|
6015
|
-
scopes: { tenantId, projectId },
|
|
6016
|
-
agentId,
|
|
6042
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
6017
6043
|
dataComponentId
|
|
6018
6044
|
});
|
|
6019
6045
|
logger11.info({ agentId, dataComponentId }, "Agent-dataComponent relation created");
|
|
@@ -6035,8 +6061,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6035
6061
|
);
|
|
6036
6062
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
6037
6063
|
await deleteAgentArtifactComponentRelationByAgent(db)({
|
|
6038
|
-
scopes: { tenantId, projectId }
|
|
6039
|
-
agentId
|
|
6064
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
6040
6065
|
});
|
|
6041
6066
|
}
|
|
6042
6067
|
const agentArtifactComponentPromises = [];
|
|
@@ -6047,8 +6072,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6047
6072
|
(async () => {
|
|
6048
6073
|
try {
|
|
6049
6074
|
await associateArtifactComponentWithAgent(db)({
|
|
6050
|
-
scopes: { tenantId, projectId },
|
|
6051
|
-
agentId,
|
|
6075
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
6052
6076
|
artifactComponentId
|
|
6053
6077
|
});
|
|
6054
6078
|
logger11.info(
|
|
@@ -6072,8 +6096,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6072
6096
|
"All agent-artifactComponent relations updated"
|
|
6073
6097
|
);
|
|
6074
6098
|
await deleteAgentRelationsByGraph(db)({
|
|
6075
|
-
scopes: { tenantId, projectId }
|
|
6076
|
-
graphId: typedGraphDefinition.id
|
|
6099
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
6077
6100
|
});
|
|
6078
6101
|
const agentRelationPromises = [];
|
|
6079
6102
|
for (const [agentId, agentData] of Object.entries(typedGraphDefinition.agents)) {
|
|
@@ -6149,8 +6172,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6149
6172
|
"All agent relations updated"
|
|
6150
6173
|
);
|
|
6151
6174
|
const updatedGraph = await getFullGraphDefinition(db)({
|
|
6152
|
-
scopes: { tenantId, projectId }
|
|
6153
|
-
graphId: typedGraphDefinition.id
|
|
6175
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
6154
6176
|
});
|
|
6155
6177
|
if (!updatedGraph) {
|
|
6156
6178
|
throw new Error("Failed to retrieve updated graph");
|
|
@@ -6163,22 +6185,21 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6163
6185
|
}
|
|
6164
6186
|
};
|
|
6165
6187
|
var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
6166
|
-
const { scopes
|
|
6188
|
+
const { scopes } = params;
|
|
6167
6189
|
const { tenantId, projectId } = scopes;
|
|
6168
|
-
logger11.info({ tenantId, graphId }, "Retrieving full graph definition");
|
|
6190
|
+
logger11.info({ tenantId, graphId: scopes.graphId }, "Retrieving full graph definition");
|
|
6169
6191
|
try {
|
|
6170
6192
|
const graph = await getFullGraphDefinition(db)({
|
|
6171
|
-
scopes: { tenantId, projectId }
|
|
6172
|
-
graphId
|
|
6193
|
+
scopes: { tenantId, projectId, graphId: scopes.graphId }
|
|
6173
6194
|
});
|
|
6174
6195
|
if (!graph) {
|
|
6175
|
-
logger11.info({ tenantId, graphId }, "Graph not found");
|
|
6196
|
+
logger11.info({ tenantId, graphId: scopes.graphId }, "Graph not found");
|
|
6176
6197
|
return null;
|
|
6177
6198
|
}
|
|
6178
6199
|
logger11.info(
|
|
6179
6200
|
{
|
|
6180
6201
|
tenantId,
|
|
6181
|
-
graphId,
|
|
6202
|
+
graphId: scopes.graphId,
|
|
6182
6203
|
agentCount: Object.keys(graph.agents).length
|
|
6183
6204
|
},
|
|
6184
6205
|
"Full graph retrieved successfully"
|
|
@@ -6188,7 +6209,7 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
6188
6209
|
logger11.error(
|
|
6189
6210
|
{
|
|
6190
6211
|
tenantId,
|
|
6191
|
-
graphId,
|
|
6212
|
+
graphId: scopes.graphId,
|
|
6192
6213
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
6193
6214
|
},
|
|
6194
6215
|
"Failed to retrieve full graph"
|
|
@@ -6197,29 +6218,25 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
6197
6218
|
}
|
|
6198
6219
|
};
|
|
6199
6220
|
var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
6200
|
-
const {
|
|
6201
|
-
const { tenantId, projectId } = scopes;
|
|
6221
|
+
const { tenantId, projectId, graphId } = params.scopes;
|
|
6202
6222
|
logger11.info({ tenantId, graphId }, "Deleting full graph and related entities");
|
|
6203
6223
|
try {
|
|
6204
6224
|
const graph = await getFullGraphDefinition(db)({
|
|
6205
|
-
scopes: { tenantId, projectId }
|
|
6206
|
-
graphId
|
|
6225
|
+
scopes: { tenantId, projectId, graphId }
|
|
6207
6226
|
});
|
|
6208
6227
|
if (!graph) {
|
|
6209
6228
|
logger11.info({ tenantId, graphId }, "Graph not found for deletion");
|
|
6210
6229
|
return false;
|
|
6211
6230
|
}
|
|
6212
6231
|
await deleteAgentRelationsByGraph(db)({
|
|
6213
|
-
scopes: { tenantId, projectId }
|
|
6214
|
-
graphId
|
|
6232
|
+
scopes: { tenantId, projectId, graphId }
|
|
6215
6233
|
});
|
|
6216
6234
|
logger11.info({ tenantId, graphId }, "Agent relations deleted");
|
|
6217
6235
|
const agentIds = Object.keys(graph.agents);
|
|
6218
6236
|
if (agentIds.length > 0) {
|
|
6219
6237
|
for (const agentId of agentIds) {
|
|
6220
6238
|
await deleteAgentToolRelationByAgent(db)({
|
|
6221
|
-
scopes: { tenantId, projectId }
|
|
6222
|
-
agentId
|
|
6239
|
+
scopes: { tenantId, projectId, graphId, agentId }
|
|
6223
6240
|
});
|
|
6224
6241
|
}
|
|
6225
6242
|
logger11.info(
|
|
@@ -6228,8 +6245,7 @@ var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
6228
6245
|
);
|
|
6229
6246
|
}
|
|
6230
6247
|
await deleteAgentGraph(db)({
|
|
6231
|
-
scopes: { tenantId, projectId }
|
|
6232
|
-
graphId
|
|
6248
|
+
scopes: { tenantId, projectId, graphId }
|
|
6233
6249
|
});
|
|
6234
6250
|
logger11.info({ tenantId, graphId }, "Graph metadata deleted");
|
|
6235
6251
|
logger11.info({ tenantId, graphId }, "Full graph deleted successfully");
|
|
@@ -6938,8 +6954,7 @@ var createFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
6938
6954
|
db,
|
|
6939
6955
|
logger11
|
|
6940
6956
|
)({
|
|
6941
|
-
scopes: { tenantId, projectId: typed.id }
|
|
6942
|
-
projectId: typed.id
|
|
6957
|
+
scopes: { tenantId, projectId: typed.id }
|
|
6943
6958
|
});
|
|
6944
6959
|
} catch (error) {
|
|
6945
6960
|
logger11.error(
|
|
@@ -7245,8 +7260,7 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
7245
7260
|
db,
|
|
7246
7261
|
logger11
|
|
7247
7262
|
)({
|
|
7248
|
-
scopes: { tenantId, projectId: typed.id }
|
|
7249
|
-
projectId: typed.id
|
|
7263
|
+
scopes: { tenantId, projectId: typed.id }
|
|
7250
7264
|
});
|
|
7251
7265
|
} catch (error) {
|
|
7252
7266
|
logger11.error(
|
|
@@ -7261,8 +7275,8 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
7261
7275
|
}
|
|
7262
7276
|
};
|
|
7263
7277
|
var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
7264
|
-
const { scopes
|
|
7265
|
-
const { tenantId } = scopes;
|
|
7278
|
+
const { scopes } = params;
|
|
7279
|
+
const { tenantId, projectId } = scopes;
|
|
7266
7280
|
logger11.info({ tenantId, projectId }, "Retrieving full project definition");
|
|
7267
7281
|
try {
|
|
7268
7282
|
const project = await getProject(db)({
|
|
@@ -7416,18 +7430,10 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
7416
7430
|
"Retrieving full graph definition"
|
|
7417
7431
|
);
|
|
7418
7432
|
const fullGraph = await getFullGraph(db)({
|
|
7419
|
-
scopes: { tenantId, projectId }
|
|
7420
|
-
graphId: graph.id
|
|
7433
|
+
scopes: { tenantId, projectId, graphId: graph.id }
|
|
7421
7434
|
});
|
|
7422
7435
|
if (fullGraph) {
|
|
7423
|
-
const {
|
|
7424
|
-
tools: _tools,
|
|
7425
|
-
dataComponents: _dataComponents,
|
|
7426
|
-
artifactComponents: _artifactComponents,
|
|
7427
|
-
contextConfig: _contextConfig,
|
|
7428
|
-
credentialReferences: _credentialReferences,
|
|
7429
|
-
...graphWithoutProjectResources
|
|
7430
|
-
} = fullGraph;
|
|
7436
|
+
const { contextConfig: _contextConfig, ...graphWithoutProjectResources } = fullGraph;
|
|
7431
7437
|
graphs[graph.id] = graphWithoutProjectResources;
|
|
7432
7438
|
logger11.info(
|
|
7433
7439
|
{ tenantId, projectId, graphId: graph.id },
|
|
@@ -7482,16 +7488,15 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
7482
7488
|
}
|
|
7483
7489
|
};
|
|
7484
7490
|
var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
7485
|
-
const { scopes
|
|
7486
|
-
const { tenantId } = scopes;
|
|
7491
|
+
const { scopes } = params;
|
|
7492
|
+
const { tenantId, projectId } = scopes;
|
|
7487
7493
|
logger11.info({ tenantId, projectId }, "Deleting full project and related entities");
|
|
7488
7494
|
try {
|
|
7489
7495
|
const project = await getFullProject(
|
|
7490
7496
|
db,
|
|
7491
7497
|
logger11
|
|
7492
7498
|
)({
|
|
7493
|
-
scopes: { tenantId, projectId }
|
|
7494
|
-
projectId
|
|
7499
|
+
scopes: { tenantId, projectId }
|
|
7495
7500
|
});
|
|
7496
7501
|
if (!project) {
|
|
7497
7502
|
logger11.info({ tenantId, projectId }, "Project not found for deletion");
|
|
@@ -7513,8 +7518,7 @@ var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
7513
7518
|
db,
|
|
7514
7519
|
logger11
|
|
7515
7520
|
)({
|
|
7516
|
-
scopes: { tenantId, projectId }
|
|
7517
|
-
graphId
|
|
7521
|
+
scopes: { tenantId, projectId, graphId }
|
|
7518
7522
|
});
|
|
7519
7523
|
logger11.info(
|
|
7520
7524
|
{ tenantId, projectId, graphId },
|
|
@@ -8929,8 +8933,7 @@ async function validateRequestContext({
|
|
|
8929
8933
|
}) {
|
|
8930
8934
|
try {
|
|
8931
8935
|
const agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
|
|
8932
|
-
scopes: { tenantId, projectId }
|
|
8933
|
-
graphId
|
|
8936
|
+
scopes: { tenantId, projectId, graphId }
|
|
8934
8937
|
});
|
|
8935
8938
|
if (!agentGraph2?.contextConfigId) {
|
|
8936
8939
|
logger7.debug({ graphId }, "No context config found for graph, skipping validation");
|
|
@@ -9070,13 +9073,11 @@ function contextValidationMiddleware(dbClient) {
|
|
|
9070
9073
|
},
|
|
9071
9074
|
"Request context validation failed"
|
|
9072
9075
|
);
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
400
|
|
9079
|
-
);
|
|
9076
|
+
const errorMessage = `Invalid request context: ${validationResult.errors.map((e) => `${e.field}: ${e.message}`).join(", ")}`;
|
|
9077
|
+
throw createApiError({
|
|
9078
|
+
code: "bad_request",
|
|
9079
|
+
message: errorMessage
|
|
9080
|
+
});
|
|
9080
9081
|
}
|
|
9081
9082
|
c.set("validatedContext", validationResult.validatedContext);
|
|
9082
9083
|
logger7.debug(
|
|
@@ -9095,13 +9096,10 @@ function contextValidationMiddleware(dbClient) {
|
|
|
9095
9096
|
},
|
|
9096
9097
|
"Context validation middleware error"
|
|
9097
9098
|
);
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
},
|
|
9103
|
-
500
|
|
9104
|
-
);
|
|
9099
|
+
throw createApiError({
|
|
9100
|
+
code: "internal_server_error",
|
|
9101
|
+
message: "Context validation failed"
|
|
9102
|
+
});
|
|
9105
9103
|
}
|
|
9106
9104
|
};
|
|
9107
9105
|
}
|
|
@@ -9477,7 +9475,15 @@ async function handleContextConfigChange(tenantId, projectId, conversationId, gr
|
|
|
9477
9475
|
);
|
|
9478
9476
|
}
|
|
9479
9477
|
}
|
|
9480
|
-
async function handleContextResolution(
|
|
9478
|
+
async function handleContextResolution({
|
|
9479
|
+
tenantId,
|
|
9480
|
+
projectId,
|
|
9481
|
+
graphId,
|
|
9482
|
+
conversationId,
|
|
9483
|
+
requestContext,
|
|
9484
|
+
dbClient,
|
|
9485
|
+
credentialStores
|
|
9486
|
+
}) {
|
|
9481
9487
|
return tracer.startActiveSpan(
|
|
9482
9488
|
"context.handle_context_resolution",
|
|
9483
9489
|
{
|
|
@@ -9490,8 +9496,7 @@ async function handleContextResolution(tenantId, projectId, conversationId, grap
|
|
|
9490
9496
|
let trigger;
|
|
9491
9497
|
try {
|
|
9492
9498
|
agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
|
|
9493
|
-
scopes: { tenantId, projectId }
|
|
9494
|
-
graphId
|
|
9499
|
+
scopes: { tenantId, projectId, graphId }
|
|
9495
9500
|
});
|
|
9496
9501
|
if (!agentGraph2?.contextConfigId) {
|
|
9497
9502
|
logger9.debug({ graphId }, "No context config found for graph");
|
|
@@ -10192,7 +10197,7 @@ function createDefaultCredentialStores() {
|
|
|
10192
10197
|
if (process.env.NANGO_SECRET_KEY) {
|
|
10193
10198
|
stores.push(
|
|
10194
10199
|
createNangoCredentialStore("nango-default", {
|
|
10195
|
-
apiUrl: process.env.
|
|
10200
|
+
apiUrl: process.env.NANGO_SERVER_URL || "https://api.nango.dev",
|
|
10196
10201
|
secretKey: process.env.NANGO_SECRET_KEY
|
|
10197
10202
|
})
|
|
10198
10203
|
);
|
|
@@ -10214,12 +10219,13 @@ var loadEnvironmentFiles = () => {
|
|
|
10214
10219
|
}
|
|
10215
10220
|
const userConfigPath = path__default.default.join(os__default.default.homedir(), ".inkeep", "config");
|
|
10216
10221
|
if (fs__default.default.existsSync(userConfigPath)) {
|
|
10217
|
-
dotenv__default.default.config({ path: userConfigPath, override: true });
|
|
10222
|
+
dotenv__default.default.config({ path: userConfigPath, override: true, quiet: true });
|
|
10218
10223
|
}
|
|
10219
10224
|
if (environmentFiles.length > 0) {
|
|
10220
10225
|
dotenv__default.default.config({
|
|
10221
10226
|
path: environmentFiles,
|
|
10222
|
-
override: false
|
|
10227
|
+
override: false,
|
|
10228
|
+
quiet: true
|
|
10223
10229
|
});
|
|
10224
10230
|
dotenvExpand.expand({ processEnv: process.env });
|
|
10225
10231
|
}
|
|
@@ -10317,7 +10323,6 @@ exports.ArtifactComponentApiUpdateSchema = ArtifactComponentApiUpdateSchema;
|
|
|
10317
10323
|
exports.ArtifactComponentInsertSchema = ArtifactComponentInsertSchema;
|
|
10318
10324
|
exports.ArtifactComponentSelectSchema = ArtifactComponentSelectSchema;
|
|
10319
10325
|
exports.ArtifactComponentUpdateSchema = ArtifactComponentUpdateSchema;
|
|
10320
|
-
exports.ConsoleLogger = ConsoleLogger;
|
|
10321
10326
|
exports.ContextCache = ContextCache;
|
|
10322
10327
|
exports.ContextCacheApiInsertSchema = ContextCacheApiInsertSchema;
|
|
10323
10328
|
exports.ContextCacheApiSelectSchema = ContextCacheApiSelectSchema;
|
|
@@ -10405,9 +10410,9 @@ exports.MessageUpdateSchema = MessageUpdateSchema;
|
|
|
10405
10410
|
exports.ModelSchema = ModelSchema;
|
|
10406
10411
|
exports.ModelSettingsSchema = ModelSettingsSchema;
|
|
10407
10412
|
exports.NangoCredentialStore = NangoCredentialStore;
|
|
10408
|
-
exports.NoOpLogger = NoOpLogger;
|
|
10409
10413
|
exports.PaginationQueryParamsSchema = PaginationQueryParamsSchema;
|
|
10410
10414
|
exports.PaginationSchema = PaginationSchema;
|
|
10415
|
+
exports.PinoLogger = PinoLogger;
|
|
10411
10416
|
exports.ProjectApiInsertSchema = ProjectApiInsertSchema;
|
|
10412
10417
|
exports.ProjectApiSelectSchema = ProjectApiSelectSchema;
|
|
10413
10418
|
exports.ProjectApiUpdateSchema = ProjectApiUpdateSchema;
|
|
@@ -10437,6 +10442,8 @@ exports.TaskUpdateSchema = TaskUpdateSchema;
|
|
|
10437
10442
|
exports.TemplateEngine = TemplateEngine;
|
|
10438
10443
|
exports.TenantIdParamsSchema = TenantIdParamsSchema;
|
|
10439
10444
|
exports.TenantParamsSchema = TenantParamsSchema;
|
|
10445
|
+
exports.TenantProjectGraphIdParamsSchema = TenantProjectGraphIdParamsSchema;
|
|
10446
|
+
exports.TenantProjectGraphParamsSchema = TenantProjectGraphParamsSchema;
|
|
10440
10447
|
exports.TenantProjectIdParamsSchema = TenantProjectIdParamsSchema;
|
|
10441
10448
|
exports.TenantProjectParamsSchema = TenantProjectParamsSchema;
|
|
10442
10449
|
exports.ToolApiInsertSchema = ToolApiInsertSchema;
|
|
@@ -10453,6 +10460,7 @@ exports.addToolToAgent = addToolToAgent;
|
|
|
10453
10460
|
exports.agentArtifactComponents = agentArtifactComponents;
|
|
10454
10461
|
exports.agentArtifactComponentsRelations = agentArtifactComponentsRelations;
|
|
10455
10462
|
exports.agentDataComponents = agentDataComponents;
|
|
10463
|
+
exports.agentDataComponentsRelations = agentDataComponentsRelations;
|
|
10456
10464
|
exports.agentGraph = agentGraph;
|
|
10457
10465
|
exports.agentGraphRelations = agentGraphRelations;
|
|
10458
10466
|
exports.agentRelations = agentRelations;
|
|
@@ -10474,7 +10482,6 @@ exports.commonCreateErrorResponses = commonCreateErrorResponses;
|
|
|
10474
10482
|
exports.commonDeleteErrorResponses = commonDeleteErrorResponses;
|
|
10475
10483
|
exports.commonGetErrorResponses = commonGetErrorResponses;
|
|
10476
10484
|
exports.commonUpdateErrorResponses = commonUpdateErrorResponses;
|
|
10477
|
-
exports.configureLogging = configureLogging;
|
|
10478
10485
|
exports.contextCache = contextCache;
|
|
10479
10486
|
exports.contextCacheRelations = contextCacheRelations;
|
|
10480
10487
|
exports.contextConfig = contextConfig;
|
|
@@ -10523,6 +10530,7 @@ exports.createValidatedDataAccess = createValidatedDataAccess;
|
|
|
10523
10530
|
exports.credentialReferences = credentialReferences;
|
|
10524
10531
|
exports.credentialReferencesRelations = credentialReferencesRelations;
|
|
10525
10532
|
exports.dataComponents = dataComponents;
|
|
10533
|
+
exports.dataComponentsRelations = dataComponentsRelations;
|
|
10526
10534
|
exports.dbResultToMcpTool = dbResultToMcpTool;
|
|
10527
10535
|
exports.deleteAgent = deleteAgent;
|
|
10528
10536
|
exports.deleteAgentArtifactComponentRelationByAgent = deleteAgentArtifactComponentRelationByAgent;
|
|
@@ -10563,10 +10571,8 @@ exports.generateApiKey = generateApiKey;
|
|
|
10563
10571
|
exports.generateIdFromName = generateIdFromName;
|
|
10564
10572
|
exports.getActiveAgentForConversation = getActiveAgentForConversation;
|
|
10565
10573
|
exports.getAgentById = getAgentById;
|
|
10566
|
-
exports.getAgentGraph = getAgentGraph;
|
|
10567
10574
|
exports.getAgentGraphById = getAgentGraphById;
|
|
10568
10575
|
exports.getAgentGraphWithDefaultAgent = getAgentGraphWithDefaultAgent;
|
|
10569
|
-
exports.getAgentInGraphContext = getAgentInGraphContext;
|
|
10570
10576
|
exports.getAgentRelationById = getAgentRelationById;
|
|
10571
10577
|
exports.getAgentRelationByParams = getAgentRelationByParams;
|
|
10572
10578
|
exports.getAgentRelations = getAgentRelations;
|
|
@@ -10641,13 +10647,13 @@ exports.isValidHttpRequest = isValidHttpRequest;
|
|
|
10641
10647
|
exports.isValidResourceId = isValidResourceId;
|
|
10642
10648
|
exports.ledgerArtifacts = ledgerArtifacts;
|
|
10643
10649
|
exports.ledgerArtifactsContextIdIdx = ledgerArtifactsContextIdIdx;
|
|
10650
|
+
exports.ledgerArtifactsRelations = ledgerArtifactsRelations;
|
|
10644
10651
|
exports.ledgerArtifactsTaskContextNameUnique = ledgerArtifactsTaskContextNameUnique;
|
|
10645
10652
|
exports.ledgerArtifactsTaskIdIdx = ledgerArtifactsTaskIdIdx;
|
|
10646
10653
|
exports.listAgentGraphs = listAgentGraphs;
|
|
10647
10654
|
exports.listAgentGraphsPaginated = listAgentGraphsPaginated;
|
|
10648
10655
|
exports.listAgentRelations = listAgentRelations;
|
|
10649
10656
|
exports.listAgentToolRelations = listAgentToolRelations;
|
|
10650
|
-
exports.listAgentToolRelationsByAgent = listAgentToolRelationsByAgent;
|
|
10651
10657
|
exports.listAgents = listAgents;
|
|
10652
10658
|
exports.listAgentsPaginated = listAgentsPaginated;
|
|
10653
10659
|
exports.listApiKeys = listApiKeys;
|