@contractspec/example.agent-console 3.2.0 → 3.3.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.
@@ -3,15 +3,15 @@ $ bun run prebuild && bun run build:bundle && bun run build:types
3
3
  $ contractspec-bun-build prebuild
4
4
  $ contractspec-bun-build transpile
5
5
  [contractspec-bun-build] transpile target=bun root=src entries=66
6
- Bundled 66 modules in 103ms
6
+ Bundled 66 modules in 87ms
7
7
 
8
8
  ./agent.capability.js 442 bytes (entry point)
9
9
  tool/tool.test-spec.js 1.38 KB (entry point)
10
10
  shared/overlay-types.js 8 bytes (entry point)
11
11
  run/run.test-spec.js 1.37 KB (entry point)
12
12
  seeders/index.js 0.64 KB (entry point)
13
- ./index.js 200.84 KB (entry point)
14
- ui/index.js 77.35 KB (entry point)
13
+ ./index.js 202.80 KB (entry point)
14
+ ui/index.js 78.0 KB (entry point)
15
15
  ui/views/index.js 22.0 KB (entry point)
16
16
  ui/renderers/index.js 14.75 KB (entry point)
17
17
  ui/renderers/agent-list.markdown.js 1.49 KB (entry point)
@@ -23,18 +23,18 @@ Bundled 66 modules in 103ms
23
23
  ui/modals/index.js 22.38 KB (entry point)
24
24
  ui/overlays/index.js 1.46 KB (entry point)
25
25
  ui/overlays/demo-overlays.js 1.46 KB (entry point)
26
- ui/AgentDashboard.js 62.32 KB (entry point)
26
+ ui/AgentDashboard.js 63.0 KB (entry point)
27
27
  ui/modals/AgentActionsModal.js 12.32 KB (entry point)
28
28
  ui/modals/CreateAgentModal.js 9.99 KB (entry point)
29
29
  ui/AgentRunList.js 9.39 KB (entry point)
30
30
  ui/views/RunListView.js 9.33 KB (entry point)
31
31
  ui/AgentToolRegistry.js 6.99 KB (entry point)
32
32
  ui/views/ToolRegistryView.js 6.92 KB (entry point)
33
- ui/hooks/index.js 8.61 KB (entry point)
33
+ ui/hooks/index.js 9.30 KB (entry point)
34
34
  ui/hooks/useRunList.js 1.69 KB (entry point)
35
35
  ui/hooks/useToolList.js 2.52 KB (entry point)
36
36
  ui/hooks/useAgentList.js 1.69 KB (entry point)
37
- ui/hooks/useAgentMutations.js 2.50 KB (entry point)
37
+ ui/hooks/useAgentMutations.js 3.18 KB (entry point)
38
38
  tool/index.js 28.61 KB (entry point)
39
39
  tool/tool.entity.js 2.65 KB (entry point)
40
40
  tool/tool.event.js 3.25 KB (entry point)
@@ -56,12 +56,12 @@ Bundled 66 modules in 103ms
56
56
  docs/index.js 3.74 KB (entry point)
57
57
  docs/agent-console.docblock.js 3.74 KB (entry point)
58
58
  ./example.js 1.25 KB (entry point)
59
- handlers/index.js 24.39 KB (entry point)
59
+ handlers/index.js 25.34 KB (entry point)
60
60
  tool/tool.handler.js 6.38 KB (entry point)
61
61
  run/run.handler.js 7.61 KB (entry point)
62
62
  shared/mock-runs.js 3.0 KB (entry point)
63
- handlers/agent.handlers.js 8.30 KB (entry point)
64
- ./agent.feature.js 4.37 KB (entry point)
63
+ handlers/agent.handlers.js 9.24 KB (entry point)
64
+ ./agent.feature.js 4.70 KB (entry point)
65
65
  agent/agent.entity.js 3.92 KB (entry point)
66
66
  agent/agent.handler.js 8.88 KB (entry point)
67
67
  shared/mock-tools.js 4.15 KB (entry point)
@@ -73,15 +73,15 @@ Bundled 66 modules in 103ms
73
73
  agent/agent.enum.js 467 bytes (entry point)
74
74
 
75
75
  [contractspec-bun-build] transpile target=node root=src entries=66
76
- Bundled 66 modules in 130ms
76
+ Bundled 66 modules in 82ms
77
77
 
