@contractspec/example.agent-console 3.7.7 → 3.8.4

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 (191) hide show
  1. package/.turbo/turbo-build.log +126 -105
  2. package/AGENTS.md +3 -1
  3. package/CHANGELOG.md +57 -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.d.ts +1 -1
  124. package/dist/ui/renderers/agent-list.markdown.js +14 -5
  125. package/dist/ui/renderers/agent-list.renderer.d.ts +1 -1
  126. package/dist/ui/renderers/dashboard.markdown.d.ts +1 -1
  127. package/dist/ui/renderers/dashboard.markdown.js +207 -36
  128. package/dist/ui/renderers/index.js +245 -49
  129. package/dist/ui/renderers/run-list.markdown.d.ts +1 -1
  130. package/dist/ui/renderers/run-list.markdown.js +9 -4
  131. package/dist/ui/renderers/tool-registry.markdown.d.ts +2 -2
  132. package/dist/ui/renderers/tool-registry.markdown.js +15 -4
  133. package/dist/ui/views/RunDataTable.d.ts +18 -0
  134. package/dist/ui/views/RunDataTable.js +327 -0
  135. package/dist/ui/views/RunListView.js +359 -127
  136. package/dist/ui/views/index.js +406 -174
  137. package/dist/ui/views/run-data-table.columns.d.ts +3 -0
  138. package/dist/ui/views/run-data-table.columns.js +272 -0
  139. package/dist/ui/views/run-list.shared.d.ts +14 -0
  140. package/dist/ui/views/run-list.shared.js +178 -0
  141. package/dist/visualizations/catalog.d.ts +10 -0
  142. package/dist/visualizations/catalog.js +135 -0
  143. package/dist/visualizations/index.d.ts +2 -0
  144. package/dist/visualizations/index.js +188 -0
  145. package/dist/visualizations/selectors.d.ts +3 -0
  146. package/dist/visualizations/selectors.js +182 -0
  147. package/dist/visualizations/selectors.test.d.ts +1 -0
  148. package/package.json +114 -11
  149. package/proofs/agent-console-meetup.replay.json +220 -0
  150. package/src/agent/agent.handler.ts +18 -1
  151. package/src/agent.feature.ts +3 -0
  152. package/src/docs/agent-console.docblock.ts +11 -8
  153. package/src/example.test.ts +75 -0
  154. package/src/example.ts +2 -3
  155. package/src/handlers/agent.handlers.ts +55 -2
  156. package/src/handlers/index.ts +18 -2
  157. package/src/handlers/mock-handlers.test.ts +77 -0
  158. package/src/index.ts +2 -0
  159. package/src/proof/index.ts +2 -0
  160. package/src/proof/meetup-proof.runtime.ts +196 -0
  161. package/src/proof/meetup-proof.scenario.ts +99 -0
  162. package/src/proof/meetup-proof.suite.ts +29 -0
  163. package/src/proof/meetup-proof.test.ts +28 -0
  164. package/src/proof/meetup-proof.ts +130 -0
  165. package/src/run/run.handler.ts +17 -1
  166. package/src/shared/demo-dashboard-data.ts +58 -0
  167. package/src/shared/demo-runtime-seed.ts +139 -0
  168. package/src/shared/demo-runtime.test.ts +169 -0
  169. package/src/shared/demo-runtime.ts +260 -0
  170. package/src/shared/index.ts +11 -0
  171. package/src/shared/mock-runs.ts +5 -0
  172. package/src/tool/tool.handler.ts +21 -4
  173. package/src/ui/AgentDashboard.sandbox.test.tsx +312 -0
  174. package/src/ui/AgentDashboard.tsx +4 -1
  175. package/src/ui/AgentDashboard.visualizations.tsx +35 -0
  176. package/src/ui/hooks/useAgentMutations.ts +19 -11
  177. package/src/ui/hooks/useRunList.ts +41 -9
  178. package/src/ui/renderers/agent-list.markdown.ts +32 -13
  179. package/src/ui/renderers/agent-list.renderer.tsx +1 -1
  180. package/src/ui/renderers/dashboard.markdown.ts +38 -43
  181. package/src/ui/renderers/run-list.markdown.ts +17 -9
  182. package/src/ui/renderers/tool-registry.markdown.ts +22 -10
  183. package/src/ui/views/RunDataTable.tsx +74 -0
  184. package/src/ui/views/RunListView.tsx +37 -111
  185. package/src/ui/views/run-data-table.columns.tsx +102 -0
  186. package/src/ui/views/run-list.shared.tsx +139 -0
  187. package/src/visualizations/catalog.ts +132 -0
  188. package/src/visualizations/index.ts +2 -0
  189. package/src/visualizations/selectors.test.ts +12 -0
  190. package/src/visualizations/selectors.ts +70 -0
  191. package/tsdown.config.js +17 -0
@@ -1,4 +1,136 @@
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
+
2
134
  // src/shared/mock-agents.ts
