@contractspec/example.agent-console 3.7.7 → 3.8.2

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 (186) hide show
  1. package/.turbo/turbo-build.log +126 -105
  2. package/AGENTS.md +3 -1
  3. package/CHANGELOG.md +29 -0
  4. package/README.md +46 -9
  5. package/dist/agent/agent.handler.d.ts +3 -0
  6. package/dist/agent/agent.handler.js +730 -1
  7. package/dist/agent/index.js +73 -72
  8. package/dist/agent.feature.js +179 -0
  9. package/dist/browser/agent/agent.handler.js +730 -1
  10. package/dist/browser/agent/index.js +73 -72
  11. package/dist/browser/agent.feature.js +179 -0
  12. package/dist/browser/docs/agent-console.docblock.js +11 -8
  13. package/dist/browser/docs/index.js +11 -8
  14. package/dist/browser/example.js +2 -3
  15. package/dist/browser/handlers/agent.handlers.js +1883 -2
  16. package/dist/browser/handlers/index.js +2142 -8
  17. package/dist/browser/index.js +3347 -2433
  18. package/dist/browser/presentations/index.js +49 -49
  19. package/dist/browser/run/index.js +818 -812
  20. package/dist/browser/run/run.handler.js +666 -1
  21. package/dist/browser/shared/index.js +293 -1
  22. package/dist/browser/shared/mock-runs.js +5 -0
  23. package/dist/browser/tool/index.js +331 -331
  24. package/dist/browser/tool/tool.handler.js +479 -3
  25. package/dist/browser/ui/AgentDashboard.js +1204 -319
  26. package/dist/browser/ui/AgentDashboard.visualizations.js +217 -0
  27. package/dist/browser/ui/AgentRunList.js +359 -127
  28. package/dist/browser/ui/hooks/index.js +468 -18
  29. package/dist/browser/ui/hooks/useAgentMutations.js +443 -8
  30. package/dist/browser/ui/hooks/useRunList.js +25 -10
  31. package/dist/browser/ui/index.js +1293 -390
  32. package/dist/browser/ui/renderers/agent-list.markdown.js +14 -5
  33. package/dist/browser/ui/renderers/dashboard.markdown.js +207 -36
  34. package/dist/browser/ui/renderers/index.js +245 -49
  35. package/dist/browser/ui/renderers/run-list.markdown.js +9 -4
  36. package/dist/browser/ui/renderers/tool-registry.markdown.js +15 -4
  37. package/dist/browser/ui/views/RunDataTable.js +326 -0
  38. package/dist/browser/ui/views/RunListView.js +359 -127
  39. package/dist/browser/ui/views/index.js +406 -174
  40. package/dist/browser/ui/views/run-data-table.columns.js +271 -0
  41. package/dist/browser/ui/views/run-list.shared.js +177 -0
  42. package/dist/browser/visualizations/catalog.js +134 -0
  43. package/dist/browser/visualizations/index.js +187 -0
  44. package/dist/browser/visualizations/selectors.js +181 -0
  45. package/dist/docs/agent-console.docblock.js +11 -8
  46. package/dist/docs/index.js +11 -8
  47. package/dist/example.js +2 -3
  48. package/dist/example.test.d.ts +1 -0
  49. package/dist/handlers/agent.handlers.d.ts +2 -0
  50. package/dist/handlers/agent.handlers.js +1883 -2
  51. package/dist/handlers/index.d.ts +1 -3
  52. package/dist/handlers/index.js +2142 -8
  53. package/dist/handlers/mock-handlers.test.d.ts +1 -0
  54. package/dist/index.d.ts +2 -0
  55. package/dist/index.js +3347 -2433
  56. package/dist/node/agent/agent.handler.js +730 -1
  57. package/dist/node/agent/index.js +73 -72
  58. package/dist/node/agent.feature.js +179 -0
  59. package/dist/node/docs/agent-console.docblock.js +11 -8
  60. package/dist/node/docs/index.js +11 -8
  61. package/dist/node/example.js +2 -3
  62. package/dist/node/handlers/agent.handlers.js +1883 -2
  63. package/dist/node/handlers/index.js +2142 -8
  64. package/dist/node/index.js +3347 -2433
  65. package/dist/node/presentations/index.js +49 -49
  66. package/dist/node/run/index.js +818 -812
  67. package/dist/node/run/run.handler.js +666 -1
  68. package/dist/node/shared/index.js +293 -1
  69. package/dist/node/shared/mock-runs.js +5 -0
  70. package/dist/node/tool/index.js +331 -331
  71. package/dist/node/tool/tool.handler.js +479 -3
  72. package/dist/node/ui/AgentDashboard.js +1204 -319
  73. package/dist/node/ui/AgentDashboard.visualizations.js +217 -0
  74. package/dist/node/ui/AgentRunList.js +359 -127
  75. package/dist/node/ui/hooks/index.js +468 -18
  76. package/dist/node/ui/hooks/useAgentMutations.js +443 -8
  77. package/dist/node/ui/hooks/useRunList.js +25 -10
  78. package/dist/node/ui/index.js +1293 -390
  79. package/dist/node/ui/renderers/agent-list.markdown.js +14 -5
  80. package/dist/node/ui/renderers/dashboard.markdown.js +207 -36
  81. package/dist/node/ui/renderers/index.js +245 -49
  82. package/dist/node/ui/renderers/run-list.markdown.js +9 -4
  83. package/dist/node/ui/renderers/tool-registry.markdown.js +15 -4
  84. package/dist/node/ui/views/RunDataTable.js +326 -0
  85. package/dist/node/ui/views/RunListView.js +359 -127
  86. package/dist/node/ui/views/index.js +406 -174
  87. package/dist/node/ui/views/run-data-table.columns.js +271 -0
  88. package/dist/node/ui/views/run-list.shared.js +177 -0
  89. package/dist/node/visualizations/catalog.js +134 -0
  90. package/dist/node/visualizations/index.js +187 -0
  91. package/dist/node/visualizations/selectors.js +181 -0
  92. package/dist/presentations/index.js +49 -49
  93. package/dist/proof/index.d.ts +2 -0
  94. package/dist/proof/meetup-proof.d.ts +10 -0
  95. package/dist/proof/meetup-proof.runtime.d.ts +22 -0
  96. package/dist/proof/meetup-proof.scenario.d.ts +2 -0
  97. package/dist/proof/meetup-proof.suite.d.ts +1 -0
  98. package/dist/proof/meetup-proof.test.d.ts +1 -0
  99. package/dist/run/index.js +818 -812
  100. package/dist/run/run.handler.d.ts +4 -0
  101. package/dist/run/run.handler.js +666 -1
  102. package/dist/shared/demo-dashboard-data.d.ts +16 -0
  103. package/dist/shared/demo-runtime-seed.d.ts +17 -0
  104. package/dist/shared/demo-runtime.d.ts +8 -0
  105. package/dist/shared/demo-runtime.test.d.ts +1 -0
  106. package/dist/shared/index.d.ts +3 -0
  107. package/dist/shared/index.js +293 -1
  108. package/dist/shared/mock-runs.d.ts +4 -0
  109. package/dist/shared/mock-runs.js +5 -0
  110. package/dist/tool/index.js +331 -331
  111. package/dist/tool/tool.handler.d.ts +4 -1
  112. package/dist/tool/tool.handler.js +479 -3
  113. package/dist/ui/AgentDashboard.js +1204 -319
  114. package/dist/ui/AgentDashboard.sandbox.test.d.ts +1 -0
  115. package/dist/ui/AgentDashboard.visualizations.d.ts +4 -0
  116. package/dist/ui/AgentDashboard.visualizations.js +218 -0
  117. package/dist/ui/AgentRunList.js +359 -127
  118. package/dist/ui/hooks/index.js +468 -18
  119. package/dist/ui/hooks/useAgentMutations.js +443 -8
  120. package/dist/ui/hooks/useRunList.d.ts +8 -2
  121. package/dist/ui/hooks/useRunList.js +25 -10
  122. package/dist/ui/index.js +1293 -390
  123. package/dist/ui/renderers/agent-list.markdown.js +14 -5
  124. package/dist/ui/renderers/dashboard.markdown.js +207 -36
  125. package/dist/ui/renderers/index.js +245 -49
  126. package/dist/ui/renderers/run-list.markdown.js +9 -4
  127. package/dist/ui/renderers/tool-registry.markdown.d.ts +1 -1
  128. package/dist/ui/renderers/tool-registry.markdown.js +15 -4
  129. package/dist/ui/views/RunDataTable.d.ts +18 -0
  130. package/dist/ui/views/RunDataTable.js +327 -0
  131. package/dist/ui/views/RunListView.js +359 -127
  132. package/dist/ui/views/index.js +406 -174
  133. package/dist/ui/views/run-data-table.columns.d.ts +3 -0
  134. package/dist/ui/views/run-data-table.columns.js +272 -0
  135. package/dist/ui/views/run-list.shared.d.ts +14 -0
  136. package/dist/ui/views/run-list.shared.js +178 -0
  137. package/dist/visualizations/catalog.d.ts +10 -0
  138. package/dist/visualizations/catalog.js +135 -0
  139. package/dist/visualizations/index.d.ts +2 -0
  140. package/dist/visualizations/index.js +188 -0
  141. package/dist/visualizations/selectors.d.ts +3 -0
  142. package/dist/visualizations/selectors.js +182 -0
  143. package/dist/visualizations/selectors.test.d.ts +1 -0
  144. package/package.json +112 -10
  145. package/proofs/agent-console-meetup.replay.json +220 -0
  146. package/src/agent/agent.handler.ts +18 -1
  147. package/src/agent.feature.ts +3 -0
  148. package/src/docs/agent-console.docblock.ts +11 -8
  149. package/src/example.test.ts +75 -0
  150. package/src/example.ts +2 -3
  151. package/src/handlers/agent.handlers.ts +55 -2
  152. package/src/handlers/index.ts +18 -2
  153. package/src/handlers/mock-handlers.test.ts +77 -0
  154. package/src/index.ts +2 -0
  155. package/src/proof/index.ts +2 -0
  156. package/src/proof/meetup-proof.runtime.ts +196 -0
  157. package/src/proof/meetup-proof.scenario.ts +99 -0
  158. package/src/proof/meetup-proof.suite.ts +29 -0
  159. package/src/proof/meetup-proof.test.ts +28 -0
  160. package/src/proof/meetup-proof.ts +130 -0
  161. package/src/run/run.handler.ts +17 -1
  162. package/src/shared/demo-dashboard-data.ts +58 -0
  163. package/src/shared/demo-runtime-seed.ts +139 -0
  164. package/src/shared/demo-runtime.test.ts +169 -0
  165. package/src/shared/demo-runtime.ts +260 -0
  166. package/src/shared/index.ts +11 -0
  167. package/src/shared/mock-runs.ts +5 -0
  168. package/src/tool/tool.handler.ts +21 -4
  169. package/src/ui/AgentDashboard.sandbox.test.tsx +312 -0
  170. package/src/ui/AgentDashboard.tsx +4 -1
  171. package/src/ui/AgentDashboard.visualizations.tsx +35 -0
  172. package/src/ui/hooks/useAgentMutations.ts +19 -11
  173. package/src/ui/hooks/useRunList.ts +41 -9
  174. package/src/ui/renderers/agent-list.markdown.ts +31 -12
  175. package/src/ui/renderers/dashboard.markdown.ts +37 -42
  176. package/src/ui/renderers/run-list.markdown.ts +16 -8
  177. package/src/ui/renderers/tool-registry.markdown.ts +21 -9
  178. package/src/ui/views/RunDataTable.tsx +74 -0
  179. package/src/ui/views/RunListView.tsx +37 -111
  180. package/src/ui/views/run-data-table.columns.tsx +102 -0
  181. package/src/ui/views/run-list.shared.tsx +139 -0
  182. package/src/visualizations/catalog.ts +132 -0
  183. package/src/visualizations/index.ts +2 -0
  184. package/src/visualizations/selectors.test.ts +12 -0
  185. package/src/visualizations/selectors.ts +70 -0
  186. package/tsdown.config.js +17 -0
