@contractspec/example.agent-console 1.44.0

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 (168) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +133 -0
  2. package/.turbo/turbo-build.log +134 -0
  3. package/CHANGELOG.md +212 -0
  4. package/LICENSE +21 -0
  5. package/README.md +86 -0
  6. package/dist/agent/agent.entity.d.ts +55 -0
  7. package/dist/agent/agent.entity.d.ts.map +1 -0
  8. package/dist/agent/agent.entity.js +136 -0
  9. package/dist/agent/agent.entity.js.map +1 -0
  10. package/dist/agent/agent.enum.d.ts +18 -0
  11. package/dist/agent/agent.enum.d.ts.map +1 -0
  12. package/dist/agent/agent.enum.js +34 -0
  13. package/dist/agent/agent.enum.js.map +1 -0
  14. package/dist/agent/agent.event.d.ts +128 -0
  15. package/dist/agent/agent.event.d.ts.map +1 -0
  16. package/dist/agent/agent.event.js +210 -0
  17. package/dist/agent/agent.event.js.map +1 -0
  18. package/dist/agent/agent.handler.d.ts +100 -0
  19. package/dist/agent/agent.handler.d.ts.map +1 -0
  20. package/dist/agent/agent.handler.js +84 -0
  21. package/dist/agent/agent.handler.js.map +1 -0
  22. package/dist/agent/agent.operation.d.ts +471 -0
  23. package/dist/agent/agent.operation.d.ts.map +1 -0
  24. package/dist/agent/agent.operation.js +486 -0
  25. package/dist/agent/agent.operation.js.map +1 -0
  26. package/dist/agent/agent.presentation.d.ts +19 -0
  27. package/dist/agent/agent.presentation.d.ts.map +1 -0
  28. package/dist/agent/agent.presentation.js +89 -0
  29. package/dist/agent/agent.presentation.js.map +1 -0
  30. package/dist/agent/agent.schema.d.ts +401 -0
  31. package/dist/agent/agent.schema.d.ts.map +1 -0
  32. package/dist/agent/agent.schema.js +406 -0
  33. package/dist/agent/agent.schema.js.map +1 -0
  34. package/dist/agent/index.d.ts +8 -0
  35. package/dist/agent/index.js +9 -0
  36. package/dist/agent.feature.d.ts +12 -0
  37. package/dist/agent.feature.d.ts.map +1 -0
  38. package/dist/agent.feature.js +303 -0
  39. package/dist/agent.feature.js.map +1 -0
  40. package/dist/docs/agent-console.docblock.d.ts +1 -0
  41. package/dist/docs/agent-console.docblock.js +113 -0
  42. package/dist/docs/agent-console.docblock.js.map +1 -0
  43. package/dist/docs/index.d.ts +1 -0
  44. package/dist/docs/index.js +1 -0
  45. package/dist/example.d.ts +40 -0
  46. package/dist/example.d.ts.map +1 -0
  47. package/dist/example.js +51 -0
  48. package/dist/example.js.map +1 -0
  49. package/dist/handlers/index.d.ts +4 -0
  50. package/dist/handlers/index.js +5 -0
  51. package/dist/index.d.ts +30 -0
  52. package/dist/index.js +32 -0
  53. package/dist/presentations/index.d.ts +4 -0
  54. package/dist/presentations/index.js +5 -0
  55. package/dist/run/index.d.ts +8 -0
  56. package/dist/run/index.js +9 -0
  57. package/dist/run/run.entity.d.ts +82 -0
  58. package/dist/run/run.entity.d.ts.map +1 -0
  59. package/dist/run/run.entity.js +205 -0
  60. package/dist/run/run.entity.js.map +1 -0
  61. package/dist/run/run.enum.d.ts +22 -0
  62. package/dist/run/run.enum.d.ts.map +1 -0
  63. package/dist/run/run.enum.js +45 -0
  64. package/dist/run/run.enum.js.map +1 -0
  65. package/dist/run/run.event.d.ts +290 -0
  66. package/dist/run/run.event.d.ts.map +1 -0
  67. package/dist/run/run.event.js +434 -0
  68. package/dist/run/run.event.js.map +1 -0
  69. package/dist/run/run.handler.d.ts +203 -0
  70. package/dist/run/run.handler.d.ts.map +1 -0
  71. package/dist/run/run.handler.js +83 -0
  72. package/dist/run/run.handler.js.map +1 -0
  73. package/dist/run/run.operation.d.ts +720 -0
  74. package/dist/run/run.operation.d.ts.map +1 -0
  75. package/dist/run/run.operation.js +626 -0
  76. package/dist/run/run.operation.js.map +1 -0
  77. package/dist/run/run.presentation.d.ts +15 -0
  78. package/dist/run/run.presentation.d.ts.map +1 -0
  79. package/dist/run/run.presentation.js +65 -0
  80. package/dist/run/run.presentation.js.map +1 -0
  81. package/dist/run/run.schema.d.ts +416 -0
  82. package/dist/run/run.schema.d.ts.map +1 -0
  83. package/dist/run/run.schema.js +338 -0
  84. package/dist/run/run.schema.js.map +1 -0
  85. package/dist/shared/index.d.ts +4 -0
  86. package/dist/shared/index.js +5 -0
  87. package/dist/shared/mock-agents.d.ts +88 -0
  88. package/dist/shared/mock-agents.d.ts.map +1 -0
  89. package/dist/shared/mock-agents.js +94 -0
  90. package/dist/shared/mock-agents.js.map +1 -0
  91. package/dist/shared/mock-runs.d.ts +120 -0
  92. package/dist/shared/mock-runs.d.ts.map +1 -0
  93. package/dist/shared/mock-runs.js +118 -0
  94. package/dist/shared/mock-runs.js.map +1 -0
  95. package/dist/shared/mock-tools.d.ts +244 -0
  96. package/dist/shared/mock-tools.d.ts.map +1 -0
  97. package/dist/shared/mock-tools.js +181 -0
  98. package/dist/shared/mock-tools.js.map +1 -0
  99. package/dist/tool/index.d.ts +8 -0
  100. package/dist/tool/index.js +9 -0
  101. package/dist/tool/tool.entity.d.ts +42 -0
  102. package/dist/tool/tool.entity.d.ts.map +1 -0
  103. package/dist/tool/tool.entity.js +105 -0
  104. package/dist/tool/tool.entity.js.map +1 -0
  105. package/dist/tool/tool.enum.d.ts +18 -0
  106. package/dist/tool/tool.enum.d.ts.map +1 -0
  107. package/dist/tool/tool.enum.js +35 -0
  108. package/dist/tool/tool.enum.js.map +1 -0
  109. package/dist/tool/tool.event.d.ts +103 -0
  110. package/dist/tool/tool.event.d.ts.map +1 -0
  111. package/dist/tool/tool.event.js +159 -0
  112. package/dist/tool/tool.event.js.map +1 -0
  113. package/dist/tool/tool.handler.d.ts +315 -0
  114. package/dist/tool/tool.handler.d.ts.map +1 -0
  115. package/dist/tool/tool.handler.js +87 -0
  116. package/dist/tool/tool.handler.js.map +1 -0
  117. package/dist/tool/tool.operation.d.ts +411 -0
  118. package/dist/tool/tool.operation.d.ts.map +1 -0
  119. package/dist/tool/tool.operation.js +406 -0
  120. package/dist/tool/tool.operation.js.map +1 -0
  121. package/dist/tool/tool.presentation.d.ts +15 -0
  122. package/dist/tool/tool.presentation.d.ts.map +1 -0
  123. package/dist/tool/tool.presentation.js +65 -0
  124. package/dist/tool/tool.presentation.js.map +1 -0
  125. package/dist/tool/tool.schema.d.ts +218 -0
  126. package/dist/tool/tool.schema.d.ts.map +1 -0
  127. package/dist/tool/tool.schema.js +236 -0
  128. package/dist/tool/tool.schema.js.map +1 -0
  129. package/example.ts +1 -0
  130. package/package.json +123 -0
  131. package/src/agent/agent.entity.ts +137 -0
  132. package/src/agent/agent.enum.ts +31 -0
  133. package/src/agent/agent.event.ts +142 -0
  134. package/src/agent/agent.handler.ts +178 -0
  135. package/src/agent/agent.operation.ts +444 -0
  136. package/src/agent/agent.presentation.ts +81 -0
  137. package/src/agent/agent.schema.ts +214 -0
  138. package/src/agent/index.ts +67 -0
  139. package/src/agent.feature.ts +146 -0
  140. package/src/docs/agent-console.docblock.ts +97 -0
  141. package/src/docs/index.ts +1 -0
  142. package/src/example.ts +34 -0
  143. package/src/handlers/index.ts +27 -0
  144. package/src/index.ts +27 -0
  145. package/src/presentations/index.ts +26 -0
  146. package/src/run/index.ts +68 -0
  147. package/src/run/run.entity.ts +175 -0
  148. package/src/run/run.enum.ts +43 -0
  149. package/src/run/run.event.ts +264 -0
  150. package/src/run/run.handler.ts +138 -0
  151. package/src/run/run.operation.ts +524 -0
  152. package/src/run/run.presentation.ts +55 -0
  153. package/src/run/run.schema.ts +169 -0
  154. package/src/shared/index.ts +6 -0
  155. package/src/shared/mock-agents.ts +81 -0
  156. package/src/shared/mock-runs.ts +107 -0
  157. package/src/shared/mock-tools.ts +145 -0
  158. package/src/tool/index.ts +60 -0
  159. package/src/tool/tool.entity.ts +99 -0
  160. package/src/tool/tool.enum.ts +32 -0
  161. package/src/tool/tool.event.ts +119 -0
  162. package/src/tool/tool.handler.ts +154 -0
  163. package/src/tool/tool.operation.ts +366 -0
  164. package/src/tool/tool.presentation.ts +56 -0
  165. package/src/tool/tool.schema.ts +133 -0
  166. package/tsconfig.json +10 -0
  167. package/tsconfig.tsbuildinfo +1 -0
  168. package/tsdown.config.js +7 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Run domain - Agent execution and monitoring.
