@contractspec/example.agent-console 3.7.7 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/.turbo/turbo-build.log +126 -105
  2. package/AGENTS.md +3 -1
  3. package/CHANGELOG.md +29 -0
  4. package/README.md +46 -9
  5. package/dist/agent/agent.handler.d.ts +3 -0
  6. package/dist/agent/agent.handler.js +730 -1
  7. package/dist/agent/index.js +73 -72
  8. package/dist/agent.feature.js +179 -0
  9. package/dist/browser/agent/agent.handler.js +730 -1
  10. package/dist/browser/agent/index.js +73 -72
  11. package/dist/browser/agent.feature.js +179 -0
  12. package/dist/browser/docs/agent-console.docblock.js +11 -8
  13. package/dist/browser/docs/index.js +11 -8
  14. package/dist/browser/example.js +2 -3
  15. package/dist/browser/handlers/agent.handlers.js +1883 -2
  16. package/dist/browser/handlers/index.js +2142 -8
  17. package/dist/browser/index.js +3347 -2433
  18. package/dist/browser/presentations/index.js +49 -49
  19. package/dist/browser/run/index.js +818 -812
  20. package/dist/browser/run/run.handler.js +666 -1
  21. package/dist/browser/shared/index.js +293 -1
  22. package/dist/browser/shared/mock-runs.js +5 -0
  23. package/dist/browser/tool/index.js +331 -331
  24. package/dist/browser/tool/tool.handler.js +479 -3
  25. package/dist/browser/ui/AgentDashboard.js +1204 -319
  26. package/dist/browser/ui/AgentDashboard.visualizations.js +217 -0
  27. package/dist/browser/ui/AgentRunList.js +359 -127
  28. package/dist/browser/ui/hooks/index.js +468 -18
  29. package/dist/browser/ui/hooks/useAgentMutations.js +443 -8
  30. package/dist/browser/ui/hooks/useRunList.js +25 -10
  31. package/dist/browser/ui/index.js +1293 -390
  32. package/dist/browser/ui/renderers/agent-list.markdown.js +14 -5
  33. package/dist/browser/ui/renderers/dashboard.markdown.js +207 -36
  34. package/dist/browser/ui/renderers/index.js +245 -49
  35. package/dist/browser/ui/renderers/run-list.markdown.js +9 -4
  36. package/dist/browser/ui/renderers/tool-registry.markdown.js +15 -4
  37. package/dist/browser/ui/views/RunDataTable.js +326 -0
  38. package/dist/browser/ui/views/RunListView.js +359 -127
  39. package/dist/browser/ui/views/index.js +406 -174
  40. package/dist/browser/ui/views/run-data-table.columns.js +271 -0
  41. package/dist/browser/ui/views/run-list.shared.js +177 -0
  42. package/dist/browser/visualizations/catalog.js +134 -0
  43. package/dist/browser/visualizations/index.js +187 -0
  44. package/dist/browser/visualizations/selectors.js +181 -0
  45. package/dist/docs/agent-console.docblock.js +11 -8
  46. package/dist/docs/index.js +11 -8
  47. package/dist/example.js +2 -3
  48. package/dist/example.test.d.ts +1 -0
  49. package/dist/handlers/agent.handlers.d.ts +2 -0
  50. package/dist/handlers/agent.handlers.js +1883 -2
  51. package/dist/handlers/index.d.ts +1 -3
  52. package/dist/handlers/index.js +2142 -8
  53. package/dist/handlers/mock-handlers.test.d.ts +1 -0
  54. package/dist/index.d.ts +2 -0
  55. package/dist/index.js +3347 -2433
  56. package/dist/node/agent/agent.handler.js +730 -1
  57. package/dist/node/agent/index.js +73 -72
  58. package/dist/node/agent.feature.js +179 -0
  59. package/dist/node/docs/agent-console.docblock.js +11 -8
  60. package/dist/node/docs/index.js +11 -8
  61. package/dist/node/example.js +2 -3
  62. package/dist/node/handlers/agent.handlers.js +1883 -2
  63. package/dist/node/handlers/index.js +2142 -8
  64. package/dist/node/index.js +3347 -2433
  65. package/dist/node/presentations/index.js +49 -49
  66. package/dist/node/run/index.js +818 -812
  67. package/dist/node/run/run.handler.js +666 -1
  68. package/dist/node/shared/index.js +293 -1
  69. package/dist/node/shared/mock-runs.js +5 -0
  70. package/dist/node/tool/index.js +331 -331
  71. package/dist/node/tool/tool.handler.js +479 -3
  72. package/dist/node/ui/AgentDashboard.js +1204 -319
  73. package/dist/node/ui/AgentDashboard.visualizations.js +217 -0
  74. package/dist/node/ui/AgentRunList.js +359 -127
  75. package/dist/node/ui/hooks/index.js +468 -18
  76. package/dist/node/ui/hooks/useAgentMutations.js +443 -8
  77. package/dist/node/ui/hooks/useRunList.js +25 -10
  78. package/dist/node/ui/index.js +1293 -390
  79. package/dist/node/ui/renderers/agent-list.markdown.js +14 -5
  80. package/dist/node/ui/renderers/dashboard.markdown.js +207 -36
  81. package/dist/node/ui/renderers/index.js +245 -49
  82. package/dist/node/ui/renderers/run-list.markdown.js +9 -4
  83. package/dist/node/ui/renderers/tool-registry.markdown.js +15 -4
  84. package/dist/node/ui/views/RunDataTable.js +326 -0
  85. package/dist/node/ui/views/RunListView.js +359 -127
  86. package/dist/node/ui/views/index.js +406 -174
  87. package/dist/node/ui/views/run-data-table.columns.js +271 -0
  88. package/dist/node/ui/views/run-list.shared.js +177 -0
  89. package/dist/node/visualizations/catalog.js +134 -0
  90. package/dist/node/visualizations/index.js +187 -0
  91. package/dist/node/visualizations/selectors.js +181 -0
  92. package/dist/presentations/index.js +49 -49
  93. package/dist/proof/index.d.ts +2 -0
  94. package/dist/proof/meetup-proof.d.ts +10 -0
  95. package/dist/proof/meetup-proof.runtime.d.ts +22 -0
  96. package/dist/proof/meetup-proof.scenario.d.ts +2 -0
  97. package/dist/proof/meetup-proof.suite.d.ts +1 -0
  98. package/dist/proof/meetup-proof.test.d.ts +1 -0
  99. package/dist/run/index.js +818 -812
  100. package/dist/run/run.handler.d.ts +4 -0
  101. package/dist/run/run.handler.js +666 -1
  102. package/dist/shared/demo-dashboard-data.d.ts +16 -0
  103. package/dist/shared/demo-runtime-seed.d.ts +17 -0
  104. package/dist/shared/demo-runtime.d.ts +8 -0
  105. package/dist/shared/demo-runtime.test.d.ts +1 -0
  106. package/dist/shared/index.d.ts +3 -0
  107. package/dist/shared/index.js +293 -1
  108. package/dist/shared/mock-runs.d.ts +4 -0
  109. package/dist/shared/mock-runs.js +5 -0
  110. package/dist/tool/index.js +331 -331
  111. package/dist/tool/tool.handler.d.ts +4 -1
  112. package/dist/tool/tool.handler.js +479 -3
  113. package/dist/ui/AgentDashboard.js +1204 -319
  114. package/dist/ui/AgentDashboard.sandbox.test.d.ts +1 -0
  115. package/dist/ui/AgentDashboard.visualizations.d.ts +4 -0
  116. package/dist/ui/AgentDashboard.visualizations.js +218 -0
  117. package/dist/ui/AgentRunList.js +359 -127
  118. package/dist/ui/hooks/index.js +468 -18
  119. package/dist/ui/hooks/useAgentMutations.js +443 -8
  120. package/dist/ui/hooks/useRunList.d.ts +8 -2
  121. package/dist/ui/hooks/useRunList.js +25 -10
  122. package/dist/ui/index.js +1293 -390
  123. package/dist/ui/renderers/agent-list.markdown.js +14 -5
  124. package/dist/ui/renderers/dashboard.markdown.js +207 -36
  125. package/dist/ui/renderers/index.js +245 -49
  126. package/dist/ui/renderers/run-list.markdown.js +9 -4
  127. package/dist/ui/renderers/tool-registry.markdown.d.ts +1 -1
  128. package/dist/ui/renderers/tool-registry.markdown.js +15 -4
  129. package/dist/ui/views/RunDataTable.d.ts +18 -0
  130. package/dist/ui/views/RunDataTable.js +327 -0
  131. package/dist/ui/views/RunListView.js +359 -127
  132. package/dist/ui/views/index.js +406 -174
  133. package/dist/ui/views/run-data-table.columns.d.ts +3 -0
  134. package/dist/ui/views/run-data-table.columns.js +272 -0
  135. package/dist/ui/views/run-list.shared.d.ts +14 -0
  136. package/dist/ui/views/run-list.shared.js +178 -0
  137. package/dist/visualizations/catalog.d.ts +10 -0
  138. package/dist/visualizations/catalog.js +135 -0
  139. package/dist/visualizations/index.d.ts +2 -0
  140. package/dist/visualizations/index.js +188 -0
  141. package/dist/visualizations/selectors.d.ts +3 -0
  142. package/dist/visualizations/selectors.js +182 -0
  143. package/dist/visualizations/selectors.test.d.ts +1 -0
  144. package/package.json +112 -10
  145. package/proofs/agent-console-meetup.replay.json +220 -0
  146. package/src/agent/agent.handler.ts +18 -1
  147. package/src/agent.feature.ts +3 -0
  148. package/src/docs/agent-console.docblock.ts +11 -8
  149. package/src/example.test.ts +75 -0
  150. package/src/example.ts +2 -3
  151. package/src/handlers/agent.handlers.ts +55 -2
  152. package/src/handlers/index.ts +18 -2
  153. package/src/handlers/mock-handlers.test.ts +77 -0
  154. package/src/index.ts +2 -0
  155. package/src/proof/index.ts +2 -0
  156. package/src/proof/meetup-proof.runtime.ts +196 -0
  157. package/src/proof/meetup-proof.scenario.ts +99 -0
  158. package/src/proof/meetup-proof.suite.ts +29 -0
  159. package/src/proof/meetup-proof.test.ts +28 -0
  160. package/src/proof/meetup-proof.ts +130 -0
  161. package/src/run/run.handler.ts +17 -1
  162. package/src/shared/demo-dashboard-data.ts +58 -0
  163. package/src/shared/demo-runtime-seed.ts +139 -0
  164. package/src/shared/demo-runtime.test.ts +169 -0
  165. package/src/shared/demo-runtime.ts +260 -0
  166. package/src/shared/index.ts +11 -0
  167. package/src/shared/mock-runs.ts +5 -0
  168. package/src/tool/tool.handler.ts +21 -4
  169. package/src/ui/AgentDashboard.sandbox.test.tsx +312 -0
  170. package/src/ui/AgentDashboard.tsx +4 -1
  171. package/src/ui/AgentDashboard.visualizations.tsx +35 -0
  172. package/src/ui/hooks/useAgentMutations.ts +19 -11
  173. package/src/ui/hooks/useRunList.ts +41 -9
  174. package/src/ui/renderers/agent-list.markdown.ts +31 -12
  175. package/src/ui/renderers/dashboard.markdown.ts +37 -42
  176. package/src/ui/renderers/run-list.markdown.ts +16 -8
  177. package/src/ui/renderers/tool-registry.markdown.ts +21 -9
  178. package/src/ui/views/RunDataTable.tsx +74 -0
  179. package/src/ui/views/RunListView.tsx +37 -111
  180. package/src/ui/views/run-data-table.columns.tsx +102 -0
  181. package/src/ui/views/run-list.shared.tsx +139 -0
  182. package/src/visualizations/catalog.ts +132 -0
  183. package/src/visualizations/index.ts +2 -0
  184. package/src/visualizations/selectors.test.ts +12 -0
  185. package/src/visualizations/selectors.ts +70 -0
  186. package/tsdown.config.js +17 -0