@@ -9,7 +9,10 @@ function useRunList(options = {}) {
9
9
  const [metrics, setMetrics] = useState(null);
10
10
  const [loading, setLoading] = useState(true);
11
11
  const [error, setError] = useState(null);
12
- const [page, setPage] = useState(1);
12
+ const [internalPageIndex, setInternalPageIndex] = useState(0);
13
+ const pageSize = options.pageSize ?? options.limit ?? 20;
14
+ const pageIndex = options.pageIndex ?? internalPageIndex;
15
+ const [sort] = options.sorting ?? [];
13
16
  const fetchData = useCallback(async () => {
14
17
  setLoading(true);
15
18
  setError(null);
@@ -19,14 +22,14 @@ function useRunList(options = {}) {
19
22
  projectId,
20
23
  agentId: options.agentId,
21
24
  status: options.status === "all" ? undefined : options.status,
22
- limit: options.limit ?? 20,
23
- offset: (page - 1) * (options.limit ?? 20)
25
+ sortBy: sort?.id,
26
+ sortDirection: sort ? sort.desc ? "desc" : "asc" : undefined,
27
+ limit: pageSize,
28
+ offset: pageIndex * pageSize
24
29
  }),
25
30
  agent.getRunMetrics({
26
31
  projectId,
27
- agentId: options.agentId,
28
- startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
29
- endDate: new Date
32
+ agentId: options.agentId
30
33
  })
31
34
  ]);