78
78
  ./agent.capability.js 434 bytes (entry point)
79
79
  tool/tool.test-spec.js 1.38 KB (entry point)
80
80
  shared/overlay-types.js 0 KB (entry point)
81
81
  run/run.test-spec.js 1.36 KB (entry point)
82
82
  seeders/index.js 0.63 KB (entry point)
83
- ./index.js 200.78 KB (entry point)
84
- ui/index.js 77.30 KB (entry point)
83
+ ./index.js 202.74 KB (entry point)
84
+ ui/index.js 77.99 KB (entry point)
85
85
  ui/views/index.js 22.00 KB (entry point)
86
86
  ui/renderers/index.js 14.73 KB (entry point)
87
87
  ui/renderers/agent-list.markdown.js 1.48 KB (entry point)
@@ -93,18 +93,18 @@ Bundled 66 modules in 130ms
93
93
  ui/modals/index.js 22.36 KB (entry point)
94
94
  ui/overlays/index.js 1.45 KB (entry point)
95
95
  ui/overlays/demo-overlays.js 1.45 KB (entry point)
96
- ui/AgentDashboard.js 62.29 KB (entry point)
96
+ ui/AgentDashboard.js 62.97 KB (entry point)
97
97
  ui/modals/AgentActionsModal.js 12.29 KB (entry point)
98
98
  ui/modals/CreateAgentModal.js 9.99 KB (entry point)
99
99
  ui/AgentRunList.js 9.38 KB (entry point)
100
100
  ui/views/RunListView.js 9.32 KB (entry point)
101
101
  ui/AgentToolRegistry.js 6.97 KB (entry point)
102
102
  ui/views/ToolRegistryView.js 6.91 KB (entry point)
103
- ui/hooks/index.js 8.60 KB (entry point)
103
+ ui/hooks/index.js 9.29 KB (entry point)
104
104
  ui/hooks/useRunList.js 1.69 KB (entry point)
105
105
  ui/hooks/useToolList.js 2.51 KB (entry point)
106
106
  ui/hooks/useAgentList.js 1.68 KB (entry point)
107
- ui/hooks/useAgentMutations.js 2.49 KB (entry point)
107
+ ui/hooks/useAgentMutations.js 3.18 KB (entry point)
108
108
  tool/index.js 28.60 KB (entry point)
109
109
  tool/tool.entity.js 2.64 KB (entry point)
110
110
  tool/tool.event.js 3.24 KB (entry point)
@@ -126,12 +126,12 @@ Bundled 66 modules in 130ms
126
126
  docs/index.js 3.72 KB (entry point)
127
127
  docs/agent-console.docblock.js 3.72 KB (entry point)
128
128
  ./example.js 1.24 KB (entry point)
129
- handlers/index.js 24.39 KB (entry point)
129
+ handlers/index.js 25.33 KB (entry point)
130
130
  tool/tool.handler.js 6.37 KB (entry point)
131
131
  run/run.handler.js 7.60 KB (entry point)
132
132
  shared/mock-runs.js 3.0 KB (entry point)
133
- handlers/agent.handlers.js 8.29 KB (entry point)
134
- ./agent.feature.js 4.36 KB (entry point)
133
+ handlers/agent.handlers.js 9.24 KB (entry point)
134
+ ./agent.feature.js 4.69 KB (entry point)
135
135
  agent/agent.entity.js 3.92 KB (entry point)
136
136
  agent/agent.handler.js 8.88 KB (entry point)
137
137
  shared/mock-tools.js 4.14 KB (entry point)
@@ -143,15 +143,15 @@ Bundled 66 modules in 130ms
143
143
  agent/agent.enum.js 459 bytes (entry point)
144
144
 
145
145
  [contractspec-bun-build] transpile target=browser root=src entries=66
146
- Bundled 66 modules in 87ms
146
+ Bundled 66 modules in 78ms
147
147
 
148
148
  ./agent.capability.js 434 bytes (entry point)
149
149
  tool/tool.test-spec.js 1.38 KB (entry point)
150
150
  shared/overlay-types.js 0 KB (entry point)
151
151
  run/run.test-spec.js 1.36 KB (entry point)
152
152
  seeders/index.js 0.63 KB (entry point)
