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