@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
@@ -78,11 +78,671 @@ var MOCK_AGENTS = [
78
78
  }
79
79
  ];
80
80
 
81
+ // src/run/run.enum.ts
82
+ import { defineEnum } from "@contractspec/lib.schema";
83
+ var RunStatusEnum = defineEnum("RunStatus", [
84
+ "QUEUED",
85
+ "IN_PROGRESS",
86
+ "COMPLETED",
87
+ "FAILED",
88
+ "CANCELLED",
89
+ "EXPIRED"
90
+ ]);
91
+ var RunStepTypeEnum = defineEnum("RunStepType", [
92
+ "MESSAGE_CREATION",
93
+ "TOOL_CALL",
94
+ "TOOL_RESULT",
95
+ "ERROR"
96
+ ]);
97
+ var LogLevelEnum = defineEnum("LogLevel", [
98
+ "DEBUG",
99
+ "INFO",
100
+ "WARN",
101
+ "ERROR"
102
+ ]);
103
+ var GranularityEnum = defineEnum("Granularity", [
104
+ "hour",
105
+ "day",
106
+ "week",
107
+ "month"
108
+ ]);
109
+
110
+ // src/run/run.schema.ts
111
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
112
+ var RunInputModel = defineSchemaModel({
113
+ name: "RunInput",
114
+ description: "Input data for agent execution",
115
+ fields: {
116
+ message: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
117
+ context: { type: ScalarTypeEnum.JSONObject(), isOptional: true }
118
+ }
119
+ });
120
+ var RunStepModel = defineSchemaModel({
121
+ name: "RunStep",
122
+ description: "Individual step within a run",
123
+ fields: {
124
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
125
+ stepNumber: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
126
+ type: { type: RunStepTypeEnum, isOptional: false },
127
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
128
+ toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
129
+ input: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
130
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
131
+ status: { type: RunStatusEnum, isOptional: false },
132
+ errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
133
+ tokensUsed: {
134
+ type: ScalarTypeEnum.Int_unsecure(),
135
+ isOptional: false,
136
+ defaultValue: 0
137
+ },
138
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
139
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
140
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
141
+ }
142
+ });
143
+ var RunLogModel = defineSchemaModel({
144
+ name: "RunLog",
145
+ description: "Execution log entry",
146
+ fields: {
147
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
148
+ stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
149
+ level: { type: LogLevelEnum, isOptional: false },
150
+ message: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
151
+ data: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
152
+ source: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
153
+ traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
154
+ spanId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
155
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
156
+ }
157
+ });
158
+ var RunAgentRefModel = defineSchemaModel({
159
+ name: "RunAgentRef",
160
+ description: "Agent reference in a run",
161
+ fields: {
162
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
163
+ name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
164
+ modelProvider: {
165
+ type: ScalarTypeEnum.String_unsecure(),
166
+ isOptional: false
167
+ },
168
+ modelName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
169
+ }
170
+ });
171
+ var RunModel = defineSchemaModel({
172
+ name: "Run",
173
+ description: "Agent execution instance",
174
+ fields: {
175
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
176
+ organizationId: {
177
+ type: ScalarTypeEnum.String_unsecure(),
178
+ isOptional: false
179
+ },
180
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
181
+ userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
182
+ sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
183
+ input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
184
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
185
+ status: { type: RunStatusEnum, isOptional: false },
186
+ errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
187
+ errorCode: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
188
+ totalTokens: {
189
+ type: ScalarTypeEnum.Int_unsecure(),
190
+ isOptional: false,
191
+ defaultValue: 0
192
+ },
193
+ promptTokens: {
194
+ type: ScalarTypeEnum.Int_unsecure(),
195
+ isOptional: false,
196
+ defaultValue: 0
197
+ },
198
+ completionTokens: {
199
+ type: ScalarTypeEnum.Int_unsecure(),
200
+ isOptional: false,
201
+ defaultValue: 0
202
+ },
203
+ totalIterations: {
204
+ type: ScalarTypeEnum.Int_unsecure(),
205
+ isOptional: false,
206
+ defaultValue: 0
207
+ },
208
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
209
+ estimatedCostUsd: {
210
+ type: ScalarTypeEnum.Float_unsecure(),
211
+ isOptional: true
212
+ },
213
+ queuedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
214
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
215
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
216
+ metadata: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
217
+ steps: { type: RunStepModel, isArray: true, isOptional: true },
218
+ logs: { type: RunLogModel, isArray: true, isOptional: true },
219
+ agent: { type: RunAgentRefModel, isOptional: true }
220
+ }
221
+ });
222
+ var RunSummaryModel = defineSchemaModel({
223
+ name: "RunSummary",
224
+ description: "Summary of a run for list views",
225
+ fields: {
226
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
227
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
228
+ agentName: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
229
+ status: { type: RunStatusEnum, isOptional: false },
230
+ totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
231
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
232
+ estimatedCostUsd: {
233
+ type: ScalarTypeEnum.Float_unsecure(),
234
+ isOptional: true
235
+ },
236
+ queuedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
237
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
238
+ }
239
+ });
240
+ var TimelineDataPointModel = defineSchemaModel({
241
+ name: "TimelineDataPoint",
242
+ description: "Timeline data point for metrics",
243
+ fields: {
244
+ period: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
245
+ runs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
246
+ tokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
247
+ costUsd: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
248
+ avgDurationMs: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false }
249
+ }
250
+ });
251
+
252
+ // src/run/run.operation.ts
253
+ import {
254
+ defineCommand,
255
+ defineQuery
256
+ } from "@contractspec/lib.contracts-spec/operations";
257
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
258
+ var OWNERS = ["@agent-console-team"];
259
+ var ExecuteAgentCommand = defineCommand({
260
+ meta: {
261
+ key: "agent.run.execute",
262
+ version: "1.0.0",
263
+ stability: "stable",
264
+ owners: [...OWNERS],
265
+ tags: ["run", "execute"],
266
+ description: "Starts a new agent run with the given input.",
267
+ goal: "Execute an AI agent with user input.",
268
+ context: "Called from chat interface or API."
269
+ },
270
+ io: {
271
+ input: defineSchemaModel2({
272
+ name: "ExecuteAgentInput",
273
+ fields: {
274
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
275
+ input: { type: RunInputModel, isOptional: false },
276
+ sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
277
+ metadata: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
278
+ stream: { type: ScalarTypeEnum2.Boolean(), isOptional: true },
279
+ maxIterations: {
280
+ type: ScalarTypeEnum2.Int_unsecure(),
281
+ isOptional: true
282
+ },
283
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true }
284
+ }
285
+ }),
286
+ output: defineSchemaModel2({
287
+ name: "ExecuteAgentOutput",
288
+ fields: {
289
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
290
+ status: { type: RunStatusEnum, isOptional: false },
291
+ estimatedWaitMs: {
292
+ type: ScalarTypeEnum2.Int_unsecure(),
293
+ isOptional: true
294
+ }
295
+ }
296
+ }),
297
+ errors: {
298
+ AGENT_NOT_FOUND: {
299
+ description: "The specified agent does not exist",
300
+ http: 404,
301
+ gqlCode: "AGENT_NOT_FOUND",
302
+ when: "Agent ID is invalid"
303
+ },
304
+ AGENT_NOT_ACTIVE: {
305
+ description: "The specified agent is not active",
306
+ http: 400,
307
+ gqlCode: "AGENT_NOT_ACTIVE",
308
+ when: "Agent is in draft/paused/archived state"
309
+ }
310
+ }
311
+ },
312
+ policy: { auth: "user" },
313
+ sideEffects: {
314
+ emits: [
315
+ {
316
+ key: "run.started",
317
+ version: "1.0.0",
318
+ stability: "stable",
319
+ owners: [...OWNERS],
320
+ tags: ["run", "started"],
321
+ when: "Run is queued",
322
+ payload: RunSummaryModel
323
+ }
324
+ ],
325
+ audit: ["run.started"]
326
+ },
327
+ acceptance: {
328
+ scenarios: [
329
+ {
330
+ key: "execute-agent-happy-path",
331
+ given: ["Agent exists", "Agent is active"],
332
+ when: ["User submits execution request"],
333
+ then: ["Run is created", "RunStarted event is emitted"]
334
+ },
335
+ {
336
+ key: "execute-agent-not-active",
337
+ given: ["Agent exists but is not active"],
338
+ when: ["User attempts to execute"],
339
+ then: ["AGENT_NOT_ACTIVE error is returned"]
340
+ }
341
+ ],
342
+ examples: [
343
+ {
344
+ key: "basic-execute",
345
+ input: { agentId: "agent-123", input: { message: "Hello" } },
346
+ output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
347
+ }
348
+ ]
349
+ }
350
+ });
351
+ var CancelRunCommand = defineCommand({
352
+ meta: {
353
+ key: "agent.run.cancel",
354
+ version: "1.0.0",
355
+ stability: "stable",
356
+ owners: [...OWNERS],
357
+ tags: ["run", "cancel"],
358
+ description: "Cancels an in-progress agent run.",
359
+ goal: "Stop a running agent execution.",
360
+ context: "Called when user wants to abort a long-running task."
361
+ },
362
+ io: {
363
+ input: defineSchemaModel2({
364
+ name: "CancelRunInput",
365
+ fields: {
366
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
367
+ reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
368
+ }
369
+ }),
370
+ output: defineSchemaModel2({
371
+ name: "CancelRunOutput",
372
+ fields: {
373
+ success: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
374
+ status: { type: RunStatusEnum, isOptional: false }
375
+ }
376
+ }),
377
+ errors: {
378
+ RUN_NOT_FOUND: {
379
+ description: "The specified run does not exist",
380
+ http: 404,
381
+ gqlCode: "RUN_NOT_FOUND",
382
+ when: "Run ID is invalid"
383
+ },
384
+ RUN_NOT_CANCELLABLE: {
385
+ description: "The run cannot be cancelled",
386
+ http: 400,
387
+ gqlCode: "RUN_NOT_CANCELLABLE",
388
+ when: "Run is already completed/failed/cancelled"
389
+ }
390
+ }
391
+ },
392
+ policy: { auth: "user" },
393
+ sideEffects: {
394
+ emits: [
395
+ {
396
+ key: "run.cancelled",
397
+ version: "1.0.0",
398
+ stability: "stable",
399
+ owners: [...OWNERS],
400
+ tags: ["run", "cancelled"],
401
+ when: "Run is cancelled",
402
+ payload: RunSummaryModel
403
+ }
404
+ ],
405
+ audit: ["run.cancelled"]
406
+ },
407
+ acceptance: {
408
+ scenarios: [
409
+ {
410
+ key: "cancel-run-happy-path",
411
+ given: ["Run exists", "Run is in progress"],
412
+ when: ["User cancels run"],
413
+ then: ["Run is cancelled", "RunCancelled event is emitted"]
414
+ },
415
+ {
416
+ key: "cancel-run-already-completed",
417
+ given: ["Run exists but is already completed"],
418
+ when: ["User attempts to cancel"],
419
+ then: ["RUN_NOT_CANCELLABLE error is returned"]
420
+ }
421
+ ],
422
+ examples: [
423
+ {
424
+ key: "cancel-basic",
425
+ input: { runId: "run-456", reason: "User requested" },
426
+ output: { success: true, status: "cancelled" }
427
+ }
428
+ ]
429
+ }
430
+ });
431
+ var GetRunQuery = defineQuery({
432
+ meta: {
433
+ key: "agent.run.get",
434
+ version: "1.0.0",
435
+ stability: "stable",
436
+ owners: [...OWNERS],
437
+ tags: ["run", "get"],
438
+ description: "Retrieves a run by its ID with optional details.",
439
+ goal: "View detailed run information.",
440
+ context: "Run details page or monitoring."
441
+ },
442
+ io: {
443
+ input: defineSchemaModel2({
444
+ name: "GetRunInput",
445
+ fields: {
446
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
447
+ includeSteps: { type: ScalarTypeEnum2.Boolean(), isOptional: true },
448
+ includeLogs: { type: ScalarTypeEnum2.Boolean(), isOptional: true }
449
+ }
450
+ }),
451
+ output: RunModel,
452
+ errors: {
453
+ RUN_NOT_FOUND: {
454
+ description: "The specified run does not exist",
455
+ http: 404,
456
+ gqlCode: "RUN_NOT_FOUND",
457
+ when: "Run ID is invalid"
458
+ }
459
+ }
460
+ },
461
+ policy: { auth: "user" },
462
+ acceptance: {
463
+ scenarios: [
464
+ {
465
+ key: "get-run-happy-path",
466
+ given: ["Run exists"],
467
+ when: ["User requests run by ID"],
468
+ then: ["Run details are returned"]
469
+ }
470
+ ],
471
+ examples: [
472
+ {
473
+ key: "get-with-steps",
474
+ input: { runId: "run-456", includeSteps: true, includeLogs: false },
475
+ output: { id: "run-456", status: "completed", steps: [] }
476
+ }
477
+ ]
478
+ }
479
+ });
480
+ var ListRunsQuery = defineQuery({
481
+ meta: {
482
+ key: "agent.run.list",
483
+ version: "1.0.0",
484
+ stability: "stable",
485
+ owners: [...OWNERS],
486
+ tags: ["run", "list"],
487
+ description: "Lists runs with optional filtering.",
488
+ goal: "Browse and search run history.",
489
+ context: "Run history/dashboard view."
490
+ },
491
+ io: {
492
+ input: defineSchemaModel2({
493
+ name: "ListRunsInput",
494
+ fields: {
495
+ organizationId: {
496
+ type: ScalarTypeEnum2.String_unsecure(),
497
+ isOptional: true
498
+ },
499
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
500
+ userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
501
+ sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
502
+ status: { type: RunStatusEnum, isOptional: true },
503
+ startDate: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
504
+ endDate: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
505
+ limit: {
506
+ type: ScalarTypeEnum2.Int_unsecure(),
507
+ isOptional: true,
508
+ defaultValue: 20
509
+ },
510
+ offset: {
511
+ type: ScalarTypeEnum2.Int_unsecure(),
512
+ isOptional: true,
513
+ defaultValue: 0
514
+ }
515
+ }
516
+ }),
517
+ output: defineSchemaModel2({
518
+ name: "ListRunsOutput",
519
+ fields: {
520
+ items: { type: RunSummaryModel, isArray: true, isOptional: false },
521
+ total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
522
+ hasMore: { type: ScalarTypeEnum2.Boolean(), isOptional: false }
523
+ }
524
+ })
525
+ },
526
+ policy: { auth: "user" },
527
+ acceptance: {
528
+ scenarios: [
529
+ {
530
+ key: "list-runs-happy-path",
531
+ given: ["Organization has runs"],
532
+ when: ["User lists runs"],
533
+ then: ["Paginated list of runs is returned"]
534
+ }
535
+ ],
536
+ examples: [
537
+ {
538
+ key: "list-by-agent",
539
+ input: { agentId: "agent-123", limit: 20, offset: 0 },
540
+ output: { items: [], total: 0, hasMore: false }
541
+ }
542
+ ]
543
+ }
544
+ });
545
+ var GetRunStepsQuery = defineQuery({
546
+ meta: {
547
+ key: "agent.run.getSteps",
548
+ version: "1.0.0",
549
+ stability: "stable",
550
+ owners: [...OWNERS],
551
+ tags: ["run", "steps"],
552
+ description: "Retrieves all steps for a specific run.",
553
+ goal: "View step-by-step execution details.",
554
+ context: "Run details page - steps tab."
555
+ },
556
+ io: {
557
+ input: defineSchemaModel2({
558
+ name: "GetRunStepsInput",
559
+ fields: {
560
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
561
+ }
562
+ }),
563
+ output: defineSchemaModel2({
564
+ name: "GetRunStepsOutput",
565
+ fields: {
566
+ steps: { type: RunStepModel, isArray: true, isOptional: false }
567
+ }
568
+ })
569
+ },
570
+ policy: { auth: "user" },
571
+ acceptance: {
572
+ scenarios: [
573
+ {
574
+ key: "get-run-steps-happy-path",
575
+ given: ["Run exists with steps"],
576
+ when: ["User requests steps"],
577
+ then: ["Steps list is returned"]
578
+ }
579
+ ],
580
+ examples: [
581
+ {
582
+ key: "get-steps-basic",
583
+ input: { runId: "run-456" },
584
+ output: { steps: [] }
585
+ }
586
+ ]
587
+ }
588
+ });
589
+ var GetRunLogsQuery = defineQuery({
590
+ meta: {
591
+ key: "agent.run.getLogs",
592
+ version: "1.0.0",
593
+ stability: "stable",
594
+ owners: [...OWNERS],
595
+ tags: ["run", "logs"],
596
+ description: "Retrieves all logs for a specific run.",
597
+ goal: "Debug and audit run execution.",
598
+ context: "Run details page - logs tab."
599
+ },
600
+ io: {
601
+ input: defineSchemaModel2({
602
+ name: "GetRunLogsInput",
603
+ fields: {
604
+ runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
605
+ level: { type: LogLevelEnum, isOptional: true },
606
+ stepId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
607
+ limit: {
608
+ type: ScalarTypeEnum2.Int_unsecure(),
609
+ isOptional: true,
610
+ defaultValue: 100
611
+ },
612
+ offset: {
613
+ type: ScalarTypeEnum2.Int_unsecure(),
614
+ isOptional: true,
615
+ defaultValue: 0
616
+ }
617
+ }
618
+ }),
619
+ output: defineSchemaModel2({
620
+ name: "GetRunLogsOutput",
621
+ fields: {
622
+ items: { type: RunLogModel, isArray: true, isOptional: false },
623
+ total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
624
+ hasMore: { type: ScalarTypeEnum2.Boolean(), isOptional: false }
625
+ }
626
+ })
627
+ },
628
+ policy: { auth: "user" },
629
+ acceptance: {
630
+ scenarios: [
631
+ {
632
+ key: "get-run-logs-happy-path",
633
+ given: ["Run exists with logs"],
634
+ when: ["User requests logs"],
635
+ then: ["Paginated logs list is returned"]
636
+ }
637
+ ],
638
+ examples: [
639
+ {
640
+ key: "get-logs-filtered",
641
+ input: { runId: "run-456", level: "error", limit: 50 },
642
+ output: { items: [], total: 0, hasMore: false }
643
+ }
644
+ ]
645
+ }
646
+ });
647
+ var GetRunMetricsQuery = defineQuery({
648
+ meta: {
649
+ key: "agent.run.getMetrics",
650
+ version: "1.0.0",
651
+ stability: "stable",
652
+ owners: [...OWNERS],
653
+ tags: ["run", "metrics"],
654
+ description: "Retrieves aggregated metrics for runs within a time period.",
655
+ goal: "Monitor and analyze agent usage.",
656
+ context: "Analytics dashboard."
657
+ },
658
+ io: {
659
+ input: defineSchemaModel2({
660
+ name: "GetRunMetricsInput",
661
+ fields: {
662
+ organizationId: {
663
+ type: ScalarTypeEnum2.String_unsecure(),
664
+ isOptional: false
665
+ },
666
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
667
+ startDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
668
+ endDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
669
+ granularity: {
670
+ type: GranularityEnum,
671
+ isOptional: true,
672
+ defaultValue: "day"
673
+ }
674
+ }
675
+ }),
676
+ output: defineSchemaModel2({
677
+ name: "GetRunMetricsOutput",
678
+ fields: {
679
+ totalRuns: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
680
+ completedRuns: {
681
+ type: ScalarTypeEnum2.Int_unsecure(),
682
+ isOptional: false
683
+ },
684
+ failedRuns: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
685
+ totalTokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
686
+ totalCostUsd: {
687
+ type: ScalarTypeEnum2.Float_unsecure(),
688
+ isOptional: false
689
+ },
690
+ averageDurationMs: {
691
+ type: ScalarTypeEnum2.Float_unsecure(),
692
+ isOptional: false
693
+ },
694
+ successRate: {
695
+ type: ScalarTypeEnum2.Float_unsecure(),
696
+ isOptional: false
697
+ },
698
+ timeline: {
699
+ type: TimelineDataPointModel,
700
+ isArray: true,
701
+ isOptional: false
702
+ }
703
+ }
704
+ })
705
+ },
706
+ policy: { auth: "user" },
707
+ acceptance: {
708
+ scenarios: [
709
+ {
710
+ key: "get-run-metrics-happy-path",
711
+ given: ["Organization has run history"],
712
+ when: ["User requests metrics for date range"],
713
+ then: ["Aggregated metrics are returned"]
714
+ }
715
+ ],
716
+ examples: [
717
+ {
718
+ key: "get-daily-metrics",
719
+ input: {
720
+ organizationId: "org-123",
721
+ startDate: "2025-01-01",
722
+ endDate: "2025-01-31",
723
+ granularity: "day"
724
+ },
725
+ output: {
726
+ totalRuns: 100,
727
+ completedRuns: 90,
728
+ failedRuns: 10,
729
+ totalTokens: 50000,
730
+ totalCostUsd: 5,
731
+ averageDurationMs: 2500,
732
+ successRate: 0.9,
733
+ timeline: []
734
+ }
735
+ }
736
+ ]
737
+ }
738
+ });
739
+
81
740
  // src/shared/mock-runs.ts