153
- ./index.js 200.78 KB (entry point)
154
- ui/index.js 77.30 KB (entry point)
153
+ ./index.js 202.74 KB (entry point)
154
+ ui/index.js 77.99 KB (entry point)
155
155
  ui/views/index.js 22.00 KB (entry point)
156
156
  ui/renderers/index.js 14.73 KB (entry point)
157
157
  ui/renderers/agent-list.markdown.js 1.48 KB (entry point)
@@ -163,18 +163,18 @@ Bundled 66 modules in 87ms
163
163
  ui/modals/index.js 22.36 KB (entry point)
164
164
  ui/overlays/index.js 1.45 KB (entry point)
165
165
  ui/overlays/demo-overlays.js 1.45 KB (entry point)
166
- ui/AgentDashboard.js 62.29 KB (entry point)
166
+ ui/AgentDashboard.js 62.97 KB (entry point)
167
167
  ui/modals/AgentActionsModal.js 12.29 KB (entry point)
168
168
  ui/modals/CreateAgentModal.js 9.99 KB (entry point)
169
169
  ui/AgentRunList.js 9.38 KB (entry point)
170
170
  ui/views/RunListView.js 9.32 KB (entry point)
171
171
  ui/AgentToolRegistry.js 6.97 KB (entry point)
172
172
  ui/views/ToolRegistryView.js 6.91 KB (entry point)
173
- ui/hooks/index.js 8.60 KB (entry point)
173
+ ui/hooks/index.js 9.29 KB (entry point)
174
174
  ui/hooks/useRunList.js 1.69 KB (entry point)
175
175
  ui/hooks/useToolList.js 2.51 KB (entry point)
176
176
  ui/hooks/useAgentList.js 1.68 KB (entry point)
177
- ui/hooks/useAgentMutations.js 2.49 KB (entry point)
177
+ ui/hooks/useAgentMutations.js 3.18 KB (entry point)
178
178
  tool/index.js 28.60 KB (entry point)
179
179
  tool/tool.entity.js 2.64 KB (entry point)
180
180
  tool/tool.event.js 3.24 KB (entry point)
@@ -196,12 +196,12 @@ Bundled 66 modules in 87ms
196
196
  docs/index.js 3.72 KB (entry point)
197
197
  docs/agent-console.docblock.js 3.72 KB (entry point)
198
198
  ./example.js 1.24 KB (entry point)
199
- handlers/index.js 24.39 KB (entry point)
199
+ handlers/index.js 25.33 KB (entry point)
200
200
  tool/tool.handler.js 6.37 KB (entry point)
201
201
  run/run.handler.js 7.60 KB (entry point)
202
202
  shared/mock-runs.js 3.0 KB (entry point)
203
- handlers/agent.handlers.js 8.29 KB (entry point)
204
- ./agent.feature.js 4.36 KB (entry point)
203
+ handlers/agent.handlers.js 9.24 KB (entry point)
204
+ ./agent.feature.js 4.69 KB (entry point)
205
205
  agent/agent.entity.js 3.92 KB (entry point)
206
206
  agent/agent.handler.js 8.88 KB (entry point)
207
207
  shared/mock-tools.js 4.14 KB (entry point)
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @contractspec/example.agent-console
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 890a0da: fix: stability improvements
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [890a0da]
12
+ - @contractspec/lib.example-shared-ui@3.3.0
13
+ - @contractspec/lib.runtime-sandbox@2.3.0
14
+ - @contractspec/lib.contracts-spec@3.3.0
15
+ - @contractspec/lib.design-system@3.3.0
16
+ - @contractspec/lib.schema@3.3.0
17
+
3
18
  ## 3.2.0
4
19
 
5
20
  ### Minor Changes
@@ -112,7 +112,15 @@ var AgentConsoleFeature = defineFeature({
112
112
  { key: "jobs", version: "1.0.0" }
113
113
  ],
114
114
  provides: [{ key: "agent", version: "1.0.0" }]
115
- }
115
+ },
116
+ telemetry: [{ key: "agent-console.telemetry", version: "1.0.0" }],
117
+ jobs: [{ key: "agent-console.job.run-execution", version: "1.0.0" }],
118
+ docs: [
119
+ "docs.examples.agent-console.goal",
120
+ "docs.examples.agent-console.usage",
121
+ "docs.examples.agent-console.reference",
122
+ "docs.examples.agent-console.constraints"
123
+ ]
116
124
  });
