@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
@@ -1,7 +1,439 @@
1
1
  // @bun
2
+ // src/shared/mock-agents.ts
3
+ var MOCK_AGENTS = [
4
+ {
5
+ id: "agent-1",
6
+ organizationId: "demo-org",
7
+ name: "Customer Support Bot",
8
+ slug: "customer-support-bot",
9
+ description: "Handles tier-1 customer inquiries and routes complex issues.",
10
+ status: "ACTIVE",
11
+ modelProvider: "OPENAI",
12
+ modelName: "gpt-4o-mini",
13
+ modelConfig: { temperature: 0.7 },
14
+ systemPrompt: "You are a helpful customer support assistant.",
15
+ toolChoice: "auto",
16
+ maxIterations: 10,
17
+ timeoutMs: 120000,
18
+ version: "1.0.0",
19
+ tags: ["support", "tier-1"],
20
+ createdAt: new Date("2024-01-15T10:00:00Z"),
21
+ updatedAt: new Date("2024-03-20T14:30:00Z")
22
+ },
23
+ {
24
+ id: "agent-2",
25
+ organizationId: "demo-org",
26
+ name: "Code Review Assistant",
27
+ slug: "code-review-assistant",
28
+ description: "Reviews pull requests and provides actionable feedback.",
29
+ status: "ACTIVE",
30
+ modelProvider: "ANTHROPIC",
31
+ modelName: "claude-sonnet-4-20250514",
32
+ modelConfig: { temperature: 0.3 },
33
+ systemPrompt: "You are a code review expert.",
34
+ toolChoice: "auto",
35
+ maxIterations: 15,
36
+ timeoutMs: 180000,
37
+ version: "2.1.0",
38
+ tags: ["code", "review", "dev"],
39
+ createdAt: new Date("2024-02-10T09:00:00Z"),
40
+ updatedAt: new Date("2024-04-05T11:15:00Z")
41
+ },
42
+ {
43
+ id: "agent-3",
44
+ organizationId: "demo-org",
45
+ name: "Data Analyst",
46
+ slug: "data-analyst",
47
+ description: "Queries databases and generates insights from data.",
48
+ status: "PAUSED",
49
+ modelProvider: "OPENAI",
50
+ modelName: "gpt-4o",
51
+ modelConfig: { temperature: 0.5 },
52
+ systemPrompt: "You are a data analyst expert in SQL and analytics.",
53
+ toolChoice: "required",
54
+ maxIterations: 20,
55
+ timeoutMs: 300000,
56
+ version: "1.2.0",
57
+ tags: ["data", "analytics", "sql"],
58
+ createdAt: new Date("2024-03-01T08:00:00Z"),
59
+ updatedAt: new Date("2024-04-10T16:45:00Z")
60
+ },
61
+ {
62
+ id: "agent-4",
63
+ organizationId: "demo-org",
64
+ name: "Meeting Scheduler",
65
+ slug: "meeting-scheduler",
66
+ description: "Schedules meetings and manages calendar conflicts.",
67
+ status: "DRAFT",
68
+ modelProvider: "GOOGLE",
69
+ modelName: "gemini-2.0-flash",
70
+ modelConfig: { temperature: 0.2 },
71
+ systemPrompt: "You help schedule and organize meetings efficiently.",
72
+ toolChoice: "auto",
73
+ maxIterations: 5,
74
+ timeoutMs: 60000,
75
+ version: "0.1.0",
76
+ tags: ["calendar", "scheduling"],
77
+ createdAt: new Date("2024-04-01T12:00:00Z"),
78
+ updatedAt: new Date("2024-04-01T12:00:00Z")
79
+ }
80
+ ];
81
+
82
+ // src/shared/mock-tools.ts
83
+ var MOCK_TOOLS = [
84
+ {
85
+ id: "tool-1",
86
+ organizationId: "demo-org",
87
+ name: "Web Search",
88
+ slug: "web-search",
89
+ description: "Search the web for real-time information using Brave API.",
90
+ category: "RETRIEVAL",
91
+ status: "ACTIVE",
92
+ parametersSchema: {
93
+ type: "object",
94
+ properties: {
95
+ query: { type: "string", description: "Search query" },
96
+ numResults: { type: "number", default: 10 }
97
+ },
98
+ required: ["query"]
99
+ },
100
+ outputSchema: { type: "array", items: { type: "object" } },
101
+ implementationType: "http",
102
+ implementationConfig: {
103
+ url: "https://api.brave.com/search",
104
+ method: "GET"
105
+ },
106
+ maxInvocationsPerMinute: 60,
107
+ timeoutMs: 30000,
108
+ version: "1.0.0",
109
+ tags: ["search", "web"],
110
+ createdAt: new Date("2024-01-01T00:00:00Z"),
111
+ updatedAt: new Date("2024-02-15T10:00:00Z")
112
+ },
113
+ {
114
+ id: "tool-2",
115
+ organizationId: "demo-org",
116
+ name: "SQL Query",
117
+ slug: "sql-query",
118
+ description: "Execute read-only SQL queries against the data warehouse.",
119
+ category: "RETRIEVAL",
120
+ status: "ACTIVE",
121
+ parametersSchema: {
122
+ type: "object",
123
+ properties: {
124
+ query: { type: "string", description: "SQL query" },
125
+ maxRows: { type: "number", default: 100 }
126
+ },
127
+ required: ["query"]
128
+ },
129
+ outputSchema: { type: "object" },
130
+ implementationType: "function",
131
+ implementationConfig: { handler: "executeSqlQuery" },
132
+ maxInvocationsPerMinute: 30,
133
+ timeoutMs: 60000,
134
+ version: "1.1.0",
135
+ tags: ["sql", "database"],
136
+ createdAt: new Date("2024-01-05T00:00:00Z"),
137
+ updatedAt: new Date("2024-03-10T14:00:00Z")
138
+ },
139
+ {
140
+ id: "tool-3",
141
+ organizationId: "demo-org",
142
+ name: "Email Sender",
143
+ slug: "email-sender",
144
+ description: "Send emails via SMTP or API.",
145
+ category: "COMMUNICATION",
146
+ status: "ACTIVE",
147
+ parametersSchema: {
148
+ type: "object",
149
+ properties: {
150
+ to: { type: "string" },
151
+ subject: { type: "string" },
152
+ body: { type: "string" }
153
+ },
154
+ required: ["to", "subject", "body"]
155
+ },
156
+ implementationType: "http",
157
+ implementationConfig: { url: "/api/send-email", method: "POST" },
158
+ maxInvocationsPerMinute: 10,
159
+ timeoutMs: 30000,
160
+ version: "1.0.0",
161
+ tags: ["email", "communication"],
162
+ createdAt: new Date("2024-02-01T00:00:00Z"),
163
+ updatedAt: new Date("2024-02-01T00:00:00Z")
164
+ },
165
+ {
166
+ id: "tool-4",
167
+ organizationId: "demo-org",
168
+ name: "GitHub Integration",
169
+ slug: "github-integration",
170
+ description: "Interact with GitHub repositories, PRs, and issues.",
171
+ category: "INTEGRATION",
172
+ status: "ACTIVE",
173
+ parametersSchema: {
174
+ type: "object",
175
+ properties: {
176
+ action: {
177
+ type: "string",
178
+ enum: ["list_prs", "get_pr", "create_comment"]
179
+ },
180
+ repo: { type: "string" },
181
+ params: { type: "object" }
182
+ },
183
+ required: ["action", "repo"]
184
+ },
185
+ implementationType: "http",
186
+ implementationConfig: { url: "https://api.github.com", auth: "token" },
187
+ maxInvocationsPerMinute: 100,
188
+ timeoutMs: 15000,
189
+ version: "2.0.0",
190
+ tags: ["github", "integration", "code"],
191
+ createdAt: new Date("2024-02-20T00:00:00Z"),
192
+ updatedAt: new Date("2024-04-01T09:00:00Z")
193
+ },
194
+ {
195
+ id: "tool-5",
196
+ organizationId: "demo-org",
197
+ name: "Calculator",
198
+ slug: "calculator",
199
+ description: "Perform mathematical calculations.",
200
+ category: "COMPUTATION",
201
+ status: "ACTIVE",
202
+ parametersSchema: {
203
+ type: "object",
204
+ properties: {
205
+ expression: {
206
+ type: "string",
207
+ description: "Math expression to evaluate"
208
+ }
209
+ },
210
+ required: ["expression"]
211
+ },
212
+ outputSchema: {
213
+ type: "object",
214
+ properties: { result: { type: "number" } }
215
+ },
216
+ implementationType: "function",
217
+ implementationConfig: { handler: "evaluateMath" },
218
+ timeoutMs: 5000,
219
+ version: "1.0.0",
220
+ tags: ["math", "utility"],
221
+ createdAt: new Date("2024-01-10T00:00:00Z"),
222
+ updatedAt: new Date("2024-01-10T00:00:00Z")
223
+ }
224
+ ];
225
+
226
+ // src/shared/mock-runs.ts
227
+ var MOCK_RUNS = [
228
+ {
229
+ id: "run-1",
230
+ organizationId: "demo-org",
231
+ projectId: "demo-project",
232
+ agentId: "agent-1",
233
+ agentName: "Customer Support Bot",
234
+ userId: "user-1",
235
+ sessionId: "session-1",
236
+ input: { message: "How do I reset my password?", context: {} },
237
+ output: { response: "You can reset your password by clicking..." },
238
+ status: "COMPLETED",
239
+ totalTokens: 1250,
240
+ promptTokens: 800,
241
+ completionTokens: 450,
242
+ totalIterations: 3,
243
+ durationMs: 4500,
244
+ estimatedCostUsd: 0.0025,
245
+ queuedAt: new Date("2024-04-15T10:00:00Z"),
246
+ startedAt: new Date("2024-04-15T10:00:01Z"),
247
+ completedAt: new Date("2024-04-15T10:00:05Z"),
248
+ steps: [],
249
+ logs: []
250
+ },
251
+ {
252
+ id: "run-2",
253
+ organizationId: "demo-org",
254
+ projectId: "demo-project",
255
+ agentId: "agent-2",
256
+ agentName: "Code Review Assistant",
257
+ userId: "user-2",
258
+ input: { message: "Review PR #123", context: { prNumber: 123 } },
259
+ status: "IN_PROGRESS",
260
+ totalTokens: 3500,
261
+ promptTokens: 3000,
262
+ completionTokens: 500,
263
+ totalIterations: 5,
264
+ queuedAt: new Date("2024-04-15T10:30:00Z"),
265
+ startedAt: new Date("2024-04-15T10:30:02Z"),
266
+ steps: [],
267
+ logs: []
268
+ },
269
+ {
270
+ id: "run-3",
271
+ organizationId: "demo-org",
272
+ projectId: "demo-project",
273
+ agentId: "agent-1",
274
+ agentName: "Customer Support Bot",
275
+ userId: "user-1",
276
+ input: { message: "What are your business hours?" },
277
+ output: { response: "Our business hours are 9 AM to 5 PM EST..." },
278
+ status: "COMPLETED",
279
+ totalTokens: 800,
280
+ promptTokens: 500,
281
+ completionTokens: 300,
282
+ totalIterations: 2,
283
+ durationMs: 2100,
284
+ estimatedCostUsd: 0.0012,
285
+ queuedAt: new Date("2024-04-15T09:00:00Z"),
286
+ startedAt: new Date("2024-04-15T09:00:01Z"),
287
+ completedAt: new Date("2024-04-15T09:00:03Z"),
288
+ steps: [],
289
+ logs: []
290
+ },
291
+ {
292
+ id: "run-4",
293
+ organizationId: "demo-org",
294
+ projectId: "demo-project",
295
+ agentId: "agent-3",
296
+ agentName: "Data Analyst",
297
+ userId: "user-3",
298
+ input: { message: "Generate sales report for Q1" },
299
+ status: "FAILED",
300
+ errorMessage: "Database connection timeout",
301
+ errorCode: "DB_TIMEOUT",
302
+ totalTokens: 2000,
303
+ promptTokens: 1500,
304
+ completionTokens: 500,
305
+ totalIterations: 8,
306
+ durationMs: 45000,
307
+ queuedAt: new Date("2024-04-14T15:00:00Z"),
308
+ startedAt: new Date("2024-04-14T15:00:05Z"),
309
+ completedAt: new Date("2024-04-14T15:00:50Z"),
310
+ steps: [],
311
+ logs: []
312
+ },
313
+ {
314
+ id: "run-5",
315
+ organizationId: "demo-org",
316
+ projectId: "demo-project",
317
+ agentId: "agent-2",
318
+ agentName: "Code Review Assistant",
319
+ userId: "user-2",
320
+ input: { message: "Review PR #120" },
321
+ output: { response: "Code review complete. 3 suggestions..." },
322
+ status: "COMPLETED",
323
+ totalTokens: 5200,
324
+ promptTokens: 4000,
325
+ completionTokens: 1200,
326
+ totalIterations: 7,
327
+ durationMs: 15000,
328
+ estimatedCostUsd: 0.0156,
329
+ queuedAt: new Date("2024-04-14T11:00:00Z"),
330
+ startedAt: new Date("2024-04-14T11:00:03Z"),
331
+ completedAt: new Date("2024-04-14T11:00:18Z"),
332
+ steps: [],
333
+ logs: []
334
+ }
335
+ ];
336
+
2
337
  // src/ui/hooks/useAgentMutations.ts
