@contractspec/example.agent-console 3.2.0 → 3.4.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.
@@ -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
 
@@ -520,6 +520,11 @@ function useAgentMutations(options = {}) {
520
520
  error: null,
521
521
  data: null
522
522
  });
523
+ const [executeState, setExecuteState] = useState4({
524
+ loading: false,
525
+ error: null,
526
+ data: null
527
+ });
523
528
  const createAgent = useCallback4(async (input) => {
524
529
  setCreateState({ loading: true, error: null, data: null });
525
530
  try {
@@ -561,10 +566,23 @@ function useAgentMutations(options = {}) {
561
566
  return updateAgent({ id: agentId, status: "ARCHIVED" });
562
567
  }, [updateAgent]);
563
568
  const executeAgent = useCallback4(async (input) => {
564
- console.log("Execute agent:", input);
565
- options.onSuccess?.();
566
- return null;
567
- }, [options]);
569
+ setExecuteState({ loading: true, error: null, data: null });
570
+ try {
571
+ const result = await agent.executeAgent({
572
+ agentId: input.agentId,
573
+ message: input.message,
574
+ context: { projectId, organizationId: "demo-org" }
575
+ });
576
+ setExecuteState({ loading: false, error: null, data: result });
577
+ options.onSuccess?.();
578
+ return result;
579
+ } catch (err) {
580
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
581
+ setExecuteState({ loading: false, error, data: null });
582
+ options.onError?.(error);
583
+ return null;
584
+ }
585
+ }, [agent, projectId, options]);
568
586
  return {
569
587
  createAgent,
570
588
  updateAgent,
@@ -574,7 +592,8 @@ function useAgentMutations(options = {}) {
574
592
  executeAgent,
575
593
  createState,
576
594
  updateState,
577
- isLoading: createState.loading || updateState.loading
595
+ executeState,
596
+ isLoading: createState.loading || updateState.loading || executeState.loading
578
597
  };
579
598
  }
580
599
 
@@ -204,6 +204,11 @@ function useAgentMutations(options = {}) {
204
204
  error: null,
205
205
  data: null
206
206
  });
207
+ const [executeState, setExecuteState] = useState4({
208
+ loading: false,
209
+ error: null,
210
+ data: null
211
+ });
207
212
  const createAgent = useCallback4(async (input) => {
208
213
  setCreateState({ loading: true, error: null, data: null });
209
214
  try {
@@ -245,10 +250,23 @@ function useAgentMutations(options = {}) {
245
250
  return updateAgent({ id: agentId, status: "ARCHIVED" });
246
251
  }, [updateAgent]);
247
252
  const executeAgent = useCallback4(async (input) => {
248
- console.log("Execute agent:", input);
249
- options.onSuccess?.();
250
- return null;
251
- }, [options]);
253
+ setExecuteState({ loading: true, error: null, data: null });
254
+ try {
255
+ const result = await agent.executeAgent({
256
+ agentId: input.agentId,
257
+ message: input.message,
258
+ context: { projectId, organizationId: "demo-org" }
259
+ });
260
+ setExecuteState({ loading: false, error: null, data: result });
261
+ options.onSuccess?.();
262
+ return result;
263
+ } catch (err) {
264
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
265
+ setExecuteState({ loading: false, error, data: null });
266
+ options.onError?.(error);
267
+ return null;
268
+ }
269
+ }, [agent, projectId, options]);
252
270
  return {
253
271
  createAgent,
254
272
  updateAgent,
@@ -258,7 +276,8 @@ function useAgentMutations(options = {}) {
258
276
  executeAgent,
259
277
  createState,
260
278
  updateState,
261
- isLoading: createState.loading || updateState.loading
279
+ executeState,
280
+ isLoading: createState.loading || updateState.loading || executeState.loading
262
281
  };
263
282
  }
264
283
 