@@ -79,11 +79,671 @@ var MOCK_AGENTS = [
79
79
  }
80
80
  ];
81
81
 
82
+ // src/run/run.enum.ts
83
+ import { defineEnum } from "@contractspec/lib.schema";
84
+ var RunStatusEnum = defineEnum("RunStatus", [
85
+ "QUEUED",
86
+ "IN_PROGRESS",
87
+ "COMPLETED",
88
+ "FAILED",
89
+ "CANCELLED",
90
+ "EXPIRED"
91
+ ]);
92
+ var RunStepTypeEnum = defineEnum("RunStepType", [
93
+ "MESSAGE_CREATION",
94
+ "TOOL_CALL",
95
+ "TOOL_RESULT",
96
+ "ERROR"
97
+ ]);
98
+ var LogLevelEnum = defineEnum("LogLevel", [
99
+ "DEBUG",
100
+ "INFO",
101
+ "WARN",
102
+ "ERROR"
103
+ ]);
104
+ var GranularityEnum = defineEnum("Granularity", [
105
+ "hour",
106
+ "day",
107
+ "week",
108
+ "month"
109
+ ]);
110
+
111
+ // src/run/run.schema.ts
112
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
113
+ var RunInputModel = defineSchemaModel({
114
+ name: "RunInput",
115
+ description: "Input data for agent execution",
116
+ fields: {
117
+ message: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
118
+ context: { type: ScalarTypeEnum.JSONObject(), isOptional: true }
119
+ }
120
+ });
121
+ var RunStepModel = defineSchemaModel({
122
+ name: "RunStep",
123
+ description: "Individual step within a run",
124
+ fields: {
125
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
126
+ stepNumber: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
127
+ type: { type: RunStepTypeEnum, isOptional: false },
128
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
129
+ toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
130
+ input: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
131
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
132
+ status: { type: RunStatusEnum, isOptional: false },
133
+ errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
134
+ tokensUsed: {
135
+ type: ScalarTypeEnum.Int_unsecure(),
136
+ isOptional: false,
137
+ defaultValue: 0
138
+ },
139
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
140
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
141
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
142
+ }
143
+ });
144
+ var RunLogModel = defineSchemaModel({
145
+ name: "RunLog",
146
+ description: "Execution log entry",
147
+ fields: {
148
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
149
+ stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
150
+ level: { type: LogLevelEnum, isOptional: false },
151
+ message: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
152
+ data: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
153
+ source: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
154
+ traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
155
+ spanId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
156
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
157
+ }
158
+ });
159
+ var RunAgentRefModel = defineSchemaModel({
160
+ name: "RunAgentRef",
161
+ description: "Agent reference in a run",
162
+ fields: {
163
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
164
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
165
+ modelProvider: {
166
+ type: ScalarTypeEnum.String_unsecure(),
167
+ isOptional: false
168
+ },
169
+ modelName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
170
+ }
171
+ });
172
+ var RunModel = defineSchemaModel({
173
+ name: "Run",
174
+ description: "Agent execution instance",
175
+ fields: {
176
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
177
+ organizationId: {
178
+ type: ScalarTypeEnum.String_unsecure(),
179
+ isOptional: false
180
+ },
181
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
182
+ userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
183
+ sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
184
+ input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
185
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
186
+ status: { type: RunStatusEnum, isOptional: false },
187
+ errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
188
+ errorCode: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
189
+ totalTokens: {
190
+ type: ScalarTypeEnum.Int_unsecure(),
191
+ isOptional: false,
192
+ defaultValue: 0
193
+ },
194
+ promptTokens: {
195
+ type: ScalarTypeEnum.Int_unsecure(),
196
+ isOptional: false,
197
+ defaultValue: 0
198
+ },
199
+ completionTokens: {
200
+ type: ScalarTypeEnum.Int_unsecure(),
201
+ isOptional: false,
202
+ defaultValue: 0
203
+ },
204
+ totalIterations: {
205
+ type: ScalarTypeEnum.Int_unsecure(),
206
+ isOptional: false,
207
+ defaultValue: 0
208
+ },
209
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
210
+ estimatedCostUsd: {
211
+ type: ScalarTypeEnum.Float_unsecure(),
212
+ isOptional: true
213
+ },
214
+ queuedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
215
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
216
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
217
+ metadata: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
218
+ steps: { type: RunStepModel, isArray: true, isOptional: true },
219
+ logs: { type: RunLogModel, isArray: true, isOptional: true },
220
+ agent: { type: RunAgentRefModel, isOptional: true }
221
+ }
222
+ });
223
+ var RunSummaryModel = defineSchemaModel({
224
+ name: "RunSummary",
225
+ description: "Summary of a run for list views",
226
+ fields: {
227
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
228
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
229
+ agentName: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
230
+ status: { type: RunStatusEnum, isOptional: false },
231
+ totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
232
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
233
+ estimatedCostUsd: {
234
+ type: ScalarTypeEnum.Float_unsecure(),
235
+ isOptional: true
236
+ },
237
+ queuedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
238
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
239
+ }
240
+ });
241
+ var TimelineDataPointModel = defineSchemaModel({
242
+ name: "TimelineDataPoint",
243
+ description: "Timeline data point for metrics",
244
+ fields: {
245
+ period: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
246
+ runs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
247
+ tokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
248
+ costUsd: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
249
+ avgDurationMs: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false }
250
+ }
251
+ });
252
+
253
+ // src/run/run.operation.ts
254
+ import {
255
+ defineCommand,
256
+ defineQuery
257
+ } from "@contractspec/lib.contracts-spec/operations";
258
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
259
+ var OWNERS = ["@agent-console-team"];
260
+ var ExecuteAgentCommand = defineCommand({
261
+ meta: {
262
+ key: "agent.run.execute",
263
+ version: "1.0.0",
264
+ stability: "stable",
265
+ owners: [...OWNERS],
266
+ tags: ["run", "execute"],
267
+ description: "Starts a new agent run with the given input.",
268
+ goal: "Execute an AI agent with user input.",
269
+ context: "Called from chat interface or API."
270
+ },
271
+ io: {
272
+ input: defineSchemaModel2({
273
+ name: "ExecuteAgentInput",
274
+ fields: {
275
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
276
+ input: { type: RunInputModel, isOptional: false },
277
+ sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
278
+ metadata: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
279
+ stream: { type: ScalarTypeEnum2.Boolean(), isOptional: true },
280
+ maxIterations: {
281
+ type: ScalarTypeEnum2.Int_unsecure(),
282
+ isOptional: true
283
+ },
284
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true }
285
+ }
286
+ }),
287
+ output: defineSchemaModel2({
288
+ name: "ExecuteAgentOutput",
289
+ fields: {
290
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
291
+ status: { type: RunStatusEnum, isOptional: false },
292
+ estimatedWaitMs: {
293
+ type: ScalarTypeEnum2.Int_unsecure(),
294
+ isOptional: true
295
+ }
296
+ }
297
+ }),
298
+ errors: {
299
+ AGENT_NOT_FOUND: {
300
+ description: "The specified agent does not exist",
301
+ http: 404,
302
+ gqlCode: "AGENT_NOT_FOUND",
303
+ when: "Agent ID is invalid"
304
+ },
305
+ AGENT_NOT_ACTIVE: {
306
+ description: "The specified agent is not active",
307
+ http: 400,
308
+ gqlCode: "AGENT_NOT_ACTIVE",
309
+ when: "Agent is in draft/paused/archived state"
310
+ }
311
+ }
312
+ },
313
+ policy: { auth: "user" },
314
+ sideEffects: {
315
+ emits: [
316
+ {
317
+ key: "run.started",
318
+ version: "1.0.0",
319
+ stability: "stable",
320
+ owners: [...OWNERS],
321
+ tags: ["run", "started"],
322
+ when: "Run is queued",
323
+ payload: RunSummaryModel
324
+ }
325
+ ],
326
+ audit: ["run.started"]
327
+ },
328
+ acceptance: {
329
+ scenarios: [
330
+ {
331
+ key: "execute-agent-happy-path",
332
+ given: ["Agent exists", "Agent is active"],
333
+ when: ["User submits execution request"],
334
+ then: ["Run is created", "RunStarted event is emitted"]
335
+ },
336
+ {
337
+ key: "execute-agent-not-active",
338
+ given: ["Agent exists but is not active"],
339
+ when: ["User attempts to execute"],
340
+ then: ["AGENT_NOT_ACTIVE error is returned"]
341
+ }
342
+ ],
343
+ examples: [
344
+ {
345
+ key: "basic-execute",
346
+ input: { agentId: "agent-123", input: { message: "Hello" } },
347
+ output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
348
+ }
349
+ ]
350
+ }
351
+ });
352
+ var CancelRunCommand = defineCommand({
353
+ meta: {
354
+ key: "agent.run.cancel",
355
+ version: "1.0.0",
356
+ stability: "stable",
357
+ owners: [...OWNERS],
358
+ tags: ["run", "cancel"],
359
+ description: "Cancels an in-progress agent run.",
360
+ goal: "Stop a running agent execution.",
361
+ context: "Called when user wants to abort a long-running task."
362
+ },
363
+ io: {
364
+ input: defineSchemaModel2({
365
+ name: "CancelRunInput",
366
+ fields: {
367
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
368
+ reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
369
+ }
370
+ }),
371
+ output: defineSchemaModel2({
372
+ name: "CancelRunOutput",
373
+ fields: {
374
+ success: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
375
+ status: { type: RunStatusEnum, isOptional: false }
376
+ }
377
+ }),
378
+ errors: {
379
+ RUN_NOT_FOUND: {
380
+ description: "The specified run does not exist",
381
+ http: 404,
382
+ gqlCode: "RUN_NOT_FOUND",
383
+ when: "Run ID is invalid"
384
+ },
385
+ RUN_NOT_CANCELLABLE: {
386
+ description: "The run cannot be cancelled",
387
+ http: 400,
388
+ gqlCode: "RUN_NOT_CANCELLABLE",
389
+ when: "Run is already completed/failed/cancelled"
390
+ }
391
+ }
392
+ },
393
+ policy: { auth: "user" },
394
+ sideEffects: {
395
+ emits: [
396
+ {
397
+ key: "run.cancelled",
398
+ version: "1.0.0",
399
+ stability: "stable",
400
+ owners: [...OWNERS],
401
+ tags: ["run", "cancelled"],
402
+ when: "Run is cancelled",
403
+ payload: RunSummaryModel
404
+ }
405
+ ],
406
+ audit: ["run.cancelled"]
407
+ },
408
+ acceptance: {
409
+ scenarios: [
410
+ {
411
+ key: "cancel-run-happy-path",
412
+ given: ["Run exists", "Run is in progress"],
413
+ when: ["User cancels run"],
414
+ then: ["Run is cancelled", "RunCancelled event is emitted"]
415
+ },
416
+ {
417
+ key: "cancel-run-already-completed",
418
+ given: ["Run exists but is already completed"],
419
+ when: ["User attempts to cancel"],
420
+ then: ["RUN_NOT_CANCELLABLE error is returned"]
421
+ }
422
+ ],
423
+ examples: [
424
+ {
425
+ key: "cancel-basic",
426
+ input: { runId: "run-456", reason: "User requested" },
427
+ output: { success: true, status: "cancelled" }
428
+ }
429
+ ]
430
+ }
431
+ });
432
+ var GetRunQuery = defineQuery({
433
+ meta: {
434
+ key: "agent.run.get",
435
+ version: "1.0.0",
436
+ stability: "stable",
437
+ owners: [...OWNERS],
438
+ tags: ["run", "get"],
439
+ description: "Retrieves a run by its ID with optional details.",
440
+ goal: "View detailed run information.",
441
+ context: "Run details page or monitoring."
442
+ },
443
+ io: {
444
+ input: defineSchemaModel2({
445
+ name: "GetRunInput",
446
+ fields: {
447
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
448
+ includeSteps: { type: ScalarTypeEnum2.Boolean(), isOptional: true },
449
+ includeLogs: { type: ScalarTypeEnum2.Boolean(), isOptional: true }
450
+ }
451
+ }),
452
+ output: RunModel,
453
+ errors: {
454
+ RUN_NOT_FOUND: {
455
+ description: "The specified run does not exist",
456
+ http: 404,
457
+ gqlCode: "RUN_NOT_FOUND",
458
+ when: "Run ID is invalid"
459
+ }
460
+ }
461
+ },
462
+ policy: { auth: "user" },
463
+ acceptance: {
464
+ scenarios: [
465
+ {
466
+ key: "get-run-happy-path",
467
+ given: ["Run exists"],
468
+ when: ["User requests run by ID"],
469
+ then: ["Run details are returned"]
470
+ }
471
+ ],
472
+ examples: [
473
+ {
474
+ key: "get-with-steps",
475
+ input: { runId: "run-456", includeSteps: true, includeLogs: false },
476
+ output: { id: "run-456", status: "completed", steps: [] }
477
+ }
478
+ ]
479
+ }
480
+ });
481
+ var ListRunsQuery = defineQuery({
482
+ meta: {
483
+ key: "agent.run.list",
484
+ version: "1.0.0",
485
+ stability: "stable",
486
+ owners: [...OWNERS],
487
+ tags: ["run", "list"],
488
+ description: "Lists runs with optional filtering.",
489
+ goal: "Browse and search run history.",
490
+ context: "Run history/dashboard view."
491
+ },
492
+ io: {
493
+ input: defineSchemaModel2({
494
+ name: "ListRunsInput",
495
+ fields: {
496
+ organizationId: {
497
+ type: ScalarTypeEnum2.String_unsecure(),
498
+ isOptional: true
499
+ },
500
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
501
+ userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
502
+ sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
503
+ status: { type: RunStatusEnum, isOptional: true },
504
+ startDate: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
505
+ endDate: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
506
+ limit: {
507
+ type: ScalarTypeEnum2.Int_unsecure(),
508
+ isOptional: true,
509
+ defaultValue: 20
510
+ },
511
+ offset: {
512
+ type: ScalarTypeEnum2.Int_unsecure(),
513
+ isOptional: true,
514
+ defaultValue: 0
515
+ }
516
+ }
517
+ }),
518
+ output: defineSchemaModel2({
519
+ name: "ListRunsOutput",
520
+ fields: {
521
+ items: { type: RunSummaryModel, isArray: true, isOptional: false },
522
+ total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
523
+ hasMore: { type: ScalarTypeEnum2.Boolean(), isOptional: false }
524
+ }
525
+ })
526
+ },
527
+ policy: { auth: "user" },
528
+ acceptance: {
529
+ scenarios: [
530
+ {
531
+ key: "list-runs-happy-path",
532
+ given: ["Organization has runs"],
533
+ when: ["User lists runs"],
534
+ then: ["Paginated list of runs is returned"]
535
+ }
536
+ ],
537
+ examples: [
538
+ {
539
+ key: "list-by-agent",
540
+ input: { agentId: "agent-123", limit: 20, offset: 0 },
541
+ output: { items: [], total: 0, hasMore: false }
542
+ }
543
+ ]
544
+ }
545
+ });
546
+ var GetRunStepsQuery = defineQuery({
547
+ meta: {
548
+ key: "agent.run.getSteps",
549
+ version: "1.0.0",
550
+ stability: "stable",
551
+ owners: [...OWNERS],
552
+ tags: ["run", "steps"],
553
+ description: "Retrieves all steps for a specific run.",
554
+ goal: "View step-by-step execution details.",
555
+ context: "Run details page - steps tab."
556
+ },
557
+ io: {
558
+ input: defineSchemaModel2({
559
+ name: "GetRunStepsInput",
560
+ fields: {
561
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
562
+ }
563
+ }),
564
+ output: defineSchemaModel2({
565
+ name: "GetRunStepsOutput",
566
+ fields: {
567
+ steps: { type: RunStepModel, isArray: true, isOptional: false }
568
+ }
569
+ })
570
+ },
571
+ policy: { auth: "user" },
572
+ acceptance: {
573
+ scenarios: [
574
+ {
575
+ key: "get-run-steps-happy-path",
576
+ given: ["Run exists with steps"],
577
+ when: ["User requests steps"],
578
+ then: ["Steps list is returned"]
579
+ }
580
+ ],
581
+ examples: [
582
+ {
583
+ key: "get-steps-basic",
584
+ input: { runId: "run-456" },
585
+ output: { steps: [] }
586
+ }
587
+ ]
588
+ }
589
+ });
590
+ var GetRunLogsQuery = defineQuery({
591
+ meta: {
592
+ key: "agent.run.getLogs",
593
+ version: "1.0.0",
594
+ stability: "stable",
595
+ owners: [...OWNERS],
596
+ tags: ["run", "logs"],
597
+ description: "Retrieves all logs for a specific run.",
598
+ goal: "Debug and audit run execution.",
599
+ context: "Run details page - logs tab."
600
+ },
601
+ io: {
602
+ input: defineSchemaModel2({
603
+ name: "GetRunLogsInput",
604
+ fields: {
605
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
606
+ level: { type: LogLevelEnum, isOptional: true },
607
+ stepId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
608
+ limit: {
609
+ type: ScalarTypeEnum2.Int_unsecure(),
610
+ isOptional: true,
611
+ defaultValue: 100
612
+ },
613
+ offset: {
614
+ type: ScalarTypeEnum2.Int_unsecure(),
615
+ isOptional: true,
616
+ defaultValue: 0
617
+ }
618
+ }
619
+ }),
620
+ output: defineSchemaModel2({
621
+ name: "GetRunLogsOutput",
622
+ fields: {
623
+ items: { type: RunLogModel, isArray: true, isOptional: false },
624
+ total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
625
+ hasMore: { type: ScalarTypeEnum2.Boolean(), isOptional: false }
626
+ }
627
+ })
628
+ },
629
+ policy: { auth: "user" },
630
+ acceptance: {
631
+ scenarios: [
632
+ {
633
+ key: "get-run-logs-happy-path",
634
+ given: ["Run exists with logs"],
635
+ when: ["User requests logs"],
636
+ then: ["Paginated logs list is returned"]
637
+ }
638
+ ],
639
+ examples: [
640
+ {
641
+ key: "get-logs-filtered",
642
+ input: { runId: "run-456", level: "error", limit: 50 },
643
+ output: { items: [], total: 0, hasMore: false }
644
+ }
645
+ ]
646
+ }
647
+ });
648
+ var GetRunMetricsQuery = defineQuery({
649
+ meta: {
650
+ key: "agent.run.getMetrics",
651
+ version: "1.0.0",
652
+ stability: "stable",
653
+ owners: [...OWNERS],
654
+ tags: ["run", "metrics"],
655
+ description: "Retrieves aggregated metrics for runs within a time period.",
656
+ goal: "Monitor and analyze agent usage.",
657
+ context: "Analytics dashboard."
658
+ },
659
+ io: {
660
+ input: defineSchemaModel2({
661
+ name: "GetRunMetricsInput",
662
+ fields: {
663
+ organizationId: {
664
+ type: ScalarTypeEnum2.String_unsecure(),
665
+ isOptional: false
666
+ },
667
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
668
+ startDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
669
+ endDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
670
+ granularity: {
671
+ type: GranularityEnum,
672
+ isOptional: true,
673
+ defaultValue: "day"
674
+ }
675
+ }
676
+ }),
677
+ output: defineSchemaModel2({
678
+ name: "GetRunMetricsOutput",
679
+ fields: {
680
+ totalRuns: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
681
+ completedRuns: {
682
+ type: ScalarTypeEnum2.Int_unsecure(),
683
+ isOptional: false
684
+ },
685
+ failedRuns: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
686
+ totalTokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
687
+ totalCostUsd: {
688
+ type: ScalarTypeEnum2.Float_unsecure(),
689
+ isOptional: false
690
+ },
691
+ averageDurationMs: {
692
+ type: ScalarTypeEnum2.Float_unsecure(),
693
+ isOptional: false
694
+ },
695
+ successRate: {
696
+ type: ScalarTypeEnum2.Float_unsecure(),
697
+ isOptional: false
698
+ },
699
+ timeline: {
700
+ type: TimelineDataPointModel,
701
+ isArray: true,
702
+ isOptional: false
703
+ }
704
+ }
705
+ })
706
+ },
707
+ policy: { auth: "user" },
708
+ acceptance: {
709
+ scenarios: [
710
+ {
711
+ key: "get-run-metrics-happy-path",
712
+ given: ["Organization has run history"],
713
+ when: ["User requests metrics for date range"],
714
+ then: ["Aggregated metrics are returned"]
715
+ }
716
+ ],
717
+ examples: [
718
+ {
719
+ key: "get-daily-metrics",
720
+ input: {
721
+ organizationId: "org-123",
722
+ startDate: "2025-01-01",
723
+ endDate: "2025-01-31",
724
+ granularity: "day"
725
+ },
726
+ output: {
727
+ totalRuns: 100,
728
+ completedRuns: 90,
729
+ failedRuns: 10,
730
+ totalTokens: 50000,
731
+ totalCostUsd: 5,
732
+ averageDurationMs: 2500,
733
+ successRate: 0.9,
734
+ timeline: []
735
+ }
736
+ }
737
+ ]
738
+ }
739
+ });
740
+
82
741
  // src/shared/mock-runs.ts
