@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
@@ -1,7 +1,1878 @@
1
1
  // @bun
2
+ // src/agent/agent.enum.ts
3
+ import { defineEnum } from "@contractspec/lib.schema";
4
+ var AgentStatusEnum = defineEnum("AgentStatus", [
5
+ "DRAFT",
6
+ "ACTIVE",
7
+ "PAUSED",
8
+ "ARCHIVED"
9
+ ]);
10
+ var ModelProviderEnum = defineEnum("ModelProvider", [
11
+ "OPENAI",
12
+ "ANTHROPIC",
13
+ "GOOGLE",
14
+ "MISTRAL",
15
+ "CUSTOM"
16
+ ]);
17
+ var ToolChoiceEnum = defineEnum("ToolChoice", [
18
+ "auto",
19
+ "required",
20
+ "none"
21
+ ]);
22
+
23
+ // src/agent/agent.event.ts
24
+ import { defineEvent } from "@contractspec/lib.contracts-spec";
25
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
26
+ var OWNERS = ["@agent-console-team"];
27
+ var AgentCreatedPayload = defineSchemaModel({
28
+ name: "AgentCreatedPayload",
29
+ description: "Payload for agent created event",
30
+ fields: {
31
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
32
+ organizationId: {
33
+ type: ScalarTypeEnum.String_unsecure(),
34
+ isOptional: false
35
+ },
36
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ slug: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
38
+ modelProvider: {
39
+ type: ScalarTypeEnum.String_unsecure(),
40
+ isOptional: false
41
+ },
42
+ modelName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
43
+ toolCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
44
+ createdById: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
45
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
46
+ }
47
+ });
48
+ var AgentCreatedEvent = defineEvent({
49
+ meta: {
50
+ key: "agent-console.agent.created",
51
+ version: "1.0.0",
52
+ description: "A new AI agent was configured.",
53
+ stability: "stable",
54
+ owners: [...OWNERS],
55
+ tags: ["agent", "created"]
56
+ },
57
+ payload: AgentCreatedPayload
58
+ });
59
+ var AgentUpdatedPayload = defineSchemaModel({
60
+ name: "AgentUpdatedPayload",
61
+ description: "Payload for agent updated event",
62
+ fields: {
63
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
64
+ organizationId: {
65
+ type: ScalarTypeEnum.String_unsecure(),
66
+ isOptional: false
67
+ },
68
+ name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
69
+ status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
70
+ updatedFields: {
71
+ type: ScalarTypeEnum.String_unsecure(),
72
+ isArray: true,
73
+ isOptional: false
74
+ },
75
+ updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
76
+ }
77
+ });
78
+ var AgentUpdatedEvent = defineEvent({
79
+ meta: {
80
+ key: "agent-console.agent.updated",
81
+ version: "1.0.0",
82
+ description: "An AI agent configuration was updated.",
83
+ stability: "stable",
84
+ owners: [...OWNERS],
85
+ tags: ["agent", "updated"]
86
+ },
87
+ payload: AgentUpdatedPayload
88
+ });
89
+ var AgentToolAssignedPayload = defineSchemaModel({
90
+ name: "AgentToolAssignedPayload",
91
+ description: "Payload for agent tool assigned event",
92
+ fields: {
93
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
94
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
95
+ agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
96
+ toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
97
+ assignedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
98
+ }
99
+ });
100
+ var AgentToolAssignedEvent = defineEvent({
101
+ meta: {
102
+ key: "agent-console.agent.toolAssigned",
103
+ version: "1.0.0",
104
+ description: "A tool was assigned to an agent.",
105
+ stability: "stable",
106
+ owners: [...OWNERS],
107
+ tags: ["agent", "tool", "assigned"]
108
+ },
109
+ payload: AgentToolAssignedPayload
110
+ });
111
+ var AgentToolRemovedPayload = defineSchemaModel({
112
+ name: "AgentToolRemovedPayload",
113
+ description: "Payload for agent tool removed event",
114
+ fields: {
115
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
116
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
117
+ agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
118
+ toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
119
+ removedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
120
+ }
121
+ });
122
+ var AgentToolRemovedEvent = defineEvent({
123
+ meta: {
124
+ key: "agent-console.agent.toolRemoved",
125
+ version: "1.0.0",
126
+ description: "A tool was removed from an agent.",
127
+ stability: "stable",
128
+ owners: [...OWNERS],
129
+ tags: ["agent", "tool", "removed"]
130
+ },
131
+ payload: AgentToolRemovedPayload
132
+ });
133
+
134
+ // src/agent/agent.schema.ts
135
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
136
+ var AgentModel = defineSchemaModel2({
137
+ name: "Agent",
138
+ description: "AI agent configuration",
139
+ fields: {
140
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
141
+ organizationId: {
142
+ type: ScalarTypeEnum2.String_unsecure(),
143
+ isOptional: false
144
+ },
145
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
146
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
147
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
148
+ status: { type: AgentStatusEnum, isOptional: false },
149
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
150
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
151
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
152
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
153
+ userPromptTemplate: {
154
+ type: ScalarTypeEnum2.String_unsecure(),
155
+ isOptional: true
156
+ },
157
+ toolIds: {
158
+ type: ScalarTypeEnum2.String_unsecure(),
159
+ isArray: true,
160
+ isOptional: true
161
+ },
162
+ toolChoice: {
163
+ type: ToolChoiceEnum,
164
+ isOptional: false,
165
+ defaultValue: "auto"
166
+ },
167
+ maxIterations: {
168
+ type: ScalarTypeEnum2.Int_unsecure(),
169
+ isOptional: false,
170
+ defaultValue: 10
171
+ },
172
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
173
+ timeoutMs: {
174
+ type: ScalarTypeEnum2.Int_unsecure(),
175
+ isOptional: false,
176
+ defaultValue: 120000
177
+ },
178
+ version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
179
+ tags: {
180
+ type: ScalarTypeEnum2.String_unsecure(),
181
+ isArray: true,
182
+ isOptional: true
183
+ },
184
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
185
+ updatedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
186
+ }
187
+ });
188
+ var AgentSummaryModel = defineSchemaModel2({
189
+ name: "AgentSummary",
190
+ description: "Summary of an agent for list views",
191
+ fields: {
192
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
193
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
194
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
195
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
196
+ status: { type: AgentStatusEnum, isOptional: false },
197
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
198
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
199
+ version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
200
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
201
+ }
202
+ });
203
+ var AgentToolRefModel = defineSchemaModel2({
204
+ name: "AgentToolRef",
205
+ description: "Tool reference in agent context",
206
+ fields: {
207
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
208
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
209
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
210
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
211
+ category: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
212
+ }
213
+ });
214
+ var AgentWithToolsModel = defineSchemaModel2({
215
+ name: "AgentWithTools",
216
+ description: "Agent with associated tools",
217
+ fields: {
218
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
219
+ organizationId: {
220
+ type: ScalarTypeEnum2.String_unsecure(),
221
+ isOptional: false
222
+ },
223
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
224
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
225
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
226
+ status: { type: AgentStatusEnum, isOptional: false },
227
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
228
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
229
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
230
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
231
+ userPromptTemplate: {
232
+ type: ScalarTypeEnum2.String_unsecure(),
233
+ isOptional: true
234
+ },
235
+ toolIds: {
236
+ type: ScalarTypeEnum2.String_unsecure(),
237
+ isArray: true,
238
+ isOptional: true
239
+ },
240
+ toolChoice: { type: ToolChoiceEnum, isOptional: false },
241
+ maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
242
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
243
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
244
+ version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
245
+ tags: {
246
+ type: ScalarTypeEnum2.String_unsecure(),
247
+ isArray: true,
248
+ isOptional: true
249
+ },
250
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
251
+ updatedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
252
+ tools: { type: AgentToolRefModel, isArray: true, isOptional: true }
253
+ }
254
+ });
255
+ var CreateAgentInputModel = defineSchemaModel2({
256
+ name: "CreateAgentInput",
257
+ description: "Input for creating an agent",
258
+ fields: {
259
+ organizationId: {
260
+ type: ScalarTypeEnum2.String_unsecure(),
261
+ isOptional: false
262
+ },
263
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
264
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
265
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
266
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
267
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
268
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
269
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
270
+ userPromptTemplate: {
271
+ type: ScalarTypeEnum2.String_unsecure(),
272
+ isOptional: true
273
+ },
274
+ toolIds: {
275
+ type: ScalarTypeEnum2.String_unsecure(),
276
+ isArray: true,
277
+ isOptional: true
278
+ },
279
+ toolChoice: { type: ToolChoiceEnum, isOptional: true },
280
+ maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
281
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
282
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
283
+ tags: {
284
+ type: ScalarTypeEnum2.String_unsecure(),
285
+ isArray: true,
286
+ isOptional: true
287
+ }
288
+ }
289
+ });
290
+ var UpdateAgentInputModel = defineSchemaModel2({
291
+ name: "UpdateAgentInput",
292
+ description: "Input for updating an agent",
293
+ fields: {
294
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
295
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: true },
296
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
297
+ status: { type: AgentStatusEnum, isOptional: true },
298
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
299
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
300
+ userPromptTemplate: {
301
+ type: ScalarTypeEnum2.String_unsecure(),
302
+ isOptional: true
303
+ },
304
+ toolIds: {
305
+ type: ScalarTypeEnum2.String_unsecure(),
306
+ isArray: true,
307
+ isOptional: true
308
+ },
309
+ toolChoice: { type: ToolChoiceEnum, isOptional: true },
310
+ maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
311
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
312
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
313
+ tags: {
314
+ type: ScalarTypeEnum2.String_unsecure(),
315
+ isArray: true,
316
+ isOptional: true
317
+ }
318
+ }
319
+ });
320
+
321
+ // src/agent/agent.operation.ts
322
+ import {
323
+ defineCommand,
324
+ defineQuery
325
+ } from "@contractspec/lib.contracts-spec/operations";
326
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
327
+ var OWNERS2 = ["@agent-console-team"];
328
+ var CreateAgentCommand = defineCommand({
329
+ meta: {
330
+ key: "agent-console.agent.create",
331
+ version: "1.0.0",
332
+ stability: "stable",
333
+ owners: [...OWNERS2],
334
+ tags: ["agent", "create"],
335
+ description: "Creates a new AI agent configuration.",
336
+ goal: "Allow users to define new AI agents with specific models and tools.",
337
+ context: "Called from the agent builder UI when creating a new agent."
338
+ },
339
+ io: {
340
+ input: CreateAgentInputModel,
341
+ output: defineSchemaModel3({
342
+ name: "CreateAgentOutput",
343
+ fields: {
344
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
345
+ name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
346
+ slug: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
347
+ status: { type: AgentStatusEnum, isOptional: false }
348
+ }
349
+ }),
350
+ errors: {
351
+ SLUG_EXISTS: {
352
+ description: "An agent with this slug already exists in the organization",
353
+ http: 409,
354
+ gqlCode: "SLUG_EXISTS",
355
+ when: "Slug is already taken"
356
+ }
357
+ }
358
+ },
359
+ policy: { auth: "user" },
360
+ sideEffects: {
361
+ emits: [
362
+ {
363
+ ref: AgentCreatedEvent.meta,
364
+ when: "Agent is successfully created"
365
+ }
366
+ ],
367
+ audit: ["agent-console.agent.created"]
368
+ },
369
+ acceptance: {
370
+ scenarios: [
371
+ {
372
+ key: "create-agent-happy-path",
373
+ given: ["User is authenticated", "Organization exists"],
374
+ when: ["User submits valid agent configuration"],
375
+ then: [
376
+ "New agent is created with DRAFT status",
377
+ "AgentCreated event is emitted"
378
+ ]
379
+ },
380
+ {
381
+ key: "create-agent-slug-conflict",
382
+ given: ["User is authenticated", "Agent with same slug exists"],
383
+ when: ["User submits agent with duplicate slug"],
384
+ then: ["SLUG_EXISTS error is returned with 409 status"]
385
+ }
386
+ ],
387
+ examples: [
388
+ {
389
+ key: "basic-create",
390
+ input: {
391
+ name: "Support Assistant",
392
+ slug: "support-assistant",
393
+ modelProvider: "openai",
394
+ modelId: "gpt-4"
395
+ },
396
+ output: {
397
+ id: "agent-123",
398
+ name: "Support Assistant",
399
+ slug: "support-assistant",
400
+ status: "draft"
401
+ }
402
+ }
403
+ ]
404
+ }
405
+ });
406
+ var UpdateAgentCommand = defineCommand({
407
+ meta: {
408
+ key: "agent-console.agent.update",
409
+ version: "1.0.0",
410
+ stability: "stable",
411
+ owners: [...OWNERS2],
412
+ tags: ["agent", "update"],
413
+ description: "Updates an existing AI agent configuration.",
414
+ goal: "Allow users to modify agent settings and configuration.",
415
+ context: "Called from the agent settings UI."
416
+ },
417
+ io: {
418
+ input: UpdateAgentInputModel,
419
+ output: defineSchemaModel3({
420
+ name: "UpdateAgentOutput",
421
+ fields: {
422
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
423
+ name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
424
+ status: { type: AgentStatusEnum, isOptional: false },
425
+ updatedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
426
+ }
427
+ }),
428
+ errors: {
429
+ AGENT_NOT_FOUND: {
430
+ description: "The specified agent does not exist",
431
+ http: 404,
432
+ gqlCode: "AGENT_NOT_FOUND",
433
+ when: "Agent ID is invalid"
434
+ }
435
+ }
436
+ },
437
+ policy: { auth: "user" },
438
+ sideEffects: {
439
+ emits: [
440
+ {
441
+ key: "agent.updated",
442
+ version: "1.0.0",
443
+ stability: "stable",
444
+ owners: [...OWNERS2],
445
+ tags: ["agent", "updated"],
446
+ when: "Agent is updated",
447
+ payload: AgentSummaryModel
448
+ }
449
+ ],
450
+ audit: ["agent.updated"]
451
+ },
452
+ acceptance: {
453
+ scenarios: [
454
+ {
455
+ key: "update-agent-happy-path",
456
+ given: ["Agent exists", "User owns the agent"],
457
+ when: ["User submits updated configuration"],
458
+ then: ["Agent is updated", "AgentUpdated event is emitted"]
459
+ },
460
+ {
461
+ key: "update-agent-not-found",
462
+ given: ["Agent does not exist"],
463
+ when: ["User attempts to update"],
464
+ then: ["AGENT_NOT_FOUND error is returned"]
465
+ }
466
+ ],
467
+ examples: [
468
+ {
469
+ key: "update-name",
470
+ input: {
471
+ agentId: "agent-123",
472
+ name: "Updated Assistant",
473
+ systemPrompt: "You are a helpful assistant."
474
+ },
475
+ output: {
476
+ id: "agent-123",
477
+ name: "Updated Assistant",
478
+ status: "draft",
479
+ updatedAt: "2025-01-01T00:00:00Z"
480
+ }
481
+ }
482
+ ]
483
+ }
484
+ });
485
+ var GetAgentQuery = defineQuery({
486
+ meta: {
487
+ key: "agent-console.agent.get",
488
+ version: "1.0.0",
489
+ stability: "stable",
490
+ owners: [...OWNERS2],
491
+ tags: ["agent", "get"],
492
+ description: "Retrieves an agent by its ID.",
493
+ goal: "View detailed agent configuration.",
494
+ context: "Called when viewing agent details or editing."
495
+ },
496
+ io: {
497
+ input: defineSchemaModel3({
498
+ name: "GetAgentInput",
499
+ fields: {
500
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
501
+ includeTools: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
502
+ }
503
+ }),
504
+ output: AgentWithToolsModel,
505
+ errors: {
506
+ AGENT_NOT_FOUND: {
507
+ description: "The specified agent does not exist",
508
+ http: 404,
509
+ gqlCode: "AGENT_NOT_FOUND",
510
+ when: "Agent ID is invalid"
511
+ }
512
+ }
513
+ },
514
+ policy: { auth: "user" },
515
+ acceptance: {
516
+ scenarios: [
517
+ {
518
+ key: "get-agent-happy-path",
519
+ given: ["Agent exists"],
520
+ when: ["User requests agent by ID"],
521
+ then: ["Agent details are returned"]
522
+ },
523
+ {
524
+ key: "get-agent-with-tools",
525
+ given: ["Agent exists with assigned tools"],
526
+ when: ["User requests agent with includeTools=true"],
527
+ then: ["Agent details with tools list are returned"]
528
+ }
529
+ ],
530
+ examples: [
531
+ {
532
+ key: "get-basic",
533
+ input: { agentId: "agent-123", includeTools: false },
534
+ output: {
535
+ id: "agent-123",
536
+ name: "Support Assistant",
537
+ status: "active",
538
+ tools: []
539
+ }
540
+ }
541
+ ]
542
+ }
543
+ });
544
+ var ListAgentsQuery = defineQuery({
545
+ meta: {
546
+ key: "agent-console.agent.list",
547
+ version: "1.0.0",
548
+ stability: "stable",
549
+ owners: [...OWNERS2],
550
+ tags: ["agent", "list"],
551
+ description: "Lists agents for an organization with optional filtering.",
552
+ goal: "Browse and search available agents.",
553
+ context: "Agent list/dashboard view."
554
+ },
555
+ io: {
556
+ input: defineSchemaModel3({
557
+ name: "ListAgentsInput",
558
+ fields: {
559
+ organizationId: {
560
+ type: ScalarTypeEnum3.String_unsecure(),
561
+ isOptional: false
562
+ },
563
+ status: { type: AgentStatusEnum, isOptional: true },
564
+ modelProvider: { type: ModelProviderEnum, isOptional: true },
565
+ search: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
566
+ limit: {
567
+ type: ScalarTypeEnum3.Int_unsecure(),
568
+ isOptional: true,
569
+ defaultValue: 20
570
+ },
571
+ offset: {
572
+ type: ScalarTypeEnum3.Int_unsecure(),
573
+ isOptional: true,
574
+ defaultValue: 0
575
+ }
576
+ }
577
+ }),
578
+ output: defineSchemaModel3({
579
+ name: "ListAgentsOutput",
580
+ fields: {
581
+ items: { type: AgentSummaryModel, isArray: true, isOptional: false },
582
+ total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
583
+ hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
584
+ }
585
+ })
586
+ },
587
+ policy: { auth: "user" },
588
+ acceptance: {
589
+ scenarios: [
590
+ {
591
+ key: "list-agents-happy-path",
592
+ given: ["Organization has agents"],
593
+ when: ["User lists agents"],
594
+ then: ["Paginated list of agents is returned"]
595
+ },
596
+ {
597
+ key: "list-agents-filter-by-status",
598
+ given: ["Organization has agents with mixed statuses"],
599
+ when: ["User filters by status=active"],
600
+ then: ["Only active agents are returned"]
601
+ }
602
+ ],
603
+ examples: [
604
+ {
605
+ key: "list-basic",
606
+ input: { organizationId: "org-123", limit: 10, offset: 0 },
607
+ output: { items: [], total: 0, hasMore: false }
608
+ }
609
+ ]
610
+ }
611
+ });
612
+ var AssignToolToAgentCommand = defineCommand({
613
+ meta: {
614
+ key: "agent-console.agent.assignTool",
615
+ version: "1.0.0",
616
+ stability: "stable",
617
+ owners: [...OWNERS2],
618
+ tags: ["agent", "tool", "assign"],
619
+ description: "Assigns a tool to an agent with optional configuration.",
620
+ goal: "Enable agents to use specific tools.",
621
+ context: "Agent configuration UI - tool selection."
622
+ },
623
+ io: {
624
+ input: defineSchemaModel3({
625
+ name: "AssignToolToAgentInput",
626
+ fields: {
627
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
628
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
629
+ config: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
630
+ order: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true }
631
+ }
632
+ }),
633
+ output: defineSchemaModel3({
634
+ name: "AssignToolToAgentOutput",
635
+ fields: {
636
+ agentToolId: {
637
+ type: ScalarTypeEnum3.String_unsecure(),
638
+ isOptional: false
639
+ },
640
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
641
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
642
+ }
643
+ }),
644
+ errors: {
645
+ TOOL_ALREADY_ASSIGNED: {
646
+ description: "This tool is already assigned to the agent",
647
+ http: 409,
648
+ gqlCode: "TOOL_ALREADY_ASSIGNED",
649
+ when: "Tool assignment already exists"
650
+ }
651
+ }
652
+ },
653
+ policy: { auth: "user" },
654
+ sideEffects: { audit: ["agent.tool.assigned"] },
655
+ acceptance: {
656
+ scenarios: [
657
+ {
658
+ key: "assign-tool-happy-path",
659
+ given: ["Agent exists", "Tool exists and is not assigned"],
660
+ when: ["User assigns tool to agent"],
661
+ then: ["Tool is assigned", "Assignment ID is returned"]
662
+ },
663
+ {
664
+ key: "assign-tool-already-assigned",
665
+ given: ["Tool is already assigned to agent"],
666
+ when: ["User attempts to assign again"],
667
+ then: ["TOOL_ALREADY_ASSIGNED error is returned"]
668
+ }
669
+ ],
670
+ examples: [
671
+ {
672
+ key: "assign-basic",
673
+ input: { agentId: "agent-123", toolId: "tool-456" },
674
+ output: {
675
+ agentToolId: "at-789",
676
+ agentId: "agent-123",
677
+ toolId: "tool-456"
678
+ }
679
+ }
680
+ ]
681
+ }
682
+ });
683
+ var RemoveToolFromAgentCommand = defineCommand({
684
+ meta: {
685
+ key: "agent-console.agent.removeTool",
686
+ version: "1.0.0",
687
+ stability: "stable",
688
+ owners: [...OWNERS2],
689
+ tags: ["agent", "tool", "remove"],
690
+ description: "Removes a tool assignment from an agent.",
691
+ goal: "Disable specific tools for an agent.",
692
+ context: "Agent configuration UI - tool management."
693
+ },
694
+ io: {
695
+ input: defineSchemaModel3({
696
+ name: "RemoveToolFromAgentInput",
697
+ fields: {
698
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
699
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
700
+ }
701
+ }),
702
+ output: defineSchemaModel3({
703
+ name: "RemoveToolFromAgentOutput",
704
+ fields: {
705
+ success: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
706
+ }
707
+ })
708
+ },
709
+ policy: { auth: "user" },
710
+ sideEffects: { audit: ["agent.tool.removed"] },
711
+ acceptance: {
712
+ scenarios: [
713
+ {
714
+ key: "remove-tool-happy-path",
715
+ given: ["Agent exists", "Tool is assigned to agent"],
716
+ when: ["User removes tool from agent"],
717
+ then: ["Tool is unassigned", "Success is returned"]
718
+ }
719
+ ],
720
+ examples: [
721
+ {
722
+ key: "remove-basic",
723
+ input: { agentId: "agent-123", toolId: "tool-456" },
724
+ output: { success: true }
725
+ }
726
+ ]
727
+ }
728
+ });
729
+
730
+ // src/run/run.enum.ts
731
+ import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
732
+ var RunStatusEnum = defineEnum2("RunStatus", [
733
+ "QUEUED",
734
+ "IN_PROGRESS",
735
+ "COMPLETED",
736
+ "FAILED",
737
+ "CANCELLED",
738
+ "EXPIRED"
739
+ ]);
740
+ var RunStepTypeEnum = defineEnum2("RunStepType", [
741
+ "MESSAGE_CREATION",
742
+ "TOOL_CALL",
743
+ "TOOL_RESULT",
744
+ "ERROR"
745
+ ]);
746
+ var LogLevelEnum = defineEnum2("LogLevel", [
747
+ "DEBUG",
748
+ "INFO",
749
+ "WARN",
750
+ "ERROR"
751
+ ]);
752
+ var GranularityEnum = defineEnum2("Granularity", [
753
+ "hour",
754
+ "day",
755
+ "week",
756
+ "month"
757
+ ]);
758
+
759
+ // src/run/run.schema.ts
760
+ import { defineSchemaModel as defineSchemaModel4, ScalarTypeEnum as ScalarTypeEnum4 } from "@contractspec/lib.schema";
761
+ var RunInputModel = defineSchemaModel4({
762
+ name: "RunInput",
763
+ description: "Input data for agent execution",
764
+ fields: {
765
+ message: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
766
+ context: { type: ScalarTypeEnum4.JSONObject(), isOptional: true }
767
+ }
768
+ });
769
+ var RunStepModel = defineSchemaModel4({
770
+ name: "RunStep",
771
+ description: "Individual step within a run",
772
+ fields: {
773
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
774
+ stepNumber: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
775
+ type: { type: RunStepTypeEnum, isOptional: false },
776
+ toolId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
777
+ toolName: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
778
+ input: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
779
+ output: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
780
+ status: { type: RunStatusEnum, isOptional: false },
781
+ errorMessage: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
782
+ tokensUsed: {
783
+ type: ScalarTypeEnum4.Int_unsecure(),
784
+ isOptional: false,
785
+ defaultValue: 0
786
+ },
787
+ durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
788
+ startedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
789
+ completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true }
790
+ }
791
+ });
792
+ var RunLogModel = defineSchemaModel4({
793
+ name: "RunLog",
794
+ description: "Execution log entry",
795
+ fields: {
796
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
797
+ stepId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
798
+ level: { type: LogLevelEnum, isOptional: false },
799
+ message: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
800
+ data: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
801
+ source: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
802
+ traceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
803
+ spanId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
804
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
805
+ }
806
+ });
807
+ var RunAgentRefModel = defineSchemaModel4({
808
+ name: "RunAgentRef",
809
+ description: "Agent reference in a run",
810
+ fields: {
811
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
812
+ name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
813
+ modelProvider: {
814
+ type: ScalarTypeEnum4.String_unsecure(),
815
+ isOptional: false
816
+ },
817
+ modelName: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false }
818
+ }
819
+ });
820
+ var RunModel = defineSchemaModel4({
821
+ name: "Run",
822
+ description: "Agent execution instance",
823
+ fields: {
824
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
825
+ organizationId: {
826
+ type: ScalarTypeEnum4.String_unsecure(),
827
+ isOptional: false
828
+ },
829
+ agentId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
830
+ userId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
831
+ sessionId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
832
+ input: { type: ScalarTypeEnum4.JSONObject(), isOptional: false },
833
+ output: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
834
+ status: { type: RunStatusEnum, isOptional: false },
835
+ errorMessage: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
836
+ errorCode: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
837
+ totalTokens: {
838
+ type: ScalarTypeEnum4.Int_unsecure(),
839
+ isOptional: false,
840
+ defaultValue: 0
841
+ },
842
+ promptTokens: {
843
+ type: ScalarTypeEnum4.Int_unsecure(),
844
+ isOptional: false,
845
+ defaultValue: 0
846
+ },
847
+ completionTokens: {
848
+ type: ScalarTypeEnum4.Int_unsecure(),
849
+ isOptional: false,
850
+ defaultValue: 0
851
+ },
852
+ totalIterations: {
853
+ type: ScalarTypeEnum4.Int_unsecure(),
854
+ isOptional: false,
855
+ defaultValue: 0
856
+ },
857
+ durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
858
+ estimatedCostUsd: {
859
+ type: ScalarTypeEnum4.Float_unsecure(),
860
+ isOptional: true
861
+ },
862
+ queuedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
863
+ startedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true },
864
+ completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true },
865
+ metadata: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
866
+ steps: { type: RunStepModel, isArray: true, isOptional: true },
867
+ logs: { type: RunLogModel, isArray: true, isOptional: true },
868
+ agent: { type: RunAgentRefModel, isOptional: true }
869
+ }
870
+ });
871
+ var RunSummaryModel = defineSchemaModel4({
872
+ name: "RunSummary",
873
+ description: "Summary of a run for list views",
874
+ fields: {
875
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
876
+ agentId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
877
+ agentName: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
878
+ status: { type: RunStatusEnum, isOptional: false },
879
+ totalTokens: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
880
+ durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
881
+ estimatedCostUsd: {
882
+ type: ScalarTypeEnum4.Float_unsecure(),
883
+ isOptional: true
884
+ },
885
+ queuedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
886
+ completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true }
887
+ }
888
+ });
889
+ var TimelineDataPointModel = defineSchemaModel4({
890
+ name: "TimelineDataPoint",
891
+ description: "Timeline data point for metrics",
892
+ fields: {
893
+ period: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
894
+ runs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
895
+ tokens: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
896
+ costUsd: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false },
897
+ avgDurationMs: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false }
898
+ }
899
+ });
900
+
901
+ // src/run/run.operation.ts
902
+ import {
903
+ defineCommand as defineCommand2,
904
+ defineQuery as defineQuery2
905
+ } from "@contractspec/lib.contracts-spec/operations";
906
+ import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
907
+ var OWNERS3 = ["@agent-console-team"];
908
+ var ExecuteAgentCommand = defineCommand2({
909
+ meta: {
910
+ key: "agent.run.execute",
911
+ version: "1.0.0",
912
+ stability: "stable",
913
+ owners: [...OWNERS3],
914
+ tags: ["run", "execute"],
915
+ description: "Starts a new agent run with the given input.",
916
+ goal: "Execute an AI agent with user input.",
917
+ context: "Called from chat interface or API."
918
+ },
919
+ io: {
920
+ input: defineSchemaModel5({
921
+ name: "ExecuteAgentInput",
922
+ fields: {
923
+ agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
924
+ input: { type: RunInputModel, isOptional: false },
925
+ sessionId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
926
+ metadata: { type: ScalarTypeEnum5.JSONObject(), isOptional: true },
927
+ stream: { type: ScalarTypeEnum5.Boolean(), isOptional: true },
928
+ maxIterations: {
929
+ type: ScalarTypeEnum5.Int_unsecure(),
930
+ isOptional: true
931
+ },
932
+ timeoutMs: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: true }
933
+ }
934
+ }),
935
+ output: defineSchemaModel5({
936
+ name: "ExecuteAgentOutput",
937
+ fields: {
938
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
939
+ status: { type: RunStatusEnum, isOptional: false },
940
+ estimatedWaitMs: {
941
+ type: ScalarTypeEnum5.Int_unsecure(),
942
+ isOptional: true
943
+ }
944
+ }
945
+ }),
946
+ errors: {
947
+ AGENT_NOT_FOUND: {
948
+ description: "The specified agent does not exist",
949
+ http: 404,
950
+ gqlCode: "AGENT_NOT_FOUND",
951
+ when: "Agent ID is invalid"
952
+ },
953
+ AGENT_NOT_ACTIVE: {
954
+ description: "The specified agent is not active",
955
+ http: 400,
956
+ gqlCode: "AGENT_NOT_ACTIVE",
957
+ when: "Agent is in draft/paused/archived state"
958
+ }
959
+ }
960
+ },
961
+ policy: { auth: "user" },
962
+ sideEffects: {
963
+ emits: [
964
+ {
965
+ key: "run.started",
966
+ version: "1.0.0",
967
+ stability: "stable",
968
+ owners: [...OWNERS3],
969
+ tags: ["run", "started"],
970
+ when: "Run is queued",
971
+ payload: RunSummaryModel
972
+ }
973
+ ],
974
+ audit: ["run.started"]
975
+ },
976
+ acceptance: {
977
+ scenarios: [
978
+ {
979
+ key: "execute-agent-happy-path",
980
+ given: ["Agent exists", "Agent is active"],
981
+ when: ["User submits execution request"],
982
+ then: ["Run is created", "RunStarted event is emitted"]
983
+ },
984
+ {
985
+ key: "execute-agent-not-active",
986
+ given: ["Agent exists but is not active"],
987
+ when: ["User attempts to execute"],
988
+ then: ["AGENT_NOT_ACTIVE error is returned"]
989
+ }
990
+ ],
991
+ examples: [
992
+ {
993
+ key: "basic-execute",
994
+ input: { agentId: "agent-123", input: { message: "Hello" } },
995
+ output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
996
+ }
997
+ ]
998
+ }
999
+ });
1000
+ var CancelRunCommand = defineCommand2({
1001
+ meta: {
1002
+ key: "agent.run.cancel",
1003
+ version: "1.0.0",
1004
+ stability: "stable",
1005
+ owners: [...OWNERS3],
1006
+ tags: ["run", "cancel"],
1007
+ description: "Cancels an in-progress agent run.",
1008
+ goal: "Stop a running agent execution.",
1009
+ context: "Called when user wants to abort a long-running task."
1010
+ },
1011
+ io: {
1012
+ input: defineSchemaModel5({
1013
+ name: "CancelRunInput",
1014
+ fields: {
1015
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1016
+ reason: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
1017
+ }
1018
+ }),
1019
+ output: defineSchemaModel5({
1020
+ name: "CancelRunOutput",
1021
+ fields: {
1022
+ success: { type: ScalarTypeEnum5.Boolean(), isOptional: false },
1023
+ status: { type: RunStatusEnum, isOptional: false }
1024
+ }
1025
+ }),
1026
+ errors: {
1027
+ RUN_NOT_FOUND: {
1028
+ description: "The specified run does not exist",
1029
+ http: 404,
1030
+ gqlCode: "RUN_NOT_FOUND",
1031
+ when: "Run ID is invalid"
1032
+ },
1033
+ RUN_NOT_CANCELLABLE: {
1034
+ description: "The run cannot be cancelled",
1035
+ http: 400,
1036
+ gqlCode: "RUN_NOT_CANCELLABLE",
1037
+ when: "Run is already completed/failed/cancelled"
1038
+ }
1039
+ }
1040
+ },
1041
+ policy: { auth: "user" },
1042
+ sideEffects: {
1043
+ emits: [
1044
+ {
1045
+ key: "run.cancelled",
1046
+ version: "1.0.0",
1047
+ stability: "stable",
1048
+ owners: [...OWNERS3],
1049
+ tags: ["run", "cancelled"],
1050
+ when: "Run is cancelled",
1051
+ payload: RunSummaryModel
1052
+ }
1053
+ ],
1054
+ audit: ["run.cancelled"]
1055
+ },
1056
+ acceptance: {
1057
+ scenarios: [
1058
+ {
1059
+ key: "cancel-run-happy-path",
1060
+ given: ["Run exists", "Run is in progress"],
1061
+ when: ["User cancels run"],
1062
+ then: ["Run is cancelled", "RunCancelled event is emitted"]
1063
+ },
1064
+ {
1065
+ key: "cancel-run-already-completed",
1066
+ given: ["Run exists but is already completed"],
1067
+ when: ["User attempts to cancel"],
1068
+ then: ["RUN_NOT_CANCELLABLE error is returned"]
1069
+ }
1070
+ ],
1071
+ examples: [
1072
+ {
1073
+ key: "cancel-basic",
1074
+ input: { runId: "run-456", reason: "User requested" },
1075
+ output: { success: true, status: "cancelled" }
1076
+ }
1077
+ ]
1078
+ }
1079
+ });
1080
+ var GetRunQuery = defineQuery2({
1081
+ meta: {
1082
+ key: "agent.run.get",
1083
+ version: "1.0.0",
1084
+ stability: "stable",
1085
+ owners: [...OWNERS3],
1086
+ tags: ["run", "get"],
1087
+ description: "Retrieves a run by its ID with optional details.",
1088
+ goal: "View detailed run information.",
1089
+ context: "Run details page or monitoring."
1090
+ },
1091
+ io: {
1092
+ input: defineSchemaModel5({
1093
+ name: "GetRunInput",
1094
+ fields: {
1095
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1096
+ includeSteps: { type: ScalarTypeEnum5.Boolean(), isOptional: true },
1097
+ includeLogs: { type: ScalarTypeEnum5.Boolean(), isOptional: true }
1098
+ }
1099
+ }),
1100
+ output: RunModel,
1101
+ errors: {
1102
+ RUN_NOT_FOUND: {
1103
+ description: "The specified run does not exist",
1104
+ http: 404,
1105
+ gqlCode: "RUN_NOT_FOUND",
1106
+ when: "Run ID is invalid"
1107
+ }
1108
+ }
1109
+ },
1110
+ policy: { auth: "user" },
1111
+ acceptance: {
1112
+ scenarios: [
1113
+ {
1114
+ key: "get-run-happy-path",
1115
+ given: ["Run exists"],
1116
+ when: ["User requests run by ID"],
1117
+ then: ["Run details are returned"]
1118
+ }
1119
+ ],
1120
+ examples: [
1121
+ {
1122
+ key: "get-with-steps",
1123
+ input: { runId: "run-456", includeSteps: true, includeLogs: false },
1124
+ output: { id: "run-456", status: "completed", steps: [] }
1125
+ }
1126
+ ]
1127
+ }
1128
+ });
1129
+ var ListRunsQuery = defineQuery2({
1130
+ meta: {
1131
+ key: "agent.run.list",
1132
+ version: "1.0.0",
1133
+ stability: "stable",
1134
+ owners: [...OWNERS3],
1135
+ tags: ["run", "list"],
1136
+ description: "Lists runs with optional filtering.",
1137
+ goal: "Browse and search run history.",
1138
+ context: "Run history/dashboard view."
1139
+ },
1140
+ io: {
1141
+ input: defineSchemaModel5({
1142
+ name: "ListRunsInput",
1143
+ fields: {
1144
+ organizationId: {
1145
+ type: ScalarTypeEnum5.String_unsecure(),
1146
+ isOptional: true
1147
+ },
1148
+ agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1149
+ userId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1150
+ sessionId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1151
+ status: { type: RunStatusEnum, isOptional: true },
1152
+ startDate: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
1153
+ endDate: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
1154
+ limit: {
1155
+ type: ScalarTypeEnum5.Int_unsecure(),
1156
+ isOptional: true,
1157
+ defaultValue: 20
1158
+ },
1159
+ offset: {
1160
+ type: ScalarTypeEnum5.Int_unsecure(),
1161
+ isOptional: true,
1162
+ defaultValue: 0
1163
+ }
1164
+ }
1165
+ }),
1166
+ output: defineSchemaModel5({
1167
+ name: "ListRunsOutput",
1168
+ fields: {
1169
+ items: { type: RunSummaryModel, isArray: true, isOptional: false },
1170
+ total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1171
+ hasMore: { type: ScalarTypeEnum5.Boolean(), isOptional: false }
1172
+ }
1173
+ })
1174
+ },
1175
+ policy: { auth: "user" },
1176
+ acceptance: {
1177
+ scenarios: [
1178
+ {
1179
+ key: "list-runs-happy-path",
1180
+ given: ["Organization has runs"],
1181
+ when: ["User lists runs"],
1182
+ then: ["Paginated list of runs is returned"]
1183
+ }
1184
+ ],
1185
+ examples: [
1186
+ {
1187
+ key: "list-by-agent",
1188
+ input: { agentId: "agent-123", limit: 20, offset: 0 },
1189
+ output: { items: [], total: 0, hasMore: false }
1190
+ }
1191
+ ]
1192
+ }
1193
+ });
1194
+ var GetRunStepsQuery = defineQuery2({
1195
+ meta: {
1196
+ key: "agent.run.getSteps",
1197
+ version: "1.0.0",
1198
+ stability: "stable",
1199
+ owners: [...OWNERS3],
1200
+ tags: ["run", "steps"],
1201
+ description: "Retrieves all steps for a specific run.",
1202
+ goal: "View step-by-step execution details.",
1203
+ context: "Run details page - steps tab."
1204
+ },
1205
+ io: {
1206
+ input: defineSchemaModel5({
1207
+ name: "GetRunStepsInput",
1208
+ fields: {
1209
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false }
1210
+ }
1211
+ }),
1212
+ output: defineSchemaModel5({
1213
+ name: "GetRunStepsOutput",
1214
+ fields: {
1215
+ steps: { type: RunStepModel, isArray: true, isOptional: false }
1216
+ }
1217
+ })
1218
+ },
1219
+ policy: { auth: "user" },
1220
+ acceptance: {
1221
+ scenarios: [
1222
+ {
1223
+ key: "get-run-steps-happy-path",
1224
+ given: ["Run exists with steps"],
1225
+ when: ["User requests steps"],
1226
+ then: ["Steps list is returned"]
1227
+ }
1228
+ ],
1229
+ examples: [
1230
+ {
1231
+ key: "get-steps-basic",
1232
+ input: { runId: "run-456" },
1233
+ output: { steps: [] }
1234
+ }
1235
+ ]
1236
+ }
1237
+ });
1238
+ var GetRunLogsQuery = defineQuery2({
1239
+ meta: {
1240
+ key: "agent.run.getLogs",
1241
+ version: "1.0.0",
1242
+ stability: "stable",
1243
+ owners: [...OWNERS3],
1244
+ tags: ["run", "logs"],
1245
+ description: "Retrieves all logs for a specific run.",
1246
+ goal: "Debug and audit run execution.",
1247
+ context: "Run details page - logs tab."
1248
+ },
1249
+ io: {
1250
+ input: defineSchemaModel5({
1251
+ name: "GetRunLogsInput",
1252
+ fields: {
1253
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1254
+ level: { type: LogLevelEnum, isOptional: true },
1255
+ stepId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1256
+ limit: {
1257
+ type: ScalarTypeEnum5.Int_unsecure(),
1258
+ isOptional: true,
1259
+ defaultValue: 100
1260
+ },
1261
+ offset: {
1262
+ type: ScalarTypeEnum5.Int_unsecure(),
1263
+ isOptional: true,
1264
+ defaultValue: 0
1265
+ }
1266
+ }
1267
+ }),
1268
+ output: defineSchemaModel5({
1269
+ name: "GetRunLogsOutput",
1270
+ fields: {
1271
+ items: { type: RunLogModel, isArray: true, isOptional: false },
1272
+ total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1273
+ hasMore: { type: ScalarTypeEnum5.Boolean(), isOptional: false }
1274
+ }
1275
+ })
1276
+ },
1277
+ policy: { auth: "user" },
1278
+ acceptance: {
1279
+ scenarios: [
1280
+ {
1281
+ key: "get-run-logs-happy-path",
1282
+ given: ["Run exists with logs"],
1283
+ when: ["User requests logs"],
1284
+ then: ["Paginated logs list is returned"]
1285
+ }
1286
+ ],
1287
+ examples: [
1288
+ {
1289
+ key: "get-logs-filtered",
1290
+ input: { runId: "run-456", level: "error", limit: 50 },
1291
+ output: { items: [], total: 0, hasMore: false }
1292
+ }
1293
+ ]
1294
+ }
1295
+ });
1296
+ var GetRunMetricsQuery = defineQuery2({
1297
+ meta: {
1298
+ key: "agent.run.getMetrics",
1299
+ version: "1.0.0",
1300
+ stability: "stable",
1301
+ owners: [...OWNERS3],
1302
+ tags: ["run", "metrics"],
1303
+ description: "Retrieves aggregated metrics for runs within a time period.",
1304
+ goal: "Monitor and analyze agent usage.",
1305
+ context: "Analytics dashboard."
1306
+ },
1307
+ io: {
1308
+ input: defineSchemaModel5({
1309
+ name: "GetRunMetricsInput",
1310
+ fields: {
1311
+ organizationId: {
1312
+ type: ScalarTypeEnum5.String_unsecure(),
1313
+ isOptional: false
1314
+ },
1315
+ agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1316
+ startDate: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
1317
+ endDate: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
1318
+ granularity: {
1319
+ type: GranularityEnum,
1320
+ isOptional: true,
1321
+ defaultValue: "day"
1322
+ }
1323
+ }
1324
+ }),
1325
+ output: defineSchemaModel5({
1326
+ name: "GetRunMetricsOutput",
1327
+ fields: {
1328
+ totalRuns: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1329
+ completedRuns: {
1330
+ type: ScalarTypeEnum5.Int_unsecure(),
1331
+ isOptional: false
1332
+ },
1333
+ failedRuns: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1334
+ totalTokens: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1335
+ totalCostUsd: {
1336
+ type: ScalarTypeEnum5.Float_unsecure(),
1337
+ isOptional: false
1338
+ },
1339
+ averageDurationMs: {
1340
+ type: ScalarTypeEnum5.Float_unsecure(),
1341
+ isOptional: false
1342
+ },
1343
+ successRate: {
1344
+ type: ScalarTypeEnum5.Float_unsecure(),
1345
+ isOptional: false
1346
+ },
1347
+ timeline: {
1348
+ type: TimelineDataPointModel,
1349
+ isArray: true,
1350
+ isOptional: false
1351
+ }
1352
+ }
1353
+ })
1354
+ },
1355
+ policy: { auth: "user" },
1356
+ acceptance: {
1357
+ scenarios: [
1358
+ {
1359
+ key: "get-run-metrics-happy-path",
1360
+ given: ["Organization has run history"],
1361
+ when: ["User requests metrics for date range"],
1362
+ then: ["Aggregated metrics are returned"]
1363
+ }
1364
+ ],
1365
+ examples: [
1366
+ {
1367
+ key: "get-daily-metrics",
1368
+ input: {
1369
+ organizationId: "org-123",
1370
+ startDate: "2025-01-01",
1371
+ endDate: "2025-01-31",
1372
+ granularity: "day"
1373
+ },
1374
+ output: {
1375
+ totalRuns: 100,
1376
+ completedRuns: 90,
1377
+ failedRuns: 10,
1378
+ totalTokens: 50000,
1379
+ totalCostUsd: 5,
1380
+ averageDurationMs: 2500,
1381
+ successRate: 0.9,
1382
+ timeline: []
1383
+ }
1384
+ }
1385
+ ]
1386
+ }
1387
+ });
1388
+
1389
+ // src/tool/tool.enum.ts
1390
+ import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
1391
+ var ToolCategoryEnum = defineEnum3("ToolCategory", [
1392
+ "RETRIEVAL",
1393
+ "COMPUTATION",
1394
+ "COMMUNICATION",
1395
+ "INTEGRATION",
1396
+ "UTILITY",
1397
+ "CUSTOM"
1398
+ ]);
1399
+ var ToolStatusEnum = defineEnum3("ToolStatus", [
1400
+ "DRAFT",
1401
+ "ACTIVE",
1402
+ "DEPRECATED",
1403
+ "DISABLED"
1404
+ ]);
1405
+ var ImplementationTypeEnum = defineEnum3("ImplementationType", [
1406
+ "http",
1407
+ "function",
1408
+ "workflow"
1409
+ ]);
1410
+
1411
+ // src/tool/tool.schema.ts
1412
+ import { defineSchemaModel as defineSchemaModel6, ScalarTypeEnum as ScalarTypeEnum6 } from "@contractspec/lib.schema";
1413
+ var ToolModel = defineSchemaModel6({
1414
+ name: "Tool",
1415
+ description: "AI tool definition",
1416
+ fields: {
1417
+ id: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1418
+ organizationId: {
1419
+ type: ScalarTypeEnum6.String_unsecure(),
1420
+ isOptional: false
1421
+ },
1422
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1423
+ slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1424
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1425
+ category: { type: ToolCategoryEnum, isOptional: false },
1426
+ status: { type: ToolStatusEnum, isOptional: false },
1427
+ parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: false },
1428
+ outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1429
+ implementationType: { type: ImplementationTypeEnum, isOptional: false },
1430
+ implementationConfig: {
1431
+ type: ScalarTypeEnum6.JSONObject(),
1432
+ isOptional: false
1433
+ },
1434
+ maxInvocationsPerMinute: {
1435
+ type: ScalarTypeEnum6.Int_unsecure(),
1436
+ isOptional: true
1437
+ },
1438
+ timeoutMs: {
1439
+ type: ScalarTypeEnum6.Int_unsecure(),
1440
+ isOptional: false,
1441
+ defaultValue: 30000
1442
+ },
1443
+ version: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1444
+ tags: {
1445
+ type: ScalarTypeEnum6.String_unsecure(),
1446
+ isArray: true,
1447
+ isOptional: true
1448
+ },
1449
+ createdAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false },
1450
+ updatedAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1451
+ }
1452
+ });
1453
+ var ToolSummaryModel = defineSchemaModel6({
1454
+ name: "ToolSummary",
1455
+ description: "Summary of a tool for list views",
1456
+ fields: {
1457
+ id: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1458
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1459
+ slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1460
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1461
+ category: { type: ToolCategoryEnum, isOptional: false },
1462
+ status: { type: ToolStatusEnum, isOptional: false },
1463
+ version: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1464
+ createdAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1465
+ }
1466
+ });
1467
+ var CreateToolInputModel = defineSchemaModel6({
1468
+ name: "CreateToolInput",
1469
+ description: "Input for creating a tool",
1470
+ fields: {
1471
+ organizationId: {
1472
+ type: ScalarTypeEnum6.String_unsecure(),
1473
+ isOptional: false
1474
+ },
1475
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1476
+ slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1477
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1478
+ category: { type: ToolCategoryEnum, isOptional: true },
1479
+ parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: false },
1480
+ outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1481
+ implementationType: { type: ImplementationTypeEnum, isOptional: false },
1482
+ implementationConfig: {
1483
+ type: ScalarTypeEnum6.JSONObject(),
1484
+ isOptional: false
1485
+ },
1486
+ maxInvocationsPerMinute: {
1487
+ type: ScalarTypeEnum6.Int_unsecure(),
1488
+ isOptional: true
1489
+ },
1490
+ timeoutMs: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: true },
1491
+ tags: {
1492
+ type: ScalarTypeEnum6.String_unsecure(),
1493
+ isArray: true,
1494
+ isOptional: true
1495
+ }
1496
+ }
1497
+ });
1498
+ var UpdateToolInputModel = defineSchemaModel6({
1499
+ name: "UpdateToolInput",
1500
+ description: "Input for updating a tool",
1501
+ fields: {
1502
+ toolId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1503
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: true },
1504
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true },
1505
+ status: { type: ToolStatusEnum, isOptional: true },
1506
+ parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1507
+ outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1508
+ implementationConfig: {
1509
+ type: ScalarTypeEnum6.JSONObject(),
1510
+ isOptional: true
1511
+ },
1512
+ maxInvocationsPerMinute: {
1513
+ type: ScalarTypeEnum6.Int_unsecure(),
1514
+ isOptional: true
1515
+ },
1516
+ timeoutMs: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: true },
1517
+ tags: {
1518
+ type: ScalarTypeEnum6.String_unsecure(),
1519
+ isArray: true,
1520
+ isOptional: true
1521
+ }
1522
+ }
1523
+ });
1524
+
1525
+ // src/tool/tool.operation.ts
1526
+ import {
1527
+ defineCommand as defineCommand3,
1528
+ defineQuery as defineQuery3
1529
+ } from "@contractspec/lib.contracts-spec/operations";
1530
+ import { defineSchemaModel as defineSchemaModel7, ScalarTypeEnum as ScalarTypeEnum7 } from "@contractspec/lib.schema";
1531
+ var OWNERS4 = ["@agent-console-team"];
1532
+ var CreateToolCommand = defineCommand3({
1533
+ meta: {
1534
+ key: "agent.tool.create",
1535
+ version: "1.0.0",
1536
+ stability: "stable",
1537
+ owners: [...OWNERS4],
1538
+ tags: ["tool", "create"],
1539
+ description: "Creates a new AI tool definition.",
1540
+ goal: "Allow users to define new tools that agents can use.",
1541
+ context: "Called from the tool builder UI when creating a new tool."
1542
+ },
1543
+ io: {
1544
+ input: CreateToolInputModel,
1545
+ output: defineSchemaModel7({
1546
+ name: "CreateToolOutput",
1547
+ fields: {
1548
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1549
+ name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1550
+ slug: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1551
+ status: { type: ToolStatusEnum, isOptional: false }
1552
+ }
1553
+ }),
1554
+ errors: {
1555
+ SLUG_EXISTS: {
1556
+ description: "A tool with this slug already exists in the organization",
1557
+ http: 409,
1558
+ gqlCode: "SLUG_EXISTS",
1559
+ when: "Slug is already taken"
1560
+ }
1561
+ }
1562
+ },
1563
+ policy: { auth: "user" },
1564
+ sideEffects: {
1565
+ emits: [
1566
+ {
1567
+ key: "tool.created",
1568
+ version: "1.0.0",
1569
+ stability: "stable",
1570
+ owners: [...OWNERS4],
1571
+ tags: ["tool", "created"],
1572
+ when: "Tool is successfully created",
1573
+ payload: ToolSummaryModel
1574
+ }
1575
+ ],
1576
+ audit: ["tool.created"]
1577
+ },
1578
+ acceptance: {
1579
+ scenarios: [
1580
+ {
1581
+ key: "create-tool-happy-path",
1582
+ given: ["User is authenticated", "Organization exists"],
1583
+ when: ["User submits valid tool configuration"],
1584
+ then: ["New tool is created", "ToolCreated event is emitted"]
1585
+ },
1586
+ {
1587
+ key: "create-tool-slug-conflict",
1588
+ given: ["Tool with same slug exists"],
1589
+ when: ["User submits tool with duplicate slug"],
1590
+ then: ["SLUG_EXISTS error is returned"]
1591
+ }
1592
+ ],
1593
+ examples: [
1594
+ {
1595
+ key: "create-api-tool",
1596
+ input: {
1597
+ name: "Weather API",
1598
+ slug: "weather-api",
1599
+ category: "api",
1600
+ description: "Fetches weather data"
1601
+ },
1602
+ output: {
1603
+ id: "tool-123",
1604
+ name: "Weather API",
1605
+ slug: "weather-api",
1606
+ status: "draft"
1607
+ }
1608
+ }
1609
+ ]
1610
+ }
1611
+ });
1612
+ var UpdateToolCommand = defineCommand3({
1613
+ meta: {
1614
+ key: "agent.tool.update",
1615
+ version: "1.0.0",
1616
+ stability: "stable",
1617
+ owners: [...OWNERS4],
1618
+ tags: ["tool", "update"],
1619
+ description: "Updates an existing AI tool definition.",
1620
+ goal: "Allow users to modify tool settings and configuration.",
1621
+ context: "Called from the tool settings UI."
1622
+ },
1623
+ io: {
1624
+ input: UpdateToolInputModel,
1625
+ output: defineSchemaModel7({
1626
+ name: "UpdateToolOutput",
1627
+ fields: {
1628
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1629
+ name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1630
+ status: { type: ToolStatusEnum, isOptional: false },
1631
+ updatedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false }
1632
+ }
1633
+ }),
1634
+ errors: {
1635
+ TOOL_NOT_FOUND: {
1636
+ description: "The specified tool does not exist",
1637
+ http: 404,
1638
+ gqlCode: "TOOL_NOT_FOUND",
1639
+ when: "Tool ID is invalid"
1640
+ }
1641
+ }
1642
+ },
1643
+ policy: { auth: "user" },
1644
+ sideEffects: {
1645
+ emits: [
1646
+ {
1647
+ key: "tool.updated",
1648
+ version: "1.0.0",
1649
+ stability: "stable",
1650
+ owners: [...OWNERS4],
1651
+ tags: ["tool", "updated"],
1652
+ when: "Tool is updated",
1653
+ payload: ToolSummaryModel
1654
+ }
1655
+ ],
1656
+ audit: ["tool.updated"]
1657
+ },
1658
+ acceptance: {
1659
+ scenarios: [
1660
+ {
1661
+ key: "update-tool-happy-path",
1662
+ given: ["Tool exists", "User owns the tool"],
1663
+ when: ["User submits updated configuration"],
1664
+ then: ["Tool is updated", "ToolUpdated event is emitted"]
1665
+ }
1666
+ ],
1667
+ examples: [
1668
+ {
1669
+ key: "update-description",
1670
+ input: { toolId: "tool-123", description: "Updated weather API tool" },
1671
+ output: {
1672
+ id: "tool-123",
1673
+ name: "Weather API",
1674
+ status: "draft",
1675
+ updatedAt: "2025-01-01T00:00:00Z"
1676
+ }
1677
+ }
1678
+ ]
1679
+ }
1680
+ });
1681
+ var GetToolQuery = defineQuery3({
1682
+ meta: {
1683
+ key: "agent.tool.get",
1684
+ version: "1.0.0",
1685
+ stability: "stable",
1686
+ owners: [...OWNERS4],
1687
+ tags: ["tool", "get"],
1688
+ description: "Retrieves a tool by its ID.",
1689
+ goal: "View detailed tool configuration.",
1690
+ context: "Called when viewing tool details or editing."
1691
+ },
1692
+ io: {
1693
+ input: defineSchemaModel7({
1694
+ name: "GetToolInput",
1695
+ fields: {
1696
+ toolId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false }
1697
+ }
1698
+ }),
1699
+ output: ToolModel,
1700
+ errors: {
1701
+ TOOL_NOT_FOUND: {
1702
+ description: "The specified tool does not exist",
1703
+ http: 404,
1704
+ gqlCode: "TOOL_NOT_FOUND",
1705
+ when: "Tool ID is invalid"
1706
+ }
1707
+ }
1708
+ },
1709
+ policy: { auth: "user" },
1710
+ acceptance: {
1711
+ scenarios: [
1712
+ {
1713
+ key: "get-tool-happy-path",
1714
+ given: ["Tool exists"],
1715
+ when: ["User requests tool by ID"],
1716
+ then: ["Tool details are returned"]
1717
+ }
1718
+ ],
1719
+ examples: [
1720
+ {
1721
+ key: "get-basic",
1722
+ input: { toolId: "tool-123" },
1723
+ output: {
1724
+ id: "tool-123",
1725
+ name: "Weather API",
1726
+ status: "active",
1727
+ category: "api"
1728
+ }
1729
+ }
1730
+ ]
1731
+ }
1732
+ });
1733
+ var ListToolsQuery = defineQuery3({
1734
+ meta: {
1735
+ key: "agent.tool.list",
1736
+ version: "1.0.0",
1737
+ stability: "stable",
1738
+ owners: [...OWNERS4],
1739
+ tags: ["tool", "list"],
1740
+ description: "Lists tools for an organization with optional filtering.",
1741
+ goal: "Browse and search available tools.",
1742
+ context: "Tool list/dashboard view."
1743
+ },
1744
+ io: {
1745
+ input: defineSchemaModel7({
1746
+ name: "ListToolsInput",
1747
+ fields: {
1748
+ organizationId: {
1749
+ type: ScalarTypeEnum7.String_unsecure(),
1750
+ isOptional: false
1751
+ },
1752
+ category: { type: ToolCategoryEnum, isOptional: true },
1753
+ status: { type: ToolStatusEnum, isOptional: true },
1754
+ search: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1755
+ limit: {
1756
+ type: ScalarTypeEnum7.Int_unsecure(),
1757
+ isOptional: true,
1758
+ defaultValue: 20
1759
+ },
1760
+ offset: {
1761
+ type: ScalarTypeEnum7.Int_unsecure(),
1762
+ isOptional: true,
1763
+ defaultValue: 0
1764
+ }
1765
+ }
1766
+ }),
1767
+ output: defineSchemaModel7({
1768
+ name: "ListToolsOutput",
1769
+ fields: {
1770
+ items: { type: ToolSummaryModel, isArray: true, isOptional: false },
1771
+ total: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
1772
+ hasMore: { type: ScalarTypeEnum7.Boolean(), isOptional: false }
1773
+ }
1774
+ })
1775
+ },
1776
+ policy: { auth: "user" },
1777
+ acceptance: {
1778
+ scenarios: [
1779
+ {
1780
+ key: "list-tools-happy-path",
1781
+ given: ["Organization has tools"],
1782
+ when: ["User lists tools"],
1783
+ then: ["Paginated list of tools is returned"]
1784
+ }
1785
+ ],
1786
+ examples: [
1787
+ {
1788
+ key: "list-by-category",
1789
+ input: { organizationId: "org-123", category: "api", limit: 10 },
1790
+ output: { items: [], total: 0, hasMore: false }
1791
+ }
1792
+ ]
1793
+ }
1794
+ });
1795
+ var TestToolCommand = defineCommand3({
1796
+ meta: {
1797
+ key: "agent.tool.test",
1798
+ version: "1.0.0",
1799
+ stability: "stable",
1800
+ owners: [...OWNERS4],
1801
+ tags: ["tool", "test"],
1802
+ description: "Tests a tool with sample input to verify it works correctly.",
1803
+ goal: "Validate tool configuration before deployment.",
1804
+ context: "Tool builder UI - test panel."
1805
+ },
1806
+ io: {
1807
+ input: defineSchemaModel7({
1808
+ name: "TestToolInput",
1809
+ fields: {
1810
+ toolId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1811
+ testInput: { type: ScalarTypeEnum7.JSONObject(), isOptional: false }
1812
+ }
1813
+ }),
1814
+ output: defineSchemaModel7({
1815
+ name: "TestToolOutput",
1816
+ fields: {
1817
+ success: { type: ScalarTypeEnum7.Boolean(), isOptional: false },
1818
+ output: { type: ScalarTypeEnum7.JSONObject(), isOptional: true },
1819
+ error: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1820
+ durationMs: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false }
1821
+ }
1822
+ }),
1823
+ errors: {
1824
+ TOOL_NOT_FOUND: {
1825
+ description: "The specified tool does not exist",
1826
+ http: 404,
1827
+ gqlCode: "TOOL_NOT_FOUND",
1828
+ when: "Tool ID is invalid"
1829
+ },
1830
+ TOOL_EXECUTION_ERROR: {
1831
+ description: "Tool execution failed",
1832
+ http: 500,
1833
+ gqlCode: "TOOL_EXECUTION_ERROR",
1834
+ when: "Tool returns an error"
1835
+ }
1836
+ }
1837
+ },
1838
+ policy: { auth: "user" },
1839
+ sideEffects: { audit: ["tool.tested"] },
1840
+ acceptance: {
1841
+ scenarios: [
1842
+ {
1843
+ key: "test-tool-success",
1844
+ given: ["Tool exists", "Tool is configured correctly"],
1845
+ when: ["User runs test with valid input"],
1846
+ then: ["Tool executes successfully", "Output is returned"]
1847
+ },
1848
+ {
1849
+ key: "test-tool-failure",
1850
+ given: ["Tool exists", "Tool has configuration error"],
1851
+ when: ["User runs test"],
1852
+ then: ["TOOL_EXECUTION_ERROR is returned"]
1853
+ }
1854
+ ],
1855
+ examples: [
1856
+ {
1857
+ key: "test-weather-api",
1858
+ input: { toolId: "tool-123", testInput: { city: "Paris" } },
1859
+ output: { success: true, output: { temperature: 22 }, durationMs: 150 }
1860
+ }
1861
+ ]
1862
+ }
1863
+ });
1864
+
2
1865
  // src/handlers/agent.handlers.ts
