@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.
Files changed (176) hide show
  1. package/.turbo/turbo-build.log +18 -18
  2. package/AGENTS.md +50 -31
  3. package/CHANGELOG.md +12 -0
  4. package/README.md +69 -77
  5. package/dist/agent/agent.event.js +1 -1
  6. package/dist/agent/agent.operation.js +1 -1
  7. package/dist/agent/index.d.ts +5 -5
  8. package/dist/agent/index.js +1 -1
  9. package/dist/browser/agent/agent.event.js +1 -1
  10. package/dist/browser/agent/agent.operation.js +1 -1
  11. package/dist/browser/agent/index.js +1 -1
  12. package/dist/browser/index.js +2145 -2145
  13. package/dist/browser/presentations/index.js +4 -4
  14. package/dist/browser/run/index.js +536 -536
  15. package/dist/browser/run/run.event.js +2 -2
  16. package/dist/browser/run/run.presentation.js +2 -2
  17. package/dist/browser/tool/index.js +260 -260
  18. package/dist/browser/tool/tool.event.js +1 -1
  19. package/dist/browser/tool/tool.presentation.js +2 -2
  20. package/dist/browser/ui/AgentDashboard.js +956 -956
  21. package/dist/browser/ui/AgentRunList.js +16 -16
  22. package/dist/browser/ui/AgentToolRegistry.js +9 -9
  23. package/dist/browser/ui/hooks/index.js +153 -153
  24. package/dist/browser/ui/hooks/useAgentList.js +1 -1
  25. package/dist/browser/ui/hooks/useAgentMutations.js +1 -1
  26. package/dist/browser/ui/hooks/useRunList.js +1 -1
  27. package/dist/browser/ui/hooks/useToolList.js +1 -1
  28. package/dist/browser/ui/index.js +1222 -1222
  29. package/dist/browser/ui/modals/AgentActionsModal.js +13 -13
  30. package/dist/browser/ui/modals/CreateAgentModal.js +15 -15
  31. package/dist/browser/ui/modals/index.js +297 -297
  32. package/dist/browser/ui/renderers/agent-list.renderer.js +7 -7
  33. package/dist/browser/ui/renderers/index.js +157 -157
  34. package/dist/browser/ui/views/AgentListView.js +7 -7
  35. package/dist/browser/ui/views/RunListView.js +16 -16
  36. package/dist/browser/ui/views/ToolRegistryView.js +9 -9
  37. package/dist/browser/ui/views/index.js +97 -97
  38. package/dist/handlers/index.d.ts +1 -1
  39. package/dist/index.d.ts +4 -4
  40. package/dist/index.js +2145 -2145
  41. package/dist/node/agent/agent.event.js +1 -1
  42. package/dist/node/agent/agent.operation.js +1 -1
  43. package/dist/node/agent/index.js +1 -1
  44. package/dist/node/index.js +2145 -2145
  45. package/dist/node/presentations/index.js +4 -4
  46. package/dist/node/run/index.js +536 -536
  47. package/dist/node/run/run.event.js +2 -2
  48. package/dist/node/run/run.presentation.js +2 -2
  49. package/dist/node/tool/index.js +260 -260
  50. package/dist/node/tool/tool.event.js +1 -1
  51. package/dist/node/tool/tool.presentation.js +2 -2
  52. package/dist/node/ui/AgentDashboard.js +956 -956
  53. package/dist/node/ui/AgentRunList.js +16 -16
  54. package/dist/node/ui/AgentToolRegistry.js +9 -9
  55. package/dist/node/ui/hooks/index.js +153 -153
  56. package/dist/node/ui/hooks/useAgentList.js +1 -1
  57. package/dist/node/ui/hooks/useAgentMutations.js +1 -1
  58. package/dist/node/ui/hooks/useRunList.js +1 -1
  59. package/dist/node/ui/hooks/useToolList.js +1 -1
  60. package/dist/node/ui/index.js +1222 -1222
  61. package/dist/node/ui/modals/AgentActionsModal.js +13 -13
  62. package/dist/node/ui/modals/CreateAgentModal.js +15 -15
  63. package/dist/node/ui/modals/index.js +297 -297
  64. package/dist/node/ui/renderers/agent-list.renderer.js +7 -7
  65. package/dist/node/ui/renderers/index.js +157 -157
  66. package/dist/node/ui/views/AgentListView.js +7 -7
  67. package/dist/node/ui/views/RunListView.js +16 -16
  68. package/dist/node/ui/views/ToolRegistryView.js +9 -9
  69. package/dist/node/ui/views/index.js +97 -97
  70. package/dist/presentations/index.d.ts +3 -5
  71. package/dist/presentations/index.js +4 -4
  72. package/dist/run/index.d.ts +7 -7
  73. package/dist/run/index.js +536 -536
  74. package/dist/run/run.event.js +2 -2
  75. package/dist/run/run.handler.d.ts +3 -0
  76. package/dist/run/run.presentation.js +2 -2
  77. package/dist/shared/index.d.ts +1 -1
  78. package/dist/tool/index.d.ts +7 -7
  79. package/dist/tool/index.js +260 -260
  80. package/dist/tool/tool.event.js +1 -1
  81. package/dist/tool/tool.handler.d.ts +1 -1
  82. package/dist/tool/tool.presentation.js +2 -2
  83. package/dist/ui/AgentDashboard.js +956 -956
  84. package/dist/ui/AgentRunList.js +16 -16
  85. package/dist/ui/AgentToolRegistry.js +9 -9
  86. package/dist/ui/hooks/index.d.ts +4 -4
  87. package/dist/ui/hooks/index.js +153 -153
  88. package/dist/ui/hooks/useAgentList.d.ts +5 -0
  89. package/dist/ui/hooks/useAgentList.js +1 -1
  90. package/dist/ui/hooks/useAgentMutations.d.ts +9 -2
  91. package/dist/ui/hooks/useAgentMutations.js +1 -1
  92. package/dist/ui/hooks/useRunList.d.ts +5 -0
  93. package/dist/ui/hooks/useRunList.js +1 -1
  94. package/dist/ui/hooks/useToolList.d.ts +5 -0
  95. package/dist/ui/hooks/useToolList.js +1 -1
  96. package/dist/ui/index.d.ts +3 -3
  97. package/dist/ui/index.js +1222 -1222
  98. package/dist/ui/modals/AgentActionsModal.js +13 -13
  99. package/dist/ui/modals/CreateAgentModal.js +15 -15
  100. package/dist/ui/modals/index.d.ts +1 -1
  101. package/dist/ui/modals/index.js +297 -297
  102. package/dist/ui/renderers/agent-list.markdown.d.ts +5 -0
  103. package/dist/ui/renderers/agent-list.renderer.js +7 -7
  104. package/dist/ui/renderers/dashboard.markdown.d.ts +5 -0
  105. package/dist/ui/renderers/index.d.ts +2 -2
  106. package/dist/ui/renderers/index.js +157 -157
  107. package/dist/ui/renderers/run-list.markdown.d.ts +5 -0
  108. package/dist/ui/renderers/tool-registry.markdown.d.ts +5 -0
  109. package/dist/ui/views/AgentListView.js +7 -7
  110. package/dist/ui/views/RunListView.js +16 -16
  111. package/dist/ui/views/ToolRegistryView.js +9 -9
  112. package/dist/ui/views/index.js +97 -97
  113. package/package.json +10 -10
  114. package/src/agent/agent.entity.ts +111 -111
  115. package/src/agent/agent.enum.ts +12 -12
  116. package/src/agent/agent.event.ts +91 -91
  117. package/src/agent/agent.handler.ts +123 -123
  118. package/src/agent/agent.operation.ts +400 -400
  119. package/src/agent/agent.presentation.ts +62 -62
  120. package/src/agent/agent.schema.ts +175 -175
  121. package/src/agent/agent.test-spec.ts +48 -48
  122. package/src/agent/index.ts +46 -51
  123. package/src/agent.capability.ts +11 -11
  124. package/src/agent.feature.ts +131 -131
  125. package/src/docs/agent-console.docblock.ts +42 -42
  126. package/src/example.ts +35 -35
  127. package/src/handlers/agent.handlers.ts +522 -521
  128. package/src/handlers/index.ts +12 -12
  129. package/src/index.ts +8 -9
  130. package/src/presentations/index.ts +11 -13
  131. package/src/run/index.ts +49 -54
  132. package/src/run/run.entity.ts +137 -137
  133. package/src/run/run.enum.ts +18 -18
  134. package/src/run/run.event.ts +174 -174
  135. package/src/run/run.handler.ts +92 -91
  136. package/src/run/run.operation.ts +474 -474
  137. package/src/run/run.presentation.ts +42 -42
  138. package/src/run/run.schema.ts +126 -126
  139. package/src/run/run.test-spec.ts +48 -48
  140. package/src/seeders/index.ts +21 -21
  141. package/src/shared/index.ts +1 -1
  142. package/src/shared/mock-agents.ts +76 -76
  143. package/src/shared/mock-runs.ts +102 -102
  144. package/src/shared/mock-tools.ts +140 -140
  145. package/src/shared/overlay-types.ts +23 -23
  146. package/src/tool/index.ts +39 -44
  147. package/src/tool/tool.entity.ts +73 -73
  148. package/src/tool/tool.enum.ts +13 -13
  149. package/src/tool/tool.event.ts +80 -80
  150. package/src/tool/tool.handler.ts +102 -102
  151. package/src/tool/tool.operation.ts +328 -328
  152. package/src/tool/tool.presentation.ts +43 -43
  153. package/src/tool/tool.schema.ts +106 -106
  154. package/src/tool/tool.test-spec.ts +48 -48
  155. package/src/ui/AgentDashboard.tsx +348 -348
  156. package/src/ui/hooks/index.ts +7 -7
  157. package/src/ui/hooks/useAgentList.ts +57 -56
  158. package/src/ui/hooks/useAgentMutations.ts +160 -159
  159. package/src/ui/hooks/useRunList.ts +58 -57
  160. package/src/ui/hooks/useToolList.ts +102 -101
  161. package/src/ui/index.ts +6 -9
  162. package/src/ui/modals/AgentActionsModal.tsx +262 -262
  163. package/src/ui/modals/CreateAgentModal.tsx +232 -232
  164. package/src/ui/modals/index.ts +1 -1
  165. package/src/ui/overlays/demo-overlays.ts +52 -52
  166. package/src/ui/renderers/agent-list.markdown.ts +61 -60
  167. package/src/ui/renderers/agent-list.renderer.tsx +14 -14
  168. package/src/ui/renderers/dashboard.markdown.ts +140 -139
  169. package/src/ui/renderers/index.ts +3 -4
  170. package/src/ui/renderers/run-list.markdown.ts +48 -47
  171. package/src/ui/renderers/tool-registry.markdown.ts +66 -65
  172. package/src/ui/views/AgentListView.tsx +90 -90
  173. package/src/ui/views/RunListView.tsx +141 -141
  174. package/src/ui/views/ToolRegistryView.tsx +113 -113
  175. package/tsconfig.json +7 -8
  176. package/tsdown.config.js +7 -3