83
742
  var MOCK_RUNS = [
84
743
  {
85
744
  id: "run-1",
86
745
  organizationId: "demo-org",
746
+ projectId: "demo-project",
87
747
  agentId: "agent-1",
88
748
  agentName: "Customer Support Bot",
89
749
  userId: "user-1",
@@ -106,6 +766,7 @@ var MOCK_RUNS = [
106
766
  {
107
767
  id: "run-2",
108
768
  organizationId: "demo-org",
769
+ projectId: "demo-project",
109
770
  agentId: "agent-2",
110
771
  agentName: "Code Review Assistant",
111
772
  userId: "user-2",
@@ -123,6 +784,7 @@ var MOCK_RUNS = [
123
784
  {
124
785
  id: "run-3",
125
786
  organizationId: "demo-org",
787
+ projectId: "demo-project",
126
788
  agentId: "agent-1",
127
789
  agentName: "Customer Support Bot",
128
790
  userId: "user-1",
@@ -144,6 +806,7 @@ var MOCK_RUNS = [
144
806
  {
145
807
  id: "run-4",
146
808
  organizationId: "demo-org",
809
+ projectId: "demo-project",
147
810
  agentId: "agent-3",
148
811
  agentName: "Data Analyst",
149
812
  userId: "user-3",
@@ -165,6 +828,7 @@ var MOCK_RUNS = [
165
828
  {
166
829
  id: "run-5",
167
830
  organizationId: "demo-org",
831
+ projectId: "demo-project",
168
832
  agentId: "agent-2",
169
833
  agentName: "Code Review Assistant",
170
834
  userId: "user-2",
@@ -186,6 +850,7 @@ var MOCK_RUNS = [
186
850
  ];
187
851
 
188
852
  // src/run/run.handler.ts
853
+ var nextMockRunId = MOCK_RUNS.length + 1;
189
854
  async function mockListRunsHandler(input) {
190
855
  const { agentId, status, limit = 20, offset = 0 } = input;
191
856
  let filtered = [...MOCK_RUNS];
@@ -234,7 +899,7 @@ async function mockExecuteAgentHandler(input) {
234
899
  if (agent.status !== "ACTIVE")
235
900
  throw new Error("AGENT_NOT_ACTIVE");
236
901
  return {
237
- runId: `run-${Date.now()}`,
902
+ runId: `run-${nextMockRunId++}`,
238
903
  status: "QUEUED",
239
904
  estimatedWaitMs: 500
240
905
  };