3
338
  import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
339
  import { useCallback, useState } from "react";
340
+
341
+ // src/shared/demo-runtime-seed.ts
342
+ var AGENT_CONSOLE_DEMO_ORGANIZATION_ID = "demo-org";
343
+ var AGENT_CONSOLE_DEMO_PROJECT_ID = "agent-console-demo";
344
+ function slugify(name) {
345
+ return name.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
346
+ }
347
+ function cloneAgent(agent) {
348
+ return { ...agent };
349
+ }
350
+ function cloneTool(tool) {
351
+ return { ...tool };
352
+ }
353
+ function cloneRun(run) {
354
+ return { ...run };
355
+ }
356
+ function createDefaultNow() {
357
+ let tick = 0;
358
+ const base = Date.parse("2026-03-20T09:00:00.000Z");
359
+ return () => new Date(base + tick++ * 60000);
360
+ }
361
+ function normalizeProvider(provider) {
362
+ return provider.toLowerCase();
363
+ }
364
+ function normalizeRunStatus(status) {
365
+ return status === "IN_PROGRESS" ? "RUNNING" : status;
366
+ }
367
+ function createSeedState(projectId, organizationId) {
368
+ const agents = MOCK_AGENTS.map((agent) => ({
369
+ id: agent.id,
370
+ projectId,
371
+ organizationId,
372
+ name: agent.name,
373
+ slug: agent.slug,
374
+ description: agent.description,
375
+ modelProvider: normalizeProvider(agent.modelProvider),
376
+ modelName: agent.modelName,
377
+ systemPrompt: agent.systemPrompt,
378
+ temperature: typeof agent.modelConfig?.temperature === "number" ? agent.modelConfig.temperature : 0.4,
379
+ maxTokens: 8192,
380
+ status: agent.status,
381
+ createdAt: agent.createdAt,
382
+ updatedAt: agent.updatedAt
383
+ }));
384
+ const tools = MOCK_TOOLS.map((tool) => ({
385
+ id: tool.id,
386
+ projectId,
387
+ organizationId,
388
+ name: tool.name,
389
+ description: tool.description,
390
+ version: tool.version,
391
+ category: tool.category,
392
+ status: tool.status,
393
+ inputSchema: JSON.stringify(tool.parametersSchema),
394
+ outputSchema: tool.outputSchema ? JSON.stringify(tool.outputSchema) : undefined,
395
+ endpoint: typeof tool.implementationConfig?.url === "string" ? tool.implementationConfig.url : undefined,
396
+ createdAt: tool.createdAt,
397
+ updatedAt: tool.updatedAt
398
+ }));
399
+ const agentNames = new Map(agents.map((agent) => [agent.id, agent.name]));
400
+ const runs = MOCK_RUNS.map((run) => ({
401
+ id: run.id,
402
+ projectId,
403
+ agentId: run.agentId,
404
+ agentName: agentNames.get(run.agentId) ?? run.agentName ?? "Unknown agent",
405
+ status: normalizeRunStatus(run.status),
406
+ input: JSON.stringify(run.input),
407
+ output: run.output ? JSON.stringify(run.output) : undefined,
408
+ totalTokens: run.totalTokens,
409
+ promptTokens: run.promptTokens,
410
+ completionTokens: run.completionTokens,
411
+ estimatedCostUsd: run.estimatedCostUsd ?? 0,
412
+ durationMs: run.durationMs,
413
+ errorMessage: run.errorMessage,
414
+ queuedAt: run.queuedAt,
415
+ startedAt: run.startedAt,
416
+ completedAt: run.completedAt
417
+ }));
418
+ return { agents, tools, runs };
419
+ }
420
+ function summarizeRunMetrics(runs) {
421
+ const totalRuns = runs.length;
422
+ const completedRuns = runs.filter((run) => run.status === "COMPLETED").length;
423
+ const completedDurations = runs.map((run) => run.durationMs).filter((duration) => typeof duration === "number");
424
+ return {
425
+ totalRuns,
426
+ successRate: totalRuns === 0 ? 0 : completedRuns / totalRuns,
427
+ averageDurationMs: completedDurations.length === 0 ? 0 : Math.round(completedDurations.reduce((sum, duration) => sum + duration, 0) / completedDurations.length),
428
+ totalTokens: runs.reduce((sum, run) => sum + run.totalTokens, 0),
429
+ totalCostUsd: runs.reduce((sum, run) => sum + run.estimatedCostUsd, 0)
430
+ };
431
+ }
432
+
433
+ // src/ui/hooks/useAgentMutations.ts
434
+ function normalizeMutationError(error, fallbackMessage) {
435
+ return error instanceof Error ? error : new Error(fallbackMessage);
436
+ }
5
437
  function useAgentMutations(options = {}) {
6
438
  const { handlers, projectId } = useTemplateRuntime();
7
439
  const { agent } = handlers;
@@ -25,16 +457,16 @@ function useAgentMutations(options = {}) {
25
457
  try {
26
458
  const result = await agent.createAgent(input, {
27
459
  projectId,
28
- organizationId: "demo-org"
460
+ organizationId: AGENT_CONSOLE_DEMO_ORGANIZATION_ID
29
461
  });
30
462
  setCreateState({ loading: false, error: null, data: result });
31
463
  options.onSuccess?.();
32
464
  return result;
33
465
  } catch (err) {
34
- const error = err instanceof Error ? err : new Error("Failed to create agent");
466
+ const error = normalizeMutationError(err, "Failed to create agent");
35
467
  setCreateState({ loading: false, error, data: null });
36
468
  options.onError?.(error);
37
- return null;
469
+ throw error;
38
470
  }
39
471
  }, [agent, projectId, options]);
