@inkeep/agents-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +51 -0
- package/README.md +464 -0
- package/dist/__tests__/integration/helpers.d.ts +5 -0
- package/dist/__tests__/integration/helpers.d.ts.map +1 -0
- package/dist/__tests__/integration/helpers.js +37 -0
- package/dist/__tests__/integration/helpers.js.map +1 -0
- package/dist/__tests__/setup.d.ts +3 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +29 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client-exports.d.ts +301 -0
- package/dist/client-exports.d.ts.map +1 -0
- package/dist/client-exports.js +251 -0
- package/dist/client-exports.js.map +1 -0
- package/dist/context/ContextConfig.d.ts +55 -0
- package/dist/context/ContextConfig.d.ts.map +1 -0
- package/dist/context/ContextConfig.js +302 -0
- package/dist/context/ContextConfig.js.map +1 -0
- package/dist/context/ContextFetcher.d.ts +64 -0
- package/dist/context/ContextFetcher.d.ts.map +1 -0
- package/dist/context/ContextFetcher.js +325 -0
- package/dist/context/ContextFetcher.js.map +1 -0
- package/dist/context/ContextResolver.d.ts +52 -0
- package/dist/context/ContextResolver.d.ts.map +1 -0
- package/dist/context/ContextResolver.js +298 -0
- package/dist/context/ContextResolver.js.map +1 -0
- package/dist/context/TemplateEngine.d.ts +46 -0
- package/dist/context/TemplateEngine.d.ts.map +1 -0
- package/dist/context/TemplateEngine.js +175 -0
- package/dist/context/TemplateEngine.js.map +1 -0
- package/dist/context/context.d.ts +7 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.js +157 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/contextCache.d.ts +50 -0
- package/dist/context/contextCache.d.ts.map +1 -0
- package/dist/context/contextCache.js +175 -0
- package/dist/context/contextCache.js.map +1 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +8 -0
- package/dist/context/index.js.map +1 -0
- package/dist/credential-stores/index.d.ts +4 -0
- package/dist/credential-stores/index.d.ts.map +1 -0
- package/dist/credential-stores/index.js +4 -0
- package/dist/credential-stores/index.js.map +1 -0
- package/dist/credential-stores/keychain-store.d.ts +100 -0
- package/dist/credential-stores/keychain-store.d.ts.map +1 -0
- package/dist/credential-stores/keychain-store.js +225 -0
- package/dist/credential-stores/keychain-store.js.map +1 -0
- package/dist/credential-stores/memory-store.d.ts +39 -0
- package/dist/credential-stores/memory-store.d.ts.map +1 -0
- package/dist/credential-stores/memory-store.js +58 -0
- package/dist/credential-stores/memory-store.js.map +1 -0
- package/dist/credential-stores/nango-store.d.ts +59 -0
- package/dist/credential-stores/nango-store.d.ts.map +1 -0
- package/dist/credential-stores/nango-store.js +264 -0
- package/dist/credential-stores/nango-store.js.map +1 -0
- package/dist/credential-stuffer/CredentialStuffer.d.ts +80 -0
- package/dist/credential-stuffer/CredentialStuffer.d.ts.map +1 -0
- package/dist/credential-stuffer/CredentialStuffer.js +186 -0
- package/dist/credential-stuffer/CredentialStuffer.js.map +1 -0
- package/dist/credential-stuffer/index.d.ts +2 -0
- package/dist/credential-stuffer/index.d.ts.map +1 -0
- package/dist/credential-stuffer/index.js +2 -0
- package/dist/credential-stuffer/index.js.map +1 -0
- package/dist/data-access/agentDataComponents.d.ts +1 -0
- package/dist/data-access/agentDataComponents.d.ts.map +1 -0
- package/dist/data-access/agentDataComponents.js +2 -0
- package/dist/data-access/agentDataComponents.js.map +1 -0
- package/dist/data-access/agentGraphs.d.ts +406 -0
- package/dist/data-access/agentGraphs.d.ts.map +1 -0
- package/dist/data-access/agentGraphs.js +551 -0
- package/dist/data-access/agentGraphs.js.map +1 -0
- package/dist/data-access/agentRelations.d.ts +456 -0
- package/dist/data-access/agentRelations.d.ts.map +1 -0
- package/dist/data-access/agentRelations.js +471 -0
- package/dist/data-access/agentRelations.js.map +1 -0
- package/dist/data-access/agents.d.ts +218 -0
- package/dist/data-access/agents.d.ts.map +1 -0
- package/dist/data-access/agents.js +130 -0
- package/dist/data-access/agents.js.map +1 -0
- package/dist/data-access/apiKeys.d.ts +114 -0
- package/dist/data-access/apiKeys.d.ts.map +1 -0
- package/dist/data-access/apiKeys.js +185 -0
- package/dist/data-access/apiKeys.js.map +1 -0
- package/dist/data-access/artifactComponents.d.ts +152 -0
- package/dist/data-access/artifactComponents.d.ts.map +1 -0
- package/dist/data-access/artifactComponents.js +214 -0
- package/dist/data-access/artifactComponents.js.map +1 -0
- package/dist/data-access/contextCache.d.ts +68 -0
- package/dist/data-access/contextCache.d.ts.map +1 -0
- package/dist/data-access/contextCache.js +160 -0
- package/dist/data-access/contextCache.js.map +1 -0
- package/dist/data-access/contextConfigs.d.ts +110 -0
- package/dist/data-access/contextConfigs.d.ts.map +1 -0
- package/dist/data-access/contextConfigs.js +156 -0
- package/dist/data-access/contextConfigs.js.map +1 -0
- package/dist/data-access/conversations.d.ts +125 -0
- package/dist/data-access/conversations.d.ts.map +1 -0
- package/dist/data-access/conversations.js +244 -0
- package/dist/data-access/conversations.js.map +1 -0
- package/dist/data-access/credentialReferences.d.ts +86 -0
- package/dist/data-access/credentialReferences.d.ts.map +1 -0
- package/dist/data-access/credentialReferences.js +175 -0
- package/dist/data-access/credentialReferences.js.map +1 -0
- package/dist/data-access/dataComponents.d.ts +129 -0
- package/dist/data-access/dataComponents.d.ts.map +1 -0
- package/dist/data-access/dataComponents.js +213 -0
- package/dist/data-access/dataComponents.js.map +1 -0
- package/dist/data-access/externalAgents.d.ts +83 -0
- package/dist/data-access/externalAgents.d.ts.map +1 -0
- package/dist/data-access/externalAgents.js +163 -0
- package/dist/data-access/externalAgents.js.map +1 -0
- package/dist/data-access/graphFull.d.ts +32 -0
- package/dist/data-access/graphFull.d.ts.map +1 -0
- package/dist/data-access/graphFull.js +995 -0
- package/dist/data-access/graphFull.js.map +1 -0
- package/dist/data-access/index.d.ts +21 -0
- package/dist/data-access/index.d.ts.map +1 -0
- package/dist/data-access/index.js +22 -0
- package/dist/data-access/index.js.map +1 -0
- package/dist/data-access/ledgerArtifacts.d.ts +50 -0
- package/dist/data-access/ledgerArtifacts.d.ts.map +1 -0
- package/dist/data-access/ledgerArtifacts.js +112 -0
- package/dist/data-access/ledgerArtifacts.js.map +1 -0
- package/dist/data-access/messages.d.ts +209 -0
- package/dist/data-access/messages.d.ts.map +1 -0
- package/dist/data-access/messages.js +100 -0
- package/dist/data-access/messages.js.map +1 -0
- package/dist/data-access/projects.d.ts +67 -0
- package/dist/data-access/projects.d.ts.map +1 -0
- package/dist/data-access/projects.js +336 -0
- package/dist/data-access/projects.js.map +1 -0
- package/dist/data-access/tasks.d.ts +37 -0
- package/dist/data-access/tasks.d.ts.map +1 -0
- package/dist/data-access/tasks.js +40 -0
- package/dist/data-access/tasks.js.map +1 -0
- package/dist/data-access/tools.d.ts +277 -0
- package/dist/data-access/tools.d.ts.map +1 -0
- package/dist/data-access/tools.js +183 -0
- package/dist/data-access/tools.js.map +1 -0
- package/dist/data-access/validation.d.ts +17 -0
- package/dist/data-access/validation.d.ts.map +1 -0
- package/dist/data-access/validation.js +52 -0
- package/dist/data-access/validation.js.map +1 -0
- package/dist/db/clean.d.ts +6 -0
- package/dist/db/clean.d.ts.map +1 -0
- package/dist/db/clean.js +81 -0
- package/dist/db/clean.js.map +1 -0
- package/dist/db/client.d.ts +19 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +24 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/schema.d.ts +4337 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +696 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/test-client.d.ts +25 -0
- package/dist/db/test-client.d.ts.map +1 -0
- package/dist/db/test-client.js +136 -0
- package/dist/db/test-client.js.map +1 -0
- package/dist/env.d.ts +17 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +48 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/contextValidation.d.ts +48 -0
- package/dist/middleware/contextValidation.d.ts.map +1 -0
- package/dist/middleware/contextValidation.js +469 -0
- package/dist/middleware/contextValidation.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/server/BaseServer.d.ts +83 -0
- package/dist/server/BaseServer.d.ts.map +1 -0
- package/dist/server/BaseServer.js +218 -0
- package/dist/server/BaseServer.js.map +1 -0
- package/dist/types/a2a.d.ts +373 -0
- package/dist/types/a2a.d.ts.map +1 -0
- package/dist/types/a2a.js +14 -0
- package/dist/types/a2a.js.map +1 -0
- package/dist/types/entities.d.ts +147 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/entities.js +2 -0
- package/dist/types/entities.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/server.d.ts +116 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/server.js +2 -0
- package/dist/types/server.js.map +1 -0
- package/dist/types/utility.d.ts +214 -0
- package/dist/types/utility.d.ts.map +1 -0
- package/dist/types/utility.js +9 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/utils/apiKeys.d.ts +32 -0
- package/dist/utils/apiKeys.d.ts.map +1 -0
- package/dist/utils/apiKeys.js +117 -0
- package/dist/utils/apiKeys.js.map +1 -0
- package/dist/utils/auth-detection.d.ts +23 -0
- package/dist/utils/auth-detection.d.ts.map +1 -0
- package/dist/utils/auth-detection.js +148 -0
- package/dist/utils/auth-detection.js.map +1 -0
- package/dist/utils/credential-store-utils.d.ts +11 -0
- package/dist/utils/credential-store-utils.d.ts.map +1 -0
- package/dist/utils/credential-store-utils.js +19 -0
- package/dist/utils/credential-store-utils.js.map +1 -0
- package/dist/utils/error.d.ts +526 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +282 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/execution.d.ts +18 -0
- package/dist/utils/execution.d.ts.map +1 -0
- package/dist/utils/execution.js +25 -0
- package/dist/utils/execution.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +79 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +102 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logging.d.ts +11 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/logging.js +6 -0
- package/dist/utils/logging.js.map +1 -0
- package/dist/utils/mcp-client.d.ts +48 -0
- package/dist/utils/mcp-client.d.ts.map +1 -0
- package/dist/utils/mcp-client.js +171 -0
- package/dist/utils/mcp-client.js.map +1 -0
- package/dist/utils/tracer.d.ts +24 -0
- package/dist/utils/tracer.d.ts.map +1 -0
- package/dist/utils/tracer.js +98 -0
- package/dist/utils/tracer.js.map +1 -0
- package/dist/validation/graphFull.d.ts +36 -0
- package/dist/validation/graphFull.d.ts.map +1 -0
- package/dist/validation/graphFull.js +128 -0
- package/dist/validation/graphFull.js.map +1 -0
- package/dist/validation/id-validation.d.ts +38 -0
- package/dist/validation/id-validation.d.ts.map +1 -0
- package/dist/validation/id-validation.js +60 -0
- package/dist/validation/id-validation.js.map +1 -0
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/schemas.d.ts +7233 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +525 -0
- package/dist/validation/schemas.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
import { relations, sql } from 'drizzle-orm';
|
|
2
|
+
import { blob, foreignKey, index, integer, primaryKey, sqliteTable, text, unique, } from 'drizzle-orm/sqlite-core';
|
|
3
|
+
// Projects table: Stores project metadata
|
|
4
|
+
export const projects = sqliteTable('projects', {
|
|
5
|
+
tenantId: text('tenant_id').notNull(),
|
|
6
|
+
id: text('id').notNull(), // This IS the project ID
|
|
7
|
+
name: text('name').notNull(),
|
|
8
|
+
description: text('description').notNull(),
|
|
9
|
+
// Project-level default model settingsuration that can be inherited by graphs and agents
|
|
10
|
+
models: text('models', { mode: 'json' }).$type(),
|
|
11
|
+
// Project-level stopWhen configuration that can be inherited by graphs and agents
|
|
12
|
+
stopWhen: text('stop_when', { mode: 'json' }).$type(),
|
|
13
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
14
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
15
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.id] })]);
|
|
16
|
+
// Context system: Shared context configurations
|
|
17
|
+
export const contextConfigs = sqliteTable('context_configs', {
|
|
18
|
+
tenantId: text('tenant_id').notNull(),
|
|
19
|
+
projectId: text('project_id').notNull(),
|
|
20
|
+
id: text('id').notNull(),
|
|
21
|
+
name: text('name').notNull(),
|
|
22
|
+
description: text('description').notNull(),
|
|
23
|
+
// Developer-defined Zod schema for validating incoming request context
|
|
24
|
+
requestContextSchema: blob('request_context_schema', { mode: 'json' }).$type(), // Stores serialized Zod schema
|
|
25
|
+
// Object mapping template keys to fetch definitions that use request context data
|
|
26
|
+
contextVariables: blob('context_variables', { mode: 'json' }).$type(),
|
|
27
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
28
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
29
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
30
|
+
// Context cache: Stores actual fetched context data (conversation-scoped only)
|
|
31
|
+
export const contextCache = sqliteTable('context_cache', {
|
|
32
|
+
tenantId: text('tenant_id').notNull(),
|
|
33
|
+
projectId: text('project_id').notNull(),
|
|
34
|
+
id: text('id').notNull(),
|
|
35
|
+
// Always scoped to conversation for complete data isolation
|
|
36
|
+
conversationId: text('conversation_id').notNull(),
|
|
37
|
+
// Reference to the context config and specific fetch definition
|
|
38
|
+
contextConfigId: text('context_config_id').notNull(),
|
|
39
|
+
contextVariableKey: text('context_variable_key').notNull(), // Key from contextVariables object
|
|
40
|
+
// The actual cached context data
|
|
41
|
+
value: blob('value', { mode: 'json' }).$type().notNull(),
|
|
42
|
+
// Request hash for cache invalidation based on context changes
|
|
43
|
+
requestHash: text('request_hash'), // Hash of request context that triggered this cache
|
|
44
|
+
// Metadata for monitoring and debugging
|
|
45
|
+
fetchedAt: text('fetched_at').notNull(),
|
|
46
|
+
fetchSource: text('fetch_source'), // URL or source identifier
|
|
47
|
+
fetchDurationMs: integer('fetch_duration_ms'),
|
|
48
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
49
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
50
|
+
}, (table) => [
|
|
51
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
52
|
+
index('context_cache_lookup_idx').on(table.conversationId, table.contextConfigId, table.contextVariableKey),
|
|
53
|
+
]);
|
|
54
|
+
// Define the agents table schema
|
|
55
|
+
export const agents = sqliteTable('agents', {
|
|
56
|
+
tenantId: text('tenant_id').notNull(),
|
|
57
|
+
projectId: text('project_id').notNull(),
|
|
58
|
+
id: text('id').notNull(),
|
|
59
|
+
name: text('name').notNull(),
|
|
60
|
+
description: text('description').notNull(),
|
|
61
|
+
instructions: text('instructions').notNull(),
|
|
62
|
+
conversationHistoryConfig: text('conversation_history_config', {
|
|
63
|
+
mode: 'json',
|
|
64
|
+
}).$type(),
|
|
65
|
+
models: text('models', { mode: 'json' }).$type(),
|
|
66
|
+
// Agent-level stopWhen configuration (inherited from project)
|
|
67
|
+
stopWhen: text('stop_when', { mode: 'json' }).$type(),
|
|
68
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
69
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
70
|
+
}, (table) => [
|
|
71
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
72
|
+
foreignKey({
|
|
73
|
+
columns: [table.tenantId, table.projectId],
|
|
74
|
+
foreignColumns: [projects.tenantId, projects.id],
|
|
75
|
+
name: 'agents_project_fk',
|
|
76
|
+
}),
|
|
77
|
+
]);
|
|
78
|
+
// Define the agent relations table for many-to-many relationships with directionality
|
|
79
|
+
// Supports both internal-internal and internal-external relationships
|
|
80
|
+
export const agentRelations = sqliteTable('agent_relations', {
|
|
81
|
+
tenantId: text('tenant_id').notNull(),
|
|
82
|
+
projectId: text('project_id').notNull(),
|
|
83
|
+
id: text('id').notNull(),
|
|
84
|
+
graphId: text('graph_id').notNull(),
|
|
85
|
+
sourceAgentId: text('source_agent_id').notNull(),
|
|
86
|
+
// For internal relationships
|
|
87
|
+
targetAgentId: text('target_agent_id'),
|
|
88
|
+
// For external relationships
|
|
89
|
+
externalAgentId: text('external_agent_id'),
|
|
90
|
+
relationType: text('relation_type'), // 'handoff' | 'delegate'
|
|
91
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
92
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
93
|
+
}, (table) => [
|
|
94
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
95
|
+
foreignKey({
|
|
96
|
+
columns: [table.tenantId, table.projectId],
|
|
97
|
+
foreignColumns: [projects.tenantId, projects.id],
|
|
98
|
+
name: 'agent_relations_project_fk',
|
|
99
|
+
}),
|
|
100
|
+
]);
|
|
101
|
+
// Define external agents table for inter-graph communication
|
|
102
|
+
export const externalAgents = sqliteTable('external_agents', {
|
|
103
|
+
tenantId: text('tenant_id').notNull(),
|
|
104
|
+
projectId: text('project_id').notNull(),
|
|
105
|
+
id: text('id').notNull(),
|
|
106
|
+
name: text('name').notNull(),
|
|
107
|
+
description: text('description').notNull(),
|
|
108
|
+
baseUrl: text('base_url').notNull(), // A2A endpoint URL
|
|
109
|
+
credentialReferenceId: text('credential_reference_id'),
|
|
110
|
+
headers: blob('headers', { mode: 'json' }).$type(),
|
|
111
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
112
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
113
|
+
}, (table) => [
|
|
114
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
115
|
+
foreignKey({
|
|
116
|
+
columns: [table.tenantId, table.projectId, table.credentialReferenceId],
|
|
117
|
+
foreignColumns: [
|
|
118
|
+
credentialReferences.tenantId,
|
|
119
|
+
credentialReferences.projectId,
|
|
120
|
+
credentialReferences.id,
|
|
121
|
+
],
|
|
122
|
+
name: 'external_agents_credential_reference_fk',
|
|
123
|
+
}).onDelete('set null'),
|
|
124
|
+
]);
|
|
125
|
+
// Define the agent graph table (updated to reference context configs)
|
|
126
|
+
export const agentGraph = sqliteTable('agent_graph', {
|
|
127
|
+
tenantId: text('tenant_id').notNull(),
|
|
128
|
+
projectId: text('project_id').notNull(),
|
|
129
|
+
id: text('id').notNull(),
|
|
130
|
+
name: text('name').notNull(),
|
|
131
|
+
description: text('description'),
|
|
132
|
+
defaultAgentId: text('default_agent_id').notNull(),
|
|
133
|
+
// Reference to shared context configuration for all agents in this graph
|
|
134
|
+
contextConfigId: text('context_config_id'),
|
|
135
|
+
// Graph-level model settingsuration that can be inherited by agents
|
|
136
|
+
models: text('models', { mode: 'json' }).$type(),
|
|
137
|
+
// Status updates configuration for intelligent progress summaries
|
|
138
|
+
statusUpdates: text('status_updates', { mode: 'json' }).$type(),
|
|
139
|
+
// Graph-level prompt that can be used as additional context for agents
|
|
140
|
+
graphPrompt: text('graph_prompt'),
|
|
141
|
+
// Graph-level stopWhen configuration that can be inherited by agents
|
|
142
|
+
stopWhen: text('stop_when', { mode: 'json' }).$type(),
|
|
143
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
144
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
145
|
+
}, (table) => [
|
|
146
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
147
|
+
foreignKey({
|
|
148
|
+
columns: [table.tenantId, table.projectId],
|
|
149
|
+
foreignColumns: [projects.tenantId, projects.id],
|
|
150
|
+
name: 'agent_graph_project_fk',
|
|
151
|
+
}),
|
|
152
|
+
]);
|
|
153
|
+
export const tasks = sqliteTable('tasks', {
|
|
154
|
+
tenantId: text('tenant_id').notNull(),
|
|
155
|
+
projectId: text('project_id').notNull(),
|
|
156
|
+
id: text('id').notNull(),
|
|
157
|
+
contextId: text('context_id').notNull(),
|
|
158
|
+
status: text('status').notNull(),
|
|
159
|
+
metadata: blob('metadata', { mode: 'json' }).$type(),
|
|
160
|
+
agentId: text('agent_id').notNull(),
|
|
161
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
162
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
163
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
164
|
+
// Define the task relations table for parent-child relationships
|
|
165
|
+
export const taskRelations = sqliteTable('task_relations', {
|
|
166
|
+
tenantId: text('tenant_id').notNull(),
|
|
167
|
+
projectId: text('project_id').notNull(),
|
|
168
|
+
id: text('id').notNull(),
|
|
169
|
+
parentTaskId: text('parent_task_id').notNull(),
|
|
170
|
+
childTaskId: text('child_task_id').notNull(),
|
|
171
|
+
relationType: text('relation_type').default('parent_child'), // Could be extended for other relation types
|
|
172
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
173
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
174
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
175
|
+
export const dataComponents = sqliteTable('data_components', {
|
|
176
|
+
tenantId: text('tenant_id').notNull(),
|
|
177
|
+
projectId: text('project_id').notNull(),
|
|
178
|
+
id: text('id').notNull(),
|
|
179
|
+
name: text('name').notNull(),
|
|
180
|
+
description: text('description').notNull(),
|
|
181
|
+
props: blob('props', { mode: 'json' }).$type(),
|
|
182
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
183
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
184
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
185
|
+
// Junction table for agent-specific data component associations
|
|
186
|
+
export const agentDataComponents = sqliteTable('agent_data_components', {
|
|
187
|
+
tenantId: text('tenant_id').notNull(),
|
|
188
|
+
projectId: text('project_id').notNull(),
|
|
189
|
+
id: text('id').notNull(),
|
|
190
|
+
agentId: text('agent_id').notNull(),
|
|
191
|
+
dataComponentId: text('data_component_id').notNull(),
|
|
192
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
193
|
+
}, (table) => [
|
|
194
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
195
|
+
// Foreign key constraint to agents table
|
|
196
|
+
foreignKey({
|
|
197
|
+
columns: [table.tenantId, table.projectId, table.agentId],
|
|
198
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
199
|
+
name: 'agent_data_components_agent_fk',
|
|
200
|
+
}).onDelete('cascade'),
|
|
201
|
+
// Foreign key constraint to data_components table
|
|
202
|
+
foreignKey({
|
|
203
|
+
columns: [table.tenantId, table.projectId, table.dataComponentId],
|
|
204
|
+
foreignColumns: [dataComponents.tenantId, dataComponents.projectId, dataComponents.id],
|
|
205
|
+
name: 'agent_data_components_data_component_fk',
|
|
206
|
+
}).onDelete('cascade'),
|
|
207
|
+
]);
|
|
208
|
+
export const artifactComponents = sqliteTable('artifact_components', {
|
|
209
|
+
tenantId: text('tenant_id').notNull(),
|
|
210
|
+
projectId: text('project_id').notNull(),
|
|
211
|
+
id: text('id').notNull(),
|
|
212
|
+
name: text('name').notNull(),
|
|
213
|
+
description: text('description').notNull(),
|
|
214
|
+
summaryProps: blob('summary_props', { mode: 'json' }).$type(),
|
|
215
|
+
fullProps: blob('full_props', { mode: 'json' }).$type(),
|
|
216
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
217
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
218
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
219
|
+
// Junction table for agent-specific artifact component associations
|
|
220
|
+
export const agentArtifactComponents = sqliteTable('agent_artifact_components', {
|
|
221
|
+
tenantId: text('tenant_id').notNull(),
|
|
222
|
+
projectId: text('project_id').notNull(),
|
|
223
|
+
id: text('id').notNull(),
|
|
224
|
+
agentId: text('agent_id').notNull(),
|
|
225
|
+
artifactComponentId: text('artifact_component_id').notNull(),
|
|
226
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
227
|
+
}, (table) => [
|
|
228
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
229
|
+
// Foreign key constraint to agents table
|
|
230
|
+
foreignKey({
|
|
231
|
+
columns: [table.tenantId, table.projectId, table.agentId],
|
|
232
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
233
|
+
name: 'agent_artifact_components_agent_fk',
|
|
234
|
+
}).onDelete('cascade'),
|
|
235
|
+
// Foreign key constraint to artifact_components table
|
|
236
|
+
foreignKey({
|
|
237
|
+
columns: [table.tenantId, table.projectId, table.artifactComponentId],
|
|
238
|
+
foreignColumns: [
|
|
239
|
+
artifactComponents.tenantId,
|
|
240
|
+
artifactComponents.projectId,
|
|
241
|
+
artifactComponents.id,
|
|
242
|
+
],
|
|
243
|
+
name: 'agent_artifact_components_artifact_component_fk',
|
|
244
|
+
}).onDelete('cascade'),
|
|
245
|
+
]);
|
|
246
|
+
export const tools = sqliteTable('tools', {
|
|
247
|
+
tenantId: text('tenant_id').notNull(),
|
|
248
|
+
projectId: text('project_id').notNull(),
|
|
249
|
+
id: text('id').notNull(),
|
|
250
|
+
name: text('name').notNull(),
|
|
251
|
+
// Enhanced MCP configuration
|
|
252
|
+
config: blob('config', { mode: 'json' })
|
|
253
|
+
.$type()
|
|
254
|
+
.notNull(),
|
|
255
|
+
credentialReferenceId: text('credential_reference_id'),
|
|
256
|
+
headers: blob('headers', { mode: 'json' }).$type(),
|
|
257
|
+
// Image URL for custom tool icon (supports regular URLs and base64 encoded images)
|
|
258
|
+
imageUrl: text('image_url'),
|
|
259
|
+
// Server capabilities and status
|
|
260
|
+
capabilities: blob('capabilities', { mode: 'json' }).$type(),
|
|
261
|
+
// Connection health and monitoring
|
|
262
|
+
status: text('status').notNull().default('unknown'),
|
|
263
|
+
lastHealthCheck: text('last_health_check'),
|
|
264
|
+
lastError: text('last_error'),
|
|
265
|
+
// Tool discovery cache
|
|
266
|
+
availableTools: blob('available_tools', { mode: 'json' }).$type(),
|
|
267
|
+
lastToolsSync: text('last_tools_sync'),
|
|
268
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
269
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
270
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
271
|
+
export const agentToolRelations = sqliteTable('agent_tool_relations', {
|
|
272
|
+
tenantId: text('tenant_id').notNull(),
|
|
273
|
+
projectId: text('project_id').notNull(),
|
|
274
|
+
id: text('id').notNull(),
|
|
275
|
+
agentId: text('agent_id').notNull(),
|
|
276
|
+
toolId: text('tool_id').notNull(),
|
|
277
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
278
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
279
|
+
}, (table) => [
|
|
280
|
+
primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
|
|
281
|
+
// Foreign key constraint to agents table
|
|
282
|
+
foreignKey({
|
|
283
|
+
columns: [table.tenantId, table.projectId, table.agentId],
|
|
284
|
+
foreignColumns: [agents.tenantId, agents.projectId, agents.id],
|
|
285
|
+
name: 'agent_tool_relations_agent_fk',
|
|
286
|
+
}).onDelete('cascade'),
|
|
287
|
+
// Foreign key constraint to tools table
|
|
288
|
+
foreignKey({
|
|
289
|
+
columns: [table.tenantId, table.projectId, table.toolId],
|
|
290
|
+
foreignColumns: [tools.tenantId, tools.projectId, tools.id],
|
|
291
|
+
name: 'agent_tool_relations_tool_fk',
|
|
292
|
+
}).onDelete('cascade'),
|
|
293
|
+
]);
|
|
294
|
+
// Define conversations table to track user sessions
|
|
295
|
+
export const conversations = sqliteTable('conversations', {
|
|
296
|
+
tenantId: text('tenant_id').notNull(),
|
|
297
|
+
projectId: text('project_id').notNull(),
|
|
298
|
+
id: text('id').notNull(),
|
|
299
|
+
userId: text('user_id'),
|
|
300
|
+
activeAgentId: text('active_agent_id').notNull(),
|
|
301
|
+
title: text('title'),
|
|
302
|
+
lastContextResolution: text('last_context_resolution'),
|
|
303
|
+
metadata: blob('metadata', { mode: 'json' }).$type(),
|
|
304
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
305
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
306
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
307
|
+
// Define the unified message model supporting both A2A and OpenAI Chat Completions
|
|
308
|
+
export const messages = sqliteTable('messages', {
|
|
309
|
+
tenantId: text('tenant_id').notNull(),
|
|
310
|
+
projectId: text('project_id').notNull(),
|
|
311
|
+
id: text('id').notNull(),
|
|
312
|
+
conversationId: text('conversation_id').notNull(),
|
|
313
|
+
// Role mapping: user, agent, system (unified for both formats)
|
|
314
|
+
role: text('role').notNull(), // 'user' | 'agent' | 'system'
|
|
315
|
+
// Agent sender/recipient tracking (nullable - only populated when relevant)
|
|
316
|
+
fromAgentId: text('from_agent_id'), // Populated when message is from an agent
|
|
317
|
+
toAgentId: text('to_agent_id'), // Populated when message is directed to a specific agent (e.g., handoffs/delegations)
|
|
318
|
+
// External agent sender tracking
|
|
319
|
+
fromExternalAgentId: text('from_external_agent_id'), // Populated when message is directed from an external agent
|
|
320
|
+
// External agent recipient tracking
|
|
321
|
+
toExternalAgentId: text('to_external_agent_id'), // Populated when message is directed to an external agent
|
|
322
|
+
// Message content stored as JSON to support both formats
|
|
323
|
+
content: blob('content', { mode: 'json' }).$type().notNull(),
|
|
324
|
+
// Message classification and filtering
|
|
325
|
+
visibility: text('visibility').notNull().default('user-facing'), // 'user-facing' | 'internal' | 'system' | 'external'
|
|
326
|
+
messageType: text('message_type').notNull().default('chat'), // 'chat' | 'a2a-request' | 'a2a-response' | 'task-update' | 'tool-call'
|
|
327
|
+
// Legacy agent association (consider deprecating in favor of fromAgentId/toAgentId)
|
|
328
|
+
agentId: text('agent_id'),
|
|
329
|
+
taskId: text('task_id'),
|
|
330
|
+
parentMessageId: text('parent_message_id'), // Remove self-reference constraint here
|
|
331
|
+
// A2A specific fields
|
|
332
|
+
a2aTaskId: text('a2a_task_id'), // Links to A2A task when relevant
|
|
333
|
+
a2aSessionId: text('a2a_session_id'), // A2A session identifier
|
|
334
|
+
// Metadata for extensions
|
|
335
|
+
metadata: blob('metadata', { mode: 'json' }).$type(),
|
|
336
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
337
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
338
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
339
|
+
// === Ledger tables (artifacts only) ===
|
|
340
|
+
export const ledgerArtifacts = sqliteTable('ledger_artifacts', {
|
|
341
|
+
// Primary identifier (maps to `artifactId`)
|
|
342
|
+
tenantId: text('tenant_id').notNull(),
|
|
343
|
+
projectId: text('project_id').notNull(),
|
|
344
|
+
id: text('id').notNull(),
|
|
345
|
+
// Links
|
|
346
|
+
taskId: text('task_id'),
|
|
347
|
+
contextId: text('context_id').notNull(),
|
|
348
|
+
// Core Artifact fields
|
|
349
|
+
type: text('type').notNull().default('source'),
|
|
350
|
+
name: text('name'),
|
|
351
|
+
description: text('description'),
|
|
352
|
+
parts: blob('parts', { mode: 'json' }).$type(),
|
|
353
|
+
metadata: blob('metadata', { mode: 'json' }).$type(),
|
|
354
|
+
// Extra ledger information (not part of the Artifact spec – kept optional)
|
|
355
|
+
summary: text('summary'),
|
|
356
|
+
mime: blob('mime', { mode: 'json' }).$type(),
|
|
357
|
+
visibility: text('visibility').default('context'),
|
|
358
|
+
allowedAgents: blob('allowed_agents', { mode: 'json' }).$type(),
|
|
359
|
+
derivedFrom: text('derived_from'),
|
|
360
|
+
// Timestamps
|
|
361
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
362
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
363
|
+
}, (table) => [primaryKey({ columns: [table.tenantId, table.projectId, table.id] })]);
|
|
364
|
+
// API Keys table for secure API authentication
|
|
365
|
+
export const apiKeys = sqliteTable('api_keys', {
|
|
366
|
+
id: text('id').primaryKey(),
|
|
367
|
+
tenantId: text('tenant_id').notNull(),
|
|
368
|
+
projectId: text('project_id').notNull(),
|
|
369
|
+
graphId: text('graph_id').notNull(),
|
|
370
|
+
publicId: text('public_id').notNull().unique(), // Public ID for O(1) lookup (e.g., "abc123def456")
|
|
371
|
+
keyHash: text('key_hash').notNull(), // Hashed API key (never store plaintext)
|
|
372
|
+
keyPrefix: text('key_prefix').notNull(), // First 8 chars for identification (e.g., "sk_live_abc...")
|
|
373
|
+
lastUsedAt: text('last_used_at'),
|
|
374
|
+
expiresAt: text('expires_at'),
|
|
375
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
376
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
377
|
+
}, (t) => [
|
|
378
|
+
foreignKey({
|
|
379
|
+
columns: [t.tenantId, t.projectId, t.graphId],
|
|
380
|
+
foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
|
|
381
|
+
name: 'api_keys_graph_fk',
|
|
382
|
+
}).onDelete('cascade'),
|
|
383
|
+
index('api_keys_tenant_graph_idx').on(t.tenantId, t.graphId),
|
|
384
|
+
index('api_keys_prefix_idx').on(t.keyPrefix),
|
|
385
|
+
index('api_keys_public_id_idx').on(t.publicId),
|
|
386
|
+
]);
|
|
387
|
+
// Credential references for CredentialStore implementations
|
|
388
|
+
export const credentialReferences = sqliteTable('credential_references', {
|
|
389
|
+
tenantId: text('tenant_id').notNull(),
|
|
390
|
+
projectId: text('project_id').notNull(),
|
|
391
|
+
id: text('id').notNull(),
|
|
392
|
+
type: text('type').notNull(), // Implementation type: 'vault', 'nango', 'inmemory', etc.
|
|
393
|
+
credentialStoreId: text('credential_store_id').notNull(), // Maps to framework.getCredentialStore(id)
|
|
394
|
+
retrievalParams: blob('retrieval_params', { mode: 'json' }).$type(),
|
|
395
|
+
createdAt: text('created_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
396
|
+
updatedAt: text('updated_at').notNull().default(sql `CURRENT_TIMESTAMP`),
|
|
397
|
+
}, (t) => [primaryKey({ columns: [t.tenantId, t.projectId, t.id] })]);
|
|
398
|
+
// Indexes & Constraints for ledger artifacts
|
|
399
|
+
export const ledgerArtifactsTaskIdIdx = index('ledger_artifacts_task_id_idx').on(ledgerArtifacts.taskId);
|
|
400
|
+
export const ledgerArtifactsContextIdIdx = index('ledger_artifacts_context_id_idx').on(ledgerArtifacts.contextId);
|
|
401
|
+
export const ledgerArtifactsTaskContextNameUnique = unique('ledger_artifacts_task_context_name_unique').on(ledgerArtifacts.taskId, ledgerArtifacts.contextId, ledgerArtifacts.name);
|
|
402
|
+
// Relations definitions
|
|
403
|
+
export const tasksRelations = relations(tasks, ({ one, many }) => ({
|
|
404
|
+
// A task belongs to one project
|
|
405
|
+
project: one(projects, {
|
|
406
|
+
fields: [tasks.tenantId, tasks.projectId],
|
|
407
|
+
references: [projects.tenantId, projects.id],
|
|
408
|
+
}),
|
|
409
|
+
// A task can have many parent relationships (where it's the child)
|
|
410
|
+
parentRelations: many(taskRelations, {
|
|
411
|
+
relationName: 'childTask',
|
|
412
|
+
}),
|
|
413
|
+
// A task can have many child relationships (where it's the parent)
|
|
414
|
+
childRelations: many(taskRelations, {
|
|
415
|
+
relationName: 'parentTask',
|
|
416
|
+
}),
|
|
417
|
+
// A task belongs to one agent
|
|
418
|
+
agent: one(agents, {
|
|
419
|
+
fields: [tasks.agentId],
|
|
420
|
+
references: [agents.id],
|
|
421
|
+
}),
|
|
422
|
+
// A task can have many messages associated with it
|
|
423
|
+
messages: many(messages),
|
|
424
|
+
}));
|
|
425
|
+
// Define relations for projects
|
|
426
|
+
export const projectsRelations = relations(projects, ({ many }) => ({
|
|
427
|
+
// A project can have many agents
|
|
428
|
+
agents: many(agents),
|
|
429
|
+
// A project can have many agent graphs
|
|
430
|
+
agentGraphs: many(agentGraph),
|
|
431
|
+
// A project can have many tools
|
|
432
|
+
tools: many(tools),
|
|
433
|
+
// A project can have many context configs
|
|
434
|
+
contextConfigs: many(contextConfigs),
|
|
435
|
+
// A project can have many external agents
|
|
436
|
+
externalAgents: many(externalAgents),
|
|
437
|
+
// A project can have many conversations
|
|
438
|
+
conversations: many(conversations),
|
|
439
|
+
// A project can have many tasks
|
|
440
|
+
tasks: many(tasks),
|
|
441
|
+
}));
|
|
442
|
+
// Define relations for taskRelations junction table
|
|
443
|
+
export const taskRelationsRelations = relations(taskRelations, ({ one }) => ({
|
|
444
|
+
// Each relation has one parent task
|
|
445
|
+
parentTask: one(tasks, {
|
|
446
|
+
fields: [taskRelations.parentTaskId],
|
|
447
|
+
references: [tasks.id],
|
|
448
|
+
relationName: 'parentTask',
|
|
449
|
+
}),
|
|
450
|
+
// Each relation has one child task
|
|
451
|
+
childTask: one(tasks, {
|
|
452
|
+
fields: [taskRelations.childTaskId],
|
|
453
|
+
references: [tasks.id],
|
|
454
|
+
relationName: 'childTask',
|
|
455
|
+
}),
|
|
456
|
+
}));
|
|
457
|
+
// Define relations for context system
|
|
458
|
+
export const contextConfigsRelations = relations(contextConfigs, ({ many, one }) => ({
|
|
459
|
+
// A context config belongs to one project
|
|
460
|
+
project: one(projects, {
|
|
461
|
+
fields: [contextConfigs.tenantId, contextConfigs.projectId],
|
|
462
|
+
references: [projects.tenantId, projects.id],
|
|
463
|
+
}),
|
|
464
|
+
// A context config can be used by many agent graphs
|
|
465
|
+
graphs: many(agentGraph),
|
|
466
|
+
// A context config can have many cached entries
|
|
467
|
+
cache: many(contextCache),
|
|
468
|
+
}));
|
|
469
|
+
export const contextCacheRelations = relations(contextCache, ({ one }) => ({
|
|
470
|
+
// Each cache entry belongs to one context config
|
|
471
|
+
contextConfig: one(contextConfigs, {
|
|
472
|
+
fields: [contextCache.contextConfigId],
|
|
473
|
+
references: [contextConfigs.id],
|
|
474
|
+
}),
|
|
475
|
+
}));
|
|
476
|
+
// Define relations for agents
|
|
477
|
+
export const agentsRelations = relations(agents, ({ many, one }) => ({
|
|
478
|
+
// A context config belongs to one project
|
|
479
|
+
project: one(projects, {
|
|
480
|
+
fields: [agents.tenantId, agents.projectId],
|
|
481
|
+
references: [projects.tenantId, projects.id],
|
|
482
|
+
}),
|
|
483
|
+
// An agent can have many tasks
|
|
484
|
+
tasks: many(tasks),
|
|
485
|
+
// An agent can be the default agent for many graphs
|
|
486
|
+
defaultForGraphs: many(agentGraph),
|
|
487
|
+
// Agent relation tracking
|
|
488
|
+
sourceRelations: many(agentRelations, {
|
|
489
|
+
relationName: 'sourceRelations',
|
|
490
|
+
}),
|
|
491
|
+
targetRelations: many(agentRelations, {
|
|
492
|
+
relationName: 'targetRelations',
|
|
493
|
+
}),
|
|
494
|
+
// Message tracking relations
|
|
495
|
+
sentMessages: many(messages, {
|
|
496
|
+
relationName: 'sentMessages',
|
|
497
|
+
}),
|
|
498
|
+
receivedMessages: many(messages, {
|
|
499
|
+
relationName: 'receivedMessages',
|
|
500
|
+
}),
|
|
501
|
+
// Legacy message association (consider deprecating)
|
|
502
|
+
associatedMessages: many(messages, {
|
|
503
|
+
relationName: 'associatedAgent',
|
|
504
|
+
}),
|
|
505
|
+
toolRelations: many(agentToolRelations),
|
|
506
|
+
}));
|
|
507
|
+
// Define relations for agent graphs (updated to include context config)
|
|
508
|
+
export const agentGraphRelations = relations(agentGraph, ({ one }) => ({
|
|
509
|
+
// An agent graph belongs to one project
|
|
510
|
+
project: one(projects, {
|
|
511
|
+
fields: [agentGraph.tenantId, agentGraph.projectId],
|
|
512
|
+
references: [projects.tenantId, projects.id],
|
|
513
|
+
}),
|
|
514
|
+
// An agent graph belongs to one default agent
|
|
515
|
+
defaultAgent: one(agents, {
|
|
516
|
+
fields: [agentGraph.defaultAgentId],
|
|
517
|
+
references: [agents.id],
|
|
518
|
+
}),
|
|
519
|
+
// An agent graph can reference one context config
|
|
520
|
+
contextConfig: one(contextConfigs, {
|
|
521
|
+
fields: [agentGraph.contextConfigId],
|
|
522
|
+
references: [contextConfigs.id],
|
|
523
|
+
}),
|
|
524
|
+
}));
|
|
525
|
+
// Define relations for external agents
|
|
526
|
+
export const externalAgentsRelations = relations(externalAgents, ({ one, many }) => ({
|
|
527
|
+
// An external agent belongs to one project
|
|
528
|
+
project: one(projects, {
|
|
529
|
+
fields: [externalAgents.tenantId, externalAgents.projectId],
|
|
530
|
+
references: [projects.tenantId, projects.id],
|
|
531
|
+
}),
|
|
532
|
+
// An external agent can be referenced by many agent relations
|
|
533
|
+
agentRelations: many(agentRelations),
|
|
534
|
+
// An external agent may have one credential reference
|
|
535
|
+
credentialReference: one(credentialReferences, {
|
|
536
|
+
fields: [externalAgents.credentialReferenceId],
|
|
537
|
+
references: [credentialReferences.id],
|
|
538
|
+
}),
|
|
539
|
+
}));
|
|
540
|
+
// Define relations for API keys
|
|
541
|
+
export const apiKeysRelations = relations(apiKeys, ({ one }) => ({
|
|
542
|
+
// An API key belongs to one project
|
|
543
|
+
project: one(projects, {
|
|
544
|
+
fields: [apiKeys.tenantId, apiKeys.projectId],
|
|
545
|
+
references: [projects.tenantId, projects.id],
|
|
546
|
+
}),
|
|
547
|
+
// An API key belongs to one tenant and graph
|
|
548
|
+
graph: one(agentGraph, {
|
|
549
|
+
fields: [apiKeys.graphId],
|
|
550
|
+
references: [agentGraph.id],
|
|
551
|
+
}),
|
|
552
|
+
}));
|
|
553
|
+
// Define relations for agent tool relations
|
|
554
|
+
export const agentToolRelationsRelations = relations(agentToolRelations, ({ one }) => ({
|
|
555
|
+
// An agent-tool relation belongs to one agent
|
|
556
|
+
agent: one(agents, {
|
|
557
|
+
fields: [agentToolRelations.agentId],
|
|
558
|
+
references: [agents.id],
|
|
559
|
+
}),
|
|
560
|
+
// An agent-tool relation belongs to one tool
|
|
561
|
+
tool: one(tools, {
|
|
562
|
+
fields: [agentToolRelations.toolId],
|
|
563
|
+
references: [tools.id],
|
|
564
|
+
}),
|
|
565
|
+
}));
|
|
566
|
+
// Define relations for credential references
|
|
567
|
+
export const credentialReferencesRelations = relations(credentialReferences, ({ many }) => ({
|
|
568
|
+
tools: many(tools),
|
|
569
|
+
}));
|
|
570
|
+
// Define relations for tools
|
|
571
|
+
export const toolsRelations = relations(tools, ({ one, many }) => ({
|
|
572
|
+
// A tool belongs to one project
|
|
573
|
+
project: one(projects, {
|
|
574
|
+
fields: [tools.tenantId, tools.projectId],
|
|
575
|
+
references: [projects.tenantId, projects.id],
|
|
576
|
+
}),
|
|
577
|
+
// A tool can be used by many agents through agent-tool relations
|
|
578
|
+
agentRelations: many(agentToolRelations),
|
|
579
|
+
// A tool may have one credential reference
|
|
580
|
+
credentialReference: one(credentialReferences, {
|
|
581
|
+
fields: [tools.credentialReferenceId],
|
|
582
|
+
references: [credentialReferences.id],
|
|
583
|
+
}),
|
|
584
|
+
}));
|
|
585
|
+
// Define relations for conversations
|
|
586
|
+
export const conversationsRelations = relations(conversations, ({ one, many }) => ({
|
|
587
|
+
// A conversation belongs to one project
|
|
588
|
+
project: one(projects, {
|
|
589
|
+
fields: [conversations.tenantId, conversations.projectId],
|
|
590
|
+
references: [projects.tenantId, projects.id],
|
|
591
|
+
}),
|
|
592
|
+
// A conversation has many messages
|
|
593
|
+
messages: many(messages),
|
|
594
|
+
// A conversation has one active agent
|
|
595
|
+
activeAgent: one(agents, {
|
|
596
|
+
fields: [conversations.activeAgentId],
|
|
597
|
+
references: [agents.id],
|
|
598
|
+
}),
|
|
599
|
+
}));
|
|
600
|
+
// Define relations for messages
|
|
601
|
+
export const messagesRelations = relations(messages, ({ one, many }) => ({
|
|
602
|
+
// A message belongs to one conversation
|
|
603
|
+
conversation: one(conversations, {
|
|
604
|
+
fields: [messages.conversationId],
|
|
605
|
+
references: [conversations.id],
|
|
606
|
+
}),
|
|
607
|
+
// Legacy agent association (consider deprecating)
|
|
608
|
+
agent: one(agents, {
|
|
609
|
+
fields: [messages.agentId],
|
|
610
|
+
references: [agents.id],
|
|
611
|
+
relationName: 'associatedAgent',
|
|
612
|
+
}),
|
|
613
|
+
// Sender tracking relations
|
|
614
|
+
fromAgent: one(agents, {
|
|
615
|
+
fields: [messages.fromAgentId],
|
|
616
|
+
references: [agents.id],
|
|
617
|
+
relationName: 'sentMessages',
|
|
618
|
+
}),
|
|
619
|
+
// Recipient tracking relations
|
|
620
|
+
toAgent: one(agents, {
|
|
621
|
+
fields: [messages.toAgentId],
|
|
622
|
+
references: [agents.id],
|
|
623
|
+
relationName: 'receivedMessages',
|
|
624
|
+
}),
|
|
625
|
+
// External agent sender tracking relations
|
|
626
|
+
fromExternalAgent: one(externalAgents, {
|
|
627
|
+
fields: [messages.fromExternalAgentId],
|
|
628
|
+
references: [externalAgents.id],
|
|
629
|
+
relationName: 'receivedExternalMessages',
|
|
630
|
+
}),
|
|
631
|
+
// External agent recipient tracking relations
|
|
632
|
+
toExternalAgent: one(externalAgents, {
|
|
633
|
+
fields: [messages.toExternalAgentId],
|
|
634
|
+
references: [externalAgents.id],
|
|
635
|
+
relationName: 'sentExternalMessages',
|
|
636
|
+
}),
|
|
637
|
+
// A message may be associated with a task
|
|
638
|
+
task: one(tasks, {
|
|
639
|
+
fields: [messages.taskId],
|
|
640
|
+
references: [tasks.id],
|
|
641
|
+
}),
|
|
642
|
+
// A message may have a parent message (for threading)
|
|
643
|
+
parentMessage: one(messages, {
|
|
644
|
+
fields: [messages.parentMessageId],
|
|
645
|
+
references: [messages.id],
|
|
646
|
+
relationName: 'parentChild',
|
|
647
|
+
}),
|
|
648
|
+
// A message may have child messages
|
|
649
|
+
childMessages: many(messages, {
|
|
650
|
+
relationName: 'parentChild',
|
|
651
|
+
}),
|
|
652
|
+
}));
|
|
653
|
+
// Define relations for artifact components
|
|
654
|
+
export const artifactComponentsRelations = relations(artifactComponents, ({ many }) => ({
|
|
655
|
+
// An artifact component can be associated with many agents
|
|
656
|
+
agentRelations: many(agentArtifactComponents),
|
|
657
|
+
}));
|
|
658
|
+
// Define relations for agent-artifact component associations
|
|
659
|
+
export const agentArtifactComponentsRelations = relations(agentArtifactComponents, ({ one }) => ({
|
|
660
|
+
// An agent-artifact component relation belongs to one agent
|
|
661
|
+
agent: one(agents, {
|
|
662
|
+
fields: [agentArtifactComponents.agentId],
|
|
663
|
+
references: [agents.id],
|
|
664
|
+
}),
|
|
665
|
+
// An agent-artifact component relation belongs to one artifact component
|
|
666
|
+
artifactComponent: one(artifactComponents, {
|
|
667
|
+
fields: [agentArtifactComponents.artifactComponentId],
|
|
668
|
+
references: [artifactComponents.id],
|
|
669
|
+
}),
|
|
670
|
+
}));
|
|
671
|
+
// Define relations for agent relations
|
|
672
|
+
export const agentRelationsRelations = relations(agentRelations, ({ one }) => ({
|
|
673
|
+
// An agent relation belongs to one graph
|
|
674
|
+
graph: one(agentGraph, {
|
|
675
|
+
fields: [agentRelations.graphId],
|
|
676
|
+
references: [agentGraph.id],
|
|
677
|
+
}),
|
|
678
|
+
// An agent relation has one source agent
|
|
679
|
+
sourceAgent: one(agents, {
|
|
680
|
+
fields: [agentRelations.sourceAgentId],
|
|
681
|
+
references: [agents.id],
|
|
682
|
+
relationName: 'sourceRelations',
|
|
683
|
+
}),
|
|
684
|
+
// An agent relation may have one target agent (for internal relations)
|
|
685
|
+
targetAgent: one(agents, {
|
|
686
|
+
fields: [agentRelations.targetAgentId],
|
|
687
|
+
references: [agents.id],
|
|
688
|
+
relationName: 'targetRelations',
|
|
689
|
+
}),
|
|
690
|
+
// An agent relation may have one external agent (for external relations)
|
|
691
|
+
externalAgent: one(externalAgents, {
|
|
692
|
+
fields: [agentRelations.externalAgentId],
|
|
693
|
+
references: [externalAgents.id],
|
|
694
|
+
}),
|
|
695
|
+
}));
|
|
696
|
+
//# sourceMappingURL=schema.js.map
|