117
125
  export {
118
126
  AgentConsoleFeature
@@ -111,7 +111,15 @@ var AgentConsoleFeature = defineFeature({
111
111
  { key: "jobs", version: "1.0.0" }
112
112
  ],
113
113
  provides: [{ key: "agent", version: "1.0.0" }]
114
- }
114
+ },
115
+ telemetry: [{ key: "agent-console.telemetry", version: "1.0.0" }],
116
+ jobs: [{ key: "agent-console.job.run-execution", version: "1.0.0" }],
117
+ docs: [
118
+ "docs.examples.agent-console.goal",
119
+ "docs.examples.agent-console.usage",
120
+ "docs.examples.agent-console.reference",
121
+ "docs.examples.agent-console.constraints"
122
+ ]
115
123
  });
116
124
  export {
117
125
  AgentConsoleFeature
@@ -237,11 +237,28 @@ function createAgentHandlers(db) {
237
237
  totalCostUsd: data?.totalCost ?? 0
238
238
  };
239
239
  }
240
+ async function executeAgent(input) {
241
+ const agent = await getAgent(input.agentId);
242
+ if (!agent)
243
+ throw new Error("AGENT_NOT_FOUND");
244
+ if (agent.status !== "ACTIVE")
245
+ throw new Error("AGENT_NOT_ACTIVE");
246
+ const id = generateId("run");
247
+ const now = new Date().toISOString();
248
+ const pid = input.context?.projectId ?? agent.projectId;
249
+ await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
250
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
251
+ const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
252
+ if (!rows[0])
253
+ throw new Error("Failed to retrieve created run");
254
+ return rowToRun(rows[0], rows[0].agentName);
255
+ }
240
256
  return {
241
257
  listAgents,
242
258
  getAgent,
243
259
  createAgent,
244
260
  updateAgent,
261
+ executeAgent,
245
262
  listTools,
246
263
  listRuns,
247
264
  getRunMetrics
@@ -533,11 +533,28 @@ function createAgentHandlers(db) {
533
533
  totalCostUsd: data?.totalCost ?? 0
534
534
  };
535
535
  }
536
+ async function executeAgent(input) {
537
+ const agent = await getAgent(input.agentId);
538
+ if (!agent)
539
+ throw new Error("AGENT_NOT_FOUND");
540
+ if (agent.status !== "ACTIVE")
541
+ throw new Error("AGENT_NOT_ACTIVE");
542
+ const id = generateId("run");
543
+ const now = new Date().toISOString();
544
+ const pid = input.context?.projectId ?? agent.projectId;
545
+ await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
546
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
547
+ const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
548
+ if (!rows[0])
549
+ throw new Error("Failed to retrieve created run");
550
+ return rowToRun(rows[0], rows[0].agentName);
551
+ }
536
552
  return {
537
553
  listAgents,
538
554
  getAgent,
539
555
  createAgent,
540
556
  updateAgent,
557
+ executeAgent,
541
558
  listTools,
542
559
  listRuns,
543
560
  getRunMetrics
@@ -111,7 +111,15 @@ var AgentConsoleFeature = defineFeature({
111
111
  { key: "jobs", version: "1.0.0" }
112
112
  ],
113
113
  provides: [{ key: "agent", version: "1.0.0" }]
114
- }
114
+ },
115
+ telemetry: [{ key: "agent-console.telemetry", version: "1.0.0" }],
116
+ jobs: [{ key: "agent-console.job.run-execution", version: "1.0.0" }],
117
+ docs: [
118
+ "docs.examples.agent-console.goal",
119
+ "docs.examples.agent-console.usage",
120
+ "docs.examples.agent-console.reference",
121
+ "docs.examples.agent-console.constraints"
122
+ ]
115
123
  });
116
124
 
117
125
  // src/agent/agent.entity.ts
@@ -1701,11 +1709,28 @@ function createAgentHandlers(db) {
1701
1709
  totalCostUsd: data?.totalCost ?? 0
1702
1710
  };
1703
1711
  }