@@ -3,12 +3,12 @@
3
3
  /**
4
4
  * Data hooks for agent-console template
5
5
  */
6
- export { useAgentList, type UseAgentListOptions } from './useAgentList';
7
- export { useRunList, type UseRunListOptions } from './useRunList';
8
- export { useToolList, type UseToolListOptions } from './useToolList';
6
+ export { type UseAgentListOptions, useAgentList } from './useAgentList';
9
7
  export {
10
- useAgentMutations,
11
- type UseAgentMutationsOptions,
12
- type CreateAgentInput,
13
- type UpdateAgentInput,
8
+ type CreateAgentInput,
9
+ type UpdateAgentInput,
10
+ type UseAgentMutationsOptions,
11
+ useAgentMutations,
14
12
  } from './useAgentMutations';
13
+ export { type UseRunListOptions, useRunList } from './useRunList';
14
+ export { type UseToolListOptions, useToolList } from './useToolList';
@@ -3,78 +3,79 @@
3
3
  *
4
4
  * Uses runtime-local database-backed handlers.
5
5
  */
6
- import { useCallback, useEffect, useMemo, useState } from 'react';
6
+
7
7
  import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
8
+ import { useCallback, useEffect, useMemo, useState } from 'react';
8
9
  import type {
9
- Agent as RuntimeAgent,
10
- ListAgentsOutput as RuntimeListAgentsOutput,
10
+ AgentHandlers,
11
+ Agent as RuntimeAgent,
12
+ ListAgentsOutput as RuntimeListAgentsOutput,
11
13
  } from '../../handlers/agent.handlers';