32
35
  setData(runsResult);
@@ -36,31 +39,38 @@ function useRunList(options = {}) {
36
39
  } finally {
37
40
  setLoading(false);
38
41
  }
39
- }, [agent, projectId, options.agentId, options.status, options.limit, page]);
42
+ }, [
43
+ agent,
44
+ pageIndex,
45
+ pageSize,
46
+ projectId,
47
+ options.agentId,
48
+ options.status,
49
+ sort?.desc,
50
+ sort?.id
51
+ ]);
40
52
  useEffect(() => {
41
53
  fetchData();
42
54
  }, [fetchData]);
55
+ const hasControlledPagination = options.pageIndex !== undefined;
43
56
  return {
44
57
  data,
45
58
  metrics,
46
59
  loading,
47
60
  error,
48
- page,
61
+ page: pageIndex + 1,
62
+ pageIndex,
63
+ pageSize,
49
64
  refetch: fetchData,
50
- nextPage: () => setPage((p) => p + 1),
51
- prevPage: () => page > 1 && setPage((p) => p - 1)
65
+ nextPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => current + 1),
66
+ prevPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => Math.max(0, current - 1))
52
67
  };
53
68
  }
54
69
 
55
- // src/ui/views/RunListView.tsx
56
- import {
57
- EmptyState,
58
- ErrorState,
59
- LoaderBlock,
60
- StatCard,
61
- StatCardGroup,
62
- StatusChip
63
- } from "@contractspec/lib.design-system";
70
+ // src/ui/views/run-list.shared.tsx
71
+ import { Button, StatusChip } from "@contractspec/lib.design-system";
72
+ import { HStack, VStack } from "@contractspec/lib.ui-kit-web/ui/stack";
73
+ import { Text } from "@contractspec/lib.ui-kit-web/ui/text";
64
74
  import { jsxDEV } from "react/jsx-dev-runtime";