3
135
  var MOCK_AGENTS = [
4
136
  {
@@ -223,7 +355,604 @@ var MOCK_TOOLS = [
223
355
  }
224
356
  ];
225
357
 
358
+ // src/agent/agent.schema.ts
359
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
360
+ var AgentModel = defineSchemaModel2({
361
+ name: "Agent",
362
+ description: "AI agent configuration",
363
+ fields: {
364
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
365
+ organizationId: {
366
+ type: ScalarTypeEnum2.String_unsecure(),
367
+ isOptional: false
368
+ },
369
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
370
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
371
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
372
+ status: { type: AgentStatusEnum, isOptional: false },
373
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
374
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
375
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
376
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
377
+ userPromptTemplate: {
378
+ type: ScalarTypeEnum2.String_unsecure(),
379
+ isOptional: true
380
+ },
381
+ toolIds: {
382
+ type: ScalarTypeEnum2.String_unsecure(),
383
+ isArray: true,
384
+ isOptional: true
385
+ },
386
+ toolChoice: {
387
+ type: ToolChoiceEnum,
388
+ isOptional: false,
389
+ defaultValue: "auto"
390
+ },
391
+ maxIterations: {
392
+ type: ScalarTypeEnum2.Int_unsecure(),
393
+ isOptional: false,
394
+ defaultValue: 10
395
+ },
396
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
397
+ timeoutMs: {
398
+ type: ScalarTypeEnum2.Int_unsecure(),
399
+ isOptional: false,
400
+ defaultValue: 120000
401
+ },
402
+ version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
403
+ tags: {
404
+ type: ScalarTypeEnum2.String_unsecure(),
405
+ isArray: true,
406
+ isOptional: true
407
+ },
408
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
409
+ updatedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
410
+ }
411
+ });
412
+ var AgentSummaryModel = defineSchemaModel2({
413
+ name: "AgentSummary",
414
+ description: "Summary of an agent for list views",
415
+ fields: {
416
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
417
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
418
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
419
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
420
+ status: { type: AgentStatusEnum, isOptional: false },
421
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
422
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
423
+ version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
424
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
425
+ }
426
+ });
427
+ var AgentToolRefModel = defineSchemaModel2({
428
+ name: "AgentToolRef",
429
+ description: "Tool reference in agent context",
430
+ fields: {
431
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
432
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
433
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
434
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
435
+ category: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
436
+ }
437
+ });
438
+ var AgentWithToolsModel = defineSchemaModel2({
439
+ name: "AgentWithTools",
440
+ description: "Agent with associated tools",
441
+ fields: {
442
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
443
+ organizationId: {
444
+ type: ScalarTypeEnum2.String_unsecure(),
445
+ isOptional: false
446
+ },
447
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
448
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
449
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
450
+ status: { type: AgentStatusEnum, isOptional: false },
451
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
452
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
453
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
454
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
455
+ userPromptTemplate: {
456
+ type: ScalarTypeEnum2.String_unsecure(),
457
+ isOptional: true
458
+ },
459
+ toolIds: {
460
+ type: ScalarTypeEnum2.String_unsecure(),
461
+ isArray: true,
462
+ isOptional: true
463
+ },
464
+ toolChoice: { type: ToolChoiceEnum, isOptional: false },
465
+ maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
466
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
467
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
468
+ version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
469
+ tags: {
470
+ type: ScalarTypeEnum2.String_unsecure(),
471
+ isArray: true,
472
+ isOptional: true
473
+ },
474
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
475
+ updatedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
476
+ tools: { type: AgentToolRefModel, isArray: true, isOptional: true }
477
+ }
478
+ });
479
+ var CreateAgentInputModel = defineSchemaModel2({
480
+ name: "CreateAgentInput",
481
+ description: "Input for creating an agent",
482
+ fields: {
483
+ organizationId: {
484
+ type: ScalarTypeEnum2.String_unsecure(),
485
+ isOptional: false
486
+ },
487
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
488
+ slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
489
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
490
+ modelProvider: { type: ModelProviderEnum, isOptional: false },
491
+ modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
492
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
493
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
494
+ userPromptTemplate: {
495
+ type: ScalarTypeEnum2.String_unsecure(),
496
+ isOptional: true
497
+ },
498
+ toolIds: {
499
+ type: ScalarTypeEnum2.String_unsecure(),
500
+ isArray: true,
501
+ isOptional: true
502
+ },
503
+ toolChoice: { type: ToolChoiceEnum, isOptional: true },
504
+ maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
505
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
506
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
507
+ tags: {
508
+ type: ScalarTypeEnum2.String_unsecure(),
509
+ isArray: true,
510
+ isOptional: true
511
+ }
512
+ }
513
+ });
514
+ var UpdateAgentInputModel = defineSchemaModel2({
515
+ name: "UpdateAgentInput",
516
+ description: "Input for updating an agent",
517
+ fields: {
518
+ agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
519
+ name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: true },
520
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
521
+ status: { type: AgentStatusEnum, isOptional: true },
522
+ modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
523
+ systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
524
+ userPromptTemplate: {
525
+ type: ScalarTypeEnum2.String_unsecure(),
526
+ isOptional: true
527
+ },
528
+ toolIds: {
529
+ type: ScalarTypeEnum2.String_unsecure(),
530
+ isArray: true,
531
+ isOptional: true
532
+ },
533
+ toolChoice: { type: ToolChoiceEnum, isOptional: true },
534
+ maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
535
+ maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
536
+ timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
537
+ tags: {
538
+ type: ScalarTypeEnum2.String_unsecure(),
539
+ isArray: true,
540
+ isOptional: true
541
+ }
542
+ }
543
+ });
544
+
545
+ // src/agent/agent.operation.ts
546
+ import {
547
+ defineCommand,
548
+ defineQuery
549
+ } from "@contractspec/lib.contracts-spec/operations";
550
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
551
+ var OWNERS2 = ["@agent-console-team"];
552
+ var CreateAgentCommand = defineCommand({
553
+ meta: {
554
+ key: "agent-console.agent.create",
555
+ version: "1.0.0",
556
+ stability: "stable",
557
+ owners: [...OWNERS2],
558
+ tags: ["agent", "create"],
559
+ description: "Creates a new AI agent configuration.",
560
+ goal: "Allow users to define new AI agents with specific models and tools.",
561
+ context: "Called from the agent builder UI when creating a new agent."
562
+ },
563
+ io: {
564
+ input: CreateAgentInputModel,
565
+ output: defineSchemaModel3({
566
+ name: "CreateAgentOutput",
567
+ fields: {
568
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
569
+ name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
570
+ slug: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
571
+ status: { type: AgentStatusEnum, isOptional: false }
572
+ }
573
+ }),
574
+ errors: {
575
+ SLUG_EXISTS: {
576
+ description: "An agent with this slug already exists in the organization",
577
+ http: 409,
578
+ gqlCode: "SLUG_EXISTS",
579
+ when: "Slug is already taken"
580
+ }
581
+ }
582
+ },
583
+ policy: { auth: "user" },
584
+ sideEffects: {
585
+ emits: [
586
+ {
587
+ ref: AgentCreatedEvent.meta,
588
+ when: "Agent is successfully created"
589
+ }
590
+ ],
591
+ audit: ["agent-console.agent.created"]
592
+ },
593
+ acceptance: {
594
+ scenarios: [
595
+ {
596
+ key: "create-agent-happy-path",
597
+ given: ["User is authenticated", "Organization exists"],
598
+ when: ["User submits valid agent configuration"],
599
+ then: [
600
+ "New agent is created with DRAFT status",
601
+ "AgentCreated event is emitted"
602
+ ]
603
+ },
604
+ {
605
+ key: "create-agent-slug-conflict",
606
+ given: ["User is authenticated", "Agent with same slug exists"],
607
+ when: ["User submits agent with duplicate slug"],
608
+ then: ["SLUG_EXISTS error is returned with 409 status"]
609
+ }
610
+ ],
611
+ examples: [
612
+ {
613
+ key: "basic-create",
614
+ input: {
615
+ name: "Support Assistant",
616
+ slug: "support-assistant",
617
+ modelProvider: "openai",
618
+ modelId: "gpt-4"
619
+ },
620
+ output: {
621
+ id: "agent-123",
622
+ name: "Support Assistant",
623
+ slug: "support-assistant",
624
+ status: "draft"
625
+ }
626
+ }
627
+ ]
628
+ }
629
+ });
630
+ var UpdateAgentCommand = defineCommand({
631
+ meta: {
632
+ key: "agent-console.agent.update",
633
+ version: "1.0.0",
634
+ stability: "stable",
635
+ owners: [...OWNERS2],
636
+ tags: ["agent", "update"],
637
+ description: "Updates an existing AI agent configuration.",
638
+ goal: "Allow users to modify agent settings and configuration.",
639
+ context: "Called from the agent settings UI."
640
+ },
641
+ io: {
642
+ input: UpdateAgentInputModel,
643
+ output: defineSchemaModel3({
644
+ name: "UpdateAgentOutput",
645
+ fields: {
646
+ id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
647
+ name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
648
+ status: { type: AgentStatusEnum, isOptional: false },
649
+ updatedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
650
+ }
651
+ }),
652
+ errors: {
653
+ AGENT_NOT_FOUND: {
654
+ description: "The specified agent does not exist",
655
+ http: 404,
656
+ gqlCode: "AGENT_NOT_FOUND",
657
+ when: "Agent ID is invalid"
658
+ }
659
+ }
660
+ },
661
+ policy: { auth: "user" },
662
+ sideEffects: {
663
+ emits: [
664
+ {
665
+ key: "agent.updated",
666
+ version: "1.0.0",
667
+ stability: "stable",
668
+ owners: [...OWNERS2],
669
+ tags: ["agent", "updated"],
670
+ when: "Agent is updated",
671
+ payload: AgentSummaryModel
672
+ }
673
+ ],
674
+ audit: ["agent.updated"]
675
+ },
676
+ acceptance: {
677
+ scenarios: [
678
+ {
679
+ key: "update-agent-happy-path",
680
+ given: ["Agent exists", "User owns the agent"],
681
+ when: ["User submits updated configuration"],
682
+ then: ["Agent is updated", "AgentUpdated event is emitted"]
683
+ },
684
+ {
685
+ key: "update-agent-not-found",
686
+ given: ["Agent does not exist"],
687
+ when: ["User attempts to update"],
688
+ then: ["AGENT_NOT_FOUND error is returned"]
689
+ }
690
+ ],
691
+ examples: [
692
+ {
693
+ key: "update-name",
694
+ input: {
695
+ agentId: "agent-123",
696
+ name: "Updated Assistant",
697
+ systemPrompt: "You are a helpful assistant."
698
+ },
699
+ output: {
700
+ id: "agent-123",
701
+ name: "Updated Assistant",
702
+ status: "draft",
703
+ updatedAt: "2025-01-01T00:00:00Z"
704
+ }
705
+ }
706
+ ]
707
+ }
708
+ });
709
+ var GetAgentQuery = defineQuery({
710
+ meta: {
711
+ key: "agent-console.agent.get",
712
+ version: "1.0.0",
713
+ stability: "stable",
714
+ owners: [...OWNERS2],
715
+ tags: ["agent", "get"],
716
+ description: "Retrieves an agent by its ID.",
717
+ goal: "View detailed agent configuration.",
718
+ context: "Called when viewing agent details or editing."
719
+ },
720
+ io: {
721
+ input: defineSchemaModel3({
722
+ name: "GetAgentInput",
723
+ fields: {
724
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
725
+ includeTools: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
726
+ }
727
+ }),
728
+ output: AgentWithToolsModel,
729
+ errors: {
730
+ AGENT_NOT_FOUND: {
731
+ description: "The specified agent does not exist",
732
+ http: 404,
733
+ gqlCode: "AGENT_NOT_FOUND",
734
+ when: "Agent ID is invalid"
735
+ }
736
+ }
737
+ },
738
+ policy: { auth: "user" },
739
+ acceptance: {
740
+ scenarios: [
741
+ {
742
+ key: "get-agent-happy-path",
743
+ given: ["Agent exists"],
744
+ when: ["User requests agent by ID"],
745
+ then: ["Agent details are returned"]
746
+ },
747
+ {
748
+ key: "get-agent-with-tools",
749
+ given: ["Agent exists with assigned tools"],
750
+ when: ["User requests agent with includeTools=true"],
751
+ then: ["Agent details with tools list are returned"]
752
+ }
753
+ ],
754
+ examples: [
755
+ {
756
+ key: "get-basic",
757
+ input: { agentId: "agent-123", includeTools: false },
758
+ output: {
759
+ id: "agent-123",
760
+ name: "Support Assistant",
761
+ status: "active",
762
+ tools: []
763
+ }
764
+ }
765
+ ]
766
+ }
767
+ });
768
+ var ListAgentsQuery = defineQuery({
769
+ meta: {
770
+ key: "agent-console.agent.list",
771
+ version: "1.0.0",
772
+ stability: "stable",
773
+ owners: [...OWNERS2],
774
+ tags: ["agent", "list"],
775
+ description: "Lists agents for an organization with optional filtering.",
776
+ goal: "Browse and search available agents.",
777
+ context: "Agent list/dashboard view."
778
+ },
779
+ io: {
780
+ input: defineSchemaModel3({
781
+ name: "ListAgentsInput",
782
+ fields: {
783
+ organizationId: {
784
+ type: ScalarTypeEnum3.String_unsecure(),
785
+ isOptional: false
786
+ },
787
+ status: { type: AgentStatusEnum, isOptional: true },
788
+ modelProvider: { type: ModelProviderEnum, isOptional: true },
789
+ search: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
790
+ limit: {
791
+ type: ScalarTypeEnum3.Int_unsecure(),
792
+ isOptional: true,
793
+ defaultValue: 20
794
+ },
795
+ offset: {
796
+ type: ScalarTypeEnum3.Int_unsecure(),
797
+ isOptional: true,
798
+ defaultValue: 0
799
+ }
800
+ }
801
+ }),
802
+ output: defineSchemaModel3({
803
+ name: "ListAgentsOutput",
804
+ fields: {
805
+ items: { type: AgentSummaryModel, isArray: true, isOptional: false },
806
+ total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
807
+ hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
808
+ }
809
+ })
810
+ },
811
+ policy: { auth: "user" },
812
+ acceptance: {
813
+ scenarios: [
814
+ {
815
+ key: "list-agents-happy-path",
816
+ given: ["Organization has agents"],
817
+ when: ["User lists agents"],
818
+ then: ["Paginated list of agents is returned"]
819
+ },
820
+ {
821
+ key: "list-agents-filter-by-status",
822
+ given: ["Organization has agents with mixed statuses"],
823
+ when: ["User filters by status=active"],
824
+ then: ["Only active agents are returned"]
825
+ }
826
+ ],
827
+ examples: [
828
+ {
829
+ key: "list-basic",
830
+ input: { organizationId: "org-123", limit: 10, offset: 0 },
831
+ output: { items: [], total: 0, hasMore: false }
832
+ }
833
+ ]
834
+ }
835
+ });
836
+ var AssignToolToAgentCommand = defineCommand({
837
+ meta: {
838
+ key: "agent-console.agent.assignTool",
839
+ version: "1.0.0",
840
+ stability: "stable",
841
+ owners: [...OWNERS2],
842
+ tags: ["agent", "tool", "assign"],
843
+ description: "Assigns a tool to an agent with optional configuration.",
844
+ goal: "Enable agents to use specific tools.",
845
+ context: "Agent configuration UI - tool selection."
846
+ },
847
+ io: {
848
+ input: defineSchemaModel3({
849
+ name: "AssignToolToAgentInput",
850
+ fields: {
851
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
852
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
853
+ config: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
854
+ order: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true }
855
+ }
856
+ }),
857
+ output: defineSchemaModel3({
858
+ name: "AssignToolToAgentOutput",
859
+ fields: {
860
+ agentToolId: {
861
+ type: ScalarTypeEnum3.String_unsecure(),
862
+ isOptional: false
863
+ },
864
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
865
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
866
+ }
867
+ }),
868
+ errors: {
869
+ TOOL_ALREADY_ASSIGNED: {
870
+ description: "This tool is already assigned to the agent",
871
+ http: 409,
872
+ gqlCode: "TOOL_ALREADY_ASSIGNED",
873
+ when: "Tool assignment already exists"
874
+ }
875
+ }
876
+ },
877
+ policy: { auth: "user" },
878
+ sideEffects: { audit: ["agent.tool.assigned"] },
879
+ acceptance: {
880
+ scenarios: [
881
+ {
882
+ key: "assign-tool-happy-path",
883
+ given: ["Agent exists", "Tool exists and is not assigned"],
884
+ when: ["User assigns tool to agent"],
885
+ then: ["Tool is assigned", "Assignment ID is returned"]
886
+ },
887
+ {
888
+ key: "assign-tool-already-assigned",
889
+ given: ["Tool is already assigned to agent"],
890
+ when: ["User attempts to assign again"],
891
+ then: ["TOOL_ALREADY_ASSIGNED error is returned"]
892
+ }
893
+ ],
894
+ examples: [
895
+ {
896
+ key: "assign-basic",
897
+ input: { agentId: "agent-123", toolId: "tool-456" },
898
+ output: {
899
+ agentToolId: "at-789",
900
+ agentId: "agent-123",
901
+ toolId: "tool-456"
902
+ }
903
+ }
904
+ ]
905
+ }
906
+ });
907
+ var RemoveToolFromAgentCommand = defineCommand({
908
+ meta: {
909
+ key: "agent-console.agent.removeTool",
910
+ version: "1.0.0",
911
+ stability: "stable",
912
+ owners: [...OWNERS2],
913
+ tags: ["agent", "tool", "remove"],
914
+ description: "Removes a tool assignment from an agent.",
915
+ goal: "Disable specific tools for an agent.",
916
+ context: "Agent configuration UI - tool management."
917
+ },
918
+ io: {
919
+ input: defineSchemaModel3({
920
+ name: "RemoveToolFromAgentInput",
921
+ fields: {
922
+ agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
923
+ toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
924
+ }
925
+ }),
926
+ output: defineSchemaModel3({
927
+ name: "RemoveToolFromAgentOutput",
928
+ fields: {
929
+ success: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
930
+ }
931
+ })
932
+ },
933
+ policy: { auth: "user" },
934
+ sideEffects: { audit: ["agent.tool.removed"] },
935
+ acceptance: {
936
+ scenarios: [
937
+ {
938
+ key: "remove-tool-happy-path",
939
+ given: ["Agent exists", "Tool is assigned to agent"],
940
+ when: ["User removes tool from agent"],
941
+ then: ["Tool is unassigned", "Success is returned"]
942
+ }
943
+ ],
944
+ examples: [
945
+ {
946
+ key: "remove-basic",
947
+ input: { agentId: "agent-123", toolId: "tool-456" },
948
+ output: { success: true }
949
+ }
950
+ ]
951
+ }
952
+ });
953
+
226
954
  // src/agent/agent.handler.ts