3
+ */
4
+
5
+ // Enums
6
+ export {
7
+ RunStatusEnum,
8
+ RunStepTypeEnum,
9
+ LogLevelEnum,
10
+ GranularityEnum,
11
+ } from './run.enum';
12
+
13
+ // Schema models
14
+ export {
15
+ RunInputModel,
16
+ RunStepModel,
17
+ RunLogModel,
18
+ RunAgentRefModel,
19
+ RunModel,
20
+ RunSummaryModel,
21
+ TimelineDataPointModel,
22
+ } from './run.schema';
23
+
24
+ // Contracts
25
+ export {
26
+ ExecuteAgentCommand,
27
+ CancelRunCommand,
28
+ GetRunQuery,
29
+ ListRunsQuery,
30
+ GetRunStepsQuery,
31
+ GetRunLogsQuery,
32
+ GetRunMetricsQuery,
33
+ } from './run.operation';
34
+
35
+ // Events
36
+ export {
37
+ RunStartedEvent,
38
+ RunCompletedEvent,
39
+ RunFailedEvent,
40
+ RunCancelledEvent,
41
+ ToolInvokedEvent,
42
+ ToolCompletedEvent,
43
+ MessageGeneratedEvent,
44
+ } from './run.event';
45
+
46
+ // Entities
47
+ export {
48
+ RunStatusEntityEnum,
49
+ RunStepTypeEntityEnum,
50
+ LogLevelEntityEnum,
51
+ RunEntity,
52
+ RunStepEntity,
53
+ RunLogEntity,
54
+ } from './run.entity';
55
+
56
+ // Presentations
57
+ export { RunListPresentation, RunDetailPresentation } from './run.presentation';
58
+
59
+ // Handlers
60
+ export {
61
+ mockListRunsHandler,
62
+ mockGetRunHandler,
63
+ mockExecuteAgentHandler,
64
+ mockCancelRunHandler,
65
+ type ListRunsInput,
66
+ type RunSummary,
67
+ type ListRunsOutput,
68
+ } from './run.handler';
@@ -0,0 +1,175 @@
1
+ import {
2
+ defineEntity,
3
+ defineEntityEnum,
4
+ field,
5
+ index,
6
+ } from '@contractspec/lib.schema';
7
+
8
+ /**
9
+ * Run status enum for entities.
10
+ */
11
+ export const RunStatusEntityEnum = defineEntityEnum({
12
+ name: 'RunStatus',
13
+ values: [
14
+ 'QUEUED',
15
+ 'IN_PROGRESS',
16
+ 'COMPLETED',
17
+ 'FAILED',
18
+ 'CANCELLED',
19
+ 'EXPIRED',
20
+ ],
21
+ description: 'Status of an agent run',
22
+ });
23
+
24
+ /**
25
+ * Run step type enum for entities.
26
+ */
27
+ export const RunStepTypeEntityEnum = defineEntityEnum({
28
+ name: 'RunStepType',
29
+ values: ['MESSAGE_CREATION', 'TOOL_CALL', 'TOOL_RESULT', 'ERROR'],
30
+ description: 'Type of run step',
31
+ });
32
+
33
+ /**
34
+ * Log level enum for entities.
35
+ */
36
+ export const LogLevelEntityEnum = defineEntityEnum({
37
+ name: 'LogLevel',
38
+ values: ['DEBUG', 'INFO', 'WARN', 'ERROR'],
39
+ description: 'Log level',
40
+ });
41
+
42
+ /**
43
+ * Run entity - Represents an agent execution.
44
+ */
45
+ export const RunEntity = defineEntity({
46
+ name: 'Run',
47
+ schema: 'agent_console',
48
+ description: 'An execution of an agent with input/output and metrics.',
49
+ fields: {
50
+ id: field.id(),
51
+ organizationId: field.string({ description: 'Organization ID' }),
52
+ agentId: field.foreignKey({ description: 'Agent being executed' }),
53
+ userId: field.string({
54
+ isOptional: true,
55
+ description: 'User who initiated the run',
56
+ }),
57
+ sessionId: field.string({
58
+ isOptional: true,
59
+ description: 'Conversation session ID',
60
+ }),
61
+ input: field.json({ description: 'Input data for the run' }),
62
+ output: field.json({
63
+ isOptional: true,
64
+ description: 'Output result from the run',
65
+ }),
66
+ status: field.enum('RunStatus', { default: 'QUEUED' }),
67
+ errorMessage: field.string({
68
+ isOptional: true,
69
+ description: 'Error message if failed',
70
+ }),
71
+ errorCode: field.string({
72
+ isOptional: true,
73
+ description: 'Error code if failed',
74
+ }),
75
+ totalTokens: field.int({ default: 0, description: 'Total tokens used' }),
76
+ promptTokens: field.int({ default: 0, description: 'Prompt tokens used' }),
77
+ completionTokens: field.int({
78
+ default: 0,
79
+ description: 'Completion tokens used',
80
+ }),
81
+ totalIterations: field.int({
82
+ default: 0,
83
+ description: 'Number of iterations',
84
+ }),
85
+ durationMs: field.int({
86
+ isOptional: true,
87
+ description: 'Execution duration in ms',
88
+ }),
89
+ estimatedCostUsd: field.float({
90
+ isOptional: true,
91
+ description: 'Estimated cost in USD',
92
+ }),
93
+ queuedAt: field.dateTime({ description: 'When run was queued' }),
94
+ startedAt: field.dateTime({
95
+ isOptional: true,
96
+ description: 'When run started executing',
97
+ }),
98
+ completedAt: field.dateTime({
99
+ isOptional: true,
100
+ description: 'When run completed',
101
+ }),
102
+ metadata: field.json({
103
+ isOptional: true,
104
+ description: 'Additional metadata',
105
+ }),
106
+ agent: field.belongsTo('Agent', ['agentId'], ['id']),
107
+ steps: field.hasMany('RunStep', { description: 'Execution steps' }),
108
+ logs: field.hasMany('RunLog', { description: 'Execution logs' }),
109
+ },
110
+ indexes: [
111
+ index.on(['organizationId', 'agentId', 'queuedAt']),
112
+ index.on(['organizationId', 'status']),
113
+ index.on(['agentId', 'status']),
114
+ index.on(['sessionId']),
115
+ ],
116
+ enums: [RunStatusEntityEnum],
117
+ });
118
+
119
+ /**
120
+ * RunStep entity - Individual step in a run.
121
+ */
122
+ export const RunStepEntity = defineEntity({
123
+ name: 'RunStep',
124
+ schema: 'agent_console',
125
+ description: 'An individual step in an agent run.',
126
+ fields: {
127
+ id: field.id(),
128
+ runId: field.foreignKey({ description: 'Parent run' }),
129
+ stepNumber: field.int({ description: 'Step sequence number' }),
130
+ type: field.enum('RunStepType'),
131
+ toolId: field.string({
132
+ isOptional: true,
133
+ description: 'Tool used in this step',
134
+ }),
135
+ toolName: field.string({ isOptional: true, description: 'Tool name' }),
136
+ input: field.json({ isOptional: true, description: 'Step input' }),
137
+ output: field.json({ isOptional: true, description: 'Step output' }),
138
+ status: field.enum('RunStatus'),
139
+ errorMessage: field.string({ isOptional: true }),
140
+ tokensUsed: field.int({ default: 0 }),
141
+ durationMs: field.int({ isOptional: true }),
142
+ startedAt: field.dateTime(),
143
+ completedAt: field.dateTime({ isOptional: true }),
144
+ run: field.belongsTo('Run', ['runId'], ['id']),
145
+ },
146
+ indexes: [index.on(['runId', 'stepNumber'])],
147
+ enums: [RunStepTypeEntityEnum],
148
+ });
149
+
150
+ /**
151
+ * RunLog entity - Log entry for a run.
152
+ */
153
+ export const RunLogEntity = defineEntity({
154
+ name: 'RunLog',
155
+ schema: 'agent_console',
156
+ description: 'A log entry for an agent run.',
157
+ fields: {
158
+ id: field.id(),
159
+ runId: field.foreignKey({ description: 'Parent run' }),
160
+ stepId: field.string({ isOptional: true, description: 'Related step' }),
161
+ level: field.enum('LogLevel'),
162
+ message: field.string({ description: 'Log message' }),
163
+ data: field.json({ isOptional: true, description: 'Additional log data' }),
164
+ source: field.string({
165
+ isOptional: true,
166
+ description: 'Log source component',
167
+ }),
168
+ traceId: field.string({ isOptional: true }),
169
+ spanId: field.string({ isOptional: true }),
170
+ timestamp: field.dateTime(),
171
+ run: field.belongsTo('Run', ['runId'], ['id']),
172
+ },
173
+ indexes: [index.on(['runId', 'timestamp']), index.on(['runId', 'level'])],
174
+ enums: [LogLevelEntityEnum],
175
+ });
@@ -0,0 +1,43 @@
1
+ import { defineEnum } from '@contractspec/lib.schema';
2
+
3
+ /**
4
+ * Run status enum.
5
+ */
6
+ export const RunStatusEnum = defineEnum('RunStatus', [
7
+ 'QUEUED',
8
+ 'IN_PROGRESS',
9
+ 'COMPLETED',
10
+ 'FAILED',
11
+ 'CANCELLED',
12
+ 'EXPIRED',
13
+ ]);
14
+
15
+ /**
16
+ * Run step type enum.
17
+ */
18
+ export const RunStepTypeEnum = defineEnum('RunStepType', [
19
+ 'MESSAGE_CREATION',
20
+ 'TOOL_CALL',
21
+ 'TOOL_RESULT',
22
+ 'ERROR',
23
+ ]);
24
+
25
+ /**
26
+ * Log level enum.
27
+ */
28
+ export const LogLevelEnum = defineEnum('LogLevel', [
29
+ 'DEBUG',
30
+ 'INFO',
31
+ 'WARN',
32
+ 'ERROR',
33
+ ]);
34
+
35
+ /**
36
+ * Granularity enum for metrics.
37
+ */
38
+ export const GranularityEnum = defineEnum('Granularity', [
39
+ 'hour',
40
+ 'day',
41
+ 'week',
42
+ 'month',
43
+ ]);
@@ -0,0 +1,264 @@
1
+ import { defineEvent, defineSchemaModel } from '@contractspec/lib.contracts';
2
+ import { ScalarTypeEnum, defineEnum } from '@contractspec/lib.schema';
3
+
4
+ const OWNERS = ['@agent-console-team'] as const;
5
+
6
+ /**
7
+ * Payload for run started event.
8
+ */
9
+ const RunStartedPayload = defineSchemaModel({
10
+ name: 'RunStartedPayload',
11
+ description: 'Payload for run started event',
12
+ fields: {
13
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
14
+ organizationId: {
15
+ type: ScalarTypeEnum.String_unsecure(),
16
+ isOptional: false,
17
+ },
18
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
19
+ agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
20
+ userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
21
+ sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
22
+ input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
23
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
24
+ },
25
+ });
26
+
27
+ /**
28
+ * RunStartedEvent - An agent run was started.
29
+ */
30
+ export const RunStartedEvent = defineEvent({
31
+ meta: {
32
+ key: 'agent.run.started',
33
+ version: 1,
34
+ description: 'An agent run was started.',
35
+ stability: 'stable',
36
+ owners: [...OWNERS],
37
+ tags: ['run', 'started'],
38
+ },
39
+ payload: RunStartedPayload,
40
+ });
41
+
42
+ /**
43
+ * Payload for run completed event.
44
+ */
45
+ const RunCompletedPayload = defineSchemaModel({
46
+ name: 'RunCompletedPayload',
47
+ description: 'Payload for run completed event',
48
+ fields: {
49
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
50
+ organizationId: {
51
+ type: ScalarTypeEnum.String_unsecure(),
52
+ isOptional: false,
53
+ },
54
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
55
+ agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
56
+ userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
57
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
58
+ totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
59
+ promptTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
60
+ completionTokens: {
61
+ type: ScalarTypeEnum.Int_unsecure(),
62
+ isOptional: false,
63
+ },
64
+ totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
65
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
66
+ estimatedCostUsd: {
67
+ type: ScalarTypeEnum.Float_unsecure(),
68
+ isOptional: true,
69
+ },
70
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
71
+ },
72
+ });
73
+
74
+ /**
75
+ * RunCompletedEvent - An agent run completed successfully.
76
+ */
77
+ export const RunCompletedEvent = defineEvent({
78
+ meta: {
79
+ key: 'agent.run.completed',
80
+ version: 1,
81
+ description: 'An agent run completed successfully.',
82
+ stability: 'stable',
83
+ owners: [...OWNERS],
84
+ tags: ['run', 'completed'],
85
+ },
86
+ payload: RunCompletedPayload,
87
+ });
88
+
89
+ /**
90
+ * Payload for run failed event.
91
+ */
92
+ const RunFailedPayload = defineSchemaModel({
93
+ name: 'RunFailedPayload',
94
+ description: 'Payload for run failed event',
95
+ fields: {
96
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
97
+ organizationId: {
98
+ type: ScalarTypeEnum.String_unsecure(),
99
+ isOptional: false,
100
+ },
101
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
102
+ agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
103
+ userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
104
+ errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
105
+ errorCode: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
106
+ totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
107
+ totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
108
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
109
+ failedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
110
+ },
111
+ });
112
+
113
+ /**
114
+ * RunFailedEvent - An agent run failed.
115
+ */
116
+ export const RunFailedEvent = defineEvent({
117
+ meta: {
118
+ key: 'agent.run.failed',
119
+ version: 1,
120
+ description: 'An agent run encountered an error.',
121
+ stability: 'stable',
122
+ owners: [...OWNERS],
123
+ tags: ['run', 'failed'],
124
+ },
125
+ payload: RunFailedPayload,
126
+ });
127
+
128
+ /**
129
+ * Payload for run cancelled event.
130
+ */
131
+ const RunCancelledPayload = defineSchemaModel({
132
+ name: 'RunCancelledPayload',
133
+ description: 'Payload for run cancelled event',
134
+ fields: {
135
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
136
+ organizationId: {
137
+ type: ScalarTypeEnum.String_unsecure(),
138
+ isOptional: false,
139
+ },
140
+ agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
141
+ userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
142
+ cancelledBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
143
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
144
+ totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
145
+ totalIterations: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
146
+ cancelledAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
147
+ },
148
+ });
149
+
150
+ /**
151
+ * RunCancelledEvent - An agent run was cancelled.
152
+ */
153
+ export const RunCancelledEvent = defineEvent({
154
+ meta: {
155
+ key: 'agent.run.cancelled',
156
+ version: 1,
157
+ description: 'An agent run was cancelled by the user.',
158
+ stability: 'stable',
159
+ owners: [...OWNERS],
160
+ tags: ['run', 'cancelled'],
161
+ },
162
+ payload: RunCancelledPayload,
163
+ });
164
+
165
+ /**
166
+ * Payload for tool invoked event.
167
+ */
168
+ const ToolInvokedPayload = defineSchemaModel({
169
+ name: 'ToolInvokedPayload',
170
+ description: 'Payload for tool invoked event',
171
+ fields: {
172
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
173
+ stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
174
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
175
+ toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
176
+ input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
177
+ invokedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
178
+ },
179
+ });
180
+
181
+ /**
182
+ * ToolInvokedEvent - A tool was invoked during a run.
183
+ */
184
+ export const ToolInvokedEvent = defineEvent({
185
+ meta: {
186
+ key: 'agent.run.toolInvoked',
187
+ version: 1,
188
+ description: 'A tool was invoked during an agent run.',
189
+ stability: 'stable',
190
+ owners: [...OWNERS],
191
+ tags: ['run', 'tool', 'invoked'],
192
+ },
193
+ payload: ToolInvokedPayload,
194
+ });
195
+
196
+ /**
197
+ * Payload for tool completed event.
198
+ */
199
+ const ToolCompletedPayload = defineSchemaModel({
200
+ name: 'ToolCompletedPayload',
201
+ description: 'Payload for tool completed event',
202
+ fields: {
203
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
204
+ stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
205
+ toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
206
+ toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
207
+ success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
208
+ output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
209
+ errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
210
+ durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
211
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
212
+ },
213
+ });
214
+
215
+ /**
216
+ * ToolCompletedEvent - A tool invocation completed.
217
+ */
218
+ export const ToolCompletedEvent = defineEvent({
219
+ meta: {
220
+ key: 'agent.run.toolCompleted',
221
+ version: 1,
222
+ description: 'A tool invocation completed during an agent run.',
223
+ stability: 'stable',
224
+ owners: [...OWNERS],
225
+ tags: ['run', 'tool', 'completed'],
226
+ },
227
+ payload: ToolCompletedPayload,
228
+ });
229
+
230
+ /**
231
+ * Message type enum.
232
+ */
233
+ const MessageTypeEnum = defineEnum('MessageType', ['assistant', 'system']);
234
+
235
+ /**
236
+ * Payload for message generated event.
237
+ */
238
+ const MessageGeneratedPayload = defineSchemaModel({
239
+ name: 'MessageGeneratedPayload',
240
+ description: 'Payload for message generated event',
241
+ fields: {
242
+ runId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
243
+ stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
244
+ messageType: { type: MessageTypeEnum, isOptional: false },
245
+ content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
246
+ tokensUsed: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
247
+ generatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
248
+ },
249
+ });
250
+
251
+ /**
252
+ * MessageGeneratedEvent - Agent generated a message.
253
+ */
254
+ export const MessageGeneratedEvent = defineEvent({
255
+ meta: {
256
+ key: 'agent.run.messageGenerated',
257
+ version: 1,
258
+ description: 'An agent generated a message during a run.',
259
+ stability: 'stable',
260
+ owners: [...OWNERS],
261
+ tags: ['run', 'message', 'generated'],
262
+ },
263
+ payload: MessageGeneratedPayload,
264
+ });
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Mock handlers for Run contracts.
3
+ */
4
+ import { MOCK_RUNS } from '../shared/mock-runs';
5
+ import { MOCK_AGENTS } from '../shared/mock-agents';
6
+
7
+ export interface ListRunsInput {
8
+ organizationId?: string;
9
+ agentId?: string;
10
+ userId?: string;
11
+ sessionId?: string;
12
+ status?:
13
+ | 'QUEUED'
14
+ | 'IN_PROGRESS'
15
+ | 'COMPLETED'
16
+ | 'FAILED'
17
+ | 'CANCELLED'
18
+ | 'EXPIRED';
19
+ startDate?: Date;
20
+ endDate?: Date;
21
+ limit?: number;
22
+ offset?: number;
23
+ }
24
+
25
+ export interface RunSummary {
26
+ id: string;
27
+ agentId: string;
28
+ agentName: string;
29
+ status:
30
+ | 'QUEUED'
31
+ | 'IN_PROGRESS'
32
+ | 'COMPLETED'
33
+ | 'FAILED'
34
+ | 'CANCELLED'
35
+ | 'EXPIRED';
36
+ totalTokens: number;
37
+ durationMs?: number;
38
+ estimatedCostUsd?: number;
39
+ queuedAt: Date;
40
+ completedAt?: Date;
41
+ }
42
+
43
+ export interface ListRunsOutput {
44
+ items: RunSummary[];
45
+ total: number;
46
+ hasMore: boolean;
47
+ }
48
+
49
+ /**
50
+ * Mock handler for ListRunsQuery.
51
+ */
52
+ export async function mockListRunsHandler(
53
+ input: ListRunsInput
54
+ ): Promise<ListRunsOutput> {
55
+ const { agentId, status, limit = 20, offset = 0 } = input;
56
+
57
+ let filtered = [...MOCK_RUNS];
58
+ if (agentId) filtered = filtered.filter((r) => r.agentId === agentId);
59
+ if (status) filtered = filtered.filter((r) => r.status === status);
60
+
61
+ const total = filtered.length;
62
+ const items = filtered.slice(offset, offset + limit).map((r) => {
63
+ const agent = MOCK_AGENTS.find((a) => a.id === r.agentId);
64
+ return {
65
+ id: r.id,
66
+ agentId: r.agentId,
67
+ agentName: agent?.name ?? 'Unknown',
68
+ status: r.status,
69
+ totalTokens: r.totalTokens,
70
+ durationMs: r.durationMs,
71
+ estimatedCostUsd: r.estimatedCostUsd,
72
+ queuedAt: r.queuedAt,
73
+ completedAt: r.completedAt,
74
+ };
75
+ });
76
+
77
+ return { items, total, hasMore: offset + limit < total };
78
+ }
79
+
80
+ /**
81
+ * Mock handler for GetRunQuery.
82
+ */
83
+ export async function mockGetRunHandler(input: {
84
+ runId: string;
85
+ includeSteps?: boolean;
86
+ includeLogs?: boolean;
87
+ }) {
88
+ const run = MOCK_RUNS.find((r) => r.id === input.runId);
89
+ if (!run) throw new Error('RUN_NOT_FOUND');
90
+
91
+ const agent = MOCK_AGENTS.find((a) => a.id === run.agentId);
92
+ return {
93
+ ...run,
94
+ agent: agent
95
+ ? {
96
+ id: agent.id,
97
+ name: agent.name,
98
+ modelProvider: agent.modelProvider,
99
+ modelName: agent.modelName,
100
+ }
101
+ : undefined,
102
+ steps: input.includeSteps ? run.steps : undefined,
103
+ logs: input.includeLogs ? run.logs : undefined,
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Mock handler for ExecuteAgentCommand.
109
+ */
110
+ export async function mockExecuteAgentHandler(input: {
111
+ agentId: string;
112
+ input: { message: string; context?: Record<string, unknown> };
113
+ }) {
114
+ const agent = MOCK_AGENTS.find((a) => a.id === input.agentId);
115
+ if (!agent) throw new Error('AGENT_NOT_FOUND');
116
+ if (agent.status !== 'ACTIVE') throw new Error('AGENT_NOT_ACTIVE');
117
+
118
+ return {
119
+ runId: `run-${Date.now()}`,
120
+ status: 'QUEUED' as const,
121
+ estimatedWaitMs: 500,
122
+ };
123
+ }
124
+
125
+ /**
126
+ * Mock handler for CancelRunCommand.
127
+ */
128
+ export async function mockCancelRunHandler(input: {
129
+ runId: string;
130
+ reason?: string;
131
+ }) {
132
+ const run = MOCK_RUNS.find((r) => r.id === input.runId);
133
+ if (!run) throw new Error('RUN_NOT_FOUND');
134
+ if (!['QUEUED', 'IN_PROGRESS'].includes(run.status))
135
+ throw new Error('RUN_NOT_CANCELLABLE');
136
+
137
+ return { success: true, status: 'CANCELLED' as const };
138
+ }