@contractspec/example.agent-console 3.8.8 → 3.8.10

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 (228) hide show
  1. package/.turbo/turbo-build.log +225 -222
  2. package/CHANGELOG.md +34 -0
  3. package/dist/agent/agent.entity.js +1 -127
  4. package/dist/agent/agent.enum.js +1 -25
  5. package/dist/agent/agent.event.js +1 -116
  6. package/dist/agent/agent.handler.js +1 -1030
  7. package/dist/agent/agent.operation.js +1 -735
  8. package/dist/agent/agent.presentation.js +1 -282
  9. package/dist/agent/agent.schema.js +1 -215
  10. package/dist/agent/agent.test-spec.js +1 -58
  11. package/dist/agent/index.js +1 -1248
  12. package/dist/agent.capability.js +1 -19
  13. package/dist/agent.feature.js +1 -305
  14. package/dist/browser/agent/agent.entity.js +1 -127
  15. package/dist/browser/agent/agent.enum.js +1 -25
  16. package/dist/browser/agent/agent.event.js +1 -116
  17. package/dist/browser/agent/agent.handler.js +1 -1030
  18. package/dist/browser/agent/agent.operation.js +1 -735
  19. package/dist/browser/agent/agent.presentation.js +1 -282
  20. package/dist/browser/agent/agent.schema.js +1 -215
  21. package/dist/browser/agent/agent.test-spec.js +1 -58
  22. package/dist/browser/agent/index.js +1 -1248
  23. package/dist/browser/agent.capability.js +1 -19
  24. package/dist/browser/agent.feature.js +1 -305
  25. package/dist/browser/docs/agent-console.docblock.js +5 -49
  26. package/dist/browser/docs/index.js +5 -49
  27. package/dist/browser/example.js +1 -41
  28. package/dist/browser/handlers/agent.handlers.js +6 -2143
  29. package/dist/browser/handlers/index.js +6 -2943
  30. package/dist/browser/index.js +14 -6828
  31. package/dist/browser/presentations/index.js +1 -693
  32. package/dist/browser/run/index.js +1 -1363
  33. package/dist/browser/run/run.entity.js +1 -160
  34. package/dist/browser/run/run.enum.js +1 -34
  35. package/dist/browser/run/run.event.js +1 -217
  36. package/dist/browser/run/run.handler.js +1 -919
  37. package/dist/browser/run/run.operation.js +1 -667
  38. package/dist/browser/run/run.presentation.js +1 -223
  39. package/dist/browser/run/run.schema.js +1 -179
  40. package/dist/browser/run/run.test-spec.js +1 -58
  41. package/dist/browser/seeders/index.js +2 -21
  42. package/dist/browser/shared/index.js +1 -626
  43. package/dist/browser/shared/mock-agents.js +1 -82
  44. package/dist/browser/shared/mock-runs.js +1 -113
  45. package/dist/browser/shared/mock-tools.js +1 -146
  46. package/dist/browser/tool/index.js +1 -949
  47. package/dist/browser/tool/tool.entity.js +1 -90
  48. package/dist/browser/tool/tool.enum.js +1 -26
  49. package/dist/browser/tool/tool.event.js +1 -99
  50. package/dist/browser/tool/tool.handler.js +1 -699
  51. package/dist/browser/tool/tool.operation.js +1 -482
  52. package/dist/browser/tool/tool.presentation.js +1 -188
  53. package/dist/browser/tool/tool.schema.js +1 -141
  54. package/dist/browser/tool/tool.test-spec.js +1 -58
  55. package/dist/browser/ui/AgentDashboard.js +1 -2527
  56. package/dist/browser/ui/AgentDashboard.visualizations.js +1 -217
  57. package/dist/browser/ui/AgentRunList.js +1 -482
  58. package/dist/browser/ui/AgentToolRegistry.js +1 -212
  59. package/dist/browser/ui/ExecutionConsoleHost.js +1 -0
  60. package/dist/browser/ui/hooks/index.js +1 -740
  61. package/dist/browser/ui/hooks/useAgentList.js +1 -55
  62. package/dist/browser/ui/hooks/useAgentMutations.js +1 -530
  63. package/dist/browser/ui/hooks/useRunList.js +1 -70
  64. package/dist/browser/ui/hooks/useToolList.js +1 -85
  65. package/dist/browser/ui/index.js +5 -3018
  66. package/dist/browser/ui/modals/AgentActionsModal.js +1 -304
  67. package/dist/browser/ui/modals/CreateAgentModal.js +1 -243
  68. package/dist/browser/ui/modals/index.js +1 -546
  69. package/dist/browser/ui/overlays/demo-overlays.js +1 -64
  70. package/dist/browser/ui/overlays/index.js +1 -64
  71. package/dist/browser/ui/renderers/agent-list.markdown.js +2 -64
  72. package/dist/browser/ui/renderers/agent-list.renderer.js +1 -180
  73. package/dist/browser/ui/renderers/dashboard.markdown.js +2 -288
  74. package/dist/browser/ui/renderers/index.js +5 -642
  75. package/dist/browser/ui/renderers/run-list.markdown.js +2 -50
  76. package/dist/browser/ui/renderers/tool-registry.markdown.js +2 -64
  77. package/dist/browser/ui/views/AgentListView.js +1 -165
  78. package/dist/browser/ui/views/RunDataTable.js +1 -326
  79. package/dist/browser/ui/views/RunListView.js +1 -479
  80. package/dist/browser/ui/views/ToolRegistryView.js +1 -209
  81. package/dist/browser/ui/views/index.js +1 -851
  82. package/dist/browser/ui/views/run-data-table.columns.js +1 -271
  83. package/dist/browser/ui/views/run-list.shared.js +1 -177
  84. package/dist/browser/visualizations/catalog.js +1 -134
  85. package/dist/browser/visualizations/index.js +1 -187
  86. package/dist/browser/visualizations/selectors.js +1 -181
  87. package/dist/docs/agent-console.docblock.js +5 -49
  88. package/dist/docs/index.js +5 -49
  89. package/dist/example.js +1 -41
  90. package/dist/handlers/agent.handlers.js +6 -2143
  91. package/dist/handlers/index.js +6 -2943
  92. package/dist/index.js +14 -6828
  93. package/dist/node/agent/agent.entity.js +1 -127
  94. package/dist/node/agent/agent.enum.js +1 -25
  95. package/dist/node/agent/agent.event.js +1 -116
  96. package/dist/node/agent/agent.handler.js +1 -1030
  97. package/dist/node/agent/agent.operation.js +1 -735
  98. package/dist/node/agent/agent.presentation.js +1 -282
  99. package/dist/node/agent/agent.schema.js +1 -215
  100. package/dist/node/agent/agent.test-spec.js +1 -58
  101. package/dist/node/agent/index.js +1 -1248
  102. package/dist/node/agent.capability.js +1 -19
  103. package/dist/node/agent.feature.js +1 -305
  104. package/dist/node/docs/agent-console.docblock.js +5 -49
  105. package/dist/node/docs/index.js +5 -49
  106. package/dist/node/example.js +1 -41
  107. package/dist/node/handlers/agent.handlers.js +6 -2143
  108. package/dist/node/handlers/index.js +6 -2943
  109. package/dist/node/index.js +14 -6828
  110. package/dist/node/presentations/index.js +1 -693
  111. package/dist/node/run/index.js +1 -1363
  112. package/dist/node/run/run.entity.js +1 -160
  113. package/dist/node/run/run.enum.js +1 -34
  114. package/dist/node/run/run.event.js +1 -217
  115. package/dist/node/run/run.handler.js +1 -919
  116. package/dist/node/run/run.operation.js +1 -667
  117. package/dist/node/run/run.presentation.js +1 -223
  118. package/dist/node/run/run.schema.js +1 -179
  119. package/dist/node/run/run.test-spec.js +1 -58
  120. package/dist/node/seeders/index.js +2 -21
  121. package/dist/node/shared/index.js +1 -626
  122. package/dist/node/shared/mock-agents.js +1 -82
  123. package/dist/node/shared/mock-runs.js +1 -113
  124. package/dist/node/shared/mock-tools.js +1 -146
  125. package/dist/node/tool/index.js +1 -949
  126. package/dist/node/tool/tool.entity.js +1 -90
  127. package/dist/node/tool/tool.enum.js +1 -26
  128. package/dist/node/tool/tool.event.js +1 -99
  129. package/dist/node/tool/tool.handler.js +1 -699
  130. package/dist/node/tool/tool.operation.js +1 -482
  131. package/dist/node/tool/tool.presentation.js +1 -188
  132. package/dist/node/tool/tool.schema.js +1 -141
  133. package/dist/node/tool/tool.test-spec.js +1 -58
  134. package/dist/node/ui/AgentDashboard.js +1 -2527
  135. package/dist/node/ui/AgentDashboard.visualizations.js +1 -217
  136. package/dist/node/ui/AgentRunList.js +1 -482
  137. package/dist/node/ui/AgentToolRegistry.js +1 -212
  138. package/dist/node/ui/ExecutionConsoleHost.js +1 -0
  139. package/dist/node/ui/hooks/index.js +1 -740
  140. package/dist/node/ui/hooks/useAgentList.js +1 -55
  141. package/dist/node/ui/hooks/useAgentMutations.js +1 -530
  142. package/dist/node/ui/hooks/useRunList.js +1 -70
  143. package/dist/node/ui/hooks/useToolList.js +1 -85
  144. package/dist/node/ui/index.js +5 -3018
  145. package/dist/node/ui/modals/AgentActionsModal.js +1 -304
  146. package/dist/node/ui/modals/CreateAgentModal.js +1 -243
  147. package/dist/node/ui/modals/index.js +1 -546
  148. package/dist/node/ui/overlays/demo-overlays.js +1 -64
  149. package/dist/node/ui/overlays/index.js +1 -64
  150. package/dist/node/ui/renderers/agent-list.markdown.js +2 -64
  151. package/dist/node/ui/renderers/agent-list.renderer.js +1 -180
  152. package/dist/node/ui/renderers/dashboard.markdown.js +2 -288
  153. package/dist/node/ui/renderers/index.js +5 -642
  154. package/dist/node/ui/renderers/run-list.markdown.js +2 -50
  155. package/dist/node/ui/renderers/tool-registry.markdown.js +2 -64
  156. package/dist/node/ui/views/AgentListView.js +1 -165
  157. package/dist/node/ui/views/RunDataTable.js +1 -326
  158. package/dist/node/ui/views/RunListView.js +1 -479
  159. package/dist/node/ui/views/ToolRegistryView.js +1 -209
  160. package/dist/node/ui/views/index.js +1 -851
  161. package/dist/node/ui/views/run-data-table.columns.js +1 -271
  162. package/dist/node/ui/views/run-list.shared.js +1 -177
  163. package/dist/node/visualizations/catalog.js +1 -134
  164. package/dist/node/visualizations/index.js +1 -187
  165. package/dist/node/visualizations/selectors.js +1 -181
  166. package/dist/presentations/index.js +1 -693
  167. package/dist/run/index.js +1 -1363
  168. package/dist/run/run.entity.js +1 -160
  169. package/dist/run/run.enum.js +1 -34
  170. package/dist/run/run.event.js +1 -217
  171. package/dist/run/run.handler.js +1 -919
  172. package/dist/run/run.operation.js +1 -667
  173. package/dist/run/run.presentation.js +1 -223
  174. package/dist/run/run.schema.js +1 -179
  175. package/dist/run/run.test-spec.js +1 -58
  176. package/dist/seeders/index.js +2 -21
  177. package/dist/shared/index.js +1 -626
  178. package/dist/shared/mock-agents.js +1 -82
  179. package/dist/shared/mock-runs.js +1 -113
  180. package/dist/shared/mock-tools.js +1 -146
  181. package/dist/tool/index.js +1 -949
  182. package/dist/tool/tool.entity.js +1 -90
  183. package/dist/tool/tool.enum.js +1 -26
  184. package/dist/tool/tool.event.js +1 -99
  185. package/dist/tool/tool.handler.js +1 -699
  186. package/dist/tool/tool.operation.js +1 -482
  187. package/dist/tool/tool.presentation.js +1 -188
  188. package/dist/tool/tool.schema.js +1 -141
  189. package/dist/tool/tool.test-spec.js +1 -58
  190. package/dist/ui/AgentDashboard.js +1 -2527
  191. package/dist/ui/AgentDashboard.visualizations.js +1 -217
  192. package/dist/ui/AgentRunList.js +1 -482
  193. package/dist/ui/AgentToolRegistry.js +1 -212
  194. package/dist/ui/ExecutionConsoleHost.d.ts +1 -0
  195. package/dist/ui/ExecutionConsoleHost.js +2 -0
  196. package/dist/ui/ExecutionConsoleHost.test.d.ts +1 -0
  197. package/dist/ui/hooks/index.js +1 -740
  198. package/dist/ui/hooks/useAgentList.js +1 -55
  199. package/dist/ui/hooks/useAgentMutations.js +1 -530
  200. package/dist/ui/hooks/useRunList.js +1 -70
  201. package/dist/ui/hooks/useToolList.js +1 -85
  202. package/dist/ui/index.d.ts +1 -0
  203. package/dist/ui/index.js +5 -3018
  204. package/dist/ui/modals/AgentActionsModal.js +1 -304
  205. package/dist/ui/modals/CreateAgentModal.js +1 -243
  206. package/dist/ui/modals/index.js +1 -546
  207. package/dist/ui/overlays/demo-overlays.js +1 -64
  208. package/dist/ui/overlays/index.js +1 -64
  209. package/dist/ui/renderers/agent-list.markdown.js +2 -64
  210. package/dist/ui/renderers/agent-list.renderer.js +1 -180
  211. package/dist/ui/renderers/dashboard.markdown.js +2 -288
  212. package/dist/ui/renderers/index.js +5 -642
  213. package/dist/ui/renderers/run-list.markdown.js +2 -50
  214. package/dist/ui/renderers/tool-registry.markdown.js +2 -64
  215. package/dist/ui/views/AgentListView.js +1 -165
  216. package/dist/ui/views/RunDataTable.js +1 -326
  217. package/dist/ui/views/RunListView.js +1 -479
  218. package/dist/ui/views/ToolRegistryView.js +1 -209
  219. package/dist/ui/views/index.js +1 -851
  220. package/dist/ui/views/run-data-table.columns.js +1 -271
  221. package/dist/ui/views/run-list.shared.js +1 -177
  222. package/dist/visualizations/catalog.js +1 -134
  223. package/dist/visualizations/index.js +1 -187
  224. package/dist/visualizations/selectors.js +1 -181
  225. package/package.json +29 -13
  226. package/src/ui/ExecutionConsoleHost.test.tsx +110 -0
  227. package/src/ui/ExecutionConsoleHost.tsx +14 -0
  228. package/src/ui/index.ts +1 -1