82
741
  var MOCK_RUNS = [
83
742
  {
84
743
  id: "run-1",
85
744
  organizationId: "demo-org",
745
+ projectId: "demo-project",
86
746
  agentId: "agent-1",
87
747
  agentName: "Customer Support Bot",
88
748
  userId: "user-1",
@@ -105,6 +765,7 @@ var MOCK_RUNS = [
105
765
  {
106
766
  id: "run-2",
107
767
  organizationId: "demo-org",
768
+ projectId: "demo-project",
108
769
  agentId: "agent-2",
109
770
  agentName: "Code Review Assistant",
110
771
  userId: "user-2",
@@ -122,6 +783,7 @@ var MOCK_RUNS = [
122
783
  {
123
784
  id: "run-3",
124
785
  organizationId: "demo-org",
786
+ projectId: "demo-project",
125
787
  agentId: "agent-1",
126
788
  agentName: "Customer Support Bot",
127
789
  userId: "user-1",
@@ -143,6 +805,7 @@ var MOCK_RUNS = [
143
805
  {
144
806
  id: "run-4",
145
807
  organizationId: "demo-org",
808
+ projectId: "demo-project",
146
809
  agentId: "agent-3",
147
810
  agentName: "Data Analyst",
148
811
  userId: "user-3",
@@ -164,6 +827,7 @@ var MOCK_RUNS = [
164
827
  {
165
828
  id: "run-5",
166
829
  organizationId: "demo-org",
830
+ projectId: "demo-project",
167
831
  agentId: "agent-2",
168
832
  agentName: "Code Review Assistant",
169
833
  userId: "user-2",
@@ -185,6 +849,7 @@ var MOCK_RUNS = [
185
849
  ];
186
850
 
187
851
  // src/run/run.handler.ts
852
+ var nextMockRunId = MOCK_RUNS.length + 1;
188
853
  async function mockListRunsHandler(input) {
189
854
  const { agentId, status, limit = 20, offset = 0 } = input;
190
855
  let filtered = [...MOCK_RUNS];
@@ -233,7 +898,7 @@ async function mockExecuteAgentHandler(input) {
233
898
  if (agent.status !== "ACTIVE")
234
899
  throw new Error("AGENT_NOT_ACTIVE");
235
900
  return {
236
- runId: `run-${Date.now()}`,
901
+ runId: `run-${nextMockRunId++}`,
237
902
  status: "QUEUED",
238
903
  estimatedWaitMs: 500
239
904
  };
@@ -400,873 +1065,214 @@ var RunLogEntity = defineEntity({
400
1065
  enums: [LogLevelEntityEnum]
401
1066
  });
402
1067
 
403
- // src/run/run.enum.ts
404
- import { defineEnum } from "@contractspec/lib.schema";
405
- var RunStatusEnum = defineEnum("RunStatus", [
406
- "QUEUED",
407
- "IN_PROGRESS",
408
- "COMPLETED",
409
- "FAILED",
410
- "CANCELLED",
411
- "EXPIRED"
412
- ]);
413
- var RunStepTypeEnum = defineEnum("RunStepType", [
414
- "MESSAGE_CREATION",
415
- "TOOL_CALL",
416
- "TOOL_RESULT",
417
- "ERROR"
418
- ]);
419
- var LogLevelEnum = defineEnum("LogLevel", [
420
- "DEBUG",
421
- "INFO",
422
- "WARN",
423
- "ERROR"
424
- ]);
425
- var GranularityEnum = defineEnum("Granularity", [
426
- "hour",
427
- "day",
428
- "week",
429
- "month"
430
- ]);
431
-
432
1068
  // src/run/run.event.ts
433
1069
  import { defineEvent } from "@contractspec/lib.contracts-spec";
434
1070
  import {
435
1071
  defineEnum as defineEnum2,
436
- defineSchemaModel,
437
- ScalarTypeEnum
1072
+ defineSchemaModel as defineSchemaModel3,
1073
+ ScalarTypeEnum as ScalarTypeEnum3
438
1074
  } from "@contractspec/lib.schema";
439
- var OWNERS = ["@agent-console-team"];
440
- var RunStartedPayload = defineSchemaModel({
1075
+ var OWNERS2 = ["@agent-console-team"];
1076
+ var RunStartedPayload = defineSchemaModel3({
441
1077
  name: "RunStartedPayload",
442
- description: "Payload for run started event",
443
- fields: {
444
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
445
- organizationId: {
446
- type: ScalarTypeEnum.String_unsecure(),
447
- isOptional: false
448
- },
449
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
450
- agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
451
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
452
- sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
453
- input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
454
- startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
455
- }
456
- });
457
- var RunStartedEvent = defineEvent({
458
- meta: {
459
- key: "agent.run.started",
460
- version: "1.0.0",
461
- description: "An agent run was started.",
462
- stability: "stable",
463
- owners: [...OWNERS],
464
- tags: ["run", "started"]
465
- },
466
- payload: RunStartedPayload
467
- });
468
- var RunCompletedPayload = defineSchemaModel({
469
- name: "RunCompletedPayload",
470
- description: "Payload for run completed event",
471
- fields: {
472
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
473
- organizationId: {
474
- type: ScalarTypeEnum.String_unsecure(),
475
- isOptional: false
476
- },
477
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
478
- agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
479
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
480
- output: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
481
- totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
482
- promptTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
483
- completionTokens: {
484
- type: ScalarTypeEnum.Int_unsecure(),
485
- isOptional: false
486
- },
487
- totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
488
- durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
489
- estimatedCostUsd: {
490
- type: ScalarTypeEnum.Float_unsecure(),
491
- isOptional: true
492
- },
493
- completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
494
- }
495
- });
496
- var RunCompletedEvent = defineEvent({
497
- meta: {
498
- key: "agent.run.completed",
499
- version: "1.0.0",
500
- description: "An agent run completed successfully.",
501
- stability: "stable",
502
- owners: [...OWNERS],
503
- tags: ["run", "completed"]
504
- },
505
- payload: RunCompletedPayload
506
- });
507
- var RunFailedPayload = defineSchemaModel({
508
- name: "RunFailedPayload",
509
- description: "Payload for run failed event",
510
- fields: {
511
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
512
- organizationId: {
513
- type: ScalarTypeEnum.String_unsecure(),
514
- isOptional: false
515
- },
516
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
517
- agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
518
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
519
- errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
520
- errorCode: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
521
- totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
522
- totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
523
- durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
524
- failedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
525
- }
526
- });
527
- var RunFailedEvent = defineEvent({
528
- meta: {
529
- key: "agent.run.failed",
530
- version: "1.0.0",
531
- description: "An agent run encountered an error.",
532
- stability: "stable",
533
- owners: [...OWNERS],
534
- tags: ["run", "failed"]
535
- },
536
- payload: RunFailedPayload
537
- });
538
- var RunCancelledPayload = defineSchemaModel({
539
- name: "RunCancelledPayload",
540
- description: "Payload for run cancelled event",
541
- fields: {
542
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
543
- organizationId: {
544
- type: ScalarTypeEnum.String_unsecure(),
545
- isOptional: false
546
- },
547
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
548
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
549
- cancelledBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
550
- reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
551
- totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
552
- totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
553
- cancelledAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
554
- }
555
- });
556
- var RunCancelledEvent = defineEvent({
557
- meta: {
558
- key: "agent.run.cancelled",
559
- version: "1.0.0",
560
- description: "An agent run was cancelled by the user.",
561
- stability: "stable",
562
- owners: [...OWNERS],
563
- tags: ["run", "cancelled"]
564
- },
565
- payload: RunCancelledPayload
566
- });
567
- var ToolInvokedPayload = defineSchemaModel({
568
- name: "ToolInvokedPayload",
569
- description: "Payload for tool invoked event",
570
- fields: {
571
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
572
- stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
573
- toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
574
- toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
575
- input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
576
- invokedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
577
- }
578
- });
579
- var ToolInvokedEvent = defineEvent({
580
- meta: {
581
- key: "agent.run.toolInvoked",
582
- version: "1.0.0",
583
- description: "A tool was invoked during an agent run.",
584
- stability: "stable",
585
- owners: [...OWNERS],
586
- tags: ["run", "tool", "invoked"]
587
- },
588
- payload: ToolInvokedPayload
589
- });
590
- var ToolCompletedPayload = defineSchemaModel({
591
- name: "ToolCompletedPayload",
592
- description: "Payload for tool completed event",
593
- fields: {
594
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
595
- stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
596
- toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
597
- toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
598
- success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
599
- output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
600
- errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
601
- durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
602
- completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
603
- }
604
- });
605
- var ToolCompletedEvent = defineEvent({
606
- meta: {
607
- key: "agent.run.toolCompleted",
608
- version: "1.0.0",
609
- description: "A tool invocation completed during an agent run.",
610
- stability: "stable",
611
- owners: [...OWNERS],
612
- tags: ["run", "tool", "completed"]
613
- },
614
- payload: ToolCompletedPayload
615
- });
616
- var MessageTypeEnum = defineEnum2("MessageType", ["assistant", "system"]);
617
- var MessageGeneratedPayload = defineSchemaModel({
618
- name: "MessageGeneratedPayload",
619
- description: "Payload for message generated event",
620
- fields: {
621
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
622
- stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
623
- messageType: { type: MessageTypeEnum, isOptional: false },
624
- content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
625
- tokensUsed: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
626
- generatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
627
- }
628
- });
629
- var MessageGeneratedEvent = defineEvent({
630
- meta: {
631
- key: "agent.run.messageGenerated",
632
- version: "1.0.0",
633
- description: "An agent generated a message during a run.",
634
- stability: "stable",
635
- owners: [...OWNERS],
636
- tags: ["run", "message", "generated"]
637
- },
638
- payload: MessageGeneratedPayload
639
- });
640
-
641
- // src/run/run.schema.ts
642
- import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
643
- var RunInputModel = defineSchemaModel2({
644
- name: "RunInput",
645
- description: "Input data for agent execution",
646
- fields: {
647
- message: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
648
- context: { type: ScalarTypeEnum2.JSONObject(), isOptional: true }
649
- }
650
- });
651
- var RunStepModel = defineSchemaModel2({
652
- name: "RunStep",
653
- description: "Individual step within a run",
654
- fields: {
655
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
656
- stepNumber: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
657
- type: { type: RunStepTypeEnum, isOptional: false },
658
- toolId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
659
- toolName: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
660
- input: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
661
- output: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
662
- status: { type: RunStatusEnum, isOptional: false },
663
- errorMessage: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
664
- tokensUsed: {
665
- type: ScalarTypeEnum2.Int_unsecure(),
666
- isOptional: false,
667
- defaultValue: 0
668
- },
669
- durationMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
670
- startedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
671
- completedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true }
672
- }
673
- });
674
- var RunLogModel = defineSchemaModel2({
675
- name: "RunLog",
676
- description: "Execution log entry",
677
- fields: {
678
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
679
- stepId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
680
- level: { type: LogLevelEnum, isOptional: false },
681
- message: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
682
- data: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
683
- source: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
684
- traceId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
685
- spanId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
686
- timestamp: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
687
- }
688
- });
689
- var RunAgentRefModel = defineSchemaModel2({
690
- name: "RunAgentRef",
691
- description: "Agent reference in a run",
1078
+ description: "Payload for run started event",
692
1079
  fields: {
693
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
694
- name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
695
- modelProvider: {
696
- type: ScalarTypeEnum2.String_unsecure(),
1080
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1081
+ organizationId: {
1082
+ type: ScalarTypeEnum3.String_unsecure(),
697
1083
  isOptional: false
698
1084
  },
699
- modelName: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
1085
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1086
+ agentName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1087
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1088
+ sessionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1089
+ input: { type: ScalarTypeEnum3.JSONObject(), isOptional: false },
1090
+ startedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
700
1091
  }
701
1092
  });
702
- var RunModel = defineSchemaModel2({
703
- name: "Run",
704
- description: "Agent execution instance",
1093
+ var RunStartedEvent = defineEvent({
1094
+ meta: {
1095
+ key: "agent.run.started",
1096
+ version: "1.0.0",
1097
+ description: "An agent run was started.",
1098
+ stability: "stable",
1099
+ owners: [...OWNERS2],
1100
+ tags: ["run", "started"]
1101
+ },
1102
+ payload: RunStartedPayload
1103
+ });
1104
+ var RunCompletedPayload = defineSchemaModel3({
1105
+ name: "RunCompletedPayload",
1106
+ description: "Payload for run completed event",
705
1107
  fields: {
706
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
1108
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
707
1109
  organizationId: {
708
- type: ScalarTypeEnum2.String_unsecure(),
1110
+ type: ScalarTypeEnum3.String_unsecure(),
709
1111
  isOptional: false
710
1112
  },
711
- agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
712
- userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
713
- sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
714
- input: { type: ScalarTypeEnum2.JSONObject(), isOptional: false },
715
- output: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
716
- status: { type: RunStatusEnum, isOptional: false },
717
- errorMessage: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
718
- errorCode: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
719
- totalTokens: {
720
- type: ScalarTypeEnum2.Int_unsecure(),
721
- isOptional: false,
722
- defaultValue: 0
723
- },
724
- promptTokens: {
725
- type: ScalarTypeEnum2.Int_unsecure(),
726
- isOptional: false,
727
- defaultValue: 0
728
- },
1113
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1114
+ agentName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1115
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1116
+ output: { type: ScalarTypeEnum3.JSONObject(), isOptional: false },
1117
+ totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1118
+ promptTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
729
1119
  completionTokens: {
730
- type: ScalarTypeEnum2.Int_unsecure(),
731
- isOptional: false,
732
- defaultValue: 0
733
- },
734
- totalIterations: {
735
- type: ScalarTypeEnum2.Int_unsecure(),
736
- isOptional: false,
737
- defaultValue: 0
738
- },
739
- durationMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
740
- estimatedCostUsd: {
741
- type: ScalarTypeEnum2.Float_unsecure(),
742
- isOptional: true
1120
+ type: ScalarTypeEnum3.Int_unsecure(),
1121
+ isOptional: false
743
1122
  },
744
- queuedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
745
- startedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
746
- completedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
747
- metadata: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
748
- steps: { type: RunStepModel, isArray: true, isOptional: true },
749
- logs: { type: RunLogModel, isArray: true, isOptional: true },
750
- agent: { type: RunAgentRefModel, isOptional: true }
751
- }
752
- });
753
- var RunSummaryModel = defineSchemaModel2({
754
- name: "RunSummary",
755
- description: "Summary of a run for list views",
756
- fields: {
757
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
758
- agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
759
- agentName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
760
- status: { type: RunStatusEnum, isOptional: false },
761
- totalTokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
762
- durationMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
1123
+ totalIterations: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1124
+ durationMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
763
1125
  estimatedCostUsd: {
764
- type: ScalarTypeEnum2.Float_unsecure(),
1126
+ type: ScalarTypeEnum3.Float_unsecure(),
765
1127
  isOptional: true
766
1128
  },
767
- queuedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
768
- completedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true }
769
- }
770
- });
771
- var TimelineDataPointModel = defineSchemaModel2({
772
- name: "TimelineDataPoint",
773
- description: "Timeline data point for metrics",
774
- fields: {
775
- period: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
776
- runs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
777
- tokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
778
- costUsd: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false },
779
- avgDurationMs: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false }
780
- }
781
- });
782
-
783
- // src/run/run.operation.ts
784
- import {
785
- defineCommand,
786
- defineQuery
787
- } from "@contractspec/lib.contracts-spec/operations";
788
- import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
789
- var OWNERS2 = ["@agent-console-team"];
790
- var ExecuteAgentCommand = defineCommand({
791
- meta: {
792
- key: "agent.run.execute",
793
- version: "1.0.0",
794
- stability: "stable",
795
- owners: [...OWNERS2],
796
- tags: ["run", "execute"],
797
- description: "Starts a new agent run with the given input.",
798
- goal: "Execute an AI agent with user input.",
799
- context: "Called from chat interface or API."
800
- },
801
- io: {
802
- input: defineSchemaModel3({
803
- name: "ExecuteAgentInput",
804
- fields: {
805
- agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
806
- input: { type: RunInputModel, isOptional: false },
807
- sessionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
808
- metadata: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
809
- stream: { type: ScalarTypeEnum3.Boolean(), isOptional: true },
810
- maxIterations: {
811
- type: ScalarTypeEnum3.Int_unsecure(),
812
- isOptional: true
813
- },
814
- timeoutMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true }
815
- }
816
- }),
817
- output: defineSchemaModel3({
818
- name: "ExecuteAgentOutput",
819
- fields: {
820
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
821
- status: { type: RunStatusEnum, isOptional: false },
822
- estimatedWaitMs: {
823
- type: ScalarTypeEnum3.Int_unsecure(),
824
- isOptional: true
825
- }
826
- }
827
- }),
828
- errors: {
829
- AGENT_NOT_FOUND: {
830
- description: "The specified agent does not exist",
831
- http: 404,
832
- gqlCode: "AGENT_NOT_FOUND",
833
- when: "Agent ID is invalid"
834
- },
835
- AGENT_NOT_ACTIVE: {
836
- description: "The specified agent is not active",
837
- http: 400,
838
- gqlCode: "AGENT_NOT_ACTIVE",
839
- when: "Agent is in draft/paused/archived state"
840
- }
841
- }
842
- },
843
- policy: { auth: "user" },
844
- sideEffects: {
845
- emits: [
846
- {
847
- key: "run.started",
848
- version: "1.0.0",
849
- stability: "stable",
850
- owners: [...OWNERS2],
851
- tags: ["run", "started"],
852
- when: "Run is queued",
853
- payload: RunSummaryModel
854
- }
855
- ],
856
- audit: ["run.started"]
857
- },
858
- acceptance: {
859
- scenarios: [
860
- {
861
- key: "execute-agent-happy-path",
862
- given: ["Agent exists", "Agent is active"],
863
- when: ["User submits execution request"],
864
- then: ["Run is created", "RunStarted event is emitted"]
865
- },
866
- {
867
- key: "execute-agent-not-active",
868
- given: ["Agent exists but is not active"],
869
- when: ["User attempts to execute"],
870
- then: ["AGENT_NOT_ACTIVE error is returned"]
871
- }
872
- ],
873
- examples: [
874
- {
875
- key: "basic-execute",
876
- input: { agentId: "agent-123", input: { message: "Hello" } },
877
- output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
878
- }
879
- ]
880
- }
881
- });
882
- var CancelRunCommand = defineCommand({
883
- meta: {
884
- key: "agent.run.cancel",
885
- version: "1.0.0",
886
- stability: "stable",
887
- owners: [...OWNERS2],
888
- tags: ["run", "cancel"],
889
- description: "Cancels an in-progress agent run.",
890
- goal: "Stop a running agent execution.",
891
- context: "Called when user wants to abort a long-running task."
892
- },
893
- io: {
894
- input: defineSchemaModel3({
895
- name: "CancelRunInput",
896
- fields: {
897
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
898
- reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
899
- }
900
- }),
901
- output: defineSchemaModel3({
902
- name: "CancelRunOutput",
903
- fields: {
904
- success: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
905
- status: { type: RunStatusEnum, isOptional: false }
906
- }
907
- }),
908
- errors: {
909
- RUN_NOT_FOUND: {
910
- description: "The specified run does not exist",
911
- http: 404,
912
- gqlCode: "RUN_NOT_FOUND",
913
- when: "Run ID is invalid"
914
- },
915
- RUN_NOT_CANCELLABLE: {
916
- description: "The run cannot be cancelled",
917
- http: 400,
918
- gqlCode: "RUN_NOT_CANCELLABLE",
919
- when: "Run is already completed/failed/cancelled"
920
- }
921
- }
922
- },
923
- policy: { auth: "user" },
924
- sideEffects: {
925
- emits: [
926
- {
927
- key: "run.cancelled",
928
- version: "1.0.0",
929
- stability: "stable",
930
- owners: [...OWNERS2],
931
- tags: ["run", "cancelled"],
932
- when: "Run is cancelled",
933
- payload: RunSummaryModel
934
- }
935
- ],
936
- audit: ["run.cancelled"]
937
- },
938
- acceptance: {
939
- scenarios: [
940
- {
941
- key: "cancel-run-happy-path",
942
- given: ["Run exists", "Run is in progress"],
943
- when: ["User cancels run"],
944
- then: ["Run is cancelled", "RunCancelled event is emitted"]
945
- },
946
- {
947
- key: "cancel-run-already-completed",
948
- given: ["Run exists but is already completed"],
949
- when: ["User attempts to cancel"],
950
- then: ["RUN_NOT_CANCELLABLE error is returned"]
951
- }
952
- ],
953
- examples: [
954
- {
955
- key: "cancel-basic",
956
- input: { runId: "run-456", reason: "User requested" },
957
- output: { success: true, status: "cancelled" }
958
- }
959
- ]
1129
+ completedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
960
1130
  }
961
1131
  });
962
- var GetRunQuery = defineQuery({
1132
+ var RunCompletedEvent = defineEvent({
963
1133
  meta: {
964
- key: "agent.run.get",
1134
+ key: "agent.run.completed",
965
1135
  version: "1.0.0",
1136
+ description: "An agent run completed successfully.",
966
1137
  stability: "stable",
967
1138
  owners: [...OWNERS2],
968
- tags: ["run", "get"],
969
- description: "Retrieves a run by its ID with optional details.",
970
- goal: "View detailed run information.",
971
- context: "Run details page or monitoring."
972
- },
973
- io: {
974
- input: defineSchemaModel3({
975
- name: "GetRunInput",
976
- fields: {
977
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
978
- includeSteps: { type: ScalarTypeEnum3.Boolean(), isOptional: true },
979
- includeLogs: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
980
- }
981
- }),
982
- output: RunModel,
983
- errors: {
984
- RUN_NOT_FOUND: {
985
- description: "The specified run does not exist",
986
- http: 404,
987
- gqlCode: "RUN_NOT_FOUND",
988
- when: "Run ID is invalid"
989
- }
990
- }
991
- },
992
- policy: { auth: "user" },
993
- acceptance: {
994
- scenarios: [
995
- {
996
- key: "get-run-happy-path",
997
- given: ["Run exists"],
998
- when: ["User requests run by ID"],
999
- then: ["Run details are returned"]
1000
- }
1001
- ],
1002
- examples: [
1003
- {
1004
- key: "get-with-steps",
1005
- input: { runId: "run-456", includeSteps: true, includeLogs: false },
1006
- output: { id: "run-456", status: "completed", steps: [] }
1007
- }
1008
- ]
1139
+ tags: ["run", "completed"]
1140
+ },
1141
+ payload: RunCompletedPayload
1142
+ });
1143
+ var RunFailedPayload = defineSchemaModel3({
1144
+ name: "RunFailedPayload",
1145
+ description: "Payload for run failed event",
1146
+ fields: {
1147
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1148
+ organizationId: {
1149
+ type: ScalarTypeEnum3.String_unsecure(),
1150
+ isOptional: false
1151
+ },
1152
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1153
+ agentName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1154
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1155
+ errorMessage: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1156
+ errorCode: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1157
+ totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1158
+ totalIterations: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1159
+ durationMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true },
1160
+ failedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1009
1161
  }
1010
1162
  });
1011
- var ListRunsQuery = defineQuery({
1163
+ var RunFailedEvent = defineEvent({
1012
1164
  meta: {
1013
- key: "agent.run.list",
1165
+ key: "agent.run.failed",
1014
1166
  version: "1.0.0",
1167
+ description: "An agent run encountered an error.",
1015
1168
  stability: "stable",
1016
1169
  owners: [...OWNERS2],
1017
- tags: ["run", "list"],
1018
- description: "Lists runs with optional filtering.",
1019
- goal: "Browse and search run history.",
1020
- context: "Run history/dashboard view."
1021
- },
1022
- io: {
1023
- input: defineSchemaModel3({
1024
- name: "ListRunsInput",
1025
- fields: {
1026
- organizationId: {
1027
- type: ScalarTypeEnum3.String_unsecure(),
1028
- isOptional: true
1029
- },
1030
- agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1031
- userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1032
- sessionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1033
- status: { type: RunStatusEnum, isOptional: true },
1034
- startDate: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
1035
- endDate: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
1036
- limit: {
1037
- type: ScalarTypeEnum3.Int_unsecure(),
1038
- isOptional: true,
1039
- defaultValue: 20
1040
- },
1041
- offset: {
1042
- type: ScalarTypeEnum3.Int_unsecure(),
1043
- isOptional: true,
1044
- defaultValue: 0
1045
- }
1046
- }
1047
- }),
1048
- output: defineSchemaModel3({
1049
- name: "ListRunsOutput",
1050
- fields: {
1051
- items: { type: RunSummaryModel, isArray: true, isOptional: false },
1052
- total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1053
- hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
1054
- }
1055
- })
1170
+ tags: ["run", "failed"]
1056
1171
  },
1057
- policy: { auth: "user" },
1058
- acceptance: {
1059
- scenarios: [
1060
- {
1061
- key: "list-runs-happy-path",
1062
- given: ["Organization has runs"],
1063
- when: ["User lists runs"],
1064
- then: ["Paginated list of runs is returned"]
1065
- }
1066
- ],
1067
- examples: [
1068
- {
1069
- key: "list-by-agent",
1070
- input: { agentId: "agent-123", limit: 20, offset: 0 },
1071
- output: { items: [], total: 0, hasMore: false }
1072
- }
1073
- ]
1172
+ payload: RunFailedPayload
1173
+ });
1174
+ var RunCancelledPayload = defineSchemaModel3({
1175
+ name: "RunCancelledPayload",
1176
+ description: "Payload for run cancelled event",
1177
+ fields: {
1178
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1179
+ organizationId: {
1180
+ type: ScalarTypeEnum3.String_unsecure(),
1181
+ isOptional: false
1182
+ },
1183
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1184
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1185
+ cancelledBy: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1186
+ reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1187
+ totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1188
+ totalIterations: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1189
+ cancelledAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1074
1190
  }
1075
1191
  });
1076
- var GetRunStepsQuery = defineQuery({
1192
+ var RunCancelledEvent = defineEvent({
1077
1193
  meta: {
1078
- key: "agent.run.getSteps",
1194
+ key: "agent.run.cancelled",
1079
1195
  version: "1.0.0",
1196
+ description: "An agent run was cancelled by the user.",
1080
1197
  stability: "stable",
1081
1198
  owners: [...OWNERS2],
1082
- tags: ["run", "steps"],
1083
- description: "Retrieves all steps for a specific run.",
1084
- goal: "View step-by-step execution details.",
1085
- context: "Run details page - steps tab."
1086
- },
1087
- io: {
1088
- input: defineSchemaModel3({
1089
- name: "GetRunStepsInput",
1090
- fields: {
1091
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
1092
- }
1093
- }),
1094
- output: defineSchemaModel3({
1095
- name: "GetRunStepsOutput",
1096
- fields: {
1097
- steps: { type: RunStepModel, isArray: true, isOptional: false }
1098
- }
1099
- })
1199
+ tags: ["run", "cancelled"]
1100
1200
  },
1101
- policy: { auth: "user" },
1102
- acceptance: {
1103
- scenarios: [
1104
- {
1105
- key: "get-run-steps-happy-path",
1106
- given: ["Run exists with steps"],
1107
- when: ["User requests steps"],
1108
- then: ["Steps list is returned"]
1109
- }
1110
- ],
1111
- examples: [
1112
- {
1113
- key: "get-steps-basic",
1114
- input: { runId: "run-456" },
1115
- output: { steps: [] }
1116
- }
1117
- ]
1201
+ payload: RunCancelledPayload
1202
+ });
1203
+ var ToolInvokedPayload = defineSchemaModel3({
1204
+ name: "ToolInvokedPayload",
1205
+ description: "Payload for tool invoked event",
1206
+ fields: {
1207
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1208
+ stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1209
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1210
+ toolName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1211
+ input: { type: ScalarTypeEnum3.JSONObject(), isOptional: false },
1212
+ invokedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1118
1213
  }
1119
1214
  });
1120
- var GetRunLogsQuery = defineQuery({
1215
+ var ToolInvokedEvent = defineEvent({
1121
1216
  meta: {
1122
- key: "agent.run.getLogs",
1217
+ key: "agent.run.toolInvoked",
1123
1218
  version: "1.0.0",
1219
+ description: "A tool was invoked during an agent run.",
1124
1220
  stability: "stable",
1125
1221
  owners: [...OWNERS2],
1126
- tags: ["run", "logs"],
1127
- description: "Retrieves all logs for a specific run.",
1128
- goal: "Debug and audit run execution.",
1129
- context: "Run details page - logs tab."
1130
- },
1131
- io: {
1132
- input: defineSchemaModel3({
1133
- name: "GetRunLogsInput",
1134
- fields: {
1135
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1136
- level: { type: LogLevelEnum, isOptional: true },
1137
- stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1138
- limit: {
1139
- type: ScalarTypeEnum3.Int_unsecure(),
1140
- isOptional: true,
1141
- defaultValue: 100
1142
- },
1143
- offset: {
1144
- type: ScalarTypeEnum3.Int_unsecure(),
1145
- isOptional: true,
1146
- defaultValue: 0
1147
- }
1148
- }
1149
- }),
1150
- output: defineSchemaModel3({
1151
- name: "GetRunLogsOutput",
1152
- fields: {
1153
- items: { type: RunLogModel, isArray: true, isOptional: false },
1154
- total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1155
- hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
1156
- }
1157
- })
1222
+ tags: ["run", "tool", "invoked"]
1158
1223
  },
1159
- policy: { auth: "user" },
1160
- acceptance: {
1161
- scenarios: [
1162
- {
1163
- key: "get-run-logs-happy-path",
1164
- given: ["Run exists with logs"],
1165
- when: ["User requests logs"],
1166
- then: ["Paginated logs list is returned"]
1167
- }
1168
- ],
1169
- examples: [
1170
- {
1171
- key: "get-logs-filtered",
1172
- input: { runId: "run-456", level: "error", limit: 50 },
1173
- output: { items: [], total: 0, hasMore: false }
1174
- }
1175
- ]
1224
+ payload: ToolInvokedPayload
1225
+ });
1226
+ var ToolCompletedPayload = defineSchemaModel3({
1227
+ name: "ToolCompletedPayload",
1228
+ description: "Payload for tool completed event",
1229
+ fields: {
1230
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1231
+ stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1232
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1233
+ toolName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1234
+ success: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
1235
+ output: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
1236
+ errorMessage: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1237
+ durationMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1238
+ completedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1176
1239
  }
1177
1240
  });
1178
- var GetRunMetricsQuery = defineQuery({
1241
+ var ToolCompletedEvent = defineEvent({
1179
1242
  meta: {
1180
- key: "agent.run.getMetrics",
1243
+ key: "agent.run.toolCompleted",
1181
1244
  version: "1.0.0",
1245
+ description: "A tool invocation completed during an agent run.",
1182
1246
  stability: "stable",
1183
1247
  owners: [...OWNERS2],
1184
- tags: ["run", "metrics"],
1185
- description: "Retrieves aggregated metrics for runs within a time period.",
1186
- goal: "Monitor and analyze agent usage.",
1187
- context: "Analytics dashboard."
1188
- },
1189
- io: {
1190
- input: defineSchemaModel3({
1191
- name: "GetRunMetricsInput",
1192
- fields: {
1193
- organizationId: {
1194
- type: ScalarTypeEnum3.String_unsecure(),
1195
- isOptional: false
1196
- },
1197
- agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1198
- startDate: { type: ScalarTypeEnum3.DateTime(), isOptional: false },
1199
- endDate: { type: ScalarTypeEnum3.DateTime(), isOptional: false },
1200
- granularity: {
1201
- type: GranularityEnum,
1202
- isOptional: true,
1203
- defaultValue: "day"
1204
- }
1205
- }
1206
- }),
1207
- output: defineSchemaModel3({
1208
- name: "GetRunMetricsOutput",
1209
- fields: {
1210
- totalRuns: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1211
- completedRuns: {
1212
- type: ScalarTypeEnum3.Int_unsecure(),
1213
- isOptional: false
1214
- },
1215
- failedRuns: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1216
- totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1217
- totalCostUsd: {
1218
- type: ScalarTypeEnum3.Float_unsecure(),
1219
- isOptional: false
1220
- },
1221
- averageDurationMs: {
1222
- type: ScalarTypeEnum3.Float_unsecure(),
1223
- isOptional: false
1224
- },
1225
- successRate: {
1226
- type: ScalarTypeEnum3.Float_unsecure(),
1227
- isOptional: false
1228
- },
1229
- timeline: {
1230
- type: TimelineDataPointModel,
1231
- isArray: true,
1232
- isOptional: false
1233
- }
1234
- }
1235
- })
1248
+ tags: ["run", "tool", "completed"]
1236
1249
  },
1237
- policy: { auth: "user" },
1238
- acceptance: {
1239
- scenarios: [
1240
- {
1241
- key: "get-run-metrics-happy-path",
1242
- given: ["Organization has run history"],
1243
- when: ["User requests metrics for date range"],
1244
- then: ["Aggregated metrics are returned"]
1245
- }
1246
- ],
1247
- examples: [
1248
- {
1249
- key: "get-daily-metrics",
1250
- input: {
1251
- organizationId: "org-123",
1252
- startDate: "2025-01-01",
1253
- endDate: "2025-01-31",
1254
- granularity: "day"
1255
- },
1256
- output: {
1257
- totalRuns: 100,
1258
- completedRuns: 90,
1259
- failedRuns: 10,
1260
- totalTokens: 50000,
1261
- totalCostUsd: 5,
1262
- averageDurationMs: 2500,
1263
- successRate: 0.9,
1264
- timeline: []
1265
- }
1266
- }
1267
- ]
1250
+ payload: ToolCompletedPayload
1251
+ });
1252
+ var MessageTypeEnum = defineEnum2("MessageType", ["assistant", "system"]);
1253
+ var MessageGeneratedPayload = defineSchemaModel3({
1254
+ name: "MessageGeneratedPayload",
1255
+ description: "Payload for message generated event",
1256
+ fields: {
1257
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1258
+ stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1259
+ messageType: { type: MessageTypeEnum, isOptional: false },
1260
+ content: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1261
+ tokensUsed: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1262
+ generatedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1268
1263
  }
1269
1264
  });
1265
+ var MessageGeneratedEvent = defineEvent({
1266
+ meta: {
1267
+ key: "agent.run.messageGenerated",
1268
+ version: "1.0.0",
1269
+ description: "An agent generated a message during a run.",
1270
+ stability: "stable",
1271
+ owners: [...OWNERS2],
1272
+ tags: ["run", "message", "generated"]
1273
+ },
1274
+ payload: MessageGeneratedPayload
1275
+ });
1270
1276
 
1271
1277
  // src/run/run.presentation.ts
1272
1278
  import {