1712
+ async function executeAgent(input) {
1713
+ const agent = await getAgent(input.agentId);
1714
+ if (!agent)
1715
+ throw new Error("AGENT_NOT_FOUND");
1716
+ if (agent.status !== "ACTIVE")
1717
+ throw new Error("AGENT_NOT_ACTIVE");
1718
+ const id = generateId("run");
1719
+ const now = new Date().toISOString();
1720
+ const pid = input.context?.projectId ?? agent.projectId;
1721
+ await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
1722
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
1723
+ const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
1724
+ if (!rows[0])
1725
+ throw new Error("Failed to retrieve created run");
1726
+ return rowToRun(rows[0], rows[0].agentName);
1727
+ }
1704
1728
  return {
1705
1729
  listAgents,
1706
1730
  getAgent,
1707
1731
  createAgent,
1708
1732
  updateAgent,
1733
+ executeAgent,
1709
1734
  listTools,
1710
1735
  listRuns,
1711
1736
  getRunMetrics
@@ -4248,6 +4273,11 @@ function useAgentMutations(options = {}) {
4248
4273
  error: null,
4249
4274
  data: null
4250
4275
  });
4276
+ const [executeState, setExecuteState] = useState4({
4277
+ loading: false,
4278
+ error: null,
4279
+ data: null
4280
+ });
4251
4281
  const createAgent = useCallback4(async (input) => {
4252
4282
  setCreateState({ loading: true, error: null, data: null });
4253
4283
  try {
@@ -4289,10 +4319,23 @@ function useAgentMutations(options = {}) {
4289
4319
  return updateAgent({ id: agentId, status: "ARCHIVED" });
4290
4320
  }, [updateAgent]);
4291
4321
  const executeAgent = useCallback4(async (input) => {
4292
- console.log("Execute agent:", input);
4293
- options.onSuccess?.();
4294
- return null;
4295
- }, [options]);
4322
+ setExecuteState({ loading: true, error: null, data: null });
4323
+ try {
4324
+ const result = await agent.executeAgent({
4325
+ agentId: input.agentId,
4326
+ message: input.message,
4327
+ context: { projectId, organizationId: "demo-org" }
4328
+ });
4329
+ setExecuteState({ loading: false, error: null, data: result });
4330
+ options.onSuccess?.();
4331
+ return result;
4332
+ } catch (err) {
4333
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
4334
+ setExecuteState({ loading: false, error, data: null });
4335
+ options.onError?.(error);
4336
+ return null;
4337
+ }
4338
+ }, [agent, projectId, options]);
4296
4339
  return {
4297
4340
  createAgent,
4298
4341
  updateAgent,
@@ -4302,7 +4345,8 @@ function useAgentMutations(options = {}) {
4302
4345
  executeAgent,
4303
4346
  createState,
4304
4347
  updateState,
4305
- isLoading: createState.loading || updateState.loading
4348
+ executeState,
4349
+ isLoading: createState.loading || updateState.loading || executeState.loading
4306
4350
  };
4307
4351
  }
4308
4352
 
@@ -519,6 +519,11 @@ function useAgentMutations(options = {}) {
519
519
  error: null,
520
520
  data: null
521
521
  });
522
+ const [executeState, setExecuteState] = useState4({
523
+ loading: false,
524
+ error: null,
525
+ data: null
526
+ });
522
527
  const createAgent = useCallback4(async (input) => {
523
528
  setCreateState({ loading: true, error: null, data: null });
524
529
  try {
@@ -560,10 +565,23 @@ function useAgentMutations(options = {}) {
560
565
  return updateAgent({ id: agentId, status: "ARCHIVED" });
561
566
  }, [updateAgent]);
562
567
  const executeAgent = useCallback4(async (input) => {
563
- console.log("Execute agent:", input);
564
- options.onSuccess?.();
565
- return null;
566
- }, [options]);
568
+ setExecuteState({ loading: true, error: null, data: null });
569
+ try {
570
+ const result = await agent.executeAgent({
571
+ agentId: input.agentId,
572
+ message: input.message,
573
+ context: { projectId, organizationId: "demo-org" }
574
+ });
575
+ setExecuteState({ loading: false, error: null, data: result });
576
+ options.onSuccess?.();
577
+ return result;
578
+ } catch (err) {
579
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
580
+ setExecuteState({ loading: false, error, data: null });
581
+ options.onError?.(error);
582
+ return null;
583
+ }
584
+ }, [agent, projectId, options]);
567
585
  return {
568
586
  createAgent,
569
587
  updateAgent,
@@ -573,7 +591,8 @@ function useAgentMutations(options = {}) {
573
591
  executeAgent,
574
592
  createState,
575
593
  updateState,
576
- isLoading: createState.loading || updateState.loading
594
+ executeState,
595
+ isLoading: createState.loading || updateState.loading || executeState.loading
577
596
  };
578
597
  }