@@ -1,4 +1,4 @@
1
- import type { Agent, CreateAgentInput, UpdateAgentInput } from '../../handlers/agent.handlers';
1
+ import type { Agent, Run, CreateAgentInput, UpdateAgentInput } from '../../handlers/agent.handlers';
2
2
  export interface MutationState<T> {
3
3
  loading: boolean;
4
4
  error: Error | null;
@@ -17,9 +17,10 @@ export declare function useAgentMutations(options?: UseAgentMutationsOptions): {
17
17
  executeAgent: (input: {
18
18
  agentId: string;
19
19
  message: string;
20
- }) => Promise<null>;
20
+ }) => Promise<Run | null>;
21
21
  createState: MutationState<Agent>;
22
22
  updateState: MutationState<Agent>;
23
+ executeState: MutationState<Run>;
23
24
  isLoading: boolean;
24
25
  };
25
- export type { CreateAgentInput, UpdateAgentInput, Agent };
26
+ export type { CreateAgentInput, UpdateAgentInput, Agent, Run };
@@ -15,6 +15,11 @@ function useAgentMutations(options = {}) {
15
15
  error: null,
16
16
  data: null
17
17
  });
18
+ const [executeState, setExecuteState] = useState({
19
+ loading: false,
20
+ error: null,
21
+ data: null
22
+ });
18
23
  const createAgent = useCallback(async (input) => {
19
24
  setCreateState({ loading: true, error: null, data: null });
20
25
  try {
@@ -56,10 +61,23 @@ function useAgentMutations(options = {}) {
56
61
  return updateAgent({ id: agentId, status: "ARCHIVED" });
57
62
  }, [updateAgent]);
58
63
  const executeAgent = useCallback(async (input) => {
59
- console.log("Execute agent:", input);
60
- options.onSuccess?.();
61
- return null;
62
- }, [options]);
64
+ setExecuteState({ loading: true, error: null, data: null });
65
+ try {
66
+ const result = await agent.executeAgent({
67
+ agentId: input.agentId,
68
+ message: input.message,
69
+ context: { projectId, organizationId: "demo-org" }
70
+ });
71
+ setExecuteState({ loading: false, error: null, data: result });
72
+ options.onSuccess?.();
73
+ return result;
74
+ } catch (err) {
75
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
76
+ setExecuteState({ loading: false, error, data: null });
77
+ options.onError?.(error);
78
+ return null;
79
+ }
80
+ }, [agent, projectId, options]);
63
81
  return {
64
82
  createAgent,
65
83
  updateAgent,
@@ -69,7 +87,8 @@ function useAgentMutations(options = {}) {
69
87
  executeAgent,
70
88
  createState,
71
89
  updateState,
72
- isLoading: createState.loading || updateState.loading
90
+ executeState,
91
+ isLoading: createState.loading || updateState.loading || executeState.loading
73
92
  };
74
93
  }
75
94
  export {
package/dist/ui/index.js CHANGED
@@ -520,6 +520,11 @@ function useAgentMutations(options = {}) {
520
520
  error: null,
521
521
  data: null
522
522
  });