955
+ var nextMockAgentId = MOCK_AGENTS.length + 1;
227
956
  async function mockListAgentsHandler(input) {
228
957
  const {
229
958
  organizationId,
@@ -277,7 +1006,7 @@ async function mockCreateAgentHandler(input) {
277
1006
  if (exists)
278
1007
  throw new Error("SLUG_EXISTS");
279
1008
  return {
280
- id: `agent-${Date.now()}`,
1009
+ id: `agent-${nextMockAgentId++}`,
281
1010
  name: input.name,
282
1011
  slug: input.slug,
283
1012
  status: "DRAFT"
@@ -295,9 +1024,1152 @@ async function mockUpdateAgentHandler(input) {
295
1024
  };
296
1025
  }
297
1026
 
1027
+ // src/run/run.enum.ts
1028
+ import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
1029
+ var RunStatusEnum = defineEnum2("RunStatus", [
1030
+ "QUEUED",
1031
+ "IN_PROGRESS",
1032
+ "COMPLETED",
1033
+ "FAILED",
1034
+ "CANCELLED",
1035
+ "EXPIRED"
1036
+ ]);
1037
+ var RunStepTypeEnum = defineEnum2("RunStepType", [
1038
+ "MESSAGE_CREATION",
1039
+ "TOOL_CALL",
1040
+ "TOOL_RESULT",
1041
+ "ERROR"
1042
+ ]);
1043
+ var LogLevelEnum = defineEnum2("LogLevel", [
1044
+ "DEBUG",
1045
+ "INFO",
1046
+ "WARN",
1047
+ "ERROR"
1048
+ ]);
1049
+ var GranularityEnum = defineEnum2("Granularity", [
1050
+ "hour",
1051
+ "day",
1052
+ "week",
1053
+ "month"
1054
+ ]);
1055
+
1056
+ // src/run/run.schema.ts
1057
+ import { defineSchemaModel as defineSchemaModel4, ScalarTypeEnum as ScalarTypeEnum4 } from "@contractspec/lib.schema";
1058
+ var RunInputModel = defineSchemaModel4({
1059
+ name: "RunInput",
1060
+ description: "Input data for agent execution",
1061
+ fields: {
1062
+ message: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1063
+ context: { type: ScalarTypeEnum4.JSONObject(), isOptional: true }
1064
+ }
1065
+ });
1066
+ var RunStepModel = defineSchemaModel4({
1067
+ name: "RunStep",
1068
+ description: "Individual step within a run",
1069
+ fields: {
1070
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1071
+ stepNumber: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
1072
+ type: { type: RunStepTypeEnum, isOptional: false },
1073
+ toolId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1074
+ toolName: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1075
+ input: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
1076
+ output: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
1077
+ status: { type: RunStatusEnum, isOptional: false },
1078
+ errorMessage: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1079
+ tokensUsed: {
1080
+ type: ScalarTypeEnum4.Int_unsecure(),
1081
+ isOptional: false,
1082
+ defaultValue: 0
1083
+ },
1084
+ durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1085
+ startedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
1086
+ completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true }
1087
+ }
1088
+ });
1089
+ var RunLogModel = defineSchemaModel4({
1090
+ name: "RunLog",
1091
+ description: "Execution log entry",
1092
+ fields: {
1093
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1094
+ stepId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1095
+ level: { type: LogLevelEnum, isOptional: false },
1096
+ message: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1097
+ data: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
1098
+ source: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1099
+ traceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1100
+ spanId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1101
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
1102
+ }
1103
+ });
1104
+ var RunAgentRefModel = defineSchemaModel4({
1105
+ name: "RunAgentRef",
1106
+ description: "Agent reference in a run",
1107
+ fields: {
1108
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1109
+ name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1110
+ modelProvider: {
1111
+ type: ScalarTypeEnum4.String_unsecure(),
1112
+ isOptional: false
1113
+ },
1114
+ modelName: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false }
1115
+ }
1116
+ });
1117
+ var RunModel = defineSchemaModel4({
1118
+ name: "Run",
1119
+ description: "Agent execution instance",
1120
+ fields: {
1121
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1122
+ organizationId: {
1123
+ type: ScalarTypeEnum4.String_unsecure(),
1124
+ isOptional: false
1125
+ },
1126
+ agentId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1127
+ userId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1128
+ sessionId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1129
+ input: { type: ScalarTypeEnum4.JSONObject(), isOptional: false },
1130
+ output: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
1131
+ status: { type: RunStatusEnum, isOptional: false },
1132
+ errorMessage: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1133
+ errorCode: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1134
+ totalTokens: {
1135
+ type: ScalarTypeEnum4.Int_unsecure(),
1136
+ isOptional: false,
1137
+ defaultValue: 0
1138
+ },
1139
+ promptTokens: {
1140
+ type: ScalarTypeEnum4.Int_unsecure(),
1141
+ isOptional: false,
1142
+ defaultValue: 0
1143
+ },
1144
+ completionTokens: {
1145
+ type: ScalarTypeEnum4.Int_unsecure(),
1146
+ isOptional: false,
1147
+ defaultValue: 0
1148
+ },
1149
+ totalIterations: {
1150
+ type: ScalarTypeEnum4.Int_unsecure(),
1151
+ isOptional: false,
1152
+ defaultValue: 0
1153
+ },
1154
+ durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1155
+ estimatedCostUsd: {
1156
+ type: ScalarTypeEnum4.Float_unsecure(),
1157
+ isOptional: true
1158
+ },
1159
+ queuedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
1160
+ startedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true },
1161
+ completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true },
1162
+ metadata: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
1163
+ steps: { type: RunStepModel, isArray: true, isOptional: true },
1164
+ logs: { type: RunLogModel, isArray: true, isOptional: true },
1165
+ agent: { type: RunAgentRefModel, isOptional: true }
1166
+ }
1167
+ });
1168
+ var RunSummaryModel = defineSchemaModel4({
1169
+ name: "RunSummary",
1170
+ description: "Summary of a run for list views",
1171
+ fields: {
1172
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1173
+ agentId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1174
+ agentName: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1175
+ status: { type: RunStatusEnum, isOptional: false },
1176
+ totalTokens: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
1177
+ durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1178
+ estimatedCostUsd: {
1179
+ type: ScalarTypeEnum4.Float_unsecure(),
1180
+ isOptional: true
1181
+ },
1182
+ queuedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
1183
+ completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true }
1184
+ }
1185
+ });
1186
+ var TimelineDataPointModel = defineSchemaModel4({
1187
+ name: "TimelineDataPoint",
1188
+ description: "Timeline data point for metrics",
1189
+ fields: {
1190
+ period: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
1191
+ runs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
1192
+ tokens: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
1193
+ costUsd: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false },
1194
+ avgDurationMs: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false }
1195
+ }
1196
+ });
1197
+
1198
+ // src/run/run.operation.ts
1199
+ import {
1200
+ defineCommand as defineCommand2,
1201
+ defineQuery as defineQuery2
1202
+ } from "@contractspec/lib.contracts-spec/operations";
1203
+ import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
1204
+ var OWNERS3 = ["@agent-console-team"];
1205
+ var ExecuteAgentCommand = defineCommand2({
1206
+ meta: {
1207
+ key: "agent.run.execute",
1208
+ version: "1.0.0",
1209
+ stability: "stable",
1210
+ owners: [...OWNERS3],
1211
+ tags: ["run", "execute"],
1212
+ description: "Starts a new agent run with the given input.",
1213
+ goal: "Execute an AI agent with user input.",
1214
+ context: "Called from chat interface or API."
1215
+ },
1216
+ io: {
1217
+ input: defineSchemaModel5({
1218
+ name: "ExecuteAgentInput",
1219
+ fields: {
1220
+ agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1221
+ input: { type: RunInputModel, isOptional: false },
1222
+ sessionId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1223
+ metadata: { type: ScalarTypeEnum5.JSONObject(), isOptional: true },
1224
+ stream: { type: ScalarTypeEnum5.Boolean(), isOptional: true },
1225
+ maxIterations: {
1226
+ type: ScalarTypeEnum5.Int_unsecure(),
1227
+ isOptional: true
1228
+ },
1229
+ timeoutMs: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: true }
1230
+ }
1231
+ }),
1232
+ output: defineSchemaModel5({
1233
+ name: "ExecuteAgentOutput",
1234
+ fields: {
1235
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1236
+ status: { type: RunStatusEnum, isOptional: false },
1237
+ estimatedWaitMs: {
1238
+ type: ScalarTypeEnum5.Int_unsecure(),
1239
+ isOptional: true
1240
+ }
1241
+ }
1242
+ }),
1243
+ errors: {
1244
+ AGENT_NOT_FOUND: {
1245
+ description: "The specified agent does not exist",
1246
+ http: 404,
1247
+ gqlCode: "AGENT_NOT_FOUND",
1248
+ when: "Agent ID is invalid"
1249
+ },
1250
+ AGENT_NOT_ACTIVE: {
1251
+ description: "The specified agent is not active",
1252
+ http: 400,
1253
+ gqlCode: "AGENT_NOT_ACTIVE",
1254
+ when: "Agent is in draft/paused/archived state"
1255
+ }
1256
+ }
1257
+ },
1258
+ policy: { auth: "user" },
1259
+ sideEffects: {
1260
+ emits: [
1261
+ {
1262
+ key: "run.started",
1263
+ version: "1.0.0",
1264
+ stability: "stable",
1265
+ owners: [...OWNERS3],
1266
+ tags: ["run", "started"],
1267
+ when: "Run is queued",
1268
+ payload: RunSummaryModel
1269
+ }
1270
+ ],
1271
+ audit: ["run.started"]
1272
+ },
1273
+ acceptance: {
1274
+ scenarios: [
1275
+ {
1276
+ key: "execute-agent-happy-path",
1277
+ given: ["Agent exists", "Agent is active"],
1278
+ when: ["User submits execution request"],
1279
+ then: ["Run is created", "RunStarted event is emitted"]
1280
+ },
1281
+ {
1282
+ key: "execute-agent-not-active",
1283
+ given: ["Agent exists but is not active"],
1284
+ when: ["User attempts to execute"],
1285
+ then: ["AGENT_NOT_ACTIVE error is returned"]
1286
+ }
1287
+ ],
1288
+ examples: [
1289
+ {
1290
+ key: "basic-execute",
1291
+ input: { agentId: "agent-123", input: { message: "Hello" } },
1292
+ output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
1293
+ }
1294
+ ]
1295
+ }
1296
+ });
1297
+ var CancelRunCommand = defineCommand2({
1298
+ meta: {
1299
+ key: "agent.run.cancel",
1300
+ version: "1.0.0",
1301
+ stability: "stable",
1302
+ owners: [...OWNERS3],
1303
+ tags: ["run", "cancel"],
1304
+ description: "Cancels an in-progress agent run.",
1305
+ goal: "Stop a running agent execution.",
1306
+ context: "Called when user wants to abort a long-running task."
1307
+ },
1308
+ io: {
1309
+ input: defineSchemaModel5({
1310
+ name: "CancelRunInput",
1311
+ fields: {
1312
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1313
+ reason: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
1314
+ }
1315
+ }),
1316
+ output: defineSchemaModel5({
1317
+ name: "CancelRunOutput",
1318
+ fields: {
1319
+ success: { type: ScalarTypeEnum5.Boolean(), isOptional: false },
1320
+ status: { type: RunStatusEnum, isOptional: false }
1321
+ }
1322
+ }),
1323
+ errors: {
1324
+ RUN_NOT_FOUND: {
1325
+ description: "The specified run does not exist",
1326
+ http: 404,
1327
+ gqlCode: "RUN_NOT_FOUND",
1328
+ when: "Run ID is invalid"
1329
+ },
1330
+ RUN_NOT_CANCELLABLE: {
1331
+ description: "The run cannot be cancelled",
1332
+ http: 400,
1333
+ gqlCode: "RUN_NOT_CANCELLABLE",
1334
+ when: "Run is already completed/failed/cancelled"
1335
+ }
1336
+ }
1337
+ },
1338
+ policy: { auth: "user" },
1339
+ sideEffects: {
1340
+ emits: [
1341
+ {
1342
+ key: "run.cancelled",
1343
+ version: "1.0.0",
1344
+ stability: "stable",
1345
+ owners: [...OWNERS3],
1346
+ tags: ["run", "cancelled"],
1347
+ when: "Run is cancelled",
1348
+ payload: RunSummaryModel
1349
+ }
1350
+ ],
1351
+ audit: ["run.cancelled"]
1352
+ },
1353
+ acceptance: {
1354
+ scenarios: [
1355
+ {
1356
+ key: "cancel-run-happy-path",
1357
+ given: ["Run exists", "Run is in progress"],
1358
+ when: ["User cancels run"],
1359
+ then: ["Run is cancelled", "RunCancelled event is emitted"]
1360
+ },
1361
+ {
1362
+ key: "cancel-run-already-completed",
1363
+ given: ["Run exists but is already completed"],
1364
+ when: ["User attempts to cancel"],
1365
+ then: ["RUN_NOT_CANCELLABLE error is returned"]
1366
+ }
1367
+ ],
1368
+ examples: [
1369
+ {
1370
+ key: "cancel-basic",
1371
+ input: { runId: "run-456", reason: "User requested" },
1372
+ output: { success: true, status: "cancelled" }
1373
+ }
1374
+ ]
1375
+ }
1376
+ });
1377
+ var GetRunQuery = defineQuery2({
1378
+ meta: {
1379
+ key: "agent.run.get",
1380
+ version: "1.0.0",
1381
+ stability: "stable",
1382
+ owners: [...OWNERS3],
1383
+ tags: ["run", "get"],
1384
+ description: "Retrieves a run by its ID with optional details.",
1385
+ goal: "View detailed run information.",
1386
+ context: "Run details page or monitoring."
1387
+ },
1388
+ io: {
1389
+ input: defineSchemaModel5({
1390
+ name: "GetRunInput",
1391
+ fields: {
1392
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1393
+ includeSteps: { type: ScalarTypeEnum5.Boolean(), isOptional: true },
1394
+ includeLogs: { type: ScalarTypeEnum5.Boolean(), isOptional: true }
1395
+ }
1396
+ }),
1397
+ output: RunModel,
1398
+ errors: {
1399
+ RUN_NOT_FOUND: {
1400
+ description: "The specified run does not exist",
1401
+ http: 404,
1402
+ gqlCode: "RUN_NOT_FOUND",
1403
+ when: "Run ID is invalid"
1404
+ }
1405
+ }
1406
+ },
1407
+ policy: { auth: "user" },
1408
+ acceptance: {
1409
+ scenarios: [
1410
+ {
1411
+ key: "get-run-happy-path",
1412
+ given: ["Run exists"],
1413
+ when: ["User requests run by ID"],
1414
+ then: ["Run details are returned"]
1415
+ }
1416
+ ],
1417
+ examples: [
1418
+ {
1419
+ key: "get-with-steps",
1420
+ input: { runId: "run-456", includeSteps: true, includeLogs: false },
1421
+ output: { id: "run-456", status: "completed", steps: [] }
1422
+ }
1423
+ ]
1424
+ }
1425
+ });
1426
+ var ListRunsQuery = defineQuery2({
1427
+ meta: {
1428
+ key: "agent.run.list",
1429
+ version: "1.0.0",
1430
+ stability: "stable",
1431
+ owners: [...OWNERS3],
1432
+ tags: ["run", "list"],
1433
+ description: "Lists runs with optional filtering.",
1434
+ goal: "Browse and search run history.",
1435
+ context: "Run history/dashboard view."
1436
+ },
1437
+ io: {
1438
+ input: defineSchemaModel5({
1439
+ name: "ListRunsInput",
1440
+ fields: {
1441
+ organizationId: {
1442
+ type: ScalarTypeEnum5.String_unsecure(),
1443
+ isOptional: true
1444
+ },
1445
+ agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1446
+ userId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1447
+ sessionId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1448
+ status: { type: RunStatusEnum, isOptional: true },
1449
+ startDate: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
1450
+ endDate: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
1451
+ limit: {
1452
+ type: ScalarTypeEnum5.Int_unsecure(),
1453
+ isOptional: true,
1454
+ defaultValue: 20
1455
+ },
1456
+ offset: {
1457
+ type: ScalarTypeEnum5.Int_unsecure(),
1458
+ isOptional: true,
1459
+ defaultValue: 0
1460
+ }
1461
+ }
1462
+ }),
1463
+ output: defineSchemaModel5({
1464
+ name: "ListRunsOutput",
1465
+ fields: {
1466
+ items: { type: RunSummaryModel, isArray: true, isOptional: false },
1467
+ total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1468
+ hasMore: { type: ScalarTypeEnum5.Boolean(), isOptional: false }
1469
+ }
1470
+ })
1471
+ },
1472
+ policy: { auth: "user" },
1473
+ acceptance: {
1474
+ scenarios: [
1475
+ {
1476
+ key: "list-runs-happy-path",
1477
+ given: ["Organization has runs"],
1478
+ when: ["User lists runs"],
1479
+ then: ["Paginated list of runs is returned"]
1480
+ }
1481
+ ],
1482
+ examples: [
1483
+ {
1484
+ key: "list-by-agent",
1485
+ input: { agentId: "agent-123", limit: 20, offset: 0 },
1486
+ output: { items: [], total: 0, hasMore: false }
1487
+ }
1488
+ ]
1489
+ }
1490
+ });
1491
+ var GetRunStepsQuery = defineQuery2({
1492
+ meta: {
1493
+ key: "agent.run.getSteps",
1494
+ version: "1.0.0",
1495
+ stability: "stable",
1496
+ owners: [...OWNERS3],
1497
+ tags: ["run", "steps"],
1498
+ description: "Retrieves all steps for a specific run.",
1499
+ goal: "View step-by-step execution details.",
1500
+ context: "Run details page - steps tab."
1501
+ },
1502
+ io: {
1503
+ input: defineSchemaModel5({
1504
+ name: "GetRunStepsInput",
1505
+ fields: {
1506
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false }
1507
+ }
1508
+ }),
1509
+ output: defineSchemaModel5({
1510
+ name: "GetRunStepsOutput",
1511
+ fields: {
1512
+ steps: { type: RunStepModel, isArray: true, isOptional: false }
1513
+ }
1514
+ })
1515
+ },
1516
+ policy: { auth: "user" },
1517
+ acceptance: {
1518
+ scenarios: [
1519
+ {
1520
+ key: "get-run-steps-happy-path",
1521
+ given: ["Run exists with steps"],
1522
+ when: ["User requests steps"],
1523
+ then: ["Steps list is returned"]
1524
+ }
1525
+ ],
1526
+ examples: [
1527
+ {
1528
+ key: "get-steps-basic",
1529
+ input: { runId: "run-456" },
1530
+ output: { steps: [] }
1531
+ }
1532
+ ]
1533
+ }
1534
+ });
1535
+ var GetRunLogsQuery = defineQuery2({
1536
+ meta: {
1537
+ key: "agent.run.getLogs",
1538
+ version: "1.0.0",
1539
+ stability: "stable",
1540
+ owners: [...OWNERS3],
1541
+ tags: ["run", "logs"],
1542
+ description: "Retrieves all logs for a specific run.",
1543
+ goal: "Debug and audit run execution.",
1544
+ context: "Run details page - logs tab."
1545
+ },
1546
+ io: {
1547
+ input: defineSchemaModel5({
1548
+ name: "GetRunLogsInput",
1549
+ fields: {
1550
+ runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1551
+ level: { type: LogLevelEnum, isOptional: true },
1552
+ stepId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1553
+ limit: {
1554
+ type: ScalarTypeEnum5.Int_unsecure(),
1555
+ isOptional: true,
1556
+ defaultValue: 100
1557
+ },
1558
+ offset: {
1559
+ type: ScalarTypeEnum5.Int_unsecure(),
1560
+ isOptional: true,
1561
+ defaultValue: 0
1562
+ }
1563
+ }
1564
+ }),
1565
+ output: defineSchemaModel5({
1566
+ name: "GetRunLogsOutput",
1567
+ fields: {
1568
+ items: { type: RunLogModel, isArray: true, isOptional: false },
1569
+ total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1570
+ hasMore: { type: ScalarTypeEnum5.Boolean(), isOptional: false }
1571
+ }
1572
+ })
1573
+ },
1574
+ policy: { auth: "user" },
1575
+ acceptance: {
1576
+ scenarios: [
1577
+ {
1578
+ key: "get-run-logs-happy-path",
1579
+ given: ["Run exists with logs"],
1580
+ when: ["User requests logs"],
1581
+ then: ["Paginated logs list is returned"]
1582
+ }
1583
+ ],
1584
+ examples: [
1585
+ {
1586
+ key: "get-logs-filtered",
1587
+ input: { runId: "run-456", level: "error", limit: 50 },
1588
+ output: { items: [], total: 0, hasMore: false }
1589
+ }
1590
+ ]
1591
+ }
1592
+ });
1593
+ var GetRunMetricsQuery = defineQuery2({
1594
+ meta: {
1595
+ key: "agent.run.getMetrics",
1596
+ version: "1.0.0",
1597
+ stability: "stable",
1598
+ owners: [...OWNERS3],
1599
+ tags: ["run", "metrics"],
1600
+ description: "Retrieves aggregated metrics for runs within a time period.",
1601
+ goal: "Monitor and analyze agent usage.",
1602
+ context: "Analytics dashboard."
1603
+ },
1604
+ io: {
1605
+ input: defineSchemaModel5({
1606
+ name: "GetRunMetricsInput",
1607
+ fields: {
1608
+ organizationId: {
1609
+ type: ScalarTypeEnum5.String_unsecure(),
1610
+ isOptional: false
1611
+ },
1612
+ agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1613
+ startDate: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
1614
+ endDate: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
1615
+ granularity: {
1616
+ type: GranularityEnum,
1617
+ isOptional: true,
1618
+ defaultValue: "day"
1619
+ }
1620
+ }
1621
+ }),
1622
+ output: defineSchemaModel5({
1623
+ name: "GetRunMetricsOutput",
1624
+ fields: {
1625
+ totalRuns: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1626
+ completedRuns: {
1627
+ type: ScalarTypeEnum5.Int_unsecure(),
1628
+ isOptional: false
1629
+ },
1630
+ failedRuns: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1631
+ totalTokens: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1632
+ totalCostUsd: {
1633
+ type: ScalarTypeEnum5.Float_unsecure(),
1634
+ isOptional: false
1635
+ },
1636
+ averageDurationMs: {
1637
+ type: ScalarTypeEnum5.Float_unsecure(),
1638
+ isOptional: false
1639
+ },
1640
+ successRate: {
1641
+ type: ScalarTypeEnum5.Float_unsecure(),
1642
+ isOptional: false
1643
+ },
1644
+ timeline: {
1645
+ type: TimelineDataPointModel,
1646
+ isArray: true,
1647
+ isOptional: false
1648
+ }
1649
+ }
1650
+ })
1651
+ },
1652
+ policy: { auth: "user" },
1653
+ acceptance: {
1654
+ scenarios: [
1655
+ {
1656
+ key: "get-run-metrics-happy-path",
1657
+ given: ["Organization has run history"],
1658
+ when: ["User requests metrics for date range"],
1659
+ then: ["Aggregated metrics are returned"]
1660
+ }
1661
+ ],
1662
+ examples: [
1663
+ {
1664
+ key: "get-daily-metrics",
1665
+ input: {
1666
+ organizationId: "org-123",
1667
+ startDate: "2025-01-01",
1668
+ endDate: "2025-01-31",
1669
+ granularity: "day"
1670
+ },
1671
+ output: {
1672
+ totalRuns: 100,
1673
+ completedRuns: 90,
1674
+ failedRuns: 10,
1675
+ totalTokens: 50000,
1676
+ totalCostUsd: 5,
1677
+ averageDurationMs: 2500,
1678
+ successRate: 0.9,
1679
+ timeline: []
1680
+ }
1681
+ }
1682
+ ]
1683
+ }
1684
+ });
1685
+
1686
+ // src/tool/tool.enum.ts
1687
+ import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
1688
+ var ToolCategoryEnum = defineEnum3("ToolCategory", [
1689
+ "RETRIEVAL",
1690
+ "COMPUTATION",
1691
+ "COMMUNICATION",
1692
+ "INTEGRATION",
1693
+ "UTILITY",
1694
+ "CUSTOM"
1695
+ ]);
1696
+ var ToolStatusEnum = defineEnum3("ToolStatus", [
1697
+ "DRAFT",
1698
+ "ACTIVE",
1699
+ "DEPRECATED",
1700
+ "DISABLED"
1701
+ ]);
1702
+ var ImplementationTypeEnum = defineEnum3("ImplementationType", [
1703
+ "http",
1704
+ "function",
1705
+ "workflow"
1706
+ ]);
1707
+
1708
+ // src/tool/tool.schema.ts
1709
+ import { defineSchemaModel as defineSchemaModel6, ScalarTypeEnum as ScalarTypeEnum6 } from "@contractspec/lib.schema";
1710
+ var ToolModel = defineSchemaModel6({
1711
+ name: "Tool",
1712
+ description: "AI tool definition",
1713
+ fields: {
1714
+ id: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1715
+ organizationId: {
1716
+ type: ScalarTypeEnum6.String_unsecure(),
1717
+ isOptional: false
1718
+ },
1719
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1720
+ slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1721
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1722
+ category: { type: ToolCategoryEnum, isOptional: false },
1723
+ status: { type: ToolStatusEnum, isOptional: false },
1724
+ parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: false },
1725
+ outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1726
+ implementationType: { type: ImplementationTypeEnum, isOptional: false },
1727
+ implementationConfig: {
1728
+ type: ScalarTypeEnum6.JSONObject(),
1729
+ isOptional: false
1730
+ },
1731
+ maxInvocationsPerMinute: {
1732
+ type: ScalarTypeEnum6.Int_unsecure(),
1733
+ isOptional: true
1734
+ },
1735
+ timeoutMs: {
1736
+ type: ScalarTypeEnum6.Int_unsecure(),
1737
+ isOptional: false,
1738
+ defaultValue: 30000
1739
+ },
1740
+ version: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1741
+ tags: {
1742
+ type: ScalarTypeEnum6.String_unsecure(),
1743
+ isArray: true,
1744
+ isOptional: true
1745
+ },
1746
+ createdAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false },
1747
+ updatedAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1748
+ }
1749
+ });
1750
+ var ToolSummaryModel = defineSchemaModel6({
1751
+ name: "ToolSummary",
1752
+ description: "Summary of a tool for list views",
1753
+ fields: {
1754
+ id: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1755
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1756
+ slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1757
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1758
+ category: { type: ToolCategoryEnum, isOptional: false },
1759
+ status: { type: ToolStatusEnum, isOptional: false },
1760
+ version: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1761
+ createdAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1762
+ }
1763
+ });
1764
+ var CreateToolInputModel = defineSchemaModel6({
1765
+ name: "CreateToolInput",
1766
+ description: "Input for creating a tool",
1767
+ fields: {
1768
+ organizationId: {
1769
+ type: ScalarTypeEnum6.String_unsecure(),
1770
+ isOptional: false
1771
+ },
1772
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
1773
+ slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1774
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1775
+ category: { type: ToolCategoryEnum, isOptional: true },
1776
+ parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: false },
1777
+ outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1778
+ implementationType: { type: ImplementationTypeEnum, isOptional: false },
1779
+ implementationConfig: {
1780
+ type: ScalarTypeEnum6.JSONObject(),
1781
+ isOptional: false
1782
+ },
1783
+ maxInvocationsPerMinute: {
1784
+ type: ScalarTypeEnum6.Int_unsecure(),
1785
+ isOptional: true
1786
+ },
1787
+ timeoutMs: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: true },
1788
+ tags: {
1789
+ type: ScalarTypeEnum6.String_unsecure(),
1790
+ isArray: true,
1791
+ isOptional: true
1792
+ }
1793
+ }
1794
+ });
1795
+ var UpdateToolInputModel = defineSchemaModel6({
1796
+ name: "UpdateToolInput",
1797
+ description: "Input for updating a tool",
1798
+ fields: {
1799
+ toolId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1800
+ name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: true },
1801
+ description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true },
1802
+ status: { type: ToolStatusEnum, isOptional: true },
1803
+ parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1804
+ outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
1805
+ implementationConfig: {
1806
+ type: ScalarTypeEnum6.JSONObject(),
1807
+ isOptional: true
1808
+ },
1809
+ maxInvocationsPerMinute: {
1810
+ type: ScalarTypeEnum6.Int_unsecure(),
1811
+ isOptional: true
1812
+ },
1813
+ timeoutMs: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: true },
1814
+ tags: {
1815
+ type: ScalarTypeEnum6.String_unsecure(),
1816
+ isArray: true,
1817
+ isOptional: true
1818
+ }
1819
+ }
1820
+ });
1821
+
1822
+ // src/tool/tool.operation.ts
1823
+ import {
1824
+ defineCommand as defineCommand3,
1825
+ defineQuery as defineQuery3
1826
+ } from "@contractspec/lib.contracts-spec/operations";
1827
+ import { defineSchemaModel as defineSchemaModel7, ScalarTypeEnum as ScalarTypeEnum7 } from "@contractspec/lib.schema";
1828
+ var OWNERS4 = ["@agent-console-team"];
1829
+ var CreateToolCommand = defineCommand3({
1830
+ meta: {
1831
+ key: "agent.tool.create",
1832
+ version: "1.0.0",
1833
+ stability: "stable",
1834
+ owners: [...OWNERS4],
1835
+ tags: ["tool", "create"],
1836
+ description: "Creates a new AI tool definition.",
1837
+ goal: "Allow users to define new tools that agents can use.",
1838
+ context: "Called from the tool builder UI when creating a new tool."
1839
+ },
1840
+ io: {
1841
+ input: CreateToolInputModel,
1842
+ output: defineSchemaModel7({
1843
+ name: "CreateToolOutput",
1844
+ fields: {
1845
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1846
+ name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1847
+ slug: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1848
+ status: { type: ToolStatusEnum, isOptional: false }
1849
+ }
1850
+ }),
1851
+ errors: {
1852
+ SLUG_EXISTS: {
1853
+ description: "A tool with this slug already exists in the organization",
1854
+ http: 409,
1855
+ gqlCode: "SLUG_EXISTS",
1856
+ when: "Slug is already taken"
1857
+ }
1858
+ }
1859
+ },
1860
+ policy: { auth: "user" },
1861
+ sideEffects: {
1862
+ emits: [
1863
+ {
1864
+ key: "tool.created",
1865
+ version: "1.0.0",
1866
+ stability: "stable",
1867
+ owners: [...OWNERS4],
1868
+ tags: ["tool", "created"],
1869
+ when: "Tool is successfully created",
1870
+ payload: ToolSummaryModel
1871
+ }
1872
+ ],
1873
+ audit: ["tool.created"]
1874
+ },
1875
+ acceptance: {
1876
+ scenarios: [
1877
+ {
1878
+ key: "create-tool-happy-path",
1879
+ given: ["User is authenticated", "Organization exists"],
1880
+ when: ["User submits valid tool configuration"],
1881
+ then: ["New tool is created", "ToolCreated event is emitted"]
1882
+ },
1883
+ {
1884
+ key: "create-tool-slug-conflict",
1885
+ given: ["Tool with same slug exists"],
1886
+ when: ["User submits tool with duplicate slug"],
1887
+ then: ["SLUG_EXISTS error is returned"]
1888
+ }
1889
+ ],
1890
+ examples: [
1891
+ {
1892
+ key: "create-api-tool",
1893
+ input: {
1894
+ name: "Weather API",
1895
+ slug: "weather-api",
1896
+ category: "api",
1897
+ description: "Fetches weather data"
1898
+ },
1899
+ output: {
1900
+ id: "tool-123",
1901
+ name: "Weather API",
1902
+ slug: "weather-api",
1903
+ status: "draft"
1904
+ }
1905
+ }
1906
+ ]
1907
+ }
1908
+ });
1909
+ var UpdateToolCommand = defineCommand3({
1910
+ meta: {
1911
+ key: "agent.tool.update",
1912
+ version: "1.0.0",
1913
+ stability: "stable",
1914
+ owners: [...OWNERS4],
1915
+ tags: ["tool", "update"],
1916
+ description: "Updates an existing AI tool definition.",
1917
+ goal: "Allow users to modify tool settings and configuration.",
1918
+ context: "Called from the tool settings UI."
1919
+ },
1920
+ io: {
1921
+ input: UpdateToolInputModel,
1922
+ output: defineSchemaModel7({
1923
+ name: "UpdateToolOutput",
1924
+ fields: {
1925
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1926
+ name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1927
+ status: { type: ToolStatusEnum, isOptional: false },
1928
+ updatedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false }
1929
+ }
1930
+ }),
1931
+ errors: {
1932
+ TOOL_NOT_FOUND: {
1933
+ description: "The specified tool does not exist",
1934
+ http: 404,
1935
+ gqlCode: "TOOL_NOT_FOUND",
1936
+ when: "Tool ID is invalid"
1937
+ }
1938
+ }
1939
+ },
1940
+ policy: { auth: "user" },
1941
+ sideEffects: {
1942
+ emits: [
1943
+ {
1944
+ key: "tool.updated",
1945
+ version: "1.0.0",
1946
+ stability: "stable",
1947
+ owners: [...OWNERS4],
1948
+ tags: ["tool", "updated"],
1949
+ when: "Tool is updated",
1950
+ payload: ToolSummaryModel
1951
+ }
1952
+ ],
1953
+ audit: ["tool.updated"]
1954
+ },
1955
+ acceptance: {
1956
+ scenarios: [
1957
+ {
1958
+ key: "update-tool-happy-path",
1959
+ given: ["Tool exists", "User owns the tool"],
1960
+ when: ["User submits updated configuration"],
1961
+ then: ["Tool is updated", "ToolUpdated event is emitted"]
1962
+ }
1963
+ ],
1964
+ examples: [
1965
+ {
1966
+ key: "update-description",
1967
+ input: { toolId: "tool-123", description: "Updated weather API tool" },
1968
+ output: {
1969
+ id: "tool-123",
1970
+ name: "Weather API",
1971
+ status: "draft",
1972
+ updatedAt: "2025-01-01T00:00:00Z"
1973
+ }
1974
+ }
1975
+ ]
1976
+ }
1977
+ });
1978
+ var GetToolQuery = defineQuery3({
1979
+ meta: {
1980
+ key: "agent.tool.get",
1981
+ version: "1.0.0",
1982
+ stability: "stable",
1983
+ owners: [...OWNERS4],
1984
+ tags: ["tool", "get"],
1985
+ description: "Retrieves a tool by its ID.",
1986
+ goal: "View detailed tool configuration.",
1987
+ context: "Called when viewing tool details or editing."
1988
+ },
1989
+ io: {
1990
+ input: defineSchemaModel7({
1991
+ name: "GetToolInput",
1992
+ fields: {
1993
+ toolId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false }
1994
+ }
1995
+ }),
1996
+ output: ToolModel,
1997
+ errors: {
1998
+ TOOL_NOT_FOUND: {
1999
+ description: "The specified tool does not exist",
2000
+ http: 404,
2001
+ gqlCode: "TOOL_NOT_FOUND",
2002
+ when: "Tool ID is invalid"
2003
+ }
2004
+ }
2005
+ },
2006
+ policy: { auth: "user" },
2007
+ acceptance: {
2008
+ scenarios: [
2009
+ {
2010
+ key: "get-tool-happy-path",
2011
+ given: ["Tool exists"],
2012
+ when: ["User requests tool by ID"],
2013
+ then: ["Tool details are returned"]
2014
+ }
2015
+ ],
2016
+ examples: [
2017
+ {
2018
+ key: "get-basic",
2019
+ input: { toolId: "tool-123" },
2020
+ output: {
2021
+ id: "tool-123",
2022
+ name: "Weather API",
2023
+ status: "active",
2024
+ category: "api"
2025
+ }
2026
+ }
2027
+ ]
2028
+ }
2029
+ });
2030
+ var ListToolsQuery = defineQuery3({
2031
+ meta: {
2032
+ key: "agent.tool.list",
2033
+ version: "1.0.0",
2034
+ stability: "stable",
2035
+ owners: [...OWNERS4],
2036
+ tags: ["tool", "list"],
2037
+ description: "Lists tools for an organization with optional filtering.",
2038
+ goal: "Browse and search available tools.",
2039
+ context: "Tool list/dashboard view."
2040
+ },
2041
+ io: {
2042
+ input: defineSchemaModel7({
2043
+ name: "ListToolsInput",
2044
+ fields: {
2045
+ organizationId: {
2046
+ type: ScalarTypeEnum7.String_unsecure(),
2047
+ isOptional: false
2048
+ },
2049
+ category: { type: ToolCategoryEnum, isOptional: true },
2050
+ status: { type: ToolStatusEnum, isOptional: true },
2051
+ search: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
2052
+ limit: {
2053
+ type: ScalarTypeEnum7.Int_unsecure(),
2054
+ isOptional: true,
2055
+ defaultValue: 20
2056
+ },
2057
+ offset: {
2058
+ type: ScalarTypeEnum7.Int_unsecure(),
2059
+ isOptional: true,
2060
+ defaultValue: 0
2061
+ }
2062
+ }
2063
+ }),
2064
+ output: defineSchemaModel7({
2065
+ name: "ListToolsOutput",
2066
+ fields: {
2067
+ items: { type: ToolSummaryModel, isArray: true, isOptional: false },
2068
+ total: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
2069
+ hasMore: { type: ScalarTypeEnum7.Boolean(), isOptional: false }
2070
+ }
2071
+ })
2072
+ },
2073
+ policy: { auth: "user" },
2074
+ acceptance: {
2075
+ scenarios: [
2076
+ {
2077
+ key: "list-tools-happy-path",
2078
+ given: ["Organization has tools"],
2079
+ when: ["User lists tools"],
2080
+ then: ["Paginated list of tools is returned"]
2081
+ }
2082
+ ],
2083
+ examples: [
2084
+ {
2085
+ key: "list-by-category",
2086
+ input: { organizationId: "org-123", category: "api", limit: 10 },
2087
+ output: { items: [], total: 0, hasMore: false }
2088
+ }
2089
+ ]
2090
+ }
2091
+ });
2092
+ var TestToolCommand = defineCommand3({
2093
+ meta: {
2094
+ key: "agent.tool.test",
2095
+ version: "1.0.0",
2096
+ stability: "stable",
2097
+ owners: [...OWNERS4],
2098
+ tags: ["tool", "test"],
2099
+ description: "Tests a tool with sample input to verify it works correctly.",
2100
+ goal: "Validate tool configuration before deployment.",
2101
+ context: "Tool builder UI - test panel."
2102
+ },
2103
+ io: {
2104
+ input: defineSchemaModel7({
2105
+ name: "TestToolInput",
2106
+ fields: {
2107
+ toolId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
2108
+ testInput: { type: ScalarTypeEnum7.JSONObject(), isOptional: false }
2109
+ }
2110
+ }),
2111
+ output: defineSchemaModel7({
2112
+ name: "TestToolOutput",
2113
+ fields: {
2114
+ success: { type: ScalarTypeEnum7.Boolean(), isOptional: false },
2115
+ output: { type: ScalarTypeEnum7.JSONObject(), isOptional: true },
2116
+ error: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
2117
+ durationMs: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false }
2118
+ }
2119
+ }),
2120
+ errors: {
2121
+ TOOL_NOT_FOUND: {
2122
+ description: "The specified tool does not exist",
2123
+ http: 404,
2124
+ gqlCode: "TOOL_NOT_FOUND",
2125
+ when: "Tool ID is invalid"
2126
+ },
2127
+ TOOL_EXECUTION_ERROR: {
2128
+ description: "Tool execution failed",
2129
+ http: 500,
2130
+ gqlCode: "TOOL_EXECUTION_ERROR",
2131
+ when: "Tool returns an error"
2132
+ }
2133
+ }
2134
+ },
2135
+ policy: { auth: "user" },
2136
+ sideEffects: { audit: ["tool.tested"] },
2137
+ acceptance: {
2138
+ scenarios: [
2139
+ {
2140
+ key: "test-tool-success",
2141
+ given: ["Tool exists", "Tool is configured correctly"],
2142
+ when: ["User runs test with valid input"],
2143
+ then: ["Tool executes successfully", "Output is returned"]
2144
+ },
2145
+ {
2146
+ key: "test-tool-failure",
2147
+ given: ["Tool exists", "Tool has configuration error"],
2148
+ when: ["User runs test"],
2149
+ then: ["TOOL_EXECUTION_ERROR is returned"]
2150
+ }
2151
+ ],
2152
+ examples: [
2153
+ {
2154
+ key: "test-weather-api",
2155
+ input: { toolId: "tool-123", testInput: { city: "Paris" } },
2156
+ output: { success: true, output: { temperature: 22 }, durationMs: 150 }
2157
+ }
2158
+ ]
2159
+ }
2160
+ });
2161
+
298
2162
  // src/handlers/agent.handlers.ts