579
598
 
@@ -203,6 +203,11 @@ function useAgentMutations(options = {}) {
203
203
  error: null,
204
204
  data: null
205
205
  });
206
+ const [executeState, setExecuteState] = useState4({
207
+ loading: false,
208
+ error: null,
209
+ data: null
210
+ });
206
211
  const createAgent = useCallback4(async (input) => {
207
212
  setCreateState({ loading: true, error: null, data: null });
208
213
  try {
@@ -244,10 +249,23 @@ function useAgentMutations(options = {}) {
244
249
  return updateAgent({ id: agentId, status: "ARCHIVED" });
245
250
  }, [updateAgent]);
246
251
  const executeAgent = useCallback4(async (input) => {
247
- console.log("Execute agent:", input);
248
- options.onSuccess?.();
249
- return null;
250
- }, [options]);
252
+ setExecuteState({ loading: true, error: null, data: null });
253
+ try {
254
+ const result = await agent.executeAgent({
255
+ agentId: input.agentId,
256
+ message: input.message,
257
+ context: { projectId, organizationId: "demo-org" }
258
+ });
259
+ setExecuteState({ loading: false, error: null, data: result });
260
+ options.onSuccess?.();
261
+ return result;
262
+ } catch (err) {
263
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
264
+ setExecuteState({ loading: false, error, data: null });
265
+ options.onError?.(error);
266
+ return null;
267
+ }
268
+ }, [agent, projectId, options]);
251
269
  return {
252
270
  createAgent,
253
271
  updateAgent,
@@ -257,7 +275,8 @@ function useAgentMutations(options = {}) {
257
275
  executeAgent,
258
276
  createState,
259
277
  updateState,
260
- isLoading: createState.loading || updateState.loading
278
+ executeState,
279
+ isLoading: createState.loading || updateState.loading || executeState.loading
261
280
  };
262
281
  }
263
282
 
@@ -14,6 +14,11 @@ function useAgentMutations(options = {}) {
14
14
  error: null,
15
15
  data: null
16
16
  });
17
+ const [executeState, setExecuteState] = useState({
18
+ loading: false,
19
+ error: null,
20
+ data: null
21
+ });
17
22
  const createAgent = useCallback(async (input) => {
18
23
  setCreateState({ loading: true, error: null, data: null });
19
24
  try {
@@ -55,10 +60,23 @@ function useAgentMutations(options = {}) {
55
60
  return updateAgent({ id: agentId, status: "ARCHIVED" });
56
61
  }, [updateAgent]);
57
62
  const executeAgent = useCallback(async (input) => {
58
- console.log("Execute agent:", input);
59
- options.onSuccess?.();
60
- return null;
61
- }, [options]);
63
+ setExecuteState({ loading: true, error: null, data: null });
64
+ try {
65
+ const result = await agent.executeAgent({
66
+ agentId: input.agentId,
67
+ message: input.message,
68
+ context: { projectId, organizationId: "demo-org" }
69
+ });
70
+ setExecuteState({ loading: false, error: null, data: result });
71
+ options.onSuccess?.();
72
+ return result;
73
+ } catch (err) {
74
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
75
+ setExecuteState({ loading: false, error, data: null });
76
+ options.onError?.(error);
77
+ return null;
78
+ }
79
+ }, [agent, projectId, options]);
62
80
  return {
63
81
  createAgent,
64
82
  updateAgent,
@@ -68,7 +86,8 @@ function useAgentMutations(options = {}) {
68
86
  executeAgent,
69
87
  createState,
70
88
  updateState,
71
- isLoading: createState.loading || updateState.loading
89
+ executeState,
90
+ isLoading: createState.loading || updateState.loading || executeState.loading
72
91
  };
73
92
  }
74
93
  export {
@@ -519,6 +519,11 @@ function useAgentMutations(options = {}) {
519
519
  error: null,
520
520
  data: null
521
521
  });