523
+ const [executeState, setExecuteState] = useState4({
524
+ loading: false,
525
+ error: null,
526
+ data: null
527
+ });
523
528
  const createAgent = useCallback4(async (input) => {
524
529
  setCreateState({ loading: true, error: null, data: null });
525
530
  try {
@@ -561,10 +566,23 @@ function useAgentMutations(options = {}) {
561
566
  return updateAgent({ id: agentId, status: "ARCHIVED" });
562
567
  }, [updateAgent]);
563
568
  const executeAgent = useCallback4(async (input) => {
564
- console.log("Execute agent:", input);
565
- options.onSuccess?.();
566
- return null;
567
- }, [options]);
569
+ setExecuteState({ loading: true, error: null, data: null });
570
+ try {
571
+ const result = await agent.executeAgent({
572
+ agentId: input.agentId,
573
+ message: input.message,
574
+ context: { projectId, organizationId: "demo-org" }
575
+ });
576
+ setExecuteState({ loading: false, error: null, data: result });
577
+ options.onSuccess?.();
578
+ return result;
579
+ } catch (err) {
580
+ const error = err instanceof Error ? err : new Error("Failed to execute agent");
581
+ setExecuteState({ loading: false, error, data: null });
582
+ options.onError?.(error);
583
+ return null;
584
+ }
585
+ }, [agent, projectId, options]);
568
586
  return {
569
587
  createAgent,
570
588
  updateAgent,
@@ -574,7 +592,8 @@ function useAgentMutations(options = {}) {
574
592
  executeAgent,
575
593
  createState,
576
594
  updateState,
577
- isLoading: createState.loading || updateState.loading
595
+ executeState,
596
+ isLoading: createState.loading || updateState.loading || executeState.loading
578
597
  };
579
598
  }
580
599
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contractspec/example.agent-console",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Agent Console example - AI agent orchestration with tools, runs, and logs",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -582,20 +582,20 @@
582
582
  "typecheck": "tsc --noEmit"
583
583
  },
584
584
  "dependencies": {
585
- "@contractspec/lib.schema": "3.2.0",
586
- "@contractspec/lib.contracts-spec": "3.2.0",
587
- "@contractspec/lib.example-shared-ui": "3.2.0",
588
- "@contractspec/lib.design-system": "3.2.0",
589
- "@contractspec/lib.runtime-sandbox": "2.2.0",
585
+ "@contractspec/lib.schema": "3.4.0",
586
+ "@contractspec/lib.contracts-spec": "3.4.0",
587
+ "@contractspec/lib.example-shared-ui": "3.4.0",
588
+ "@contractspec/lib.design-system": "3.4.0",
589
+ "@contractspec/lib.runtime-sandbox": "2.4.0",
590
590
  "react": "19.2.4",
591
591
  "react-dom": "19.2.4"
592
592
  },
593
593
  "devDependencies": {
594
- "@contractspec/tool.typescript": "3.2.0",
594
+ "@contractspec/tool.typescript": "3.4.0",
595
595
  "typescript": "^5.9.3",
596
596
  "@types/react": "^19.2.14",
597
597
  "@types/react-dom": "^19.2.2",
598
- "@contractspec/tool.bun": "3.2.0"
598
+ "@contractspec/tool.bun": "3.4.0"
599
599
  },
600
600
  "publishConfig": {
601
601
  "exports": {
@@ -144,4 +144,15 @@ export const AgentConsoleFeature: FeatureModuleSpec = defineFeature({
144
144
  ],
145
145
  provides: [{ key: 'agent', version: '1.0.0' }],
146
146
  },
147
+
148
+ telemetry: [{ key: 'agent-console.telemetry', version: '1.0.0' }],
149
+
150
+ jobs: [{ key: 'agent-console.job.run-execution', version: '1.0.0' }],
151
+
152
+ docs: [
153
+ 'docs.examples.agent-console.goal',
154
+ 'docs.examples.agent-console.usage',
155
+ 'docs.examples.agent-console.reference',
156
+ 'docs.examples.agent-console.constraints',
157
+ ],
147
158
  });
@@ -558,11 +558,45 @@ export function createAgentHandlers(db: DatabasePort) {
558
558
  };
559
559
  }
560
560
 