12
- import type { AgentHandlers } from '../../handlers/agent.handlers';
13
14
 
14
15
  // Re-export types for convenience
15
16
  export type Agent = RuntimeAgent;
16
17
  export type ListAgentsOutput = RuntimeListAgentsOutput;
17
18
 
18
19
  export interface UseAgentListOptions {
19
- search?: string;
20
- status?: 'DRAFT' | 'ACTIVE' | 'PAUSED' | 'ARCHIVED' | 'all';
21
- limit?: number;
20
+ search?: string;
21
+ status?: 'DRAFT' | 'ACTIVE' | 'PAUSED' | 'ARCHIVED' | 'all';
22
+ limit?: number;
22
23
  }
23
24
 
24
25
  export function useAgentList(options: UseAgentListOptions = {}) {
25
- const { handlers, projectId } = useTemplateRuntime<{
26
- agent: AgentHandlers;
27
- }>();
28
- const { agent } = handlers;
26
+ const { handlers, projectId } = useTemplateRuntime<{
27
+ agent: AgentHandlers;
28
+ }>();
29
+ const { agent } = handlers;
29
30
 
30
- const [data, setData] = useState<ListAgentsOutput | null>(null);
31
- const [loading, setLoading] = useState(true);
32
- const [error, setError] = useState<Error | null>(null);
33
- const [page, setPage] = useState(1);
31
+ const [data, setData] = useState<ListAgentsOutput | null>(null);
32
+ const [loading, setLoading] = useState(true);
33
+ const [error, setError] = useState<Error | null>(null);
34
+ const [page, setPage] = useState(1);
34
35
 
35
- const fetchData = useCallback(async () => {
36
- setLoading(true);
37
- setError(null);
36
+ const fetchData = useCallback(async () => {
37
+ setLoading(true);
38
+ setError(null);
38
39
 
39
- try {
40
- const result = await agent.listAgents({
41
- projectId,
42
- search: options.search,
43
- status: options.status === 'all' ? undefined : options.status,
44
- limit: options.limit ?? 20,
45
- offset: (page - 1) * (options.limit ?? 20),
46
- });
47
- setData(result);
48
- } catch (err) {
49
- setError(err instanceof Error ? err : new Error('Unknown error'));
50
- } finally {
51
- setLoading(false);
52
- }
53
- }, [agent, projectId, options.search, options.status, options.limit, page]);
40
+ try {
41
+ const result = await agent.listAgents({
42
+ projectId,
43
+ search: options.search,
44
+ status: options.status === 'all' ? undefined : options.status,
45
+ limit: options.limit ?? 20,
46
+ offset: (page - 1) * (options.limit ?? 20),
47
+ });
48
+ setData(result);
49
+ } catch (err) {
50
+ setError(err instanceof Error ? err : new Error('Unknown error'));
51
+ } finally {
52
+ setLoading(false);
53
+ }
54
+ }, [agent, projectId, options.search, options.status, options.limit, page]);
54
55
 
55
- useEffect(() => {
56
- fetchData();
57
- }, [fetchData]);
56
+ useEffect(() => {
57
+ fetchData();
58
+ }, [fetchData]);
58
59
 
59
- // Calculate stats
60
- const stats = useMemo(() => {
61
- if (!data) return null;
62
- return {
63
- total: data.total,
64
- active: data.items.filter((a) => a.status === 'ACTIVE').length,
65
- paused: data.items.filter((a) => a.status === 'PAUSED').length,
66
- draft: data.items.filter((a) => a.status === 'DRAFT').length,
67
- };
68
- }, [data]);
60
+ // Calculate stats
61
+ const stats = useMemo(() => {
62
+ if (!data) return null;
63
+ return {
64
+ total: data.total,
65
+ active: data.items.filter((a) => a.status === 'ACTIVE').length,
66
+ paused: data.items.filter((a) => a.status === 'PAUSED').length,
67
+ draft: data.items.filter((a) => a.status === 'DRAFT').length,
68
+ };
69
+ }, [data]);
69
70
 
70
- return {
71
- data,
72
- loading,
73
- error,
74
- stats,
75
- page,
76
- refetch: fetchData,
77
- nextPage: () => setPage((p) => p + 1),
78
- prevPage: () => page > 1 && setPage((p) => p - 1),
79
- };
71
+ return {
72
+ data,
73
+ loading,
74
+ error,
75
+ stats,
76
+ page,
77
+ refetch: fetchData,
78
+ nextPage: () => setPage((p) => p + 1),
79
+ prevPage: () => page > 1 && setPage((p) => p - 1),
80
+ };
80
81
  }
