@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,479 +1 @@
1
- // src/ui/hooks/useRunList.ts
2
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
3
- import { useCallback, useEffect, useState } from "react";
4
- function useRunList(options = {}) {
5
- const { handlers, projectId } = useTemplateRuntime();
6
- const { agent } = handlers;
7
- const [data, setData] = useState(null);
8
- const [metrics, setMetrics] = useState(null);
9
- const [loading, setLoading] = useState(true);
10
- const [error, setError] = useState(null);
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 ?? [];
15
- const fetchData = useCallback(async () => {
16
- setLoading(true);
17
- setError(null);
18
- try {
19
- const [runsResult, metricsResult] = await Promise.all([
20
- agent.listRuns({
21
- projectId,
22
- agentId: options.agentId,
23
- status: options.status === "all" ? undefined : options.status,
24
- sortBy: sort?.id,
25
- sortDirection: sort ? sort.desc ? "desc" : "asc" : undefined,
26
- limit: pageSize,
27
- offset: pageIndex * pageSize
28
- }),
29
- agent.getRunMetrics({
30
- projectId,
31
- agentId: options.agentId
32
- })
33
- ]);
34
- setData(runsResult);
35
- setMetrics(metricsResult);
36
- } catch (err) {
37
- setError(err instanceof Error ? err : new Error("Unknown error"));
38
- } finally {
39
- setLoading(false);
40
- }
41
- }, [
42
- agent,
43
- pageIndex,
44
- pageSize,
45
- projectId,
46
- options.agentId,
47
- options.status,
48
- sort?.desc,
49
- sort?.id
50
- ]);
51
- useEffect(() => {
52
- fetchData();
53
- }, [fetchData]);
54
- const hasControlledPagination = options.pageIndex !== undefined;
55
- return {
56
- data,
57
- metrics,
58
- loading,
59
- error,
60
- page: pageIndex + 1,
61
- pageIndex,
62
- pageSize,
63
- refetch: fetchData,
64
- nextPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => current + 1),
65
- prevPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => Math.max(0, current - 1))
66
- };
67
- }
68
-
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";
73
- import { jsxDEV } from "react/jsx-dev-runtime";
74
- "use client";
75
- function getStatusTone(status) {
76
- switch (status) {
77
- case "COMPLETED":
78
- return "success";
79
- case "RUNNING":
80
- return "warning";
81
- case "QUEUED":
82
- return "neutral";
83
- case "FAILED":
84
- case "CANCELLED":
85
- return "danger";
86
- default:
87
- return "neutral";
88
- }
89
- }
90
- function formatDuration(ms) {
91
- if (!ms)
92
- return "-";
93
- if (ms < 1000)
94
- return `${ms}ms`;
95
- if (ms < 60000)
96
- return `${(ms / 1000).toFixed(1)}s`;
97
- return `${(ms / 60000).toFixed(1)}m`;
98
- }
99
- function formatTokens(tokens) {
100
- if (tokens < 1000)
101
- return tokens.toString();
102
- if (tokens < 1e6)
103
- return `${(tokens / 1000).toFixed(1)}K`;
104
- return `${(tokens / 1e6).toFixed(2)}M`;
105
- }
106
- function formatCost(cost) {
107
- if (!cost)
108
- return "-";
109
- return `$${cost.toFixed(4)}`;
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";
404
- function RunListView({ agentId, onRunClick }) {
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
- });
418
- if (loading && !data) {
419
- return /* @__PURE__ */ jsxDEV4(LoaderBlock, {
420
- label: "Loading runs..."
421
- }, undefined, false, undefined, this);
422
- }
423
- if (error) {
424
- return /* @__PURE__ */ jsxDEV4(ErrorState, {
425
- title: "Failed to load runs",
426
- description: error.message,
427
- onRetry: refetch,
428
- retryLabel: "Retry"
429
- }, undefined, false, undefined, this);
430
- }
431
- if (!data?.items.length) {
432
- return /* @__PURE__ */ jsxDEV4(EmptyState, {
433
- title: "No runs yet",
434
- description: "Execute an agent to see run history here."
435
- }, undefined, false, undefined, this);
436
- }
437
- return /* @__PURE__ */ jsxDEV4("div", {
438
- className: "space-y-6",
439
- children: [
440
- metrics ? /* @__PURE__ */ jsxDEV4(StatCardGroup, {
441
- children: [
442
- /* @__PURE__ */ jsxDEV4(StatCard, {
443
- label: "Total Runs",
444
- value: metrics.totalRuns
445
- }, undefined, false, undefined, this),
446
- /* @__PURE__ */ jsxDEV4(StatCard, {
447
- label: "Success Rate",
448
- value: `${(metrics.successRate * 100).toFixed(1)}%`
449
- }, undefined, false, undefined, this),
450
- /* @__PURE__ */ jsxDEV4(StatCard, {
451
- label: "Total Tokens",
452
- value: formatTokens(metrics.totalTokens)
453
- }, undefined, false, undefined, this),
454
- /* @__PURE__ */ jsxDEV4(StatCard, {
455
- label: "Total Cost",
456
- value: `$${metrics.totalCostUsd.toFixed(2)}`
457
- }, undefined, false, undefined, this)
458
- ]
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)
474
- ]
475
- }, undefined, true, undefined, this);
476
- }
477
- export {
478
- RunListView
479
- };
1
+ import{useTemplateRuntime as u}from"@contractspec/lib.example-shared-ui";import{useCallback as r,useEffect as a,useState as B}from"react";function C(A={}){let{handlers:N,projectId:O}=u(),{agent:Q}=N,[K,W]=B(null),[F,Y]=B(null),[y,G]=B(!0),[J,X]=B(null),[P,T]=B(0),V=A.pageSize??A.limit??20,z=A.pageIndex??P,[H]=A.sorting??[],b=r(async()=>{G(!0),X(null);try{let[_,i]=await Promise.all([Q.listRuns({projectId:O,agentId:A.agentId,status:A.status==="all"?void 0:A.status,sortBy:H?.id,sortDirection:H?H.desc?"desc":"asc":void 0,limit:V,offset:z*V}),Q.getRunMetrics({projectId:O,agentId:A.agentId})]);W(_),Y(i)}catch(_){X(_ instanceof Error?_:Error("Unknown error"))}finally{G(!1)}},[Q,z,V,O,A.agentId,A.status,H?.desc,H?.id]);a(()=>{b()},[b]);let k=A.pageIndex!==void 0;return{data:K,metrics:F,loading:y,error:J,page:z+1,pageIndex:z,pageSize:V,refetch:b,nextPage:k?void 0:()=>T((_)=>_+1),prevPage:k?void 0:()=>T((_)=>Math.max(0,_-1))}}import{Button as E,StatusChip as o}from"@contractspec/lib.design-system";import{HStack as R,VStack as f}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as M}from"@contractspec/lib.ui-kit-web/ui/text";import{jsx as Z,jsxs as U}from"react/jsx-runtime";function I(A){switch(A){case"COMPLETED":return"success";case"RUNNING":return"warning";case"QUEUED":return"neutral";case"FAILED":case"CANCELLED":return"danger";default:return"neutral"}}function h(A){if(!A)return"-";if(A<1000)return`${A}ms`;if(A<60000)return`${(A/1000).toFixed(1)}s`;return`${(A/60000).toFixed(1)}m`}function q(A){if(A<1000)return A.toString();if(A<1e6)return`${(A/1000).toFixed(1)}K`;return`${(A/1e6).toFixed(2)}M`}function j(A){if(!A)return"-";return`$${A.toFixed(4)}`}function S(A){return JSON.stringify(A??null,null,2)}function d({run:A}){return U(f,{gap:"sm",className:"py-2",children:[U(R,{justify:"between",className:"flex-wrap",children:[Z(o,{tone:I(A.status),label:A.status}),U(M,{className:"text-muted-foreground text-sm",children:["Queued ",A.queuedAt.toLocaleString()]})]}),U(R,{gap:"lg",className:"flex-wrap",children:[U(M,{className:"text-muted-foreground text-sm",children:["Prompt ",q(A.promptTokens)]}),U(M,{className:"text-muted-foreground text-sm",children:["Completion ",q(A.completionTokens)]}),U(M,{className:"text-muted-foreground text-sm",children:["Duration ",h(A.durationMs)]})]}),U(f,{gap:"xs",children:[Z(M,{className:"font-medium text-sm",children:"Input"}),Z("pre",{className:"overflow-auto rounded-md bg-muted/40 p-3 text-xs",children:S(A.input)})]}),U(f,{gap:"xs",children:[Z(M,{className:"font-medium text-sm",children:"Output"}),Z("pre",{className:"overflow-auto rounded-md bg-muted/40 p-3 text-xs",children:S(A.output??A.errorMessage??"Pending")})]})]})}function g({controller:A,totalRuns:N}){let O=A.rows[0],Q=A.columns.find((F)=>F.id==="queuedAt"),K=A.columns.find((F)=>F.id==="durationMs"),W=A.columns.find((F)=>F.id==="estimatedCostUsd");return U(R,{gap:"sm",className:"flex-wrap",children:[U(M,{className:"text-muted-foreground text-sm",children:[N," runs"]}),Z(E,{variant:"outline",size:"sm",onPress:()=>O?.toggleExpanded?.(!O?.isExpanded),children:"Expand Latest Run"}),Z(E,{variant:"outline",size:"sm",onPress:()=>Q?.toggleVisibility?.(!Q?.visible),children:Q?.visible?"Hide Time":"Show Time"}),Z(E,{variant:"outline",size:"sm",onPress:()=>K?.toggleVisibility?.(!K?.visible),children:K?.visible?"Hide Duration":"Show Duration"}),Z(E,{variant:"outline",size:"sm",onPress:()=>W?.toggleVisibility?.(!W?.visible),children:W?.visible?"Hide Cost":"Show Cost"})]})}import{StatusChip as s}from"@contractspec/lib.design-system";import{VStack as n}from"@contractspec/lib.ui-kit-web/ui/stack";import{Text as v}from"@contractspec/lib.ui-kit-web/ui/text";import{jsx as L,jsxs as e}from"react/jsx-runtime";function p(){return[{id:"queuedAt",header:"Run",label:"Run",accessor:(A)=>A.queuedAt.getTime(),cell:({item:A})=>e(n,{gap:"xs",children:[L(v,{className:"font-mono text-sm",children:A.id.slice(-8)}),L(v,{className:"text-muted-foreground text-xs",children:A.queuedAt.toLocaleString()})]}),size:220,minSize:180,canSort:!0,canHide:!0,canResize:!0},{id:"agentName",header:"Agent",label:"Agent",accessor:(A)=>A.agentName??"Unknown Agent",cell:({value:A})=>L(v,{className:"font-medium",children:typeof A==="string"?A:"Unknown Agent"}),size:220,canSort:!0,canResize:!0},{id:"status",header:"Status",label:"Status",accessorKey:"status",cell:({value:A})=>{let N=typeof A==="string"?A:"QUEUED";return L(s,{tone:I(N),label:N})},size:150,canSort:!0,canResize:!0},{id:"totalTokens",header:"Tokens",label:"Tokens",accessorKey:"totalTokens",cell:({value:A})=>q(Number(A??0)),align:"right",size:140,canSort:!0,canResize:!0},{id:"durationMs",header:"Duration",label:"Duration",accessorKey:"durationMs",cell:({value:A})=>h(typeof A==="number"?A:void 0),align:"right",size:140,canSort:!0,canHide:!0,canResize:!0},{id:"estimatedCostUsd",header:"Cost",label:"Cost",accessorKey:"estimatedCostUsd",cell:({value:A})=>j(typeof A==="number"?A:void 0),align:"right",size:140,canSort:!0,canHide:!0,canResize:!0}]}import{DataTable as t}from"@contractspec/lib.design-system";import{useContractTable as AA}from"@contractspec/lib.presentation-runtime-react";import*as m from"react";import{jsx as w}from"react/jsx-runtime";function x({runs:A,totalItems:N,pageIndex:O,pageSize:Q,sorting:K,loading:W,onSortingChange:F,onPaginationChange:Y,onRunClick:y}){let G=m.useMemo(()=>p(),[]),J=AA({data:A,columns:G,executionMode:"server",totalItems:N,state:{sorting:K,pagination:{pageIndex:O,pageSize:Q}},onSortingChange:F,onPaginationChange:Y,initialState:{columnVisibility:{estimatedCostUsd:!1}},getRowId:(X)=>X.id,renderExpandedContent:(X)=>w(d,{run:X}),getCanExpand:()=>!0});return w(t,{controller:J,title:"Run History",description:"Server-mode ContractSpec table with shared pagination, sorting, visibility, and expansion.",loading:W,onRowPress:(X)=>y?.(X.id),toolbar:w(g,{controller:J,totalRuns:N}),emptyState:w("div",{className:"rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",children:"No runs yet"})})}import{EmptyState as FA,ErrorState as KA,LoaderBlock as NA,StatCard as D,StatCardGroup as OA}from"@contractspec/lib.design-system";import{useState as c}from"react";import{jsx as $,jsxs as l}from"react/jsx-runtime";function IA({agentId:A,onRunClick:N}){let[O,Q]=c([{id:"queuedAt",desc:!0}]),[K,W]=c({pageIndex:0,pageSize:3}),{data:F,metrics:Y,loading:y,error:G,refetch:J}=C({agentId:A,pageIndex:K.pageIndex,pageSize:K.pageSize,sorting:O});if(y&&!F)return $(NA,{label:"Loading runs..."});if(G)return $(KA,{title:"Failed to load runs",description:G.message,onRetry:J,retryLabel:"Retry"});if(!F?.items.length)return $(FA,{title:"No runs yet",description:"Execute an agent to see run history here."});return l("div",{className:"space-y-6",children:[Y?l(OA,{children:[$(D,{label:"Total Runs",value:Y.totalRuns}),$(D,{label:"Success Rate",value:`${(Y.successRate*100).toFixed(1)}%`}),$(D,{label:"Total Tokens",value:q(Y.totalTokens)}),$(D,{label:"Total Cost",value:`$${Y.totalCostUsd.toFixed(2)}`})]}):null,$(x,{runs:F.items,totalItems:F.total,pageIndex:K.pageIndex,pageSize:K.pageSize,sorting:O,loading:y,onSortingChange:(X)=>{Q(X),W((P)=>({...P,pageIndex:0}))},onPaginationChange:W,onRunClick:N})]})}export{IA as RunListView};