@contractspec/example.agent-console 3.7.7 → 3.8.4

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