@@ -5,176 +5,177 @@
5
5
  * - CreateAgentCommand
6
6
  * - UpdateAgentCommand
7
7
  */
8
- import { useCallback, useState } from 'react';
8
+
9
9
  import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
10
+ import { useCallback, useState } from 'react';
10
11
  import type {
11
- Agent,
12
- Run,
13
- CreateAgentInput,
14
- UpdateAgentInput,
15
- AgentHandlers,
12
+ Agent,
13
+ AgentHandlers,
14
+ CreateAgentInput,
15
+ Run,
16
+ UpdateAgentInput,
16
17
  } from '../../handlers/agent.handlers';
17
18
 
18
19
  export interface MutationState<T> {
19
- loading: boolean;
20
- error: Error | null;
21
- data: T | null;
20
+ loading: boolean;
21
+ error: Error | null;
22
+ data: T | null;
22
23
  }
23
24
 
24
25
  export interface UseAgentMutationsOptions {
25
- onSuccess?: () => void;
26
- onError?: (error: Error) => void;
26
+ onSuccess?: () => void;
27
+ onError?: (error: Error) => void;
27
28
  }
28
29
 
29
30
  export function useAgentMutations(options: UseAgentMutationsOptions = {}) {
30
- const { handlers, projectId } = useTemplateRuntime<{
31
- agent: AgentHandlers;
32
- }>();
33
- const { agent } = handlers;
34
-
35
- const [createState, setCreateState] = useState<MutationState<Agent>>({
36
- loading: false,
37
- error: null,
38
- data: null,
39
- });
40
-
41
- const [updateState, setUpdateState] = useState<MutationState<Agent>>({
42
- loading: false,
43
- error: null,
44
- data: null,
45
- });
46
-
47
- const [executeState, setExecuteState] = useState<MutationState<Run>>({
48
- loading: false,
49
- error: null,
50
- data: null,
51
- });
52
-
53
- /**
54
- * Create a new agent
55
- */
56
- const createAgent = useCallback(
57
- async (input: CreateAgentInput): Promise<Agent | null> => {
58
- setCreateState({ loading: true, error: null, data: null });
59
- try {
60
- const result = await agent.createAgent(input, {
61
- projectId,
62
- organizationId: 'demo-org',
63
- });
64
- setCreateState({ loading: false, error: null, data: result });
65
- options.onSuccess?.();
66
- return result;
67
- } catch (err) {
68
- const error =
69
- err instanceof Error ? err : new Error('Failed to create agent');
70
- setCreateState({ loading: false, error, data: null });
71
- options.onError?.(error);
72
- return null;
73
- }
74
- },
75
- [agent, projectId, options]
76
- );
77
-
78
- /**
79
- * Update an agent (name, status)
80
- */
81
- const updateAgent = useCallback(
82
- async (input: UpdateAgentInput): Promise<Agent | null> => {
83
- setUpdateState({ loading: true, error: null, data: null });
84
- try {
85
- const result = await agent.updateAgent(input);
86
- setUpdateState({ loading: false, error: null, data: result });
87
- options.onSuccess?.();
88
- return result;
89
- } catch (err) {
90
- const error =
91
- err instanceof Error ? err : new Error('Failed to update agent');
92
- setUpdateState({ loading: false, error, data: null });
93
- options.onError?.(error);
94
- return null;
95
- }
96
- },
97
- [agent, options]
98
- );
99
-
100
- /**
101
- * Activate an agent
102
- */
103
- const activateAgent = useCallback(
104
- async (agentId: string): Promise<Agent | null> => {
105
- return updateAgent({ id: agentId, status: 'ACTIVE' });
106
- },
107
- [updateAgent]
108
- );
109
-
110
- /**
111
- * Pause an agent
112
- */
113
- const pauseAgent = useCallback(
114
- async (agentId: string): Promise<Agent | null> => {
115
- return updateAgent({ id: agentId, status: 'PAUSED' });
116
- },
117
- [updateAgent]
118
- );
119
-
120
- /**
121
- * Archive an agent
122
- */
123
- const archiveAgent = useCallback(
124
- async (agentId: string): Promise<Agent | null> => {
125
- return updateAgent({ id: agentId, status: 'ARCHIVED' });
126
- },
127
- [updateAgent]
128
- );
129
-
130
- /**
131
- * Execute an agent (creates a queued run).
132
- */
133
- const executeAgent = useCallback(
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
- }
155
- },
156
- [agent, projectId, options]
157
- );
158
-
159
- return {
160
- // Mutations
161
- createAgent,
162
- updateAgent,
163
- activateAgent,
164
- pauseAgent,
165
- archiveAgent,
166
- executeAgent,
167
-
168
- // State
169
- createState,
170
- updateState,
171
- executeState,
172
-
173
- // Convenience
174
- isLoading:
175
- createState.loading || updateState.loading || executeState.loading,
176
- };
31
+ const { handlers, projectId } = useTemplateRuntime<{
32
+ agent: AgentHandlers;
33
+ }>();
34
+ const { agent } = handlers;
35
+
36
+ const [createState, setCreateState] = useState<MutationState<Agent>>({
37
+ loading: false,
38
+ error: null,
39
+ data: null,
40
+ });
41
+
42
+ const [updateState, setUpdateState] = useState<MutationState<Agent>>({
43
+ loading: false,
44
+ error: null,
45
+ data: null,
46
+ });
47
+
48
+ const [executeState, setExecuteState] = useState<MutationState<Run>>({
49
+ loading: false,
50
+ error: null,
51
+ data: null,
52
+ });
53
+
54
+ /**
55
+ * Create a new agent
56
+ */
57
+ const createAgent = useCallback(
58
+ async (input: CreateAgentInput): Promise<Agent | null> => {
59
+ setCreateState({ loading: true, error: null, data: null });
60
+ try {
61
+ const result = await agent.createAgent(input, {
62
+ projectId,
63
+ organizationId: 'demo-org',
64
+ });
65
+ setCreateState({ loading: false, error: null, data: result });
66
+ options.onSuccess?.();
67
+ return result;
68
+ } catch (err) {
69
+ const error =
70
+ err instanceof Error ? err : new Error('Failed to create agent');
71
+ setCreateState({ loading: false, error, data: null });
72
+ options.onError?.(error);
73
+ return null;
74
+ }
75
+ },
76
+ [agent, projectId, options]
77
+ );
78
+
79
+ /**
80
+ * Update an agent (name, status)
81
+ */
82
+ const updateAgent = useCallback(
83
+ async (input: UpdateAgentInput): Promise<Agent | null> => {
84
+ setUpdateState({ loading: true, error: null, data: null });
85
+ try {
86
+ const result = await agent.updateAgent(input);
87
+ setUpdateState({ loading: false, error: null, data: result });
88
+ options.onSuccess?.();
89
+ return result;
90
+ } catch (err) {
91
+ const error =
92
+ err instanceof Error ? err : new Error('Failed to update agent');
93
+ setUpdateState({ loading: false, error, data: null });
94
+ options.onError?.(error);
95
+ return null;
96
+ }
97
+ },
98
+ [agent, options]
99
+ );
100
+
101
+ /**
102
+ * Activate an agent
103
+ */
104
+ const activateAgent = useCallback(
105
+ async (agentId: string): Promise<Agent | null> => {
106
+ return updateAgent({ id: agentId, status: 'ACTIVE' });
107
+ },
108
+ [updateAgent]
109
+ );
110
+
111
+ /**
112
+ * Pause an agent
113
+ */
114
+ const pauseAgent = useCallback(
115
+ async (agentId: string): Promise<Agent | null> => {
116
+ return updateAgent({ id: agentId, status: 'PAUSED' });
117
+ },
118
+ [updateAgent]
119
+ );
120
+
121
+ /**
122
+ * Archive an agent
123
+ */
124
+ const archiveAgent = useCallback(
125
+ async (agentId: string): Promise<Agent | null> => {
126
+ return updateAgent({ id: agentId, status: 'ARCHIVED' });
127
+ },
128
+ [updateAgent]
129
+ );
130
+
131
+ /**
132
+ * Execute an agent (creates a queued run).
133
+ */
134
+ const executeAgent = useCallback(
135
+ async (input: {
136
+ agentId: string;
137
+ message: string;
138
+ }): Promise<Run | null> => {
139
+ setExecuteState({ loading: true, error: null, data: null });
140
+ try {
141
+ const result = await agent.executeAgent({
142
+ agentId: input.agentId,
143
+ message: input.message,
144
+ context: { projectId, organizationId: 'demo-org' },
145
+ });
146
+ setExecuteState({ loading: false, error: null, data: result });
147
+ options.onSuccess?.();
148
+ return result;
149
+ } catch (err) {
150
+ const error =
151
+ err instanceof Error ? err : new Error('Failed to execute agent');
152
+ setExecuteState({ loading: false, error, data: null });
153
+ options.onError?.(error);
154
+ return null;
155
+ }
156
+ },
157
+ [agent, projectId, options]
158
+ );
159
+
160
+ return {
161
+ // Mutations
162
+ createAgent,
163
+ updateAgent,
164
+ activateAgent,
165
+ pauseAgent,
166
+ archiveAgent,
167
+ executeAgent,
168
+
169
+ // State
170
+ createState,
171
+ updateState,
172
+ executeState,
173
+
174
+ // Convenience
175
+ isLoading:
176
+ createState.loading || updateState.loading || executeState.loading,
177
+ };
177
178
  }
