@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
package/dist/run/index.js CHANGED
@@ -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
  };
@@ -401,873 +1066,214 @@ var RunLogEntity = defineEntity({
401
1066
  enums: [LogLevelEntityEnum]
402
1067
  });
403
1068
 
404
- // src/run/run.enum.ts
405
- import { defineEnum } from "@contractspec/lib.schema";
406
- var RunStatusEnum = defineEnum("RunStatus", [
407
- "QUEUED",
408
- "IN_PROGRESS",
409
- "COMPLETED",
410
- "FAILED",
411
- "CANCELLED",
412
- "EXPIRED"
413
- ]);
414
- var RunStepTypeEnum = defineEnum("RunStepType", [
415
- "MESSAGE_CREATION",
416
- "TOOL_CALL",
417
- "TOOL_RESULT",
418
- "ERROR"
419
- ]);
420
- var LogLevelEnum = defineEnum("LogLevel", [
421
- "DEBUG",
422
- "INFO",
423
- "WARN",
424
- "ERROR"
425
- ]);
426
- var GranularityEnum = defineEnum("Granularity", [
427
- "hour",
428
- "day",
429
- "week",
430
- "month"
431
- ]);
432
-
433
1069
  // src/run/run.event.ts
434
1070
  import { defineEvent } from "@contractspec/lib.contracts-spec";
435
1071
  import {
436
1072
  defineEnum as defineEnum2,
437
- defineSchemaModel,
438
- ScalarTypeEnum
1073
+ defineSchemaModel as defineSchemaModel3,
1074
+ ScalarTypeEnum as ScalarTypeEnum3
439
1075
  } from "@contractspec/lib.schema";