40
472
  const updateAgent = useCallback(async (input) => {
@@ -45,10 +477,10 @@ function useAgentMutations(options = {}) {
45
477
  options.onSuccess?.();
46
478
  return result;
47
479
  } catch (err) {
48
- const error = err instanceof Error ? err : new Error("Failed to update agent");
480
+ const error = normalizeMutationError(err, "Failed to update agent");
49
481
  setUpdateState({ loading: false, error, data: null });
50
482
  options.onError?.(error);
51
- return null;
483
+ throw error;
52
484
  }
53
485
  }, [agent, options]);
54
486
  const activateAgent = useCallback(async (agentId) => {
@@ -66,16 +498,19 @@ function useAgentMutations(options = {}) {
66
498
  const result = await agent.executeAgent({
67
499
  agentId: input.agentId,
68
500
  message: input.message,
69
- context: { projectId, organizationId: "demo-org" }
501
+ context: {
502
+ projectId,
503
+ organizationId: AGENT_CONSOLE_DEMO_ORGANIZATION_ID
504
+ }
70
505
  });
71
506
  setExecuteState({ loading: false, error: null, data: result });
72
507
  options.onSuccess?.();
73
508
  return result;
74
509
  } catch (err) {
75
- const error = err instanceof Error ? err : new Error("Failed to execute agent");
510
+ const error = normalizeMutationError(err, "Failed to execute agent");
76
511
  setExecuteState({ loading: false, error, data: null });
77
512
  options.onError?.(error);
78
- return null;
513
+ throw error;
79
514
  }
80
515
  }, [agent, projectId, options]);