299
2163
  import { web } from "@contractspec/lib.runtime-sandbox";
300
2164
  var { generateId } = web;
2165
+ var RUN_SORT_COLUMNS = {
2166
+ queuedAt: "r.queuedAt",
2167
+ totalTokens: "r.totalTokens",
2168
+ durationMs: "r.durationMs",
2169
+ estimatedCostUsd: "r.estimatedCostUsd",
2170
+ status: "r.status",
2171
+ agentName: "a.name"
2172
+ };
301
2173
  function rowToAgent(row) {
302
2174
  return {
303
2175
  id: row.id,
@@ -477,7 +2349,15 @@ function createAgentHandlers(db) {
477
2349
  };
478
2350
  }
479
2351
  async function listRuns(input) {
480
- const { projectId, agentId, status, limit = 20, offset = 0 } = input;
2352
+ const {
2353
+ projectId,
2354
+ agentId,
2355
+ status,
2356
+ sortBy,
2357
+ sortDirection = "desc",
2358
+ limit = 20,
2359
+ offset = 0
2360
+ } = input;
481
2361
  let whereClause = "WHERE r.projectId = ?";
482
2362
  const params = [projectId];
483
2363
  if (agentId) {
@@ -490,11 +2370,13 @@ function createAgentHandlers(db) {
490
2370
  }
491
2371
  const countResult = (await db.query(`SELECT COUNT(*) as count FROM agent_run r ${whereClause}`, params)).rows;
492
2372
  const total = countResult[0]?.count ?? 0;
2373
+ const sortColumn = sortBy ? RUN_SORT_COLUMNS[sortBy] : RUN_SORT_COLUMNS.queuedAt;
2374
+ const direction = sortDirection === "asc" ? "ASC" : "DESC";
493
2375
  const rows = (await db.query(`SELECT r.*, a.name as agentName
494
2376
  FROM agent_run r
495
2377
  LEFT JOIN agent_definition a ON r.agentId = a.id
496
2378
  ${whereClause}
497
- ORDER BY r.queuedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
2379
+ ORDER BY ${sortColumn} ${direction}, r.queuedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
498
2380
  return {
499
2381
  items: rows.map((r) => rowToRun(r, r.agentName)),
500
2382
  total,
@@ -567,6 +2449,7 @@ var MOCK_RUNS = [
567
2449
  {
568
2450
  id: "run-1",
569
2451
  organizationId: "demo-org",
2452
+ projectId: "demo-project",
570
2453
  agentId: "agent-1",
571
2454
  agentName: "Customer Support Bot",
572
2455
  userId: "user-1",
@@ -589,6 +2472,7 @@ var MOCK_RUNS = [
589
2472
  {
590
2473
  id: "run-2",
591
2474
  organizationId: "demo-org",
2475
+ projectId: "demo-project",
592
2476
  agentId: "agent-2",
593
2477
  agentName: "Code Review Assistant",
594
2478
  userId: "user-2",
@@ -606,6 +2490,7 @@ var MOCK_RUNS = [
606
2490
  {
607
2491
  id: "run-3",
608
2492
  organizationId: "demo-org",
2493
+ projectId: "demo-project",
609
2494
  agentId: "agent-1",
610
2495
  agentName: "Customer Support Bot",
611
2496
  userId: "user-1",
@@ -627,6 +2512,7 @@ var MOCK_RUNS = [
627
2512
  {
628
2513
  id: "run-4",
629
2514
  organizationId: "demo-org",
2515
+ projectId: "demo-project",
630
2516
  agentId: "agent-3",
631
2517
  agentName: "Data Analyst",
632
2518
  userId: "user-3",
@@ -648,6 +2534,7 @@ var MOCK_RUNS = [
648
2534
  {
649
2535
  id: "run-5",
650
2536
  organizationId: "demo-org",
2537
+ projectId: "demo-project",
651
2538
  agentId: "agent-2",
652
2539
  agentName: "Code Review Assistant",
653
2540
  userId: "user-2",
@@ -669,6 +2556,7 @@ var MOCK_RUNS = [
669
2556
  ];
670
2557
 
671
2558
  // src/run/run.handler.ts
2559
+ var nextMockRunId = MOCK_RUNS.length + 1;
672
2560
  async function mockListRunsHandler(input) {
673
2561
  const { agentId, status, limit = 20, offset = 0 } = input;
674
2562
  let filtered = [...MOCK_RUNS];
@@ -717,7 +2605,7 @@ async function mockExecuteAgentHandler(input) {
717
2605
  if (agent.status !== "ACTIVE")
718
2606
  throw new Error("AGENT_NOT_ACTIVE");
719
2607
  return {
720
- runId: `run-${Date.now()}`,
2608
+ runId: `run-${nextMockRunId++}`,
721
2609
  status: "QUEUED",
722
2610
  estimatedWaitMs: 500
723
2611
  };
@@ -732,6 +2620,7 @@ async function mockCancelRunHandler(input) {
732
2620
  }
733
2621
 
734
2622
  // src/tool/tool.handler.ts
2623
+ var nextMockToolId = MOCK_TOOLS.length + 1;
735
2624
  async function mockListToolsHandler(input) {
736
2625
  const {
737
2626
  organizationId,
@@ -774,7 +2663,7 @@ async function mockCreateToolHandler(input) {
774
2663
  if (exists)
775
2664
  throw new Error("SLUG_EXISTS");
776
2665
  return {
777
- id: `tool-${Date.now()}`,
2666
+ id: `tool-${nextMockToolId++}`,
778
2667
  name: input.name,
779
2668
  slug: input.slug,
780
2669
  status: "DRAFT"
@@ -795,12 +2684,256 @@ async function mockTestToolHandler(input) {
795
2684
  const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
796
2685
  if (!tool)
797
2686
  throw new Error("TOOL_NOT_FOUND");
798
- const startTime = Date.now();
799
2687
  await new Promise((resolve) => setTimeout(resolve, 100));
800
2688
  return {
801
2689
  success: true,
802
2690
  output: { result: "Test successful", input: input.testInput },
803
- durationMs: Date.now() - startTime
2691
+ durationMs: 100
2692
+ };
2693
+ }
2694
+ // src/shared/demo-runtime-seed.ts
2695
+ var AGENT_CONSOLE_DEMO_ORGANIZATION_ID = "demo-org";
2696
+ var AGENT_CONSOLE_DEMO_PROJECT_ID = "agent-console-demo";
2697
+ function slugify(name) {
2698
+ return name.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
2699
+ }
2700
+ function cloneAgent(agent) {
2701
+ return { ...agent };
2702
+ }
2703
+ function cloneTool(tool) {
2704
+ return { ...tool };
2705
+ }
2706
+ function cloneRun(run) {
2707
+ return { ...run };
2708
+ }
2709
+ function createDefaultNow() {
2710
+ let tick = 0;
2711
+ const base = Date.parse("2026-03-20T09:00:00.000Z");
2712
+ return () => new Date(base + tick++ * 60000);
2713
+ }
2714
+ function normalizeProvider(provider) {
2715
+ return provider.toLowerCase();
2716
+ }
2717
+ function normalizeRunStatus(status) {
2718
+ return status === "IN_PROGRESS" ? "RUNNING" : status;
2719
+ }
2720
+ function createSeedState(projectId, organizationId) {
2721
+ const agents = MOCK_AGENTS.map((agent) => ({
2722
+ id: agent.id,
2723
+ projectId,
2724
+ organizationId,
2725
+ name: agent.name,
2726
+ slug: agent.slug,
2727
+ description: agent.description,
2728
+ modelProvider: normalizeProvider(agent.modelProvider),
2729
+ modelName: agent.modelName,
2730
+ systemPrompt: agent.systemPrompt,
2731
+ temperature: typeof agent.modelConfig?.temperature === "number" ? agent.modelConfig.temperature : 0.4,
2732
+ maxTokens: 8192,
2733
+ status: agent.status,
2734
+ createdAt: agent.createdAt,
2735
+ updatedAt: agent.updatedAt
2736
+ }));
2737
+ const tools = MOCK_TOOLS.map((tool) => ({
2738
+ id: tool.id,
2739
+ projectId,
2740
+ organizationId,
2741
+ name: tool.name,
2742
+ description: tool.description,
2743
+ version: tool.version,
2744
+ category: tool.category,
2745
+ status: tool.status,
2746
+ inputSchema: JSON.stringify(tool.parametersSchema),
2747
+ outputSchema: tool.outputSchema ? JSON.stringify(tool.outputSchema) : undefined,
2748
+ endpoint: typeof tool.implementationConfig?.url === "string" ? tool.implementationConfig.url : undefined,
2749
+ createdAt: tool.createdAt,
2750
+ updatedAt: tool.updatedAt
2751
+ }));
2752
+ const agentNames = new Map(agents.map((agent) => [agent.id, agent.name]));
2753
+ const runs = MOCK_RUNS.map((run) => ({
2754
+ id: run.id,
2755
+ projectId,
2756
+ agentId: run.agentId,
2757
+ agentName: agentNames.get(run.agentId) ?? run.agentName ?? "Unknown agent",
2758
+ status: normalizeRunStatus(run.status),
2759
+ input: JSON.stringify(run.input),
2760
+ output: run.output ? JSON.stringify(run.output) : undefined,
2761
+ totalTokens: run.totalTokens,
2762
+ promptTokens: run.promptTokens,
2763
+ completionTokens: run.completionTokens,
2764
+ estimatedCostUsd: run.estimatedCostUsd ?? 0,
2765
+ durationMs: run.durationMs,
2766
+ errorMessage: run.errorMessage,
2767
+ queuedAt: run.queuedAt,
2768
+ startedAt: run.startedAt,
2769
+ completedAt: run.completedAt
2770
+ }));
2771
+ return { agents, tools, runs };
2772
+ }
2773
+ function summarizeRunMetrics(runs) {
2774
+ const totalRuns = runs.length;
2775
+ const completedRuns = runs.filter((run) => run.status === "COMPLETED").length;
2776
+ const completedDurations = runs.map((run) => run.durationMs).filter((duration) => typeof duration === "number");
2777
+ return {
2778
+ totalRuns,
2779
+ successRate: totalRuns === 0 ? 0 : completedRuns / totalRuns,
2780
+ averageDurationMs: completedDurations.length === 0 ? 0 : Math.round(completedDurations.reduce((sum, duration) => sum + duration, 0) / completedDurations.length),
2781
+ totalTokens: runs.reduce((sum, run) => sum + run.totalTokens, 0),
2782
+ totalCostUsd: runs.reduce((sum, run) => sum + run.estimatedCostUsd, 0)
2783
+ };
2784
+ }
2785
+
2786
+ // src/shared/demo-runtime.ts
2787
+ function createAgentConsoleDemoHandlers(options) {
2788
+ const projectId = options.projectId;
2789
+ const organizationId = options.organizationId ?? AGENT_CONSOLE_DEMO_ORGANIZATION_ID;
2790
+ const now = options.now ?? createDefaultNow();
2791
+ const state = createSeedState(projectId, organizationId);
2792
+ let agentIndex = state.agents.length + 1;
2793
+ let runIndex = state.runs.length + 1;
2794
+ const nextId = (kind) => {
2795
+ const nextIndex = kind === "agent" ? agentIndex++ : runIndex++;
2796
+ return options.idFactory?.(kind, nextIndex) ?? `${kind}-demo-${nextIndex}`;
2797
+ };
2798
+ return {
2799
+ async listAgents(input) {
2800
+ const filtered = state.agents.filter((agent) => agent.projectId === input.projectId).filter((agent) => !input.organizationId || agent.organizationId === input.organizationId).filter((agent) => !input.status || input.status === "all" || agent.status === input.status).filter((agent) => {
2801
+ if (!input.search)
2802
+ return true;
2803
+ const query = input.search.toLowerCase();
2804
+ return agent.name.toLowerCase().includes(query) || (agent.description ?? "").toLowerCase().includes(query);
2805
+ }).sort((left, right) => right.updatedAt.getTime() - left.updatedAt.getTime());
2806
+ const limit = input.limit ?? 20;
2807
+ const offset = input.offset ?? 0;
2808
+ const items = filtered.slice(offset, offset + limit).map(cloneAgent);
2809
+ return {
2810
+ items,
2811
+ total: filtered.length,
2812
+ hasMore: offset + items.length < filtered.length
2813
+ };
2814
+ },
2815
+ async getAgent(id) {
2816
+ const agent = state.agents.find((item) => item.id === id);
2817
+ return agent ? cloneAgent(agent) : null;
2818
+ },
2819
+ async createAgent(input, context) {
2820
+ const name = input.name.trim();
2821
+ const slug = slugify(name);
2822
+ const duplicate = state.agents.find((agent2) => agent2.projectId === context.projectId && agent2.organizationId === context.organizationId && (agent2.slug === slug || agent2.name.toLowerCase() === name.toLowerCase()));
2823
+ if (duplicate)
2824
+ throw new Error("AGENT_NAME_OR_SLUG_EXISTS");
2825
+ const timestamp = now();
2826
+ const agent = {
2827
+ id: nextId("agent"),
2828
+ projectId: context.projectId,
2829
+ organizationId: context.organizationId,
2830
+ name,
2831
+ slug,
2832
+ description: input.description,
2833
+ modelProvider: input.modelProvider ?? "openai",
2834
+ modelName: input.modelName ?? "gpt-5.4",
2835
+ systemPrompt: input.systemPrompt,
2836
+ temperature: input.temperature ?? 0.4,
2837
+ maxTokens: input.maxTokens ?? 8192,
2838
+ status: "DRAFT",
2839
+ createdAt: timestamp,
2840
+ updatedAt: timestamp
2841
+ };
2842
+ state.agents.unshift(agent);
2843
+ return cloneAgent(agent);
2844
+ },
2845
+ async updateAgent(input) {
2846
+ const agent = state.agents.find((item) => item.id === input.id);
2847
+ if (!agent)
2848
+ throw new Error("AGENT_NOT_FOUND");
2849
+ const nextName = input.name;
2850
+ if (nextName && slugify(nextName) !== agent.slug) {
2851
+ const duplicate = state.agents.find((item) => item.id !== agent.id && item.projectId === agent.projectId && item.organizationId === agent.organizationId && (item.slug === slugify(nextName) || item.name.toLowerCase() === nextName.toLowerCase()));
2852
+ if (duplicate)
2853
+ throw new Error("AGENT_NAME_OR_SLUG_EXISTS");
2854
+ agent.slug = slugify(nextName);
2855
+ agent.name = nextName;
2856
+ }
2857
+ if (input.description !== undefined)
2858
+ agent.description = input.description;
2859
+ if (input.status)
2860
+ agent.status = input.status;
2861
+ agent.updatedAt = now();
2862
+ return cloneAgent(agent);
2863
+ },
2864
+ async executeAgent(input) {
2865
+ const agent = state.agents.find((item) => item.id === input.agentId);
2866
+ if (!agent)
2867
+ throw new Error("AGENT_NOT_FOUND");
2868
+ if (agent.status !== "ACTIVE")
2869
+ throw new Error("AGENT_NOT_ACTIVE");
2870
+ const queuedAt = now();
2871
+ const startedAt = now();
2872
+ const completedAt = now();
2873
+ const durationMs = 2200 + input.message.length * 12;
2874
+ const promptTokens = 600 + input.message.length * 3;
2875
+ const completionTokens = 240 + agent.name.length * 4;
2876
+ const run = {
2877
+ id: nextId("run"),
2878
+ projectId: input.context?.projectId ?? agent.projectId,
2879
+ agentId: agent.id,
2880
+ agentName: agent.name,
2881
+ status: "COMPLETED",
2882
+ input: input.message,
2883
+ output: `Deterministic demo reply from ${agent.name}: ${input.message}`,
2884
+ totalTokens: promptTokens + completionTokens,
2885
+ promptTokens,
2886
+ completionTokens,
2887
+ estimatedCostUsd: Number(((promptTokens + completionTokens) / 1e6).toFixed(4)),
2888
+ durationMs,
2889
+ queuedAt,
2890
+ startedAt,
2891
+ completedAt
2892
+ };
2893
+ state.runs.unshift(run);
2894
+ return cloneRun(run);
2895
+ },
2896
+ async listTools(input) {
2897
+ const filtered = state.tools.filter((tool) => tool.projectId === input.projectId).filter((tool) => !input.organizationId || tool.organizationId === input.organizationId).filter((tool) => !input.category || input.category === "all" || tool.category === input.category).filter((tool) => !input.status || input.status === "all" || tool.status === input.status).filter((tool) => {
2898
+ if (!input.search)
2899
+ return true;
2900
+ const query = input.search.toLowerCase();
2901
+ return tool.name.toLowerCase().includes(query) || (tool.description ?? "").toLowerCase().includes(query);
2902
+ }).sort((left, right) => left.name.localeCompare(right.name));
2903
+ const limit = input.limit ?? 50;
2904
+ const offset = input.offset ?? 0;
2905
+ const items = filtered.slice(offset, offset + limit).map(cloneTool);
2906
+ return {
2907
+ items,
2908
+ total: filtered.length,
2909
+ hasMore: offset + items.length < filtered.length
2910
+ };
2911
+ },
2912
+ async listRuns(input) {
2913
+ const filtered = state.runs.filter((run) => run.projectId === input.projectId).filter((run) => !input.agentId || run.agentId === input.agentId).filter((run) => !input.status || input.status === "all" || run.status === input.status).sort((left, right) => right.queuedAt.getTime() - left.queuedAt.getTime());
2914
+ const limit = input.limit ?? 20;
2915
+ const offset = input.offset ?? 0;
2916
+ const items = filtered.slice(offset, offset + limit).map(cloneRun);
2917
+ return {
2918
+ items,
2919
+ total: filtered.length,
2920
+ hasMore: offset + items.length < filtered.length
2921
+ };
2922
+ },
2923
+ async getRunMetrics(input) {
2924
+ const filtered = state.runs.filter((run) => {
2925
+ if (run.projectId !== input.projectId)
2926
+ return false;
2927
+ if (input.agentId && run.agentId !== input.agentId)
2928
+ return false;
2929
+ if (input.startDate && run.queuedAt < input.startDate)
2930
+ return false;
2931
+ if (input.endDate && run.queuedAt > input.endDate)
2932
+ return false;
2933
+ return true;
2934
+ });
2935
+ return summarizeRunMetrics(filtered);
2936
+ }
804
2937
  };
805
2938
  }
806
2939
  export {
@@ -813,5 +2946,6 @@ export {
813
2946
  mockExecuteAgentHandler,
814
2947
  mockCreateToolHandler,
815
2948
  mockCreateAgentHandler,
816
- createAgentHandlers
2949
+ createAgentHandlers,
2950
+ createAgentConsoleDemoHandlers
817
2951
  };