440
- var OWNERS = ["@agent-console-team"];
441
- var RunStartedPayload = defineSchemaModel({
1076
+ var OWNERS2 = ["@agent-console-team"];
1077
+ var RunStartedPayload = defineSchemaModel3({
442
1078
  name: "RunStartedPayload",
443
- description: "Payload for run started event",
444
- fields: {
445
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
446
- organizationId: {
447
- type: ScalarTypeEnum.String_unsecure(),
448
- isOptional: false
449
- },
450
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
451
- agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
452
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
453
- sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
454
- input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
455
- startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
456
- }
457
- });
458
- var RunStartedEvent = defineEvent({
459
- meta: {
460
- key: "agent.run.started",
461
- version: "1.0.0",
462
- description: "An agent run was started.",
463
- stability: "stable",
464
- owners: [...OWNERS],
465
- tags: ["run", "started"]
466
- },
467
- payload: RunStartedPayload
468
- });
469
- var RunCompletedPayload = defineSchemaModel({
470
- name: "RunCompletedPayload",
471
- description: "Payload for run completed event",
472
- fields: {
473
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
474
- organizationId: {
475
- type: ScalarTypeEnum.String_unsecure(),
476
- isOptional: false
477
- },
478
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
479
- agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
480
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
481
- output: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
482
- totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
483
- promptTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
484
- completionTokens: {
485
- type: ScalarTypeEnum.Int_unsecure(),
486
- isOptional: false
487
- },
488
- totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
489
- durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
490
- estimatedCostUsd: {
491
- type: ScalarTypeEnum.Float_unsecure(),
492
- isOptional: true
493
- },
494
- completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
495
- }
496
- });
497
- var RunCompletedEvent = defineEvent({
498
- meta: {
499
- key: "agent.run.completed",
500
- version: "1.0.0",
501
- description: "An agent run completed successfully.",
502
- stability: "stable",
503
- owners: [...OWNERS],
504
- tags: ["run", "completed"]
505
- },
506
- payload: RunCompletedPayload
507
- });
508
- var RunFailedPayload = defineSchemaModel({
509
- name: "RunFailedPayload",
510
- description: "Payload for run failed event",
511
- fields: {
512
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
513
- organizationId: {
514
- type: ScalarTypeEnum.String_unsecure(),
515
- isOptional: false
516
- },
517
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
518
- agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
519
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
520
- errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
521
- errorCode: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
522
- totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
523
- totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
524
- durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
525
- failedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
526
- }
527
- });
528
- var RunFailedEvent = defineEvent({
529
- meta: {
530
- key: "agent.run.failed",
531
- version: "1.0.0",
532
- description: "An agent run encountered an error.",
533
- stability: "stable",
534
- owners: [...OWNERS],
535
- tags: ["run", "failed"]
536
- },
537
- payload: RunFailedPayload
538
- });
539
- var RunCancelledPayload = defineSchemaModel({
540
- name: "RunCancelledPayload",
541
- description: "Payload for run cancelled event",
542
- fields: {
543
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
544
- organizationId: {
545
- type: ScalarTypeEnum.String_unsecure(),
546
- isOptional: false
547
- },
548
- agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
549
- userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
550
- cancelledBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
551
- reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
552
- totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
553
- totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
554
- cancelledAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
555
- }
556
- });
557
- var RunCancelledEvent = defineEvent({
558
- meta: {
559
- key: "agent.run.cancelled",
560
- version: "1.0.0",
561
- description: "An agent run was cancelled by the user.",
562
- stability: "stable",
563
- owners: [...OWNERS],
564
- tags: ["run", "cancelled"]
565
- },
566
- payload: RunCancelledPayload
567
- });
568
- var ToolInvokedPayload = defineSchemaModel({
569
- name: "ToolInvokedPayload",
570
- description: "Payload for tool invoked event",
571
- fields: {
572
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
573
- stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
574
- toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
575
- toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
576
- input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
577
- invokedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
578
- }
579
- });
580
- var ToolInvokedEvent = defineEvent({
581
- meta: {
582
- key: "agent.run.toolInvoked",
583
- version: "1.0.0",
584
- description: "A tool was invoked during an agent run.",
585
- stability: "stable",
586
- owners: [...OWNERS],
587
- tags: ["run", "tool", "invoked"]
588
- },
589
- payload: ToolInvokedPayload
590
- });
591
- var ToolCompletedPayload = defineSchemaModel({
592
- name: "ToolCompletedPayload",
593
- description: "Payload for tool completed event",
594
- fields: {
595
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
596
- stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
597
- toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
598
- toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
599
- success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
600
- output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
601
- errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
602
- durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
603
- completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
604
- }
605
- });
606
- var ToolCompletedEvent = defineEvent({
607
- meta: {
608
- key: "agent.run.toolCompleted",
609
- version: "1.0.0",
610
- description: "A tool invocation completed during an agent run.",
611
- stability: "stable",
612
- owners: [...OWNERS],
613
- tags: ["run", "tool", "completed"]
614
- },
615
- payload: ToolCompletedPayload
616
- });
617
- var MessageTypeEnum = defineEnum2("MessageType", ["assistant", "system"]);
618
- var MessageGeneratedPayload = defineSchemaModel({
619
- name: "MessageGeneratedPayload",
620
- description: "Payload for message generated event",
621
- fields: {
622
- runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
623
- stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
624
- messageType: { type: MessageTypeEnum, isOptional: false },
625
- content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
626
- tokensUsed: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
627
- generatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
628
- }
629
- });
630
- var MessageGeneratedEvent = defineEvent({
631
- meta: {
632
- key: "agent.run.messageGenerated",
633
- version: "1.0.0",
634
- description: "An agent generated a message during a run.",
635
- stability: "stable",
636
- owners: [...OWNERS],
637
- tags: ["run", "message", "generated"]
638
- },
639
- payload: MessageGeneratedPayload
640
- });
641
-
642
- // src/run/run.schema.ts
643
- import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
644
- var RunInputModel = defineSchemaModel2({
645
- name: "RunInput",
646
- description: "Input data for agent execution",
647
- fields: {
648
- message: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
649
- context: { type: ScalarTypeEnum2.JSONObject(), isOptional: true }
650
- }
651
- });
652
- var RunStepModel = defineSchemaModel2({
653
- name: "RunStep",
654
- description: "Individual step within a run",
655
- fields: {
656
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
657
- stepNumber: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
658
- type: { type: RunStepTypeEnum, isOptional: false },
659
- toolId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
660
- toolName: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
661
- input: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
662
- output: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
663
- status: { type: RunStatusEnum, isOptional: false },
664
- errorMessage: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
665
- tokensUsed: {
666
- type: ScalarTypeEnum2.Int_unsecure(),
667
- isOptional: false,
668
- defaultValue: 0
669
- },
670
- durationMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
671
- startedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
672
- completedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true }
673
- }
674
- });
675
- var RunLogModel = defineSchemaModel2({
676
- name: "RunLog",
677
- description: "Execution log entry",
678
- fields: {
679
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
680
- stepId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
681
- level: { type: LogLevelEnum, isOptional: false },
682
- message: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
683
- data: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
684
- source: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
685
- traceId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
686
- spanId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
687
- timestamp: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
688
- }
689
- });
690
- var RunAgentRefModel = defineSchemaModel2({
691
- name: "RunAgentRef",
692
- description: "Agent reference in a run",
1079
+ description: "Payload for run started event",
693
1080
  fields: {
694
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
695
- name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
696
- modelProvider: {
697
- type: ScalarTypeEnum2.String_unsecure(),
1081
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1082
+ organizationId: {
1083
+ type: ScalarTypeEnum3.String_unsecure(),
698
1084
  isOptional: false
699
1085
  },
700
- modelName: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
1086
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1087
+ agentName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1088
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1089
+ sessionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1090
+ input: { type: ScalarTypeEnum3.JSONObject(), isOptional: false },
1091
+ startedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
701
1092
  }
702
1093
  });
703
- var RunModel = defineSchemaModel2({
704
- name: "Run",
705
- description: "Agent execution instance",
1094
+ var RunStartedEvent = defineEvent({
1095
+ meta: {
1096
+ key: "agent.run.started",
1097
+ version: "1.0.0",
1098
+ description: "An agent run was started.",
1099
+ stability: "stable",
1100
+ owners: [...OWNERS2],
1101
+ tags: ["run", "started"]
1102
+ },
1103
+ payload: RunStartedPayload
1104
+ });
1105
+ var RunCompletedPayload = defineSchemaModel3({
1106
+ name: "RunCompletedPayload",
1107
+ description: "Payload for run completed event",
706
1108
  fields: {
707
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
1109
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
708
1110
  organizationId: {
709
- type: ScalarTypeEnum2.String_unsecure(),
1111
+ type: ScalarTypeEnum3.String_unsecure(),
710
1112
  isOptional: false
711
1113
  },
712
- agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
713
- userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
714
- sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
715
- input: { type: ScalarTypeEnum2.JSONObject(), isOptional: false },
716
- output: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
717
- status: { type: RunStatusEnum, isOptional: false },
718
- errorMessage: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
719
- errorCode: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
720
- totalTokens: {
721
- type: ScalarTypeEnum2.Int_unsecure(),
722
- isOptional: false,
723
- defaultValue: 0
724
- },
725
- promptTokens: {
726
- type: ScalarTypeEnum2.Int_unsecure(),
727
- isOptional: false,
728
- defaultValue: 0
729
- },
1114
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1115
+ agentName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1116
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1117
+ output: { type: ScalarTypeEnum3.JSONObject(), isOptional: false },
1118
+ totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1119
+ promptTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
730
1120
  completionTokens: {
731
- type: ScalarTypeEnum2.Int_unsecure(),
732
- isOptional: false,
733
- defaultValue: 0
734
- },
735
- totalIterations: {
736
- type: ScalarTypeEnum2.Int_unsecure(),
737
- isOptional: false,
738
- defaultValue: 0
739
- },
740
- durationMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
741
- estimatedCostUsd: {
742
- type: ScalarTypeEnum2.Float_unsecure(),
743
- isOptional: true
1121
+ type: ScalarTypeEnum3.Int_unsecure(),
1122
+ isOptional: false
744
1123
  },
745
- queuedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
746
- startedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
747
- completedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
748
- metadata: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
749
- steps: { type: RunStepModel, isArray: true, isOptional: true },
750
- logs: { type: RunLogModel, isArray: true, isOptional: true },
751
- agent: { type: RunAgentRefModel, isOptional: true }
752
- }
753
- });
754
- var RunSummaryModel = defineSchemaModel2({
755
- name: "RunSummary",
756
- description: "Summary of a run for list views",
757
- fields: {
758
- id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
759
- agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
760
- agentName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
761
- status: { type: RunStatusEnum, isOptional: false },
762
- totalTokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
763
- durationMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
1124
+ totalIterations: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1125
+ durationMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
764
1126
  estimatedCostUsd: {
765
- type: ScalarTypeEnum2.Float_unsecure(),
1127
+ type: ScalarTypeEnum3.Float_unsecure(),
766
1128
  isOptional: true
767
1129
  },
768
- queuedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
769
- completedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true }
770
- }
771
- });
772
- var TimelineDataPointModel = defineSchemaModel2({
773
- name: "TimelineDataPoint",
774
- description: "Timeline data point for metrics",
775
- fields: {
776
- period: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
777
- runs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
778
- tokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
779
- costUsd: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false },
780
- avgDurationMs: { type: ScalarTypeEnum2.Float_unsecure(), isOptional: false }
781
- }
782
- });
783
-
784
- // src/run/run.operation.ts
785
- import {
786
- defineCommand,
787
- defineQuery
788
- } from "@contractspec/lib.contracts-spec/operations";
789
- import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
790
- var OWNERS2 = ["@agent-console-team"];
791
- var ExecuteAgentCommand = defineCommand({
792
- meta: {
793
- key: "agent.run.execute",
794
- version: "1.0.0",
795
- stability: "stable",
796
- owners: [...OWNERS2],
797
- tags: ["run", "execute"],
798
- description: "Starts a new agent run with the given input.",
799
- goal: "Execute an AI agent with user input.",
800
- context: "Called from chat interface or API."
801
- },
802
- io: {
803
- input: defineSchemaModel3({
804
- name: "ExecuteAgentInput",
805
- fields: {
806
- agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
807
- input: { type: RunInputModel, isOptional: false },
808
- sessionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
809
- metadata: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
810
- stream: { type: ScalarTypeEnum3.Boolean(), isOptional: true },
811
- maxIterations: {
812
- type: ScalarTypeEnum3.Int_unsecure(),
813
- isOptional: true
814
- },
815
- timeoutMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true }
816
- }
817
- }),
818
- output: defineSchemaModel3({
819
- name: "ExecuteAgentOutput",
820
- fields: {
821
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
822
- status: { type: RunStatusEnum, isOptional: false },
823
- estimatedWaitMs: {
824
- type: ScalarTypeEnum3.Int_unsecure(),
825
- isOptional: true
826
- }
827
- }
828
- }),
829
- errors: {
830
- AGENT_NOT_FOUND: {
831
- description: "The specified agent does not exist",
832
- http: 404,
833
- gqlCode: "AGENT_NOT_FOUND",
834
- when: "Agent ID is invalid"
835
- },
836
- AGENT_NOT_ACTIVE: {
837
- description: "The specified agent is not active",
838
- http: 400,
839
- gqlCode: "AGENT_NOT_ACTIVE",
840
- when: "Agent is in draft/paused/archived state"
841
- }
842
- }
843
- },
844
- policy: { auth: "user" },
845
- sideEffects: {
846
- emits: [
847
- {
848
- key: "run.started",
849
- version: "1.0.0",
850
- stability: "stable",
851
- owners: [...OWNERS2],
852
- tags: ["run", "started"],
853
- when: "Run is queued",
854
- payload: RunSummaryModel
855
- }
856
- ],
857
- audit: ["run.started"]
858
- },
859
- acceptance: {
860
- scenarios: [
861
- {
862
- key: "execute-agent-happy-path",
863
- given: ["Agent exists", "Agent is active"],
864
- when: ["User submits execution request"],
865
- then: ["Run is created", "RunStarted event is emitted"]
866
- },
867
- {
868
- key: "execute-agent-not-active",
869
- given: ["Agent exists but is not active"],
870
- when: ["User attempts to execute"],
871
- then: ["AGENT_NOT_ACTIVE error is returned"]
872
- }
873
- ],
874
- examples: [
875
- {
876
- key: "basic-execute",
877
- input: { agentId: "agent-123", input: { message: "Hello" } },
878
- output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
879
- }
880
- ]
881
- }
882
- });
883
- var CancelRunCommand = defineCommand({
884
- meta: {
885
- key: "agent.run.cancel",
886
- version: "1.0.0",
887
- stability: "stable",
888
- owners: [...OWNERS2],
889
- tags: ["run", "cancel"],
890
- description: "Cancels an in-progress agent run.",
891
- goal: "Stop a running agent execution.",
892
- context: "Called when user wants to abort a long-running task."
893
- },
894
- io: {
895
- input: defineSchemaModel3({
896
- name: "CancelRunInput",
897
- fields: {
898
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
899
- reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
900
- }
901
- }),
902
- output: defineSchemaModel3({
903
- name: "CancelRunOutput",
904
- fields: {
905
- success: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
906
- status: { type: RunStatusEnum, isOptional: false }
907
- }
908
- }),
909
- errors: {
910
- RUN_NOT_FOUND: {
911
- description: "The specified run does not exist",
912
- http: 404,
913
- gqlCode: "RUN_NOT_FOUND",
914
- when: "Run ID is invalid"
915
- },
916
- RUN_NOT_CANCELLABLE: {
917
- description: "The run cannot be cancelled",
918
- http: 400,
919
- gqlCode: "RUN_NOT_CANCELLABLE",
920
- when: "Run is already completed/failed/cancelled"
921
- }
922
- }
923
- },
924
- policy: { auth: "user" },
925
- sideEffects: {
926
- emits: [
927
- {
928
- key: "run.cancelled",
929
- version: "1.0.0",
930
- stability: "stable",
931
- owners: [...OWNERS2],
932
- tags: ["run", "cancelled"],
933
- when: "Run is cancelled",
934
- payload: RunSummaryModel
935
- }
936
- ],
937
- audit: ["run.cancelled"]
938
- },
939
- acceptance: {
940
- scenarios: [
941
- {
942
- key: "cancel-run-happy-path",
943
- given: ["Run exists", "Run is in progress"],
944
- when: ["User cancels run"],
945
- then: ["Run is cancelled", "RunCancelled event is emitted"]
946
- },
947
- {
948
- key: "cancel-run-already-completed",
949
- given: ["Run exists but is already completed"],
950
- when: ["User attempts to cancel"],
951
- then: ["RUN_NOT_CANCELLABLE error is returned"]
952
- }
953
- ],
954
- examples: [
955
- {
956
- key: "cancel-basic",
957
- input: { runId: "run-456", reason: "User requested" },
958
- output: { success: true, status: "cancelled" }
959
- }
960
- ]
1130
+ completedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
961
1131
  }
962
1132
  });
963
- var GetRunQuery = defineQuery({
1133
+ var RunCompletedEvent = defineEvent({
964
1134
  meta: {
965
- key: "agent.run.get",
1135
+ key: "agent.run.completed",
966
1136
  version: "1.0.0",
1137
+ description: "An agent run completed successfully.",
967
1138
  stability: "stable",
968
1139
  owners: [...OWNERS2],
969
- tags: ["run", "get"],
970
- description: "Retrieves a run by its ID with optional details.",
971
- goal: "View detailed run information.",
972
- context: "Run details page or monitoring."
973
- },
974
- io: {
975
- input: defineSchemaModel3({
976
- name: "GetRunInput",
977
- fields: {
978
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
979
- includeSteps: { type: ScalarTypeEnum3.Boolean(), isOptional: true },
980
- includeLogs: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
981
- }
982
- }),
983
- output: RunModel,
984
- errors: {
985
- RUN_NOT_FOUND: {
986
- description: "The specified run does not exist",
987
- http: 404,
988
- gqlCode: "RUN_NOT_FOUND",
989
- when: "Run ID is invalid"
990
- }
991
- }
992
- },
993
- policy: { auth: "user" },
994
- acceptance: {
995
- scenarios: [
996
- {
997
- key: "get-run-happy-path",
998
- given: ["Run exists"],
999
- when: ["User requests run by ID"],
1000
- then: ["Run details are returned"]
1001
- }
1002
- ],
1003
- examples: [
1004
- {
1005
- key: "get-with-steps",
1006
- input: { runId: "run-456", includeSteps: true, includeLogs: false },
1007
- output: { id: "run-456", status: "completed", steps: [] }
1008
- }
1009
- ]
1140
+ tags: ["run", "completed"]
1141
+ },
1142
+ payload: RunCompletedPayload
1143
+ });
1144
+ var RunFailedPayload = defineSchemaModel3({
1145
+ name: "RunFailedPayload",
1146
+ description: "Payload for run failed event",
1147
+ fields: {
1148
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1149
+ organizationId: {
1150
+ type: ScalarTypeEnum3.String_unsecure(),
1151
+ isOptional: false
1152
+ },
1153
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1154
+ agentName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1155
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1156
+ errorMessage: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1157
+ errorCode: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1158
+ totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1159
+ totalIterations: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1160
+ durationMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true },
1161
+ failedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1010
1162
  }
1011
1163
  });
1012
- var ListRunsQuery = defineQuery({
1164
+ var RunFailedEvent = defineEvent({
1013
1165
  meta: {
1014
- key: "agent.run.list",
1166
+ key: "agent.run.failed",
1015
1167
  version: "1.0.0",
1168
+ description: "An agent run encountered an error.",
1016
1169
  stability: "stable",
1017
1170
  owners: [...OWNERS2],
1018
- tags: ["run", "list"],
1019
- description: "Lists runs with optional filtering.",
1020
- goal: "Browse and search run history.",
1021
- context: "Run history/dashboard view."
1022
- },
1023
- io: {
1024
- input: defineSchemaModel3({
1025
- name: "ListRunsInput",
1026
- fields: {
1027
- organizationId: {
1028
- type: ScalarTypeEnum3.String_unsecure(),
1029
- isOptional: true
1030
- },
1031
- agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1032
- userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1033
- sessionId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1034
- status: { type: RunStatusEnum, isOptional: true },
1035
- startDate: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
1036
- endDate: { type: ScalarTypeEnum3.DateTime(), isOptional: true },
1037
- limit: {
1038
- type: ScalarTypeEnum3.Int_unsecure(),
1039
- isOptional: true,
1040
- defaultValue: 20
1041
- },
1042
- offset: {
1043
- type: ScalarTypeEnum3.Int_unsecure(),
1044
- isOptional: true,
1045
- defaultValue: 0
1046
- }
1047
- }
1048
- }),
1049
- output: defineSchemaModel3({
1050
- name: "ListRunsOutput",
1051
- fields: {
1052
- items: { type: RunSummaryModel, isArray: true, isOptional: false },
1053
- total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1054
- hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
1055
- }
1056
- })
1171
+ tags: ["run", "failed"]
1057
1172
  },
1058
- policy: { auth: "user" },
1059
- acceptance: {
1060
- scenarios: [
1061
- {
1062
- key: "list-runs-happy-path",
1063
- given: ["Organization has runs"],
1064
- when: ["User lists runs"],
1065
- then: ["Paginated list of runs is returned"]
1066
- }
1067
- ],
1068
- examples: [
1069
- {
1070
- key: "list-by-agent",
1071
- input: { agentId: "agent-123", limit: 20, offset: 0 },
1072
- output: { items: [], total: 0, hasMore: false }
1073
- }
1074
- ]
1173
+ payload: RunFailedPayload
1174
+ });
1175
+ var RunCancelledPayload = defineSchemaModel3({
1176
+ name: "RunCancelledPayload",
1177
+ description: "Payload for run cancelled event",
1178
+ fields: {
1179
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1180
+ organizationId: {
1181
+ type: ScalarTypeEnum3.String_unsecure(),
1182
+ isOptional: false
1183
+ },
1184
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1185
+ userId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1186
+ cancelledBy: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1187
+ reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1188
+ totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1189
+ totalIterations: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1190
+ cancelledAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1075
1191
  }
1076
1192
  });
1077
- var GetRunStepsQuery = defineQuery({
1193
+ var RunCancelledEvent = defineEvent({
1078
1194
  meta: {
1079
- key: "agent.run.getSteps",
1195
+ key: "agent.run.cancelled",
1080
1196
  version: "1.0.0",
1197
+ description: "An agent run was cancelled by the user.",
1081
1198
  stability: "stable",
1082
1199
  owners: [...OWNERS2],
1083
- tags: ["run", "steps"],
1084
- description: "Retrieves all steps for a specific run.",
1085
- goal: "View step-by-step execution details.",
1086
- context: "Run details page - steps tab."
1087
- },
1088
- io: {
1089
- input: defineSchemaModel3({
1090
- name: "GetRunStepsInput",
1091
- fields: {
1092
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
1093
- }
1094
- }),
1095
- output: defineSchemaModel3({
1096
- name: "GetRunStepsOutput",
1097
- fields: {
1098
- steps: { type: RunStepModel, isArray: true, isOptional: false }
1099
- }
1100
- })
1200
+ tags: ["run", "cancelled"]
1101
1201
  },
1102
- policy: { auth: "user" },
1103
- acceptance: {
1104
- scenarios: [
1105
- {
1106
- key: "get-run-steps-happy-path",
1107
- given: ["Run exists with steps"],
1108
- when: ["User requests steps"],
1109
- then: ["Steps list is returned"]
1110
- }
1111
- ],
1112
- examples: [
1113
- {
1114
- key: "get-steps-basic",
1115
- input: { runId: "run-456" },
1116
- output: { steps: [] }
1117
- }
1118
- ]
1202
+ payload: RunCancelledPayload
1203
+ });
1204
+ var ToolInvokedPayload = defineSchemaModel3({
1205
+ name: "ToolInvokedPayload",
1206
+ description: "Payload for tool invoked event",
1207
+ fields: {
1208
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1209
+ stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1210
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1211
+ toolName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1212
+ input: { type: ScalarTypeEnum3.JSONObject(), isOptional: false },
1213
+ invokedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1119
1214
  }
1120
1215
  });
1121
- var GetRunLogsQuery = defineQuery({
1216
+ var ToolInvokedEvent = defineEvent({
1122
1217
  meta: {
1123
- key: "agent.run.getLogs",
1218
+ key: "agent.run.toolInvoked",
1124
1219
  version: "1.0.0",
1220
+ description: "A tool was invoked during an agent run.",
1125
1221
  stability: "stable",
1126
1222
  owners: [...OWNERS2],
1127
- tags: ["run", "logs"],
1128
- description: "Retrieves all logs for a specific run.",
1129
- goal: "Debug and audit run execution.",
1130
- context: "Run details page - logs tab."
1131
- },
1132
- io: {
1133
- input: defineSchemaModel3({
1134
- name: "GetRunLogsInput",
1135
- fields: {
1136
- runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1137
- level: { type: LogLevelEnum, isOptional: true },
1138
- stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1139
- limit: {
1140
- type: ScalarTypeEnum3.Int_unsecure(),
1141
- isOptional: true,
1142
- defaultValue: 100
1143
- },
1144
- offset: {
1145
- type: ScalarTypeEnum3.Int_unsecure(),
1146
- isOptional: true,
1147
- defaultValue: 0
1148
- }
1149
- }
1150
- }),
1151
- output: defineSchemaModel3({
1152
- name: "GetRunLogsOutput",
1153
- fields: {
1154
- items: { type: RunLogModel, isArray: true, isOptional: false },
1155
- total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1156
- hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
1157
- }
1158
- })
1223
+ tags: ["run", "tool", "invoked"]
1159
1224
  },
1160
- policy: { auth: "user" },
1161
- acceptance: {
1162
- scenarios: [
1163
- {
1164
- key: "get-run-logs-happy-path",
1165
- given: ["Run exists with logs"],
1166
- when: ["User requests logs"],
1167
- then: ["Paginated logs list is returned"]
1168
- }
1169
- ],
1170
- examples: [
1171
- {
1172
- key: "get-logs-filtered",
1173
- input: { runId: "run-456", level: "error", limit: 50 },
1174
- output: { items: [], total: 0, hasMore: false }
1175
- }
1176
- ]
1225
+ payload: ToolInvokedPayload
1226
+ });
1227
+ var ToolCompletedPayload = defineSchemaModel3({
1228
+ name: "ToolCompletedPayload",
1229
+ description: "Payload for tool completed event",
1230
+ fields: {
1231
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1232
+ stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1233
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1234
+ toolName: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1235
+ success: { type: ScalarTypeEnum3.Boolean(), isOptional: false },
1236
+ output: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
1237
+ errorMessage: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1238
+ durationMs: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1239
+ completedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1177
1240
  }
1178
1241
  });
1179
- var GetRunMetricsQuery = defineQuery({
1242
+ var ToolCompletedEvent = defineEvent({
1180
1243
  meta: {
1181
- key: "agent.run.getMetrics",
1244
+ key: "agent.run.toolCompleted",
1182
1245
  version: "1.0.0",
1246
+ description: "A tool invocation completed during an agent run.",
1183
1247
  stability: "stable",
1184
1248
  owners: [...OWNERS2],
1185
- tags: ["run", "metrics"],
1186
- description: "Retrieves aggregated metrics for runs within a time period.",
1187
- goal: "Monitor and analyze agent usage.",
1188
- context: "Analytics dashboard."
1189
- },
1190
- io: {
1191
- input: defineSchemaModel3({
1192
- name: "GetRunMetricsInput",
1193
- fields: {
1194
- organizationId: {
1195
- type: ScalarTypeEnum3.String_unsecure(),
1196
- isOptional: false
1197
- },
1198
- agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
1199
- startDate: { type: ScalarTypeEnum3.DateTime(), isOptional: false },
1200
- endDate: { type: ScalarTypeEnum3.DateTime(), isOptional: false },
1201
- granularity: {
1202
- type: GranularityEnum,
1203
- isOptional: true,
1204
- defaultValue: "day"
1205
- }
1206
- }
1207
- }),
1208
- output: defineSchemaModel3({
1209
- name: "GetRunMetricsOutput",
1210
- fields: {
1211
- totalRuns: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1212
- completedRuns: {
1213
- type: ScalarTypeEnum3.Int_unsecure(),
1214
- isOptional: false
1215
- },
1216
- failedRuns: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1217
- totalTokens: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1218
- totalCostUsd: {
1219
- type: ScalarTypeEnum3.Float_unsecure(),
1220
- isOptional: false
1221
- },
1222
- averageDurationMs: {
1223
- type: ScalarTypeEnum3.Float_unsecure(),
1224
- isOptional: false
1225
- },
1226
- successRate: {
1227
- type: ScalarTypeEnum3.Float_unsecure(),
1228
- isOptional: false
1229
- },
1230
- timeline: {
1231
- type: TimelineDataPointModel,
1232
- isArray: true,
1233
- isOptional: false
1234
- }
1235
- }
1236
- })
1249
+ tags: ["run", "tool", "completed"]
1237
1250
  },
1238
- policy: { auth: "user" },
1239
- acceptance: {
1240
- scenarios: [
1241
- {
1242
- key: "get-run-metrics-happy-path",
1243
- given: ["Organization has run history"],
1244
- when: ["User requests metrics for date range"],
1245
- then: ["Aggregated metrics are returned"]
1246
- }
1247
- ],
1248
- examples: [
1249
- {
1250
- key: "get-daily-metrics",
1251
- input: {
1252
- organizationId: "org-123",
1253
- startDate: "2025-01-01",
1254
- endDate: "2025-01-31",
1255
- granularity: "day"
1256
- },
1257
- output: {
1258
- totalRuns: 100,
1259
- completedRuns: 90,
1260
- failedRuns: 10,
1261
- totalTokens: 50000,
1262
- totalCostUsd: 5,
1263
- averageDurationMs: 2500,
1264
- successRate: 0.9,
1265
- timeline: []
1266
- }
1267
- }
1268
- ]
1251
+ payload: ToolCompletedPayload
1252
+ });
1253
+ var MessageTypeEnum = defineEnum2("MessageType", ["assistant", "system"]);
1254
+ var MessageGeneratedPayload = defineSchemaModel3({
1255
+ name: "MessageGeneratedPayload",
1256
+ description: "Payload for message generated event",
1257
+ fields: {
1258
+ runId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1259
+ stepId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1260
+ messageType: { type: MessageTypeEnum, isOptional: false },
1261
+ content: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
1262
+ tokensUsed: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
1263
+ generatedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
1269
1264
  }
1270
1265
  });
1266
+ var MessageGeneratedEvent = defineEvent({
1267
+ meta: {
1268
+ key: "agent.run.messageGenerated",
1269
+ version: "1.0.0",
1270
+ description: "An agent generated a message during a run.",
1271
+ stability: "stable",
1272
+ owners: [...OWNERS2],
1273
+ tags: ["run", "message", "generated"]
1274
+ },
1275
+ payload: MessageGeneratedPayload
1276
+ });
1271
1277
 
1272
1278
  // src/run/run.presentation.ts
1273
1279
  import {