65
75
  "use client";
66
76
  function getStatusTone(status) {
@@ -99,15 +109,320 @@ function formatCost(cost) {
99
109
  return "-";
100
110
  return `$${cost.toFixed(4)}`;
101
111
  }
112
+ function formatJson(value) {
113
+ return JSON.stringify(value ?? null, null, 2);
114
+ }
115
+ function RunExpandedContent({ run }) {
116
+ return /* @__PURE__ */ jsxDEV(VStack, {
117
+ gap: "sm",
118
+ className: "py-2",
119
+ children: [
120
+ /* @__PURE__ */ jsxDEV(HStack, {
121
+ justify: "between",
122
+ className: "flex-wrap",
123
+ children: [
124
+ /* @__PURE__ */ jsxDEV(StatusChip, {
125
+ tone: getStatusTone(run.status),
126
+ label: run.status
127
+ }, undefined, false, undefined, this),
128
+ /* @__PURE__ */ jsxDEV(Text, {
129
+ className: "text-muted-foreground text-sm",
130
+ children: [
131
+ "Queued ",
132
+ run.queuedAt.toLocaleString()
133
+ ]
134
+ }, undefined, true, undefined, this)
135
+ ]
136
+ }, undefined, true, undefined, this),
137
+ /* @__PURE__ */ jsxDEV(HStack, {
138
+ gap: "lg",
139
+ className: "flex-wrap",
140
+ children: [
141
+ /* @__PURE__ */ jsxDEV(Text, {
142
+ className: "text-muted-foreground text-sm",
143
+ children: [
144
+ "Prompt ",
145
+ formatTokens(run.promptTokens)
146
+ ]
147
+ }, undefined, true, undefined, this),
148
+ /* @__PURE__ */ jsxDEV(Text, {
149
+ className: "text-muted-foreground text-sm",
150
+ children: [
151
+ "Completion ",
152
+ formatTokens(run.completionTokens)
153
+ ]
154
+ }, undefined, true, undefined, this),
155
+ /* @__PURE__ */ jsxDEV(Text, {
156
+ className: "text-muted-foreground text-sm",
157
+ children: [
158
+ "Duration ",
159
+ formatDuration(run.durationMs)
160
+ ]
161
+ }, undefined, true, undefined, this)
162
+ ]
163
+ }, undefined, true, undefined, this),
164
+ /* @__PURE__ */ jsxDEV(VStack, {
165
+ gap: "xs",
166
+ children: [
167
+ /* @__PURE__ */ jsxDEV(Text, {
168
+ className: "font-medium text-sm",
169
+ children: "Input"
170
+ }, undefined, false, undefined, this),
171
+ /* @__PURE__ */ jsxDEV("pre", {
172
+ className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
173
+ children: formatJson(run.input)
174
+ }, undefined, false, undefined, this)
175
+ ]
176
+ }, undefined, true, undefined, this),
177
+ /* @__PURE__ */ jsxDEV(VStack, {
178
+ gap: "xs",
179
+ children: [
180
+ /* @__PURE__ */ jsxDEV(Text, {
181
+ className: "font-medium text-sm",
182
+ children: "Output"
183
+ }, undefined, false, undefined, this),
184
+ /* @__PURE__ */ jsxDEV("pre", {
185
+ className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
186
+ children: formatJson(run.output ?? run.errorMessage ?? "Pending")
187
+ }, undefined, false, undefined, this)
188
+ ]
189
+ }, undefined, true, undefined, this)
190
+ ]
191
+ }, undefined, true, undefined, this);
192
+ }
193
+ function RunTableToolbar({
194
+ controller,
195
+ totalRuns
196
+ }) {
197
+ const firstRow = controller.rows[0];
198
+ const queuedColumn = controller.columns.find((column) => column.id === "queuedAt");
199
+ const durationColumn = controller.columns.find((column) => column.id === "durationMs");
200
+ const costColumn = controller.columns.find((column) => column.id === "estimatedCostUsd");
201
+ return /* @__PURE__ */ jsxDEV(HStack, {
202
+ gap: "sm",
203
+ className: "flex-wrap",
204
+ children: [
205
+ /* @__PURE__ */ jsxDEV(Text, {
206
+ className: "text-muted-foreground text-sm",
207
+ children: [
208
+ totalRuns,
209
+ " runs"
210
+ ]
211
+ }, undefined, true, undefined, this),
212
+ /* @__PURE__ */ jsxDEV(Button, {
213
+ variant: "outline",
214
+ size: "sm",
215
+ onPress: () => firstRow?.toggleExpanded?.(!firstRow?.isExpanded),
216
+ children: "Expand Latest Run"
217
+ }, undefined, false, undefined, this),
218
+ /* @__PURE__ */ jsxDEV(Button, {
219
+ variant: "outline",
220
+ size: "sm",
221
+ onPress: () => queuedColumn?.toggleVisibility?.(!queuedColumn?.visible),
222
+ children: queuedColumn?.visible ? "Hide Time" : "Show Time"
223
+ }, undefined, false, undefined, this),
224
+ /* @__PURE__ */ jsxDEV(Button, {
225
+ variant: "outline",
226
+ size: "sm",
227
+ onPress: () => durationColumn?.toggleVisibility?.(!durationColumn?.visible),
228
+ children: durationColumn?.visible ? "Hide Duration" : "Show Duration"
229
+ }, undefined, false, undefined, this),
230
+ /* @__PURE__ */ jsxDEV(Button, {
231
+ variant: "outline",
232
+ size: "sm",
233
+ onPress: () => costColumn?.toggleVisibility?.(!costColumn?.visible),
234
+ children: costColumn?.visible ? "Hide Cost" : "Show Cost"
235
+ }, undefined, false, undefined, this)
236
+ ]
237
+ }, undefined, true, undefined, this);
238
+ }
239
+
240
+ // src/ui/views/run-data-table.columns.tsx
241
+ import { StatusChip as StatusChip2 } from "@contractspec/lib.design-system";
242
+ import { VStack as VStack2 } from "@contractspec/lib.ui-kit-web/ui/stack";
243
+ import { Text as Text2 } from "@contractspec/lib.ui-kit-web/ui/text";
244
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
245
+ "use client";
246
+ function createRunTableColumns() {
247
+ return [
248
+ {
249
+ id: "queuedAt",
250
+ header: "Run",
251
+ label: "Run",
252
+ accessor: (run) => run.queuedAt.getTime(),
253
+ cell: ({ item }) => /* @__PURE__ */ jsxDEV2(VStack2, {
254
+ gap: "xs",
255
+ children: [
256
+ /* @__PURE__ */ jsxDEV2(Text2, {
257
+ className: "font-mono text-sm",
258
+ children: item.id.slice(-8)
259
+ }, undefined, false, undefined, this),
260
+ /* @__PURE__ */ jsxDEV2(Text2, {
261
+ className: "text-muted-foreground text-xs",
262
+ children: item.queuedAt.toLocaleString()
263
+ }, undefined, false, undefined, this)
264
+ ]
265
+ }, undefined, true, undefined, this),
266
+ size: 220,
267
+ minSize: 180,
268
+ canSort: true,
269
+ canHide: true,
270
+ canResize: true
271
+ },
272
+ {
273
+ id: "agentName",
274
+ header: "Agent",
275
+ label: "Agent",
276
+ accessor: (run) => run.agentName ?? "Unknown Agent",
277
+ cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Text2, {
278
+ className: "font-medium",
279
+ children: typeof value === "string" ? value : "Unknown Agent"
280
+ }, undefined, false, undefined, this),
281
+ size: 220,
282
+ canSort: true,
283
+ canResize: true
284
+ },
285
+ {
286
+ id: "status",
287
+ header: "Status",
288
+ label: "Status",
289
+ accessorKey: "status",
290
+ cell: ({ value }) => {
291
+ const status = typeof value === "string" ? value : "QUEUED";
292
+ return /* @__PURE__ */ jsxDEV2(StatusChip2, {
293
+ tone: getStatusTone(status),
294
+ label: status
295
+ }, undefined, false, undefined, this);
296
+ },
297
+ size: 150,
298
+ canSort: true,
299
+ canResize: true
300
+ },
301
+ {
302
+ id: "totalTokens",
303
+ header: "Tokens",
304
+ label: "Tokens",
305
+ accessorKey: "totalTokens",
306
+ cell: ({ value }) => formatTokens(Number(value ?? 0)),
307
+ align: "right",
308
+ size: 140,
309
+ canSort: true,
310
+ canResize: true
311
+ },
312
+ {
313
+ id: "durationMs",
314
+ header: "Duration",
315
+ label: "Duration",
316
+ accessorKey: "durationMs",
317
+ cell: ({ value }) => formatDuration(typeof value === "number" ? value : undefined),
318
+ align: "right",
319
+ size: 140,
320
+ canSort: true,
321
+ canHide: true,
322
+ canResize: true
323
+ },
324
+ {
325
+ id: "estimatedCostUsd",
326
+ header: "Cost",
327
+ label: "Cost",
328
+ accessorKey: "estimatedCostUsd",
329
+ cell: ({ value }) => formatCost(typeof value === "number" ? value : undefined),
330
+ align: "right",
331
+ size: 140,
332
+ canSort: true,
333
+ canHide: true,
334
+ canResize: true
335
+ }
336
+ ];
337
+ }
338
+
339
+ // src/ui/views/RunDataTable.tsx
340
+ import { DataTable } from "@contractspec/lib.design-system";
341
+ import { useContractTable } from "@contractspec/lib.presentation-runtime-react";
342
+ import * as React from "react";
343
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
344
+ "use client";
345
+ function RunDataTable({
346
+ runs,
347
+ totalItems,
348
+ pageIndex,
349
+ pageSize,
350
+ sorting,
351
+ loading,
352
+ onSortingChange,
353
+ onPaginationChange,
354
+ onRunClick
355
+ }) {
356
+ const columns = React.useMemo(() => createRunTableColumns(), []);
357
+ const controller = useContractTable({
358
+ data: runs,
359
+ columns,
360
+ executionMode: "server",
361
+ totalItems,
362
+ state: {
363
+ sorting,
364
+ pagination: { pageIndex, pageSize }
365
+ },
366
+ onSortingChange,
367
+ onPaginationChange,
368
+ initialState: {
369
+ columnVisibility: { estimatedCostUsd: false }
370
+ },
371
+ getRowId: (run) => run.id,
372
+ renderExpandedContent: (run) => /* @__PURE__ */ jsxDEV3(RunExpandedContent, {
373
+ run
374
+ }, undefined, false, undefined, this),
375
+ getCanExpand: () => true
376
+ });
377
+ return /* @__PURE__ */ jsxDEV3(DataTable, {
378
+ controller,
379
+ title: "Run History",
380
+ description: "Server-mode ContractSpec table with shared pagination, sorting, visibility, and expansion.",
381
+ loading,
382
+ onRowPress: (row) => onRunClick?.(row.id),
383
+ toolbar: /* @__PURE__ */ jsxDEV3(RunTableToolbar, {
384
+ controller,
385
+ totalRuns: totalItems
386
+ }, undefined, false, undefined, this),
387
+ emptyState: /* @__PURE__ */ jsxDEV3("div", {
388
+ className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
389
+ children: "No runs yet"
390
+ }, undefined, false, undefined, this)
391
+ }, undefined, false, undefined, this);
392
+ }
393
+
394
+ // src/ui/views/RunListView.tsx
395
+ import {
396
+ EmptyState,
397
+ ErrorState,
398
+ LoaderBlock,
399
+ StatCard,
400
+ StatCardGroup
401
+ } from "@contractspec/lib.design-system";
402
+ import { useState as useState2 } from "react";
403
+ import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
404
+ "use client";
102
405
  function RunListView({ agentId, onRunClick }) {
103
- const { data, metrics, loading, error, refetch } = useRunList({ agentId });
406
+ const [sorting, setSorting] = useState2([
407
+ { id: "queuedAt", desc: true }
408
+ ]);
409
+ const [pagination, setPagination] = useState2({
410
+ pageIndex: 0,
411
+ pageSize: 3
412
+ });
413
+ const { data, metrics, loading, error, refetch } = useRunList({
414
+ agentId,
415
+ pageIndex: pagination.pageIndex,
416
+ pageSize: pagination.pageSize,
417
+ sorting
418
+ });
104
419
  if (loading && !data) {
105
- return /* @__PURE__ */ jsxDEV(LoaderBlock, {
420
+ return /* @__PURE__ */ jsxDEV4(LoaderBlock, {
106
421
  label: "Loading runs..."
107
422
  }, undefined, false, undefined, this);
108
423
  }
109
424
  if (error) {
110
- return /* @__PURE__ */ jsxDEV(ErrorState, {
425
+ return /* @__PURE__ */ jsxDEV4(ErrorState, {
111
426
  title: "Failed to load runs",
112
427
  description: error.message,
113
428
  onRetry: refetch,
@@ -115,131 +430,48 @@ function RunListView({ agentId, onRunClick }) {
115
430
  }, undefined, false, undefined, this);
116
431
  }
117
432
  if (!data?.items.length) {
118
- return /* @__PURE__ */ jsxDEV(EmptyState, {
433
+ return /* @__PURE__ */ jsxDEV4(EmptyState, {
119
434
  title: "No runs yet",
120
435
  description: "Execute an agent to see run history here."
121
436
  }, undefined, false, undefined, this);
122
437
  }
123
- return /* @__PURE__ */ jsxDEV("div", {
438
+ return /* @__PURE__ */ jsxDEV4("div", {
124
439
  className: "space-y-6",
125
440
  children: [
126
- metrics && /* @__PURE__ */ jsxDEV(StatCardGroup, {
441
+ metrics ? /* @__PURE__ */ jsxDEV4(StatCardGroup, {
127
442
  children: [
128
- /* @__PURE__ */ jsxDEV(StatCard, {
443
+ /* @__PURE__ */ jsxDEV4(StatCard, {
129
444
  label: "Total Runs",
130
445
  value: metrics.totalRuns
131
446
  }, undefined, false, undefined, this),
132
- /* @__PURE__ */ jsxDEV(StatCard, {
447
+ /* @__PURE__ */ jsxDEV4(StatCard, {
133
448
  label: "Success Rate",
134
449
  value: `${(metrics.successRate * 100).toFixed(1)}%`
135
450
  }, undefined, false, undefined, this),
136
- /* @__PURE__ */ jsxDEV(StatCard, {
451
+ /* @__PURE__ */ jsxDEV4(StatCard, {
137
452
  label: "Total Tokens",
138
453
  value: formatTokens(metrics.totalTokens)
139
454
  }, undefined, false, undefined, this),
140
- /* @__PURE__ */ jsxDEV(StatCard, {
455
+ /* @__PURE__ */ jsxDEV4(StatCard, {
141
456
  label: "Total Cost",
142
457
  value: `$${metrics.totalCostUsd.toFixed(2)}`
143
458
  }, undefined, false, undefined, this)
144
459
  ]
145
- }, undefined, true, undefined, this),
146
- /* @__PURE__ */ jsxDEV("div", {
147
- className: "rounded-lg border border-border",
148
- children: /* @__PURE__ */ jsxDEV("table", {
149
- className: "w-full",
150
- children: [
151
- /* @__PURE__ */ jsxDEV("thead", {
152
- className: "border-border border-b bg-muted/30",
153
- children: /* @__PURE__ */ jsxDEV("tr", {
154
- children: [
155
- /* @__PURE__ */ jsxDEV("th", {
156
- className: "px-4 py-3 text-left font-medium text-muted-foreground text-sm",
157
- children: "Run"
158
- }, undefined, false, undefined, this),
159
- /* @__PURE__ */ jsxDEV("th", {
160
- className: "px-4 py-3 text-left font-medium text-muted-foreground text-sm",
161
- children: "Agent"
162
- }, undefined, false, undefined, this),
163
- /* @__PURE__ */ jsxDEV("th", {
164
- className: "px-4 py-3 text-left font-medium text-muted-foreground text-sm",
165
- children: "Status"
166
- }, undefined, false, undefined, this),
167
- /* @__PURE__ */ jsxDEV("th", {
168
- className: "px-4 py-3 text-right font-medium text-muted-foreground text-sm",
169
- children: "Tokens"
170
- }, undefined, false, undefined, this),
171
- /* @__PURE__ */ jsxDEV("th", {
172
- className: "px-4 py-3 text-right font-medium text-muted-foreground text-sm",
173
- children: "Duration"
174
- }, undefined, false, undefined, this),
175
- /* @__PURE__ */ jsxDEV("th", {
176
- className: "px-4 py-3 text-right font-medium text-muted-foreground text-sm",
177
- children: "Cost"
178
- }, undefined, false, undefined, this)
179
- ]
180
- }, undefined, true, undefined, this)
181
- }, undefined, false, undefined, this),
182
- /* @__PURE__ */ jsxDEV("tbody", {
183
- className: "divide-y divide-border",
184
- children: data.items.map((run) => /* @__PURE__ */ jsxDEV("tr", {
185
- className: "cursor-pointer transition-colors hover:bg-muted/50",
186
- onClick: () => onRunClick?.(run.id),
187
- children: [
188
- /* @__PURE__ */ jsxDEV("td", {
189
- className: "px-4 py-3",
190
- children: [
191
- /* @__PURE__ */ jsxDEV("div", {
192
- className: "font-mono text-sm",
193
- children: run.id.slice(-8)
194
- }, undefined, false, undefined, this),
195
- /* @__PURE__ */ jsxDEV("div", {
196
- className: "text-muted-foreground text-xs",
197
- children: run.queuedAt.toLocaleString()
198
- }, undefined, false, undefined, this)
199
- ]
200
- }, undefined, true, undefined, this),
201
- /* @__PURE__ */ jsxDEV("td", {
202
- className: "px-4 py-3",
203
- children: /* @__PURE__ */ jsxDEV("span", {
204
- className: "font-medium",
205
- children: run.agentName
206
- }, undefined, false, undefined, this)
207
- }, undefined, false, undefined, this),
208
- /* @__PURE__ */ jsxDEV("td", {
209
- className: "px-4 py-3",
210
- children: /* @__PURE__ */ jsxDEV(StatusChip, {
211
- tone: getStatusTone(run.status),
212
- label: run.status
213
- }, undefined, false, undefined, this)
214
- }, undefined, false, undefined, this),
215
- /* @__PURE__ */ jsxDEV("td", {
216
- className: "px-4 py-3 text-right font-mono text-sm",
217
- children: formatTokens(run.totalTokens)
218
- }, undefined, false, undefined, this),
219
- /* @__PURE__ */ jsxDEV("td", {
220
- className: "px-4 py-3 text-right font-mono text-sm",
221
- children: formatDuration(run.durationMs)
222
- }, undefined, false, undefined, this),
223
- /* @__PURE__ */ jsxDEV("td", {
224
- className: "px-4 py-3 text-right font-mono text-sm",
225
- children: formatCost(run.estimatedCostUsd)
226
- }, undefined, false, undefined, this)
227
- ]
228
- }, run.id, true, undefined, this))
229
- }, undefined, false, undefined, this)
230
- ]
231
- }, undefined, true, undefined, this)
232
- }, undefined, false, undefined, this),
233
- /* @__PURE__ */ jsxDEV("div", {
234
- className: "text-center text-muted-foreground text-sm",
235
- children: [
236
- "Showing ",
237
- data.items.length,
238
- " of ",
239
- data.total,
240
- " runs"
241
- ]
242
- }, undefined, true, undefined, this)
460
+ }, undefined, true, undefined, this) : null,
461
+ /* @__PURE__ */ jsxDEV4(RunDataTable, {
462
+ runs: data.items,
463
+ totalItems: data.total,
464
+ pageIndex: pagination.pageIndex,
465
+ pageSize: pagination.pageSize,
466
+ sorting,
467
+ loading,
468
+ onSortingChange: (nextSorting) => {
469
+ setSorting(nextSorting);
470
+ setPagination((current) => ({ ...current, pageIndex: 0 }));
471
+ },
472
+ onPaginationChange: setPagination,
473
+ onRunClick
474
+ }, undefined, false, undefined, this)
243
475
  ]
244
476
  }, undefined, true, undefined, this);
245
477
  }