@contractspec/example.agent-console 3.7.5 → 3.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +18 -18
- package/AGENTS.md +50 -31
- package/CHANGELOG.md +12 -0
- package/README.md +69 -77
- package/dist/agent/agent.event.js +1 -1
- package/dist/agent/agent.operation.js +1 -1
- package/dist/agent/index.d.ts +5 -5
- package/dist/agent/index.js +1 -1
- package/dist/browser/agent/agent.event.js +1 -1
- package/dist/browser/agent/agent.operation.js +1 -1
- package/dist/browser/agent/index.js +1 -1
- package/dist/browser/index.js +2145 -2145
- package/dist/browser/presentations/index.js +4 -4
- package/dist/browser/run/index.js +536 -536
- package/dist/browser/run/run.event.js +2 -2
- package/dist/browser/run/run.presentation.js +2 -2
- package/dist/browser/tool/index.js +260 -260
- package/dist/browser/tool/tool.event.js +1 -1
- package/dist/browser/tool/tool.presentation.js +2 -2
- package/dist/browser/ui/AgentDashboard.js +956 -956
- package/dist/browser/ui/AgentRunList.js +16 -16
- package/dist/browser/ui/AgentToolRegistry.js +9 -9
- package/dist/browser/ui/hooks/index.js +153 -153
- package/dist/browser/ui/hooks/useAgentList.js +1 -1
- package/dist/browser/ui/hooks/useAgentMutations.js +1 -1
- package/dist/browser/ui/hooks/useRunList.js +1 -1
- package/dist/browser/ui/hooks/useToolList.js +1 -1
- package/dist/browser/ui/index.js +1222 -1222
- package/dist/browser/ui/modals/AgentActionsModal.js +13 -13
- package/dist/browser/ui/modals/CreateAgentModal.js +15 -15
- package/dist/browser/ui/modals/index.js +297 -297
- package/dist/browser/ui/renderers/agent-list.renderer.js +7 -7
- package/dist/browser/ui/renderers/index.js +157 -157
- package/dist/browser/ui/views/AgentListView.js +7 -7
- package/dist/browser/ui/views/RunListView.js +16 -16
- package/dist/browser/ui/views/ToolRegistryView.js +9 -9
- package/dist/browser/ui/views/index.js +97 -97
- package/dist/handlers/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2145 -2145
- package/dist/node/agent/agent.event.js +1 -1
- package/dist/node/agent/agent.operation.js +1 -1
- package/dist/node/agent/index.js +1 -1
- package/dist/node/index.js +2145 -2145
- package/dist/node/presentations/index.js +4 -4
- package/dist/node/run/index.js +536 -536
- package/dist/node/run/run.event.js +2 -2
- package/dist/node/run/run.presentation.js +2 -2
- package/dist/node/tool/index.js +260 -260
- package/dist/node/tool/tool.event.js +1 -1
- package/dist/node/tool/tool.presentation.js +2 -2
- package/dist/node/ui/AgentDashboard.js +956 -956
- package/dist/node/ui/AgentRunList.js +16 -16
- package/dist/node/ui/AgentToolRegistry.js +9 -9
- package/dist/node/ui/hooks/index.js +153 -153
- package/dist/node/ui/hooks/useAgentList.js +1 -1
- package/dist/node/ui/hooks/useAgentMutations.js +1 -1
- package/dist/node/ui/hooks/useRunList.js +1 -1
- package/dist/node/ui/hooks/useToolList.js +1 -1
- package/dist/node/ui/index.js +1222 -1222
- package/dist/node/ui/modals/AgentActionsModal.js +13 -13
- package/dist/node/ui/modals/CreateAgentModal.js +15 -15
- package/dist/node/ui/modals/index.js +297 -297
- package/dist/node/ui/renderers/agent-list.renderer.js +7 -7
- package/dist/node/ui/renderers/index.js +157 -157
- package/dist/node/ui/views/AgentListView.js +7 -7
- package/dist/node/ui/views/RunListView.js +16 -16
- package/dist/node/ui/views/ToolRegistryView.js +9 -9
- package/dist/node/ui/views/index.js +97 -97
- package/dist/presentations/index.d.ts +3 -5
- package/dist/presentations/index.js +4 -4
- package/dist/run/index.d.ts +7 -7
- package/dist/run/index.js +536 -536
- package/dist/run/run.event.js +2 -2
- package/dist/run/run.handler.d.ts +3 -0
- package/dist/run/run.presentation.js +2 -2
- package/dist/shared/index.d.ts +1 -1
- package/dist/tool/index.d.ts +7 -7
- package/dist/tool/index.js +260 -260
- package/dist/tool/tool.event.js +1 -1
- package/dist/tool/tool.handler.d.ts +1 -1
- package/dist/tool/tool.presentation.js +2 -2
- package/dist/ui/AgentDashboard.js +956 -956
- package/dist/ui/AgentRunList.js +16 -16
- package/dist/ui/AgentToolRegistry.js +9 -9
- package/dist/ui/hooks/index.d.ts +4 -4
- package/dist/ui/hooks/index.js +153 -153
- package/dist/ui/hooks/useAgentList.d.ts +5 -0
- package/dist/ui/hooks/useAgentList.js +1 -1
- package/dist/ui/hooks/useAgentMutations.d.ts +9 -2
- package/dist/ui/hooks/useAgentMutations.js +1 -1
- package/dist/ui/hooks/useRunList.d.ts +5 -0
- package/dist/ui/hooks/useRunList.js +1 -1
- package/dist/ui/hooks/useToolList.d.ts +5 -0
- package/dist/ui/hooks/useToolList.js +1 -1
- package/dist/ui/index.d.ts +3 -3
- package/dist/ui/index.js +1222 -1222
- package/dist/ui/modals/AgentActionsModal.js +13 -13
- package/dist/ui/modals/CreateAgentModal.js +15 -15
- package/dist/ui/modals/index.d.ts +1 -1
- package/dist/ui/modals/index.js +297 -297
- package/dist/ui/renderers/agent-list.markdown.d.ts +5 -0
- package/dist/ui/renderers/agent-list.renderer.js +7 -7
- package/dist/ui/renderers/dashboard.markdown.d.ts +5 -0
- package/dist/ui/renderers/index.d.ts +2 -2
- package/dist/ui/renderers/index.js +157 -157
- package/dist/ui/renderers/run-list.markdown.d.ts +5 -0
- package/dist/ui/renderers/tool-registry.markdown.d.ts +5 -0
- package/dist/ui/views/AgentListView.js +7 -7
- package/dist/ui/views/RunListView.js +16 -16
- package/dist/ui/views/ToolRegistryView.js +9 -9
- package/dist/ui/views/index.js +97 -97
- package/package.json +10 -10
- package/src/agent/agent.entity.ts +111 -111
- package/src/agent/agent.enum.ts +12 -12
- package/src/agent/agent.event.ts +91 -91
- package/src/agent/agent.handler.ts +123 -123
- package/src/agent/agent.operation.ts +400 -400
- package/src/agent/agent.presentation.ts +62 -62
- package/src/agent/agent.schema.ts +175 -175
- package/src/agent/agent.test-spec.ts +48 -48
- package/src/agent/index.ts +46 -51
- package/src/agent.capability.ts +11 -11
- package/src/agent.feature.ts +131 -131
- package/src/docs/agent-console.docblock.ts +42 -42
- package/src/example.ts +35 -35
- package/src/handlers/agent.handlers.ts +522 -521
- package/src/handlers/index.ts +12 -12
- package/src/index.ts +8 -9
- package/src/presentations/index.ts +11 -13
- package/src/run/index.ts +49 -54
- package/src/run/run.entity.ts +137 -137
- package/src/run/run.enum.ts +18 -18
- package/src/run/run.event.ts +174 -174
- package/src/run/run.handler.ts +92 -91
- package/src/run/run.operation.ts +474 -474
- package/src/run/run.presentation.ts +42 -42
- package/src/run/run.schema.ts +126 -126
- package/src/run/run.test-spec.ts +48 -48
- package/src/seeders/index.ts +21 -21
- package/src/shared/index.ts +1 -1
- package/src/shared/mock-agents.ts +76 -76
- package/src/shared/mock-runs.ts +102 -102
- package/src/shared/mock-tools.ts +140 -140
- package/src/shared/overlay-types.ts +23 -23
- package/src/tool/index.ts +39 -44
- package/src/tool/tool.entity.ts +73 -73
- package/src/tool/tool.enum.ts +13 -13
- package/src/tool/tool.event.ts +80 -80
- package/src/tool/tool.handler.ts +102 -102
- package/src/tool/tool.operation.ts +328 -328
- package/src/tool/tool.presentation.ts +43 -43
- package/src/tool/tool.schema.ts +106 -106
- package/src/tool/tool.test-spec.ts +48 -48
- package/src/ui/AgentDashboard.tsx +348 -348
- package/src/ui/hooks/index.ts +7 -7
- package/src/ui/hooks/useAgentList.ts +57 -56
- package/src/ui/hooks/useAgentMutations.ts +160 -159
- package/src/ui/hooks/useRunList.ts +58 -57
- package/src/ui/hooks/useToolList.ts +102 -101
- package/src/ui/index.ts +6 -9
- package/src/ui/modals/AgentActionsModal.tsx +262 -262
- package/src/ui/modals/CreateAgentModal.tsx +232 -232
- package/src/ui/modals/index.ts +1 -1
- package/src/ui/overlays/demo-overlays.ts +52 -52
- package/src/ui/renderers/agent-list.markdown.ts +61 -60
- package/src/ui/renderers/agent-list.renderer.tsx +14 -14
- package/src/ui/renderers/dashboard.markdown.ts +140 -139
- package/src/ui/renderers/index.ts +3 -4
- package/src/ui/renderers/run-list.markdown.ts +48 -47
- package/src/ui/renderers/tool-registry.markdown.ts +66 -65
- package/src/ui/views/AgentListView.tsx +90 -90
- package/src/ui/views/RunListView.tsx +141 -141
- package/src/ui/views/ToolRegistryView.tsx +113 -113
- package/tsconfig.json +7 -8
- package/tsdown.config.js +7 -3
|
@@ -5,602 +5,603 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { DatabasePort } from '@contractspec/lib.runtime-sandbox';
|
|
7
7
|
import { web } from '@contractspec/lib.runtime-sandbox';
|
|
8
|
+
|
|
8
9
|
const { generateId } = web;
|
|
9
10
|
|
|
10
11
|
// ============ Types ============
|
|
11
12
|
|
|
12
13
|
export interface Agent {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
id: string;
|
|
15
|
+
projectId: string;
|
|
16
|
+
organizationId: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
modelProvider: string;
|
|
20
|
+
modelName: string;
|
|
21
|
+
systemPrompt?: string;
|
|
22
|
+
temperature: number;
|
|
23
|
+
maxTokens: number;
|
|
24
|
+
status: 'DRAFT' | 'ACTIVE' | 'PAUSED' | 'ARCHIVED';
|
|
25
|
+
createdAt: Date;
|
|
26
|
+
updatedAt: Date;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface Tool {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
id: string;
|
|
31
|
+
projectId: string;
|
|
32
|
+
organizationId: string;
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string;
|
|
35
|
+
version: string;
|
|
36
|
+
category:
|
|
37
|
+
| 'RETRIEVAL'
|
|
38
|
+
| 'COMPUTATION'
|
|
39
|
+
| 'COMMUNICATION'
|
|
40
|
+
| 'INTEGRATION'
|
|
41
|
+
| 'UTILITY'
|
|
42
|
+
| 'CUSTOM';
|
|
43
|
+
status: 'ACTIVE' | 'DISABLED' | 'DEPRECATED' | 'DRAFT';
|
|
44
|
+
inputSchema?: string;
|
|
45
|
+
outputSchema?: string;
|
|
46
|
+
endpoint?: string;
|
|
47
|
+
createdAt: Date;
|
|
48
|
+
updatedAt: Date;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export interface Run {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
id: string;
|
|
53
|
+
projectId: string;
|
|
54
|
+
agentId: string;
|
|
55
|
+
agentName?: string;
|
|
56
|
+
status: 'QUEUED' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED';
|
|
57
|
+
input?: string;
|
|
58
|
+
output?: string;
|
|
59
|
+
totalTokens: number;
|
|
60
|
+
promptTokens: number;
|
|
61
|
+
completionTokens: number;
|
|
62
|
+
estimatedCostUsd: number;
|
|
63
|
+
durationMs?: number;
|
|
64
|
+
errorMessage?: string;
|
|
65
|
+
queuedAt: Date;
|
|
66
|
+
startedAt?: Date;
|
|
67
|
+
completedAt?: Date;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export interface RunMetrics {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
totalRuns: number;
|
|
72
|
+
successRate: number;
|
|
73
|
+
averageDurationMs: number;
|
|
74
|
+
totalTokens: number;
|
|
75
|
+
totalCostUsd: number;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
export interface ListAgentsInput {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
projectId: string;
|
|
80
|
+
organizationId?: string;
|
|
81
|
+
status?: Agent['status'] | 'all';
|
|
82
|
+
search?: string;
|
|
83
|
+
limit?: number;
|
|
84
|
+
offset?: number;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
export interface ListAgentsOutput {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
items: Agent[];
|
|
89
|
+
total: number;
|
|
90
|
+
hasMore: boolean;
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
export interface ListToolsInput {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
projectId: string;
|
|
95
|
+
organizationId?: string;
|
|
96
|
+
category?: Tool['category'] | 'all';
|
|
97
|
+
status?: Tool['status'] | 'all';
|
|
98
|
+
search?: string;
|
|
99
|
+
limit?: number;
|
|
100
|
+
offset?: number;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
export interface ListToolsOutput {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
items: Tool[];
|
|
105
|
+
total: number;
|
|
106
|
+
hasMore: boolean;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
export interface ListRunsInput {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
projectId: string;
|
|
111
|
+
organizationId?: string;
|
|
112
|
+
agentId?: string;
|
|
113
|
+
status?: Run['status'] | 'all';
|
|
114
|
+
limit?: number;
|
|
115
|
+
offset?: number;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
export interface ListRunsOutput {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
items: Run[];
|
|
120
|
+
total: number;
|
|
121
|
+
hasMore: boolean;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
export interface CreateAgentInput {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
name: string;
|
|
126
|
+
description?: string;
|
|
127
|
+
modelProvider?: string;
|
|
128
|
+
modelName?: string;
|
|
129
|
+
systemPrompt?: string;
|
|
130
|
+
temperature?: number;
|
|
131
|
+
maxTokens?: number;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
export interface UpdateAgentInput {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
id: string;
|
|
136
|
+
name?: string;
|
|
137
|
+
description?: string;
|
|
138
|
+
status?: Agent['status'];
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
// ============ Row Types ============
|
|
141
142
|
|
|
142
143
|
interface AgentRow extends Record<string, unknown> {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
id: string;
|
|
145
|
+
projectId: string;
|
|
146
|
+
organizationId: string;
|
|
147
|
+
name: string;
|
|
148
|
+
description: string | null;
|
|
149
|
+
modelProvider: string;
|
|
150
|
+
modelName: string;
|
|
151
|
+
systemPrompt: string | null;
|
|
152
|
+
temperature: number;
|
|
153
|
+
maxTokens: number;
|
|
154
|
+
status: string;
|
|
155
|
+
createdAt: string;
|
|
156
|
+
updatedAt: string;
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
interface ToolRow extends Record<string, unknown> {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
160
|
+
id: string;
|
|
161
|
+
projectId: string;
|
|
162
|
+
organizationId: string;
|
|
163
|
+
name: string;
|
|
164
|
+
description: string | null;
|
|
165
|
+
version: string;
|
|
166
|
+
category: string;
|
|
167
|
+
status: string;
|
|
168
|
+
inputSchema: string | null;
|
|
169
|
+
outputSchema: string | null;
|
|
170
|
+
endpoint: string | null;
|
|
171
|
+
createdAt: string;
|
|
172
|
+
updatedAt: string;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
interface RunRow extends Record<string, unknown> {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
id: string;
|
|
177
|
+
projectId: string;
|
|
178
|
+
agentId: string;
|
|
179
|
+
status: string;
|
|
180
|
+
input: string | null;
|
|
181
|
+
output: string | null;
|
|
182
|
+
totalTokens: number;
|
|
183
|
+
promptTokens: number;
|
|
184
|
+
completionTokens: number;
|
|
185
|
+
estimatedCostUsd: number;
|
|
186
|
+
durationMs: number | null;
|
|
187
|
+
errorMessage: string | null;
|
|
188
|
+
queuedAt: string;
|
|
189
|
+
startedAt: string | null;
|
|
190
|
+
completedAt: string | null;
|
|
190
191
|
}
|
|
191
192
|
|
|
192
193
|
function rowToAgent(row: AgentRow): Agent {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
194
|
+
return {
|
|
195
|
+
id: row.id,
|
|
196
|
+
projectId: row.projectId,
|
|
197
|
+
organizationId: row.organizationId,
|
|
198
|
+
name: row.name,
|
|
199
|
+
description: row.description ?? undefined,
|
|
200
|
+
modelProvider: row.modelProvider,
|
|
201
|
+
modelName: row.modelName,
|
|
202
|
+
systemPrompt: row.systemPrompt ?? undefined,
|
|
203
|
+
temperature: row.temperature,
|
|
204
|
+
maxTokens: row.maxTokens,
|
|
205
|
+
status: row.status as Agent['status'],
|
|
206
|
+
createdAt: new Date(row.createdAt),
|
|
207
|
+
updatedAt: new Date(row.updatedAt),
|
|
208
|
+
};
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
function rowToTool(row: ToolRow): Tool {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
212
|
+
return {
|
|
213
|
+
id: row.id,
|
|
214
|
+
projectId: row.projectId,
|
|
215
|
+
organizationId: row.organizationId,
|
|
216
|
+
name: row.name,
|
|
217
|
+
description: row.description ?? undefined,
|
|
218
|
+
version: row.version,
|
|
219
|
+
category: row.category as Tool['category'],
|
|
220
|
+
status: row.status as Tool['status'],
|
|
221
|
+
inputSchema: row.inputSchema ?? undefined,
|
|
222
|
+
outputSchema: row.outputSchema ?? undefined,
|
|
223
|
+
endpoint: row.endpoint ?? undefined,
|
|
224
|
+
createdAt: new Date(row.createdAt),
|
|
225
|
+
updatedAt: new Date(row.updatedAt),
|
|
226
|
+
};
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
function rowToRun(row: RunRow, agentName?: string): Run {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
230
|
+
return {
|
|
231
|
+
id: row.id,
|
|
232
|
+
projectId: row.projectId,
|
|
233
|
+
agentId: row.agentId,
|
|
234
|
+
agentName,
|
|
235
|
+
status: row.status as Run['status'],
|
|
236
|
+
input: row.input ?? undefined,
|
|
237
|
+
output: row.output ?? undefined,
|
|
238
|
+
totalTokens: row.totalTokens,
|
|
239
|
+
promptTokens: row.promptTokens,
|
|
240
|
+
completionTokens: row.completionTokens,
|
|
241
|
+
estimatedCostUsd: row.estimatedCostUsd,
|
|
242
|
+
durationMs: row.durationMs ?? undefined,
|
|
243
|
+
errorMessage: row.errorMessage ?? undefined,
|
|
244
|
+
queuedAt: new Date(row.queuedAt),
|
|
245
|
+
startedAt: row.startedAt ? new Date(row.startedAt) : undefined,
|
|
246
|
+
completedAt: row.completedAt ? new Date(row.completedAt) : undefined,
|
|
247
|
+
};
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
// ============ Handler Factory ============
|
|
250
251
|
|
|
251
252
|
export function createAgentHandlers(db: DatabasePort) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
253
|
+
/**
|
|
254
|
+
* List agents
|
|
255
|
+
*/
|
|
256
|
+
async function listAgents(input: ListAgentsInput): Promise<ListAgentsOutput> {
|
|
257
|
+
const {
|
|
258
|
+
projectId,
|
|
259
|
+
organizationId,
|
|
260
|
+
status,
|
|
261
|
+
search,
|
|
262
|
+
limit = 20,
|
|
263
|
+
offset = 0,
|
|
264
|
+
} = input;
|
|
265
|
+
|
|
266
|
+
let whereClause = 'WHERE projectId = ?';
|
|
267
|
+
const params: (string | number)[] = [projectId];
|
|
268
|
+
|
|
269
|
+
if (organizationId) {
|
|
270
|
+
whereClause += ' AND organizationId = ?';
|
|
271
|
+
params.push(organizationId);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (status && status !== 'all') {
|
|
275
|
+
whereClause += ' AND status = ?';
|
|
276
|
+
params.push(status);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (search) {
|
|
280
|
+
whereClause += ' AND (name LIKE ? OR description LIKE ?)';
|
|
281
|
+
params.push(`%${search}%`, `%${search}%`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const countResult = (
|
|
285
|
+
await db.query(
|
|
286
|
+
`SELECT COUNT(*) as count FROM agent_definition ${whereClause}`,
|
|
287
|
+
params
|
|
288
|
+
)
|
|
289
|
+
).rows as unknown as { count: number }[];
|
|
290
|
+
const total = countResult[0]?.count ?? 0;
|
|
291
|
+
|
|
292
|
+
const rows = (
|
|
293
|
+
await db.query(
|
|
294
|
+
`SELECT * FROM agent_definition ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
|
|
295
|
+
[...params, limit, offset]
|
|
296
|
+
)
|
|
297
|
+
).rows as unknown as AgentRow[];
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
items: rows.map(rowToAgent),
|
|
301
|
+
total,
|
|
302
|
+
hasMore: offset + rows.length < total,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Get a single agent
|
|
308
|
+
*/
|
|
309
|
+
async function getAgent(id: string): Promise<Agent | null> {
|
|
310
|
+
const rows = (
|
|
311
|
+
await db.query(`SELECT * FROM agent_definition WHERE id = ?`, [id])
|
|
312
|
+
).rows as unknown as AgentRow[];
|
|
313
|
+
return rows[0] ? rowToAgent(rows[0]) : null;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Create an agent
|
|
318
|
+
*/
|
|
319
|
+
async function createAgent(
|
|
320
|
+
input: CreateAgentInput,
|
|
321
|
+
context: { projectId: string; organizationId: string }
|
|
322
|
+
): Promise<Agent> {
|
|
323
|
+
const id = generateId('agent');
|
|
324
|
+
const now = new Date().toISOString();
|
|
325
|
+
|
|
326
|
+
await db.execute(
|
|
327
|
+
`INSERT INTO agent_definition (id, projectId, organizationId, name, description, modelProvider, modelName, systemPrompt, temperature, maxTokens, status, createdAt, updatedAt)
|
|
327
328
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
329
|
+
[
|
|
330
|
+
id,
|
|
331
|
+
context.projectId,
|
|
332
|
+
context.organizationId,
|
|
333
|
+
input.name,
|
|
334
|
+
input.description ?? null,
|
|
335
|
+
input.modelProvider ?? 'openai',
|
|
336
|
+
input.modelName ?? 'gpt-4',
|
|
337
|
+
input.systemPrompt ?? null,
|
|
338
|
+
input.temperature ?? 0.7,
|
|
339
|
+
input.maxTokens ?? 4096,
|
|
340
|
+
'DRAFT',
|
|
341
|
+
now,
|
|
342
|
+
now,
|
|
343
|
+
]
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const rows = (
|
|
347
|
+
await db.query(`SELECT * FROM agent_definition WHERE id = ?`, [id])
|
|
348
|
+
).rows as unknown as AgentRow[];
|
|
349
|
+
|
|
350
|
+
const row = rows[0];
|
|
351
|
+
if (!row) {
|
|
352
|
+
throw new Error('Failed to retrieve created agent');
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return rowToAgent(row);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Update an agent
|
|
360
|
+
*/
|
|
361
|
+
async function updateAgent(input: UpdateAgentInput): Promise<Agent> {
|
|
362
|
+
const now = new Date().toISOString();
|
|
363
|
+
const updates: string[] = ['updatedAt = ?'];
|
|
364
|
+
const params: (string | null)[] = [now];
|
|
365
|
+
|
|
366
|
+
if (input.name !== undefined) {
|
|
367
|
+
updates.push('name = ?');
|
|
368
|
+
params.push(input.name);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (input.description !== undefined) {
|
|
372
|
+
updates.push('description = ?');
|
|
373
|
+
params.push(input.description);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (input.status !== undefined) {
|
|
377
|
+
updates.push('status = ?');
|
|
378
|
+
params.push(input.status);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
params.push(input.id);
|
|
382
|
+
|
|
383
|
+
await db.execute(
|
|
384
|
+
`UPDATE agent_definition SET ${updates.join(', ')} WHERE id = ?`,
|
|
385
|
+
params
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
const rows = (
|
|
389
|
+
await db.query(`SELECT * FROM agent_definition WHERE id = ?`, [input.id])
|
|
390
|
+
).rows as unknown as AgentRow[];
|
|
391
|
+
|
|
392
|
+
if (!rows[0]) {
|
|
393
|
+
throw new Error('NOT_FOUND');
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return rowToAgent(rows[0]);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* List tools
|
|
401
|
+
*/
|
|
402
|
+
async function listTools(input: ListToolsInput): Promise<ListToolsOutput> {
|
|
403
|
+
const {
|
|
404
|
+
projectId,
|
|
405
|
+
organizationId,
|
|
406
|
+
category,
|
|
407
|
+
status,
|
|
408
|
+
search,
|
|
409
|
+
limit = 50,
|
|
410
|
+
offset = 0,
|
|
411
|
+
} = input;
|
|
412
|
+
|
|
413
|
+
let whereClause = 'WHERE projectId = ?';
|
|
414
|
+
const params: (string | number)[] = [projectId];
|
|
415
|
+
|
|
416
|
+
if (organizationId) {
|
|
417
|
+
whereClause += ' AND organizationId = ?';
|
|
418
|
+
params.push(organizationId);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (category && category !== 'all') {
|
|
422
|
+
whereClause += ' AND category = ?';
|
|
423
|
+
params.push(category);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (status && status !== 'all') {
|
|
427
|
+
whereClause += ' AND status = ?';
|
|
428
|
+
params.push(status);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (search) {
|
|
432
|
+
whereClause += ' AND (name LIKE ? OR description LIKE ?)';
|
|
433
|
+
params.push(`%${search}%`, `%${search}%`);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const countResult = (
|
|
437
|
+
await db.query(
|
|
438
|
+
`SELECT COUNT(*) as count FROM agent_tool ${whereClause}`,
|
|
439
|
+
params
|
|
440
|
+
)
|
|
441
|
+
).rows as unknown as { count: number }[];
|
|
442
|
+
const total = countResult[0]?.count ?? 0;
|
|
443
|
+
|
|
444
|
+
const rows = (
|
|
445
|
+
await db.query(
|
|
446
|
+
`SELECT * FROM agent_tool ${whereClause} ORDER BY name ASC LIMIT ? OFFSET ?`,
|
|
447
|
+
[...params, limit, offset]
|
|
448
|
+
)
|
|
449
|
+
).rows as unknown as ToolRow[];
|
|
450
|
+
|
|
451
|
+
return {
|
|
452
|
+
items: rows.map(rowToTool),
|
|
453
|
+
total,
|
|
454
|
+
hasMore: offset + rows.length < total,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* List runs
|
|
460
|
+
*/
|
|
461
|
+
async function listRuns(input: ListRunsInput): Promise<ListRunsOutput> {
|
|
462
|
+
const { projectId, agentId, status, limit = 20, offset = 0 } = input;
|
|
463
|
+
|
|
464
|
+
let whereClause = 'WHERE r.projectId = ?';
|
|
465
|
+
const params: (string | number)[] = [projectId];
|
|
466
|
+
|
|
467
|
+
if (agentId) {
|
|
468
|
+
whereClause += ' AND r.agentId = ?';
|
|
469
|
+
params.push(agentId);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (status && status !== 'all') {
|
|
473
|
+
whereClause += ' AND r.status = ?';
|
|
474
|
+
params.push(status);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const countResult = (
|
|
478
|
+
await db.query(
|
|
479
|
+
`SELECT COUNT(*) as count FROM agent_run r ${whereClause}`,
|
|
480
|
+
params
|
|
481
|
+
)
|
|
482
|
+
).rows as unknown as { count: number }[];
|
|
483
|
+
const total = countResult[0]?.count ?? 0;
|
|
484
|
+
|
|
485
|
+
const rows = (
|
|
486
|
+
await db.query(
|
|
487
|
+
`SELECT r.*, a.name as agentName
|
|
487
488
|
FROM agent_run r
|
|
488
489
|
LEFT JOIN agent_definition a ON r.agentId = a.id
|
|
489
490
|
${whereClause}
|
|
490
491
|
ORDER BY r.queuedAt DESC LIMIT ? OFFSET ?`,
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
492
|
+
[...params, limit, offset]
|
|
493
|
+
)
|
|
494
|
+
).rows as unknown as (RunRow & { agentName: string })[];
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
items: rows.map((r) => rowToRun(r, r.agentName)),
|
|
498
|
+
total,
|
|
499
|
+
hasMore: offset + rows.length < total,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Get run metrics
|
|
505
|
+
*/
|
|
506
|
+
async function getRunMetrics(input: {
|
|
507
|
+
projectId: string;
|
|
508
|
+
agentId?: string;
|
|
509
|
+
startDate?: Date;
|
|
510
|
+
endDate?: Date;
|
|
511
|
+
}): Promise<RunMetrics> {
|
|
512
|
+
let whereClause = 'WHERE projectId = ?';
|
|
513
|
+
const params: (string | number)[] = [input.projectId];
|
|
514
|
+
|
|
515
|
+
if (input.agentId) {
|
|
516
|
+
whereClause += ' AND agentId = ?';
|
|
517
|
+
params.push(input.agentId);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (input.startDate) {
|
|
521
|
+
whereClause += ' AND queuedAt >= ?';
|
|
522
|
+
params.push(input.startDate.toISOString());
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if (input.endDate) {
|
|
526
|
+
whereClause += ' AND queuedAt <= ?';
|
|
527
|
+
params.push(input.endDate.toISOString());
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const result = (
|
|
531
|
+
await db.query(
|
|
532
|
+
`SELECT
|
|
532
533
|
COUNT(*) as totalRuns,
|
|
533
534
|
SUM(CASE WHEN status = 'COMPLETED' THEN 1 ELSE 0 END) as completedRuns,
|
|
534
535
|
AVG(CASE WHEN status = 'COMPLETED' THEN durationMs ELSE NULL END) as avgDuration,
|
|
535
536
|
COALESCE(SUM(totalTokens), 0) as totalTokens,
|
|
536
537
|
COALESCE(SUM(estimatedCostUsd), 0) as totalCost
|
|
537
538
|
FROM agent_run ${whereClause}`,
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
539
|
+
params
|
|
540
|
+
)
|
|
541
|
+
).rows as unknown as {
|
|
542
|
+
totalRuns: number;
|
|
543
|
+
completedRuns: number;
|
|
544
|
+
avgDuration: number | null;
|
|
545
|
+
totalTokens: number;
|
|
546
|
+
totalCost: number;
|
|
547
|
+
}[];
|
|
548
|
+
|
|
549
|
+
const data = result[0];
|
|
550
|
+
const totalRuns = data?.totalRuns ?? 0;
|
|
551
|
+
const completedRuns = data?.completedRuns ?? 0;
|
|
552
|
+
|
|
553
|
+
return {
|
|
554
|
+
totalRuns,
|
|
555
|
+
successRate: totalRuns > 0 ? completedRuns / totalRuns : 0,
|
|
556
|
+
averageDurationMs: data?.avgDuration ?? 0,
|
|
557
|
+
totalTokens: data?.totalTokens ?? 0,
|
|
558
|
+
totalCostUsd: data?.totalCost ?? 0,
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Execute an agent (create a run and queue it).
|
|
564
|
+
*/
|
|
565
|
+
async function executeAgent(input: {
|
|
566
|
+
agentId: string;
|
|
567
|
+
message: string;
|
|
568
|
+
context?: { projectId: string; organizationId: string };
|
|
569
|
+
}): Promise<Run> {
|
|
570
|
+
const agent = await getAgent(input.agentId);
|
|
571
|
+
if (!agent) throw new Error('AGENT_NOT_FOUND');
|
|
572
|
+
if (agent.status !== 'ACTIVE') throw new Error('AGENT_NOT_ACTIVE');
|
|
573
|
+
|
|
574
|
+
const id = generateId('run');
|
|
575
|
+
const now = new Date().toISOString();
|
|
576
|
+
const pid = input.context?.projectId ?? agent.projectId;
|
|
577
|
+
|
|
578
|
+
await db.execute(
|
|
579
|
+
`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
579
580
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
581
|
+
[id, pid, input.agentId, 'QUEUED', input.message, 0, 0, 0, 0, now]
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
const rows = (
|
|
585
|
+
await db.query(
|
|
586
|
+
`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`,
|
|
587
|
+
[id]
|
|
588
|
+
)
|
|
589
|
+
).rows as unknown as (RunRow & { agentName: string })[];
|
|
590
|
+
|
|
591
|
+
if (!rows[0]) throw new Error('Failed to retrieve created run');
|
|
592
|
+
return rowToRun(rows[0], rows[0].agentName);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return {
|
|
596
|
+
listAgents,
|
|
597
|
+
getAgent,
|
|
598
|
+
createAgent,
|
|
599
|
+
updateAgent,
|
|
600
|
+
executeAgent,
|
|
601
|
+
listTools,
|
|
602
|
+
listRuns,
|
|
603
|
+
getRunMetrics,
|
|
604
|
+
};
|
|
604
605
|
}
|
|
605
606
|
|
|
606
607
|
export type AgentHandlers = ReturnType<typeof createAgentHandlers>;
|