178
179
 
179
180
  // Re-export types for convenience
180
- export type { CreateAgentInput, UpdateAgentInput, Agent, Run };
181
+ export type { Agent, CreateAgentInput, Run, UpdateAgentInput };
@@ -3,13 +3,14 @@
3
3
  *
4
4
  * Uses runtime-local database-backed handlers.
5
5
  */
6
- import { useCallback, useEffect, useState } from 'react';
6
+
7
7
  import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
8
+ import { useCallback, useEffect, useState } from 'react';
8
9
  import type {
9
- ListRunsOutput as RuntimeListRunsOutput,
10
- Run as RuntimeRun,
11
- RunMetrics as RuntimeRunMetrics,
12
- AgentHandlers,
10
+ AgentHandlers,
11
+ ListRunsOutput as RuntimeListRunsOutput,
12
+ Run as RuntimeRun,
13
+ RunMetrics as RuntimeRunMetrics,
13
14
  } from '../../handlers/agent.handlers';
14
15
 
15
16
  // Re-export types for convenience
@@ -18,64 +19,64 @@ export type ListRunsOutput = RuntimeListRunsOutput;
18
19
  export type RunMetrics = RuntimeRunMetrics;
19
20
 
20
21
  export interface UseRunListOptions {
21
- agentId?: string;
22
- status?: Run['status'] | 'all';
23
- limit?: number;
22
+ agentId?: string;
23
+ status?: Run['status'] | 'all';
24
+ limit?: number;
24
25
  }
