@contractspec/example.agent-console 3.1.1 → 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.
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.1.1",
3
+ "version": "3.3.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.1.0",
586
- "@contractspec/lib.contracts-spec": "3.1.1",
587
- "@contractspec/lib.example-shared-ui": "3.1.1",
588
- "@contractspec/lib.design-system": "3.1.1",
589
- "@contractspec/lib.runtime-sandbox": "2.1.0",
585
+ "@contractspec/lib.schema": "3.3.0",
586
+ "@contractspec/lib.contracts-spec": "3.3.0",
587
+ "@contractspec/lib.example-shared-ui": "3.3.0",
588
+ "@contractspec/lib.design-system": "3.3.0",
589
+ "@contractspec/lib.runtime-sandbox": "2.3.0",
590
590
  "react": "19.2.4",
591
591
  "react-dom": "19.2.4"
592
592
  },
593
593
  "devDependencies": {
594
- "@contractspec/tool.typescript": "3.1.0",
594
+ "@contractspec/tool.typescript": "3.3.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.1.0"
598
+ "@contractspec/tool.bun": "3.3.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 };