3
1866
  import { web } from "@contractspec/lib.runtime-sandbox";
4
1867
  var { generateId } = web;
1868
+ var RUN_SORT_COLUMNS = {
1869
+ queuedAt: "r.queuedAt",
1870
+ totalTokens: "r.totalTokens",
1871
+ durationMs: "r.durationMs",
1872
+ estimatedCostUsd: "r.estimatedCostUsd",
1873
+ status: "r.status",
1874
+ agentName: "a.name"
1875
+ };
5
1876
  function rowToAgent(row) {
6
1877
  return {
7
1878
  id: row.id,
@@ -181,7 +2052,15 @@ function createAgentHandlers(db) {
181
2052
  };
182
2053
  }
183
2054
  async function listRuns(input) {
184
- const { projectId, agentId, status, limit = 20, offset = 0 } = input;
2055
+ const {
2056
+ projectId,
2057
+ agentId,
2058
+ status,
2059
+ sortBy,
2060
+ sortDirection = "desc",
2061
+ limit = 20,
2062
+ offset = 0
2063
+ } = input;
185
2064
  let whereClause = "WHERE r.projectId = ?";
186
2065
  const params = [projectId];
187
2066
  if (agentId) {
@@ -194,11 +2073,13 @@ function createAgentHandlers(db) {
194
2073
  }
195
2074
  const countResult = (await db.query(`SELECT COUNT(*) as count FROM agent_run r ${whereClause}`, params)).rows;
196
2075
  const total = countResult[0]?.count ?? 0;
2076
+ const sortColumn = sortBy ? RUN_SORT_COLUMNS[sortBy] : RUN_SORT_COLUMNS.queuedAt;
2077
+ const direction = sortDirection === "asc" ? "ASC" : "DESC";
197
2078
  const rows = (await db.query(`SELECT r.*, a.name as agentName
198
2079
  FROM agent_run r
199
2080
  LEFT JOIN agent_definition a ON r.agentId = a.id
200
2081
  ${whereClause}
201
- ORDER BY r.queuedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
2082
+ ORDER BY ${sortColumn} ${direction}, r.queuedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
202
2083
  return {
203
2084
  items: rows.map((r) => rowToRun(r, r.agentName)),
204
2085
  total,