@contractspec/example.agent-console 3.8.8 → 3.8.10
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.
- package/.turbo/turbo-build.log +225 -222
- package/CHANGELOG.md +34 -0
- package/dist/agent/agent.entity.js +1 -127
- package/dist/agent/agent.enum.js +1 -25
- package/dist/agent/agent.event.js +1 -116
- package/dist/agent/agent.handler.js +1 -1030
- package/dist/agent/agent.operation.js +1 -735
- package/dist/agent/agent.presentation.js +1 -282
- package/dist/agent/agent.schema.js +1 -215
- package/dist/agent/agent.test-spec.js +1 -58
- package/dist/agent/index.js +1 -1248
- package/dist/agent.capability.js +1 -19
- package/dist/agent.feature.js +1 -305
- package/dist/browser/agent/agent.entity.js +1 -127
- package/dist/browser/agent/agent.enum.js +1 -25
- package/dist/browser/agent/agent.event.js +1 -116
- package/dist/browser/agent/agent.handler.js +1 -1030
- package/dist/browser/agent/agent.operation.js +1 -735
- package/dist/browser/agent/agent.presentation.js +1 -282
- package/dist/browser/agent/agent.schema.js +1 -215
- package/dist/browser/agent/agent.test-spec.js +1 -58
- package/dist/browser/agent/index.js +1 -1248
- package/dist/browser/agent.capability.js +1 -19
- package/dist/browser/agent.feature.js +1 -305
- package/dist/browser/docs/agent-console.docblock.js +5 -49
- package/dist/browser/docs/index.js +5 -49
- package/dist/browser/example.js +1 -41
- package/dist/browser/handlers/agent.handlers.js +6 -2143
- package/dist/browser/handlers/index.js +6 -2943
- package/dist/browser/index.js +14 -6828
- package/dist/browser/presentations/index.js +1 -693
- package/dist/browser/run/index.js +1 -1363
- package/dist/browser/run/run.entity.js +1 -160
- package/dist/browser/run/run.enum.js +1 -34
- package/dist/browser/run/run.event.js +1 -217
- package/dist/browser/run/run.handler.js +1 -919
- package/dist/browser/run/run.operation.js +1 -667
- package/dist/browser/run/run.presentation.js +1 -223
- package/dist/browser/run/run.schema.js +1 -179
- package/dist/browser/run/run.test-spec.js +1 -58
- package/dist/browser/seeders/index.js +2 -21
- package/dist/browser/shared/index.js +1 -626
- package/dist/browser/shared/mock-agents.js +1 -82
- package/dist/browser/shared/mock-runs.js +1 -113
- package/dist/browser/shared/mock-tools.js +1 -146
- package/dist/browser/tool/index.js +1 -949
- package/dist/browser/tool/tool.entity.js +1 -90
- package/dist/browser/tool/tool.enum.js +1 -26
- package/dist/browser/tool/tool.event.js +1 -99
- package/dist/browser/tool/tool.handler.js +1 -699
- package/dist/browser/tool/tool.operation.js +1 -482
- package/dist/browser/tool/tool.presentation.js +1 -188
- package/dist/browser/tool/tool.schema.js +1 -141
- package/dist/browser/tool/tool.test-spec.js +1 -58
- package/dist/browser/ui/AgentDashboard.js +1 -2527
- package/dist/browser/ui/AgentDashboard.visualizations.js +1 -217
- package/dist/browser/ui/AgentRunList.js +1 -482
- package/dist/browser/ui/AgentToolRegistry.js +1 -212
- package/dist/browser/ui/ExecutionConsoleHost.js +1 -0
- package/dist/browser/ui/hooks/index.js +1 -740
- package/dist/browser/ui/hooks/useAgentList.js +1 -55
- package/dist/browser/ui/hooks/useAgentMutations.js +1 -530
- package/dist/browser/ui/hooks/useRunList.js +1 -70
- package/dist/browser/ui/hooks/useToolList.js +1 -85
- package/dist/browser/ui/index.js +5 -3018
- package/dist/browser/ui/modals/AgentActionsModal.js +1 -304
- package/dist/browser/ui/modals/CreateAgentModal.js +1 -243
- package/dist/browser/ui/modals/index.js +1 -546
- package/dist/browser/ui/overlays/demo-overlays.js +1 -64
- package/dist/browser/ui/overlays/index.js +1 -64
- package/dist/browser/ui/renderers/agent-list.markdown.js +2 -64
- package/dist/browser/ui/renderers/agent-list.renderer.js +1 -180
- package/dist/browser/ui/renderers/dashboard.markdown.js +2 -288
- package/dist/browser/ui/renderers/index.js +5 -642
- package/dist/browser/ui/renderers/run-list.markdown.js +2 -50
- package/dist/browser/ui/renderers/tool-registry.markdown.js +2 -64
- package/dist/browser/ui/views/AgentListView.js +1 -165
- package/dist/browser/ui/views/RunDataTable.js +1 -326
- package/dist/browser/ui/views/RunListView.js +1 -479
- package/dist/browser/ui/views/ToolRegistryView.js +1 -209
- package/dist/browser/ui/views/index.js +1 -851
- package/dist/browser/ui/views/run-data-table.columns.js +1 -271
- package/dist/browser/ui/views/run-list.shared.js +1 -177
- package/dist/browser/visualizations/catalog.js +1 -134
- package/dist/browser/visualizations/index.js +1 -187
- package/dist/browser/visualizations/selectors.js +1 -181
- package/dist/docs/agent-console.docblock.js +5 -49
- package/dist/docs/index.js +5 -49
- package/dist/example.js +1 -41
- package/dist/handlers/agent.handlers.js +6 -2143
- package/dist/handlers/index.js +6 -2943
- package/dist/index.js +14 -6828
- package/dist/node/agent/agent.entity.js +1 -127
- package/dist/node/agent/agent.enum.js +1 -25
- package/dist/node/agent/agent.event.js +1 -116
- package/dist/node/agent/agent.handler.js +1 -1030
- package/dist/node/agent/agent.operation.js +1 -735
- package/dist/node/agent/agent.presentation.js +1 -282
- package/dist/node/agent/agent.schema.js +1 -215
- package/dist/node/agent/agent.test-spec.js +1 -58
- package/dist/node/agent/index.js +1 -1248
- package/dist/node/agent.capability.js +1 -19
- package/dist/node/agent.feature.js +1 -305
- package/dist/node/docs/agent-console.docblock.js +5 -49
- package/dist/node/docs/index.js +5 -49
- package/dist/node/example.js +1 -41
- package/dist/node/handlers/agent.handlers.js +6 -2143
- package/dist/node/handlers/index.js +6 -2943
- package/dist/node/index.js +14 -6828
- package/dist/node/presentations/index.js +1 -693
- package/dist/node/run/index.js +1 -1363
- package/dist/node/run/run.entity.js +1 -160
- package/dist/node/run/run.enum.js +1 -34
- package/dist/node/run/run.event.js +1 -217
- package/dist/node/run/run.handler.js +1 -919
- package/dist/node/run/run.operation.js +1 -667
- package/dist/node/run/run.presentation.js +1 -223
- package/dist/node/run/run.schema.js +1 -179
- package/dist/node/run/run.test-spec.js +1 -58
- package/dist/node/seeders/index.js +2 -21
- package/dist/node/shared/index.js +1 -626
- package/dist/node/shared/mock-agents.js +1 -82
- package/dist/node/shared/mock-runs.js +1 -113
- package/dist/node/shared/mock-tools.js +1 -146
- package/dist/node/tool/index.js +1 -949
- package/dist/node/tool/tool.entity.js +1 -90
- package/dist/node/tool/tool.enum.js +1 -26
- package/dist/node/tool/tool.event.js +1 -99
- package/dist/node/tool/tool.handler.js +1 -699
- package/dist/node/tool/tool.operation.js +1 -482
- package/dist/node/tool/tool.presentation.js +1 -188
- package/dist/node/tool/tool.schema.js +1 -141
- package/dist/node/tool/tool.test-spec.js +1 -58
- package/dist/node/ui/AgentDashboard.js +1 -2527
- package/dist/node/ui/AgentDashboard.visualizations.js +1 -217
- package/dist/node/ui/AgentRunList.js +1 -482
- package/dist/node/ui/AgentToolRegistry.js +1 -212
- package/dist/node/ui/ExecutionConsoleHost.js +1 -0
- package/dist/node/ui/hooks/index.js +1 -740
- package/dist/node/ui/hooks/useAgentList.js +1 -55
- package/dist/node/ui/hooks/useAgentMutations.js +1 -530
- package/dist/node/ui/hooks/useRunList.js +1 -70
- package/dist/node/ui/hooks/useToolList.js +1 -85
- package/dist/node/ui/index.js +5 -3018
- package/dist/node/ui/modals/AgentActionsModal.js +1 -304
- package/dist/node/ui/modals/CreateAgentModal.js +1 -243
- package/dist/node/ui/modals/index.js +1 -546
- package/dist/node/ui/overlays/demo-overlays.js +1 -64
- package/dist/node/ui/overlays/index.js +1 -64
- package/dist/node/ui/renderers/agent-list.markdown.js +2 -64
- package/dist/node/ui/renderers/agent-list.renderer.js +1 -180
- package/dist/node/ui/renderers/dashboard.markdown.js +2 -288
- package/dist/node/ui/renderers/index.js +5 -642
- package/dist/node/ui/renderers/run-list.markdown.js +2 -50
- package/dist/node/ui/renderers/tool-registry.markdown.js +2 -64
- package/dist/node/ui/views/AgentListView.js +1 -165
- package/dist/node/ui/views/RunDataTable.js +1 -326
- package/dist/node/ui/views/RunListView.js +1 -479
- package/dist/node/ui/views/ToolRegistryView.js +1 -209
- package/dist/node/ui/views/index.js +1 -851
- package/dist/node/ui/views/run-data-table.columns.js +1 -271
- package/dist/node/ui/views/run-list.shared.js +1 -177
- package/dist/node/visualizations/catalog.js +1 -134
- package/dist/node/visualizations/index.js +1 -187
- package/dist/node/visualizations/selectors.js +1 -181
- package/dist/presentations/index.js +1 -693
- package/dist/run/index.js +1 -1363
- package/dist/run/run.entity.js +1 -160
- package/dist/run/run.enum.js +1 -34
- package/dist/run/run.event.js +1 -217
- package/dist/run/run.handler.js +1 -919
- package/dist/run/run.operation.js +1 -667
- package/dist/run/run.presentation.js +1 -223
- package/dist/run/run.schema.js +1 -179
- package/dist/run/run.test-spec.js +1 -58
- package/dist/seeders/index.js +2 -21
- package/dist/shared/index.js +1 -626
- package/dist/shared/mock-agents.js +1 -82
- package/dist/shared/mock-runs.js +1 -113
- package/dist/shared/mock-tools.js +1 -146
- package/dist/tool/index.js +1 -949
- package/dist/tool/tool.entity.js +1 -90
- package/dist/tool/tool.enum.js +1 -26
- package/dist/tool/tool.event.js +1 -99
- package/dist/tool/tool.handler.js +1 -699
- package/dist/tool/tool.operation.js +1 -482
- package/dist/tool/tool.presentation.js +1 -188
- package/dist/tool/tool.schema.js +1 -141
- package/dist/tool/tool.test-spec.js +1 -58
- package/dist/ui/AgentDashboard.js +1 -2527
- package/dist/ui/AgentDashboard.visualizations.js +1 -217
- package/dist/ui/AgentRunList.js +1 -482
- package/dist/ui/AgentToolRegistry.js +1 -212
- package/dist/ui/ExecutionConsoleHost.d.ts +1 -0
- package/dist/ui/ExecutionConsoleHost.js +2 -0
- package/dist/ui/ExecutionConsoleHost.test.d.ts +1 -0
- package/dist/ui/hooks/index.js +1 -740
- package/dist/ui/hooks/useAgentList.js +1 -55
- package/dist/ui/hooks/useAgentMutations.js +1 -530
- package/dist/ui/hooks/useRunList.js +1 -70
- package/dist/ui/hooks/useToolList.js +1 -85
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.js +5 -3018
- package/dist/ui/modals/AgentActionsModal.js +1 -304
- package/dist/ui/modals/CreateAgentModal.js +1 -243
- package/dist/ui/modals/index.js +1 -546
- package/dist/ui/overlays/demo-overlays.js +1 -64
- package/dist/ui/overlays/index.js +1 -64
- package/dist/ui/renderers/agent-list.markdown.js +2 -64
- package/dist/ui/renderers/agent-list.renderer.js +1 -180
- package/dist/ui/renderers/dashboard.markdown.js +2 -288
- package/dist/ui/renderers/index.js +5 -642
- package/dist/ui/renderers/run-list.markdown.js +2 -50
- package/dist/ui/renderers/tool-registry.markdown.js +2 -64
- package/dist/ui/views/AgentListView.js +1 -165
- package/dist/ui/views/RunDataTable.js +1 -326
- package/dist/ui/views/RunListView.js +1 -479
- package/dist/ui/views/ToolRegistryView.js +1 -209
- package/dist/ui/views/index.js +1 -851
- package/dist/ui/views/run-data-table.columns.js +1 -271
- package/dist/ui/views/run-list.shared.js +1 -177
- package/dist/visualizations/catalog.js +1 -134
- package/dist/visualizations/index.js +1 -187
- package/dist/visualizations/selectors.js +1 -181
- package/package.json +29 -13
- package/src/ui/ExecutionConsoleHost.test.tsx +110 -0
- package/src/ui/ExecutionConsoleHost.tsx +14 -0
- package/src/ui/index.ts +1 -1
|
@@ -1,919 +1 @@
|
|
|
1
|
-
// src/shared/mock-agents.ts
|
|
2
|
-
var MOCK_AGENTS = [
|
|
3
|
-
{
|
|
4
|
-
id: "agent-1",
|
|
5
|
-
organizationId: "demo-org",
|
|
6
|
-
name: "Customer Support Bot",
|
|
7
|
-
slug: "customer-support-bot",
|
|
8
|
-
description: "Handles tier-1 customer inquiries and routes complex issues.",
|
|
9
|
-
status: "ACTIVE",
|
|
10
|
-
modelProvider: "OPENAI",
|
|
11
|
-
modelName: "gpt-4o-mini",
|
|
12
|
-
modelConfig: { temperature: 0.7 },
|
|
13
|
-
systemPrompt: "You are a helpful customer support assistant.",
|
|
14
|
-
toolChoice: "auto",
|
|
15
|
-
maxIterations: 10,
|
|
16
|
-
timeoutMs: 120000,
|
|
17
|
-
version: "1.0.0",
|
|
18
|
-
tags: ["support", "tier-1"],
|
|
19
|
-
createdAt: new Date("2024-01-15T10:00:00Z"),
|
|
20
|
-
updatedAt: new Date("2024-03-20T14:30:00Z")
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: "agent-2",
|
|
24
|
-
organizationId: "demo-org",
|
|
25
|
-
name: "Code Review Assistant",
|
|
26
|
-
slug: "code-review-assistant",
|
|
27
|
-
description: "Reviews pull requests and provides actionable feedback.",
|
|
28
|
-
status: "ACTIVE",
|
|
29
|
-
modelProvider: "ANTHROPIC",
|
|
30
|
-
modelName: "claude-sonnet-4-20250514",
|
|
31
|
-
modelConfig: { temperature: 0.3 },
|
|
32
|
-
systemPrompt: "You are a code review expert.",
|
|
33
|
-
toolChoice: "auto",
|
|
34
|
-
maxIterations: 15,
|
|
35
|
-
timeoutMs: 180000,
|
|
36
|
-
version: "2.1.0",
|
|
37
|
-
tags: ["code", "review", "dev"],
|
|
38
|
-
createdAt: new Date("2024-02-10T09:00:00Z"),
|
|
39
|
-
updatedAt: new Date("2024-04-05T11:15:00Z")
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: "agent-3",
|
|
43
|
-
organizationId: "demo-org",
|
|
44
|
-
name: "Data Analyst",
|
|
45
|
-
slug: "data-analyst",
|
|
46
|
-
description: "Queries databases and generates insights from data.",
|
|
47
|
-
status: "PAUSED",
|
|
48
|
-
modelProvider: "OPENAI",
|
|
49
|
-
modelName: "gpt-4o",
|
|
50
|
-
modelConfig: { temperature: 0.5 },
|
|
51
|
-
systemPrompt: "You are a data analyst expert in SQL and analytics.",
|
|
52
|
-
toolChoice: "required",
|
|
53
|
-
maxIterations: 20,
|
|
54
|
-
timeoutMs: 300000,
|
|
55
|
-
version: "1.2.0",
|
|
56
|
-
tags: ["data", "analytics", "sql"],
|
|
57
|
-
createdAt: new Date("2024-03-01T08:00:00Z"),
|
|
58
|
-
updatedAt: new Date("2024-04-10T16:45:00Z")
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
id: "agent-4",
|
|
62
|
-
organizationId: "demo-org",
|
|
63
|
-
name: "Meeting Scheduler",
|
|
64
|
-
slug: "meeting-scheduler",
|
|
65
|
-
description: "Schedules meetings and manages calendar conflicts.",
|
|
66
|
-
status: "DRAFT",
|
|
67
|
-
modelProvider: "GOOGLE",
|
|
68
|
-
modelName: "gemini-2.0-flash",
|
|
69
|
-
modelConfig: { temperature: 0.2 },
|
|
70
|
-
systemPrompt: "You help schedule and organize meetings efficiently.",
|
|
71
|
-
toolChoice: "auto",
|
|
72
|
-
maxIterations: 5,
|
|
73
|
-
timeoutMs: 60000,
|
|
74
|
-
version: "0.1.0",
|
|
75
|
-
tags: ["calendar", "scheduling"],
|
|
76
|
-
createdAt: new Date("2024-04-01T12:00:00Z"),
|
|
77
|
-
updatedAt: new Date("2024-04-01T12:00:00Z")
|
|
78
|
-
}
|
|
79
|
-
];
|
|
80
|
-
|
|
81
|
-
// src/run/run.enum.ts
|
|
82
|
-
import { defineEnum } from "@contractspec/lib.schema";
|
|
83
|
-
var RunStatusEnum = defineEnum("RunStatus", [
|
|
84
|
-
"QUEUED",
|
|
85
|
-
"IN_PROGRESS",
|
|
86
|
-
"COMPLETED",
|
|
87
|
-
"FAILED",
|
|
88
|
-
"CANCELLED",
|
|
89
|
-
"EXPIRED"
|
|
90
|
-
]);
|
|
91
|
-
var RunStepTypeEnum = defineEnum("RunStepType", [
|
|
92
|
-
"MESSAGE_CREATION",
|
|
93
|
-
"TOOL_CALL",
|
|
94
|
-
"TOOL_RESULT",
|
|
95
|
-
"ERROR"
|
|
96
|
-
]);
|
|
97
|
-
var LogLevelEnum = defineEnum("LogLevel", [
|
|
98
|
-
"DEBUG",
|
|
99
|
-
"INFO",
|
|
100
|
-
"WARN",
|
|
101
|
-
"ERROR"
|
|
102
|
-
]);
|
|
103
|
-
var GranularityEnum = defineEnum("Granularity", [
|
|
104
|
-
"hour",
|
|
105
|
-
"day",
|
|
106
|
-
"week",
|
|
107
|
-
"month"
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
// src/run/run.schema.ts
|
|
111
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
112
|
-
var RunInputModel = defineSchemaModel({
|
|
113
|
-
name: "RunInput",
|
|
114
|
-
description: "Input data for agent execution",
|
|
115
|
-
fields: {
|
|
116
|
-
message: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
117
|
-
context: { type: ScalarTypeEnum.JSONObject(), isOptional: true }
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
var RunStepModel = defineSchemaModel({
|
|
121
|
-
name: "RunStep",
|
|
122
|
-
description: "Individual step within a run",
|
|
123
|
-
fields: {
|
|
124
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
125
|
-
stepNumber: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
126
|
-
type: { type: RunStepTypeEnum, isOptional: false },
|
|
127
|
-
toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
128
|
-
toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
129
|
-
input: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
|
|
130
|
-
output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
|
|
131
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
132
|
-
errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
133
|
-
tokensUsed: {
|
|
134
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
135
|
-
isOptional: false,
|
|
136
|
-
defaultValue: 0
|
|
137
|
-
},
|
|
138
|
-
durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
139
|
-
startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
140
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
var RunLogModel = defineSchemaModel({
|
|
144
|
-
name: "RunLog",
|
|
145
|
-
description: "Execution log entry",
|
|
146
|
-
fields: {
|
|
147
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
148
|
-
stepId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
149
|
-
level: { type: LogLevelEnum, isOptional: false },
|
|
150
|
-
message: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
151
|
-
data: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
|
|
152
|
-
source: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
153
|
-
traceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
154
|
-
spanId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
155
|
-
timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
var RunAgentRefModel = defineSchemaModel({
|
|
159
|
-
name: "RunAgentRef",
|
|
160
|
-
description: "Agent reference in a run",
|
|
161
|
-
fields: {
|
|
162
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
163
|
-
name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
164
|
-
modelProvider: {
|
|
165
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
166
|
-
isOptional: false
|
|
167
|
-
},
|
|
168
|
-
modelName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
var RunModel = defineSchemaModel({
|
|
172
|
-
name: "Run",
|
|
173
|
-
description: "Agent execution instance",
|
|
174
|
-
fields: {
|
|
175
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
176
|
-
organizationId: {
|
|
177
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
178
|
-
isOptional: false
|
|
179
|
-
},
|
|
180
|
-
agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
181
|
-
userId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
182
|
-
sessionId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
183
|
-
input: { type: ScalarTypeEnum.JSONObject(), isOptional: false },
|
|
184
|
-
output: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
|
|
185
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
186
|
-
errorMessage: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
187
|
-
errorCode: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
188
|
-
totalTokens: {
|
|
189
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
190
|
-
isOptional: false,
|
|
191
|
-
defaultValue: 0
|
|
192
|
-
},
|
|
193
|
-
promptTokens: {
|
|
194
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
195
|
-
isOptional: false,
|
|
196
|
-
defaultValue: 0
|
|
197
|
-
},
|
|
198
|
-
completionTokens: {
|
|
199
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
200
|
-
isOptional: false,
|
|
201
|
-
defaultValue: 0
|
|
202
|
-
},
|
|
203
|
-
totalIterations: {
|
|
204
|
-
type: ScalarTypeEnum.Int_unsecure(),
|
|
205
|
-
isOptional: false,
|
|
206
|
-
defaultValue: 0
|
|
207
|
-
},
|
|
208
|
-
durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
209
|
-
estimatedCostUsd: {
|
|
210
|
-
type: ScalarTypeEnum.Float_unsecure(),
|
|
211
|
-
isOptional: true
|
|
212
|
-
},
|
|
213
|
-
queuedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
214
|
-
startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
215
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
216
|
-
metadata: { type: ScalarTypeEnum.JSONObject(), isOptional: true },
|
|
217
|
-
steps: { type: RunStepModel, isArray: true, isOptional: true },
|
|
218
|
-
logs: { type: RunLogModel, isArray: true, isOptional: true },
|
|
219
|
-
agent: { type: RunAgentRefModel, isOptional: true }
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
var RunSummaryModel = defineSchemaModel({
|
|
223
|
-
name: "RunSummary",
|
|
224
|
-
description: "Summary of a run for list views",
|
|
225
|
-
fields: {
|
|
226
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
227
|
-
agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
228
|
-
agentName: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
229
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
230
|
-
totalTokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
231
|
-
durationMs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
232
|
-
estimatedCostUsd: {
|
|
233
|
-
type: ScalarTypeEnum.Float_unsecure(),
|
|
234
|
-
isOptional: true
|
|
235
|
-
},
|
|
236
|
-
queuedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
237
|
-
completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
var TimelineDataPointModel = defineSchemaModel({
|
|
241
|
-
name: "TimelineDataPoint",
|
|
242
|
-
description: "Timeline data point for metrics",
|
|
243
|
-
fields: {
|
|
244
|
-
period: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
245
|
-
runs: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
246
|
-
tokens: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
247
|
-
costUsd: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false },
|
|
248
|
-
avgDurationMs: { type: ScalarTypeEnum.Float_unsecure(), isOptional: false }
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// src/run/run.operation.ts
|
|
253
|
-
import {
|
|
254
|
-
defineCommand,
|
|
255
|
-
defineQuery
|
|
256
|
-
} from "@contractspec/lib.contracts-spec/operations";
|
|
257
|
-
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
258
|
-
var OWNERS = ["@agent-console-team"];
|
|
259
|
-
var ExecuteAgentCommand = defineCommand({
|
|
260
|
-
meta: {
|
|
261
|
-
key: "agent.run.execute",
|
|
262
|
-
version: "1.0.0",
|
|
263
|
-
stability: "stable",
|
|
264
|
-
owners: [...OWNERS],
|
|
265
|
-
tags: ["run", "execute"],
|
|
266
|
-
description: "Starts a new agent run with the given input.",
|
|
267
|
-
goal: "Execute an AI agent with user input.",
|
|
268
|
-
context: "Called from chat interface or API."
|
|
269
|
-
},
|
|
270
|
-
io: {
|
|
271
|
-
input: defineSchemaModel2({
|
|
272
|
-
name: "ExecuteAgentInput",
|
|
273
|
-
fields: {
|
|
274
|
-
agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
275
|
-
input: { type: RunInputModel, isOptional: false },
|
|
276
|
-
sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
277
|
-
metadata: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
|
|
278
|
-
stream: { type: ScalarTypeEnum2.Boolean(), isOptional: true },
|
|
279
|
-
maxIterations: {
|
|
280
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
281
|
-
isOptional: true
|
|
282
|
-
},
|
|
283
|
-
timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true }
|
|
284
|
-
}
|
|
285
|
-
}),
|
|
286
|
-
output: defineSchemaModel2({
|
|
287
|
-
name: "ExecuteAgentOutput",
|
|
288
|
-
fields: {
|
|
289
|
-
runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
290
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
291
|
-
estimatedWaitMs: {
|
|
292
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
293
|
-
isOptional: true
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}),
|
|
297
|
-
errors: {
|
|
298
|
-
AGENT_NOT_FOUND: {
|
|
299
|
-
description: "The specified agent does not exist",
|
|
300
|
-
http: 404,
|
|
301
|
-
gqlCode: "AGENT_NOT_FOUND",
|
|
302
|
-
when: "Agent ID is invalid"
|
|
303
|
-
},
|
|
304
|
-
AGENT_NOT_ACTIVE: {
|
|
305
|
-
description: "The specified agent is not active",
|
|
306
|
-
http: 400,
|
|
307
|
-
gqlCode: "AGENT_NOT_ACTIVE",
|
|
308
|
-
when: "Agent is in draft/paused/archived state"
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
policy: { auth: "user" },
|
|
313
|
-
sideEffects: {
|
|
314
|
-
emits: [
|
|
315
|
-
{
|
|
316
|
-
key: "run.started",
|
|
317
|
-
version: "1.0.0",
|
|
318
|
-
stability: "stable",
|
|
319
|
-
owners: [...OWNERS],
|
|
320
|
-
tags: ["run", "started"],
|
|
321
|
-
when: "Run is queued",
|
|
322
|
-
payload: RunSummaryModel
|
|
323
|
-
}
|
|
324
|
-
],
|
|
325
|
-
audit: ["run.started"]
|
|
326
|
-
},
|
|
327
|
-
acceptance: {
|
|
328
|
-
scenarios: [
|
|
329
|
-
{
|
|
330
|
-
key: "execute-agent-happy-path",
|
|
331
|
-
given: ["Agent exists", "Agent is active"],
|
|
332
|
-
when: ["User submits execution request"],
|
|
333
|
-
then: ["Run is created", "RunStarted event is emitted"]
|
|
334
|
-
},
|
|
335
|
-
{
|
|
336
|
-
key: "execute-agent-not-active",
|
|
337
|
-
given: ["Agent exists but is not active"],
|
|
338
|
-
when: ["User attempts to execute"],
|
|
339
|
-
then: ["AGENT_NOT_ACTIVE error is returned"]
|
|
340
|
-
}
|
|
341
|
-
],
|
|
342
|
-
examples: [
|
|
343
|
-
{
|
|
344
|
-
key: "basic-execute",
|
|
345
|
-
input: { agentId: "agent-123", input: { message: "Hello" } },
|
|
346
|
-
output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
|
|
347
|
-
}
|
|
348
|
-
]
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
var CancelRunCommand = defineCommand({
|
|
352
|
-
meta: {
|
|
353
|
-
key: "agent.run.cancel",
|
|
354
|
-
version: "1.0.0",
|
|
355
|
-
stability: "stable",
|
|
356
|
-
owners: [...OWNERS],
|
|
357
|
-
tags: ["run", "cancel"],
|
|
358
|
-
description: "Cancels an in-progress agent run.",
|
|
359
|
-
goal: "Stop a running agent execution.",
|
|
360
|
-
context: "Called when user wants to abort a long-running task."
|
|
361
|
-
},
|
|
362
|
-
io: {
|
|
363
|
-
input: defineSchemaModel2({
|
|
364
|
-
name: "CancelRunInput",
|
|
365
|
-
fields: {
|
|
366
|
-
runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
367
|
-
reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
|
|
368
|
-
}
|
|
369
|
-
}),
|
|
370
|
-
output: defineSchemaModel2({
|
|
371
|
-
name: "CancelRunOutput",
|
|
372
|
-
fields: {
|
|
373
|
-
success: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
|
|
374
|
-
status: { type: RunStatusEnum, isOptional: false }
|
|
375
|
-
}
|
|
376
|
-
}),
|
|
377
|
-
errors: {
|
|
378
|
-
RUN_NOT_FOUND: {
|
|
379
|
-
description: "The specified run does not exist",
|
|
380
|
-
http: 404,
|
|
381
|
-
gqlCode: "RUN_NOT_FOUND",
|
|
382
|
-
when: "Run ID is invalid"
|
|
383
|
-
},
|
|
384
|
-
RUN_NOT_CANCELLABLE: {
|
|
385
|
-
description: "The run cannot be cancelled",
|
|
386
|
-
http: 400,
|
|
387
|
-
gqlCode: "RUN_NOT_CANCELLABLE",
|
|
388
|
-
when: "Run is already completed/failed/cancelled"
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
policy: { auth: "user" },
|
|
393
|
-
sideEffects: {
|
|
394
|
-
emits: [
|
|
395
|
-
{
|
|
396
|
-
key: "run.cancelled",
|
|
397
|
-
version: "1.0.0",
|
|
398
|
-
stability: "stable",
|
|
399
|
-
owners: [...OWNERS],
|
|
400
|
-
tags: ["run", "cancelled"],
|
|
401
|
-
when: "Run is cancelled",
|
|
402
|
-
payload: RunSummaryModel
|
|
403
|
-
}
|
|
404
|
-
],
|
|
405
|
-
audit: ["run.cancelled"]
|
|
406
|
-
},
|
|
407
|
-
acceptance: {
|
|
408
|
-
scenarios: [
|
|
409
|
-
{
|
|
410
|
-
key: "cancel-run-happy-path",
|
|
411
|
-
given: ["Run exists", "Run is in progress"],
|
|
412
|
-
when: ["User cancels run"],
|
|
413
|
-
then: ["Run is cancelled", "RunCancelled event is emitted"]
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
key: "cancel-run-already-completed",
|
|
417
|
-
given: ["Run exists but is already completed"],
|
|
418
|
-
when: ["User attempts to cancel"],
|
|
419
|
-
then: ["RUN_NOT_CANCELLABLE error is returned"]
|
|
420
|
-
}
|
|
421
|
-
],
|
|
422
|
-
examples: [
|
|
423
|
-
{
|
|
424
|
-
key: "cancel-basic",
|
|
425
|
-
input: { runId: "run-456", reason: "User requested" },
|
|
426
|
-
output: { success: true, status: "cancelled" }
|
|
427
|
-
}
|
|
428
|
-
]
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
var GetRunQuery = defineQuery({
|
|
432
|
-
meta: {
|
|
433
|
-
key: "agent.run.get",
|
|
434
|
-
version: "1.0.0",
|
|
435
|
-
stability: "stable",
|
|
436
|
-
owners: [...OWNERS],
|
|
437
|
-
tags: ["run", "get"],
|
|
438
|
-
description: "Retrieves a run by its ID with optional details.",
|
|
439
|
-
goal: "View detailed run information.",
|
|
440
|
-
context: "Run details page or monitoring."
|
|
441
|
-
},
|
|
442
|
-
io: {
|
|
443
|
-
input: defineSchemaModel2({
|
|
444
|
-
name: "GetRunInput",
|
|
445
|
-
fields: {
|
|
446
|
-
runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
447
|
-
includeSteps: { type: ScalarTypeEnum2.Boolean(), isOptional: true },
|
|
448
|
-
includeLogs: { type: ScalarTypeEnum2.Boolean(), isOptional: true }
|
|
449
|
-
}
|
|
450
|
-
}),
|
|
451
|
-
output: RunModel,
|
|
452
|
-
errors: {
|
|
453
|
-
RUN_NOT_FOUND: {
|
|
454
|
-
description: "The specified run does not exist",
|
|
455
|
-
http: 404,
|
|
456
|
-
gqlCode: "RUN_NOT_FOUND",
|
|
457
|
-
when: "Run ID is invalid"
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
policy: { auth: "user" },
|
|
462
|
-
acceptance: {
|
|
463
|
-
scenarios: [
|
|
464
|
-
{
|
|
465
|
-
key: "get-run-happy-path",
|
|
466
|
-
given: ["Run exists"],
|
|
467
|
-
when: ["User requests run by ID"],
|
|
468
|
-
then: ["Run details are returned"]
|
|
469
|
-
}
|
|
470
|
-
],
|
|
471
|
-
examples: [
|
|
472
|
-
{
|
|
473
|
-
key: "get-with-steps",
|
|
474
|
-
input: { runId: "run-456", includeSteps: true, includeLogs: false },
|
|
475
|
-
output: { id: "run-456", status: "completed", steps: [] }
|
|
476
|
-
}
|
|
477
|
-
]
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
var ListRunsQuery = defineQuery({
|
|
481
|
-
meta: {
|
|
482
|
-
key: "agent.run.list",
|
|
483
|
-
version: "1.0.0",
|
|
484
|
-
stability: "stable",
|
|
485
|
-
owners: [...OWNERS],
|
|
486
|
-
tags: ["run", "list"],
|
|
487
|
-
description: "Lists runs with optional filtering.",
|
|
488
|
-
goal: "Browse and search run history.",
|
|
489
|
-
context: "Run history/dashboard view."
|
|
490
|
-
},
|
|
491
|
-
io: {
|
|
492
|
-
input: defineSchemaModel2({
|
|
493
|
-
name: "ListRunsInput",
|
|
494
|
-
fields: {
|
|
495
|
-
organizationId: {
|
|
496
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
497
|
-
isOptional: true
|
|
498
|
-
},
|
|
499
|
-
agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
500
|
-
userId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
501
|
-
sessionId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
502
|
-
status: { type: RunStatusEnum, isOptional: true },
|
|
503
|
-
startDate: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
|
|
504
|
-
endDate: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
|
|
505
|
-
limit: {
|
|
506
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
507
|
-
isOptional: true,
|
|
508
|
-
defaultValue: 20
|
|
509
|
-
},
|
|
510
|
-
offset: {
|
|
511
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
512
|
-
isOptional: true,
|
|
513
|
-
defaultValue: 0
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}),
|
|
517
|
-
output: defineSchemaModel2({
|
|
518
|
-
name: "ListRunsOutput",
|
|
519
|
-
fields: {
|
|
520
|
-
items: { type: RunSummaryModel, isArray: true, isOptional: false },
|
|
521
|
-
total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
522
|
-
hasMore: { type: ScalarTypeEnum2.Boolean(), isOptional: false }
|
|
523
|
-
}
|
|
524
|
-
})
|
|
525
|
-
},
|
|
526
|
-
policy: { auth: "user" },
|
|
527
|
-
acceptance: {
|
|
528
|
-
scenarios: [
|
|
529
|
-
{
|
|
530
|
-
key: "list-runs-happy-path",
|
|
531
|
-
given: ["Organization has runs"],
|
|
532
|
-
when: ["User lists runs"],
|
|
533
|
-
then: ["Paginated list of runs is returned"]
|
|
534
|
-
}
|
|
535
|
-
],
|
|
536
|
-
examples: [
|
|
537
|
-
{
|
|
538
|
-
key: "list-by-agent",
|
|
539
|
-
input: { agentId: "agent-123", limit: 20, offset: 0 },
|
|
540
|
-
output: { items: [], total: 0, hasMore: false }
|
|
541
|
-
}
|
|
542
|
-
]
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
var GetRunStepsQuery = defineQuery({
|
|
546
|
-
meta: {
|
|
547
|
-
key: "agent.run.getSteps",
|
|
548
|
-
version: "1.0.0",
|
|
549
|
-
stability: "stable",
|
|
550
|
-
owners: [...OWNERS],
|
|
551
|
-
tags: ["run", "steps"],
|
|
552
|
-
description: "Retrieves all steps for a specific run.",
|
|
553
|
-
goal: "View step-by-step execution details.",
|
|
554
|
-
context: "Run details page - steps tab."
|
|
555
|
-
},
|
|
556
|
-
io: {
|
|
557
|
-
input: defineSchemaModel2({
|
|
558
|
-
name: "GetRunStepsInput",
|
|
559
|
-
fields: {
|
|
560
|
-
runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
|
|
561
|
-
}
|
|
562
|
-
}),
|
|
563
|
-
output: defineSchemaModel2({
|
|
564
|
-
name: "GetRunStepsOutput",
|
|
565
|
-
fields: {
|
|
566
|
-
steps: { type: RunStepModel, isArray: true, isOptional: false }
|
|
567
|
-
}
|
|
568
|
-
})
|
|
569
|
-
},
|
|
570
|
-
policy: { auth: "user" },
|
|
571
|
-
acceptance: {
|
|
572
|
-
scenarios: [
|
|
573
|
-
{
|
|
574
|
-
key: "get-run-steps-happy-path",
|
|
575
|
-
given: ["Run exists with steps"],
|
|
576
|
-
when: ["User requests steps"],
|
|
577
|
-
then: ["Steps list is returned"]
|
|
578
|
-
}
|
|
579
|
-
],
|
|
580
|
-
examples: [
|
|
581
|
-
{
|
|
582
|
-
key: "get-steps-basic",
|
|
583
|
-
input: { runId: "run-456" },
|
|
584
|
-
output: { steps: [] }
|
|
585
|
-
}
|
|
586
|
-
]
|
|
587
|
-
}
|
|
588
|
-
});
|
|
589
|
-
var GetRunLogsQuery = defineQuery({
|
|
590
|
-
meta: {
|
|
591
|
-
key: "agent.run.getLogs",
|
|
592
|
-
version: "1.0.0",
|
|
593
|
-
stability: "stable",
|
|
594
|
-
owners: [...OWNERS],
|
|
595
|
-
tags: ["run", "logs"],
|
|
596
|
-
description: "Retrieves all logs for a specific run.",
|
|
597
|
-
goal: "Debug and audit run execution.",
|
|
598
|
-
context: "Run details page - logs tab."
|
|
599
|
-
},
|
|
600
|
-
io: {
|
|
601
|
-
input: defineSchemaModel2({
|
|
602
|
-
name: "GetRunLogsInput",
|
|
603
|
-
fields: {
|
|
604
|
-
runId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
605
|
-
level: { type: LogLevelEnum, isOptional: true },
|
|
606
|
-
stepId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
607
|
-
limit: {
|
|
608
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
609
|
-
isOptional: true,
|
|
610
|
-
defaultValue: 100
|
|
611
|
-
},
|
|
612
|
-
offset: {
|
|
613
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
614
|
-
isOptional: true,
|
|
615
|
-
defaultValue: 0
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
}),
|
|
619
|
-
output: defineSchemaModel2({
|
|
620
|
-
name: "GetRunLogsOutput",
|
|
621
|
-
fields: {
|
|
622
|
-
items: { type: RunLogModel, isArray: true, isOptional: false },
|
|
623
|
-
total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
624
|
-
hasMore: { type: ScalarTypeEnum2.Boolean(), isOptional: false }
|
|
625
|
-
}
|
|
626
|
-
})
|
|
627
|
-
},
|
|
628
|
-
policy: { auth: "user" },
|
|
629
|
-
acceptance: {
|
|
630
|
-
scenarios: [
|
|
631
|
-
{
|
|
632
|
-
key: "get-run-logs-happy-path",
|
|
633
|
-
given: ["Run exists with logs"],
|
|
634
|
-
when: ["User requests logs"],
|
|
635
|
-
then: ["Paginated logs list is returned"]
|
|
636
|
-
}
|
|
637
|
-
],
|
|
638
|
-
examples: [
|
|
639
|
-
{
|
|
640
|
-
key: "get-logs-filtered",
|
|
641
|
-
input: { runId: "run-456", level: "error", limit: 50 },
|
|
642
|
-
output: { items: [], total: 0, hasMore: false }
|
|
643
|
-
}
|
|
644
|
-
]
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
var GetRunMetricsQuery = defineQuery({
|
|
648
|
-
meta: {
|
|
649
|
-
key: "agent.run.getMetrics",
|
|
650
|
-
version: "1.0.0",
|
|
651
|
-
stability: "stable",
|
|
652
|
-
owners: [...OWNERS],
|
|
653
|
-
tags: ["run", "metrics"],
|
|
654
|
-
description: "Retrieves aggregated metrics for runs within a time period.",
|
|
655
|
-
goal: "Monitor and analyze agent usage.",
|
|
656
|
-
context: "Analytics dashboard."
|
|
657
|
-
},
|
|
658
|
-
io: {
|
|
659
|
-
input: defineSchemaModel2({
|
|
660
|
-
name: "GetRunMetricsInput",
|
|
661
|
-
fields: {
|
|
662
|
-
organizationId: {
|
|
663
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
664
|
-
isOptional: false
|
|
665
|
-
},
|
|
666
|
-
agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
667
|
-
startDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
|
|
668
|
-
endDate: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
|
|
669
|
-
granularity: {
|
|
670
|
-
type: GranularityEnum,
|
|
671
|
-
isOptional: true,
|
|
672
|
-
defaultValue: "day"
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
}),
|
|
676
|
-
output: defineSchemaModel2({
|
|
677
|
-
name: "GetRunMetricsOutput",
|
|
678
|
-
fields: {
|
|
679
|
-
totalRuns: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
680
|
-
completedRuns: {
|
|
681
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
682
|
-
isOptional: false
|
|
683
|
-
},
|
|
684
|
-
failedRuns: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
685
|
-
totalTokens: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
686
|
-
totalCostUsd: {
|
|
687
|
-
type: ScalarTypeEnum2.Float_unsecure(),
|
|
688
|
-
isOptional: false
|
|
689
|
-
},
|
|
690
|
-
averageDurationMs: {
|
|
691
|
-
type: ScalarTypeEnum2.Float_unsecure(),
|
|
692
|
-
isOptional: false
|
|
693
|
-
},
|
|
694
|
-
successRate: {
|
|
695
|
-
type: ScalarTypeEnum2.Float_unsecure(),
|
|
696
|
-
isOptional: false
|
|
697
|
-
},
|
|
698
|
-
timeline: {
|
|
699
|
-
type: TimelineDataPointModel,
|
|
700
|
-
isArray: true,
|
|
701
|
-
isOptional: false
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
})
|
|
705
|
-
},
|
|
706
|
-
policy: { auth: "user" },
|
|
707
|
-
acceptance: {
|
|
708
|
-
scenarios: [
|
|
709
|
-
{
|
|
710
|
-
key: "get-run-metrics-happy-path",
|
|
711
|
-
given: ["Organization has run history"],
|
|
712
|
-
when: ["User requests metrics for date range"],
|
|
713
|
-
then: ["Aggregated metrics are returned"]
|
|
714
|
-
}
|
|
715
|
-
],
|
|
716
|
-
examples: [
|
|
717
|
-
{
|
|
718
|
-
key: "get-daily-metrics",
|
|
719
|
-
input: {
|
|
720
|
-
organizationId: "org-123",
|
|
721
|
-
startDate: "2025-01-01",
|
|
722
|
-
endDate: "2025-01-31",
|
|
723
|
-
granularity: "day"
|
|
724
|
-
},
|
|
725
|
-
output: {
|
|
726
|
-
totalRuns: 100,
|
|
727
|
-
completedRuns: 90,
|
|
728
|
-
failedRuns: 10,
|
|
729
|
-
totalTokens: 50000,
|
|
730
|
-
totalCostUsd: 5,
|
|
731
|
-
averageDurationMs: 2500,
|
|
732
|
-
successRate: 0.9,
|
|
733
|
-
timeline: []
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
]
|
|
737
|
-
}
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
// src/shared/mock-runs.ts
|
|
741
|
-
var MOCK_RUNS = [
|
|
742
|
-
{
|
|
743
|
-
id: "run-1",
|
|
744
|
-
organizationId: "demo-org",
|
|
745
|
-
projectId: "demo-project",
|
|
746
|
-
agentId: "agent-1",
|
|
747
|
-
agentName: "Customer Support Bot",
|
|
748
|
-
userId: "user-1",
|
|
749
|
-
sessionId: "session-1",
|
|
750
|
-
input: { message: "How do I reset my password?", context: {} },
|
|
751
|
-
output: { response: "You can reset your password by clicking..." },
|
|
752
|
-
status: "COMPLETED",
|
|
753
|
-
totalTokens: 1250,
|
|
754
|
-
promptTokens: 800,
|
|
755
|
-
completionTokens: 450,
|
|
756
|
-
totalIterations: 3,
|
|
757
|
-
durationMs: 4500,
|
|
758
|
-
estimatedCostUsd: 0.0025,
|
|
759
|
-
queuedAt: new Date("2024-04-15T10:00:00Z"),
|
|
760
|
-
startedAt: new Date("2024-04-15T10:00:01Z"),
|
|
761
|
-
completedAt: new Date("2024-04-15T10:00:05Z"),
|
|
762
|
-
steps: [],
|
|
763
|
-
logs: []
|
|
764
|
-
},
|
|
765
|
-
{
|
|
766
|
-
id: "run-2",
|
|
767
|
-
organizationId: "demo-org",
|
|
768
|
-
projectId: "demo-project",
|
|
769
|
-
agentId: "agent-2",
|
|
770
|
-
agentName: "Code Review Assistant",
|
|
771
|
-
userId: "user-2",
|
|
772
|
-
input: { message: "Review PR #123", context: { prNumber: 123 } },
|
|
773
|
-
status: "IN_PROGRESS",
|
|
774
|
-
totalTokens: 3500,
|
|
775
|
-
promptTokens: 3000,
|
|
776
|
-
completionTokens: 500,
|
|
777
|
-
totalIterations: 5,
|
|
778
|
-
queuedAt: new Date("2024-04-15T10:30:00Z"),
|
|
779
|
-
startedAt: new Date("2024-04-15T10:30:02Z"),
|
|
780
|
-
steps: [],
|
|
781
|
-
logs: []
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
id: "run-3",
|
|
785
|
-
organizationId: "demo-org",
|
|
786
|
-
projectId: "demo-project",
|
|
787
|
-
agentId: "agent-1",
|
|
788
|
-
agentName: "Customer Support Bot",
|
|
789
|
-
userId: "user-1",
|
|
790
|
-
input: { message: "What are your business hours?" },
|
|
791
|
-
output: { response: "Our business hours are 9 AM to 5 PM EST..." },
|
|
792
|
-
status: "COMPLETED",
|
|
793
|
-
totalTokens: 800,
|
|
794
|
-
promptTokens: 500,
|
|
795
|
-
completionTokens: 300,
|
|
796
|
-
totalIterations: 2,
|
|
797
|
-
durationMs: 2100,
|
|
798
|
-
estimatedCostUsd: 0.0012,
|
|
799
|
-
queuedAt: new Date("2024-04-15T09:00:00Z"),
|
|
800
|
-
startedAt: new Date("2024-04-15T09:00:01Z"),
|
|
801
|
-
completedAt: new Date("2024-04-15T09:00:03Z"),
|
|
802
|
-
steps: [],
|
|
803
|
-
logs: []
|
|
804
|
-
},
|
|
805
|
-
{
|
|
806
|
-
id: "run-4",
|
|
807
|
-
organizationId: "demo-org",
|
|
808
|
-
projectId: "demo-project",
|
|
809
|
-
agentId: "agent-3",
|
|
810
|
-
agentName: "Data Analyst",
|
|
811
|
-
userId: "user-3",
|
|
812
|
-
input: { message: "Generate sales report for Q1" },
|
|
813
|
-
status: "FAILED",
|
|
814
|
-
errorMessage: "Database connection timeout",
|
|
815
|
-
errorCode: "DB_TIMEOUT",
|
|
816
|
-
totalTokens: 2000,
|
|
817
|
-
promptTokens: 1500,
|
|
818
|
-
completionTokens: 500,
|
|
819
|
-
totalIterations: 8,
|
|
820
|
-
durationMs: 45000,
|
|
821
|
-
queuedAt: new Date("2024-04-14T15:00:00Z"),
|
|
822
|
-
startedAt: new Date("2024-04-14T15:00:05Z"),
|
|
823
|
-
completedAt: new Date("2024-04-14T15:00:50Z"),
|
|
824
|
-
steps: [],
|
|
825
|
-
logs: []
|
|
826
|
-
},
|
|
827
|
-
{
|
|
828
|
-
id: "run-5",
|
|
829
|
-
organizationId: "demo-org",
|
|
830
|
-
projectId: "demo-project",
|
|
831
|
-
agentId: "agent-2",
|
|
832
|
-
agentName: "Code Review Assistant",
|
|
833
|
-
userId: "user-2",
|
|
834
|
-
input: { message: "Review PR #120" },
|
|
835
|
-
output: { response: "Code review complete. 3 suggestions..." },
|
|
836
|
-
status: "COMPLETED",
|
|
837
|
-
totalTokens: 5200,
|
|
838
|
-
promptTokens: 4000,
|
|
839
|
-
completionTokens: 1200,
|
|
840
|
-
totalIterations: 7,
|
|
841
|
-
durationMs: 15000,
|
|
842
|
-
estimatedCostUsd: 0.0156,
|
|
843
|
-
queuedAt: new Date("2024-04-14T11:00:00Z"),
|
|
844
|
-
startedAt: new Date("2024-04-14T11:00:03Z"),
|
|
845
|
-
completedAt: new Date("2024-04-14T11:00:18Z"),
|
|
846
|
-
steps: [],
|
|
847
|
-
logs: []
|
|
848
|
-
}
|
|
849
|
-
];
|
|
850
|
-
|
|
851
|
-
// src/run/run.handler.ts
|
|
852
|
-
var nextMockRunId = MOCK_RUNS.length + 1;
|
|
853
|
-
async function mockListRunsHandler(input) {
|
|
854
|
-
const { agentId, status, limit = 20, offset = 0 } = input;
|
|
855
|
-
let filtered = [...MOCK_RUNS];
|
|
856
|
-
if (agentId)
|
|
857
|
-
filtered = filtered.filter((r) => r.agentId === agentId);
|
|
858
|
-
if (status)
|
|
859
|
-
filtered = filtered.filter((r) => r.status === status);
|
|
860
|
-
const total = filtered.length;
|
|
861
|
-
const items = filtered.slice(offset, offset + limit).map((r) => {
|
|
862
|
-
const agent = MOCK_AGENTS.find((a) => a.id === r.agentId);
|
|
863
|
-
return {
|
|
864
|
-
id: r.id,
|
|
865
|
-
agentId: r.agentId,
|
|
866
|
-
agentName: agent?.name ?? "Unknown",
|
|
867
|
-
status: r.status,
|
|
868
|
-
totalTokens: r.totalTokens,
|
|
869
|
-
durationMs: r.durationMs,
|
|
870
|
-
estimatedCostUsd: r.estimatedCostUsd,
|
|
871
|
-
queuedAt: r.queuedAt,
|
|
872
|
-
completedAt: r.completedAt
|
|
873
|
-
};
|
|
874
|
-
});
|
|
875
|
-
return { items, total, hasMore: offset + limit < total };
|
|
876
|
-
}
|
|
877
|
-
async function mockGetRunHandler(input) {
|
|
878
|
-
const run = MOCK_RUNS.find((r) => r.id === input.runId);
|
|
879
|
-
if (!run)
|
|
880
|
-
throw new Error("RUN_NOT_FOUND");
|
|
881
|
-
const agent = MOCK_AGENTS.find((a) => a.id === run.agentId);
|
|
882
|
-
return {
|
|
883
|
-
...run,
|
|
884
|
-
agent: agent ? {
|
|
885
|
-
id: agent.id,
|
|
886
|
-
name: agent.name,
|
|
887
|
-
modelProvider: agent.modelProvider,
|
|
888
|
-
modelName: agent.modelName
|
|
889
|
-
} : undefined,
|
|
890
|
-
steps: input.includeSteps ? run.steps : undefined,
|
|
891
|
-
logs: input.includeLogs ? run.logs : undefined
|
|
892
|
-
};
|
|
893
|
-
}
|
|
894
|
-
async function mockExecuteAgentHandler(input) {
|
|
895
|
-
const agent = MOCK_AGENTS.find((a) => a.id === input.agentId);
|
|
896
|
-
if (!agent)
|
|
897
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
898
|
-
if (agent.status !== "ACTIVE")
|
|
899
|
-
throw new Error("AGENT_NOT_ACTIVE");
|
|
900
|
-
return {
|
|
901
|
-
runId: `run-${nextMockRunId++}`,
|
|
902
|
-
status: "QUEUED",
|
|
903
|
-
estimatedWaitMs: 500
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
async function mockCancelRunHandler(input) {
|
|
907
|
-
const run = MOCK_RUNS.find((r) => r.id === input.runId);
|
|
908
|
-
if (!run)
|
|
909
|
-
throw new Error("RUN_NOT_FOUND");
|
|
910
|
-
if (!["QUEUED", "IN_PROGRESS"].includes(run.status))
|
|
911
|
-
throw new Error("RUN_NOT_CANCELLABLE");
|
|
912
|
-
return { success: true, status: "CANCELLED" };
|
|
913
|
-
}
|
|
914
|
-
export {
|
|
915
|
-
mockListRunsHandler,
|
|
916
|
-
mockGetRunHandler,
|
|
917
|
-
mockExecuteAgentHandler,
|
|
918
|
-
mockCancelRunHandler
|
|
919
|
-
};
|
|
1
|
+
var k=[{id:"agent-1",organizationId:"demo-org",name:"Customer Support Bot",slug:"customer-support-bot",description:"Handles tier-1 customer inquiries and routes complex issues.",status:"ACTIVE",modelProvider:"OPENAI",modelName:"gpt-4o-mini",modelConfig:{temperature:0.7},systemPrompt:"You are a helpful customer support assistant.",toolChoice:"auto",maxIterations:10,timeoutMs:120000,version:"1.0.0",tags:["support","tier-1"],createdAt:new Date("2024-01-15T10:00:00Z"),updatedAt:new Date("2024-03-20T14:30:00Z")},{id:"agent-2",organizationId:"demo-org",name:"Code Review Assistant",slug:"code-review-assistant",description:"Reviews pull requests and provides actionable feedback.",status:"ACTIVE",modelProvider:"ANTHROPIC",modelName:"claude-sonnet-4-20250514",modelConfig:{temperature:0.3},systemPrompt:"You are a code review expert.",toolChoice:"auto",maxIterations:15,timeoutMs:180000,version:"2.1.0",tags:["code","review","dev"],createdAt:new Date("2024-02-10T09:00:00Z"),updatedAt:new Date("2024-04-05T11:15:00Z")},{id:"agent-3",organizationId:"demo-org",name:"Data Analyst",slug:"data-analyst",description:"Queries databases and generates insights from data.",status:"PAUSED",modelProvider:"OPENAI",modelName:"gpt-4o",modelConfig:{temperature:0.5},systemPrompt:"You are a data analyst expert in SQL and analytics.",toolChoice:"required",maxIterations:20,timeoutMs:300000,version:"1.2.0",tags:["data","analytics","sql"],createdAt:new Date("2024-03-01T08:00:00Z"),updatedAt:new Date("2024-04-10T16:45:00Z")},{id:"agent-4",organizationId:"demo-org",name:"Meeting Scheduler",slug:"meeting-scheduler",description:"Schedules meetings and manages calendar conflicts.",status:"DRAFT",modelProvider:"GOOGLE",modelName:"gemini-2.0-flash",modelConfig:{temperature:0.2},systemPrompt:"You help schedule and organize meetings efficiently.",toolChoice:"auto",maxIterations:5,timeoutMs:60000,version:"0.1.0",tags:["calendar","scheduling"],createdAt:new Date("2024-04-01T12:00:00Z"),updatedAt:new Date("2024-04-01T12:00:00Z")}];import{defineEnum as C}from"@contractspec/lib.schema";var w=C("RunStatus",["QUEUED","IN_PROGRESS","COMPLETED","FAILED","CANCELLED","EXPIRED"]),B=C("RunStepType",["MESSAGE_CREATION","TOOL_CALL","TOOL_RESULT","ERROR"]),j=C("LogLevel",["DEBUG","INFO","WARN","ERROR"]),H=C("Granularity",["hour","day","week","month"]);import{defineSchemaModel as A,ScalarTypeEnum as t}from"@contractspec/lib.schema";var F=A({name:"RunInput",description:"Input data for agent execution",fields:{message:{type:t.NonEmptyString(),isOptional:!1},context:{type:t.JSONObject(),isOptional:!0}}}),x=A({name:"RunStep",description:"Individual step within a run",fields:{id:{type:t.String_unsecure(),isOptional:!1},stepNumber:{type:t.Int_unsecure(),isOptional:!1},type:{type:B,isOptional:!1},toolId:{type:t.String_unsecure(),isOptional:!0},toolName:{type:t.String_unsecure(),isOptional:!0},input:{type:t.JSONObject(),isOptional:!0},output:{type:t.JSONObject(),isOptional:!0},status:{type:w,isOptional:!1},errorMessage:{type:t.String_unsecure(),isOptional:!0},tokensUsed:{type:t.Int_unsecure(),isOptional:!1,defaultValue:0},durationMs:{type:t.Int_unsecure(),isOptional:!0},startedAt:{type:t.DateTime(),isOptional:!1},completedAt:{type:t.DateTime(),isOptional:!0}}}),b=A({name:"RunLog",description:"Execution log entry",fields:{id:{type:t.String_unsecure(),isOptional:!1},stepId:{type:t.String_unsecure(),isOptional:!0},level:{type:j,isOptional:!1},message:{type:t.String_unsecure(),isOptional:!1},data:{type:t.JSONObject(),isOptional:!0},source:{type:t.String_unsecure(),isOptional:!0},traceId:{type:t.String_unsecure(),isOptional:!0},spanId:{type:t.String_unsecure(),isOptional:!0},timestamp:{type:t.DateTime(),isOptional:!1}}}),$=A({name:"RunAgentRef",description:"Agent reference in a run",fields:{id:{type:t.String_unsecure(),isOptional:!1},name:{type:t.NonEmptyString(),isOptional:!1},modelProvider:{type:t.String_unsecure(),isOptional:!1},modelName:{type:t.String_unsecure(),isOptional:!1}}}),U=A({name:"Run",description:"Agent execution instance",fields:{id:{type:t.String_unsecure(),isOptional:!1},organizationId:{type:t.String_unsecure(),isOptional:!1},agentId:{type:t.String_unsecure(),isOptional:!1},userId:{type:t.String_unsecure(),isOptional:!0},sessionId:{type:t.String_unsecure(),isOptional:!0},input:{type:t.JSONObject(),isOptional:!1},output:{type:t.JSONObject(),isOptional:!0},status:{type:w,isOptional:!1},errorMessage:{type:t.String_unsecure(),isOptional:!0},errorCode:{type:t.String_unsecure(),isOptional:!0},totalTokens:{type:t.Int_unsecure(),isOptional:!1,defaultValue:0},promptTokens:{type:t.Int_unsecure(),isOptional:!1,defaultValue:0},completionTokens:{type:t.Int_unsecure(),isOptional:!1,defaultValue:0},totalIterations:{type:t.Int_unsecure(),isOptional:!1,defaultValue:0},durationMs:{type:t.Int_unsecure(),isOptional:!0},estimatedCostUsd:{type:t.Float_unsecure(),isOptional:!0},queuedAt:{type:t.DateTime(),isOptional:!1},startedAt:{type:t.DateTime(),isOptional:!0},completedAt:{type:t.DateTime(),isOptional:!0},metadata:{type:t.JSONObject(),isOptional:!0},steps:{type:x,isArray:!0,isOptional:!0},logs:{type:b,isArray:!0,isOptional:!0},agent:{type:$,isOptional:!0}}}),z=A({name:"RunSummary",description:"Summary of a run for list views",fields:{id:{type:t.String_unsecure(),isOptional:!1},agentId:{type:t.String_unsecure(),isOptional:!1},agentName:{type:t.NonEmptyString(),isOptional:!1},status:{type:w,isOptional:!1},totalTokens:{type:t.Int_unsecure(),isOptional:!1},durationMs:{type:t.Int_unsecure(),isOptional:!0},estimatedCostUsd:{type:t.Float_unsecure(),isOptional:!0},queuedAt:{type:t.DateTime(),isOptional:!1},completedAt:{type:t.DateTime(),isOptional:!0}}}),V=A({name:"TimelineDataPoint",description:"Timeline data point for metrics",fields:{period:{type:t.String_unsecure(),isOptional:!1},runs:{type:t.Int_unsecure(),isOptional:!1},tokens:{type:t.Int_unsecure(),isOptional:!1},costUsd:{type:t.Float_unsecure(),isOptional:!1},avgDurationMs:{type:t.Float_unsecure(),isOptional:!1}}});import{defineCommand as J,defineQuery as v}from"@contractspec/lib.contracts-spec/operations";import{defineSchemaModel as d,ScalarTypeEnum as s}from"@contractspec/lib.schema";var I=["@agent-console-team"],G=J({meta:{key:"agent.run.execute",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","execute"],description:"Starts a new agent run with the given input.",goal:"Execute an AI agent with user input.",context:"Called from chat interface or API."},io:{input:d({name:"ExecuteAgentInput",fields:{agentId:{type:s.String_unsecure(),isOptional:!1},input:{type:F,isOptional:!1},sessionId:{type:s.String_unsecure(),isOptional:!0},metadata:{type:s.JSONObject(),isOptional:!0},stream:{type:s.Boolean(),isOptional:!0},maxIterations:{type:s.Int_unsecure(),isOptional:!0},timeoutMs:{type:s.Int_unsecure(),isOptional:!0}}}),output:d({name:"ExecuteAgentOutput",fields:{runId:{type:s.String_unsecure(),isOptional:!1},status:{type:w,isOptional:!1},estimatedWaitMs:{type:s.Int_unsecure(),isOptional:!0}}}),errors:{AGENT_NOT_FOUND:{description:"The specified agent does not exist",http:404,gqlCode:"AGENT_NOT_FOUND",when:"Agent ID is invalid"},AGENT_NOT_ACTIVE:{description:"The specified agent is not active",http:400,gqlCode:"AGENT_NOT_ACTIVE",when:"Agent is in draft/paused/archived state"}}},policy:{auth:"user"},sideEffects:{emits:[{key:"run.started",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","started"],when:"Run is queued",payload:z}],audit:["run.started"]},acceptance:{scenarios:[{key:"execute-agent-happy-path",given:["Agent exists","Agent is active"],when:["User submits execution request"],then:["Run is created","RunStarted event is emitted"]},{key:"execute-agent-not-active",given:["Agent exists but is not active"],when:["User attempts to execute"],then:["AGENT_NOT_ACTIVE error is returned"]}],examples:[{key:"basic-execute",input:{agentId:"agent-123",input:{message:"Hello"}},output:{runId:"run-456",status:"pending",estimatedWaitMs:5000}}]}}),L=J({meta:{key:"agent.run.cancel",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","cancel"],description:"Cancels an in-progress agent run.",goal:"Stop a running agent execution.",context:"Called when user wants to abort a long-running task."},io:{input:d({name:"CancelRunInput",fields:{runId:{type:s.String_unsecure(),isOptional:!1},reason:{type:s.String_unsecure(),isOptional:!0}}}),output:d({name:"CancelRunOutput",fields:{success:{type:s.Boolean(),isOptional:!1},status:{type:w,isOptional:!1}}}),errors:{RUN_NOT_FOUND:{description:"The specified run does not exist",http:404,gqlCode:"RUN_NOT_FOUND",when:"Run ID is invalid"},RUN_NOT_CANCELLABLE:{description:"The run cannot be cancelled",http:400,gqlCode:"RUN_NOT_CANCELLABLE",when:"Run is already completed/failed/cancelled"}}},policy:{auth:"user"},sideEffects:{emits:[{key:"run.cancelled",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","cancelled"],when:"Run is cancelled",payload:z}],audit:["run.cancelled"]},acceptance:{scenarios:[{key:"cancel-run-happy-path",given:["Run exists","Run is in progress"],when:["User cancels run"],then:["Run is cancelled","RunCancelled event is emitted"]},{key:"cancel-run-already-completed",given:["Run exists but is already completed"],when:["User attempts to cancel"],then:["RUN_NOT_CANCELLABLE error is returned"]}],examples:[{key:"cancel-basic",input:{runId:"run-456",reason:"User requested"},output:{success:!0,status:"cancelled"}}]}}),O=v({meta:{key:"agent.run.get",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","get"],description:"Retrieves a run by its ID with optional details.",goal:"View detailed run information.",context:"Run details page or monitoring."},io:{input:d({name:"GetRunInput",fields:{runId:{type:s.String_unsecure(),isOptional:!1},includeSteps:{type:s.Boolean(),isOptional:!0},includeLogs:{type:s.Boolean(),isOptional:!0}}}),output:U,errors:{RUN_NOT_FOUND:{description:"The specified run does not exist",http:404,gqlCode:"RUN_NOT_FOUND",when:"Run ID is invalid"}}},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-run-happy-path",given:["Run exists"],when:["User requests run by ID"],then:["Run details are returned"]}],examples:[{key:"get-with-steps",input:{runId:"run-456",includeSteps:!0,includeLogs:!1},output:{id:"run-456",status:"completed",steps:[]}}]}}),_=v({meta:{key:"agent.run.list",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","list"],description:"Lists runs with optional filtering.",goal:"Browse and search run history.",context:"Run history/dashboard view."},io:{input:d({name:"ListRunsInput",fields:{organizationId:{type:s.String_unsecure(),isOptional:!0},agentId:{type:s.String_unsecure(),isOptional:!0},userId:{type:s.String_unsecure(),isOptional:!0},sessionId:{type:s.String_unsecure(),isOptional:!0},status:{type:w,isOptional:!0},startDate:{type:s.DateTime(),isOptional:!0},endDate:{type:s.DateTime(),isOptional:!0},limit:{type:s.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:s.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:d({name:"ListRunsOutput",fields:{items:{type:z,isArray:!0,isOptional:!1},total:{type:s.Int_unsecure(),isOptional:!1},hasMore:{type:s.Boolean(),isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"list-runs-happy-path",given:["Organization has runs"],when:["User lists runs"],then:["Paginated list of runs is returned"]}],examples:[{key:"list-by-agent",input:{agentId:"agent-123",limit:20,offset:0},output:{items:[],total:0,hasMore:!1}}]}}),m=v({meta:{key:"agent.run.getSteps",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","steps"],description:"Retrieves all steps for a specific run.",goal:"View step-by-step execution details.",context:"Run details page - steps tab."},io:{input:d({name:"GetRunStepsInput",fields:{runId:{type:s.String_unsecure(),isOptional:!1}}}),output:d({name:"GetRunStepsOutput",fields:{steps:{type:x,isArray:!0,isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-run-steps-happy-path",given:["Run exists with steps"],when:["User requests steps"],then:["Steps list is returned"]}],examples:[{key:"get-steps-basic",input:{runId:"run-456"},output:{steps:[]}}]}}),c=v({meta:{key:"agent.run.getLogs",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","logs"],description:"Retrieves all logs for a specific run.",goal:"Debug and audit run execution.",context:"Run details page - logs tab."},io:{input:d({name:"GetRunLogsInput",fields:{runId:{type:s.String_unsecure(),isOptional:!1},level:{type:j,isOptional:!0},stepId:{type:s.String_unsecure(),isOptional:!0},limit:{type:s.Int_unsecure(),isOptional:!0,defaultValue:100},offset:{type:s.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:d({name:"GetRunLogsOutput",fields:{items:{type:b,isArray:!0,isOptional:!1},total:{type:s.Int_unsecure(),isOptional:!1},hasMore:{type:s.Boolean(),isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-run-logs-happy-path",given:["Run exists with logs"],when:["User requests logs"],then:["Paginated logs list is returned"]}],examples:[{key:"get-logs-filtered",input:{runId:"run-456",level:"error",limit:50},output:{items:[],total:0,hasMore:!1}}]}}),u=v({meta:{key:"agent.run.getMetrics",version:"1.0.0",stability:"stable",owners:[...I],tags:["run","metrics"],description:"Retrieves aggregated metrics for runs within a time period.",goal:"Monitor and analyze agent usage.",context:"Analytics dashboard."},io:{input:d({name:"GetRunMetricsInput",fields:{organizationId:{type:s.String_unsecure(),isOptional:!1},agentId:{type:s.String_unsecure(),isOptional:!0},startDate:{type:s.DateTime(),isOptional:!1},endDate:{type:s.DateTime(),isOptional:!1},granularity:{type:H,isOptional:!0,defaultValue:"day"}}}),output:d({name:"GetRunMetricsOutput",fields:{totalRuns:{type:s.Int_unsecure(),isOptional:!1},completedRuns:{type:s.Int_unsecure(),isOptional:!1},failedRuns:{type:s.Int_unsecure(),isOptional:!1},totalTokens:{type:s.Int_unsecure(),isOptional:!1},totalCostUsd:{type:s.Float_unsecure(),isOptional:!1},averageDurationMs:{type:s.Float_unsecure(),isOptional:!1},successRate:{type:s.Float_unsecure(),isOptional:!1},timeline:{type:V,isArray:!0,isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-run-metrics-happy-path",given:["Organization has run history"],when:["User requests metrics for date range"],then:["Aggregated metrics are returned"]}],examples:[{key:"get-daily-metrics",input:{organizationId:"org-123",startDate:"2025-01-01",endDate:"2025-01-31",granularity:"day"},output:{totalRuns:100,completedRuns:90,failedRuns:10,totalTokens:50000,totalCostUsd:5,averageDurationMs:2500,successRate:0.9,timeline:[]}}]}});var P=[{id:"run-1",organizationId:"demo-org",projectId:"demo-project",agentId:"agent-1",agentName:"Customer Support Bot",userId:"user-1",sessionId:"session-1",input:{message:"How do I reset my password?",context:{}},output:{response:"You can reset your password by clicking..."},status:"COMPLETED",totalTokens:1250,promptTokens:800,completionTokens:450,totalIterations:3,durationMs:4500,estimatedCostUsd:0.0025,queuedAt:new Date("2024-04-15T10:00:00Z"),startedAt:new Date("2024-04-15T10:00:01Z"),completedAt:new Date("2024-04-15T10:00:05Z"),steps:[],logs:[]},{id:"run-2",organizationId:"demo-org",projectId:"demo-project",agentId:"agent-2",agentName:"Code Review Assistant",userId:"user-2",input:{message:"Review PR #123",context:{prNumber:123}},status:"IN_PROGRESS",totalTokens:3500,promptTokens:3000,completionTokens:500,totalIterations:5,queuedAt:new Date("2024-04-15T10:30:00Z"),startedAt:new Date("2024-04-15T10:30:02Z"),steps:[],logs:[]},{id:"run-3",organizationId:"demo-org",projectId:"demo-project",agentId:"agent-1",agentName:"Customer Support Bot",userId:"user-1",input:{message:"What are your business hours?"},output:{response:"Our business hours are 9 AM to 5 PM EST..."},status:"COMPLETED",totalTokens:800,promptTokens:500,completionTokens:300,totalIterations:2,durationMs:2100,estimatedCostUsd:0.0012,queuedAt:new Date("2024-04-15T09:00:00Z"),startedAt:new Date("2024-04-15T09:00:01Z"),completedAt:new Date("2024-04-15T09:00:03Z"),steps:[],logs:[]},{id:"run-4",organizationId:"demo-org",projectId:"demo-project",agentId:"agent-3",agentName:"Data Analyst",userId:"user-3",input:{message:"Generate sales report for Q1"},status:"FAILED",errorMessage:"Database connection timeout",errorCode:"DB_TIMEOUT",totalTokens:2000,promptTokens:1500,completionTokens:500,totalIterations:8,durationMs:45000,queuedAt:new Date("2024-04-14T15:00:00Z"),startedAt:new Date("2024-04-14T15:00:05Z"),completedAt:new Date("2024-04-14T15:00:50Z"),steps:[],logs:[]},{id:"run-5",organizationId:"demo-org",projectId:"demo-project",agentId:"agent-2",agentName:"Code Review Assistant",userId:"user-2",input:{message:"Review PR #120"},output:{response:"Code review complete. 3 suggestions..."},status:"COMPLETED",totalTokens:5200,promptTokens:4000,completionTokens:1200,totalIterations:7,durationMs:15000,estimatedCostUsd:0.0156,queuedAt:new Date("2024-04-14T11:00:00Z"),startedAt:new Date("2024-04-14T11:00:03Z"),completedAt:new Date("2024-04-14T11:00:18Z"),steps:[],logs:[]}];var Q=P.length+1;async function st(g){let{agentId:o,status:i,limit:D=20,offset:q=0}=g,Z=[...P];if(o)Z=Z.filter((e)=>e.agentId===o);if(i)Z=Z.filter((e)=>e.status===i);let Y=Z.length;return{items:Z.slice(q,q+D).map((e)=>{let N=k.find((X)=>X.id===e.agentId);return{id:e.id,agentId:e.agentId,agentName:N?.name??"Unknown",status:e.status,totalTokens:e.totalTokens,durationMs:e.durationMs,estimatedCostUsd:e.estimatedCostUsd,queuedAt:e.queuedAt,completedAt:e.completedAt}}),total:Y,hasMore:q+D<Y}}async function ot(g){let o=P.find((D)=>D.id===g.runId);if(!o)throw Error("RUN_NOT_FOUND");let i=k.find((D)=>D.id===o.agentId);return{...o,agent:i?{id:i.id,name:i.name,modelProvider:i.modelProvider,modelName:i.modelName}:void 0,steps:g.includeSteps?o.steps:void 0,logs:g.includeLogs?o.logs:void 0}}async function et(g){let o=k.find((i)=>i.id===g.agentId);if(!o)throw Error("AGENT_NOT_FOUND");if(o.status!=="ACTIVE")throw Error("AGENT_NOT_ACTIVE");return{runId:`run-${Q++}`,status:"QUEUED",estimatedWaitMs:500}}async function dt(g){let o=P.find((i)=>i.id===g.runId);if(!o)throw Error("RUN_NOT_FOUND");if(!["QUEUED","IN_PROGRESS"].includes(o.status))throw Error("RUN_NOT_CANCELLABLE");return{success:!0,status:"CANCELLED"}}export{st as mockListRunsHandler,ot as mockGetRunHandler,et as mockExecuteAgentHandler,dt as mockCancelRunHandler};
|