@inkeep/agents-core 0.0.0-dev-20250917222639 → 0.0.0-dev-20250919052931
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-BAPMUHVN.js → chunk-IIW7VAP3.js} +20 -12
- package/dist/{chunk-MXQKLGQK.js → chunk-LFWFXR4O.js} +123 -82
- package/dist/{chunk-KNC2AOJM.js → chunk-ZORVFHVU.js} +76 -29
- 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 +529 -598
- package/dist/index.js +318 -485
- package/dist/validation/index.cjs +213 -118
- package/dist/validation/index.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -132,6 +132,7 @@ __export(schema_exports, {
|
|
|
132
132
|
agentArtifactComponents: () => agentArtifactComponents,
|
|
133
133
|
agentArtifactComponentsRelations: () => agentArtifactComponentsRelations,
|
|
134
134
|
agentDataComponents: () => agentDataComponents,
|
|
135
|
+
agentDataComponentsRelations: () => agentDataComponentsRelations,
|
|
135
136
|
agentGraph: () => agentGraph,
|
|
136
137
|
agentGraphRelations: () => agentGraphRelations,
|
|
137
138
|
agentRelations: () => agentRelations,
|
|
@@ -153,10 +154,12 @@ __export(schema_exports, {
|
|
|
153
154
|
credentialReferences: () => credentialReferences,
|
|
154
155
|
credentialReferencesRelations: () => credentialReferencesRelations,
|
|
155
156
|
dataComponents: () => dataComponents,
|
|
157
|
+
dataComponentsRelations: () => dataComponentsRelations,
|
|
156
158
|
externalAgents: () => externalAgents,
|
|
157
159
|
externalAgentsRelations: () => externalAgentsRelations,
|
|
158
160
|
ledgerArtifacts: () => ledgerArtifacts,
|
|
159
161
|
ledgerArtifactsContextIdIdx: () => ledgerArtifactsContextIdIdx,
|
|
162
|
+
ledgerArtifactsRelations: () => ledgerArtifactsRelations,
|
|
160
163
|
ledgerArtifactsTaskContextNameUnique: () => ledgerArtifactsTaskContextNameUnique,
|
|
161
164
|
ledgerArtifactsTaskIdIdx: () => ledgerArtifactsTaskIdIdx,
|
|
162
165
|
messages: () => messages,
|
|
@@ -187,11 +190,44 @@ var projects = sqliteCore.sqliteTable(
|
|
|
187
190
|
},
|
|
188
191
|
(table) => [sqliteCore.primaryKey({ columns: [table.tenantId, table.id] })]
|
|
189
192
|
);
|
|
193
|
+
var agentGraph = sqliteCore.sqliteTable(
|
|
194
|
+
"agent_graph",
|
|
195
|
+
{
|
|
196
|
+
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
197
|
+
projectId: sqliteCore.text("project_id").notNull(),
|
|
198
|
+
id: sqliteCore.text("id").notNull(),
|
|
199
|
+
name: sqliteCore.text("name").notNull(),
|
|
200
|
+
description: sqliteCore.text("description"),
|
|
201
|
+
defaultAgentId: sqliteCore.text("default_agent_id"),
|
|
202
|
+
// Reference to shared context configuration for all agents in this graph
|
|
203
|
+
contextConfigId: sqliteCore.text("context_config_id"),
|
|
204
|
+
// add fk relationship
|
|
205
|
+
// Graph-level model settingsuration that can be inherited by agents
|
|
206
|
+
models: sqliteCore.text("models", { mode: "json" }).$type(),
|
|
207
|
+
// Status updates configuration for intelligent progress summaries
|
|
208
|
+
statusUpdates: sqliteCore.text("status_updates", { mode: "json" }).$type(),
|
|
209
|
+
// Graph-level prompt that can be used as additional context for agents
|
|
210
|
+
graphPrompt: sqliteCore.text("graph_prompt"),
|
|
211
|
+
// Graph-level stopWhen configuration that can be inherited by agents
|
|
212
|
+
stopWhen: sqliteCore.text("stop_when", { mode: "json" }).$type(),
|
|
213
|
+
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
|
|
214
|
+
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
215
|
+
},
|
|
216
|
+
(table) => [
|
|
217
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
218
|
+
sqliteCore.foreignKey({
|
|
219
|
+
columns: [table.tenantId, table.projectId],
|
|
220
|
+
foreignColumns: [projects.tenantId, projects.id],
|
|
221
|
+
name: "agent_graph_project_fk"
|
|
222
|
+
}).onDelete("cascade")
|
|
223
|
+
]
|
|
224
|
+
);
|
|
190
225
|
var contextConfigs = sqliteCore.sqliteTable(
|
|
191
226
|
"context_configs",
|
|
192
227
|
{
|
|
193
228
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
194
229
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
230
|
+
// Add graph level scoping
|
|
195
231
|
id: sqliteCore.text("id").notNull(),
|
|
196
232
|
name: sqliteCore.text("name").notNull(),
|
|
197
233
|
description: sqliteCore.text("description").notNull(),
|
|
@@ -256,6 +292,7 @@ var agents = sqliteCore.sqliteTable(
|
|
|
256
292
|
{
|
|
257
293
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
258
294
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
295
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
259
296
|
id: sqliteCore.text("id").notNull(),
|
|
260
297
|
name: sqliteCore.text("name").notNull(),
|
|
261
298
|
description: sqliteCore.text("description").notNull(),
|
|
@@ -270,11 +307,11 @@ var agents = sqliteCore.sqliteTable(
|
|
|
270
307
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
271
308
|
},
|
|
272
309
|
(table) => [
|
|
273
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
310
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
274
311
|
sqliteCore.foreignKey({
|
|
275
|
-
columns: [table.tenantId, table.projectId],
|
|
276
|
-
foreignColumns: [
|
|
277
|
-
name: "
|
|
312
|
+
columns: [table.tenantId, table.projectId, table.graphId],
|
|
313
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
314
|
+
name: "agents_graph_fk"
|
|
278
315
|
}).onDelete("cascade")
|
|
279
316
|
]
|
|
280
317
|
);
|
|
@@ -283,8 +320,8 @@ var agentRelations = sqliteCore.sqliteTable(
|
|
|
283
320
|
{
|
|
284
321
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
285
322
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
286
|
-
id: sqliteCore.text("id").notNull(),
|
|
287
323
|
graphId: sqliteCore.text("graph_id").notNull(),
|
|
324
|
+
id: sqliteCore.text("id").notNull(),
|
|
288
325
|
sourceAgentId: sqliteCore.text("source_agent_id").notNull(),
|
|
289
326
|
// For internal relationships
|
|
290
327
|
targetAgentId: sqliteCore.text("target_agent_id"),
|
|
@@ -296,11 +333,11 @@ var agentRelations = sqliteCore.sqliteTable(
|
|
|
296
333
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
297
334
|
},
|
|
298
335
|
(table) => [
|
|
299
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
336
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
300
337
|
sqliteCore.foreignKey({
|
|
301
|
-
columns: [table.tenantId, table.projectId],
|
|
302
|
-
foreignColumns: [
|
|
303
|
-
name: "
|
|
338
|
+
columns: [table.tenantId, table.projectId, table.graphId],
|
|
339
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
340
|
+
name: "agent_relations_graph_fk"
|
|
304
341
|
}).onDelete("cascade")
|
|
305
342
|
]
|
|
306
343
|
);
|
|
@@ -309,6 +346,7 @@ var externalAgents = sqliteCore.sqliteTable(
|
|
|
309
346
|
{
|
|
310
347
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
311
348
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
349
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
312
350
|
id: sqliteCore.text("id").notNull(),
|
|
313
351
|
name: sqliteCore.text("name").notNull(),
|
|
314
352
|
description: sqliteCore.text("description").notNull(),
|
|
@@ -320,11 +358,11 @@ var externalAgents = sqliteCore.sqliteTable(
|
|
|
320
358
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
321
359
|
},
|
|
322
360
|
(table) => [
|
|
323
|
-
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
361
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
324
362
|
sqliteCore.foreignKey({
|
|
325
|
-
columns: [table.tenantId, table.projectId],
|
|
326
|
-
foreignColumns: [
|
|
327
|
-
name: "
|
|
363
|
+
columns: [table.tenantId, table.projectId, table.graphId],
|
|
364
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
365
|
+
name: "external_agents_graph_fk"
|
|
328
366
|
}).onDelete("cascade"),
|
|
329
367
|
sqliteCore.foreignKey({
|
|
330
368
|
columns: [table.tenantId, table.projectId, table.credentialReferenceId],
|
|
@@ -337,37 +375,6 @@ var externalAgents = sqliteCore.sqliteTable(
|
|
|
337
375
|
}).onDelete("set null")
|
|
338
376
|
]
|
|
339
377
|
);
|
|
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
378
|
var tasks = sqliteCore.sqliteTable(
|
|
372
379
|
"tasks",
|
|
373
380
|
{
|
|
@@ -438,23 +445,18 @@ var agentDataComponents = sqliteCore.sqliteTable(
|
|
|
438
445
|
{
|
|
439
446
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
440
447
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
441
|
-
|
|
448
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
442
449
|
agentId: sqliteCore.text("agent_id").notNull(),
|
|
450
|
+
id: sqliteCore.text("id").notNull(),
|
|
443
451
|
dataComponentId: sqliteCore.text("data_component_id").notNull(),
|
|
444
452
|
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
445
453
|
},
|
|
446
454
|
(table) => [
|
|
447
455
|
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
448
|
-
// Foreign key constraint to
|
|
456
|
+
// Foreign key constraint to agents table (ensures graph and project exist via cascade)
|
|
449
457
|
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],
|
|
458
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
|
|
459
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
|
|
458
460
|
name: "agent_data_components_agent_fk"
|
|
459
461
|
}).onDelete("cascade"),
|
|
460
462
|
// Foreign key constraint to data_components table
|
|
@@ -492,23 +494,20 @@ var agentArtifactComponents = sqliteCore.sqliteTable(
|
|
|
492
494
|
{
|
|
493
495
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
494
496
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
495
|
-
|
|
497
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
496
498
|
agentId: sqliteCore.text("agent_id").notNull(),
|
|
499
|
+
id: sqliteCore.text("id").notNull(),
|
|
497
500
|
artifactComponentId: sqliteCore.text("artifact_component_id").notNull(),
|
|
498
501
|
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
499
502
|
},
|
|
500
503
|
(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
|
|
504
|
+
sqliteCore.primaryKey({
|
|
505
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId, table.id]
|
|
506
|
+
}),
|
|
507
|
+
// Foreign key constraint to agents table (ensures graph and project exist via cascade)
|
|
509
508
|
sqliteCore.foreignKey({
|
|
510
|
-
columns: [table.tenantId, table.projectId, table.agentId],
|
|
511
|
-
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
509
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
|
|
510
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
|
|
512
511
|
name: "agent_artifact_components_agent_fk"
|
|
513
512
|
}).onDelete("cascade"),
|
|
514
513
|
// Foreign key constraint to artifact_components table
|
|
@@ -562,25 +561,20 @@ var agentToolRelations = sqliteCore.sqliteTable(
|
|
|
562
561
|
{
|
|
563
562
|
tenantId: sqliteCore.text("tenant_id").notNull(),
|
|
564
563
|
projectId: sqliteCore.text("project_id").notNull(),
|
|
565
|
-
|
|
564
|
+
graphId: sqliteCore.text("graph_id").notNull(),
|
|
566
565
|
agentId: sqliteCore.text("agent_id").notNull(),
|
|
566
|
+
id: sqliteCore.text("id").notNull(),
|
|
567
567
|
toolId: sqliteCore.text("tool_id").notNull(),
|
|
568
568
|
selectedTools: sqliteCore.blob("selected_tools", { mode: "json" }).$type(),
|
|
569
569
|
createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
|
|
570
570
|
updatedAt: sqliteCore.text("updated_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`)
|
|
571
571
|
},
|
|
572
572
|
(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
|
|
573
|
+
sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
|
|
574
|
+
// Foreign key constraint to agents table (which includes project and graph scope)
|
|
581
575
|
sqliteCore.foreignKey({
|
|
582
|
-
columns: [table.tenantId, table.projectId, table.agentId],
|
|
583
|
-
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
576
|
+
columns: [table.tenantId, table.projectId, table.graphId, table.agentId],
|
|
577
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.graphId, agents.id],
|
|
584
578
|
name: "agent_tool_relations_agent_fk"
|
|
585
579
|
}).onDelete("cascade"),
|
|
586
580
|
// Foreign key constraint to tools table
|
|
@@ -787,7 +781,9 @@ var tasksRelations = drizzleOrm.relations(tasks, ({ one, many }) => ({
|
|
|
787
781
|
references: [agents.id]
|
|
788
782
|
}),
|
|
789
783
|
// A task can have many messages associated with it
|
|
790
|
-
messages: many(messages)
|
|
784
|
+
messages: many(messages),
|
|
785
|
+
// A task can have many ledger artifacts
|
|
786
|
+
ledgerArtifacts: many(ledgerArtifacts)
|
|
791
787
|
}));
|
|
792
788
|
var projectsRelations = drizzleOrm.relations(projects, ({ many }) => ({
|
|
793
789
|
// A project can have many agents
|
|
@@ -803,7 +799,15 @@ var projectsRelations = drizzleOrm.relations(projects, ({ many }) => ({
|
|
|
803
799
|
// A project can have many conversations
|
|
804
800
|
conversations: many(conversations),
|
|
805
801
|
// A project can have many tasks
|
|
806
|
-
tasks: many(tasks)
|
|
802
|
+
tasks: many(tasks),
|
|
803
|
+
// A project can have many data components
|
|
804
|
+
dataComponents: many(dataComponents),
|
|
805
|
+
// A project can have many artifact components
|
|
806
|
+
artifactComponents: many(artifactComponents),
|
|
807
|
+
// A project can have many ledger artifacts
|
|
808
|
+
ledgerArtifacts: many(ledgerArtifacts),
|
|
809
|
+
// A project can have many credential references
|
|
810
|
+
credentialReferences: many(credentialReferences)
|
|
807
811
|
}));
|
|
808
812
|
var taskRelationsRelations = drizzleOrm.relations(taskRelations, ({ one }) => ({
|
|
809
813
|
// Each relation has one parent task
|
|
@@ -865,7 +869,11 @@ var agentsRelations = drizzleOrm.relations(agents, ({ many, one }) => ({
|
|
|
865
869
|
associatedMessages: many(messages, {
|
|
866
870
|
relationName: "associatedAgent"
|
|
867
871
|
}),
|
|
868
|
-
toolRelations: many(agentToolRelations)
|
|
872
|
+
toolRelations: many(agentToolRelations),
|
|
873
|
+
// Data component relations
|
|
874
|
+
dataComponentRelations: many(agentDataComponents),
|
|
875
|
+
// Artifact component relations
|
|
876
|
+
artifactComponentRelations: many(agentArtifactComponents)
|
|
869
877
|
}));
|
|
870
878
|
var agentGraphRelations = drizzleOrm.relations(agentGraph, ({ one }) => ({
|
|
871
879
|
// An agent graph belongs to one project
|
|
@@ -873,7 +881,7 @@ var agentGraphRelations = drizzleOrm.relations(agentGraph, ({ one }) => ({
|
|
|
873
881
|
fields: [agentGraph.tenantId, agentGraph.projectId],
|
|
874
882
|
references: [projects.tenantId, projects.id]
|
|
875
883
|
}),
|
|
876
|
-
// An agent graph
|
|
884
|
+
// An agent graph may have one default agent (optional)
|
|
877
885
|
defaultAgent: one(agents, {
|
|
878
886
|
fields: [agentGraph.defaultAgentId],
|
|
879
887
|
references: [agents.id]
|
|
@@ -1021,6 +1029,39 @@ var agentArtifactComponentsRelations = drizzleOrm.relations(agentArtifactCompone
|
|
|
1021
1029
|
references: [artifactComponents.id]
|
|
1022
1030
|
})
|
|
1023
1031
|
}));
|
|
1032
|
+
var dataComponentsRelations = drizzleOrm.relations(dataComponents, ({ many, one }) => ({
|
|
1033
|
+
// A data component belongs to one project
|
|
1034
|
+
project: one(projects, {
|
|
1035
|
+
fields: [dataComponents.tenantId, dataComponents.projectId],
|
|
1036
|
+
references: [projects.tenantId, projects.id]
|
|
1037
|
+
}),
|
|
1038
|
+
// A data component can be associated with many agents
|
|
1039
|
+
agentRelations: many(agentDataComponents)
|
|
1040
|
+
}));
|
|
1041
|
+
var agentDataComponentsRelations = drizzleOrm.relations(agentDataComponents, ({ one }) => ({
|
|
1042
|
+
// An agent-data component relation belongs to one agent
|
|
1043
|
+
agent: one(agents, {
|
|
1044
|
+
fields: [agentDataComponents.agentId],
|
|
1045
|
+
references: [agents.id]
|
|
1046
|
+
}),
|
|
1047
|
+
// An agent-data component relation belongs to one data component
|
|
1048
|
+
dataComponent: one(dataComponents, {
|
|
1049
|
+
fields: [agentDataComponents.dataComponentId],
|
|
1050
|
+
references: [dataComponents.id]
|
|
1051
|
+
})
|
|
1052
|
+
}));
|
|
1053
|
+
var ledgerArtifactsRelations = drizzleOrm.relations(ledgerArtifacts, ({ one }) => ({
|
|
1054
|
+
// A ledger artifact belongs to one project
|
|
1055
|
+
project: one(projects, {
|
|
1056
|
+
fields: [ledgerArtifacts.tenantId, ledgerArtifacts.projectId],
|
|
1057
|
+
references: [projects.tenantId, projects.id]
|
|
1058
|
+
}),
|
|
1059
|
+
// A ledger artifact may be associated with one task
|
|
1060
|
+
task: one(tasks, {
|
|
1061
|
+
fields: [ledgerArtifacts.taskId],
|
|
1062
|
+
references: [tasks.id]
|
|
1063
|
+
})
|
|
1064
|
+
}));
|
|
1024
1065
|
var agentRelationsRelations = drizzleOrm.relations(agentRelations, ({ one }) => ({
|
|
1025
1066
|
// An agent relation belongs to one graph
|
|
1026
1067
|
graph: one(agentGraph, {
|
|
@@ -1102,15 +1143,18 @@ var ProjectModelSchema = zodOpenapi.z.object({
|
|
|
1102
1143
|
var createApiSchema = (schema) => schema.omit({ tenantId: true, projectId: true });
|
|
1103
1144
|
var createApiInsertSchema = (schema) => schema.omit({ tenantId: true, projectId: true });
|
|
1104
1145
|
var createApiUpdateSchema = (schema) => schema.omit({ tenantId: true, projectId: true }).partial();
|
|
1146
|
+
var createGraphScopedApiSchema = (schema) => schema.omit({ tenantId: true, projectId: true, graphId: true });
|
|
1147
|
+
var createGraphScopedApiInsertSchema = (schema) => schema.omit({ tenantId: true, projectId: true, graphId: true });
|
|
1148
|
+
var createGraphScopedApiUpdateSchema = (schema) => schema.omit({ tenantId: true, projectId: true, graphId: true }).partial();
|
|
1105
1149
|
var AgentSelectSchema = drizzleZod.createSelectSchema(agents);
|
|
1106
1150
|
var AgentInsertSchema = drizzleZod.createInsertSchema(agents).extend({
|
|
1107
1151
|
id: resourceIdSchema,
|
|
1108
1152
|
models: ModelSchema.optional()
|
|
1109
1153
|
});
|
|
1110
1154
|
var AgentUpdateSchema = AgentInsertSchema.partial();
|
|
1111
|
-
var AgentApiSelectSchema =
|
|
1112
|
-
var AgentApiInsertSchema =
|
|
1113
|
-
var AgentApiUpdateSchema =
|
|
1155
|
+
var AgentApiSelectSchema = createGraphScopedApiSchema(AgentSelectSchema);
|
|
1156
|
+
var AgentApiInsertSchema = createGraphScopedApiInsertSchema(AgentInsertSchema);
|
|
1157
|
+
var AgentApiUpdateSchema = createGraphScopedApiUpdateSchema(AgentUpdateSchema);
|
|
1114
1158
|
var AgentRelationSelectSchema = drizzleZod.createSelectSchema(agentRelations);
|
|
1115
1159
|
var AgentRelationInsertSchema = drizzleZod.createInsertSchema(agentRelations).extend({
|
|
1116
1160
|
id: resourceIdSchema,
|
|
@@ -1120,8 +1164,10 @@ var AgentRelationInsertSchema = drizzleZod.createInsertSchema(agentRelations).ex
|
|
|
1120
1164
|
externalAgentId: resourceIdSchema.optional()
|
|
1121
1165
|
});
|
|
1122
1166
|
var AgentRelationUpdateSchema = AgentRelationInsertSchema.partial();
|
|
1123
|
-
var AgentRelationApiSelectSchema =
|
|
1124
|
-
var AgentRelationApiInsertSchema =
|
|
1167
|
+
var AgentRelationApiSelectSchema = createGraphScopedApiSchema(AgentRelationSelectSchema);
|
|
1168
|
+
var AgentRelationApiInsertSchema = createGraphScopedApiInsertSchema(
|
|
1169
|
+
AgentRelationInsertSchema
|
|
1170
|
+
).extend({
|
|
1125
1171
|
relationType: zodOpenapi.z.enum(VALID_RELATION_TYPES)
|
|
1126
1172
|
}).refine(
|
|
1127
1173
|
(data) => {
|
|
@@ -1134,7 +1180,9 @@ var AgentRelationApiInsertSchema = createApiInsertSchema(AgentRelationInsertSche
|
|
|
1134
1180
|
path: ["targetAgentId", "externalAgentId"]
|
|
1135
1181
|
}
|
|
1136
1182
|
);
|
|
1137
|
-
var AgentRelationApiUpdateSchema =
|
|
1183
|
+
var AgentRelationApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1184
|
+
AgentRelationUpdateSchema
|
|
1185
|
+
).extend({
|
|
1138
1186
|
relationType: zodOpenapi.z.enum(VALID_RELATION_TYPES).optional()
|
|
1139
1187
|
}).refine(
|
|
1140
1188
|
(data) => {
|
|
@@ -1171,7 +1219,7 @@ var AgentGraphInsertSchema = drizzleZod.createInsertSchema(agentGraph).extend({
|
|
|
1171
1219
|
var AgentGraphUpdateSchema = AgentGraphInsertSchema.partial();
|
|
1172
1220
|
var AgentGraphApiSelectSchema = createApiSchema(AgentGraphSelectSchema);
|
|
1173
1221
|
var AgentGraphApiInsertSchema = createApiInsertSchema(AgentGraphInsertSchema).extend({
|
|
1174
|
-
id: resourceIdSchema
|
|
1222
|
+
id: resourceIdSchema
|
|
1175
1223
|
});
|
|
1176
1224
|
var AgentGraphApiUpdateSchema = createApiUpdateSchema(AgentGraphUpdateSchema);
|
|
1177
1225
|
var TaskSelectSchema = drizzleZod.createSelectSchema(tasks);
|
|
@@ -1270,11 +1318,16 @@ var DataComponentApiUpdateSchema = createApiUpdateSchema(DataComponentUpdateSche
|
|
|
1270
1318
|
var AgentDataComponentSelectSchema = drizzleZod.createSelectSchema(agentDataComponents);
|
|
1271
1319
|
var AgentDataComponentInsertSchema = drizzleZod.createInsertSchema(agentDataComponents);
|
|
1272
1320
|
var AgentDataComponentUpdateSchema = AgentDataComponentInsertSchema.partial();
|
|
1273
|
-
var AgentDataComponentApiSelectSchema =
|
|
1274
|
-
|
|
1275
|
-
AgentDataComponentInsertSchema
|
|
1321
|
+
var AgentDataComponentApiSelectSchema = createGraphScopedApiSchema(
|
|
1322
|
+
AgentDataComponentSelectSchema
|
|
1276
1323
|
);
|
|
1277
|
-
var
|
|
1324
|
+
var AgentDataComponentApiInsertSchema = AgentDataComponentInsertSchema.omit({
|
|
1325
|
+
tenantId: true,
|
|
1326
|
+
projectId: true,
|
|
1327
|
+
id: true,
|
|
1328
|
+
createdAt: true
|
|
1329
|
+
});
|
|
1330
|
+
var AgentDataComponentApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1278
1331
|
AgentDataComponentUpdateSchema
|
|
1279
1332
|
);
|
|
1280
1333
|
var ArtifactComponentSelectSchema = drizzleZod.createSelectSchema(artifactComponents);
|
|
@@ -1303,7 +1356,7 @@ var AgentArtifactComponentInsertSchema = drizzleZod.createInsertSchema(
|
|
|
1303
1356
|
artifactComponentId: resourceIdSchema
|
|
1304
1357
|
});
|
|
1305
1358
|
var AgentArtifactComponentUpdateSchema = AgentArtifactComponentInsertSchema.partial();
|
|
1306
|
-
var AgentArtifactComponentApiSelectSchema =
|
|
1359
|
+
var AgentArtifactComponentApiSelectSchema = createGraphScopedApiSchema(
|
|
1307
1360
|
AgentArtifactComponentSelectSchema
|
|
1308
1361
|
);
|
|
1309
1362
|
var AgentArtifactComponentApiInsertSchema = AgentArtifactComponentInsertSchema.omit({
|
|
@@ -1312,7 +1365,7 @@ var AgentArtifactComponentApiInsertSchema = AgentArtifactComponentInsertSchema.o
|
|
|
1312
1365
|
id: true,
|
|
1313
1366
|
createdAt: true
|
|
1314
1367
|
});
|
|
1315
|
-
var AgentArtifactComponentApiUpdateSchema =
|
|
1368
|
+
var AgentArtifactComponentApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1316
1369
|
AgentArtifactComponentUpdateSchema
|
|
1317
1370
|
);
|
|
1318
1371
|
var ExternalAgentSelectSchema = drizzleZod.createSelectSchema(externalAgents).extend({
|
|
@@ -1323,9 +1376,9 @@ var ExternalAgentInsertSchema = drizzleZod.createInsertSchema(externalAgents).ex
|
|
|
1323
1376
|
id: resourceIdSchema
|
|
1324
1377
|
});
|
|
1325
1378
|
var ExternalAgentUpdateSchema = ExternalAgentInsertSchema.partial();
|
|
1326
|
-
var ExternalAgentApiSelectSchema =
|
|
1327
|
-
var ExternalAgentApiInsertSchema =
|
|
1328
|
-
var ExternalAgentApiUpdateSchema =
|
|
1379
|
+
var ExternalAgentApiSelectSchema = createGraphScopedApiSchema(ExternalAgentSelectSchema);
|
|
1380
|
+
var ExternalAgentApiInsertSchema = createGraphScopedApiInsertSchema(ExternalAgentInsertSchema);
|
|
1381
|
+
var ExternalAgentApiUpdateSchema = createGraphScopedApiUpdateSchema(ExternalAgentUpdateSchema);
|
|
1329
1382
|
var AllAgentSchema = zodOpenapi.z.discriminatedUnion("type", [
|
|
1330
1383
|
AgentApiSelectSchema.extend({ type: zodOpenapi.z.literal("internal") }),
|
|
1331
1384
|
ExternalAgentApiSelectSchema.extend({ type: zodOpenapi.z.literal("external") })
|
|
@@ -1381,10 +1434,8 @@ var CredentialReferenceSelectSchema = zodOpenapi.z.object({
|
|
|
1381
1434
|
createdAt: zodOpenapi.z.string(),
|
|
1382
1435
|
updatedAt: zodOpenapi.z.string()
|
|
1383
1436
|
});
|
|
1384
|
-
var CredentialReferenceInsertSchema =
|
|
1437
|
+
var CredentialReferenceInsertSchema = drizzleZod.createInsertSchema(credentialReferences).extend({
|
|
1385
1438
|
id: resourceIdSchema,
|
|
1386
|
-
tenantId: zodOpenapi.z.string(),
|
|
1387
|
-
projectId: zodOpenapi.z.string(),
|
|
1388
1439
|
type: zodOpenapi.z.string(),
|
|
1389
1440
|
credentialStoreId: resourceIdSchema,
|
|
1390
1441
|
retrievalParams: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.unknown()).nullish()
|
|
@@ -1480,11 +1531,13 @@ var AgentToolRelationInsertSchema = drizzleZod.createInsertSchema(agentToolRelat
|
|
|
1480
1531
|
selectedTools: zodOpenapi.z.array(zodOpenapi.z.string()).nullish()
|
|
1481
1532
|
});
|
|
1482
1533
|
var AgentToolRelationUpdateSchema = AgentToolRelationInsertSchema.partial();
|
|
1483
|
-
var AgentToolRelationApiSelectSchema =
|
|
1484
|
-
|
|
1534
|
+
var AgentToolRelationApiSelectSchema = createGraphScopedApiSchema(
|
|
1535
|
+
AgentToolRelationSelectSchema
|
|
1536
|
+
);
|
|
1537
|
+
var AgentToolRelationApiInsertSchema = createGraphScopedApiInsertSchema(
|
|
1485
1538
|
AgentToolRelationInsertSchema
|
|
1486
1539
|
);
|
|
1487
|
-
var AgentToolRelationApiUpdateSchema =
|
|
1540
|
+
var AgentToolRelationApiUpdateSchema = createGraphScopedApiUpdateSchema(
|
|
1488
1541
|
AgentToolRelationUpdateSchema
|
|
1489
1542
|
);
|
|
1490
1543
|
var LedgerArtifactSelectSchema = drizzleZod.createSelectSchema(ledgerArtifacts);
|
|
@@ -1510,6 +1563,7 @@ var StatusUpdateSchema = zodOpenapi.z.object({
|
|
|
1510
1563
|
statusComponents: zodOpenapi.z.array(StatusComponentSchema).optional()
|
|
1511
1564
|
});
|
|
1512
1565
|
var FullGraphAgentInsertSchema = AgentApiInsertSchema.extend({
|
|
1566
|
+
type: zodOpenapi.z.literal("internal"),
|
|
1513
1567
|
tools: zodOpenapi.z.array(zodOpenapi.z.string()),
|
|
1514
1568
|
selectedTools: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.array(zodOpenapi.z.string())).optional(),
|
|
1515
1569
|
dataComponents: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
|
|
@@ -1519,10 +1573,9 @@ var FullGraphAgentInsertSchema = AgentApiInsertSchema.extend({
|
|
|
1519
1573
|
});
|
|
1520
1574
|
var FullGraphDefinitionSchema = AgentGraphApiInsertSchema.extend({
|
|
1521
1575
|
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(),
|
|
1576
|
+
// Removed project-scoped resources - these are now managed at project level:
|
|
1577
|
+
// tools, credentialReferences, dataComponents, artifactComponents
|
|
1578
|
+
// Agent relationships to these resources are maintained via agent.tools, agent.dataComponents, etc.
|
|
1526
1579
|
contextConfig: zodOpenapi.z.optional(ContextConfigApiInsertSchema),
|
|
1527
1580
|
statusUpdates: zodOpenapi.z.optional(StatusUpdateSchema),
|
|
1528
1581
|
models: ModelSchema.optional(),
|
|
@@ -1530,7 +1583,13 @@ var FullGraphDefinitionSchema = AgentGraphApiInsertSchema.extend({
|
|
|
1530
1583
|
graphPrompt: zodOpenapi.z.string().max(5e3, "Graph prompt cannot exceed 5000 characters").optional()
|
|
1531
1584
|
});
|
|
1532
1585
|
var GraphWithinContextOfProjectSchema = AgentGraphApiInsertSchema.extend({
|
|
1533
|
-
agents: zodOpenapi.z.record(
|
|
1586
|
+
agents: zodOpenapi.z.record(
|
|
1587
|
+
zodOpenapi.z.string(),
|
|
1588
|
+
zodOpenapi.z.discriminatedUnion("type", [
|
|
1589
|
+
FullGraphAgentInsertSchema,
|
|
1590
|
+
ExternalAgentApiInsertSchema.extend({ type: zodOpenapi.z.literal("external") })
|
|
1591
|
+
])
|
|
1592
|
+
),
|
|
1534
1593
|
models: ModelSchema.optional(),
|
|
1535
1594
|
stopWhen: GraphStopWhenSchema.optional(),
|
|
1536
1595
|
graphPrompt: zodOpenapi.z.string().max(5e3, "Graph prompt cannot exceed 5000 characters").optional()
|
|
@@ -1613,6 +1672,35 @@ var TenantProjectParamsSchema = zodOpenapi.z.object({
|
|
|
1613
1672
|
example: "project_456"
|
|
1614
1673
|
})
|
|
1615
1674
|
}).openapi("TenantProjectParams");
|
|
1675
|
+
var TenantProjectGraphParamsSchema = zodOpenapi.z.object({
|
|
1676
|
+
tenantId: zodOpenapi.z.string().openapi({
|
|
1677
|
+
description: "Tenant identifier",
|
|
1678
|
+
example: "tenant_123"
|
|
1679
|
+
}),
|
|
1680
|
+
projectId: zodOpenapi.z.string().openapi({
|
|
1681
|
+
description: "Project identifier",
|
|
1682
|
+
example: "project_456"
|
|
1683
|
+
}),
|
|
1684
|
+
graphId: zodOpenapi.z.string().openapi({
|
|
1685
|
+
description: "Graph identifier",
|
|
1686
|
+
example: "graph_789"
|
|
1687
|
+
})
|
|
1688
|
+
}).openapi("TenantProjectGraphParams");
|
|
1689
|
+
var TenantProjectGraphIdParamsSchema = zodOpenapi.z.object({
|
|
1690
|
+
tenantId: zodOpenapi.z.string().openapi({
|
|
1691
|
+
description: "Tenant identifier",
|
|
1692
|
+
example: "tenant_123"
|
|
1693
|
+
}),
|
|
1694
|
+
projectId: zodOpenapi.z.string().openapi({
|
|
1695
|
+
description: "Project identifier",
|
|
1696
|
+
example: "project_456"
|
|
1697
|
+
}),
|
|
1698
|
+
graphId: zodOpenapi.z.string().openapi({
|
|
1699
|
+
description: "Graph identifier",
|
|
1700
|
+
example: "graph_789"
|
|
1701
|
+
}),
|
|
1702
|
+
id: resourceIdSchema
|
|
1703
|
+
}).openapi("TenantProjectGraphIdParams");
|
|
1616
1704
|
var TenantProjectIdParamsSchema = zodOpenapi.z.object({
|
|
1617
1705
|
tenantId: zodOpenapi.z.string().openapi({
|
|
1618
1706
|
description: "Tenant identifier",
|
|
@@ -2329,6 +2417,7 @@ var getAgentRelationById = (db) => async (params) => {
|
|
|
2329
2417
|
where: drizzleOrm.and(
|
|
2330
2418
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2331
2419
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2420
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2332
2421
|
drizzleOrm.eq(agentRelations.id, params.relationId)
|
|
2333
2422
|
)
|
|
2334
2423
|
});
|
|
@@ -2339,7 +2428,8 @@ var listAgentRelations = (db) => async (params) => {
|
|
|
2339
2428
|
const offset = (page - 1) * limit;
|
|
2340
2429
|
const whereClause = drizzleOrm.and(
|
|
2341
2430
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2342
|
-
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId)
|
|
2431
|
+
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2432
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
2343
2433
|
);
|
|
2344
2434
|
const [data, totalResult] = await Promise.all([
|
|
2345
2435
|
db.select().from(agentRelations).where(whereClause).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentRelations.createdAt)),
|
|
@@ -2354,8 +2444,8 @@ var getAgentRelations = (db) => async (params) => {
|
|
|
2354
2444
|
where: drizzleOrm.and(
|
|
2355
2445
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2356
2446
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2357
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2358
|
-
drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId)
|
|
2447
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2448
|
+
drizzleOrm.eq(agentRelations.sourceAgentId, params.scopes.agentId)
|
|
2359
2449
|
)
|
|
2360
2450
|
});
|
|
2361
2451
|
};
|
|
@@ -2364,7 +2454,7 @@ var getAgentRelationsByGraph = (db) => async (params) => {
|
|
|
2364
2454
|
where: drizzleOrm.and(
|
|
2365
2455
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2366
2456
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2367
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
2457
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
2368
2458
|
)
|
|
2369
2459
|
});
|
|
2370
2460
|
};
|
|
@@ -2375,6 +2465,7 @@ var getAgentRelationsBySource = (db) => async (params) => {
|
|
|
2375
2465
|
const whereClause = drizzleOrm.and(
|
|
2376
2466
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2377
2467
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2468
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2378
2469
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.sourceAgentId)
|
|
2379
2470
|
);
|
|
2380
2471
|
const [data, totalResult] = await Promise.all([
|
|
@@ -2395,6 +2486,7 @@ var getAgentRelationsByTarget = (db) => async (params) => {
|
|
|
2395
2486
|
const whereClause = drizzleOrm.and(
|
|
2396
2487
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2397
2488
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2489
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2398
2490
|
drizzleOrm.eq(agentRelations.targetAgentId, params.targetAgentId)
|
|
2399
2491
|
);
|
|
2400
2492
|
const [data, totalResult] = await Promise.all([
|
|
@@ -2415,6 +2507,7 @@ var getExternalAgentRelations = (db) => async (params) => {
|
|
|
2415
2507
|
const whereClause = drizzleOrm.and(
|
|
2416
2508
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2417
2509
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2510
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2418
2511
|
drizzleOrm.eq(agentRelations.externalAgentId, params.externalAgentId)
|
|
2419
2512
|
);
|
|
2420
2513
|
const [data, totalResult] = await Promise.all([
|
|
@@ -2438,11 +2531,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
2438
2531
|
drizzleOrm.and(
|
|
2439
2532
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2440
2533
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2441
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2534
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2442
2535
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId),
|
|
2443
2536
|
drizzleOrm.isNotNull(agentRelations.targetAgentId),
|
|
2444
2537
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2445
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId)
|
|
2538
|
+
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2539
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId)
|
|
2446
2540
|
)
|
|
2447
2541
|
);
|
|
2448
2542
|
const externalRelations = await db.select({
|
|
@@ -2458,11 +2552,12 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
|
|
|
2458
2552
|
drizzleOrm.and(
|
|
2459
2553
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2460
2554
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2461
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2555
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2462
2556
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId),
|
|
2463
2557
|
drizzleOrm.isNotNull(agentRelations.externalAgentId),
|
|
2464
2558
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
2465
|
-
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId)
|
|
2559
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
2560
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
2466
2561
|
)
|
|
2467
2562
|
);
|
|
2468
2563
|
return {
|
|
@@ -2488,7 +2583,7 @@ var getAgentRelationByParams = (db) => async (params) => {
|
|
|
2488
2583
|
const whereConditions = [
|
|
2489
2584
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2490
2585
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2491
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId),
|
|
2586
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2492
2587
|
drizzleOrm.eq(agentRelations.sourceAgentId, params.sourceAgentId),
|
|
2493
2588
|
drizzleOrm.eq(agentRelations.relationType, params.relationType)
|
|
2494
2589
|
];
|
|
@@ -2504,8 +2599,7 @@ var getAgentRelationByParams = (db) => async (params) => {
|
|
|
2504
2599
|
};
|
|
2505
2600
|
var upsertAgentRelation = (db) => async (params) => {
|
|
2506
2601
|
const existing = await getAgentRelationByParams(db)({
|
|
2507
|
-
scopes: { tenantId: params.tenantId, projectId: params.projectId },
|
|
2508
|
-
graphId: params.graphId,
|
|
2602
|
+
scopes: { tenantId: params.tenantId, projectId: params.projectId, graphId: params.graphId },
|
|
2509
2603
|
sourceAgentId: params.sourceAgentId,
|
|
2510
2604
|
targetAgentId: params.targetAgentId,
|
|
2511
2605
|
externalAgentId: params.externalAgentId,
|
|
@@ -2531,6 +2625,7 @@ var updateAgentRelation = (db) => async (params) => {
|
|
|
2531
2625
|
drizzleOrm.and(
|
|
2532
2626
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2533
2627
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2628
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2534
2629
|
drizzleOrm.eq(agentRelations.id, params.relationId)
|
|
2535
2630
|
)
|
|
2536
2631
|
).returning();
|
|
@@ -2541,6 +2636,7 @@ var deleteAgentRelation = (db) => async (params) => {
|
|
|
2541
2636
|
drizzleOrm.and(
|
|
2542
2637
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2543
2638
|
drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
|
|
2639
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
|
|
2544
2640
|
drizzleOrm.eq(agentRelations.id, params.relationId)
|
|
2545
2641
|
)
|
|
2546
2642
|
);
|
|
@@ -2550,7 +2646,7 @@ var deleteAgentRelationsByGraph = (db) => async (params) => {
|
|
|
2550
2646
|
const result = await db.delete(agentRelations).where(
|
|
2551
2647
|
drizzleOrm.and(
|
|
2552
2648
|
drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
|
|
2553
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
2649
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
2554
2650
|
)
|
|
2555
2651
|
);
|
|
2556
2652
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -2561,6 +2657,7 @@ var createAgentToolRelation = (db) => async (params) => {
|
|
|
2561
2657
|
id: finalRelationId,
|
|
2562
2658
|
tenantId: params.scopes.tenantId,
|
|
2563
2659
|
projectId: params.scopes.projectId,
|
|
2660
|
+
graphId: params.scopes.graphId,
|
|
2564
2661
|
agentId: params.data.agentId,
|
|
2565
2662
|
toolId: params.data.toolId,
|
|
2566
2663
|
selectedTools: params.data.selectedTools
|
|
@@ -2576,6 +2673,7 @@ var updateAgentToolRelation = (db) => async (params) => {
|
|
|
2576
2673
|
drizzleOrm.and(
|
|
2577
2674
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2578
2675
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2676
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2579
2677
|
drizzleOrm.eq(agentToolRelations.id, params.relationId)
|
|
2580
2678
|
)
|
|
2581
2679
|
).returning();
|
|
@@ -2586,6 +2684,7 @@ var deleteAgentToolRelation = (db) => async (params) => {
|
|
|
2586
2684
|
drizzleOrm.and(
|
|
2587
2685
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2588
2686
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2687
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2589
2688
|
drizzleOrm.eq(agentToolRelations.id, params.relationId)
|
|
2590
2689
|
)
|
|
2591
2690
|
);
|
|
@@ -2595,7 +2694,9 @@ var deleteAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
2595
2694
|
const result = await db.delete(agentToolRelations).where(
|
|
2596
2695
|
drizzleOrm.and(
|
|
2597
2696
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2598
|
-
drizzleOrm.eq(agentToolRelations.
|
|
2697
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2698
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2699
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2599
2700
|
)
|
|
2600
2701
|
);
|
|
2601
2702
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -2605,6 +2706,7 @@ var getAgentToolRelationById = (db) => async (params) => {
|
|
|
2605
2706
|
where: drizzleOrm.and(
|
|
2606
2707
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2607
2708
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2709
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2608
2710
|
drizzleOrm.eq(agentToolRelations.id, params.relationId)
|
|
2609
2711
|
)
|
|
2610
2712
|
});
|
|
@@ -2618,14 +2720,14 @@ var getAgentToolRelationByAgent = (db) => async (params) => {
|
|
|
2618
2720
|
drizzleOrm.and(
|
|
2619
2721
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2620
2722
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2621
|
-
drizzleOrm.eq(agentToolRelations.agentId, params.agentId)
|
|
2723
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2622
2724
|
)
|
|
2623
2725
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2624
2726
|
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(
|
|
2625
2727
|
drizzleOrm.and(
|
|
2626
2728
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2627
2729
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2628
|
-
drizzleOrm.eq(agentToolRelations.agentId, params.agentId)
|
|
2730
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2629
2731
|
)
|
|
2630
2732
|
)
|
|
2631
2733
|
]);
|
|
@@ -2645,6 +2747,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
2645
2747
|
drizzleOrm.and(
|
|
2646
2748
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2647
2749
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2750
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2648
2751
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2649
2752
|
)
|
|
2650
2753
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
@@ -2652,6 +2755,7 @@ var getAgentToolRelationByTool = (db) => async (params) => {
|
|
|
2652
2755
|
drizzleOrm.and(
|
|
2653
2756
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2654
2757
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2758
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2655
2759
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2656
2760
|
)
|
|
2657
2761
|
)
|
|
@@ -2671,13 +2775,15 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
2671
2775
|
db.select().from(agentToolRelations).where(
|
|
2672
2776
|
drizzleOrm.and(
|
|
2673
2777
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2674
|
-
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId)
|
|
2778
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2779
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId)
|
|
2675
2780
|
)
|
|
2676
2781
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2677
2782
|
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(
|
|
2678
2783
|
drizzleOrm.and(
|
|
2679
2784
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2680
|
-
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId)
|
|
2785
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2786
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId)
|
|
2681
2787
|
)
|
|
2682
2788
|
)
|
|
2683
2789
|
]);
|
|
@@ -2688,26 +2794,6 @@ var listAgentToolRelations = (db) => async (params) => {
|
|
|
2688
2794
|
pagination: { page, limit, total, pages }
|
|
2689
2795
|
};
|
|
2690
2796
|
};
|
|
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
2797
|
var getToolsForAgent = (db) => async (params) => {
|
|
2712
2798
|
const page = params.pagination?.page || 1;
|
|
2713
2799
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
@@ -2738,14 +2824,16 @@ var getToolsForAgent = (db) => async (params) => {
|
|
|
2738
2824
|
drizzleOrm.and(
|
|
2739
2825
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2740
2826
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2741
|
-
drizzleOrm.eq(agentToolRelations.
|
|
2827
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2828
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2742
2829
|
)
|
|
2743
2830
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
2744
2831
|
db.select({ count: drizzleOrm.count() }).from(agentToolRelations).where(
|
|
2745
2832
|
drizzleOrm.and(
|
|
2746
2833
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2747
2834
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2748
|
-
drizzleOrm.eq(agentToolRelations.
|
|
2835
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2836
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId)
|
|
2749
2837
|
)
|
|
2750
2838
|
)
|
|
2751
2839
|
]);
|
|
@@ -2774,6 +2862,9 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
2774
2862
|
name: agents.name,
|
|
2775
2863
|
description: agents.description,
|
|
2776
2864
|
prompt: agents.prompt,
|
|
2865
|
+
conversationHistoryConfig: agents.conversationHistoryConfig,
|
|
2866
|
+
models: agents.models,
|
|
2867
|
+
stopWhen: agents.stopWhen,
|
|
2777
2868
|
createdAt: agents.createdAt,
|
|
2778
2869
|
updatedAt: agents.updatedAt
|
|
2779
2870
|
}
|
|
@@ -2781,6 +2872,7 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
2781
2872
|
drizzleOrm.and(
|
|
2782
2873
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2783
2874
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2875
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2784
2876
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2785
2877
|
)
|
|
2786
2878
|
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agentToolRelations.createdAt)),
|
|
@@ -2788,6 +2880,7 @@ var getAgentsForTool = (db) => async (params) => {
|
|
|
2788
2880
|
drizzleOrm.and(
|
|
2789
2881
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
2790
2882
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
2883
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
2791
2884
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
2792
2885
|
)
|
|
2793
2886
|
)
|
|
@@ -2804,7 +2897,8 @@ var validateInternalAgent = (db) => async (params) => {
|
|
|
2804
2897
|
drizzleOrm.and(
|
|
2805
2898
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2806
2899
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2807
|
-
drizzleOrm.eq(agents.
|
|
2900
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2901
|
+
drizzleOrm.eq(agents.id, params.scopes.agentId)
|
|
2808
2902
|
)
|
|
2809
2903
|
).limit(1);
|
|
2810
2904
|
return result.length > 0;
|
|
@@ -2814,7 +2908,8 @@ var validateExternalAgent = (db) => async (params) => {
|
|
|
2814
2908
|
drizzleOrm.and(
|
|
2815
2909
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
2816
2910
|
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
2817
|
-
drizzleOrm.eq(externalAgents.
|
|
2911
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
2912
|
+
drizzleOrm.eq(externalAgents.id, params.scopes.agentId)
|
|
2818
2913
|
)
|
|
2819
2914
|
).limit(1);
|
|
2820
2915
|
return result.length > 0;
|
|
@@ -2824,6 +2919,7 @@ var getAgentById = (db) => async (params) => {
|
|
|
2824
2919
|
where: drizzleOrm.and(
|
|
2825
2920
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2826
2921
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2922
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2827
2923
|
drizzleOrm.eq(agents.id, params.agentId)
|
|
2828
2924
|
)
|
|
2829
2925
|
});
|
|
@@ -2833,7 +2929,8 @@ var listAgents = (db) => async (params) => {
|
|
|
2833
2929
|
return await db.query.agents.findMany({
|
|
2834
2930
|
where: drizzleOrm.and(
|
|
2835
2931
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2836
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId)
|
|
2932
|
+
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2933
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId)
|
|
2837
2934
|
)
|
|
2838
2935
|
});
|
|
2839
2936
|
};
|
|
@@ -2843,7 +2940,8 @@ var listAgentsPaginated = (db) => async (params) => {
|
|
|
2843
2940
|
const offset = (page - 1) * limit;
|
|
2844
2941
|
const whereClause = drizzleOrm.and(
|
|
2845
2942
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2846
|
-
drizzleOrm.eq(agents.projectId, params.scopes.projectId)
|
|
2943
|
+
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2944
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId)
|
|
2847
2945
|
);
|
|
2848
2946
|
const [data, totalResult] = await Promise.all([
|
|
2849
2947
|
db.select().from(agents).where(whereClause).limit(limit).offset(offset).orderBy(drizzleOrm.desc(agents.createdAt)),
|
|
@@ -2875,13 +2973,18 @@ var updateAgent = (db) => async (params) => {
|
|
|
2875
2973
|
drizzleOrm.and(
|
|
2876
2974
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2877
2975
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
2976
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2878
2977
|
drizzleOrm.eq(agents.id, params.agentId)
|
|
2879
2978
|
)
|
|
2880
2979
|
).returning();
|
|
2881
2980
|
return agent[0] ?? null;
|
|
2882
2981
|
};
|
|
2883
2982
|
var upsertAgent = (db) => async (params) => {
|
|
2884
|
-
const scopes = {
|
|
2983
|
+
const scopes = {
|
|
2984
|
+
tenantId: params.data.tenantId,
|
|
2985
|
+
projectId: params.data.projectId,
|
|
2986
|
+
graphId: params.data.graphId
|
|
2987
|
+
};
|
|
2885
2988
|
const existing = await getAgentById(db)({
|
|
2886
2989
|
scopes,
|
|
2887
2990
|
agentId: params.data.id
|
|
@@ -2912,6 +3015,7 @@ var deleteAgent = (db) => async (params) => {
|
|
|
2912
3015
|
drizzleOrm.and(
|
|
2913
3016
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2914
3017
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3018
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2915
3019
|
drizzleOrm.eq(agents.id, params.agentId)
|
|
2916
3020
|
)
|
|
2917
3021
|
);
|
|
@@ -2929,36 +3033,11 @@ var getAgentsByIds = (db) => async (params) => {
|
|
|
2929
3033
|
drizzleOrm.and(
|
|
2930
3034
|
drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
|
|
2931
3035
|
drizzleOrm.eq(agents.projectId, params.scopes.projectId),
|
|
3036
|
+
drizzleOrm.eq(agents.graphId, params.scopes.graphId),
|
|
2932
3037
|
drizzleOrm.inArray(agents.id, params.agentIds)
|
|
2933
3038
|
)
|
|
2934
3039
|
);
|
|
2935
3040
|
};
|
|
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
3041
|
var getContextConfigById = (db) => async (params) => {
|
|
2963
3042
|
return await db.query.contextConfigs.findFirst({
|
|
2964
3043
|
where: drizzleOrm.and(
|
|
@@ -3113,6 +3192,8 @@ var getExternalAgent = (db) => async (params) => {
|
|
|
3113
3192
|
const result = await db.query.externalAgents.findFirst({
|
|
3114
3193
|
where: drizzleOrm.and(
|
|
3115
3194
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3195
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3196
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3116
3197
|
drizzleOrm.eq(externalAgents.id, params.agentId)
|
|
3117
3198
|
)
|
|
3118
3199
|
});
|
|
@@ -3122,6 +3203,8 @@ var getExternalAgentByUrl = (db) => async (params) => {
|
|
|
3122
3203
|
const result = await db.query.externalAgents.findFirst({
|
|
3123
3204
|
where: drizzleOrm.and(
|
|
3124
3205
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3206
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3207
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3125
3208
|
drizzleOrm.eq(externalAgents.baseUrl, params.baseUrl)
|
|
3126
3209
|
)
|
|
3127
3210
|
});
|
|
@@ -3129,7 +3212,11 @@ var getExternalAgentByUrl = (db) => async (params) => {
|
|
|
3129
3212
|
};
|
|
3130
3213
|
var listExternalAgents = (db) => async (params) => {
|
|
3131
3214
|
return await db.query.externalAgents.findMany({
|
|
3132
|
-
where: drizzleOrm.
|
|
3215
|
+
where: drizzleOrm.and(
|
|
3216
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3217
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3218
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3219
|
+
),
|
|
3133
3220
|
orderBy: [drizzleOrm.asc(externalAgents.name)]
|
|
3134
3221
|
});
|
|
3135
3222
|
};
|
|
@@ -3138,8 +3225,20 @@ var listExternalAgentsPaginated = (db) => async (params) => {
|
|
|
3138
3225
|
const limit = Math.min(params.pagination?.limit || 10, 100);
|
|
3139
3226
|
const offset = (page - 1) * limit;
|
|
3140
3227
|
const [data, totalResult] = await Promise.all([
|
|
3141
|
-
db.select().from(externalAgents).where(
|
|
3142
|
-
|
|
3228
|
+
db.select().from(externalAgents).where(
|
|
3229
|
+
drizzleOrm.and(
|
|
3230
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3231
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3232
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3233
|
+
)
|
|
3234
|
+
).limit(limit).offset(offset).orderBy(drizzleOrm.desc(externalAgents.createdAt)),
|
|
3235
|
+
db.select({ count: drizzleOrm.count() }).from(externalAgents).where(
|
|
3236
|
+
drizzleOrm.and(
|
|
3237
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3238
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3239
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3240
|
+
)
|
|
3241
|
+
)
|
|
3143
3242
|
]);
|
|
3144
3243
|
const total = typeof totalResult[0]?.count === "string" ? parseInt(totalResult[0].count, 10) : totalResult[0]?.count || 0;
|
|
3145
3244
|
const pages = Math.ceil(total / limit);
|
|
@@ -3165,13 +3264,19 @@ var updateExternalAgent = (db) => async (params) => {
|
|
|
3165
3264
|
const result = await db.update(externalAgents).set(updateData).where(
|
|
3166
3265
|
drizzleOrm.and(
|
|
3167
3266
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3267
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3268
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3168
3269
|
drizzleOrm.eq(externalAgents.id, params.agentId)
|
|
3169
3270
|
)
|
|
3170
3271
|
).returning();
|
|
3171
3272
|
return result[0] || null;
|
|
3172
3273
|
};
|
|
3173
3274
|
var upsertExternalAgent = (db) => async (params) => {
|
|
3174
|
-
const scopes = {
|
|
3275
|
+
const scopes = {
|
|
3276
|
+
tenantId: params.data.tenantId,
|
|
3277
|
+
projectId: params.data.projectId,
|
|
3278
|
+
graphId: params.data.graphId
|
|
3279
|
+
};
|
|
3175
3280
|
const existing = await getExternalAgent(db)({
|
|
3176
3281
|
scopes,
|
|
3177
3282
|
agentId: params.data.id
|
|
@@ -3201,6 +3306,8 @@ var deleteExternalAgent = (db) => async (params) => {
|
|
|
3201
3306
|
const result = await db.delete(externalAgents).where(
|
|
3202
3307
|
drizzleOrm.and(
|
|
3203
3308
|
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3309
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3310
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId),
|
|
3204
3311
|
drizzleOrm.eq(externalAgents.id, params.agentId)
|
|
3205
3312
|
)
|
|
3206
3313
|
).returning();
|
|
@@ -3219,27 +3326,24 @@ var externalAgentUrlExists = (db) => async (params) => {
|
|
|
3219
3326
|
return agent !== null;
|
|
3220
3327
|
};
|
|
3221
3328
|
var countExternalAgents = (db) => async (params) => {
|
|
3222
|
-
const result = await db.select({ count: drizzleOrm.count() }).from(externalAgents).where(
|
|
3329
|
+
const result = await db.select({ count: drizzleOrm.count() }).from(externalAgents).where(
|
|
3330
|
+
drizzleOrm.and(
|
|
3331
|
+
drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
|
|
3332
|
+
drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
|
|
3333
|
+
drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
|
|
3334
|
+
)
|
|
3335
|
+
);
|
|
3223
3336
|
const countValue = result[0]?.count;
|
|
3224
3337
|
return typeof countValue === "string" ? parseInt(countValue, 10) : countValue || 0;
|
|
3225
3338
|
};
|
|
3226
3339
|
|
|
3227
3340
|
// 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
3341
|
var getAgentGraphById = (db) => async (params) => {
|
|
3238
3342
|
const result = await db.query.agentGraph.findFirst({
|
|
3239
3343
|
where: drizzleOrm.and(
|
|
3240
3344
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3241
3345
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3242
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3346
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3243
3347
|
)
|
|
3244
3348
|
});
|
|
3245
3349
|
return result ?? null;
|
|
@@ -3249,7 +3353,7 @@ var getAgentGraphWithDefaultAgent = (db) => async (params) => {
|
|
|
3249
3353
|
where: drizzleOrm.and(
|
|
3250
3354
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3251
3355
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3252
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3356
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3253
3357
|
),
|
|
3254
3358
|
with: {
|
|
3255
3359
|
defaultAgent: true
|
|
@@ -3342,7 +3446,7 @@ var updateAgentGraph = (db) => async (params) => {
|
|
|
3342
3446
|
drizzleOrm.and(
|
|
3343
3447
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3344
3448
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3345
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3449
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3346
3450
|
)
|
|
3347
3451
|
).returning();
|
|
3348
3452
|
return graph[0] ?? null;
|
|
@@ -3352,7 +3456,7 @@ var deleteAgentGraph = (db) => async (params) => {
|
|
|
3352
3456
|
drizzleOrm.and(
|
|
3353
3457
|
drizzleOrm.eq(agentGraph.tenantId, params.scopes.tenantId),
|
|
3354
3458
|
drizzleOrm.eq(agentGraph.projectId, params.scopes.projectId),
|
|
3355
|
-
drizzleOrm.eq(agentGraph.id, params.graphId)
|
|
3459
|
+
drizzleOrm.eq(agentGraph.id, params.scopes.graphId)
|
|
3356
3460
|
)
|
|
3357
3461
|
).returning();
|
|
3358
3462
|
return result.length > 0;
|
|
@@ -3379,17 +3483,14 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3379
3483
|
agentId
|
|
3380
3484
|
}) => {
|
|
3381
3485
|
const { tenantId, projectId } = scopes;
|
|
3382
|
-
const graph = await
|
|
3383
|
-
scopes: { tenantId, projectId }
|
|
3384
|
-
graphId
|
|
3486
|
+
const graph = await getAgentGraphById(db)({
|
|
3487
|
+
scopes: { tenantId, projectId, graphId }
|
|
3385
3488
|
});
|
|
3386
3489
|
if (!graph) {
|
|
3387
3490
|
throw new Error(`Agent graph with ID ${graphId} not found for tenant ${tenantId}`);
|
|
3388
3491
|
}
|
|
3389
3492
|
const relations2 = await getAgentRelations(db)({
|
|
3390
|
-
scopes: { tenantId, projectId }
|
|
3391
|
-
graphId,
|
|
3392
|
-
agentId
|
|
3493
|
+
scopes: { tenantId, projectId, graphId, agentId }
|
|
3393
3494
|
});
|
|
3394
3495
|
const targetAgentIds = relations2.map((relation) => relation.targetAgentId).filter((id) => id !== null);
|
|
3395
3496
|
if (targetAgentIds.length === 0) {
|
|
@@ -3398,7 +3499,7 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3398
3499
|
const agentInfos = await Promise.all(
|
|
3399
3500
|
targetAgentIds.map(async (targetAgentId) => {
|
|
3400
3501
|
const agent = await getAgentById(db)({
|
|
3401
|
-
scopes: { tenantId, projectId },
|
|
3502
|
+
scopes: { tenantId, projectId, graphId },
|
|
3402
3503
|
agentId: targetAgentId
|
|
3403
3504
|
});
|
|
3404
3505
|
if (agent !== void 0) {
|
|
@@ -3410,55 +3511,35 @@ var getGraphAgentInfos = (db) => async ({
|
|
|
3410
3511
|
return agentInfos.filter((agent) => agent !== null);
|
|
3411
3512
|
};
|
|
3412
3513
|
var getFullGraphDefinition = (db) => async ({
|
|
3413
|
-
scopes: { tenantId, projectId }
|
|
3414
|
-
graphId
|
|
3514
|
+
scopes: { tenantId, projectId, graphId }
|
|
3415
3515
|
}) => {
|
|
3416
3516
|
const graph = await getAgentGraphById(db)({
|
|
3417
|
-
scopes: { tenantId, projectId }
|
|
3418
|
-
graphId
|
|
3517
|
+
scopes: { tenantId, projectId, graphId }
|
|
3419
3518
|
});
|
|
3420
3519
|
if (!graph) {
|
|
3421
3520
|
return null;
|
|
3422
3521
|
}
|
|
3423
3522
|
const graphRelations = await getAgentRelationsByGraph(db)({
|
|
3424
|
-
scopes: { tenantId, projectId }
|
|
3425
|
-
|
|
3523
|
+
scopes: { tenantId, projectId, graphId }
|
|
3524
|
+
});
|
|
3525
|
+
const graphAgents = await db.query.agents.findMany({
|
|
3526
|
+
where: drizzleOrm.and(
|
|
3527
|
+
drizzleOrm.eq(agents.tenantId, tenantId),
|
|
3528
|
+
drizzleOrm.eq(agents.projectId, projectId),
|
|
3529
|
+
drizzleOrm.eq(agents.graphId, graphId)
|
|
3530
|
+
)
|
|
3426
3531
|
});
|
|
3427
|
-
const internalAgentIds = /* @__PURE__ */ new Set();
|
|
3428
3532
|
const externalAgentIds = /* @__PURE__ */ new Set();
|
|
3429
|
-
internalAgentIds.add(graph.defaultAgentId);
|
|
3430
3533
|
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
3534
|
if (relation.externalAgentId) {
|
|
3438
3535
|
externalAgentIds.add(relation.externalAgentId);
|
|
3439
3536
|
}
|
|
3440
3537
|
}
|
|
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
|
-
});
|
|
3538
|
+
const processedAgents = await Promise.all(
|
|
3539
|
+
graphAgents.map(async (agent) => {
|
|
3459
3540
|
if (!agent) return null;
|
|
3460
3541
|
const agentRelationsList = graphRelations.filter(
|
|
3461
|
-
(relation) => relation.sourceAgentId ===
|
|
3542
|
+
(relation) => relation.sourceAgentId === agent.id
|
|
3462
3543
|
);
|
|
3463
3544
|
const canTransferTo = agentRelationsList.filter((rel) => rel.relationType === "transfer" || rel.relationType === "transfer_to").map((rel) => rel.targetAgentId).filter((id) => id !== null);
|
|
3464
3545
|
const canDelegateTo = agentRelationsList.filter((rel) => rel.relationType === "delegate" || rel.relationType === "delegate_to").map((rel) => rel.targetAgentId || rel.externalAgentId).filter((id) => id !== null);
|
|
@@ -3475,19 +3556,19 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3475
3556
|
lastToolsSync: tools.lastToolsSync,
|
|
3476
3557
|
selectedTools: agentToolRelations.selectedTools
|
|
3477
3558
|
}).from(agentToolRelations).innerJoin(tools, drizzleOrm.eq(agentToolRelations.toolId, tools.id)).where(
|
|
3478
|
-
drizzleOrm.and(drizzleOrm.eq(agentToolRelations.tenantId, tenantId), drizzleOrm.eq(agentToolRelations.agentId,
|
|
3559
|
+
drizzleOrm.and(drizzleOrm.eq(agentToolRelations.tenantId, tenantId), drizzleOrm.eq(agentToolRelations.agentId, agent.id))
|
|
3479
3560
|
);
|
|
3480
3561
|
const agentDataComponentRelations = await db.query.agentDataComponents.findMany({
|
|
3481
3562
|
where: drizzleOrm.and(
|
|
3482
3563
|
drizzleOrm.eq(agentDataComponents.tenantId, tenantId),
|
|
3483
|
-
drizzleOrm.eq(agentDataComponents.agentId,
|
|
3564
|
+
drizzleOrm.eq(agentDataComponents.agentId, agent.id)
|
|
3484
3565
|
)
|
|
3485
3566
|
});
|
|
3486
3567
|
const agentDataComponentIds = agentDataComponentRelations.map((rel) => rel.dataComponentId);
|
|
3487
3568
|
const agentArtifactComponentRelations = await db.query.agentArtifactComponents.findMany({
|
|
3488
3569
|
where: drizzleOrm.and(
|
|
3489
3570
|
drizzleOrm.eq(agentArtifactComponents.tenantId, tenantId),
|
|
3490
|
-
drizzleOrm.eq(agentArtifactComponents.agentId,
|
|
3571
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, agent.id)
|
|
3491
3572
|
)
|
|
3492
3573
|
});
|
|
3493
3574
|
const agentArtifactComponentIds = agentArtifactComponentRelations.map(
|
|
@@ -3530,7 +3611,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3530
3611
|
const externalAgents2 = await Promise.all(
|
|
3531
3612
|
Array.from(externalAgentIds).map(async (agentId) => {
|
|
3532
3613
|
const agent = await getExternalAgent(db)({
|
|
3533
|
-
scopes: { tenantId, projectId },
|
|
3614
|
+
scopes: { tenantId, projectId, graphId },
|
|
3534
3615
|
agentId
|
|
3535
3616
|
});
|
|
3536
3617
|
if (!agent) return null;
|
|
@@ -3542,7 +3623,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3542
3623
|
};
|
|
3543
3624
|
})
|
|
3544
3625
|
);
|
|
3545
|
-
const validAgents = [...
|
|
3626
|
+
const validAgents = [...processedAgents, ...externalAgents2].filter(
|
|
3546
3627
|
(agent) => agent !== null
|
|
3547
3628
|
);
|
|
3548
3629
|
const agentsObject = {};
|
|
@@ -3588,6 +3669,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3588
3669
|
}
|
|
3589
3670
|
let dataComponentsObject = {};
|
|
3590
3671
|
try {
|
|
3672
|
+
const internalAgentIds = graphAgents.map((agent) => agent.id);
|
|
3591
3673
|
const agentIds = Array.from(internalAgentIds);
|
|
3592
3674
|
dataComponentsObject = await fetchComponentRelationships(db)(
|
|
3593
3675
|
{ tenantId, projectId },
|
|
@@ -3610,6 +3692,7 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3610
3692
|
}
|
|
3611
3693
|
let artifactComponentsObject = {};
|
|
3612
3694
|
try {
|
|
3695
|
+
const internalAgentIds = graphAgents.map((agent) => agent.id);
|
|
3613
3696
|
const agentIds = Array.from(internalAgentIds);
|
|
3614
3697
|
artifactComponentsObject = await fetchComponentRelationships(db)(
|
|
3615
3698
|
{ tenantId, projectId },
|
|
@@ -3716,16 +3799,14 @@ var getFullGraphDefinition = (db) => async ({
|
|
|
3716
3799
|
return result;
|
|
3717
3800
|
};
|
|
3718
3801
|
var upsertAgentGraph = (db) => async (params) => {
|
|
3719
|
-
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId };
|
|
3720
3802
|
const graphId = params.data.id || nanoid.nanoid();
|
|
3803
|
+
const scopes = { tenantId: params.data.tenantId, projectId: params.data.projectId, graphId };
|
|
3721
3804
|
const existing = await getAgentGraphById(db)({
|
|
3722
|
-
scopes
|
|
3723
|
-
graphId
|
|
3805
|
+
scopes
|
|
3724
3806
|
});
|
|
3725
3807
|
if (existing) {
|
|
3726
3808
|
return await updateAgentGraph(db)({
|
|
3727
3809
|
scopes,
|
|
3728
|
-
graphId,
|
|
3729
3810
|
data: {
|
|
3730
3811
|
name: params.data.name,
|
|
3731
3812
|
defaultAgentId: params.data.defaultAgentId,
|
|
@@ -4071,7 +4152,8 @@ var getArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
4071
4152
|
drizzleOrm.and(
|
|
4072
4153
|
drizzleOrm.eq(artifactComponents.tenantId, params.scopes.tenantId),
|
|
4073
4154
|
drizzleOrm.eq(artifactComponents.projectId, params.scopes.projectId),
|
|
4074
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4155
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4156
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
4075
4157
|
)
|
|
4076
4158
|
).orderBy(drizzleOrm.desc(artifactComponents.createdAt));
|
|
4077
4159
|
};
|
|
@@ -4080,7 +4162,8 @@ var associateArtifactComponentWithAgent = (db) => async (params) => {
|
|
|
4080
4162
|
id: nanoid.nanoid(),
|
|
4081
4163
|
tenantId: params.scopes.tenantId,
|
|
4082
4164
|
projectId: params.scopes.projectId,
|
|
4083
|
-
|
|
4165
|
+
graphId: params.scopes.graphId,
|
|
4166
|
+
agentId: params.scopes.agentId,
|
|
4084
4167
|
artifactComponentId: params.artifactComponentId,
|
|
4085
4168
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4086
4169
|
}).returning();
|
|
@@ -4092,7 +4175,8 @@ var removeArtifactComponentFromAgent = (db) => async (params) => {
|
|
|
4092
4175
|
drizzleOrm.and(
|
|
4093
4176
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4094
4177
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4095
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4178
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4179
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId),
|
|
4096
4180
|
drizzleOrm.eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
4097
4181
|
)
|
|
4098
4182
|
).returning();
|
|
@@ -4106,13 +4190,15 @@ var deleteAgentArtifactComponentRelationByAgent = (db) => async (params) => {
|
|
|
4106
4190
|
const result = await db.delete(agentArtifactComponents).where(
|
|
4107
4191
|
drizzleOrm.and(
|
|
4108
4192
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4109
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4193
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4194
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
4110
4195
|
)
|
|
4111
4196
|
);
|
|
4112
4197
|
return (result.rowsAffected || 0) > 0;
|
|
4113
4198
|
};
|
|
4114
4199
|
var getAgentsUsingArtifactComponent = (db) => async (params) => {
|
|
4115
4200
|
return await db.select({
|
|
4201
|
+
graphId: agentArtifactComponents.graphId,
|
|
4116
4202
|
agentId: agentArtifactComponents.agentId,
|
|
4117
4203
|
createdAt: agentArtifactComponents.createdAt
|
|
4118
4204
|
}).from(agentArtifactComponents).where(
|
|
@@ -4128,7 +4214,8 @@ var isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
|
|
|
4128
4214
|
drizzleOrm.and(
|
|
4129
4215
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4130
4216
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4131
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4217
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4218
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId),
|
|
4132
4219
|
drizzleOrm.eq(agentArtifactComponents.artifactComponentId, params.artifactComponentId)
|
|
4133
4220
|
)
|
|
4134
4221
|
).limit(1);
|
|
@@ -4139,7 +4226,7 @@ var graphHasArtifactComponents = (db) => async (params) => {
|
|
|
4139
4226
|
drizzleOrm.and(
|
|
4140
4227
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4141
4228
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4142
|
-
drizzleOrm.eq(agentRelations.graphId, params.graphId)
|
|
4229
|
+
drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId)
|
|
4143
4230
|
)
|
|
4144
4231
|
).limit(1);
|
|
4145
4232
|
const total = result[0]?.count || 0;
|
|
@@ -4161,7 +4248,8 @@ var countArtifactComponentsForAgent = (db) => async (params) => {
|
|
|
4161
4248
|
drizzleOrm.and(
|
|
4162
4249
|
drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
|
|
4163
4250
|
drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
|
|
4164
|
-
drizzleOrm.eq(agentArtifactComponents.
|
|
4251
|
+
drizzleOrm.eq(agentArtifactComponents.graphId, params.scopes.graphId),
|
|
4252
|
+
drizzleOrm.eq(agentArtifactComponents.agentId, params.scopes.agentId)
|
|
4165
4253
|
)
|
|
4166
4254
|
);
|
|
4167
4255
|
const total = result[0]?.count || 0;
|
|
@@ -4781,7 +4869,8 @@ var getDataComponentsForAgent = (db) => async (params) => {
|
|
|
4781
4869
|
drizzleOrm.and(
|
|
4782
4870
|
drizzleOrm.eq(dataComponents.tenantId, params.scopes.tenantId),
|
|
4783
4871
|
drizzleOrm.eq(dataComponents.projectId, params.scopes.projectId),
|
|
4784
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4872
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4873
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId)
|
|
4785
4874
|
)
|
|
4786
4875
|
).orderBy(drizzleOrm.desc(dataComponents.createdAt));
|
|
4787
4876
|
};
|
|
@@ -4790,7 +4879,8 @@ var associateDataComponentWithAgent = (db) => async (params) => {
|
|
|
4790
4879
|
id: nanoid.nanoid(),
|
|
4791
4880
|
tenantId: params.scopes.tenantId,
|
|
4792
4881
|
projectId: params.scopes.projectId,
|
|
4793
|
-
|
|
4882
|
+
graphId: params.scopes.graphId,
|
|
4883
|
+
agentId: params.scopes.agentId,
|
|
4794
4884
|
dataComponentId: params.dataComponentId
|
|
4795
4885
|
}).returning();
|
|
4796
4886
|
return association[0];
|
|
@@ -4800,7 +4890,8 @@ var removeDataComponentFromAgent = (db) => async (params) => {
|
|
|
4800
4890
|
drizzleOrm.and(
|
|
4801
4891
|
drizzleOrm.eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
4802
4892
|
drizzleOrm.eq(agentDataComponents.projectId, params.scopes.projectId),
|
|
4803
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4893
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4894
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId),
|
|
4804
4895
|
drizzleOrm.eq(agentDataComponents.dataComponentId, params.dataComponentId)
|
|
4805
4896
|
)
|
|
4806
4897
|
).returning();
|
|
@@ -4810,7 +4901,8 @@ var deleteAgentDataComponentRelationByAgent = (db) => async (params) => {
|
|
|
4810
4901
|
const result = await db.delete(agentDataComponents).where(
|
|
4811
4902
|
drizzleOrm.and(
|
|
4812
4903
|
drizzleOrm.eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
4813
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4904
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4905
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId)
|
|
4814
4906
|
)
|
|
4815
4907
|
);
|
|
4816
4908
|
return (result.rowsAffected || 0) > 0;
|
|
@@ -4832,7 +4924,8 @@ var isDataComponentAssociatedWithAgent = (db) => async (params) => {
|
|
|
4832
4924
|
drizzleOrm.and(
|
|
4833
4925
|
drizzleOrm.eq(agentDataComponents.tenantId, params.scopes.tenantId),
|
|
4834
4926
|
drizzleOrm.eq(agentDataComponents.projectId, params.scopes.projectId),
|
|
4835
|
-
drizzleOrm.eq(agentDataComponents.
|
|
4927
|
+
drizzleOrm.eq(agentDataComponents.graphId, params.scopes.graphId),
|
|
4928
|
+
drizzleOrm.eq(agentDataComponents.agentId, params.scopes.agentId),
|
|
4836
4929
|
drizzleOrm.eq(agentDataComponents.dataComponentId, params.dataComponentId)
|
|
4837
4930
|
)
|
|
4838
4931
|
).limit(1);
|
|
@@ -4886,9 +4979,11 @@ function isExternalAgent(agent) {
|
|
|
4886
4979
|
function validateAndTypeGraphData(data) {
|
|
4887
4980
|
return FullGraphDefinitionSchema.parse(data);
|
|
4888
4981
|
}
|
|
4889
|
-
function validateToolReferences(graphData) {
|
|
4982
|
+
function validateToolReferences(graphData, availableToolIds) {
|
|
4983
|
+
if (!availableToolIds) {
|
|
4984
|
+
return;
|
|
4985
|
+
}
|
|
4890
4986
|
const errors = [];
|
|
4891
|
-
const availableToolIds = new Set(Object.keys(graphData.tools || {}));
|
|
4892
4987
|
for (const [agentId, agentData] of Object.entries(graphData.agents)) {
|
|
4893
4988
|
if (isInternalAgent(agentData) && agentData.tools && Array.isArray(agentData.tools)) {
|
|
4894
4989
|
for (const toolId of agentData.tools) {
|
|
@@ -4903,9 +4998,11 @@ function validateToolReferences(graphData) {
|
|
|
4903
4998
|
${errors.join("\n")}`);
|
|
4904
4999
|
}
|
|
4905
5000
|
}
|
|
4906
|
-
function validateDataComponentReferences(graphData) {
|
|
5001
|
+
function validateDataComponentReferences(graphData, availableDataComponentIds) {
|
|
5002
|
+
if (!availableDataComponentIds) {
|
|
5003
|
+
return;
|
|
5004
|
+
}
|
|
4907
5005
|
const errors = [];
|
|
4908
|
-
const availableDataComponentIds = new Set(Object.keys(graphData.dataComponents || {}));
|
|
4909
5006
|
for (const [agentId, agentData] of Object.entries(graphData.agents)) {
|
|
4910
5007
|
if (isInternalAgent(agentData) && agentData.dataComponents) {
|
|
4911
5008
|
for (const dataComponentId of agentData.dataComponents) {
|
|
@@ -4922,9 +5019,11 @@ function validateDataComponentReferences(graphData) {
|
|
|
4922
5019
|
${errors.join("\n")}`);
|
|
4923
5020
|
}
|
|
4924
5021
|
}
|
|
4925
|
-
function validateArtifactComponentReferences(graphData) {
|
|
5022
|
+
function validateArtifactComponentReferences(graphData, availableArtifactComponentIds) {
|
|
5023
|
+
if (!availableArtifactComponentIds) {
|
|
5024
|
+
return;
|
|
5025
|
+
}
|
|
4926
5026
|
const errors = [];
|
|
4927
|
-
const availableArtifactComponentIds = new Set(Object.keys(graphData.artifactComponents || {}));
|
|
4928
5027
|
for (const [agentId, agentData] of Object.entries(graphData.agents)) {
|
|
4929
5028
|
if (isInternalAgent(agentData) && agentData.artifactComponents) {
|
|
4930
5029
|
for (const artifactComponentId of agentData.artifactComponents) {
|
|
@@ -4971,13 +5070,15 @@ function validateAgentRelationships(graphData) {
|
|
|
4971
5070
|
${errors.join("\n")}`);
|
|
4972
5071
|
}
|
|
4973
5072
|
}
|
|
4974
|
-
function validateGraphStructure(graphData) {
|
|
4975
|
-
if (!graphData.agents[graphData.defaultAgentId]) {
|
|
5073
|
+
function validateGraphStructure(graphData, projectResources) {
|
|
5074
|
+
if (graphData.defaultAgentId && !graphData.agents[graphData.defaultAgentId]) {
|
|
4976
5075
|
throw new Error(`Default agent '${graphData.defaultAgentId}' does not exist in agents`);
|
|
4977
5076
|
}
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
5077
|
+
if (projectResources) {
|
|
5078
|
+
validateToolReferences(graphData, projectResources.toolIds);
|
|
5079
|
+
validateDataComponentReferences(graphData, projectResources.dataComponentIds);
|
|
5080
|
+
validateArtifactComponentReferences(graphData, projectResources.artifactComponentIds);
|
|
5081
|
+
}
|
|
4981
5082
|
validateAgentRelationships(graphData);
|
|
4982
5083
|
}
|
|
4983
5084
|
var dbResultToMcpTool = (dbResult) => {
|
|
@@ -5098,6 +5199,7 @@ var addToolToAgent = (db) => async (params) => {
|
|
|
5098
5199
|
id,
|
|
5099
5200
|
tenantId: params.scopes.tenantId,
|
|
5100
5201
|
projectId: params.scopes.projectId,
|
|
5202
|
+
graphId: params.scopes.graphId,
|
|
5101
5203
|
agentId: params.agentId,
|
|
5102
5204
|
toolId: params.toolId,
|
|
5103
5205
|
selectedTools: params.selectedTools,
|
|
@@ -5111,6 +5213,7 @@ var removeToolFromAgent = (db) => async (params) => {
|
|
|
5111
5213
|
drizzleOrm.and(
|
|
5112
5214
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
5113
5215
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
5216
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
5114
5217
|
drizzleOrm.eq(agentToolRelations.agentId, params.agentId),
|
|
5115
5218
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
5116
5219
|
)
|
|
@@ -5122,6 +5225,7 @@ var upsertAgentToolRelation = (db) => async (params) => {
|
|
|
5122
5225
|
where: drizzleOrm.and(
|
|
5123
5226
|
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
5124
5227
|
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
5228
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
5125
5229
|
drizzleOrm.eq(agentToolRelations.agentId, params.agentId),
|
|
5126
5230
|
drizzleOrm.eq(agentToolRelations.toolId, params.toolId)
|
|
5127
5231
|
)
|
|
@@ -5178,11 +5282,15 @@ var getHealthyToolsForAgent = (db) => async (params) => {
|
|
|
5178
5282
|
}).from(tools).innerJoin(
|
|
5179
5283
|
agentToolRelations,
|
|
5180
5284
|
drizzleOrm.and(
|
|
5181
|
-
drizzleOrm.eq(tools.
|
|
5182
|
-
drizzleOrm.eq(
|
|
5183
|
-
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId)
|
|
5285
|
+
drizzleOrm.eq(tools.tenantId, params.scopes.tenantId),
|
|
5286
|
+
drizzleOrm.eq(tools.projectId, params.scopes.projectId),
|
|
5287
|
+
drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
|
|
5288
|
+
drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
|
|
5289
|
+
drizzleOrm.eq(agentToolRelations.graphId, params.scopes.graphId),
|
|
5290
|
+
drizzleOrm.eq(agentToolRelations.agentId, params.scopes.agentId),
|
|
5291
|
+
drizzleOrm.eq(tools.id, agentToolRelations.toolId)
|
|
5184
5292
|
)
|
|
5185
|
-
).where(drizzleOrm.
|
|
5293
|
+
).where(drizzleOrm.eq(tools.status, "healthy"));
|
|
5186
5294
|
return healthyTools.map((row) => row.tool);
|
|
5187
5295
|
};
|
|
5188
5296
|
|
|
@@ -5277,59 +5385,37 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5277
5385
|
validateGraphStructure(typed);
|
|
5278
5386
|
await applyExecutionLimitsInheritance(db, logger11, { tenantId, projectId }, typed);
|
|
5279
5387
|
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
5388
|
logger11.info(
|
|
5330
|
-
{
|
|
5331
|
-
"
|
|
5389
|
+
{},
|
|
5390
|
+
"CredentialReferences are project-scoped - skipping credential reference creation in graph"
|
|
5332
5391
|
);
|
|
5392
|
+
logger11.info({}, "Tools are project-scoped - skipping tool creation in graph");
|
|
5393
|
+
let finalGraphId;
|
|
5394
|
+
try {
|
|
5395
|
+
const graphId = typed.id || nanoid.nanoid();
|
|
5396
|
+
logger11.info({ graphId }, "Creating agent graph metadata");
|
|
5397
|
+
const agentGraph2 = await upsertAgentGraph(db)({
|
|
5398
|
+
data: {
|
|
5399
|
+
id: graphId,
|
|
5400
|
+
tenantId,
|
|
5401
|
+
projectId,
|
|
5402
|
+
name: typed.name,
|
|
5403
|
+
defaultAgentId: typed.defaultAgentId,
|
|
5404
|
+
description: typed.description,
|
|
5405
|
+
contextConfigId: void 0,
|
|
5406
|
+
// Will be updated later if context config exists
|
|
5407
|
+
models: typed.models,
|
|
5408
|
+
statusUpdates: typed.statusUpdates,
|
|
5409
|
+
graphPrompt: typed.graphPrompt,
|
|
5410
|
+
stopWhen: typed.stopWhen
|
|
5411
|
+
}
|
|
5412
|
+
});
|
|
5413
|
+
finalGraphId = agentGraph2.id;
|
|
5414
|
+
logger11.info({ graphId: finalGraphId }, "Agent graph metadata created successfully");
|
|
5415
|
+
} catch (error) {
|
|
5416
|
+
logger11.error({ graphId: typed.id, error }, "Failed to create/update graph metadata");
|
|
5417
|
+
throw error;
|
|
5418
|
+
}
|
|
5333
5419
|
let contextConfigId;
|
|
5334
5420
|
if (typed.contextConfig) {
|
|
5335
5421
|
try {
|
|
@@ -5351,66 +5437,14 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5351
5437
|
throw error;
|
|
5352
5438
|
}
|
|
5353
5439
|
}
|
|
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
|
-
}
|
|
5440
|
+
logger11.info(
|
|
5441
|
+
{},
|
|
5442
|
+
"DataComponents are project-scoped - skipping dataComponent creation in graph"
|
|
5443
|
+
);
|
|
5444
|
+
logger11.info(
|
|
5445
|
+
{},
|
|
5446
|
+
"ArtifactComponents are project-scoped - skipping artifactComponent creation in graph"
|
|
5447
|
+
);
|
|
5414
5448
|
const internalAgentPromises = Object.entries(typed.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
|
|
5415
5449
|
const internalAgent = agentData;
|
|
5416
5450
|
try {
|
|
@@ -5420,6 +5454,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5420
5454
|
id: agentId,
|
|
5421
5455
|
tenantId,
|
|
5422
5456
|
projectId,
|
|
5457
|
+
graphId: finalGraphId,
|
|
5423
5458
|
name: internalAgent.name || "",
|
|
5424
5459
|
description: internalAgent.description || "",
|
|
5425
5460
|
prompt: internalAgent.prompt || "",
|
|
@@ -5448,6 +5483,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5448
5483
|
id: agentId,
|
|
5449
5484
|
tenantId,
|
|
5450
5485
|
projectId,
|
|
5486
|
+
graphId: finalGraphId,
|
|
5451
5487
|
name: externalAgent.name,
|
|
5452
5488
|
description: externalAgent.description || "",
|
|
5453
5489
|
baseUrl: externalAgent.baseUrl,
|
|
@@ -5466,29 +5502,24 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5466
5502
|
([_, agentData]) => isExternalAgent(agentData)
|
|
5467
5503
|
).length;
|
|
5468
5504
|
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;
|
|
5505
|
+
if (contextConfigId) {
|
|
5506
|
+
try {
|
|
5507
|
+
logger11.info(
|
|
5508
|
+
{ graphId: finalGraphId, contextConfigId },
|
|
5509
|
+
"Updating graph with context config"
|
|
5510
|
+
);
|
|
5511
|
+
await updateAgentGraph(db)({
|
|
5512
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5513
|
+
data: { contextConfigId }
|
|
5514
|
+
});
|
|
5515
|
+
logger11.info({ graphId: finalGraphId }, "Graph updated with context config");
|
|
5516
|
+
} catch (error) {
|
|
5517
|
+
logger11.error(
|
|
5518
|
+
{ graphId: finalGraphId, error },
|
|
5519
|
+
"Failed to update graph with context config"
|
|
5520
|
+
);
|
|
5521
|
+
throw error;
|
|
5522
|
+
}
|
|
5492
5523
|
}
|
|
5493
5524
|
const agentToolPromises = [];
|
|
5494
5525
|
for (const [agentId, agentData] of Object.entries(typed.agents)) {
|
|
@@ -5500,7 +5531,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5500
5531
|
const selectedTools = agentData.selectedTools?.[toolId];
|
|
5501
5532
|
logger11.info({ agentId, toolId }, "Processing agent-tool relation");
|
|
5502
5533
|
await upsertAgentToolRelation(db)({
|
|
5503
|
-
scopes: { tenantId, projectId },
|
|
5534
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5504
5535
|
agentId,
|
|
5505
5536
|
toolId,
|
|
5506
5537
|
selectedTools
|
|
@@ -5531,8 +5562,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5531
5562
|
"Processing agent-data component relation"
|
|
5532
5563
|
);
|
|
5533
5564
|
await upsertAgentDataComponentRelation(db)({
|
|
5534
|
-
scopes: { tenantId, projectId },
|
|
5535
|
-
agentId,
|
|
5565
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
5536
5566
|
dataComponentId
|
|
5537
5567
|
});
|
|
5538
5568
|
logger11.info(
|
|
@@ -5564,8 +5594,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5564
5594
|
"Processing agent-artifact component relation"
|
|
5565
5595
|
);
|
|
5566
5596
|
await upsertAgentArtifactComponentRelation(db)({
|
|
5567
|
-
scopes: { tenantId, projectId },
|
|
5568
|
-
agentId,
|
|
5597
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
5569
5598
|
artifactComponentId
|
|
5570
5599
|
});
|
|
5571
5600
|
logger11.info(
|
|
@@ -5661,8 +5690,7 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5661
5690
|
"All agent relations created"
|
|
5662
5691
|
);
|
|
5663
5692
|
const createdGraph = await getFullGraphDefinition(db)({
|
|
5664
|
-
scopes: { tenantId, projectId }
|
|
5665
|
-
graphId: finalGraphId
|
|
5693
|
+
scopes: { tenantId, projectId, graphId: finalGraphId }
|
|
5666
5694
|
});
|
|
5667
5695
|
if (!createdGraph) {
|
|
5668
5696
|
throw new Error("Failed to retrieve created graph");
|
|
@@ -5685,8 +5713,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5685
5713
|
{
|
|
5686
5714
|
tenantId,
|
|
5687
5715
|
graphId: typedGraphDefinition.id,
|
|
5688
|
-
agentCount: Object.keys(typedGraphDefinition.agents).length
|
|
5689
|
-
toolCount: Object.keys(typedGraphDefinition.tools || {}).length
|
|
5716
|
+
agentCount: Object.keys(typedGraphDefinition.agents).length
|
|
5690
5717
|
},
|
|
5691
5718
|
"Updating full graph in database"
|
|
5692
5719
|
);
|
|
@@ -5699,8 +5726,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5699
5726
|
);
|
|
5700
5727
|
try {
|
|
5701
5728
|
const existingGraph = await getAgentGraphById(db)({
|
|
5702
|
-
scopes: { tenantId, projectId }
|
|
5703
|
-
graphId: typedGraphDefinition.id
|
|
5729
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
5704
5730
|
});
|
|
5705
5731
|
if (!existingGraph) {
|
|
5706
5732
|
logger11.info(
|
|
@@ -5710,65 +5736,40 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5710
5736
|
return createFullGraphServerSide(db)(scopes, graphData);
|
|
5711
5737
|
}
|
|
5712
5738
|
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
|
-
}
|
|
5739
|
+
logger11.info(
|
|
5740
|
+
{},
|
|
5741
|
+
"CredentialReferences are project-scoped - skipping credential reference update in graph"
|
|
5742
|
+
);
|
|
5743
|
+
logger11.info({}, "Tools are project-scoped - skipping tool creation in graph update");
|
|
5744
|
+
let finalGraphId;
|
|
5745
|
+
try {
|
|
5746
|
+
const graphId = typedGraphDefinition.id || nanoid.nanoid();
|
|
5747
|
+
logger11.info({ graphId }, "Getting/creating agent graph metadata");
|
|
5748
|
+
const agentGraph2 = await upsertAgentGraph(db)({
|
|
5749
|
+
data: {
|
|
5750
|
+
id: graphId,
|
|
5751
|
+
tenantId,
|
|
5752
|
+
projectId,
|
|
5753
|
+
name: typedGraphDefinition.name,
|
|
5754
|
+
defaultAgentId: typedGraphDefinition.defaultAgentId,
|
|
5755
|
+
description: typedGraphDefinition.description,
|
|
5756
|
+
contextConfigId: void 0,
|
|
5757
|
+
// Will be updated later if context config exists
|
|
5758
|
+
models: typedGraphDefinition.models,
|
|
5759
|
+
statusUpdates: typedGraphDefinition.statusUpdates,
|
|
5760
|
+
graphPrompt: typedGraphDefinition.graphPrompt,
|
|
5761
|
+
stopWhen: typedGraphDefinition.stopWhen
|
|
5739
5762
|
}
|
|
5763
|
+
});
|
|
5764
|
+
finalGraphId = agentGraph2.id;
|
|
5765
|
+
logger11.info({ graphId: finalGraphId }, "Agent graph metadata ready");
|
|
5766
|
+
} catch (error) {
|
|
5767
|
+
logger11.error(
|
|
5768
|
+
{ graphId: typedGraphDefinition.id, error },
|
|
5769
|
+
"Failed to get/update graph metadata"
|
|
5740
5770
|
);
|
|
5741
|
-
|
|
5742
|
-
logger11.info(
|
|
5743
|
-
{
|
|
5744
|
-
credentialReferencesCount: Object.keys(typedGraphDefinition.credentialReferences).length
|
|
5745
|
-
},
|
|
5746
|
-
"All credential references created/updated successfully"
|
|
5747
|
-
);
|
|
5771
|
+
throw error;
|
|
5748
5772
|
}
|
|
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
5773
|
let contextConfigId;
|
|
5773
5774
|
if (typedGraphDefinition.contextConfig) {
|
|
5774
5775
|
try {
|
|
@@ -5793,66 +5794,11 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5793
5794
|
throw error;
|
|
5794
5795
|
}
|
|
5795
5796
|
}
|
|
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
|
-
}
|
|
5797
|
+
logger11.info({}, "DataComponents are project-scoped - skipping dataComponent update in graph");
|
|
5798
|
+
logger11.info(
|
|
5799
|
+
{},
|
|
5800
|
+
"ArtifactComponents are project-scoped - skipping artifactComponent update in graph"
|
|
5801
|
+
);
|
|
5856
5802
|
const internalAgentPromises = Object.entries(typedGraphDefinition.agents).filter(([_, agentData]) => isInternalAgent(agentData)).map(async ([agentId, agentData]) => {
|
|
5857
5803
|
const internalAgent = agentData;
|
|
5858
5804
|
let existingAgent = null;
|
|
@@ -5901,6 +5847,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5901
5847
|
id: agentId,
|
|
5902
5848
|
tenantId,
|
|
5903
5849
|
projectId,
|
|
5850
|
+
graphId: finalGraphId,
|
|
5904
5851
|
name: internalAgent.name || "",
|
|
5905
5852
|
description: internalAgent.description || "",
|
|
5906
5853
|
prompt: internalAgent.prompt || "",
|
|
@@ -5929,6 +5876,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5929
5876
|
id: agentId,
|
|
5930
5877
|
tenantId,
|
|
5931
5878
|
projectId,
|
|
5879
|
+
graphId: finalGraphId,
|
|
5932
5880
|
name: externalAgent.name,
|
|
5933
5881
|
description: externalAgent.description || "",
|
|
5934
5882
|
baseUrl: externalAgent.baseUrl,
|
|
@@ -5948,8 +5896,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5948
5896
|
).length;
|
|
5949
5897
|
logger11.info({ externalAgentCount }, "All external agents created/updated successfully");
|
|
5950
5898
|
await updateAgentGraph(db)({
|
|
5951
|
-
scopes: { tenantId, projectId },
|
|
5952
|
-
graphId: typedGraphDefinition.id,
|
|
5899
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id },
|
|
5953
5900
|
data: {
|
|
5954
5901
|
name: typedGraphDefinition.name,
|
|
5955
5902
|
defaultAgentId: typedGraphDefinition.defaultAgentId,
|
|
@@ -5964,8 +5911,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5964
5911
|
logger11.info({ graphId: typedGraphDefinition.id }, "Graph metadata updated");
|
|
5965
5912
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
5966
5913
|
await deleteAgentToolRelationByAgent(db)({
|
|
5967
|
-
scopes: { tenantId, projectId }
|
|
5968
|
-
agentId
|
|
5914
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
5969
5915
|
});
|
|
5970
5916
|
}
|
|
5971
5917
|
const agentToolPromises = [];
|
|
@@ -5977,7 +5923,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
5977
5923
|
try {
|
|
5978
5924
|
const selectedTools = agentData.selectedTools?.[toolId];
|
|
5979
5925
|
await createAgentToolRelation(db)({
|
|
5980
|
-
scopes: { tenantId, projectId },
|
|
5926
|
+
scopes: { tenantId, projectId, graphId: finalGraphId },
|
|
5981
5927
|
data: {
|
|
5982
5928
|
agentId,
|
|
5983
5929
|
toolId,
|
|
@@ -6000,8 +5946,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6000
5946
|
);
|
|
6001
5947
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
6002
5948
|
await deleteAgentDataComponentRelationByAgent(db)({
|
|
6003
|
-
scopes: { tenantId, projectId }
|
|
6004
|
-
agentId
|
|
5949
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
6005
5950
|
});
|
|
6006
5951
|
}
|
|
6007
5952
|
const agentDataComponentPromises = [];
|
|
@@ -6012,8 +5957,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6012
5957
|
(async () => {
|
|
6013
5958
|
try {
|
|
6014
5959
|
await associateDataComponentWithAgent(db)({
|
|
6015
|
-
scopes: { tenantId, projectId },
|
|
6016
|
-
agentId,
|
|
5960
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
6017
5961
|
dataComponentId
|
|
6018
5962
|
});
|
|
6019
5963
|
logger11.info({ agentId, dataComponentId }, "Agent-dataComponent relation created");
|
|
@@ -6035,8 +5979,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6035
5979
|
);
|
|
6036
5980
|
for (const agentId of Object.keys(typedGraphDefinition.agents)) {
|
|
6037
5981
|
await deleteAgentArtifactComponentRelationByAgent(db)({
|
|
6038
|
-
scopes: { tenantId, projectId }
|
|
6039
|
-
agentId
|
|
5982
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId }
|
|
6040
5983
|
});
|
|
6041
5984
|
}
|
|
6042
5985
|
const agentArtifactComponentPromises = [];
|
|
@@ -6047,8 +5990,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6047
5990
|
(async () => {
|
|
6048
5991
|
try {
|
|
6049
5992
|
await associateArtifactComponentWithAgent(db)({
|
|
6050
|
-
scopes: { tenantId, projectId },
|
|
6051
|
-
agentId,
|
|
5993
|
+
scopes: { tenantId, projectId, graphId: finalGraphId, agentId },
|
|
6052
5994
|
artifactComponentId
|
|
6053
5995
|
});
|
|
6054
5996
|
logger11.info(
|
|
@@ -6072,8 +6014,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6072
6014
|
"All agent-artifactComponent relations updated"
|
|
6073
6015
|
);
|
|
6074
6016
|
await deleteAgentRelationsByGraph(db)({
|
|
6075
|
-
scopes: { tenantId, projectId }
|
|
6076
|
-
graphId: typedGraphDefinition.id
|
|
6017
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
6077
6018
|
});
|
|
6078
6019
|
const agentRelationPromises = [];
|
|
6079
6020
|
for (const [agentId, agentData] of Object.entries(typedGraphDefinition.agents)) {
|
|
@@ -6149,8 +6090,7 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6149
6090
|
"All agent relations updated"
|
|
6150
6091
|
);
|
|
6151
6092
|
const updatedGraph = await getFullGraphDefinition(db)({
|
|
6152
|
-
scopes: { tenantId, projectId }
|
|
6153
|
-
graphId: typedGraphDefinition.id
|
|
6093
|
+
scopes: { tenantId, projectId, graphId: typedGraphDefinition.id }
|
|
6154
6094
|
});
|
|
6155
6095
|
if (!updatedGraph) {
|
|
6156
6096
|
throw new Error("Failed to retrieve updated graph");
|
|
@@ -6163,22 +6103,21 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
|
|
|
6163
6103
|
}
|
|
6164
6104
|
};
|
|
6165
6105
|
var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
6166
|
-
const { scopes
|
|
6106
|
+
const { scopes } = params;
|
|
6167
6107
|
const { tenantId, projectId } = scopes;
|
|
6168
|
-
logger11.info({ tenantId, graphId }, "Retrieving full graph definition");
|
|
6108
|
+
logger11.info({ tenantId, graphId: scopes.graphId }, "Retrieving full graph definition");
|
|
6169
6109
|
try {
|
|
6170
6110
|
const graph = await getFullGraphDefinition(db)({
|
|
6171
|
-
scopes: { tenantId, projectId }
|
|
6172
|
-
graphId
|
|
6111
|
+
scopes: { tenantId, projectId, graphId: scopes.graphId }
|
|
6173
6112
|
});
|
|
6174
6113
|
if (!graph) {
|
|
6175
|
-
logger11.info({ tenantId, graphId }, "Graph not found");
|
|
6114
|
+
logger11.info({ tenantId, graphId: scopes.graphId }, "Graph not found");
|
|
6176
6115
|
return null;
|
|
6177
6116
|
}
|
|
6178
6117
|
logger11.info(
|
|
6179
6118
|
{
|
|
6180
6119
|
tenantId,
|
|
6181
|
-
graphId,
|
|
6120
|
+
graphId: scopes.graphId,
|
|
6182
6121
|
agentCount: Object.keys(graph.agents).length
|
|
6183
6122
|
},
|
|
6184
6123
|
"Full graph retrieved successfully"
|
|
@@ -6188,7 +6127,7 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
6188
6127
|
logger11.error(
|
|
6189
6128
|
{
|
|
6190
6129
|
tenantId,
|
|
6191
|
-
graphId,
|
|
6130
|
+
graphId: scopes.graphId,
|
|
6192
6131
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
6193
6132
|
},
|
|
6194
6133
|
"Failed to retrieve full graph"
|
|
@@ -6197,29 +6136,25 @@ var getFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
6197
6136
|
}
|
|
6198
6137
|
};
|
|
6199
6138
|
var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
6200
|
-
const {
|
|
6201
|
-
const { tenantId, projectId } = scopes;
|
|
6139
|
+
const { tenantId, projectId, graphId } = params.scopes;
|
|
6202
6140
|
logger11.info({ tenantId, graphId }, "Deleting full graph and related entities");
|
|
6203
6141
|
try {
|
|
6204
6142
|
const graph = await getFullGraphDefinition(db)({
|
|
6205
|
-
scopes: { tenantId, projectId }
|
|
6206
|
-
graphId
|
|
6143
|
+
scopes: { tenantId, projectId, graphId }
|
|
6207
6144
|
});
|
|
6208
6145
|
if (!graph) {
|
|
6209
6146
|
logger11.info({ tenantId, graphId }, "Graph not found for deletion");
|
|
6210
6147
|
return false;
|
|
6211
6148
|
}
|
|
6212
6149
|
await deleteAgentRelationsByGraph(db)({
|
|
6213
|
-
scopes: { tenantId, projectId }
|
|
6214
|
-
graphId
|
|
6150
|
+
scopes: { tenantId, projectId, graphId }
|
|
6215
6151
|
});
|
|
6216
6152
|
logger11.info({ tenantId, graphId }, "Agent relations deleted");
|
|
6217
6153
|
const agentIds = Object.keys(graph.agents);
|
|
6218
6154
|
if (agentIds.length > 0) {
|
|
6219
6155
|
for (const agentId of agentIds) {
|
|
6220
6156
|
await deleteAgentToolRelationByAgent(db)({
|
|
6221
|
-
scopes: { tenantId, projectId }
|
|
6222
|
-
agentId
|
|
6157
|
+
scopes: { tenantId, projectId, graphId, agentId }
|
|
6223
6158
|
});
|
|
6224
6159
|
}
|
|
6225
6160
|
logger11.info(
|
|
@@ -6228,8 +6163,7 @@ var deleteFullGraph = (db, logger11 = defaultLogger) => async (params) => {
|
|
|
6228
6163
|
);
|
|
6229
6164
|
}
|
|
6230
6165
|
await deleteAgentGraph(db)({
|
|
6231
|
-
scopes: { tenantId, projectId }
|
|
6232
|
-
graphId
|
|
6166
|
+
scopes: { tenantId, projectId, graphId }
|
|
6233
6167
|
});
|
|
6234
6168
|
logger11.info({ tenantId, graphId }, "Graph metadata deleted");
|
|
6235
6169
|
logger11.info({ tenantId, graphId }, "Full graph deleted successfully");
|
|
@@ -6938,8 +6872,7 @@ var createFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
6938
6872
|
db,
|
|
6939
6873
|
logger11
|
|
6940
6874
|
)({
|
|
6941
|
-
scopes: { tenantId, projectId: typed.id }
|
|
6942
|
-
projectId: typed.id
|
|
6875
|
+
scopes: { tenantId, projectId: typed.id }
|
|
6943
6876
|
});
|
|
6944
6877
|
} catch (error) {
|
|
6945
6878
|
logger11.error(
|
|
@@ -7245,8 +7178,7 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
7245
7178
|
db,
|
|
7246
7179
|
logger11
|
|
7247
7180
|
)({
|
|
7248
|
-
scopes: { tenantId, projectId: typed.id }
|
|
7249
|
-
projectId: typed.id
|
|
7181
|
+
scopes: { tenantId, projectId: typed.id }
|
|
7250
7182
|
});
|
|
7251
7183
|
} catch (error) {
|
|
7252
7184
|
logger11.error(
|
|
@@ -7261,8 +7193,8 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
|
|
|
7261
7193
|
}
|
|
7262
7194
|
};
|
|
7263
7195
|
var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
7264
|
-
const { scopes
|
|
7265
|
-
const { tenantId } = scopes;
|
|
7196
|
+
const { scopes } = params;
|
|
7197
|
+
const { tenantId, projectId } = scopes;
|
|
7266
7198
|
logger11.info({ tenantId, projectId }, "Retrieving full project definition");
|
|
7267
7199
|
try {
|
|
7268
7200
|
const project = await getProject(db)({
|
|
@@ -7416,18 +7348,10 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
7416
7348
|
"Retrieving full graph definition"
|
|
7417
7349
|
);
|
|
7418
7350
|
const fullGraph = await getFullGraph(db)({
|
|
7419
|
-
scopes: { tenantId, projectId }
|
|
7420
|
-
graphId: graph.id
|
|
7351
|
+
scopes: { tenantId, projectId, graphId: graph.id }
|
|
7421
7352
|
});
|
|
7422
7353
|
if (fullGraph) {
|
|
7423
|
-
const {
|
|
7424
|
-
tools: _tools,
|
|
7425
|
-
dataComponents: _dataComponents,
|
|
7426
|
-
artifactComponents: _artifactComponents,
|
|
7427
|
-
contextConfig: _contextConfig,
|
|
7428
|
-
credentialReferences: _credentialReferences,
|
|
7429
|
-
...graphWithoutProjectResources
|
|
7430
|
-
} = fullGraph;
|
|
7354
|
+
const { contextConfig: _contextConfig, ...graphWithoutProjectResources } = fullGraph;
|
|
7431
7355
|
graphs[graph.id] = graphWithoutProjectResources;
|
|
7432
7356
|
logger11.info(
|
|
7433
7357
|
{ tenantId, projectId, graphId: graph.id },
|
|
@@ -7482,16 +7406,15 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
7482
7406
|
}
|
|
7483
7407
|
};
|
|
7484
7408
|
var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
7485
|
-
const { scopes
|
|
7486
|
-
const { tenantId } = scopes;
|
|
7409
|
+
const { scopes } = params;
|
|
7410
|
+
const { tenantId, projectId } = scopes;
|
|
7487
7411
|
logger11.info({ tenantId, projectId }, "Deleting full project and related entities");
|
|
7488
7412
|
try {
|
|
7489
7413
|
const project = await getFullProject(
|
|
7490
7414
|
db,
|
|
7491
7415
|
logger11
|
|
7492
7416
|
)({
|
|
7493
|
-
scopes: { tenantId, projectId }
|
|
7494
|
-
projectId
|
|
7417
|
+
scopes: { tenantId, projectId }
|
|
7495
7418
|
});
|
|
7496
7419
|
if (!project) {
|
|
7497
7420
|
logger11.info({ tenantId, projectId }, "Project not found for deletion");
|
|
@@ -7513,8 +7436,7 @@ var deleteFullProject = (db, logger11 = defaultLogger2) => async (params) => {
|
|
|
7513
7436
|
db,
|
|
7514
7437
|
logger11
|
|
7515
7438
|
)({
|
|
7516
|
-
scopes: { tenantId, projectId }
|
|
7517
|
-
graphId
|
|
7439
|
+
scopes: { tenantId, projectId, graphId }
|
|
7518
7440
|
});
|
|
7519
7441
|
logger11.info(
|
|
7520
7442
|
{ tenantId, projectId, graphId },
|
|
@@ -8929,8 +8851,7 @@ async function validateRequestContext({
|
|
|
8929
8851
|
}) {
|
|
8930
8852
|
try {
|
|
8931
8853
|
const agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
|
|
8932
|
-
scopes: { tenantId, projectId }
|
|
8933
|
-
graphId
|
|
8854
|
+
scopes: { tenantId, projectId, graphId }
|
|
8934
8855
|
});
|
|
8935
8856
|
if (!agentGraph2?.contextConfigId) {
|
|
8936
8857
|
logger7.debug({ graphId }, "No context config found for graph, skipping validation");
|
|
@@ -9477,7 +9398,15 @@ async function handleContextConfigChange(tenantId, projectId, conversationId, gr
|
|
|
9477
9398
|
);
|
|
9478
9399
|
}
|
|
9479
9400
|
}
|
|
9480
|
-
async function handleContextResolution(
|
|
9401
|
+
async function handleContextResolution({
|
|
9402
|
+
tenantId,
|
|
9403
|
+
projectId,
|
|
9404
|
+
graphId,
|
|
9405
|
+
conversationId,
|
|
9406
|
+
requestContext,
|
|
9407
|
+
dbClient,
|
|
9408
|
+
credentialStores
|
|
9409
|
+
}) {
|
|
9481
9410
|
return tracer.startActiveSpan(
|
|
9482
9411
|
"context.handle_context_resolution",
|
|
9483
9412
|
{
|
|
@@ -9490,8 +9419,7 @@ async function handleContextResolution(tenantId, projectId, conversationId, grap
|
|
|
9490
9419
|
let trigger;
|
|
9491
9420
|
try {
|
|
9492
9421
|
agentGraph2 = await getAgentGraphWithDefaultAgent(dbClient)({
|
|
9493
|
-
scopes: { tenantId, projectId }
|
|
9494
|
-
graphId
|
|
9422
|
+
scopes: { tenantId, projectId, graphId }
|
|
9495
9423
|
});
|
|
9496
9424
|
if (!agentGraph2?.contextConfigId) {
|
|
9497
9425
|
logger9.debug({ graphId }, "No context config found for graph");
|
|
@@ -10214,12 +10142,13 @@ var loadEnvironmentFiles = () => {
|
|
|
10214
10142
|
}
|
|
10215
10143
|
const userConfigPath = path__default.default.join(os__default.default.homedir(), ".inkeep", "config");
|
|
10216
10144
|
if (fs__default.default.existsSync(userConfigPath)) {
|
|
10217
|
-
dotenv__default.default.config({ path: userConfigPath, override: true });
|
|
10145
|
+
dotenv__default.default.config({ path: userConfigPath, override: true, quiet: true });
|
|
10218
10146
|
}
|
|
10219
10147
|
if (environmentFiles.length > 0) {
|
|
10220
10148
|
dotenv__default.default.config({
|
|
10221
10149
|
path: environmentFiles,
|
|
10222
|
-
override: false
|
|
10150
|
+
override: false,
|
|
10151
|
+
quiet: true
|
|
10223
10152
|
});
|
|
10224
10153
|
dotenvExpand.expand({ processEnv: process.env });
|
|
10225
10154
|
}
|
|
@@ -10437,6 +10366,8 @@ exports.TaskUpdateSchema = TaskUpdateSchema;
|
|
|
10437
10366
|
exports.TemplateEngine = TemplateEngine;
|
|
10438
10367
|
exports.TenantIdParamsSchema = TenantIdParamsSchema;
|
|
10439
10368
|
exports.TenantParamsSchema = TenantParamsSchema;
|
|
10369
|
+
exports.TenantProjectGraphIdParamsSchema = TenantProjectGraphIdParamsSchema;
|
|
10370
|
+
exports.TenantProjectGraphParamsSchema = TenantProjectGraphParamsSchema;
|
|
10440
10371
|
exports.TenantProjectIdParamsSchema = TenantProjectIdParamsSchema;
|
|
10441
10372
|
exports.TenantProjectParamsSchema = TenantProjectParamsSchema;
|
|
10442
10373
|
exports.ToolApiInsertSchema = ToolApiInsertSchema;
|
|
@@ -10453,6 +10384,7 @@ exports.addToolToAgent = addToolToAgent;
|
|
|
10453
10384
|
exports.agentArtifactComponents = agentArtifactComponents;
|
|
10454
10385
|
exports.agentArtifactComponentsRelations = agentArtifactComponentsRelations;
|
|
10455
10386
|
exports.agentDataComponents = agentDataComponents;
|
|
10387
|
+
exports.agentDataComponentsRelations = agentDataComponentsRelations;
|
|
10456
10388
|
exports.agentGraph = agentGraph;
|
|
10457
10389
|
exports.agentGraphRelations = agentGraphRelations;
|
|
10458
10390
|
exports.agentRelations = agentRelations;
|
|
@@ -10523,6 +10455,7 @@ exports.createValidatedDataAccess = createValidatedDataAccess;
|
|
|
10523
10455
|
exports.credentialReferences = credentialReferences;
|
|
10524
10456
|
exports.credentialReferencesRelations = credentialReferencesRelations;
|
|
10525
10457
|
exports.dataComponents = dataComponents;
|
|
10458
|
+
exports.dataComponentsRelations = dataComponentsRelations;
|
|
10526
10459
|
exports.dbResultToMcpTool = dbResultToMcpTool;
|
|
10527
10460
|
exports.deleteAgent = deleteAgent;
|
|
10528
10461
|
exports.deleteAgentArtifactComponentRelationByAgent = deleteAgentArtifactComponentRelationByAgent;
|
|
@@ -10563,10 +10496,8 @@ exports.generateApiKey = generateApiKey;
|
|
|
10563
10496
|
exports.generateIdFromName = generateIdFromName;
|
|
10564
10497
|
exports.getActiveAgentForConversation = getActiveAgentForConversation;
|
|
10565
10498
|
exports.getAgentById = getAgentById;
|
|
10566
|
-
exports.getAgentGraph = getAgentGraph;
|
|
10567
10499
|
exports.getAgentGraphById = getAgentGraphById;
|
|
10568
10500
|
exports.getAgentGraphWithDefaultAgent = getAgentGraphWithDefaultAgent;
|
|
10569
|
-
exports.getAgentInGraphContext = getAgentInGraphContext;
|
|
10570
10501
|
exports.getAgentRelationById = getAgentRelationById;
|
|
10571
10502
|
exports.getAgentRelationByParams = getAgentRelationByParams;
|
|
10572
10503
|
exports.getAgentRelations = getAgentRelations;
|
|
@@ -10641,13 +10572,13 @@ exports.isValidHttpRequest = isValidHttpRequest;
|
|
|
10641
10572
|
exports.isValidResourceId = isValidResourceId;
|
|
10642
10573
|
exports.ledgerArtifacts = ledgerArtifacts;
|
|
10643
10574
|
exports.ledgerArtifactsContextIdIdx = ledgerArtifactsContextIdIdx;
|
|
10575
|
+
exports.ledgerArtifactsRelations = ledgerArtifactsRelations;
|
|
10644
10576
|
exports.ledgerArtifactsTaskContextNameUnique = ledgerArtifactsTaskContextNameUnique;
|
|
10645
10577
|
exports.ledgerArtifactsTaskIdIdx = ledgerArtifactsTaskIdIdx;
|
|
10646
10578
|
exports.listAgentGraphs = listAgentGraphs;
|
|
10647
10579
|
exports.listAgentGraphsPaginated = listAgentGraphsPaginated;
|
|
10648
10580
|
exports.listAgentRelations = listAgentRelations;
|
|
10649
10581
|
exports.listAgentToolRelations = listAgentToolRelations;
|
|
10650
|
-
exports.listAgentToolRelationsByAgent = listAgentToolRelationsByAgent;
|
|
10651
10582
|
exports.listAgents = listAgents;
|
|
10652
10583
|
exports.listAgentsPaginated = listAgentsPaginated;
|
|
10653
10584
|
exports.listApiKeys = listApiKeys;
|