25
26
 
26
27
  export function useRunList(options: UseRunListOptions = {}) {
27
- const { handlers, projectId } = useTemplateRuntime<{
28
- agent: AgentHandlers;
29
- }>();
30
- const { agent } = handlers;
28
+ const { handlers, projectId } = useTemplateRuntime<{
29
+ agent: AgentHandlers;
30
+ }>();
31
+ const { agent } = handlers;
31
32
 
32
- const [data, setData] = useState<ListRunsOutput | null>(null);
33
- const [metrics, setMetrics] = useState<RunMetrics | null>(null);
34
- const [loading, setLoading] = useState(true);
35
- const [error, setError] = useState<Error | null>(null);
36
- const [page, setPage] = useState(1);
33
+ const [data, setData] = useState<ListRunsOutput | null>(null);
34
+ const [metrics, setMetrics] = useState<RunMetrics | null>(null);
35
+ const [loading, setLoading] = useState(true);
36
+ const [error, setError] = useState<Error | null>(null);
37
+ const [page, setPage] = useState(1);
37
38
 
38
- const fetchData = useCallback(async () => {
39
- setLoading(true);
40
- setError(null);
39
+ const fetchData = useCallback(async () => {
40
+ setLoading(true);
41
+ setError(null);
41
42
 
42
- try {
43
- const [runsResult, metricsResult] = await Promise.all([
44
- agent.listRuns({
45
- projectId,
46
- agentId: options.agentId,
47
- status: options.status === 'all' ? undefined : options.status,
48
- limit: options.limit ?? 20,
49
- offset: (page - 1) * (options.limit ?? 20),
50
- }),
51
- agent.getRunMetrics({
52
- projectId,
53
- agentId: options.agentId,
54
- startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), // 30 days ago
55
- endDate: new Date(),
56
- }),
57
- ]);
58
- setData(runsResult);
59
- setMetrics(metricsResult);
60
- } catch (err) {
61
- setError(err instanceof Error ? err : new Error('Unknown error'));
62
- } finally {
63
- setLoading(false);
64
- }
65
- }, [agent, projectId, options.agentId, options.status, options.limit, page]);
43
+ try {
44
+ const [runsResult, metricsResult] = await Promise.all([
45
+ agent.listRuns({
46
+ projectId,
47
+ agentId: options.agentId,
48
+ status: options.status === 'all' ? undefined : options.status,
49
+ limit: options.limit ?? 20,
50
+ offset: (page - 1) * (options.limit ?? 20),
51
+ }),
52
+ agent.getRunMetrics({
53
+ projectId,
54
+ agentId: options.agentId,
55
+ startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), // 30 days ago
56
+ endDate: new Date(),
57
+ }),
58
+ ]);
59
+ setData(runsResult);
60
+ setMetrics(metricsResult);
61
+ } catch (err) {
62
+ setError(err instanceof Error ? err : new Error('Unknown error'));
63
+ } finally {
64
+ setLoading(false);
65
+ }
66
+ }, [agent, projectId, options.agentId, options.status, options.limit, page]);
66
67
 
67
- useEffect(() => {
68
- fetchData();
69
- }, [fetchData]);
68
+ useEffect(() => {
69
+ fetchData();
70
+ }, [fetchData]);
70
71
 
71
- return {
72
- data,
73
- metrics,
74
- loading,
75
- error,
76
- page,
77
- refetch: fetchData,
78
- nextPage: () => setPage((p) => p + 1),
79
- prevPage: () => page > 1 && setPage((p) => p - 1),
80
- };
72
+ return {
73
+ data,
74
+ metrics,
75
+ loading,
76
+ error,
77
+ page,
78
+ refetch: fetchData,
79
+ nextPage: () => setPage((p) => p + 1),
80
+ prevPage: () => page > 1 && setPage((p) => p - 1),
81
+ };
81
82
  }