81
516
  return {
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Uses runtime-local database-backed handlers.
5
5
  */
6
+ import type { ContractTableSort } from '@contractspec/lib.presentation-runtime-core';
6
7
  import type { ListRunsOutput as RuntimeListRunsOutput, Run as RuntimeRun, RunMetrics as RuntimeRunMetrics } from '../../handlers/agent.handlers';
7
8
  export type Run = RuntimeRun;
8
9
  export type ListRunsOutput = RuntimeListRunsOutput;
@@ -11,6 +12,9 @@ export interface UseRunListOptions {
11
12
  agentId?: string;
12
13
  status?: Run['status'] | 'all';
13
14
  limit?: number;
15
+ pageIndex?: number;
16
+ pageSize?: number;
17
+ sorting?: ContractTableSort[];
14
18
  }
15
19
  export declare function useRunList(options?: UseRunListOptions): {
16
20
  data: RuntimeListRunsOutput | null;
@@ -18,7 +22,9 @@ export declare function useRunList(options?: UseRunListOptions): {
18
22
  loading: boolean;
19
23
  error: Error | null;
20
24
  page: number;
25
+ pageIndex: number;
26
+ pageSize: number;
21
27
  refetch: () => Promise<void>;
22
- nextPage: () => void;
23
- prevPage: () => false | void;
28
+ nextPage: (() => void) | undefined;
29
+ prevPage: (() => void) | undefined;
24
30
  };
@@ -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,19 +39,31 @@ 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
  export {