561
+ /**
562
+ * Execute an agent (create a run and queue it).
563
+ */
564
+ async function executeAgent(input: {
565
+ agentId: string;
566
+ message: string;
567
+ context?: { projectId: string; organizationId: string };
568
+ }): Promise<Run> {
569
+ const agent = await getAgent(input.agentId);
570
+ if (!agent) throw new Error('AGENT_NOT_FOUND');
571
+ if (agent.status !== 'ACTIVE') throw new Error('AGENT_NOT_ACTIVE');
572
+
573
+ const id = generateId('run');
574
+ const now = new Date().toISOString();
575
+ const pid = input.context?.projectId ?? agent.projectId;
576
+
577
+ await db.execute(
578
+ `INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
579
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
580
+ [id, pid, input.agentId, 'QUEUED', input.message, 0, 0, 0, 0, now]
581
+ );
582
+
583
+ const rows = (
584
+ await db.query(
585
+ `SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`,
586
+ [id]
587
+ )
588
+ ).rows as unknown as (RunRow & { agentName: string })[];
589
+
590
+ if (!rows[0]) throw new Error('Failed to retrieve created run');
591
+ return rowToRun(rows[0], rows[0].agentName);
592
+ }
593
+
561
594
  return {
562
595
  listAgents,
563
596
  getAgent,
564
597
  createAgent,
565
598
  updateAgent,
599
+ executeAgent,
566
600
  listTools,
567
601
  listRuns,
568
602
  getRunMetrics,
@@ -9,6 +9,7 @@ import { useCallback, useState } from 'react';
9
9
  import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
10
10
  import type {
11
11
  Agent,
12
+ Run,
12
13
  CreateAgentInput,
13
14
  UpdateAgentInput,
14
15
  AgentHandlers,
@@ -43,6 +44,12 @@ export function useAgentMutations(options: UseAgentMutationsOptions = {}) {
43
44
  data: null,
44
45
  });
45
46
 
47
+ const [executeState, setExecuteState] = useState<MutationState<Run>>({
48
+ loading: false,
49
+ error: null,
50
+ data: null,
51
+ });
52
+
46
53
  /**
47
54
  * Create a new agent
48
55
  */
@@ -121,17 +128,32 @@ export function useAgentMutations(options: UseAgentMutationsOptions = {}) {
121
128
  );
122
129
 
123
130
  /**
124
- * Execute an agent (placeholder - needs run handler)
125
- * Note: Execute functionality requires adding createRun/executeRun to agent handlers
131
+ * Execute an agent (creates a queued run).
126
132
  */
127
133
  const executeAgent = useCallback(
128
- async (input: { agentId: string; message: string }): Promise<null> => {
129
- // TODO: Implement execute when run creation handler is added to runtime-local
130
- console.log('Execute agent:', input);
131
- options.onSuccess?.();
132
- return null;
134
+ async (input: {
135
+ agentId: string;
136
+ message: string;
137
+ }): Promise<Run | null> => {
138
+ setExecuteState({ loading: true, error: null, data: null });
139
+ try {
140
+ const result = await agent.executeAgent({
141
+ agentId: input.agentId,
142
+ message: input.message,
143
+ context: { projectId, organizationId: 'demo-org' },
144
+ });
145
+ setExecuteState({ loading: false, error: null, data: result });
146
+ options.onSuccess?.();
147
+ return result;
148
+ } catch (err) {
149
+ const error =
150
+ err instanceof Error ? err : new Error('Failed to execute agent');
151
+ setExecuteState({ loading: false, error, data: null });
152
+ options.onError?.(error);
153
+ return null;
154
+ }
133
155
  },
134
- [options]
156
+ [agent, projectId, options]
135
157
  );
136
158
 
137
159
  return {
@@ -146,11 +168,13 @@ export function useAgentMutations(options: UseAgentMutationsOptions = {}) {
146
168
  // State
147
169
  createState,
148
170
  updateState,
171
+ executeState,
149
172
 
150
173
  // Convenience
151
- isLoading: createState.loading || updateState.loading,
174
+ isLoading:
175
+ createState.loading || updateState.loading || executeState.loading,
152
176
  };
153
177
  }
154
178
 
155
179
  // Re-export types for convenience
156
- export type { CreateAgentInput, UpdateAgentInput, Agent };
180
+ export type { CreateAgentInput, UpdateAgentInput, Agent, Run };