@@ -1,852 +1,2 @@
1
1
  // @bun
2
- // src/ui/hooks/useAgentList.ts
3
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
- import { useCallback, useEffect, useMemo, useState } from "react";
5
- function useAgentList(options = {}) {
6
- const { handlers, projectId } = useTemplateRuntime();
7
- const { agent } = handlers;
8
- const [data, setData] = useState(null);
9
- const [loading, setLoading] = useState(true);
10
- const [error, setError] = useState(null);
11
- const [page, setPage] = useState(1);
12
- const fetchData = useCallback(async () => {
13
- setLoading(true);
14
- setError(null);
15
- try {
16
- const result = await agent.listAgents({
17
- projectId,
18
- search: options.search,
19
- status: options.status === "all" ? undefined : options.status,
20
- limit: options.limit ?? 20,
21
- offset: (page - 1) * (options.limit ?? 20)
22
- });
23
- setData(result);
24
- } catch (err) {
25
- setError(err instanceof Error ? err : new Error("Unknown error"));
26
- } finally {
27
- setLoading(false);
28
- }
29
- }, [agent, projectId, options.search, options.status, options.limit, page]);
30
- useEffect(() => {
31
- fetchData();
32
- }, [fetchData]);
33
- const stats = useMemo(() => {
34
- if (!data)
35
- return null;
36
- return {
37
- total: data.total,
38
- active: data.items.filter((a) => a.status === "ACTIVE").length,
39
- paused: data.items.filter((a) => a.status === "PAUSED").length,
40
- draft: data.items.filter((a) => a.status === "DRAFT").length
41
- };
42
- }, [data]);
43
- return {
44
- data,
45
- loading,
46
- error,
47
- stats,
48
- page,
49
- refetch: fetchData,
50
- nextPage: () => setPage((p) => p + 1),
51
- prevPage: () => page > 1 && setPage((p) => p - 1)
52
- };
53
- }
54
-
55
- // src/ui/hooks/useRunList.ts
56
- import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
57
- import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
58
- function useRunList(options = {}) {
59
- const { handlers, projectId } = useTemplateRuntime2();
60
- const { agent } = handlers;
61
- const [data, setData] = useState2(null);
62
- const [metrics, setMetrics] = useState2(null);
63
- const [loading, setLoading] = useState2(true);
64
- const [error, setError] = useState2(null);
65
- const [internalPageIndex, setInternalPageIndex] = useState2(0);
66
- const pageSize = options.pageSize ?? options.limit ?? 20;
67
- const pageIndex = options.pageIndex ?? internalPageIndex;
68
- const [sort] = options.sorting ?? [];
69
- const fetchData = useCallback2(async () => {
70
- setLoading(true);
71
- setError(null);
72
- try {
73
- const [runsResult, metricsResult] = await Promise.all([
74
- agent.listRuns({
75
- projectId,
76
- agentId: options.agentId,
77
- status: options.status === "all" ? undefined : options.status,
78
- sortBy: sort?.id,
79
- sortDirection: sort ? sort.desc ? "desc" : "asc" : undefined,
80
- limit: pageSize,
81
- offset: pageIndex * pageSize
82
- }),
83
- agent.getRunMetrics({
84
- projectId,
85
- agentId: options.agentId
86
- })
87
- ]);
88
- setData(runsResult);
89
- setMetrics(metricsResult);
90
- } catch (err) {
91
- setError(err instanceof Error ? err : new Error("Unknown error"));
92
- } finally {
93
- setLoading(false);
94
- }
95
- }, [
96
- agent,
97
- pageIndex,
98
- pageSize,
99
- projectId,
100
- options.agentId,
101
- options.status,
102
- sort?.desc,
103
- sort?.id
104
- ]);
105
- useEffect2(() => {
106
- fetchData();
107
- }, [fetchData]);
108
- const hasControlledPagination = options.pageIndex !== undefined;
109
- return {
110
- data,
111
- metrics,
112
- loading,
113
- error,
114
- page: pageIndex + 1,
115
- pageIndex,
116
- pageSize,
117
- refetch: fetchData,
118
- nextPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => current + 1),
119
- prevPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => Math.max(0, current - 1))
120
- };
121
- }
122
-
123
- // src/ui/views/run-list.shared.tsx
124
- import { Button, StatusChip } from "@contractspec/lib.design-system";
125
- import { HStack, VStack } from "@contractspec/lib.ui-kit-web/ui/stack";
126
- import { Text } from "@contractspec/lib.ui-kit-web/ui/text";
127
- import { jsxDEV } from "react/jsx-dev-runtime";
128
- "use client";
129
- function getStatusTone(status) {
130
- switch (status) {
131
- case "COMPLETED":
132
- return "success";
133
- case "RUNNING":
134
- return "warning";
135
- case "QUEUED":
136
- return "neutral";
137
- case "FAILED":
138
- case "CANCELLED":
139
- return "danger";
140
- default:
141
- return "neutral";
142
- }
143
- }
144
- function formatDuration(ms) {
145
- if (!ms)
146
- return "-";
147
- if (ms < 1000)
148
- return `${ms}ms`;
149
- if (ms < 60000)
150
- return `${(ms / 1000).toFixed(1)}s`;
151
- return `${(ms / 60000).toFixed(1)}m`;
152
- }
153
- function formatTokens(tokens) {
154
- if (tokens < 1000)
155
- return tokens.toString();
156
- if (tokens < 1e6)
157
- return `${(tokens / 1000).toFixed(1)}K`;
158
- return `${(tokens / 1e6).toFixed(2)}M`;
159
- }
160
- function formatCost(cost) {
161
- if (!cost)
162
- return "-";
163
- return `$${cost.toFixed(4)}`;
164
- }
165
- function formatJson(value) {
166
- return JSON.stringify(value ?? null, null, 2);
167
- }
168
- function RunExpandedContent({ run }) {
169
- return /* @__PURE__ */ jsxDEV(VStack, {
170
- gap: "sm",
171
- className: "py-2",
172
- children: [
173
- /* @__PURE__ */ jsxDEV(HStack, {
174
- justify: "between",
175
- className: "flex-wrap",
176
- children: [
177
- /* @__PURE__ */ jsxDEV(StatusChip, {
178
- tone: getStatusTone(run.status),
179
- label: run.status
180
- }, undefined, false, undefined, this),
181
- /* @__PURE__ */ jsxDEV(Text, {
182
- className: "text-muted-foreground text-sm",
183
- children: [
184
- "Queued ",
185
- run.queuedAt.toLocaleString()
186
- ]
187
- }, undefined, true, undefined, this)
188
- ]
189
- }, undefined, true, undefined, this),
190
- /* @__PURE__ */ jsxDEV(HStack, {
191
- gap: "lg",
192
- className: "flex-wrap",
193
- children: [
194
- /* @__PURE__ */ jsxDEV(Text, {
195
- className: "text-muted-foreground text-sm",
196
- children: [
197
- "Prompt ",
198
- formatTokens(run.promptTokens)
199
- ]
200
- }, undefined, true, undefined, this),
201
- /* @__PURE__ */ jsxDEV(Text, {
202
- className: "text-muted-foreground text-sm",
203
- children: [
204
- "Completion ",
205
- formatTokens(run.completionTokens)
206
- ]
207
- }, undefined, true, undefined, this),
208
- /* @__PURE__ */ jsxDEV(Text, {
209
- className: "text-muted-foreground text-sm",
210
- children: [
211
- "Duration ",
212
- formatDuration(run.durationMs)
213
- ]
214
- }, undefined, true, undefined, this)
215
- ]
216
- }, undefined, true, undefined, this),
217
- /* @__PURE__ */ jsxDEV(VStack, {
218
- gap: "xs",
219
- children: [
220
- /* @__PURE__ */ jsxDEV(Text, {
221
- className: "font-medium text-sm",
222
- children: "Input"
223
- }, undefined, false, undefined, this),
224
- /* @__PURE__ */ jsxDEV("pre", {
225
- className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
226
- children: formatJson(run.input)
227
- }, undefined, false, undefined, this)
228
- ]
229
- }, undefined, true, undefined, this),
230
- /* @__PURE__ */ jsxDEV(VStack, {
231
- gap: "xs",
232
- children: [
233
- /* @__PURE__ */ jsxDEV(Text, {
234
- className: "font-medium text-sm",
235
- children: "Output"
236
- }, undefined, false, undefined, this),
237
- /* @__PURE__ */ jsxDEV("pre", {
238
- className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
239
- children: formatJson(run.output ?? run.errorMessage ?? "Pending")
240
- }, undefined, false, undefined, this)
241
- ]
242
- }, undefined, true, undefined, this)
243
- ]
244
- }, undefined, true, undefined, this);
245
- }
246
- function RunTableToolbar({
247
- controller,
248
- totalRuns
249
- }) {
250
- const firstRow = controller.rows[0];
251
- const queuedColumn = controller.columns.find((column) => column.id === "queuedAt");
252
- const durationColumn = controller.columns.find((column) => column.id === "durationMs");
253
- const costColumn = controller.columns.find((column) => column.id === "estimatedCostUsd");
254
- return /* @__PURE__ */ jsxDEV(HStack, {
255
- gap: "sm",
256
- className: "flex-wrap",
257
- children: [
258
- /* @__PURE__ */ jsxDEV(Text, {
259
- className: "text-muted-foreground text-sm",
260
- children: [
261
- totalRuns,
262
- " runs"
263
- ]
264
- }, undefined, true, undefined, this),
265
- /* @__PURE__ */ jsxDEV(Button, {
266
- variant: "outline",
267
- size: "sm",
268
- onPress: () => firstRow?.toggleExpanded?.(!firstRow?.isExpanded),
269
- children: "Expand Latest Run"
270
- }, undefined, false, undefined, this),
271
- /* @__PURE__ */ jsxDEV(Button, {
272
- variant: "outline",
273
- size: "sm",
274
- onPress: () => queuedColumn?.toggleVisibility?.(!queuedColumn?.visible),
275
- children: queuedColumn?.visible ? "Hide Time" : "Show Time"
276
- }, undefined, false, undefined, this),
277
- /* @__PURE__ */ jsxDEV(Button, {
278
- variant: "outline",
279
- size: "sm",
280
- onPress: () => durationColumn?.toggleVisibility?.(!durationColumn?.visible),
281
- children: durationColumn?.visible ? "Hide Duration" : "Show Duration"
282
- }, undefined, false, undefined, this),
283
- /* @__PURE__ */ jsxDEV(Button, {
284
- variant: "outline",
285
- size: "sm",
286
- onPress: () => costColumn?.toggleVisibility?.(!costColumn?.visible),
287
- children: costColumn?.visible ? "Hide Cost" : "Show Cost"
288
- }, undefined, false, undefined, this)
289
- ]
290
- }, undefined, true, undefined, this);
291
- }
292
-
293
- // src/ui/views/run-data-table.columns.tsx
294
- import { StatusChip as StatusChip2 } from "@contractspec/lib.design-system";
295
- import { VStack as VStack2 } from "@contractspec/lib.ui-kit-web/ui/stack";
296
- import { Text as Text2 } from "@contractspec/lib.ui-kit-web/ui/text";
297
- import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
298
- "use client";
299
- function createRunTableColumns() {
300
- return [
301
- {
302
- id: "queuedAt",
303
- header: "Run",
304
- label: "Run",
305
- accessor: (run) => run.queuedAt.getTime(),
306
- cell: ({ item }) => /* @__PURE__ */ jsxDEV2(VStack2, {
307
- gap: "xs",
308
- children: [
309
- /* @__PURE__ */ jsxDEV2(Text2, {
310
- className: "font-mono text-sm",
311
- children: item.id.slice(-8)
312
- }, undefined, false, undefined, this),
313
- /* @__PURE__ */ jsxDEV2(Text2, {
314
- className: "text-muted-foreground text-xs",
315
- children: item.queuedAt.toLocaleString()
316
- }, undefined, false, undefined, this)
317
- ]
318
- }, undefined, true, undefined, this),
319
- size: 220,
320
- minSize: 180,
321
- canSort: true,
322
- canHide: true,
323
- canResize: true
324
- },
325
- {
326
- id: "agentName",
327
- header: "Agent",
328
- label: "Agent",
329
- accessor: (run) => run.agentName ?? "Unknown Agent",
330
- cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Text2, {
331
- className: "font-medium",
332
- children: typeof value === "string" ? value : "Unknown Agent"
333
- }, undefined, false, undefined, this),
334
- size: 220,
335
- canSort: true,
336
- canResize: true
337
- },
338
- {
339
- id: "status",
340
- header: "Status",
341
- label: "Status",
342
- accessorKey: "status",
343
- cell: ({ value }) => {
344
- const status = typeof value === "string" ? value : "QUEUED";
345
- return /* @__PURE__ */ jsxDEV2(StatusChip2, {
346
- tone: getStatusTone(status),
347
- label: status
348
- }, undefined, false, undefined, this);
349
- },
350
- size: 150,
351
- canSort: true,
352
- canResize: true
353
- },
354
- {
355
- id: "totalTokens",
356
- header: "Tokens",
357
- label: "Tokens",
358
- accessorKey: "totalTokens",
359
- cell: ({ value }) => formatTokens(Number(value ?? 0)),
360
- align: "right",
361
- size: 140,
362
- canSort: true,
363
- canResize: true
364
- },
365
- {
366
- id: "durationMs",
367
- header: "Duration",
368
- label: "Duration",
369
- accessorKey: "durationMs",
370
- cell: ({ value }) => formatDuration(typeof value === "number" ? value : undefined),
371
- align: "right",
372
- size: 140,
373
- canSort: true,
374
- canHide: true,
375
- canResize: true
376
- },
377
- {
378
- id: "estimatedCostUsd",
379
- header: "Cost",
380
- label: "Cost",
381
- accessorKey: "estimatedCostUsd",
382
- cell: ({ value }) => formatCost(typeof value === "number" ? value : undefined),
383
- align: "right",
384
- size: 140,
385
- canSort: true,
386
- canHide: true,
387
- canResize: true
388
- }
389
- ];
390
- }
391
-
392
- // src/ui/views/RunDataTable.tsx
393
- import { DataTable } from "@contractspec/lib.design-system";
394
- import { useContractTable } from "@contractspec/lib.presentation-runtime-react";
395
- import * as React from "react";
396
- import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
397
- "use client";
398
- function RunDataTable({
399
- runs,
400
- totalItems,
401
- pageIndex,
402
- pageSize,
403
- sorting,
404
- loading,
405
- onSortingChange,
406
- onPaginationChange,
407
- onRunClick
408
- }) {
409
- const columns = React.useMemo(() => createRunTableColumns(), []);
410
- const controller = useContractTable({
411
- data: runs,
412
- columns,
413
- executionMode: "server",
414
- totalItems,
415
- state: {
416
- sorting,
417
- pagination: { pageIndex, pageSize }
418
- },
419
- onSortingChange,
420
- onPaginationChange,
421
- initialState: {
422
- columnVisibility: { estimatedCostUsd: false }
423
- },
424
- getRowId: (run) => run.id,
425
- renderExpandedContent: (run) => /* @__PURE__ */ jsxDEV3(RunExpandedContent, {
426
- run
427
- }, undefined, false, undefined, this),
428
- getCanExpand: () => true
429
- });
430
- return /* @__PURE__ */ jsxDEV3(DataTable, {
431
- controller,
432
- title: "Run History",
433
- description: "Server-mode ContractSpec table with shared pagination, sorting, visibility, and expansion.",
434
- loading,
435
- onRowPress: (row) => onRunClick?.(row.id),
436
- toolbar: /* @__PURE__ */ jsxDEV3(RunTableToolbar, {
437
- controller,
438
- totalRuns: totalItems
439
- }, undefined, false, undefined, this),
440
- emptyState: /* @__PURE__ */ jsxDEV3("div", {
441
- className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
442
- children: "No runs yet"
443
- }, undefined, false, undefined, this)
444
- }, undefined, false, undefined, this);
445
- }
446
-
447
- // src/ui/views/RunListView.tsx
448
- import {
449
- EmptyState,
450
- ErrorState,
451
- LoaderBlock,
452
- StatCard,
453
- StatCardGroup
454
- } from "@contractspec/lib.design-system";
455
- import { useState as useState3 } from "react";
456
- import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
457
- "use client";
458
- function RunListView({ agentId, onRunClick }) {
459
- const [sorting, setSorting] = useState3([
460
- { id: "queuedAt", desc: true }
461
- ]);
462
- const [pagination, setPagination] = useState3({
463
- pageIndex: 0,
464
- pageSize: 3
465
- });
466
- const { data, metrics, loading, error, refetch } = useRunList({
467
- agentId,
468
- pageIndex: pagination.pageIndex,
469
- pageSize: pagination.pageSize,
470
- sorting
471
- });
472
- if (loading && !data) {
473
- return /* @__PURE__ */ jsxDEV4(LoaderBlock, {
474
- label: "Loading runs..."
475
- }, undefined, false, undefined, this);
476
- }
477
- if (error) {
478
- return /* @__PURE__ */ jsxDEV4(ErrorState, {
479
- title: "Failed to load runs",
480
- description: error.message,
481
- onRetry: refetch,
482
- retryLabel: "Retry"
483
- }, undefined, false, undefined, this);
484
- }
485
- if (!data?.items.length) {
486
- return /* @__PURE__ */ jsxDEV4(EmptyState, {
487
- title: "No runs yet",
488
- description: "Execute an agent to see run history here."
489
- }, undefined, false, undefined, this);
490
- }
491
- return /* @__PURE__ */ jsxDEV4("div", {
492
- className: "space-y-6",
493
- children: [
494
- metrics ? /* @__PURE__ */ jsxDEV4(StatCardGroup, {
495
- children: [
496
- /* @__PURE__ */ jsxDEV4(StatCard, {
497
- label: "Total Runs",
498
- value: metrics.totalRuns
499
- }, undefined, false, undefined, this),
500
- /* @__PURE__ */ jsxDEV4(StatCard, {
501
- label: "Success Rate",
502
- value: `${(metrics.successRate * 100).toFixed(1)}%`
503
- }, undefined, false, undefined, this),
504
- /* @__PURE__ */ jsxDEV4(StatCard, {
505
- label: "Total Tokens",
506
- value: formatTokens(metrics.totalTokens)
507
- }, undefined, false, undefined, this),
508
- /* @__PURE__ */ jsxDEV4(StatCard, {
509
- label: "Total Cost",
510
- value: `$${metrics.totalCostUsd.toFixed(2)}`
511
- }, undefined, false, undefined, this)
512
- ]
513
- }, undefined, true, undefined, this) : null,
514
- /* @__PURE__ */ jsxDEV4(RunDataTable, {
515
- runs: data.items,
516
- totalItems: data.total,
517
- pageIndex: pagination.pageIndex,
518
- pageSize: pagination.pageSize,
519
- sorting,
520
- loading,
521
- onSortingChange: (nextSorting) => {
522
- setSorting(nextSorting);
523
- setPagination((current) => ({ ...current, pageIndex: 0 }));
524
- },
525
- onPaginationChange: setPagination,
526
- onRunClick
527
- }, undefined, false, undefined, this)
528
- ]
529
- }, undefined, true, undefined, this);
530
- }
531
-
532
- // src/ui/hooks/useToolList.ts
533
- import { useTemplateRuntime as useTemplateRuntime3 } from "@contractspec/lib.example-shared-ui";
534
- import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useState as useState4 } from "react";
535
- function useToolList(options = {}) {
536
- const { handlers, projectId } = useTemplateRuntime3();
537
- const { agent } = handlers;
538
- const [data, setData] = useState4(null);
539
- const [loading, setLoading] = useState4(true);
540
- const [error, setError] = useState4(null);
541
- const [page, setPage] = useState4(1);
542
- const fetchData = useCallback3(async () => {
543
- setLoading(true);
544
- setError(null);
545
- try {
546
- const result = await agent.listTools({
547
- projectId,
548
- search: options.search,
549
- category: options.category,
550
- status: options.status === "all" ? undefined : options.status,
551
- limit: options.limit ?? 50,
552
- offset: (page - 1) * (options.limit ?? 50)
553
- });
554
- setData(result);
555
- } catch (err) {
556
- setError(err instanceof Error ? err : new Error("Unknown error"));
557
- } finally {
558
- setLoading(false);
559
- }
560
- }, [
561
- agent,
562
- projectId,
563
- options.search,
564
- options.category,
565
- options.status,
566
- options.limit,
567
- page
568
- ]);
569
- useEffect3(() => {
570
- fetchData();
571
- }, [fetchData]);
572
- const { stats, groupedByCategory, categoryStats } = useMemo3(() => {
573
- if (!data)
574
- return { stats: null, groupedByCategory: {}, categoryStats: [] };
575
- const items = data.items;
576
- const active = items.filter((t) => t.status === "ACTIVE").length;
577
- const deprecated = items.filter((t) => t.status === "DEPRECATED").length;
578
- const disabled = items.filter((t) => t.status === "DISABLED").length;
579
- const grouped = {};
580
- const byCategory = {};
581
- items.forEach((t) => {
582
- const cat = t.category;
583
- if (!grouped[cat])
584
- grouped[cat] = [];
585
- grouped[cat].push(t);
586
- byCategory[cat] = (byCategory[cat] || 0) + 1;
587
- });
588
- const catStats = Object.entries(byCategory).map(([category, count]) => ({ category, count })).sort((a, b) => b.count - a.count);
589
- return {
590
- stats: {
591
- total: data.total,
592
- active,
593
- deprecated,
594
- disabled,
595
- topCategories: catStats.slice(0, 5)
596
- },
597
- groupedByCategory: grouped,
598
- categoryStats: catStats
599
- };
600
- }, [data]);
601
- return {
602
- data,
603
- loading,
604
- error,
605
- stats,
606
- groupedByCategory,
607
- categoryStats,
608
- page,
609
- refetch: fetchData,
610
- nextPage: () => setPage((p) => p + 1),
611
- prevPage: () => page > 1 && setPage((p) => p - 1)
612
- };
613
- }
614
-
615
- // src/ui/views/ToolRegistryView.tsx
616
- import {
617
- Button as Button2,
618
- EmptyState as EmptyState2,
619
- EntityCard,
620
- ErrorState as ErrorState2,
621
- LoaderBlock as LoaderBlock2,
622
- StatCard as StatCard2,
623
- StatCardGroup as StatCardGroup2,
624
- StatusChip as StatusChip3
625
- } from "@contractspec/lib.design-system";
626
- import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
627
- "use client";
628
- var categoryIcons = {
629
- RETRIEVAL: "\uD83D\uDD0D",
630
- COMPUTATION: "\uD83E\uDDEE",
631
- COMMUNICATION: "\uD83D\uDCE7",
632
- INTEGRATION: "\uD83D\uDD17",
633
- UTILITY: "\uD83D\uDEE0\uFE0F",
634
- CUSTOM: "\u2699\uFE0F"
635
- };
636
- function getStatusTone2(status) {
637
- switch (status) {
638
- case "ACTIVE":
639
- return "success";
640
- case "DRAFT":
641
- return "neutral";
642
- case "DEPRECATED":
643
- return "warning";
644
- case "DISABLED":
645
- return "danger";
646
- default:
647
- return "neutral";
648
- }
649
- }
650
- function ToolRegistryView({
651
- onToolClick,
652
- onCreateTool
653
- }) {
654
- const { data, loading, error, groupedByCategory, categoryStats, refetch } = useToolList();
655
- if (loading && !data) {
656
- return /* @__PURE__ */ jsxDEV5(LoaderBlock2, {
657
- label: "Loading tools..."
658
- }, undefined, false, undefined, this);
659
- }
660
- if (error) {
661
- return /* @__PURE__ */ jsxDEV5(ErrorState2, {
662
- title: "Failed to load tools",
663
- description: error.message,
664
- onRetry: refetch,
665
- retryLabel: "Retry"
666
- }, undefined, false, undefined, this);
667
- }
668
- if (!data?.items.length) {
669
- return /* @__PURE__ */ jsxDEV5(EmptyState2, {
670
- title: "No tools registered",
671
- description: "Create your first tool to extend agent capabilities.",
672
- primaryAction: onCreateTool ? /* @__PURE__ */ jsxDEV5(Button2, {
673
- onPress: onCreateTool,
674
- children: "Create Tool"
675
- }, undefined, false, undefined, this) : undefined
676
- }, undefined, false, undefined, this);
677
- }
678
- return /* @__PURE__ */ jsxDEV5("div", {
679
- className: "space-y-8",
680
- children: [
681
- /* @__PURE__ */ jsxDEV5(StatCardGroup2, {
682
- children: [
683
- /* @__PURE__ */ jsxDEV5(StatCard2, {
684
- label: "Total Tools",
685
- value: data.total
686
- }, undefined, false, undefined, this),
687
- categoryStats.slice(0, 3).map(({ category, count }) => /* @__PURE__ */ jsxDEV5(StatCard2, {
688
- label: `${categoryIcons[category] ?? ""} ${category}`,
689
- value: count
690
- }, category, false, undefined, this))
691
- ]
692
- }, undefined, true, undefined, this),
693
- Object.entries(groupedByCategory).map(([category, tools]) => /* @__PURE__ */ jsxDEV5("section", {
694
- className: "space-y-4",
695
- children: [
696
- /* @__PURE__ */ jsxDEV5("div", {
697
- className: "flex items-center gap-2",
698
- children: [
699
- /* @__PURE__ */ jsxDEV5("span", {
700
- className: "text-2xl",
701
- children: categoryIcons[category]
702
- }, undefined, false, undefined, this),
703
- /* @__PURE__ */ jsxDEV5("h3", {
704
- className: "font-semibold text-lg",
705
- children: category
706
- }, undefined, false, undefined, this),
707
- /* @__PURE__ */ jsxDEV5("span", {
708
- className: "rounded-full bg-muted px-2 py-0.5 text-muted-foreground text-xs",
709
- children: tools.length
710
- }, undefined, false, undefined, this)
711
- ]
712
- }, undefined, true, undefined, this),
713
- /* @__PURE__ */ jsxDEV5("div", {
714
- className: "grid gap-4 md:grid-cols-2 lg:grid-cols-3",
715
- children: tools.map((tool) => /* @__PURE__ */ jsxDEV5(EntityCard, {
716
- cardTitle: tool.name,
717
- cardSubtitle: `v${tool.version}`,
718
- meta: /* @__PURE__ */ jsxDEV5("p", {
719
- className: "text-muted-foreground text-sm",
720
- children: tool.description
721
- }, undefined, false, undefined, this),
722
- chips: /* @__PURE__ */ jsxDEV5(StatusChip3, {
723
- tone: getStatusTone2(tool.status),
724
- label: tool.status
725
- }, undefined, false, undefined, this),
726
- footer: /* @__PURE__ */ jsxDEV5("code", {
727
- className: "text-muted-foreground text-xs",
728
- children: tool.name
729
- }, undefined, false, undefined, this),
730
- onClick: onToolClick ? () => onToolClick(tool.id) : undefined
731
- }, tool.id, false, undefined, this))
732
- }, undefined, false, undefined, this)
733
- ]
734
- }, category, true, undefined, this))
735
- ]
736
- }, undefined, true, undefined, this);
737
- }
738
-
739
- // src/ui/views/AgentListView.tsx
740
- import {
741
- Button as Button3,
742
- EmptyState as EmptyState3,
743
- EntityCard as EntityCard2,
744
- ErrorState as ErrorState3,
745
- LoaderBlock as LoaderBlock3,
746
- StatCard as StatCard3,
747
- StatCardGroup as StatCardGroup3,
748
- StatusChip as StatusChip4
749
- } from "@contractspec/lib.design-system";
750
- import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
751
- "use client";
752
- function getStatusTone3(status) {
753
- switch (status) {
754
- case "ACTIVE":
755
- return "success";
756
- case "PAUSED":
757
- case "DRAFT":
758
- return "warning";
759
- case "ARCHIVED":
760
- return "neutral";
761
- default:
762
- return "neutral";
763
- }
764
- }
765
- function AgentListView() {
766
- const { data, loading, error, stats, refetch } = useAgentList();
767
- if (loading && !data) {
768
- return /* @__PURE__ */ jsxDEV6(LoaderBlock3, {
769
- label: "Loading agents..."
770
- }, undefined, false, undefined, this);
771
- }
772
- if (error) {
773
- return /* @__PURE__ */ jsxDEV6(ErrorState3, {
774
- title: "Failed to load agents",
775
- description: error.message,
776
- onRetry: refetch,
777
- retryLabel: "Retry"
778
- }, undefined, false, undefined, this);
779
- }
780
- if (!data?.items.length) {
781
- return /* @__PURE__ */ jsxDEV6(EmptyState3, {
782
- title: "No agents yet",
783
- description: "Create your first AI agent to get started."
784
- }, undefined, false, undefined, this);
785
- }
786
- return /* @__PURE__ */ jsxDEV6("div", {
787
- className: "space-y-6",
788
- children: [
789
- stats && /* @__PURE__ */ jsxDEV6(StatCardGroup3, {
790
- children: [
791
- /* @__PURE__ */ jsxDEV6(StatCard3, {
792
- label: "Total Agents",
793
- value: stats.total
794
- }, undefined, false, undefined, this),
795
- /* @__PURE__ */ jsxDEV6(StatCard3, {
796
- label: "Active",
797
- value: stats.active
798
- }, undefined, false, undefined, this),
799
- /* @__PURE__ */ jsxDEV6(StatCard3, {
800
- label: "Paused",
801
- value: stats.paused
802
- }, undefined, false, undefined, this),
803
- /* @__PURE__ */ jsxDEV6(StatCard3, {
804
- label: "Draft",
805
- value: stats.draft
806
- }, undefined, false, undefined, this)
807
- ]
808
- }, undefined, true, undefined, this),
809
- /* @__PURE__ */ jsxDEV6("div", {
810
- className: "flex items-center justify-between",
811
- children: [
812
- /* @__PURE__ */ jsxDEV6("h3", {
813
- className: "font-semibold text-lg",
814
- children: "Agents"
815
- }, undefined, false, undefined, this),
816
- /* @__PURE__ */ jsxDEV6(Button3, {
817
- onPress: () => alert("Create Agent clicked!"),
818
- children: "Create Agent"
819
- }, undefined, false, undefined, this)
820
- ]
821
- }, undefined, true, undefined, this),
822
- /* @__PURE__ */ jsxDEV6("div", {
823
- className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
824
- children: data.items.map((agent) => /* @__PURE__ */ jsxDEV6(EntityCard2, {
825
- cardTitle: agent.name,
826
- cardSubtitle: agent.modelName,
827
- meta: /* @__PURE__ */ jsxDEV6("p", {
828
- className: "text-muted-foreground text-sm",
829
- children: agent.description
830
- }, undefined, false, undefined, this),
831
- chips: /* @__PURE__ */ jsxDEV6(StatusChip4, {
832
- tone: getStatusTone3(agent.status),
833
- label: agent.status
834
- }, undefined, false, undefined, this),
835
- footer: /* @__PURE__ */ jsxDEV6("span", {
836
- className: "text-muted-foreground text-xs",
837
- children: [
838
- "Created ",
839
- agent.createdAt.toLocaleDateString()
840
- ]
841
- }, undefined, true, undefined, this),
842
- onClick: () => alert(`View agent: ${agent.name}`)
843
- }, agent.id, false, undefined, this))
844
- }, undefined, false, undefined, this)
845
- ]
846
- }, undefined, true, undefined, this);
847
- }
848
- export {
849
- ToolRegistryView,
850
- RunListView,
851
- AgentListView
852
- };
2
+ import{useTemplateRuntime as YF}from"@contractspec/lib.example-shared-ui";import{useCallback as ZF,useEffect as _F,useMemo as $F,useState as T}from"react";function r(F={}){let{handlers:Y,projectId:W}=YF(),{agent:N}=Y,[K,O]=T(null),[Z,J]=T(!0),[$,U]=T(null),[Q,q]=T(1),V=ZF(async()=>{J(!0),U(null);try{let X=await N.listAgents({projectId:W,search:F.search,status:F.status==="all"?void 0:F.status,limit:F.limit??20,offset:(Q-1)*(F.limit??20)});O(X)}catch(X){U(X instanceof Error?X:Error("Unknown error"))}finally{J(!1)}},[N,W,F.search,F.status,F.limit,Q]);_F(()=>{V()},[V]);let D=$F(()=>{if(!K)return null;return{total:K.total,active:K.items.filter((X)=>X.status==="ACTIVE").length,paused:K.items.filter((X)=>X.status==="PAUSED").length,draft:K.items.filter((X)=>X.status==="DRAFT").length}},[K]);return{data:K,loading:Z,error:$,stats:D,page:Q,refetch:V,nextPage:()=>q((X)=>X+1),prevPage:()=>Q>1&&q((X)=>X-1)}}import{useTemplateRuntime as UF}from"@contractspec/lib.example-shared-ui";import{useCallback as JF,useEffect as qF,useState as I}from"react";function n(F={}){let{handlers:Y,projectId:W}=UF(),{agent:N}=Y,[K,O]=I(null),[Z,J]=I(null),[$,U]=I(!0),[Q,q]=I(null),[V,D]=I(0),X=F.pageSize??F.limit??20,E=F.pageIndex??V,[_]=F.sorting??[],f=JF(async()=>{U(!0),q(null);try{let[z,R]=await Promise.all([N.listRuns({projectId:W,agentId:F.agentId,status:F.status==="all"?void 0:F.status,sortBy:_?.id,sortDirection:_?_.desc?"desc":"asc":void 0,limit:X,offset:E*X}),N.getRunMetrics({projectId:W,agentId:F.agentId})]);O(z),J(R)}catch(z){q(z instanceof Error?z:Error("Unknown error"))}finally{U(!1)}},[N,E,X,W,F.agentId,F.status,_?.desc,_?.id]);qF(()=>{f()},[f]);let b=F.pageIndex!==void 0;return{data:K,metrics:Z,loading:$,error:Q,page:E+1,pageIndex:E,pageSize:X,refetch:f,nextPage:b?void 0:()=>D((z)=>z+1),prevPage:b?void 0:()=>D((z)=>Math.max(0,z-1))}}import{Button as k,StatusChip as GF}from"@contractspec/lib.design-system";import{HStack as g,VStack as p}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as L}from"@contractspec/lib.ui-kit-web/ui/text";import{jsx as B,jsxs as A}from"react/jsx-runtime";function c(F){switch(F){case"COMPLETED":return"success";case"RUNNING":return"warning";case"QUEUED":return"neutral";case"FAILED":case"CANCELLED":return"danger";default:return"neutral"}}function l(F){if(!F)return"-";if(F<1000)return`${F}ms`;if(F<60000)return`${(F/1000).toFixed(1)}s`;return`${(F/60000).toFixed(1)}m`}function v(F){if(F<1000)return F.toString();if(F<1e6)return`${(F/1000).toFixed(1)}K`;return`${(F/1e6).toFixed(2)}M`}function a(F){if(!F)return"-";return`$${F.toFixed(4)}`}function s(F){return JSON.stringify(F??null,null,2)}function e({run:F}){return A(p,{gap:"sm",className:"py-2",children:[A(g,{justify:"between",className:"flex-wrap",children:[B(GF,{tone:c(F.status),label:F.status}),A(L,{className:"text-muted-foreground text-sm",children:["Queued ",F.queuedAt.toLocaleString()]})]}),A(g,{gap:"lg",className:"flex-wrap",children:[A(L,{className:"text-muted-foreground text-sm",children:["Prompt ",v(F.promptTokens)]}),A(L,{className:"text-muted-foreground text-sm",children:["Completion ",v(F.completionTokens)]}),A(L,{className:"text-muted-foreground text-sm",children:["Duration ",l(F.durationMs)]})]}),A(p,{gap:"xs",children:[B(L,{className:"font-medium text-sm",children:"Input"}),B("pre",{className:"overflow-auto rounded-md bg-muted/40 p-3 text-xs",children:s(F.input)})]}),A(p,{gap:"xs",children:[B(L,{className:"font-medium text-sm",children:"Output"}),B("pre",{className:"overflow-auto rounded-md bg-muted/40 p-3 text-xs",children:s(F.output??F.errorMessage??"Pending")})]})]})}function o({controller:F,totalRuns:Y}){let W=F.rows[0],N=F.columns.find((Z)=>Z.id==="queuedAt"),K=F.columns.find((Z)=>Z.id==="durationMs"),O=F.columns.find((Z)=>Z.id==="estimatedCostUsd");return A(g,{gap:"sm",className:"flex-wrap",children:[A(L,{className:"text-muted-foreground text-sm",children:[Y," runs"]}),B(k,{variant:"outline",size:"sm",onPress:()=>W?.toggleExpanded?.(!W?.isExpanded),children:"Expand Latest Run"}),B(k,{variant:"outline",size:"sm",onPress:()=>N?.toggleVisibility?.(!N?.visible),children:N?.visible?"Hide Time":"Show Time"}),B(k,{variant:"outline",size:"sm",onPress:()=>K?.toggleVisibility?.(!K?.visible),children:K?.visible?"Hide Duration":"Show Duration"}),B(k,{variant:"outline",size:"sm",onPress:()=>O?.toggleVisibility?.(!O?.visible),children:O?.visible?"Hide Cost":"Show Cost"})]})}import{StatusChip as HF}from"@contractspec/lib.design-system";import{VStack as MF}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as u}from"@contractspec/lib.ui-kit-web/ui/text";import{jsx as h,jsxs as VF}from"react/jsx-runtime";function t(){return[{id:"queuedAt",header:"Run",label:"Run",accessor:(F)=>F.queuedAt.getTime(),cell:({item:F})=>VF(MF,{gap:"xs",children:[h(u,{className:"font-mono text-sm",children:F.id.slice(-8)}),h(u,{className:"text-muted-foreground text-xs",children:F.queuedAt.toLocaleString()})]}),size:220,minSize:180,canSort:!0,canHide:!0,canResize:!0},{id:"agentName",header:"Agent",label:"Agent",accessor:(F)=>F.agentName??"Unknown Agent",cell:({value:F})=>h(u,{className:"font-medium",children:typeof F==="string"?F:"Unknown Agent"}),size:220,canSort:!0,canResize:!0},{id:"status",header:"Status",label:"Status",accessorKey:"status",cell:({value:F})=>{let Y=typeof F==="string"?F:"QUEUED";return h(HF,{tone:c(Y),label:Y})},size:150,canSort:!0,canResize:!0},{id:"totalTokens",header:"Tokens",label:"Tokens",accessorKey:"totalTokens",cell:({value:F})=>v(Number(F??0)),align:"right",size:140,canSort:!0,canResize:!0},{id:"durationMs",header:"Duration",label:"Duration",accessorKey:"durationMs",cell:({value:F})=>l(typeof F==="number"?F:void 0),align:"right",size:140,canSort:!0,canHide:!0,canResize:!0},{id:"estimatedCostUsd",header:"Cost",label:"Cost",accessorKey:"estimatedCostUsd",cell:({value:F})=>a(typeof F==="number"?F:void 0),align:"right",size:140,canSort:!0,canHide:!0,canResize:!0}]}import{DataTable as AF}from"@contractspec/lib.design-system";import{useContractTable as zF}from"@contractspec/lib.presentation-runtime-react";import*as FF from"react";import{jsx as y}from"react/jsx-runtime";function KF({runs:F,totalItems:Y,pageIndex:W,pageSize:N,sorting:K,loading:O,onSortingChange:Z,onPaginationChange:J,onRunClick:$}){let U=FF.useMemo(()=>t(),[]),Q=zF({data:F,columns:U,executionMode:"server",totalItems:Y,state:{sorting:K,pagination:{pageIndex:W,pageSize:N}},onSortingChange:Z,onPaginationChange:J,initialState:{columnVisibility:{estimatedCostUsd:!1}},getRowId:(q)=>q.id,renderExpandedContent:(q)=>y(e,{run:q}),getCanExpand:()=>!0});return y(AF,{controller:Q,title:"Run History",description:"Server-mode ContractSpec table with shared pagination, sorting, visibility, and expansion.",loading:O,onRowPress:(q)=>$?.(q.id),toolbar:y(o,{controller:Q,totalRuns:Y}),emptyState:y("div",{className:"rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",children:"No runs yet"})})}import{EmptyState as wF,ErrorState as BF,LoaderBlock as PF,StatCard as C,StatCardGroup as LF}from"@contractspec/lib.design-system";import{useState as NF}from"react";import{jsx as P,jsxs as OF}from"react/jsx-runtime";function DF({agentId:F,onRunClick:Y}){let[W,N]=NF([{id:"queuedAt",desc:!0}]),[K,O]=NF({pageIndex:0,pageSize:3}),{data:Z,metrics:J,loading:$,error:U,refetch:Q}=n({agentId:F,pageIndex:K.pageIndex,pageSize:K.pageSize,sorting:W});if($&&!Z)return P(PF,{label:"Loading runs..."});if(U)return P(BF,{title:"Failed to load runs",description:U.message,onRetry:Q,retryLabel:"Retry"});if(!Z?.items.length)return P(wF,{title:"No runs yet",description:"Execute an agent to see run history here."});return OF("div",{className:"space-y-6",children:[J?OF(LF,{children:[P(C,{label:"Total Runs",value:J.totalRuns}),P(C,{label:"Success Rate",value:`${(J.successRate*100).toFixed(1)}%`}),P(C,{label:"Total Tokens",value:v(J.totalTokens)}),P(C,{label:"Total Cost",value:`$${J.totalCostUsd.toFixed(2)}`})]}):null,P(KF,{runs:Z.items,totalItems:Z.total,pageIndex:K.pageIndex,pageSize:K.pageSize,sorting:W,loading:$,onSortingChange:(q)=>{N(q),O((V)=>({...V,pageIndex:0}))},onPaginationChange:O,onRunClick:Y})]})}import{useTemplateRuntime as EF}from"@contractspec/lib.example-shared-ui";import{useCallback as RF,useEffect as vF,useMemo as fF,useState as S}from"react";function QF(F={}){let{handlers:Y,projectId:W}=EF(),{agent:N}=Y,[K,O]=S(null),[Z,J]=S(!0),[$,U]=S(null),[Q,q]=S(1),V=RF(async()=>{J(!0),U(null);try{let _=await N.listTools({projectId:W,search:F.search,category:F.category,status:F.status==="all"?void 0:F.status,limit:F.limit??50,offset:(Q-1)*(F.limit??50)});O(_)}catch(_){U(_ instanceof Error?_:Error("Unknown error"))}finally{J(!1)}},[N,W,F.search,F.category,F.status,F.limit,Q]);vF(()=>{V()},[V]);let{stats:D,groupedByCategory:X,categoryStats:E}=fF(()=>{if(!K)return{stats:null,groupedByCategory:{},categoryStats:[]};let _=K.items,f=_.filter((M)=>M.status==="ACTIVE").length,b=_.filter((M)=>M.status==="DEPRECATED").length,z=_.filter((M)=>M.status==="DISABLED").length,R={},d={};_.forEach((M)=>{let w=M.category;if(!R[w])R[w]=[];R[w].push(M),d[w]=(d[w]||0)+1});let i=Object.entries(d).map(([M,w])=>({category:M,count:w})).sort((M,w)=>w.count-M.count);return{stats:{total:K.total,active:f,deprecated:b,disabled:z,topCategories:i.slice(0,5)},groupedByCategory:R,categoryStats:i}},[K]);return{data:K,loading:Z,error:$,stats:D,groupedByCategory:X,categoryStats:E,page:Q,refetch:V,nextPage:()=>q((_)=>_+1),prevPage:()=>Q>1&&q((_)=>_-1)}}import{Button as IF,EmptyState as bF,EntityCard as TF,ErrorState as kF,LoaderBlock as hF,StatCard as WF,StatCardGroup as yF,StatusChip as CF}from"@contractspec/lib.design-system";import{jsx as G,jsxs as m}from"react/jsx-runtime";var XF={RETRIEVAL:"\uD83D\uDD0D",COMPUTATION:"\uD83E\uDDEE",COMMUNICATION:"\uD83D\uDCE7",INTEGRATION:"\uD83D\uDD17",UTILITY:"\uD83D\uDEE0\uFE0F",CUSTOM:"\u2699\uFE0F"};function SF(F){switch(F){case"ACTIVE":return"success";case"DRAFT":return"neutral";case"DEPRECATED":return"warning";case"DISABLED":return"danger";default:return"neutral"}}function mF({onToolClick:F,onCreateTool:Y}){let{data:W,loading:N,error:K,groupedByCategory:O,categoryStats:Z,refetch:J}=QF();if(N&&!W)return G(hF,{label:"Loading tools..."});if(K)return G(kF,{title:"Failed to load tools",description:K.message,onRetry:J,retryLabel:"Retry"});if(!W?.items.length)return G(bF,{title:"No tools registered",description:"Create your first tool to extend agent capabilities.",primaryAction:Y?G(IF,{onPress:Y,children:"Create Tool"}):void 0});return m("div",{className:"space-y-8",children:[m(yF,{children:[G(WF,{label:"Total Tools",value:W.total}),Z.slice(0,3).map(({category:$,count:U})=>G(WF,{label:`${XF[$]??""} ${$}`,value:U},$))]}),Object.entries(O).map(([$,U])=>m("section",{className:"space-y-4",children:[m("div",{className:"flex items-center gap-2",children:[G("span",{className:"text-2xl",children:XF[$]}),G("h3",{className:"font-semibold text-lg",children:$}),G("span",{className:"rounded-full bg-muted px-2 py-0.5 text-muted-foreground text-xs",children:U.length})]}),G("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:U.map((Q)=>G(TF,{cardTitle:Q.name,cardSubtitle:`v${Q.version}`,meta:G("p",{className:"text-muted-foreground text-sm",children:Q.description}),chips:G(CF,{tone:SF(Q.status),label:Q.status}),footer:G("code",{className:"text-muted-foreground text-xs",children:Q.name}),onClick:F?()=>F(Q.id):void 0},Q.id))})]},$))]})}import{Button as jF,EmptyState as xF,EntityCard as dF,ErrorState as pF,LoaderBlock as gF,StatCard as j,StatCardGroup as cF,StatusChip as lF}from"@contractspec/lib.design-system";import{jsx as H,jsxs as x}from"react/jsx-runtime";function uF(F){switch(F){case"ACTIVE":return"success";case"PAUSED":case"DRAFT":return"warning";case"ARCHIVED":return"neutral";default:return"neutral"}}function iF(){let{data:F,loading:Y,error:W,stats:N,refetch:K}=r();if(Y&&!F)return H(gF,{label:"Loading agents..."});if(W)return H(pF,{title:"Failed to load agents",description:W.message,onRetry:K,retryLabel:"Retry"});if(!F?.items.length)return H(xF,{title:"No agents yet",description:"Create your first AI agent to get started."});return x("div",{className:"space-y-6",children:[N&&x(cF,{children:[H(j,{label:"Total Agents",value:N.total}),H(j,{label:"Active",value:N.active}),H(j,{label:"Paused",value:N.paused}),H(j,{label:"Draft",value:N.draft})]}),x("div",{className:"flex items-center justify-between",children:[H("h3",{className:"font-semibold text-lg",children:"Agents"}),H(jF,{onPress:()=>alert("Create Agent clicked!"),children:"Create Agent"})]}),H("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:F.items.map((O)=>H(dF,{cardTitle:O.name,cardSubtitle:O.modelName,meta:H("p",{className:"text-muted-foreground text-sm",children:O.description}),chips:H(lF,{tone:uF(O.status),label:O.status}),footer:x("span",{className:"text-muted-foreground text-xs",children:["Created ",O.createdAt.toLocaleDateString()]}),onClick:()=>alert(`View agent: ${O.name}`)},O.id))})]})}export{mF as ToolRegistryView,DF as RunListView,iF as AgentListView};