@contractspec/example.agent-console 3.7.6 → 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 (288) hide show
  1. package/.turbo/turbo-build.log +126 -105
  2. package/AGENTS.md +52 -31
  3. package/CHANGELOG.md +29 -0
  4. package/README.md +112 -83
  5. package/dist/agent/agent.event.js +1 -1
  6. package/dist/agent/agent.handler.d.ts +3 -0
  7. package/dist/agent/agent.handler.js +730 -1
  8. package/dist/agent/agent.operation.js +1 -1
  9. package/dist/agent/index.d.ts +5 -5
  10. package/dist/agent/index.js +74 -73
  11. package/dist/agent.feature.js +179 -0
  12. package/dist/browser/agent/agent.event.js +1 -1
  13. package/dist/browser/agent/agent.handler.js +730 -1
  14. package/dist/browser/agent/agent.operation.js +1 -1
  15. package/dist/browser/agent/index.js +74 -73
  16. package/dist/browser/agent.feature.js +179 -0
  17. package/dist/browser/docs/agent-console.docblock.js +11 -8
  18. package/dist/browser/docs/index.js +11 -8
  19. package/dist/browser/example.js +2 -3
  20. package/dist/browser/handlers/agent.handlers.js +1883 -2
  21. package/dist/browser/handlers/index.js +2142 -8
  22. package/dist/browser/index.js +4075 -3161
  23. package/dist/browser/presentations/index.js +51 -51
  24. package/dist/browser/run/index.js +380 -374
  25. package/dist/browser/run/run.event.js +2 -2
  26. package/dist/browser/run/run.handler.js +666 -1
  27. package/dist/browser/run/run.presentation.js +2 -2
  28. package/dist/browser/shared/index.js +293 -1
  29. package/dist/browser/shared/mock-runs.js +5 -0
  30. package/dist/browser/tool/index.js +161 -161
  31. package/dist/browser/tool/tool.event.js +1 -1
  32. package/dist/browser/tool/tool.handler.js +479 -3
  33. package/dist/browser/tool/tool.presentation.js +2 -2
  34. package/dist/browser/ui/AgentDashboard.js +1816 -931
  35. package/dist/browser/ui/AgentDashboard.visualizations.js +217 -0
  36. package/dist/browser/ui/AgentRunList.js +360 -128
  37. package/dist/browser/ui/AgentToolRegistry.js +9 -9
  38. package/dist/browser/ui/hooks/index.js +611 -161
  39. package/dist/browser/ui/hooks/useAgentList.js +1 -1
  40. package/dist/browser/ui/hooks/useAgentMutations.js +444 -9
  41. package/dist/browser/ui/hooks/useRunList.js +26 -11
  42. package/dist/browser/ui/hooks/useToolList.js +1 -1
  43. package/dist/browser/ui/index.js +2161 -1258
  44. package/dist/browser/ui/modals/AgentActionsModal.js +13 -13
  45. package/dist/browser/ui/modals/CreateAgentModal.js +15 -15
  46. package/dist/browser/ui/modals/index.js +297 -297
  47. package/dist/browser/ui/renderers/agent-list.markdown.js +14 -5
  48. package/dist/browser/ui/renderers/agent-list.renderer.js +7 -7
  49. package/dist/browser/ui/renderers/dashboard.markdown.js +207 -36
  50. package/dist/browser/ui/renderers/index.js +359 -163
  51. package/dist/browser/ui/renderers/run-list.markdown.js +9 -4
  52. package/dist/browser/ui/renderers/tool-registry.markdown.js +15 -4
  53. package/dist/browser/ui/views/AgentListView.js +7 -7
  54. package/dist/browser/ui/views/RunDataTable.js +326 -0
  55. package/dist/browser/ui/views/RunListView.js +360 -128
  56. package/dist/browser/ui/views/ToolRegistryView.js +9 -9
  57. package/dist/browser/ui/views/index.js +478 -246
  58. package/dist/browser/ui/views/run-data-table.columns.js +271 -0
  59. package/dist/browser/ui/views/run-list.shared.js +177 -0
  60. package/dist/browser/visualizations/catalog.js +134 -0
  61. package/dist/browser/visualizations/index.js +187 -0
  62. package/dist/browser/visualizations/selectors.js +181 -0
  63. package/dist/docs/agent-console.docblock.js +11 -8
  64. package/dist/docs/index.js +11 -8
  65. package/dist/example.js +2 -3
  66. package/dist/example.test.d.ts +1 -0
  67. package/dist/handlers/agent.handlers.d.ts +2 -0
  68. package/dist/handlers/agent.handlers.js +1883 -2
  69. package/dist/handlers/index.d.ts +2 -4
  70. package/dist/handlers/index.js +2142 -8
  71. package/dist/handlers/mock-handlers.test.d.ts +1 -0
  72. package/dist/index.d.ts +6 -4
  73. package/dist/index.js +4075 -3161
  74. package/dist/node/agent/agent.event.js +1 -1
  75. package/dist/node/agent/agent.handler.js +730 -1
  76. package/dist/node/agent/agent.operation.js +1 -1
  77. package/dist/node/agent/index.js +74 -73
  78. package/dist/node/agent.feature.js +179 -0
  79. package/dist/node/docs/agent-console.docblock.js +11 -8
  80. package/dist/node/docs/index.js +11 -8
  81. package/dist/node/example.js +2 -3
  82. package/dist/node/handlers/agent.handlers.js +1883 -2
  83. package/dist/node/handlers/index.js +2142 -8
  84. package/dist/node/index.js +4075 -3161
  85. package/dist/node/presentations/index.js +51 -51
  86. package/dist/node/run/index.js +380 -374
  87. package/dist/node/run/run.event.js +2 -2
  88. package/dist/node/run/run.handler.js +666 -1
  89. package/dist/node/run/run.presentation.js +2 -2
  90. package/dist/node/shared/index.js +293 -1
  91. package/dist/node/shared/mock-runs.js +5 -0
  92. package/dist/node/tool/index.js +161 -161
  93. package/dist/node/tool/tool.event.js +1 -1
  94. package/dist/node/tool/tool.handler.js +479 -3
  95. package/dist/node/tool/tool.presentation.js +2 -2
  96. package/dist/node/ui/AgentDashboard.js +1816 -931
  97. package/dist/node/ui/AgentDashboard.visualizations.js +217 -0
  98. package/dist/node/ui/AgentRunList.js +360 -128
  99. package/dist/node/ui/AgentToolRegistry.js +9 -9
  100. package/dist/node/ui/hooks/index.js +611 -161
  101. package/dist/node/ui/hooks/useAgentList.js +1 -1
  102. package/dist/node/ui/hooks/useAgentMutations.js +444 -9
  103. package/dist/node/ui/hooks/useRunList.js +26 -11
  104. package/dist/node/ui/hooks/useToolList.js +1 -1
  105. package/dist/node/ui/index.js +2161 -1258
  106. package/dist/node/ui/modals/AgentActionsModal.js +13 -13
  107. package/dist/node/ui/modals/CreateAgentModal.js +15 -15
  108. package/dist/node/ui/modals/index.js +297 -297
  109. package/dist/node/ui/renderers/agent-list.markdown.js +14 -5
  110. package/dist/node/ui/renderers/agent-list.renderer.js +7 -7
  111. package/dist/node/ui/renderers/dashboard.markdown.js +207 -36
  112. package/dist/node/ui/renderers/index.js +359 -163
  113. package/dist/node/ui/renderers/run-list.markdown.js +9 -4
  114. package/dist/node/ui/renderers/tool-registry.markdown.js +15 -4
  115. package/dist/node/ui/views/AgentListView.js +7 -7
  116. package/dist/node/ui/views/RunDataTable.js +326 -0
  117. package/dist/node/ui/views/RunListView.js +360 -128
  118. package/dist/node/ui/views/ToolRegistryView.js +9 -9
  119. package/dist/node/ui/views/index.js +478 -246
  120. package/dist/node/ui/views/run-data-table.columns.js +271 -0
  121. package/dist/node/ui/views/run-list.shared.js +177 -0
  122. package/dist/node/visualizations/catalog.js +134 -0
  123. package/dist/node/visualizations/index.js +187 -0
  124. package/dist/node/visualizations/selectors.js +181 -0
  125. package/dist/presentations/index.d.ts +3 -5
  126. package/dist/presentations/index.js +51 -51
  127. package/dist/proof/index.d.ts +2 -0
  128. package/dist/proof/meetup-proof.d.ts +10 -0
  129. package/dist/proof/meetup-proof.runtime.d.ts +22 -0
  130. package/dist/proof/meetup-proof.scenario.d.ts +2 -0
  131. package/dist/proof/meetup-proof.suite.d.ts +1 -0
  132. package/dist/proof/meetup-proof.test.d.ts +1 -0
  133. package/dist/run/index.d.ts +7 -7
  134. package/dist/run/index.js +380 -374
  135. package/dist/run/run.event.js +2 -2
  136. package/dist/run/run.handler.d.ts +7 -0
  137. package/dist/run/run.handler.js +666 -1
  138. package/dist/run/run.presentation.js +2 -2
  139. package/dist/shared/demo-dashboard-data.d.ts +16 -0
  140. package/dist/shared/demo-runtime-seed.d.ts +17 -0
  141. package/dist/shared/demo-runtime.d.ts +8 -0
  142. package/dist/shared/demo-runtime.test.d.ts +1 -0
  143. package/dist/shared/index.d.ts +4 -1
  144. package/dist/shared/index.js +293 -1
  145. package/dist/shared/mock-runs.d.ts +4 -0
  146. package/dist/shared/mock-runs.js +5 -0
  147. package/dist/tool/index.d.ts +7 -7
  148. package/dist/tool/index.js +161 -161
  149. package/dist/tool/tool.event.js +1 -1
  150. package/dist/tool/tool.handler.d.ts +3 -0
  151. package/dist/tool/tool.handler.js +479 -3
  152. package/dist/tool/tool.presentation.js +2 -2
  153. package/dist/ui/AgentDashboard.js +1816 -931
  154. package/dist/ui/AgentDashboard.sandbox.test.d.ts +1 -0
  155. package/dist/ui/AgentDashboard.visualizations.d.ts +4 -0
  156. package/dist/ui/AgentDashboard.visualizations.js +218 -0
  157. package/dist/ui/AgentRunList.js +360 -128
  158. package/dist/ui/AgentToolRegistry.js +9 -9
  159. package/dist/ui/hooks/index.d.ts +4 -4
  160. package/dist/ui/hooks/index.js +611 -161
  161. package/dist/ui/hooks/useAgentList.d.ts +5 -0
  162. package/dist/ui/hooks/useAgentList.js +1 -1
  163. package/dist/ui/hooks/useAgentMutations.d.ts +9 -2
  164. package/dist/ui/hooks/useAgentMutations.js +444 -9
  165. package/dist/ui/hooks/useRunList.d.ts +13 -2
  166. package/dist/ui/hooks/useRunList.js +26 -11
  167. package/dist/ui/hooks/useToolList.d.ts +5 -0
  168. package/dist/ui/hooks/useToolList.js +1 -1
  169. package/dist/ui/index.d.ts +3 -3
  170. package/dist/ui/index.js +2161 -1258
  171. package/dist/ui/modals/AgentActionsModal.js +13 -13
  172. package/dist/ui/modals/CreateAgentModal.js +15 -15
  173. package/dist/ui/modals/index.d.ts +1 -1
  174. package/dist/ui/modals/index.js +297 -297
  175. package/dist/ui/renderers/agent-list.markdown.d.ts +5 -0
  176. package/dist/ui/renderers/agent-list.markdown.js +14 -5
  177. package/dist/ui/renderers/agent-list.renderer.js +7 -7
  178. package/dist/ui/renderers/dashboard.markdown.d.ts +5 -0
  179. package/dist/ui/renderers/dashboard.markdown.js +207 -36
  180. package/dist/ui/renderers/index.d.ts +2 -2
  181. package/dist/ui/renderers/index.js +359 -163
  182. package/dist/ui/renderers/run-list.markdown.d.ts +5 -0
  183. package/dist/ui/renderers/run-list.markdown.js +9 -4
  184. package/dist/ui/renderers/tool-registry.markdown.d.ts +6 -1
  185. package/dist/ui/renderers/tool-registry.markdown.js +15 -4
  186. package/dist/ui/views/AgentListView.js +7 -7
  187. package/dist/ui/views/RunDataTable.d.ts +18 -0
  188. package/dist/ui/views/RunDataTable.js +327 -0
  189. package/dist/ui/views/RunListView.js +360 -128
  190. package/dist/ui/views/ToolRegistryView.js +9 -9
  191. package/dist/ui/views/index.js +478 -246
  192. package/dist/ui/views/run-data-table.columns.d.ts +3 -0
  193. package/dist/ui/views/run-data-table.columns.js +272 -0
  194. package/dist/ui/views/run-list.shared.d.ts +14 -0
  195. package/dist/ui/views/run-list.shared.js +178 -0
  196. package/dist/visualizations/catalog.d.ts +10 -0
  197. package/dist/visualizations/catalog.js +135 -0
  198. package/dist/visualizations/index.d.ts +2 -0
  199. package/dist/visualizations/index.js +188 -0
  200. package/dist/visualizations/selectors.d.ts +3 -0
  201. package/dist/visualizations/selectors.js +182 -0
  202. package/dist/visualizations/selectors.test.d.ts +1 -0
  203. package/package.json +114 -12
  204. package/proofs/agent-console-meetup.replay.json +220 -0
  205. package/src/agent/agent.entity.ts +111 -111
  206. package/src/agent/agent.enum.ts +12 -12
  207. package/src/agent/agent.event.ts +91 -91
  208. package/src/agent/agent.handler.ts +144 -127
  209. package/src/agent/agent.operation.ts +400 -400
  210. package/src/agent/agent.presentation.ts +62 -62
  211. package/src/agent/agent.schema.ts +175 -175
  212. package/src/agent/agent.test-spec.ts +48 -48
  213. package/src/agent/index.ts +46 -51
  214. package/src/agent.capability.ts +11 -11
  215. package/src/agent.feature.ts +134 -131
  216. package/src/docs/agent-console.docblock.ts +52 -49
  217. package/src/example.test.ts +75 -0
  218. package/src/example.ts +34 -35
  219. package/src/handlers/agent.handlers.ts +576 -522
  220. package/src/handlers/index.ts +30 -14
  221. package/src/handlers/mock-handlers.test.ts +77 -0
  222. package/src/index.ts +10 -9
  223. package/src/presentations/index.ts +11 -13
  224. package/src/proof/index.ts +2 -0
  225. package/src/proof/meetup-proof.runtime.ts +196 -0
  226. package/src/proof/meetup-proof.scenario.ts +99 -0
  227. package/src/proof/meetup-proof.suite.ts +29 -0
  228. package/src/proof/meetup-proof.test.ts +28 -0
  229. package/src/proof/meetup-proof.ts +130 -0
  230. package/src/run/index.ts +49 -54
  231. package/src/run/run.entity.ts +137 -137
  232. package/src/run/run.enum.ts +18 -18
  233. package/src/run/run.event.ts +174 -174
  234. package/src/run/run.handler.ts +113 -96
  235. package/src/run/run.operation.ts +474 -474
  236. package/src/run/run.presentation.ts +42 -42
  237. package/src/run/run.schema.ts +126 -126
  238. package/src/run/run.test-spec.ts +48 -48
  239. package/src/seeders/index.ts +21 -21
  240. package/src/shared/demo-dashboard-data.ts +58 -0
  241. package/src/shared/demo-runtime-seed.ts +139 -0
  242. package/src/shared/demo-runtime.test.ts +169 -0
  243. package/src/shared/demo-runtime.ts +260 -0
  244. package/src/shared/index.ts +12 -1
  245. package/src/shared/mock-agents.ts +76 -76
  246. package/src/shared/mock-runs.ts +107 -102
  247. package/src/shared/mock-tools.ts +140 -140
  248. package/src/shared/overlay-types.ts +23 -23
  249. package/src/tool/index.ts +39 -44
  250. package/src/tool/tool.entity.ts +73 -73
  251. package/src/tool/tool.enum.ts +13 -13
  252. package/src/tool/tool.event.ts +80 -80
  253. package/src/tool/tool.handler.ts +124 -107
  254. package/src/tool/tool.operation.ts +328 -328
  255. package/src/tool/tool.presentation.ts +43 -43
  256. package/src/tool/tool.schema.ts +106 -106
  257. package/src/tool/tool.test-spec.ts +48 -48
  258. package/src/ui/AgentDashboard.sandbox.test.tsx +312 -0
  259. package/src/ui/AgentDashboard.tsx +351 -348
  260. package/src/ui/AgentDashboard.visualizations.tsx +35 -0
  261. package/src/ui/hooks/index.ts +7 -7
  262. package/src/ui/hooks/useAgentList.ts +57 -56
  263. package/src/ui/hooks/useAgentMutations.ts +168 -159
  264. package/src/ui/hooks/useRunList.ts +90 -57
  265. package/src/ui/hooks/useToolList.ts +102 -101
  266. package/src/ui/index.ts +6 -9
  267. package/src/ui/modals/AgentActionsModal.tsx +262 -262
  268. package/src/ui/modals/CreateAgentModal.tsx +232 -232
  269. package/src/ui/modals/index.ts +1 -1
  270. package/src/ui/overlays/demo-overlays.ts +52 -52
  271. package/src/ui/renderers/agent-list.markdown.ts +81 -61
  272. package/src/ui/renderers/agent-list.renderer.tsx +14 -14
  273. package/src/ui/renderers/dashboard.markdown.ts +135 -139
  274. package/src/ui/renderers/index.ts +3 -4
  275. package/src/ui/renderers/run-list.markdown.ts +56 -47
  276. package/src/ui/renderers/tool-registry.markdown.ts +79 -66
  277. package/src/ui/views/AgentListView.tsx +90 -90
  278. package/src/ui/views/RunDataTable.tsx +74 -0
  279. package/src/ui/views/RunListView.tsx +84 -158
  280. package/src/ui/views/ToolRegistryView.tsx +113 -113
  281. package/src/ui/views/run-data-table.columns.tsx +102 -0
  282. package/src/ui/views/run-list.shared.tsx +139 -0
  283. package/src/visualizations/catalog.ts +132 -0
  284. package/src/visualizations/index.ts +2 -0
  285. package/src/visualizations/selectors.test.ts +12 -0
  286. package/src/visualizations/selectors.ts +70 -0
  287. package/tsconfig.json +7 -8
  288. package/tsdown.config.js +24 -3
@@ -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
  };