522
+ const [executeState, setExecuteState] = useState4({
523
+ loading: false,
524
+ error: null,
525
+ data: null
526
+ });
522
527
  const createAgent = useCallback4(async (input) => {
523
528
  setCreateState({ loading: true, error: null, data: null });
524
529
  try {
@@ -560,10 +565,23 @@ function useAgentMutations(options = {}) {
560
565
  return updateAgent({ id: agentId, status: "ARCHIVED" });
561
566
  }, [updateAgent]);
562
567
  const executeAgent = useCallback4(async (input) => {
563
- console.log("Execute agent:", input);
564
- options.onSuccess?.();
565
- return null;
566
- }, [options]);
568
+ setExecuteState({ loading: true, error: null, data: null });
569
+ try {
570
+ const result = await agent.executeAgent({
571
+ agentId: input.agentId,
572
+ message: input.message,
573
+ context: { projectId, organizationId: "demo-org" }
574
+ });
575
+ setExecuteState({ loading: false, error: null, data: result });
576
+ options.onSuccess?.();
577
+ return result;
578
+ } catch (err) {
579
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
580
+ setExecuteState({ loading: false, error, data: null });
581
+ options.onError?.(error);
582
+ return null;
583
+ }
584
+ }, [agent, projectId, options]);
567
585
  return {
568
586
  createAgent,
569
587
  updateAgent,
@@ -573,7 +591,8 @@ function useAgentMutations(options = {}) {
573
591
  executeAgent,
574
592
  createState,
575
593
  updateState,
576
- isLoading: createState.loading || updateState.loading
594
+ executeState,
595
+ isLoading: createState.loading || updateState.loading || executeState.loading
577
596
  };
578
597
  }
579
598
 
@@ -122,6 +122,14 @@ export declare function createAgentHandlers(db: DatabasePort): {
122
122
  organizationId: string;
123
123
  }) => Promise<Agent>;
124
124
  updateAgent: (input: UpdateAgentInput) => Promise<Agent>;
125
+ executeAgent: (input: {
126
+ agentId: string;
127
+ message: string;
128
+ context?: {
129
+ projectId: string;
130
+ organizationId: string;
131
+ };
132
+ }) => Promise<Run>;
125
133
  listTools: (input: ListToolsInput) => Promise<ListToolsOutput>;
126
134
  listRuns: (input: ListRunsInput) => Promise<ListRunsOutput>;
127
135
  getRunMetrics: (input: {
@@ -238,11 +238,28 @@ function createAgentHandlers(db) {
238
238
  totalCostUsd: data?.totalCost ?? 0
239
239
  };
240
240
  }
241
+ async function executeAgent(input) {
242
+ const agent = await getAgent(input.agentId);
243
+ if (!agent)
244
+ throw new Error("AGENT_NOT_FOUND");
245
+ if (agent.status !== "ACTIVE")
246
+ throw new Error("AGENT_NOT_ACTIVE");
247
+ const id = generateId("run");
248
+ const now = new Date().toISOString();
249
+ const pid = input.context?.projectId ?? agent.projectId;
250
+ await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
251
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
252
+ const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
253
+ if (!rows[0])
254
+ throw new Error("Failed to retrieve created run");
255
+ return rowToRun(rows[0], rows[0].agentName);
256
+ }
241
257
  return {
242
258
  listAgents,
243
259
  getAgent,
244
260
  createAgent,
245
261
  updateAgent,
262
+ executeAgent,
246
263
  listTools,
247
264
  listRuns,
248
265
  getRunMetrics
@@ -534,11 +534,28 @@ function createAgentHandlers(db) {
534
534
  totalCostUsd: data?.totalCost ?? 0
535
535
  };
536
536
  }
537
+ async function executeAgent(input) {
538
+ const agent = await getAgent(input.agentId);
539
+ if (!agent)
540
+ throw new Error("AGENT_NOT_FOUND");
541
+ if (agent.status !== "ACTIVE")
542
+ throw new Error("AGENT_NOT_ACTIVE");
543
+ const id = generateId("run");
544
+ const now = new Date().toISOString();
545
+ const pid = input.context?.projectId ?? agent.projectId;
546
+ await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
547
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
548
+ const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
549
+ if (!rows[0])
550
+ throw new Error("Failed to retrieve created run");
551
+ return rowToRun(rows[0], rows[0].agentName);
552
+ }
537
553
  return {
538
554
  listAgents,
539
555
  getAgent,
540
556
  createAgent,
541
557
  updateAgent,
558
+ executeAgent,
542
559
  listTools,
543
560
  listRuns,
544
561
  getRunMetrics