@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,2950 +1,13 @@
|
|
|
1
|
-
// src/agent/agent.enum.ts
|
|
2
|
-
|
|
3
|
-
var AgentStatusEnum = defineEnum("AgentStatus", [
|
|
4
|
-
"DRAFT",
|
|
5
|
-
"ACTIVE",
|
|
6
|
-
"PAUSED",
|
|
7
|
-
"ARCHIVED"
|
|
8
|
-
]);
|
|
9
|
-
var ModelProviderEnum = defineEnum("ModelProvider", [
|
|
10
|
-
"OPENAI",
|
|
11
|
-
"ANTHROPIC",
|
|
12
|
-
"GOOGLE",
|
|
13
|
-
"MISTRAL",
|
|
14
|
-
"CUSTOM"
|
|
15
|
-
]);
|
|
16
|
-
var ToolChoiceEnum = defineEnum("ToolChoice", [
|
|
17
|
-
"auto",
|
|
18
|
-
"required",
|
|
19
|
-
"none"
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
// src/agent/agent.event.ts
|
|
23
|
-
import { defineEvent } from "@contractspec/lib.contracts-spec";
|
|
24
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
25
|
-
var OWNERS = ["@agent-console-team"];
|
|
26
|
-
var AgentCreatedPayload = defineSchemaModel({
|
|
27
|
-
name: "AgentCreatedPayload",
|
|
28
|
-
description: "Payload for agent created event",
|
|
29
|
-
fields: {
|
|
30
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
31
|
-
organizationId: {
|
|
32
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
33
|
-
isOptional: false
|
|
34
|
-
},
|
|
35
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
36
|
-
slug: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
37
|
-
modelProvider: {
|
|
38
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
39
|
-
isOptional: false
|
|
40
|
-
},
|
|
41
|
-
modelName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
42
|
-
toolCount: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
43
|
-
createdById: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
44
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
var AgentCreatedEvent = defineEvent({
|
|
48
|
-
meta: {
|
|
49
|
-
key: "agent-console.agent.created",
|
|
50
|
-
version: "1.0.0",
|
|
51
|
-
description: "A new AI agent was configured.",
|
|
52
|
-
stability: "stable",
|
|
53
|
-
owners: [...OWNERS],
|
|
54
|
-
tags: ["agent", "created"]
|
|
55
|
-
},
|
|
56
|
-
payload: AgentCreatedPayload
|
|
57
|
-
});
|
|
58
|
-
var AgentUpdatedPayload = defineSchemaModel({
|
|
59
|
-
name: "AgentUpdatedPayload",
|
|
60
|
-
description: "Payload for agent updated event",
|
|
61
|
-
fields: {
|
|
62
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
63
|
-
organizationId: {
|
|
64
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
65
|
-
isOptional: false
|
|
66
|
-
},
|
|
67
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
68
|
-
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
69
|
-
updatedFields: {
|
|
70
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
71
|
-
isArray: true,
|
|
72
|
-
isOptional: false
|
|
73
|
-
},
|
|
74
|
-
updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
var AgentUpdatedEvent = defineEvent({
|
|
78
|
-
meta: {
|
|
79
|
-
key: "agent-console.agent.updated",
|
|
80
|
-
version: "1.0.0",
|
|
81
|
-
description: "An AI agent configuration was updated.",
|
|
82
|
-
stability: "stable",
|
|
83
|
-
owners: [...OWNERS],
|
|
84
|
-
tags: ["agent", "updated"]
|
|
85
|
-
},
|
|
86
|
-
payload: AgentUpdatedPayload
|
|
87
|
-
});
|
|
88
|
-
var AgentToolAssignedPayload = defineSchemaModel({
|
|
89
|
-
name: "AgentToolAssignedPayload",
|
|
90
|
-
description: "Payload for agent tool assigned event",
|
|
91
|
-
fields: {
|
|
92
|
-
agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
93
|
-
toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
94
|
-
agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
95
|
-
toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
96
|
-
assignedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
var AgentToolAssignedEvent = defineEvent({
|
|
100
|
-
meta: {
|
|
101
|
-
key: "agent-console.agent.toolAssigned",
|
|
102
|
-
version: "1.0.0",
|
|
103
|
-
description: "A tool was assigned to an agent.",
|
|
104
|
-
stability: "stable",
|
|
105
|
-
owners: [...OWNERS],
|
|
106
|
-
tags: ["agent", "tool", "assigned"]
|
|
107
|
-
},
|
|
108
|
-
payload: AgentToolAssignedPayload
|
|
109
|
-
});
|
|
110
|
-
var AgentToolRemovedPayload = defineSchemaModel({
|
|
111
|
-
name: "AgentToolRemovedPayload",
|
|
112
|
-
description: "Payload for agent tool removed event",
|
|
113
|
-
fields: {
|
|
114
|
-
agentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
115
|
-
toolId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
116
|
-
agentName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
117
|
-
toolName: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
118
|
-
removedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
var AgentToolRemovedEvent = defineEvent({
|
|
122
|
-
meta: {
|
|
123
|
-
key: "agent-console.agent.toolRemoved",
|
|
124
|
-
version: "1.0.0",
|
|
125
|
-
description: "A tool was removed from an agent.",
|
|
126
|
-
stability: "stable",
|
|
127
|
-
owners: [...OWNERS],
|
|
128
|
-
tags: ["agent", "tool", "removed"]
|
|
129
|
-
},
|
|
130
|
-
payload: AgentToolRemovedPayload
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// src/shared/mock-agents.ts
|
|
134
|
-
var MOCK_AGENTS = [
|
|
135
|
-
{
|
|
136
|
-
id: "agent-1",
|
|
137
|
-
organizationId: "demo-org",
|
|
138
|
-
name: "Customer Support Bot",
|
|
139
|
-
slug: "customer-support-bot",
|
|
140
|
-
description: "Handles tier-1 customer inquiries and routes complex issues.",
|
|
141
|
-
status: "ACTIVE",
|
|
142
|
-
modelProvider: "OPENAI",
|
|
143
|
-
modelName: "gpt-4o-mini",
|
|
144
|
-
modelConfig: { temperature: 0.7 },
|
|
145
|
-
systemPrompt: "You are a helpful customer support assistant.",
|
|
146
|
-
toolChoice: "auto",
|
|
147
|
-
maxIterations: 10,
|
|
148
|
-
timeoutMs: 120000,
|
|
149
|
-
version: "1.0.0",
|
|
150
|
-
tags: ["support", "tier-1"],
|
|
151
|
-
createdAt: new Date("2024-01-15T10:00:00Z"),
|
|
152
|
-
updatedAt: new Date("2024-03-20T14:30:00Z")
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
id: "agent-2",
|
|
156
|
-
organizationId: "demo-org",
|
|
157
|
-
name: "Code Review Assistant",
|
|
158
|
-
slug: "code-review-assistant",
|
|
159
|
-
description: "Reviews pull requests and provides actionable feedback.",
|
|
160
|
-
status: "ACTIVE",
|
|
161
|
-
modelProvider: "ANTHROPIC",
|
|
162
|
-
modelName: "claude-sonnet-4-20250514",
|
|
163
|
-
modelConfig: { temperature: 0.3 },
|
|
164
|
-
systemPrompt: "You are a code review expert.",
|
|
165
|
-
toolChoice: "auto",
|
|
166
|
-
maxIterations: 15,
|
|
167
|
-
timeoutMs: 180000,
|
|
168
|
-
version: "2.1.0",
|
|
169
|
-
tags: ["code", "review", "dev"],
|
|
170
|
-
createdAt: new Date("2024-02-10T09:00:00Z"),
|
|
171
|
-
updatedAt: new Date("2024-04-05T11:15:00Z")
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
id: "agent-3",
|
|
175
|
-
organizationId: "demo-org",
|
|
176
|
-
name: "Data Analyst",
|
|
177
|
-
slug: "data-analyst",
|
|
178
|
-
description: "Queries databases and generates insights from data.",
|
|
179
|
-
status: "PAUSED",
|
|
180
|
-
modelProvider: "OPENAI",
|
|
181
|
-
modelName: "gpt-4o",
|
|
182
|
-
modelConfig: { temperature: 0.5 },
|
|
183
|
-
systemPrompt: "You are a data analyst expert in SQL and analytics.",
|
|
184
|
-
toolChoice: "required",
|
|
185
|
-
maxIterations: 20,
|
|
186
|
-
timeoutMs: 300000,
|
|
187
|
-
version: "1.2.0",
|
|
188
|
-
tags: ["data", "analytics", "sql"],
|
|
189
|
-
createdAt: new Date("2024-03-01T08:00:00Z"),
|
|
190
|
-
updatedAt: new Date("2024-04-10T16:45:00Z")
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
id: "agent-4",
|
|
194
|
-
organizationId: "demo-org",
|
|
195
|
-
name: "Meeting Scheduler",
|
|
196
|
-
slug: "meeting-scheduler",
|
|
197
|
-
description: "Schedules meetings and manages calendar conflicts.",
|
|
198
|
-
status: "DRAFT",
|
|
199
|
-
modelProvider: "GOOGLE",
|
|
200
|
-
modelName: "gemini-2.0-flash",
|
|
201
|
-
modelConfig: { temperature: 0.2 },
|
|
202
|
-
systemPrompt: "You help schedule and organize meetings efficiently.",
|
|
203
|
-
toolChoice: "auto",
|
|
204
|
-
maxIterations: 5,
|
|
205
|
-
timeoutMs: 60000,
|
|
206
|
-
version: "0.1.0",
|
|
207
|
-
tags: ["calendar", "scheduling"],
|
|
208
|
-
createdAt: new Date("2024-04-01T12:00:00Z"),
|
|
209
|
-
updatedAt: new Date("2024-04-01T12:00:00Z")
|
|
210
|
-
}
|
|
211
|
-
];
|
|
212
|
-
|
|
213
|
-
// src/shared/mock-tools.ts
|
|
214
|
-
var MOCK_TOOLS = [
|
|
215
|
-
{
|
|
216
|
-
id: "tool-1",
|
|
217
|
-
organizationId: "demo-org",
|
|
218
|
-
name: "Web Search",
|
|
219
|
-
slug: "web-search",
|
|
220
|
-
description: "Search the web for real-time information using Brave API.",
|
|
221
|
-
category: "RETRIEVAL",
|
|
222
|
-
status: "ACTIVE",
|
|
223
|
-
parametersSchema: {
|
|
224
|
-
type: "object",
|
|
225
|
-
properties: {
|
|
226
|
-
query: { type: "string", description: "Search query" },
|
|
227
|
-
numResults: { type: "number", default: 10 }
|
|
228
|
-
},
|
|
229
|
-
required: ["query"]
|
|
230
|
-
},
|
|
231
|
-
outputSchema: { type: "array", items: { type: "object" } },
|
|
232
|
-
implementationType: "http",
|
|
233
|
-
implementationConfig: {
|
|
234
|
-
url: "https://api.brave.com/search",
|
|
235
|
-
method: "GET"
|
|
236
|
-
},
|
|
237
|
-
maxInvocationsPerMinute: 60,
|
|
238
|
-
timeoutMs: 30000,
|
|
239
|
-
version: "1.0.0",
|
|
240
|
-
tags: ["search", "web"],
|
|
241
|
-
createdAt: new Date("2024-01-01T00:00:00Z"),
|
|
242
|
-
updatedAt: new Date("2024-02-15T10:00:00Z")
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
id: "tool-2",
|
|
246
|
-
organizationId: "demo-org",
|
|
247
|
-
name: "SQL Query",
|
|
248
|
-
slug: "sql-query",
|
|
249
|
-
description: "Execute read-only SQL queries against the data warehouse.",
|
|
250
|
-
category: "RETRIEVAL",
|
|
251
|
-
status: "ACTIVE",
|
|
252
|
-
parametersSchema: {
|
|
253
|
-
type: "object",
|
|
254
|
-
properties: {
|
|
255
|
-
query: { type: "string", description: "SQL query" },
|
|
256
|
-
maxRows: { type: "number", default: 100 }
|
|
257
|
-
},
|
|
258
|
-
required: ["query"]
|
|
259
|
-
},
|
|
260
|
-
outputSchema: { type: "object" },
|
|
261
|
-
implementationType: "function",
|
|
262
|
-
implementationConfig: { handler: "executeSqlQuery" },
|
|
263
|
-
maxInvocationsPerMinute: 30,
|
|
264
|
-
timeoutMs: 60000,
|
|
265
|
-
version: "1.1.0",
|
|
266
|
-
tags: ["sql", "database"],
|
|
267
|
-
createdAt: new Date("2024-01-05T00:00:00Z"),
|
|
268
|
-
updatedAt: new Date("2024-03-10T14:00:00Z")
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
id: "tool-3",
|
|
272
|
-
organizationId: "demo-org",
|
|
273
|
-
name: "Email Sender",
|
|
274
|
-
slug: "email-sender",
|
|
275
|
-
description: "Send emails via SMTP or API.",
|
|
276
|
-
category: "COMMUNICATION",
|
|
277
|
-
status: "ACTIVE",
|
|
278
|
-
parametersSchema: {
|
|
279
|
-
type: "object",
|
|
280
|
-
properties: {
|
|
281
|
-
to: { type: "string" },
|
|
282
|
-
subject: { type: "string" },
|
|
283
|
-
body: { type: "string" }
|
|
284
|
-
},
|
|
285
|
-
required: ["to", "subject", "body"]
|
|
286
|
-
},
|
|
287
|
-
implementationType: "http",
|
|
288
|
-
implementationConfig: { url: "/api/send-email", method: "POST" },
|
|
289
|
-
maxInvocationsPerMinute: 10,
|
|
290
|
-
timeoutMs: 30000,
|
|
291
|
-
version: "1.0.0",
|
|
292
|
-
tags: ["email", "communication"],
|
|
293
|
-
createdAt: new Date("2024-02-01T00:00:00Z"),
|
|
294
|
-
updatedAt: new Date("2024-02-01T00:00:00Z")
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
id: "tool-4",
|
|
298
|
-
organizationId: "demo-org",
|
|
299
|
-
name: "GitHub Integration",
|
|
300
|
-
slug: "github-integration",
|
|
301
|
-
description: "Interact with GitHub repositories, PRs, and issues.",
|
|
302
|
-
category: "INTEGRATION",
|
|
303
|
-
status: "ACTIVE",
|
|
304
|
-
parametersSchema: {
|
|
305
|
-
type: "object",
|
|
306
|
-
properties: {
|
|
307
|
-
action: {
|
|
308
|
-
type: "string",
|
|
309
|
-
enum: ["list_prs", "get_pr", "create_comment"]
|
|
310
|
-
},
|
|
311
|
-
repo: { type: "string" },
|
|
312
|
-
params: { type: "object" }
|
|
313
|
-
},
|
|
314
|
-
required: ["action", "repo"]
|
|
315
|
-
},
|
|
316
|
-
implementationType: "http",
|
|
317
|
-
implementationConfig: { url: "https://api.github.com", auth: "token" },
|
|
318
|
-
maxInvocationsPerMinute: 100,
|
|
319
|
-
timeoutMs: 15000,
|
|
320
|
-
version: "2.0.0",
|
|
321
|
-
tags: ["github", "integration", "code"],
|
|
322
|
-
createdAt: new Date("2024-02-20T00:00:00Z"),
|
|
323
|
-
updatedAt: new Date("2024-04-01T09:00:00Z")
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
id: "tool-5",
|
|
327
|
-
organizationId: "demo-org",
|
|
328
|
-
name: "Calculator",
|
|
329
|
-
slug: "calculator",
|
|
330
|
-
description: "Perform mathematical calculations.",
|
|
331
|
-
category: "COMPUTATION",
|
|
332
|
-
status: "ACTIVE",
|
|
333
|
-
parametersSchema: {
|
|
334
|
-
type: "object",
|
|
335
|
-
properties: {
|
|
336
|
-
expression: {
|
|
337
|
-
type: "string",
|
|
338
|
-
description: "Math expression to evaluate"
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
required: ["expression"]
|
|
342
|
-
},
|
|
343
|
-
outputSchema: {
|
|
344
|
-
type: "object",
|
|
345
|
-
properties: { result: { type: "number" } }
|
|
346
|
-
},
|
|
347
|
-
implementationType: "function",
|
|
348
|
-
implementationConfig: { handler: "evaluateMath" },
|
|
349
|
-
timeoutMs: 5000,
|
|
350
|
-
version: "1.0.0",
|
|
351
|
-
tags: ["math", "utility"],
|
|
352
|
-
createdAt: new Date("2024-01-10T00:00:00Z"),
|
|
353
|
-
updatedAt: new Date("2024-01-10T00:00:00Z")
|
|
354
|
-
}
|
|
355
|
-
];
|
|
356
|
-
|
|
357
|
-
// src/agent/agent.schema.ts
|
|
358
|
-
import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
|
|
359
|
-
var AgentModel = defineSchemaModel2({
|
|
360
|
-
name: "Agent",
|
|
361
|
-
description: "AI agent configuration",
|
|
362
|
-
fields: {
|
|
363
|
-
id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
364
|
-
organizationId: {
|
|
365
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
366
|
-
isOptional: false
|
|
367
|
-
},
|
|
368
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
369
|
-
slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
370
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
371
|
-
status: { type: AgentStatusEnum, isOptional: false },
|
|
372
|
-
modelProvider: { type: ModelProviderEnum, isOptional: false },
|
|
373
|
-
modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
374
|
-
modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
|
|
375
|
-
systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
376
|
-
userPromptTemplate: {
|
|
377
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
378
|
-
isOptional: true
|
|
379
|
-
},
|
|
380
|
-
toolIds: {
|
|
381
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
382
|
-
isArray: true,
|
|
383
|
-
isOptional: true
|
|
384
|
-
},
|
|
385
|
-
toolChoice: {
|
|
386
|
-
type: ToolChoiceEnum,
|
|
387
|
-
isOptional: false,
|
|
388
|
-
defaultValue: "auto"
|
|
389
|
-
},
|
|
390
|
-
maxIterations: {
|
|
391
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
392
|
-
isOptional: false,
|
|
393
|
-
defaultValue: 10
|
|
394
|
-
},
|
|
395
|
-
maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
396
|
-
timeoutMs: {
|
|
397
|
-
type: ScalarTypeEnum2.Int_unsecure(),
|
|
398
|
-
isOptional: false,
|
|
399
|
-
defaultValue: 120000
|
|
400
|
-
},
|
|
401
|
-
version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
402
|
-
tags: {
|
|
403
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
404
|
-
isArray: true,
|
|
405
|
-
isOptional: true
|
|
406
|
-
},
|
|
407
|
-
createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
|
|
408
|
-
updatedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
var AgentSummaryModel = defineSchemaModel2({
|
|
412
|
-
name: "AgentSummary",
|
|
413
|
-
description: "Summary of an agent for list views",
|
|
414
|
-
fields: {
|
|
415
|
-
id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
416
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
417
|
-
slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
418
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
419
|
-
status: { type: AgentStatusEnum, isOptional: false },
|
|
420
|
-
modelProvider: { type: ModelProviderEnum, isOptional: false },
|
|
421
|
-
modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
422
|
-
version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
423
|
-
createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
var AgentToolRefModel = defineSchemaModel2({
|
|
427
|
-
name: "AgentToolRef",
|
|
428
|
-
description: "Tool reference in agent context",
|
|
429
|
-
fields: {
|
|
430
|
-
id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
431
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
432
|
-
slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
433
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
434
|
-
category: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false }
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
var AgentWithToolsModel = defineSchemaModel2({
|
|
438
|
-
name: "AgentWithTools",
|
|
439
|
-
description: "Agent with associated tools",
|
|
440
|
-
fields: {
|
|
441
|
-
id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
442
|
-
organizationId: {
|
|
443
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
444
|
-
isOptional: false
|
|
445
|
-
},
|
|
446
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
447
|
-
slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
448
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
449
|
-
status: { type: AgentStatusEnum, isOptional: false },
|
|
450
|
-
modelProvider: { type: ModelProviderEnum, isOptional: false },
|
|
451
|
-
modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
452
|
-
modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
|
|
453
|
-
systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
454
|
-
userPromptTemplate: {
|
|
455
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
456
|
-
isOptional: true
|
|
457
|
-
},
|
|
458
|
-
toolIds: {
|
|
459
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
460
|
-
isArray: true,
|
|
461
|
-
isOptional: true
|
|
462
|
-
},
|
|
463
|
-
toolChoice: { type: ToolChoiceEnum, isOptional: false },
|
|
464
|
-
maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
465
|
-
maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
466
|
-
timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
|
|
467
|
-
version: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
468
|
-
tags: {
|
|
469
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
470
|
-
isArray: true,
|
|
471
|
-
isOptional: true
|
|
472
|
-
},
|
|
473
|
-
createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
|
|
474
|
-
updatedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false },
|
|
475
|
-
tools: { type: AgentToolRefModel, isArray: true, isOptional: true }
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
var CreateAgentInputModel = defineSchemaModel2({
|
|
479
|
-
name: "CreateAgentInput",
|
|
480
|
-
description: "Input for creating an agent",
|
|
481
|
-
fields: {
|
|
482
|
-
organizationId: {
|
|
483
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
484
|
-
isOptional: false
|
|
485
|
-
},
|
|
486
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
487
|
-
slug: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
488
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
489
|
-
modelProvider: { type: ModelProviderEnum, isOptional: false },
|
|
490
|
-
modelName: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
|
|
491
|
-
modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
|
|
492
|
-
systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
493
|
-
userPromptTemplate: {
|
|
494
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
495
|
-
isOptional: true
|
|
496
|
-
},
|
|
497
|
-
toolIds: {
|
|
498
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
499
|
-
isArray: true,
|
|
500
|
-
isOptional: true
|
|
501
|
-
},
|
|
502
|
-
toolChoice: { type: ToolChoiceEnum, isOptional: true },
|
|
503
|
-
maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
504
|
-
maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
505
|
-
timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
506
|
-
tags: {
|
|
507
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
508
|
-
isArray: true,
|
|
509
|
-
isOptional: true
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
var UpdateAgentInputModel = defineSchemaModel2({
|
|
514
|
-
name: "UpdateAgentInput",
|
|
515
|
-
description: "Input for updating an agent",
|
|
516
|
-
fields: {
|
|
517
|
-
agentId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
|
|
518
|
-
name: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: true },
|
|
519
|
-
description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
520
|
-
status: { type: AgentStatusEnum, isOptional: true },
|
|
521
|
-
modelConfig: { type: ScalarTypeEnum2.JSONObject(), isOptional: true },
|
|
522
|
-
systemPrompt: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
|
|
523
|
-
userPromptTemplate: {
|
|
524
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
525
|
-
isOptional: true
|
|
526
|
-
},
|
|
527
|
-
toolIds: {
|
|
528
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
529
|
-
isArray: true,
|
|
530
|
-
isOptional: true
|
|
531
|
-
},
|
|
532
|
-
toolChoice: { type: ToolChoiceEnum, isOptional: true },
|
|
533
|
-
maxIterations: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
534
|
-
maxTokensPerRun: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
535
|
-
timeoutMs: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: true },
|
|
536
|
-
tags: {
|
|
537
|
-
type: ScalarTypeEnum2.String_unsecure(),
|
|
538
|
-
isArray: true,
|
|
539
|
-
isOptional: true
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
// src/agent/agent.operation.ts
|
|
545
|
-
import {
|
|
546
|
-
defineCommand,
|
|
547
|
-
defineQuery
|
|
548
|
-
} from "@contractspec/lib.contracts-spec/operations";
|
|
549
|
-
import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
|
|
550
|
-
var OWNERS2 = ["@agent-console-team"];
|
|
551
|
-
var CreateAgentCommand = defineCommand({
|
|
552
|
-
meta: {
|
|
553
|
-
key: "agent-console.agent.create",
|
|
554
|
-
version: "1.0.0",
|
|
555
|
-
stability: "stable",
|
|
556
|
-
owners: [...OWNERS2],
|
|
557
|
-
tags: ["agent", "create"],
|
|
558
|
-
description: "Creates a new AI agent configuration.",
|
|
559
|
-
goal: "Allow users to define new AI agents with specific models and tools.",
|
|
560
|
-
context: "Called from the agent builder UI when creating a new agent."
|
|
561
|
-
},
|
|
562
|
-
io: {
|
|
563
|
-
input: CreateAgentInputModel,
|
|
564
|
-
output: defineSchemaModel3({
|
|
565
|
-
name: "CreateAgentOutput",
|
|
566
|
-
fields: {
|
|
567
|
-
id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
568
|
-
name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
569
|
-
slug: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
570
|
-
status: { type: AgentStatusEnum, isOptional: false }
|
|
571
|
-
}
|
|
572
|
-
}),
|
|
573
|
-
errors: {
|
|
574
|
-
SLUG_EXISTS: {
|
|
575
|
-
description: "An agent with this slug already exists in the organization",
|
|
576
|
-
http: 409,
|
|
577
|
-
gqlCode: "SLUG_EXISTS",
|
|
578
|
-
when: "Slug is already taken"
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
},
|
|
582
|
-
policy: { auth: "user" },
|
|
583
|
-
sideEffects: {
|
|
584
|
-
emits: [
|
|
585
|
-
{
|
|
586
|
-
ref: AgentCreatedEvent.meta,
|
|
587
|
-
when: "Agent is successfully created"
|
|
588
|
-
}
|
|
589
|
-
],
|
|
590
|
-
audit: ["agent-console.agent.created"]
|
|
591
|
-
},
|
|
592
|
-
acceptance: {
|
|
593
|
-
scenarios: [
|
|
594
|
-
{
|
|
595
|
-
key: "create-agent-happy-path",
|
|
596
|
-
given: ["User is authenticated", "Organization exists"],
|
|
597
|
-
when: ["User submits valid agent configuration"],
|
|
598
|
-
then: [
|
|
599
|
-
"New agent is created with DRAFT status",
|
|
600
|
-
"AgentCreated event is emitted"
|
|
601
|
-
]
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
key: "create-agent-slug-conflict",
|
|
605
|
-
given: ["User is authenticated", "Agent with same slug exists"],
|
|
606
|
-
when: ["User submits agent with duplicate slug"],
|
|
607
|
-
then: ["SLUG_EXISTS error is returned with 409 status"]
|
|
608
|
-
}
|
|
609
|
-
],
|
|
610
|
-
examples: [
|
|
611
|
-
{
|
|
612
|
-
key: "basic-create",
|
|
613
|
-
input: {
|
|
614
|
-
name: "Support Assistant",
|
|
615
|
-
slug: "support-assistant",
|
|
616
|
-
modelProvider: "openai",
|
|
617
|
-
modelId: "gpt-4"
|
|
618
|
-
},
|
|
619
|
-
output: {
|
|
620
|
-
id: "agent-123",
|
|
621
|
-
name: "Support Assistant",
|
|
622
|
-
slug: "support-assistant",
|
|
623
|
-
status: "draft"
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
]
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
var UpdateAgentCommand = defineCommand({
|
|
630
|
-
meta: {
|
|
631
|
-
key: "agent-console.agent.update",
|
|
632
|
-
version: "1.0.0",
|
|
633
|
-
stability: "stable",
|
|
634
|
-
owners: [...OWNERS2],
|
|
635
|
-
tags: ["agent", "update"],
|
|
636
|
-
description: "Updates an existing AI agent configuration.",
|
|
637
|
-
goal: "Allow users to modify agent settings and configuration.",
|
|
638
|
-
context: "Called from the agent settings UI."
|
|
639
|
-
},
|
|
640
|
-
io: {
|
|
641
|
-
input: UpdateAgentInputModel,
|
|
642
|
-
output: defineSchemaModel3({
|
|
643
|
-
name: "UpdateAgentOutput",
|
|
644
|
-
fields: {
|
|
645
|
-
id: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
646
|
-
name: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
|
|
647
|
-
status: { type: AgentStatusEnum, isOptional: false },
|
|
648
|
-
updatedAt: { type: ScalarTypeEnum3.DateTime(), isOptional: false }
|
|
649
|
-
}
|
|
650
|
-
}),
|
|
651
|
-
errors: {
|
|
652
|
-
AGENT_NOT_FOUND: {
|
|
653
|
-
description: "The specified agent does not exist",
|
|
654
|
-
http: 404,
|
|
655
|
-
gqlCode: "AGENT_NOT_FOUND",
|
|
656
|
-
when: "Agent ID is invalid"
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
},
|
|
660
|
-
policy: { auth: "user" },
|
|
661
|
-
sideEffects: {
|
|
662
|
-
emits: [
|
|
663
|
-
{
|
|
664
|
-
key: "agent.updated",
|
|
665
|
-
version: "1.0.0",
|
|
666
|
-
stability: "stable",
|
|
667
|
-
owners: [...OWNERS2],
|
|
668
|
-
tags: ["agent", "updated"],
|
|
669
|
-
when: "Agent is updated",
|
|
670
|
-
payload: AgentSummaryModel
|
|
671
|
-
}
|
|
672
|
-
],
|
|
673
|
-
audit: ["agent.updated"]
|
|
674
|
-
},
|
|
675
|
-
acceptance: {
|
|
676
|
-
scenarios: [
|
|
677
|
-
{
|
|
678
|
-
key: "update-agent-happy-path",
|
|
679
|
-
given: ["Agent exists", "User owns the agent"],
|
|
680
|
-
when: ["User submits updated configuration"],
|
|
681
|
-
then: ["Agent is updated", "AgentUpdated event is emitted"]
|
|
682
|
-
},
|
|
683
|
-
{
|
|
684
|
-
key: "update-agent-not-found",
|
|
685
|
-
given: ["Agent does not exist"],
|
|
686
|
-
when: ["User attempts to update"],
|
|
687
|
-
then: ["AGENT_NOT_FOUND error is returned"]
|
|
688
|
-
}
|
|
689
|
-
],
|
|
690
|
-
examples: [
|
|
691
|
-
{
|
|
692
|
-
key: "update-name",
|
|
693
|
-
input: {
|
|
694
|
-
agentId: "agent-123",
|
|
695
|
-
name: "Updated Assistant",
|
|
696
|
-
systemPrompt: "You are a helpful assistant."
|
|
697
|
-
},
|
|
698
|
-
output: {
|
|
699
|
-
id: "agent-123",
|
|
700
|
-
name: "Updated Assistant",
|
|
701
|
-
status: "draft",
|
|
702
|
-
updatedAt: "2025-01-01T00:00:00Z"
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
]
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
var GetAgentQuery = defineQuery({
|
|
709
|
-
meta: {
|
|
710
|
-
key: "agent-console.agent.get",
|
|
711
|
-
version: "1.0.0",
|
|
712
|
-
stability: "stable",
|
|
713
|
-
owners: [...OWNERS2],
|
|
714
|
-
tags: ["agent", "get"],
|
|
715
|
-
description: "Retrieves an agent by its ID.",
|
|
716
|
-
goal: "View detailed agent configuration.",
|
|
717
|
-
context: "Called when viewing agent details or editing."
|
|
718
|
-
},
|
|
719
|
-
io: {
|
|
720
|
-
input: defineSchemaModel3({
|
|
721
|
-
name: "GetAgentInput",
|
|
722
|
-
fields: {
|
|
723
|
-
agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
724
|
-
includeTools: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
|
|
725
|
-
}
|
|
726
|
-
}),
|
|
727
|
-
output: AgentWithToolsModel,
|
|
728
|
-
errors: {
|
|
729
|
-
AGENT_NOT_FOUND: {
|
|
730
|
-
description: "The specified agent does not exist",
|
|
731
|
-
http: 404,
|
|
732
|
-
gqlCode: "AGENT_NOT_FOUND",
|
|
733
|
-
when: "Agent ID is invalid"
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
policy: { auth: "user" },
|
|
738
|
-
acceptance: {
|
|
739
|
-
scenarios: [
|
|
740
|
-
{
|
|
741
|
-
key: "get-agent-happy-path",
|
|
742
|
-
given: ["Agent exists"],
|
|
743
|
-
when: ["User requests agent by ID"],
|
|
744
|
-
then: ["Agent details are returned"]
|
|
745
|
-
},
|
|
746
|
-
{
|
|
747
|
-
key: "get-agent-with-tools",
|
|
748
|
-
given: ["Agent exists with assigned tools"],
|
|
749
|
-
when: ["User requests agent with includeTools=true"],
|
|
750
|
-
then: ["Agent details with tools list are returned"]
|
|
751
|
-
}
|
|
752
|
-
],
|
|
753
|
-
examples: [
|
|
754
|
-
{
|
|
755
|
-
key: "get-basic",
|
|
756
|
-
input: { agentId: "agent-123", includeTools: false },
|
|
757
|
-
output: {
|
|
758
|
-
id: "agent-123",
|
|
759
|
-
name: "Support Assistant",
|
|
760
|
-
status: "active",
|
|
761
|
-
tools: []
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
]
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
var ListAgentsQuery = defineQuery({
|
|
768
|
-
meta: {
|
|
769
|
-
key: "agent-console.agent.list",
|
|
770
|
-
version: "1.0.0",
|
|
771
|
-
stability: "stable",
|
|
772
|
-
owners: [...OWNERS2],
|
|
773
|
-
tags: ["agent", "list"],
|
|
774
|
-
description: "Lists agents for an organization with optional filtering.",
|
|
775
|
-
goal: "Browse and search available agents.",
|
|
776
|
-
context: "Agent list/dashboard view."
|
|
777
|
-
},
|
|
778
|
-
io: {
|
|
779
|
-
input: defineSchemaModel3({
|
|
780
|
-
name: "ListAgentsInput",
|
|
781
|
-
fields: {
|
|
782
|
-
organizationId: {
|
|
783
|
-
type: ScalarTypeEnum3.String_unsecure(),
|
|
784
|
-
isOptional: false
|
|
785
|
-
},
|
|
786
|
-
status: { type: AgentStatusEnum, isOptional: true },
|
|
787
|
-
modelProvider: { type: ModelProviderEnum, isOptional: true },
|
|
788
|
-
search: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
|
|
789
|
-
limit: {
|
|
790
|
-
type: ScalarTypeEnum3.Int_unsecure(),
|
|
791
|
-
isOptional: true,
|
|
792
|
-
defaultValue: 20
|
|
793
|
-
},
|
|
794
|
-
offset: {
|
|
795
|
-
type: ScalarTypeEnum3.Int_unsecure(),
|
|
796
|
-
isOptional: true,
|
|
797
|
-
defaultValue: 0
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}),
|
|
801
|
-
output: defineSchemaModel3({
|
|
802
|
-
name: "ListAgentsOutput",
|
|
803
|
-
fields: {
|
|
804
|
-
items: { type: AgentSummaryModel, isArray: true, isOptional: false },
|
|
805
|
-
total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
|
|
806
|
-
hasMore: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
|
|
807
|
-
}
|
|
808
|
-
})
|
|
809
|
-
},
|
|
810
|
-
policy: { auth: "user" },
|
|
811
|
-
acceptance: {
|
|
812
|
-
scenarios: [
|
|
813
|
-
{
|
|
814
|
-
key: "list-agents-happy-path",
|
|
815
|
-
given: ["Organization has agents"],
|
|
816
|
-
when: ["User lists agents"],
|
|
817
|
-
then: ["Paginated list of agents is returned"]
|
|
818
|
-
},
|
|
819
|
-
{
|
|
820
|
-
key: "list-agents-filter-by-status",
|
|
821
|
-
given: ["Organization has agents with mixed statuses"],
|
|
822
|
-
when: ["User filters by status=active"],
|
|
823
|
-
then: ["Only active agents are returned"]
|
|
824
|
-
}
|
|
825
|
-
],
|
|
826
|
-
examples: [
|
|
827
|
-
{
|
|
828
|
-
key: "list-basic",
|
|
829
|
-
input: { organizationId: "org-123", limit: 10, offset: 0 },
|
|
830
|
-
output: { items: [], total: 0, hasMore: false }
|
|
831
|
-
}
|
|
832
|
-
]
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
var AssignToolToAgentCommand = defineCommand({
|
|
836
|
-
meta: {
|
|
837
|
-
key: "agent-console.agent.assignTool",
|
|
838
|
-
version: "1.0.0",
|
|
839
|
-
stability: "stable",
|
|
840
|
-
owners: [...OWNERS2],
|
|
841
|
-
tags: ["agent", "tool", "assign"],
|
|
842
|
-
description: "Assigns a tool to an agent with optional configuration.",
|
|
843
|
-
goal: "Enable agents to use specific tools.",
|
|
844
|
-
context: "Agent configuration UI - tool selection."
|
|
845
|
-
},
|
|
846
|
-
io: {
|
|
847
|
-
input: defineSchemaModel3({
|
|
848
|
-
name: "AssignToolToAgentInput",
|
|
849
|
-
fields: {
|
|
850
|
-
agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
851
|
-
toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
852
|
-
config: { type: ScalarTypeEnum3.JSONObject(), isOptional: true },
|
|
853
|
-
order: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: true }
|
|
854
|
-
}
|
|
855
|
-
}),
|
|
856
|
-
output: defineSchemaModel3({
|
|
857
|
-
name: "AssignToolToAgentOutput",
|
|
858
|
-
fields: {
|
|
859
|
-
agentToolId: {
|
|
860
|
-
type: ScalarTypeEnum3.String_unsecure(),
|
|
861
|
-
isOptional: false
|
|
862
|
-
},
|
|
863
|
-
agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
864
|
-
toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
|
|
865
|
-
}
|
|
866
|
-
}),
|
|
867
|
-
errors: {
|
|
868
|
-
TOOL_ALREADY_ASSIGNED: {
|
|
869
|
-
description: "This tool is already assigned to the agent",
|
|
870
|
-
http: 409,
|
|
871
|
-
gqlCode: "TOOL_ALREADY_ASSIGNED",
|
|
872
|
-
when: "Tool assignment already exists"
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
},
|
|
876
|
-
policy: { auth: "user" },
|
|
877
|
-
sideEffects: { audit: ["agent.tool.assigned"] },
|
|
878
|
-
acceptance: {
|
|
879
|
-
scenarios: [
|
|
880
|
-
{
|
|
881
|
-
key: "assign-tool-happy-path",
|
|
882
|
-
given: ["Agent exists", "Tool exists and is not assigned"],
|
|
883
|
-
when: ["User assigns tool to agent"],
|
|
884
|
-
then: ["Tool is assigned", "Assignment ID is returned"]
|
|
885
|
-
},
|
|
886
|
-
{
|
|
887
|
-
key: "assign-tool-already-assigned",
|
|
888
|
-
given: ["Tool is already assigned to agent"],
|
|
889
|
-
when: ["User attempts to assign again"],
|
|
890
|
-
then: ["TOOL_ALREADY_ASSIGNED error is returned"]
|
|
891
|
-
}
|
|
892
|
-
],
|
|
893
|
-
examples: [
|
|
894
|
-
{
|
|
895
|
-
key: "assign-basic",
|
|
896
|
-
input: { agentId: "agent-123", toolId: "tool-456" },
|
|
897
|
-
output: {
|
|
898
|
-
agentToolId: "at-789",
|
|
899
|
-
agentId: "agent-123",
|
|
900
|
-
toolId: "tool-456"
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
]
|
|
904
|
-
}
|
|
905
|
-
});
|
|
906
|
-
var RemoveToolFromAgentCommand = defineCommand({
|
|
907
|
-
meta: {
|
|
908
|
-
key: "agent-console.agent.removeTool",
|
|
909
|
-
version: "1.0.0",
|
|
910
|
-
stability: "stable",
|
|
911
|
-
owners: [...OWNERS2],
|
|
912
|
-
tags: ["agent", "tool", "remove"],
|
|
913
|
-
description: "Removes a tool assignment from an agent.",
|
|
914
|
-
goal: "Disable specific tools for an agent.",
|
|
915
|
-
context: "Agent configuration UI - tool management."
|
|
916
|
-
},
|
|
917
|
-
io: {
|
|
918
|
-
input: defineSchemaModel3({
|
|
919
|
-
name: "RemoveToolFromAgentInput",
|
|
920
|
-
fields: {
|
|
921
|
-
agentId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false },
|
|
922
|
-
toolId: { type: ScalarTypeEnum3.String_unsecure(), isOptional: false }
|
|
923
|
-
}
|
|
924
|
-
}),
|
|
925
|
-
output: defineSchemaModel3({
|
|
926
|
-
name: "RemoveToolFromAgentOutput",
|
|
927
|
-
fields: {
|
|
928
|
-
success: { type: ScalarTypeEnum3.Boolean(), isOptional: false }
|
|
929
|
-
}
|
|
930
|
-
})
|
|
931
|
-
},
|
|
932
|
-
policy: { auth: "user" },
|
|
933
|
-
sideEffects: { audit: ["agent.tool.removed"] },
|
|
934
|
-
acceptance: {
|
|
935
|
-
scenarios: [
|
|
936
|
-
{
|
|
937
|
-
key: "remove-tool-happy-path",
|
|
938
|
-
given: ["Agent exists", "Tool is assigned to agent"],
|
|
939
|
-
when: ["User removes tool from agent"],
|
|
940
|
-
then: ["Tool is unassigned", "Success is returned"]
|
|
941
|
-
}
|
|
942
|
-
],
|
|
943
|
-
examples: [
|
|
944
|
-
{
|
|
945
|
-
key: "remove-basic",
|
|
946
|
-
input: { agentId: "agent-123", toolId: "tool-456" },
|
|
947
|
-
output: { success: true }
|
|
948
|
-
}
|
|
949
|
-
]
|
|
950
|
-
}
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
// src/agent/agent.handler.ts
|
|
954
|
-
var nextMockAgentId = MOCK_AGENTS.length + 1;
|
|
955
|
-
async function mockListAgentsHandler(input) {
|
|
956
|
-
const {
|
|
957
|
-
organizationId,
|
|
958
|
-
status,
|
|
959
|
-
modelProvider,
|
|
960
|
-
search,
|
|
961
|
-
limit = 20,
|
|
962
|
-
offset = 0
|
|
963
|
-
} = input;
|
|
964
|
-
let filtered = MOCK_AGENTS.filter((a) => a.organizationId === organizationId);
|
|
965
|
-
if (status)
|
|
966
|
-
filtered = filtered.filter((a) => a.status === status);
|
|
967
|
-
if (modelProvider)
|
|
968
|
-
filtered = filtered.filter((a) => a.modelProvider === modelProvider);
|
|
969
|
-
if (search) {
|
|
970
|
-
const q = search.toLowerCase();
|
|
971
|
-
filtered = filtered.filter((a) => a.name.toLowerCase().includes(q) || a.description?.toLowerCase().includes(q) || a.tags?.some((t) => t.toLowerCase().includes(q)));
|
|
972
|
-
}
|
|
973
|
-
const total = filtered.length;
|
|
974
|
-
const items = filtered.slice(offset, offset + limit).map((a) => ({
|
|
975
|
-
id: a.id,
|
|
976
|
-
name: a.name,
|
|
977
|
-
slug: a.slug,
|
|
978
|
-
description: a.description,
|
|
979
|
-
status: a.status,
|
|
980
|
-
modelProvider: a.modelProvider,
|
|
981
|
-
modelName: a.modelName,
|
|
982
|
-
version: a.version,
|
|
983
|
-
createdAt: a.createdAt
|
|
984
|
-
}));
|
|
985
|
-
return { items, total, hasMore: offset + limit < total };
|
|
986
|
-
}
|
|
987
|
-
async function mockGetAgentHandler(input) {
|
|
988
|
-
const agent = MOCK_AGENTS.find((a) => a.id === input.agentId);
|
|
989
|
-
if (!agent)
|
|
990
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
991
|
-
const result = { ...agent, toolIds: ["tool-1", "tool-2"] };
|
|
992
|
-
if (input.includeTools) {
|
|
993
|
-
result.tools = MOCK_TOOLS.slice(0, 2).map((t) => ({
|
|
994
|
-
id: t.id,
|
|
995
|
-
name: t.name,
|
|
996
|
-
slug: t.slug,
|
|
997
|
-
description: t.description,
|
|
998
|
-
category: t.category
|
|
999
|
-
}));
|
|
1000
|
-
}
|
|
1001
|
-
return result;
|
|
1002
|
-
}
|
|
1003
|
-
async function mockCreateAgentHandler(input) {
|
|
1004
|
-
const exists = MOCK_AGENTS.some((a) => a.organizationId === input.organizationId && a.slug === input.slug);
|
|
1005
|
-
if (exists)
|
|
1006
|
-
throw new Error("SLUG_EXISTS");
|
|
1007
|
-
return {
|
|
1008
|
-
id: `agent-${nextMockAgentId++}`,
|
|
1009
|
-
name: input.name,
|
|
1010
|
-
slug: input.slug,
|
|
1011
|
-
status: "DRAFT"
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
async function mockUpdateAgentHandler(input) {
|
|
1015
|
-
const agent = MOCK_AGENTS.find((a) => a.id === input.agentId);
|
|
1016
|
-
if (!agent)
|
|
1017
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
1018
|
-
return {
|
|
1019
|
-
id: agent.id,
|
|
1020
|
-
name: input.name ?? agent.name,
|
|
1021
|
-
status: input.status ?? agent.status,
|
|
1022
|
-
updatedAt: new Date
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
// src/run/run.enum.ts
|
|
1027
|
-
import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
|
|
1028
|
-
var RunStatusEnum = defineEnum2("RunStatus", [
|
|
1029
|
-
"QUEUED",
|
|
1030
|
-
"IN_PROGRESS",
|
|
1031
|
-
"COMPLETED",
|
|
1032
|
-
"FAILED",
|
|
1033
|
-
"CANCELLED",
|
|
1034
|
-
"EXPIRED"
|
|
1035
|
-
]);
|
|
1036
|
-
var RunStepTypeEnum = defineEnum2("RunStepType", [
|
|
1037
|
-
"MESSAGE_CREATION",
|
|
1038
|
-
"TOOL_CALL",
|
|
1039
|
-
"TOOL_RESULT",
|
|
1040
|
-
"ERROR"
|
|
1041
|
-
]);
|
|
1042
|
-
var LogLevelEnum = defineEnum2("LogLevel", [
|
|
1043
|
-
"DEBUG",
|
|
1044
|
-
"INFO",
|
|
1045
|
-
"WARN",
|
|
1046
|
-
"ERROR"
|
|
1047
|
-
]);
|
|
1048
|
-
var GranularityEnum = defineEnum2("Granularity", [
|
|
1049
|
-
"hour",
|
|
1050
|
-
"day",
|
|
1051
|
-
"week",
|
|
1052
|
-
"month"
|
|
1053
|
-
]);
|
|
1054
|
-
|
|
1055
|
-
// src/run/run.schema.ts
|
|
1056
|
-
import { defineSchemaModel as defineSchemaModel4, ScalarTypeEnum as ScalarTypeEnum4 } from "@contractspec/lib.schema";
|
|
1057
|
-
var RunInputModel = defineSchemaModel4({
|
|
1058
|
-
name: "RunInput",
|
|
1059
|
-
description: "Input data for agent execution",
|
|
1060
|
-
fields: {
|
|
1061
|
-
message: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
|
|
1062
|
-
context: { type: ScalarTypeEnum4.JSONObject(), isOptional: true }
|
|
1063
|
-
}
|
|
1064
|
-
});
|
|
1065
|
-
var RunStepModel = defineSchemaModel4({
|
|
1066
|
-
name: "RunStep",
|
|
1067
|
-
description: "Individual step within a run",
|
|
1068
|
-
fields: {
|
|
1069
|
-
id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1070
|
-
stepNumber: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
|
|
1071
|
-
type: { type: RunStepTypeEnum, isOptional: false },
|
|
1072
|
-
toolId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1073
|
-
toolName: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1074
|
-
input: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
|
|
1075
|
-
output: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
|
|
1076
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
1077
|
-
errorMessage: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1078
|
-
tokensUsed: {
|
|
1079
|
-
type: ScalarTypeEnum4.Int_unsecure(),
|
|
1080
|
-
isOptional: false,
|
|
1081
|
-
defaultValue: 0
|
|
1082
|
-
},
|
|
1083
|
-
durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
|
|
1084
|
-
startedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
|
|
1085
|
-
completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true }
|
|
1086
|
-
}
|
|
1087
|
-
});
|
|
1088
|
-
var RunLogModel = defineSchemaModel4({
|
|
1089
|
-
name: "RunLog",
|
|
1090
|
-
description: "Execution log entry",
|
|
1091
|
-
fields: {
|
|
1092
|
-
id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1093
|
-
stepId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1094
|
-
level: { type: LogLevelEnum, isOptional: false },
|
|
1095
|
-
message: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1096
|
-
data: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
|
|
1097
|
-
source: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1098
|
-
traceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1099
|
-
spanId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1100
|
-
timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
var RunAgentRefModel = defineSchemaModel4({
|
|
1104
|
-
name: "RunAgentRef",
|
|
1105
|
-
description: "Agent reference in a run",
|
|
1106
|
-
fields: {
|
|
1107
|
-
id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1108
|
-
name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
|
|
1109
|
-
modelProvider: {
|
|
1110
|
-
type: ScalarTypeEnum4.String_unsecure(),
|
|
1111
|
-
isOptional: false
|
|
1112
|
-
},
|
|
1113
|
-
modelName: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false }
|
|
1114
|
-
}
|
|
1115
|
-
});
|
|
1116
|
-
var RunModel = defineSchemaModel4({
|
|
1117
|
-
name: "Run",
|
|
1118
|
-
description: "Agent execution instance",
|
|
1119
|
-
fields: {
|
|
1120
|
-
id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1121
|
-
organizationId: {
|
|
1122
|
-
type: ScalarTypeEnum4.String_unsecure(),
|
|
1123
|
-
isOptional: false
|
|
1124
|
-
},
|
|
1125
|
-
agentId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1126
|
-
userId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1127
|
-
sessionId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1128
|
-
input: { type: ScalarTypeEnum4.JSONObject(), isOptional: false },
|
|
1129
|
-
output: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
|
|
1130
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
1131
|
-
errorMessage: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1132
|
-
errorCode: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
|
|
1133
|
-
totalTokens: {
|
|
1134
|
-
type: ScalarTypeEnum4.Int_unsecure(),
|
|
1135
|
-
isOptional: false,
|
|
1136
|
-
defaultValue: 0
|
|
1137
|
-
},
|
|
1138
|
-
promptTokens: {
|
|
1139
|
-
type: ScalarTypeEnum4.Int_unsecure(),
|
|
1140
|
-
isOptional: false,
|
|
1141
|
-
defaultValue: 0
|
|
1142
|
-
},
|
|
1143
|
-
completionTokens: {
|
|
1144
|
-
type: ScalarTypeEnum4.Int_unsecure(),
|
|
1145
|
-
isOptional: false,
|
|
1146
|
-
defaultValue: 0
|
|
1147
|
-
},
|
|
1148
|
-
totalIterations: {
|
|
1149
|
-
type: ScalarTypeEnum4.Int_unsecure(),
|
|
1150
|
-
isOptional: false,
|
|
1151
|
-
defaultValue: 0
|
|
1152
|
-
},
|
|
1153
|
-
durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
|
|
1154
|
-
estimatedCostUsd: {
|
|
1155
|
-
type: ScalarTypeEnum4.Float_unsecure(),
|
|
1156
|
-
isOptional: true
|
|
1157
|
-
},
|
|
1158
|
-
queuedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
|
|
1159
|
-
startedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true },
|
|
1160
|
-
completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true },
|
|
1161
|
-
metadata: { type: ScalarTypeEnum4.JSONObject(), isOptional: true },
|
|
1162
|
-
steps: { type: RunStepModel, isArray: true, isOptional: true },
|
|
1163
|
-
logs: { type: RunLogModel, isArray: true, isOptional: true },
|
|
1164
|
-
agent: { type: RunAgentRefModel, isOptional: true }
|
|
1165
|
-
}
|
|
1166
|
-
});
|
|
1167
|
-
var RunSummaryModel = defineSchemaModel4({
|
|
1168
|
-
name: "RunSummary",
|
|
1169
|
-
description: "Summary of a run for list views",
|
|
1170
|
-
fields: {
|
|
1171
|
-
id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1172
|
-
agentId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1173
|
-
agentName: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
|
|
1174
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
1175
|
-
totalTokens: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
|
|
1176
|
-
durationMs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
|
|
1177
|
-
estimatedCostUsd: {
|
|
1178
|
-
type: ScalarTypeEnum4.Float_unsecure(),
|
|
1179
|
-
isOptional: true
|
|
1180
|
-
},
|
|
1181
|
-
queuedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
|
|
1182
|
-
completedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: true }
|
|
1183
|
-
}
|
|
1184
|
-
});
|
|
1185
|
-
var TimelineDataPointModel = defineSchemaModel4({
|
|
1186
|
-
name: "TimelineDataPoint",
|
|
1187
|
-
description: "Timeline data point for metrics",
|
|
1188
|
-
fields: {
|
|
1189
|
-
period: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
|
|
1190
|
-
runs: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
|
|
1191
|
-
tokens: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
|
|
1192
|
-
costUsd: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false },
|
|
1193
|
-
avgDurationMs: { type: ScalarTypeEnum4.Float_unsecure(), isOptional: false }
|
|
1194
|
-
}
|
|
1195
|
-
});
|
|
1196
|
-
|
|
1197
|
-
// src/run/run.operation.ts
|
|
1198
|
-
import {
|
|
1199
|
-
defineCommand as defineCommand2,
|
|
1200
|
-
defineQuery as defineQuery2
|
|
1201
|
-
} from "@contractspec/lib.contracts-spec/operations";
|
|
1202
|
-
import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
|
|
1203
|
-
var OWNERS3 = ["@agent-console-team"];
|
|
1204
|
-
var ExecuteAgentCommand = defineCommand2({
|
|
1205
|
-
meta: {
|
|
1206
|
-
key: "agent.run.execute",
|
|
1207
|
-
version: "1.0.0",
|
|
1208
|
-
stability: "stable",
|
|
1209
|
-
owners: [...OWNERS3],
|
|
1210
|
-
tags: ["run", "execute"],
|
|
1211
|
-
description: "Starts a new agent run with the given input.",
|
|
1212
|
-
goal: "Execute an AI agent with user input.",
|
|
1213
|
-
context: "Called from chat interface or API."
|
|
1214
|
-
},
|
|
1215
|
-
io: {
|
|
1216
|
-
input: defineSchemaModel5({
|
|
1217
|
-
name: "ExecuteAgentInput",
|
|
1218
|
-
fields: {
|
|
1219
|
-
agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
|
|
1220
|
-
input: { type: RunInputModel, isOptional: false },
|
|
1221
|
-
sessionId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
|
|
1222
|
-
metadata: { type: ScalarTypeEnum5.JSONObject(), isOptional: true },
|
|
1223
|
-
stream: { type: ScalarTypeEnum5.Boolean(), isOptional: true },
|
|
1224
|
-
maxIterations: {
|
|
1225
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1226
|
-
isOptional: true
|
|
1227
|
-
},
|
|
1228
|
-
timeoutMs: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: true }
|
|
1229
|
-
}
|
|
1230
|
-
}),
|
|
1231
|
-
output: defineSchemaModel5({
|
|
1232
|
-
name: "ExecuteAgentOutput",
|
|
1233
|
-
fields: {
|
|
1234
|
-
runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
|
|
1235
|
-
status: { type: RunStatusEnum, isOptional: false },
|
|
1236
|
-
estimatedWaitMs: {
|
|
1237
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1238
|
-
isOptional: true
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}),
|
|
1242
|
-
errors: {
|
|
1243
|
-
AGENT_NOT_FOUND: {
|
|
1244
|
-
description: "The specified agent does not exist",
|
|
1245
|
-
http: 404,
|
|
1246
|
-
gqlCode: "AGENT_NOT_FOUND",
|
|
1247
|
-
when: "Agent ID is invalid"
|
|
1248
|
-
},
|
|
1249
|
-
AGENT_NOT_ACTIVE: {
|
|
1250
|
-
description: "The specified agent is not active",
|
|
1251
|
-
http: 400,
|
|
1252
|
-
gqlCode: "AGENT_NOT_ACTIVE",
|
|
1253
|
-
when: "Agent is in draft/paused/archived state"
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
},
|
|
1257
|
-
policy: { auth: "user" },
|
|
1258
|
-
sideEffects: {
|
|
1259
|
-
emits: [
|
|
1260
|
-
{
|
|
1261
|
-
key: "run.started",
|
|
1262
|
-
version: "1.0.0",
|
|
1263
|
-
stability: "stable",
|
|
1264
|
-
owners: [...OWNERS3],
|
|
1265
|
-
tags: ["run", "started"],
|
|
1266
|
-
when: "Run is queued",
|
|
1267
|
-
payload: RunSummaryModel
|
|
1268
|
-
}
|
|
1269
|
-
],
|
|
1270
|
-
audit: ["run.started"]
|
|
1271
|
-
},
|
|
1272
|
-
acceptance: {
|
|
1273
|
-
scenarios: [
|
|
1274
|
-
{
|
|
1275
|
-
key: "execute-agent-happy-path",
|
|
1276
|
-
given: ["Agent exists", "Agent is active"],
|
|
1277
|
-
when: ["User submits execution request"],
|
|
1278
|
-
then: ["Run is created", "RunStarted event is emitted"]
|
|
1279
|
-
},
|
|
1280
|
-
{
|
|
1281
|
-
key: "execute-agent-not-active",
|
|
1282
|
-
given: ["Agent exists but is not active"],
|
|
1283
|
-
when: ["User attempts to execute"],
|
|
1284
|
-
then: ["AGENT_NOT_ACTIVE error is returned"]
|
|
1285
|
-
}
|
|
1286
|
-
],
|
|
1287
|
-
examples: [
|
|
1288
|
-
{
|
|
1289
|
-
key: "basic-execute",
|
|
1290
|
-
input: { agentId: "agent-123", input: { message: "Hello" } },
|
|
1291
|
-
output: { runId: "run-456", status: "pending", estimatedWaitMs: 5000 }
|
|
1292
|
-
}
|
|
1293
|
-
]
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
var CancelRunCommand = defineCommand2({
|
|
1297
|
-
meta: {
|
|
1298
|
-
key: "agent.run.cancel",
|
|
1299
|
-
version: "1.0.0",
|
|
1300
|
-
stability: "stable",
|
|
1301
|
-
owners: [...OWNERS3],
|
|
1302
|
-
tags: ["run", "cancel"],
|
|
1303
|
-
description: "Cancels an in-progress agent run.",
|
|
1304
|
-
goal: "Stop a running agent execution.",
|
|
1305
|
-
context: "Called when user wants to abort a long-running task."
|
|
1306
|
-
},
|
|
1307
|
-
io: {
|
|
1308
|
-
input: defineSchemaModel5({
|
|
1309
|
-
name: "CancelRunInput",
|
|
1310
|
-
fields: {
|
|
1311
|
-
runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
|
|
1312
|
-
reason: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
|
|
1313
|
-
}
|
|
1314
|
-
}),
|
|
1315
|
-
output: defineSchemaModel5({
|
|
1316
|
-
name: "CancelRunOutput",
|
|
1317
|
-
fields: {
|
|
1318
|
-
success: { type: ScalarTypeEnum5.Boolean(), isOptional: false },
|
|
1319
|
-
status: { type: RunStatusEnum, isOptional: false }
|
|
1320
|
-
}
|
|
1321
|
-
}),
|
|
1322
|
-
errors: {
|
|
1323
|
-
RUN_NOT_FOUND: {
|
|
1324
|
-
description: "The specified run does not exist",
|
|
1325
|
-
http: 404,
|
|
1326
|
-
gqlCode: "RUN_NOT_FOUND",
|
|
1327
|
-
when: "Run ID is invalid"
|
|
1328
|
-
},
|
|
1329
|
-
RUN_NOT_CANCELLABLE: {
|
|
1330
|
-
description: "The run cannot be cancelled",
|
|
1331
|
-
http: 400,
|
|
1332
|
-
gqlCode: "RUN_NOT_CANCELLABLE",
|
|
1333
|
-
when: "Run is already completed/failed/cancelled"
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
},
|
|
1337
|
-
policy: { auth: "user" },
|
|
1338
|
-
sideEffects: {
|
|
1339
|
-
emits: [
|
|
1340
|
-
{
|
|
1341
|
-
key: "run.cancelled",
|
|
1342
|
-
version: "1.0.0",
|
|
1343
|
-
stability: "stable",
|
|
1344
|
-
owners: [...OWNERS3],
|
|
1345
|
-
tags: ["run", "cancelled"],
|
|
1346
|
-
when: "Run is cancelled",
|
|
1347
|
-
payload: RunSummaryModel
|
|
1348
|
-
}
|
|
1349
|
-
],
|
|
1350
|
-
audit: ["run.cancelled"]
|
|
1351
|
-
},
|
|
1352
|
-
acceptance: {
|
|
1353
|
-
scenarios: [
|
|
1354
|
-
{
|
|
1355
|
-
key: "cancel-run-happy-path",
|
|
1356
|
-
given: ["Run exists", "Run is in progress"],
|
|
1357
|
-
when: ["User cancels run"],
|
|
1358
|
-
then: ["Run is cancelled", "RunCancelled event is emitted"]
|
|
1359
|
-
},
|
|
1360
|
-
{
|
|
1361
|
-
key: "cancel-run-already-completed",
|
|
1362
|
-
given: ["Run exists but is already completed"],
|
|
1363
|
-
when: ["User attempts to cancel"],
|
|
1364
|
-
then: ["RUN_NOT_CANCELLABLE error is returned"]
|
|
1365
|
-
}
|
|
1366
|
-
],
|
|
1367
|
-
examples: [
|
|
1368
|
-
{
|
|
1369
|
-
key: "cancel-basic",
|
|
1370
|
-
input: { runId: "run-456", reason: "User requested" },
|
|
1371
|
-
output: { success: true, status: "cancelled" }
|
|
1372
|
-
}
|
|
1373
|
-
]
|
|
1374
|
-
}
|
|
1375
|
-
});
|
|
1376
|
-
var GetRunQuery = defineQuery2({
|
|
1377
|
-
meta: {
|
|
1378
|
-
key: "agent.run.get",
|
|
1379
|
-
version: "1.0.0",
|
|
1380
|
-
stability: "stable",
|
|
1381
|
-
owners: [...OWNERS3],
|
|
1382
|
-
tags: ["run", "get"],
|
|
1383
|
-
description: "Retrieves a run by its ID with optional details.",
|
|
1384
|
-
goal: "View detailed run information.",
|
|
1385
|
-
context: "Run details page or monitoring."
|
|
1386
|
-
},
|
|
1387
|
-
io: {
|
|
1388
|
-
input: defineSchemaModel5({
|
|
1389
|
-
name: "GetRunInput",
|
|
1390
|
-
fields: {
|
|
1391
|
-
runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
|
|
1392
|
-
includeSteps: { type: ScalarTypeEnum5.Boolean(), isOptional: true },
|
|
1393
|
-
includeLogs: { type: ScalarTypeEnum5.Boolean(), isOptional: true }
|
|
1394
|
-
}
|
|
1395
|
-
}),
|
|
1396
|
-
output: RunModel,
|
|
1397
|
-
errors: {
|
|
1398
|
-
RUN_NOT_FOUND: {
|
|
1399
|
-
description: "The specified run does not exist",
|
|
1400
|
-
http: 404,
|
|
1401
|
-
gqlCode: "RUN_NOT_FOUND",
|
|
1402
|
-
when: "Run ID is invalid"
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
},
|
|
1406
|
-
policy: { auth: "user" },
|
|
1407
|
-
acceptance: {
|
|
1408
|
-
scenarios: [
|
|
1409
|
-
{
|
|
1410
|
-
key: "get-run-happy-path",
|
|
1411
|
-
given: ["Run exists"],
|
|
1412
|
-
when: ["User requests run by ID"],
|
|
1413
|
-
then: ["Run details are returned"]
|
|
1414
|
-
}
|
|
1415
|
-
],
|
|
1416
|
-
examples: [
|
|
1417
|
-
{
|
|
1418
|
-
key: "get-with-steps",
|
|
1419
|
-
input: { runId: "run-456", includeSteps: true, includeLogs: false },
|
|
1420
|
-
output: { id: "run-456", status: "completed", steps: [] }
|
|
1421
|
-
}
|
|
1422
|
-
]
|
|
1423
|
-
}
|
|
1424
|
-
});
|
|
1425
|
-
var ListRunsQuery = defineQuery2({
|
|
1426
|
-
meta: {
|
|
1427
|
-
key: "agent.run.list",
|
|
1428
|
-
version: "1.0.0",
|
|
1429
|
-
stability: "stable",
|
|
1430
|
-
owners: [...OWNERS3],
|
|
1431
|
-
tags: ["run", "list"],
|
|
1432
|
-
description: "Lists runs with optional filtering.",
|
|
1433
|
-
goal: "Browse and search run history.",
|
|
1434
|
-
context: "Run history/dashboard view."
|
|
1435
|
-
},
|
|
1436
|
-
io: {
|
|
1437
|
-
input: defineSchemaModel5({
|
|
1438
|
-
name: "ListRunsInput",
|
|
1439
|
-
fields: {
|
|
1440
|
-
organizationId: {
|
|
1441
|
-
type: ScalarTypeEnum5.String_unsecure(),
|
|
1442
|
-
isOptional: true
|
|
1443
|
-
},
|
|
1444
|
-
agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
|
|
1445
|
-
userId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
|
|
1446
|
-
sessionId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
|
|
1447
|
-
status: { type: RunStatusEnum, isOptional: true },
|
|
1448
|
-
startDate: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
|
|
1449
|
-
endDate: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
|
|
1450
|
-
limit: {
|
|
1451
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1452
|
-
isOptional: true,
|
|
1453
|
-
defaultValue: 20
|
|
1454
|
-
},
|
|
1455
|
-
offset: {
|
|
1456
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1457
|
-
isOptional: true,
|
|
1458
|
-
defaultValue: 0
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
}),
|
|
1462
|
-
output: defineSchemaModel5({
|
|
1463
|
-
name: "ListRunsOutput",
|
|
1464
|
-
fields: {
|
|
1465
|
-
items: { type: RunSummaryModel, isArray: true, isOptional: false },
|
|
1466
|
-
total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
|
|
1467
|
-
hasMore: { type: ScalarTypeEnum5.Boolean(), isOptional: false }
|
|
1468
|
-
}
|
|
1469
|
-
})
|
|
1470
|
-
},
|
|
1471
|
-
policy: { auth: "user" },
|
|
1472
|
-
acceptance: {
|
|
1473
|
-
scenarios: [
|
|
1474
|
-
{
|
|
1475
|
-
key: "list-runs-happy-path",
|
|
1476
|
-
given: ["Organization has runs"],
|
|
1477
|
-
when: ["User lists runs"],
|
|
1478
|
-
then: ["Paginated list of runs is returned"]
|
|
1479
|
-
}
|
|
1480
|
-
],
|
|
1481
|
-
examples: [
|
|
1482
|
-
{
|
|
1483
|
-
key: "list-by-agent",
|
|
1484
|
-
input: { agentId: "agent-123", limit: 20, offset: 0 },
|
|
1485
|
-
output: { items: [], total: 0, hasMore: false }
|
|
1486
|
-
}
|
|
1487
|
-
]
|
|
1488
|
-
}
|
|
1489
|
-
});
|
|
1490
|
-
var GetRunStepsQuery = defineQuery2({
|
|
1491
|
-
meta: {
|
|
1492
|
-
key: "agent.run.getSteps",
|
|
1493
|
-
version: "1.0.0",
|
|
1494
|
-
stability: "stable",
|
|
1495
|
-
owners: [...OWNERS3],
|
|
1496
|
-
tags: ["run", "steps"],
|
|
1497
|
-
description: "Retrieves all steps for a specific run.",
|
|
1498
|
-
goal: "View step-by-step execution details.",
|
|
1499
|
-
context: "Run details page - steps tab."
|
|
1500
|
-
},
|
|
1501
|
-
io: {
|
|
1502
|
-
input: defineSchemaModel5({
|
|
1503
|
-
name: "GetRunStepsInput",
|
|
1504
|
-
fields: {
|
|
1505
|
-
runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false }
|
|
1506
|
-
}
|
|
1507
|
-
}),
|
|
1508
|
-
output: defineSchemaModel5({
|
|
1509
|
-
name: "GetRunStepsOutput",
|
|
1510
|
-
fields: {
|
|
1511
|
-
steps: { type: RunStepModel, isArray: true, isOptional: false }
|
|
1512
|
-
}
|
|
1513
|
-
})
|
|
1514
|
-
},
|
|
1515
|
-
policy: { auth: "user" },
|
|
1516
|
-
acceptance: {
|
|
1517
|
-
scenarios: [
|
|
1518
|
-
{
|
|
1519
|
-
key: "get-run-steps-happy-path",
|
|
1520
|
-
given: ["Run exists with steps"],
|
|
1521
|
-
when: ["User requests steps"],
|
|
1522
|
-
then: ["Steps list is returned"]
|
|
1523
|
-
}
|
|
1524
|
-
],
|
|
1525
|
-
examples: [
|
|
1526
|
-
{
|
|
1527
|
-
key: "get-steps-basic",
|
|
1528
|
-
input: { runId: "run-456" },
|
|
1529
|
-
output: { steps: [] }
|
|
1530
|
-
}
|
|
1531
|
-
]
|
|
1532
|
-
}
|
|
1533
|
-
});
|
|
1534
|
-
var GetRunLogsQuery = defineQuery2({
|
|
1535
|
-
meta: {
|
|
1536
|
-
key: "agent.run.getLogs",
|
|
1537
|
-
version: "1.0.0",
|
|
1538
|
-
stability: "stable",
|
|
1539
|
-
owners: [...OWNERS3],
|
|
1540
|
-
tags: ["run", "logs"],
|
|
1541
|
-
description: "Retrieves all logs for a specific run.",
|
|
1542
|
-
goal: "Debug and audit run execution.",
|
|
1543
|
-
context: "Run details page - logs tab."
|
|
1544
|
-
},
|
|
1545
|
-
io: {
|
|
1546
|
-
input: defineSchemaModel5({
|
|
1547
|
-
name: "GetRunLogsInput",
|
|
1548
|
-
fields: {
|
|
1549
|
-
runId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
|
|
1550
|
-
level: { type: LogLevelEnum, isOptional: true },
|
|
1551
|
-
stepId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
|
|
1552
|
-
limit: {
|
|
1553
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1554
|
-
isOptional: true,
|
|
1555
|
-
defaultValue: 100
|
|
1556
|
-
},
|
|
1557
|
-
offset: {
|
|
1558
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1559
|
-
isOptional: true,
|
|
1560
|
-
defaultValue: 0
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
}),
|
|
1564
|
-
output: defineSchemaModel5({
|
|
1565
|
-
name: "GetRunLogsOutput",
|
|
1566
|
-
fields: {
|
|
1567
|
-
items: { type: RunLogModel, isArray: true, isOptional: false },
|
|
1568
|
-
total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
|
|
1569
|
-
hasMore: { type: ScalarTypeEnum5.Boolean(), isOptional: false }
|
|
1570
|
-
}
|
|
1571
|
-
})
|
|
1572
|
-
},
|
|
1573
|
-
policy: { auth: "user" },
|
|
1574
|
-
acceptance: {
|
|
1575
|
-
scenarios: [
|
|
1576
|
-
{
|
|
1577
|
-
key: "get-run-logs-happy-path",
|
|
1578
|
-
given: ["Run exists with logs"],
|
|
1579
|
-
when: ["User requests logs"],
|
|
1580
|
-
then: ["Paginated logs list is returned"]
|
|
1581
|
-
}
|
|
1582
|
-
],
|
|
1583
|
-
examples: [
|
|
1584
|
-
{
|
|
1585
|
-
key: "get-logs-filtered",
|
|
1586
|
-
input: { runId: "run-456", level: "error", limit: 50 },
|
|
1587
|
-
output: { items: [], total: 0, hasMore: false }
|
|
1588
|
-
}
|
|
1589
|
-
]
|
|
1590
|
-
}
|
|
1591
|
-
});
|
|
1592
|
-
var GetRunMetricsQuery = defineQuery2({
|
|
1593
|
-
meta: {
|
|
1594
|
-
key: "agent.run.getMetrics",
|
|
1595
|
-
version: "1.0.0",
|
|
1596
|
-
stability: "stable",
|
|
1597
|
-
owners: [...OWNERS3],
|
|
1598
|
-
tags: ["run", "metrics"],
|
|
1599
|
-
description: "Retrieves aggregated metrics for runs within a time period.",
|
|
1600
|
-
goal: "Monitor and analyze agent usage.",
|
|
1601
|
-
context: "Analytics dashboard."
|
|
1602
|
-
},
|
|
1603
|
-
io: {
|
|
1604
|
-
input: defineSchemaModel5({
|
|
1605
|
-
name: "GetRunMetricsInput",
|
|
1606
|
-
fields: {
|
|
1607
|
-
organizationId: {
|
|
1608
|
-
type: ScalarTypeEnum5.String_unsecure(),
|
|
1609
|
-
isOptional: false
|
|
1610
|
-
},
|
|
1611
|
-
agentId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
|
|
1612
|
-
startDate: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
|
|
1613
|
-
endDate: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
|
|
1614
|
-
granularity: {
|
|
1615
|
-
type: GranularityEnum,
|
|
1616
|
-
isOptional: true,
|
|
1617
|
-
defaultValue: "day"
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
}),
|
|
1621
|
-
output: defineSchemaModel5({
|
|
1622
|
-
name: "GetRunMetricsOutput",
|
|
1623
|
-
fields: {
|
|
1624
|
-
totalRuns: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
|
|
1625
|
-
completedRuns: {
|
|
1626
|
-
type: ScalarTypeEnum5.Int_unsecure(),
|
|
1627
|
-
isOptional: false
|
|
1628
|
-
},
|
|
1629
|
-
failedRuns: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
|
|
1630
|
-
totalTokens: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
|
|
1631
|
-
totalCostUsd: {
|
|
1632
|
-
type: ScalarTypeEnum5.Float_unsecure(),
|
|
1633
|
-
isOptional: false
|
|
1634
|
-
},
|
|
1635
|
-
averageDurationMs: {
|
|
1636
|
-
type: ScalarTypeEnum5.Float_unsecure(),
|
|
1637
|
-
isOptional: false
|
|
1638
|
-
},
|
|
1639
|
-
successRate: {
|
|
1640
|
-
type: ScalarTypeEnum5.Float_unsecure(),
|
|
1641
|
-
isOptional: false
|
|
1642
|
-
},
|
|
1643
|
-
timeline: {
|
|
1644
|
-
type: TimelineDataPointModel,
|
|
1645
|
-
isArray: true,
|
|
1646
|
-
isOptional: false
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
})
|
|
1650
|
-
},
|
|
1651
|
-
policy: { auth: "user" },
|
|
1652
|
-
acceptance: {
|
|
1653
|
-
scenarios: [
|
|
1654
|
-
{
|
|
1655
|
-
key: "get-run-metrics-happy-path",
|
|
1656
|
-
given: ["Organization has run history"],
|
|
1657
|
-
when: ["User requests metrics for date range"],
|
|
1658
|
-
then: ["Aggregated metrics are returned"]
|
|
1659
|
-
}
|
|
1660
|
-
],
|
|
1661
|
-
examples: [
|
|
1662
|
-
{
|
|
1663
|
-
key: "get-daily-metrics",
|
|
1664
|
-
input: {
|
|
1665
|
-
organizationId: "org-123",
|
|
1666
|
-
startDate: "2025-01-01",
|
|
1667
|
-
endDate: "2025-01-31",
|
|
1668
|
-
granularity: "day"
|
|
1669
|
-
},
|
|
1670
|
-
output: {
|
|
1671
|
-
totalRuns: 100,
|
|
1672
|
-
completedRuns: 90,
|
|
1673
|
-
failedRuns: 10,
|
|
1674
|
-
totalTokens: 50000,
|
|
1675
|
-
totalCostUsd: 5,
|
|
1676
|
-
averageDurationMs: 2500,
|
|
1677
|
-
successRate: 0.9,
|
|
1678
|
-
timeline: []
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
]
|
|
1682
|
-
}
|
|
1683
|
-
});
|
|
1684
|
-
|
|
1685
|
-
// src/tool/tool.enum.ts
|
|
1686
|
-
import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
|
|
1687
|
-
var ToolCategoryEnum = defineEnum3("ToolCategory", [
|
|
1688
|
-
"RETRIEVAL",
|
|
1689
|
-
"COMPUTATION",
|
|
1690
|
-
"COMMUNICATION",
|
|
1691
|
-
"INTEGRATION",
|
|
1692
|
-
"UTILITY",
|
|
1693
|
-
"CUSTOM"
|
|
1694
|
-
]);
|
|
1695
|
-
var ToolStatusEnum = defineEnum3("ToolStatus", [
|
|
1696
|
-
"DRAFT",
|
|
1697
|
-
"ACTIVE",
|
|
1698
|
-
"DEPRECATED",
|
|
1699
|
-
"DISABLED"
|
|
1700
|
-
]);
|
|
1701
|
-
var ImplementationTypeEnum = defineEnum3("ImplementationType", [
|
|
1702
|
-
"http",
|
|
1703
|
-
"function",
|
|
1704
|
-
"workflow"
|
|
1705
|
-
]);
|
|
1706
|
-
|
|
1707
|
-
// src/tool/tool.schema.ts
|
|
1708
|
-
import { defineSchemaModel as defineSchemaModel6, ScalarTypeEnum as ScalarTypeEnum6 } from "@contractspec/lib.schema";
|
|
1709
|
-
var ToolModel = defineSchemaModel6({
|
|
1710
|
-
name: "Tool",
|
|
1711
|
-
description: "AI tool definition",
|
|
1712
|
-
fields: {
|
|
1713
|
-
id: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1714
|
-
organizationId: {
|
|
1715
|
-
type: ScalarTypeEnum6.String_unsecure(),
|
|
1716
|
-
isOptional: false
|
|
1717
|
-
},
|
|
1718
|
-
name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
|
|
1719
|
-
slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1720
|
-
description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1721
|
-
category: { type: ToolCategoryEnum, isOptional: false },
|
|
1722
|
-
status: { type: ToolStatusEnum, isOptional: false },
|
|
1723
|
-
parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: false },
|
|
1724
|
-
outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
|
|
1725
|
-
implementationType: { type: ImplementationTypeEnum, isOptional: false },
|
|
1726
|
-
implementationConfig: {
|
|
1727
|
-
type: ScalarTypeEnum6.JSONObject(),
|
|
1728
|
-
isOptional: false
|
|
1729
|
-
},
|
|
1730
|
-
maxInvocationsPerMinute: {
|
|
1731
|
-
type: ScalarTypeEnum6.Int_unsecure(),
|
|
1732
|
-
isOptional: true
|
|
1733
|
-
},
|
|
1734
|
-
timeoutMs: {
|
|
1735
|
-
type: ScalarTypeEnum6.Int_unsecure(),
|
|
1736
|
-
isOptional: false,
|
|
1737
|
-
defaultValue: 30000
|
|
1738
|
-
},
|
|
1739
|
-
version: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
|
|
1740
|
-
tags: {
|
|
1741
|
-
type: ScalarTypeEnum6.String_unsecure(),
|
|
1742
|
-
isArray: true,
|
|
1743
|
-
isOptional: true
|
|
1744
|
-
},
|
|
1745
|
-
createdAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false },
|
|
1746
|
-
updatedAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
|
|
1747
|
-
}
|
|
1748
|
-
});
|
|
1749
|
-
var ToolSummaryModel = defineSchemaModel6({
|
|
1750
|
-
name: "ToolSummary",
|
|
1751
|
-
description: "Summary of a tool for list views",
|
|
1752
|
-
fields: {
|
|
1753
|
-
id: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1754
|
-
name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
|
|
1755
|
-
slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1756
|
-
description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1757
|
-
category: { type: ToolCategoryEnum, isOptional: false },
|
|
1758
|
-
status: { type: ToolStatusEnum, isOptional: false },
|
|
1759
|
-
version: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
|
|
1760
|
-
createdAt: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
|
|
1761
|
-
}
|
|
1762
|
-
});
|
|
1763
|
-
var CreateToolInputModel = defineSchemaModel6({
|
|
1764
|
-
name: "CreateToolInput",
|
|
1765
|
-
description: "Input for creating a tool",
|
|
1766
|
-
fields: {
|
|
1767
|
-
organizationId: {
|
|
1768
|
-
type: ScalarTypeEnum6.String_unsecure(),
|
|
1769
|
-
isOptional: false
|
|
1770
|
-
},
|
|
1771
|
-
name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: false },
|
|
1772
|
-
slug: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1773
|
-
description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1774
|
-
category: { type: ToolCategoryEnum, isOptional: true },
|
|
1775
|
-
parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: false },
|
|
1776
|
-
outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
|
|
1777
|
-
implementationType: { type: ImplementationTypeEnum, isOptional: false },
|
|
1778
|
-
implementationConfig: {
|
|
1779
|
-
type: ScalarTypeEnum6.JSONObject(),
|
|
1780
|
-
isOptional: false
|
|
1781
|
-
},
|
|
1782
|
-
maxInvocationsPerMinute: {
|
|
1783
|
-
type: ScalarTypeEnum6.Int_unsecure(),
|
|
1784
|
-
isOptional: true
|
|
1785
|
-
},
|
|
1786
|
-
timeoutMs: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: true },
|
|
1787
|
-
tags: {
|
|
1788
|
-
type: ScalarTypeEnum6.String_unsecure(),
|
|
1789
|
-
isArray: true,
|
|
1790
|
-
isOptional: true
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
});
|
|
1794
|
-
var UpdateToolInputModel = defineSchemaModel6({
|
|
1795
|
-
name: "UpdateToolInput",
|
|
1796
|
-
description: "Input for updating a tool",
|
|
1797
|
-
fields: {
|
|
1798
|
-
toolId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
|
|
1799
|
-
name: { type: ScalarTypeEnum6.NonEmptyString(), isOptional: true },
|
|
1800
|
-
description: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true },
|
|
1801
|
-
status: { type: ToolStatusEnum, isOptional: true },
|
|
1802
|
-
parametersSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
|
|
1803
|
-
outputSchema: { type: ScalarTypeEnum6.JSONObject(), isOptional: true },
|
|
1804
|
-
implementationConfig: {
|
|
1805
|
-
type: ScalarTypeEnum6.JSONObject(),
|
|
1806
|
-
isOptional: true
|
|
1807
|
-
},
|
|
1808
|
-
maxInvocationsPerMinute: {
|
|
1809
|
-
type: ScalarTypeEnum6.Int_unsecure(),
|
|
1810
|
-
isOptional: true
|
|
1811
|
-
},
|
|
1812
|
-
timeoutMs: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: true },
|
|
1813
|
-
tags: {
|
|
1814
|
-
type: ScalarTypeEnum6.String_unsecure(),
|
|
1815
|
-
isArray: true,
|
|
1816
|
-
isOptional: true
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
});
|
|
1820
|
-
|
|
1821
|
-
// src/tool/tool.operation.ts
|
|
1822
|
-
import {
|
|
1823
|
-
defineCommand as defineCommand3,
|
|
1824
|
-
defineQuery as defineQuery3
|
|
1825
|
-
} from "@contractspec/lib.contracts-spec/operations";
|
|
1826
|
-
import { defineSchemaModel as defineSchemaModel7, ScalarTypeEnum as ScalarTypeEnum7 } from "@contractspec/lib.schema";
|
|
1827
|
-
var OWNERS4 = ["@agent-console-team"];
|
|
1828
|
-
var CreateToolCommand = defineCommand3({
|
|
1829
|
-
meta: {
|
|
1830
|
-
key: "agent.tool.create",
|
|
1831
|
-
version: "1.0.0",
|
|
1832
|
-
stability: "stable",
|
|
1833
|
-
owners: [...OWNERS4],
|
|
1834
|
-
tags: ["tool", "create"],
|
|
1835
|
-
description: "Creates a new AI tool definition.",
|
|
1836
|
-
goal: "Allow users to define new tools that agents can use.",
|
|
1837
|
-
context: "Called from the tool builder UI when creating a new tool."
|
|
1838
|
-
},
|
|
1839
|
-
io: {
|
|
1840
|
-
input: CreateToolInputModel,
|
|
1841
|
-
output: defineSchemaModel7({
|
|
1842
|
-
name: "CreateToolOutput",
|
|
1843
|
-
fields: {
|
|
1844
|
-
id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
|
|
1845
|
-
name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
|
|
1846
|
-
slug: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
|
|
1847
|
-
status: { type: ToolStatusEnum, isOptional: false }
|
|
1848
|
-
}
|
|
1849
|
-
}),
|
|
1850
|
-
errors: {
|
|
1851
|
-
SLUG_EXISTS: {
|
|
1852
|
-
description: "A tool with this slug already exists in the organization",
|
|
1853
|
-
http: 409,
|
|
1854
|
-
gqlCode: "SLUG_EXISTS",
|
|
1855
|
-
when: "Slug is already taken"
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
},
|
|
1859
|
-
policy: { auth: "user" },
|
|
1860
|
-
sideEffects: {
|
|
1861
|
-
emits: [
|
|
1862
|
-
{
|
|
1863
|
-
key: "tool.created",
|
|
1864
|
-
version: "1.0.0",
|
|
1865
|
-
stability: "stable",
|
|
1866
|
-
owners: [...OWNERS4],
|
|
1867
|
-
tags: ["tool", "created"],
|
|
1868
|
-
when: "Tool is successfully created",
|
|
1869
|
-
payload: ToolSummaryModel
|
|
1870
|
-
}
|
|
1871
|
-
],
|
|
1872
|
-
audit: ["tool.created"]
|
|
1873
|
-
},
|
|
1874
|
-
acceptance: {
|
|
1875
|
-
scenarios: [
|
|
1876
|
-
{
|
|
1877
|
-
key: "create-tool-happy-path",
|
|
1878
|
-
given: ["User is authenticated", "Organization exists"],
|
|
1879
|
-
when: ["User submits valid tool configuration"],
|
|
1880
|
-
then: ["New tool is created", "ToolCreated event is emitted"]
|
|
1881
|
-
},
|
|
1882
|
-
{
|
|
1883
|
-
key: "create-tool-slug-conflict",
|
|
1884
|
-
given: ["Tool with same slug exists"],
|
|
1885
|
-
when: ["User submits tool with duplicate slug"],
|
|
1886
|
-
then: ["SLUG_EXISTS error is returned"]
|
|
1887
|
-
}
|
|
1888
|
-
],
|
|
1889
|
-
examples: [
|
|
1890
|
-
{
|
|
1891
|
-
key: "create-api-tool",
|
|
1892
|
-
input: {
|
|
1893
|
-
name: "Weather API",
|
|
1894
|
-
slug: "weather-api",
|
|
1895
|
-
category: "api",
|
|
1896
|
-
description: "Fetches weather data"
|
|
1897
|
-
},
|
|
1898
|
-
output: {
|
|
1899
|
-
id: "tool-123",
|
|
1900
|
-
name: "Weather API",
|
|
1901
|
-
slug: "weather-api",
|
|
1902
|
-
status: "draft"
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
]
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
|
-
var UpdateToolCommand = defineCommand3({
|
|
1909
|
-
meta: {
|
|
1910
|
-
key: "agent.tool.update",
|
|
1911
|
-
version: "1.0.0",
|
|
1912
|
-
stability: "stable",
|
|
1913
|
-
owners: [...OWNERS4],
|
|
1914
|
-
tags: ["tool", "update"],
|
|
1915
|
-
description: "Updates an existing AI tool definition.",
|
|
1916
|
-
goal: "Allow users to modify tool settings and configuration.",
|
|
1917
|
-
context: "Called from the tool settings UI."
|
|
1918
|
-
},
|
|
1919
|
-
io: {
|
|
1920
|
-
input: UpdateToolInputModel,
|
|
1921
|
-
output: defineSchemaModel7({
|
|
1922
|
-
name: "UpdateToolOutput",
|
|
1923
|
-
fields: {
|
|
1924
|
-
id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
|
|
1925
|
-
name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
|
|
1926
|
-
status: { type: ToolStatusEnum, isOptional: false },
|
|
1927
|
-
updatedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false }
|
|
1928
|
-
}
|
|
1929
|
-
}),
|
|
1930
|
-
errors: {
|
|
1931
|
-
TOOL_NOT_FOUND: {
|
|
1932
|
-
description: "The specified tool does not exist",
|
|
1933
|
-
http: 404,
|
|
1934
|
-
gqlCode: "TOOL_NOT_FOUND",
|
|
1935
|
-
when: "Tool ID is invalid"
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
},
|
|
1939
|
-
policy: { auth: "user" },
|
|
1940
|
-
sideEffects: {
|
|
1941
|
-
emits: [
|
|
1942
|
-
{
|
|
1943
|
-
key: "tool.updated",
|
|
1944
|
-
version: "1.0.0",
|
|
1945
|
-
stability: "stable",
|
|
1946
|
-
owners: [...OWNERS4],
|
|
1947
|
-
tags: ["tool", "updated"],
|
|
1948
|
-
when: "Tool is updated",
|
|
1949
|
-
payload: ToolSummaryModel
|
|
1950
|
-
}
|
|
1951
|
-
],
|
|
1952
|
-
audit: ["tool.updated"]
|
|
1953
|
-
},
|
|
1954
|
-
acceptance: {
|
|
1955
|
-
scenarios: [
|
|
1956
|
-
{
|
|
1957
|
-
key: "update-tool-happy-path",
|
|
1958
|
-
given: ["Tool exists", "User owns the tool"],
|
|
1959
|
-
when: ["User submits updated configuration"],
|
|
1960
|
-
then: ["Tool is updated", "ToolUpdated event is emitted"]
|
|
1961
|
-
}
|
|
1962
|
-
],
|
|
1963
|
-
examples: [
|
|
1964
|
-
{
|
|
1965
|
-
key: "update-description",
|
|
1966
|
-
input: { toolId: "tool-123", description: "Updated weather API tool" },
|
|
1967
|
-
output: {
|
|
1968
|
-
id: "tool-123",
|
|
1969
|
-
name: "Weather API",
|
|
1970
|
-
status: "draft",
|
|
1971
|
-
updatedAt: "2025-01-01T00:00:00Z"
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
]
|
|
1975
|
-
}
|
|
1976
|
-
});
|
|
1977
|
-
var GetToolQuery = defineQuery3({
|
|
1978
|
-
meta: {
|
|
1979
|
-
key: "agent.tool.get",
|
|
1980
|
-
version: "1.0.0",
|
|
1981
|
-
stability: "stable",
|
|
1982
|
-
owners: [...OWNERS4],
|
|
1983
|
-
tags: ["tool", "get"],
|
|
1984
|
-
description: "Retrieves a tool by its ID.",
|
|
1985
|
-
goal: "View detailed tool configuration.",
|
|
1986
|
-
context: "Called when viewing tool details or editing."
|
|
1987
|
-
},
|
|
1988
|
-
io: {
|
|
1989
|
-
input: defineSchemaModel7({
|
|
1990
|
-
name: "GetToolInput",
|
|
1991
|
-
fields: {
|
|
1992
|
-
toolId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false }
|
|
1993
|
-
}
|
|
1994
|
-
}),
|
|
1995
|
-
output: ToolModel,
|
|
1996
|
-
errors: {
|
|
1997
|
-
TOOL_NOT_FOUND: {
|
|
1998
|
-
description: "The specified tool does not exist",
|
|
1999
|
-
http: 404,
|
|
2000
|
-
gqlCode: "TOOL_NOT_FOUND",
|
|
2001
|
-
when: "Tool ID is invalid"
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
},
|
|
2005
|
-
policy: { auth: "user" },
|
|
2006
|
-
acceptance: {
|
|
2007
|
-
scenarios: [
|
|
2008
|
-
{
|
|
2009
|
-
key: "get-tool-happy-path",
|
|
2010
|
-
given: ["Tool exists"],
|
|
2011
|
-
when: ["User requests tool by ID"],
|
|
2012
|
-
then: ["Tool details are returned"]
|
|
2013
|
-
}
|
|
2014
|
-
],
|
|
2015
|
-
examples: [
|
|
2016
|
-
{
|
|
2017
|
-
key: "get-basic",
|
|
2018
|
-
input: { toolId: "tool-123" },
|
|
2019
|
-
output: {
|
|
2020
|
-
id: "tool-123",
|
|
2021
|
-
name: "Weather API",
|
|
2022
|
-
status: "active",
|
|
2023
|
-
category: "api"
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
]
|
|
2027
|
-
}
|
|
2028
|
-
});
|
|
2029
|
-
var ListToolsQuery = defineQuery3({
|
|
2030
|
-
meta: {
|
|
2031
|
-
key: "agent.tool.list",
|
|
2032
|
-
version: "1.0.0",
|
|
2033
|
-
stability: "stable",
|
|
2034
|
-
owners: [...OWNERS4],
|
|
2035
|
-
tags: ["tool", "list"],
|
|
2036
|
-
description: "Lists tools for an organization with optional filtering.",
|
|
2037
|
-
goal: "Browse and search available tools.",
|
|
2038
|
-
context: "Tool list/dashboard view."
|
|
2039
|
-
},
|
|
2040
|
-
io: {
|
|
2041
|
-
input: defineSchemaModel7({
|
|
2042
|
-
name: "ListToolsInput",
|
|
2043
|
-
fields: {
|
|
2044
|
-
organizationId: {
|
|
2045
|
-
type: ScalarTypeEnum7.String_unsecure(),
|
|
2046
|
-
isOptional: false
|
|
2047
|
-
},
|
|
2048
|
-
category: { type: ToolCategoryEnum, isOptional: true },
|
|
2049
|
-
status: { type: ToolStatusEnum, isOptional: true },
|
|
2050
|
-
search: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
|
|
2051
|
-
limit: {
|
|
2052
|
-
type: ScalarTypeEnum7.Int_unsecure(),
|
|
2053
|
-
isOptional: true,
|
|
2054
|
-
defaultValue: 20
|
|
2055
|
-
},
|
|
2056
|
-
offset: {
|
|
2057
|
-
type: ScalarTypeEnum7.Int_unsecure(),
|
|
2058
|
-
isOptional: true,
|
|
2059
|
-
defaultValue: 0
|
|
2060
|
-
}
|
|
2061
|
-
}
|
|
2062
|
-
}),
|
|
2063
|
-
output: defineSchemaModel7({
|
|
2064
|
-
name: "ListToolsOutput",
|
|
2065
|
-
fields: {
|
|
2066
|
-
items: { type: ToolSummaryModel, isArray: true, isOptional: false },
|
|
2067
|
-
total: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
|
|
2068
|
-
hasMore: { type: ScalarTypeEnum7.Boolean(), isOptional: false }
|
|
2069
|
-
}
|
|
2070
|
-
})
|
|
2071
|
-
},
|
|
2072
|
-
policy: { auth: "user" },
|
|
2073
|
-
acceptance: {
|
|
2074
|
-
scenarios: [
|
|
2075
|
-
{
|
|
2076
|
-
key: "list-tools-happy-path",
|
|
2077
|
-
given: ["Organization has tools"],
|
|
2078
|
-
when: ["User lists tools"],
|
|
2079
|
-
then: ["Paginated list of tools is returned"]
|
|
2080
|
-
}
|
|
2081
|
-
],
|
|
2082
|
-
examples: [
|
|
2083
|
-
{
|
|
2084
|
-
key: "list-by-category",
|
|
2085
|
-
input: { organizationId: "org-123", category: "api", limit: 10 },
|
|
2086
|
-
output: { items: [], total: 0, hasMore: false }
|
|
2087
|
-
}
|
|
2088
|
-
]
|
|
2089
|
-
}
|
|
2090
|
-
});
|
|
2091
|
-
var TestToolCommand = defineCommand3({
|
|
2092
|
-
meta: {
|
|
2093
|
-
key: "agent.tool.test",
|
|
2094
|
-
version: "1.0.0",
|
|
2095
|
-
stability: "stable",
|
|
2096
|
-
owners: [...OWNERS4],
|
|
2097
|
-
tags: ["tool", "test"],
|
|
2098
|
-
description: "Tests a tool with sample input to verify it works correctly.",
|
|
2099
|
-
goal: "Validate tool configuration before deployment.",
|
|
2100
|
-
context: "Tool builder UI - test panel."
|
|
2101
|
-
},
|
|
2102
|
-
io: {
|
|
2103
|
-
input: defineSchemaModel7({
|
|
2104
|
-
name: "TestToolInput",
|
|
2105
|
-
fields: {
|
|
2106
|
-
toolId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
|
|
2107
|
-
testInput: { type: ScalarTypeEnum7.JSONObject(), isOptional: false }
|
|
2108
|
-
}
|
|
2109
|
-
}),
|
|
2110
|
-
output: defineSchemaModel7({
|
|
2111
|
-
name: "TestToolOutput",
|
|
2112
|
-
fields: {
|
|
2113
|
-
success: { type: ScalarTypeEnum7.Boolean(), isOptional: false },
|
|
2114
|
-
output: { type: ScalarTypeEnum7.JSONObject(), isOptional: true },
|
|
2115
|
-
error: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
|
|
2116
|
-
durationMs: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false }
|
|
2117
|
-
}
|
|
2118
|
-
}),
|
|
2119
|
-
errors: {
|
|
2120
|
-
TOOL_NOT_FOUND: {
|
|
2121
|
-
description: "The specified tool does not exist",
|
|
2122
|
-
http: 404,
|
|
2123
|
-
gqlCode: "TOOL_NOT_FOUND",
|
|
2124
|
-
when: "Tool ID is invalid"
|
|
2125
|
-
},
|
|
2126
|
-
TOOL_EXECUTION_ERROR: {
|
|
2127
|
-
description: "Tool execution failed",
|
|
2128
|
-
http: 500,
|
|
2129
|
-
gqlCode: "TOOL_EXECUTION_ERROR",
|
|
2130
|
-
when: "Tool returns an error"
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
},
|
|
2134
|
-
policy: { auth: "user" },
|
|
2135
|
-
sideEffects: { audit: ["tool.tested"] },
|
|
2136
|
-
acceptance: {
|
|
2137
|
-
scenarios: [
|
|
2138
|
-
{
|
|
2139
|
-
key: "test-tool-success",
|
|
2140
|
-
given: ["Tool exists", "Tool is configured correctly"],
|
|
2141
|
-
when: ["User runs test with valid input"],
|
|
2142
|
-
then: ["Tool executes successfully", "Output is returned"]
|
|
2143
|
-
},
|
|
2144
|
-
{
|
|
2145
|
-
key: "test-tool-failure",
|
|
2146
|
-
given: ["Tool exists", "Tool has configuration error"],
|
|
2147
|
-
when: ["User runs test"],
|
|
2148
|
-
then: ["TOOL_EXECUTION_ERROR is returned"]
|
|
2149
|
-
}
|
|
2150
|
-
],
|
|
2151
|
-
examples: [
|
|
2152
|
-
{
|
|
2153
|
-
key: "test-weather-api",
|
|
2154
|
-
input: { toolId: "tool-123", testInput: { city: "Paris" } },
|
|
2155
|
-
output: { success: true, output: { temperature: 22 }, durationMs: 150 }
|
|
2156
|
-
}
|
|
2157
|
-
]
|
|
2158
|
-
}
|
|
2159
|
-
});
|
|
2160
|
-
|
|
2161
|
-
// src/handlers/agent.handlers.ts
|
|
2162
|
-
import { web } from "@contractspec/lib.runtime-sandbox";
|
|
2163
|
-
var { generateId } = web;
|
|
2164
|
-
var RUN_SORT_COLUMNS = {
|
|
2165
|
-
queuedAt: "r.queuedAt",
|
|
2166
|
-
totalTokens: "r.totalTokens",
|
|
2167
|
-
durationMs: "r.durationMs",
|
|
2168
|
-
estimatedCostUsd: "r.estimatedCostUsd",
|
|
2169
|
-
status: "r.status",
|
|
2170
|
-
agentName: "a.name"
|
|
2171
|
-
};
|
|
2172
|
-
function rowToAgent(row) {
|
|
2173
|
-
return {
|
|
2174
|
-
id: row.id,
|
|
2175
|
-
projectId: row.projectId,
|
|
2176
|
-
organizationId: row.organizationId,
|
|
2177
|
-
name: row.name,
|
|
2178
|
-
description: row.description ?? undefined,
|
|
2179
|
-
modelProvider: row.modelProvider,
|
|
2180
|
-
modelName: row.modelName,
|
|
2181
|
-
systemPrompt: row.systemPrompt ?? undefined,
|
|
2182
|
-
temperature: row.temperature,
|
|
2183
|
-
maxTokens: row.maxTokens,
|
|
2184
|
-
status: row.status,
|
|
2185
|
-
createdAt: new Date(row.createdAt),
|
|
2186
|
-
updatedAt: new Date(row.updatedAt)
|
|
2187
|
-
};
|
|
2188
|
-
}
|
|
2189
|
-
function rowToTool(row) {
|
|
2190
|
-
return {
|
|
2191
|
-
id: row.id,
|
|
2192
|
-
projectId: row.projectId,
|
|
2193
|
-
organizationId: row.organizationId,
|
|
2194
|
-
name: row.name,
|
|
2195
|
-
description: row.description ?? undefined,
|
|
2196
|
-
version: row.version,
|
|
2197
|
-
category: row.category,
|
|
2198
|
-
status: row.status,
|
|
2199
|
-
inputSchema: row.inputSchema ?? undefined,
|
|
2200
|
-
outputSchema: row.outputSchema ?? undefined,
|
|
2201
|
-
endpoint: row.endpoint ?? undefined,
|
|
2202
|
-
createdAt: new Date(row.createdAt),
|
|
2203
|
-
updatedAt: new Date(row.updatedAt)
|
|
2204
|
-
};
|
|
2205
|
-
}
|
|
2206
|
-
function rowToRun(row, agentName) {
|
|
2207
|
-
return {
|
|
2208
|
-
id: row.id,
|
|
2209
|
-
projectId: row.projectId,
|
|
2210
|
-
agentId: row.agentId,
|
|
2211
|
-
agentName,
|
|
2212
|
-
status: row.status,
|
|
2213
|
-
input: row.input ?? undefined,
|
|
2214
|
-
output: row.output ?? undefined,
|
|
2215
|
-
totalTokens: row.totalTokens,
|
|
2216
|
-
promptTokens: row.promptTokens,
|
|
2217
|
-
completionTokens: row.completionTokens,
|
|
2218
|
-
estimatedCostUsd: row.estimatedCostUsd,
|
|
2219
|
-
durationMs: row.durationMs ?? undefined,
|
|
2220
|
-
errorMessage: row.errorMessage ?? undefined,
|
|
2221
|
-
queuedAt: new Date(row.queuedAt),
|
|
2222
|
-
startedAt: row.startedAt ? new Date(row.startedAt) : undefined,
|
|
2223
|
-
completedAt: row.completedAt ? new Date(row.completedAt) : undefined
|
|
2224
|
-
};
|
|
2225
|
-
}
|
|
2226
|
-
function createAgentHandlers(db) {
|
|
2227
|
-
async function listAgents(input) {
|
|
2228
|
-
const {
|
|
2229
|
-
projectId,
|
|
2230
|
-
organizationId,
|
|
2231
|
-
status,
|
|
2232
|
-
search,
|
|
2233
|
-
limit = 20,
|
|
2234
|
-
offset = 0
|
|
2235
|
-
} = input;
|
|
2236
|
-
let whereClause = "WHERE projectId = ?";
|
|
2237
|
-
const params = [projectId];
|
|
2238
|
-
if (organizationId) {
|
|
2239
|
-
whereClause += " AND organizationId = ?";
|
|
2240
|
-
params.push(organizationId);
|
|
2241
|
-
}
|
|
2242
|
-
if (status && status !== "all") {
|
|
2243
|
-
whereClause += " AND status = ?";
|
|
2244
|
-
params.push(status);
|
|
2245
|
-
}
|
|
2246
|
-
if (search) {
|
|
2247
|
-
whereClause += " AND (name LIKE ? OR description LIKE ?)";
|
|
2248
|
-
params.push(`%${search}%`, `%${search}%`);
|
|
2249
|
-
}
|
|
2250
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM agent_definition ${whereClause}`, params)).rows;
|
|
2251
|
-
const total = countResult[0]?.count ?? 0;
|
|
2252
|
-
const rows = (await db.query(`SELECT * FROM agent_definition ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
2253
|
-
return {
|
|
2254
|
-
items: rows.map(rowToAgent),
|
|
2255
|
-
total,
|
|
2256
|
-
hasMore: offset + rows.length < total
|
|
2257
|
-
};
|
|
2258
|
-
}
|
|
2259
|
-
async function getAgent(id) {
|
|
2260
|
-
const rows = (await db.query(`SELECT * FROM agent_definition WHERE id = ?`, [id])).rows;
|
|
2261
|
-
return rows[0] ? rowToAgent(rows[0]) : null;
|
|
2262
|
-
}
|
|
2263
|
-
async function createAgent(input, context) {
|
|
2264
|
-
const id = generateId("agent");
|
|
2265
|
-
const now = new Date().toISOString();
|
|
2266
|
-
await db.execute(`INSERT INTO agent_definition (id, projectId, organizationId, name, description, modelProvider, modelName, systemPrompt, temperature, maxTokens, status, createdAt, updatedAt)
|
|
2267
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
2268
|
-
id,
|
|
2269
|
-
context.projectId,
|
|
2270
|
-
context.organizationId,
|
|
2271
|
-
input.name,
|
|
2272
|
-
input.description ?? null,
|
|
2273
|
-
input.modelProvider ?? "openai",
|
|
2274
|
-
input.modelName ?? "gpt-4",
|
|
2275
|
-
input.systemPrompt ?? null,
|
|
2276
|
-
input.temperature ?? 0.7,
|
|
2277
|
-
input.maxTokens ?? 4096,
|
|
2278
|
-
"DRAFT",
|
|
2279
|
-
now,
|
|
2280
|
-
now
|
|
2281
|
-
]);
|
|
2282
|
-
const rows = (await db.query(`SELECT * FROM agent_definition WHERE id = ?`, [id])).rows;
|
|
2283
|
-
const row = rows[0];
|
|
2284
|
-
if (!row) {
|
|
2285
|
-
throw new Error("Failed to retrieve created agent");
|
|
2286
|
-
}
|
|
2287
|
-
return rowToAgent(row);
|
|
2288
|
-
}
|
|
2289
|
-
async function updateAgent(input) {
|
|
2290
|
-
const now = new Date().toISOString();
|
|
2291
|
-
const updates = ["updatedAt = ?"];
|
|
2292
|
-
const params = [now];
|
|
2293
|
-
if (input.name !== undefined) {
|
|
2294
|
-
updates.push("name = ?");
|
|
2295
|
-
params.push(input.name);
|
|
2296
|
-
}
|
|
2297
|
-
if (input.description !== undefined) {
|
|
2298
|
-
updates.push("description = ?");
|
|
2299
|
-
params.push(input.description);
|
|
2300
|
-
}
|
|
2301
|
-
if (input.status !== undefined) {
|
|
2302
|
-
updates.push("status = ?");
|
|
2303
|
-
params.push(input.status);
|
|
2304
|
-
}
|
|
2305
|
-
params.push(input.id);
|
|
2306
|
-
await db.execute(`UPDATE agent_definition SET ${updates.join(", ")} WHERE id = ?`, params);
|
|
2307
|
-
const rows = (await db.query(`SELECT * FROM agent_definition WHERE id = ?`, [input.id])).rows;
|
|
2308
|
-
if (!rows[0]) {
|
|
2309
|
-
throw new Error("NOT_FOUND");
|
|
2310
|
-
}
|
|
2311
|
-
return rowToAgent(rows[0]);
|
|
2312
|
-
}
|
|
2313
|
-
async function listTools(input) {
|
|
2314
|
-
const {
|
|
2315
|
-
projectId,
|
|
2316
|
-
organizationId,
|
|
2317
|
-
category,
|
|
2318
|
-
status,
|
|
2319
|
-
search,
|
|
2320
|
-
limit = 50,
|
|
2321
|
-
offset = 0
|
|
2322
|
-
} = input;
|
|
2323
|
-
let whereClause = "WHERE projectId = ?";
|
|
2324
|
-
const params = [projectId];
|
|
2325
|
-
if (organizationId) {
|
|
2326
|
-
whereClause += " AND organizationId = ?";
|
|
2327
|
-
params.push(organizationId);
|
|
2328
|
-
}
|
|
2329
|
-
if (category && category !== "all") {
|
|
2330
|
-
whereClause += " AND category = ?";
|
|
2331
|
-
params.push(category);
|
|
2332
|
-
}
|
|
2333
|
-
if (status && status !== "all") {
|
|
2334
|
-
whereClause += " AND status = ?";
|
|
2335
|
-
params.push(status);
|
|
2336
|
-
}
|
|
2337
|
-
if (search) {
|
|
2338
|
-
whereClause += " AND (name LIKE ? OR description LIKE ?)";
|
|
2339
|
-
params.push(`%${search}%`, `%${search}%`);
|
|
2340
|
-
}
|
|
2341
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM agent_tool ${whereClause}`, params)).rows;
|
|
2342
|
-
const total = countResult[0]?.count ?? 0;
|
|
2343
|
-
const rows = (await db.query(`SELECT * FROM agent_tool ${whereClause} ORDER BY name ASC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
2344
|
-
return {
|
|
2345
|
-
items: rows.map(rowToTool),
|
|
2346
|
-
total,
|
|
2347
|
-
hasMore: offset + rows.length < total
|
|
2348
|
-
};
|
|
2349
|
-
}
|
|
2350
|
-
async function listRuns(input) {
|
|
2351
|
-
const {
|
|
2352
|
-
projectId,
|
|
2353
|
-
agentId,
|
|
2354
|
-
status,
|
|
2355
|
-
sortBy,
|
|
2356
|
-
sortDirection = "desc",
|
|
2357
|
-
limit = 20,
|
|
2358
|
-
offset = 0
|
|
2359
|
-
} = input;
|
|
2360
|
-
let whereClause = "WHERE r.projectId = ?";
|
|
2361
|
-
const params = [projectId];
|
|
2362
|
-
if (agentId) {
|
|
2363
|
-
whereClause += " AND r.agentId = ?";
|
|
2364
|
-
params.push(agentId);
|
|
2365
|
-
}
|
|
2366
|
-
if (status && status !== "all") {
|
|
2367
|
-
whereClause += " AND r.status = ?";
|
|
2368
|
-
params.push(status);
|
|
2369
|
-
}
|
|
2370
|
-
const countResult = (await db.query(`SELECT COUNT(*) as count FROM agent_run r ${whereClause}`, params)).rows;
|
|
2371
|
-
const total = countResult[0]?.count ?? 0;
|
|
2372
|
-
const sortColumn = sortBy ? RUN_SORT_COLUMNS[sortBy] : RUN_SORT_COLUMNS.queuedAt;
|
|
2373
|
-
const direction = sortDirection === "asc" ? "ASC" : "DESC";
|
|
2374
|
-
const rows = (await db.query(`SELECT r.*, a.name as agentName
|
|
1
|
+
import{defineEnum as P0}from"@contractspec/lib.schema";var C=P0("AgentStatus",["DRAFT","ACTIVE","PAUSED","ARCHIVED"]),t=P0("ModelProvider",["OPENAI","ANTHROPIC","GOOGLE","MISTRAL","CUSTOM"]),T=P0("ToolChoice",["auto","required","none"]);import{defineEvent as p}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as l,ScalarTypeEnum as B}from"@contractspec/lib.schema";var u=["@agent-console-team"],e0=l({name:"AgentCreatedPayload",description:"Payload for agent created event",fields:{id:{type:B.String_unsecure(),isOptional:!1},organizationId:{type:B.String_unsecure(),isOptional:!1},name:{type:B.String_unsecure(),isOptional:!1},slug:{type:B.String_unsecure(),isOptional:!1},modelProvider:{type:B.String_unsecure(),isOptional:!1},modelName:{type:B.String_unsecure(),isOptional:!1},toolCount:{type:B.Int_unsecure(),isOptional:!1},createdById:{type:B.String_unsecure(),isOptional:!0},createdAt:{type:B.DateTime(),isOptional:!1}}}),G0=p({meta:{key:"agent-console.agent.created",version:"1.0.0",description:"A new AI agent was configured.",stability:"stable",owners:[...u],tags:["agent","created"]},payload:e0}),E0=l({name:"AgentUpdatedPayload",description:"Payload for agent updated event",fields:{id:{type:B.String_unsecure(),isOptional:!1},organizationId:{type:B.String_unsecure(),isOptional:!1},name:{type:B.String_unsecure(),isOptional:!1},status:{type:B.String_unsecure(),isOptional:!1},updatedFields:{type:B.String_unsecure(),isArray:!0,isOptional:!1},updatedAt:{type:B.DateTime(),isOptional:!1}}}),bs=p({meta:{key:"agent-console.agent.updated",version:"1.0.0",description:"An AI agent configuration was updated.",stability:"stable",owners:[...u],tags:["agent","updated"]},payload:E0}),S0=l({name:"AgentToolAssignedPayload",description:"Payload for agent tool assigned event",fields:{agentId:{type:B.String_unsecure(),isOptional:!1},toolId:{type:B.String_unsecure(),isOptional:!1},agentName:{type:B.String_unsecure(),isOptional:!1},toolName:{type:B.String_unsecure(),isOptional:!1},assignedAt:{type:B.DateTime(),isOptional:!1}}}),Ns=p({meta:{key:"agent-console.agent.toolAssigned",version:"1.0.0",description:"A tool was assigned to an agent.",stability:"stable",owners:[...u],tags:["agent","tool","assigned"]},payload:S0}),p0=l({name:"AgentToolRemovedPayload",description:"Payload for agent tool removed event",fields:{agentId:{type:B.String_unsecure(),isOptional:!1},toolId:{type:B.String_unsecure(),isOptional:!1},agentName:{type:B.String_unsecure(),isOptional:!1},toolName:{type:B.String_unsecure(),isOptional:!1},removedAt:{type:B.DateTime(),isOptional:!1}}}),Qs=p({meta:{key:"agent-console.agent.toolRemoved",version:"1.0.0",description:"A tool was removed from an agent.",stability:"stable",owners:[...u],tags:["agent","tool","removed"]},payload:p0});var N=[{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")}];var Q=[{id:"tool-1",organizationId:"demo-org",name:"Web Search",slug:"web-search",description:"Search the web for real-time information using Brave API.",category:"RETRIEVAL",status:"ACTIVE",parametersSchema:{type:"object",properties:{query:{type:"string",description:"Search query"},numResults:{type:"number",default:10}},required:["query"]},outputSchema:{type:"array",items:{type:"object"}},implementationType:"http",implementationConfig:{url:"https://api.brave.com/search",method:"GET"},maxInvocationsPerMinute:60,timeoutMs:30000,version:"1.0.0",tags:["search","web"],createdAt:new Date("2024-01-01T00:00:00Z"),updatedAt:new Date("2024-02-15T10:00:00Z")},{id:"tool-2",organizationId:"demo-org",name:"SQL Query",slug:"sql-query",description:"Execute read-only SQL queries against the data warehouse.",category:"RETRIEVAL",status:"ACTIVE",parametersSchema:{type:"object",properties:{query:{type:"string",description:"SQL query"},maxRows:{type:"number",default:100}},required:["query"]},outputSchema:{type:"object"},implementationType:"function",implementationConfig:{handler:"executeSqlQuery"},maxInvocationsPerMinute:30,timeoutMs:60000,version:"1.1.0",tags:["sql","database"],createdAt:new Date("2024-01-05T00:00:00Z"),updatedAt:new Date("2024-03-10T14:00:00Z")},{id:"tool-3",organizationId:"demo-org",name:"Email Sender",slug:"email-sender",description:"Send emails via SMTP or API.",category:"COMMUNICATION",status:"ACTIVE",parametersSchema:{type:"object",properties:{to:{type:"string"},subject:{type:"string"},body:{type:"string"}},required:["to","subject","body"]},implementationType:"http",implementationConfig:{url:"/api/send-email",method:"POST"},maxInvocationsPerMinute:10,timeoutMs:30000,version:"1.0.0",tags:["email","communication"],createdAt:new Date("2024-02-01T00:00:00Z"),updatedAt:new Date("2024-02-01T00:00:00Z")},{id:"tool-4",organizationId:"demo-org",name:"GitHub Integration",slug:"github-integration",description:"Interact with GitHub repositories, PRs, and issues.",category:"INTEGRATION",status:"ACTIVE",parametersSchema:{type:"object",properties:{action:{type:"string",enum:["list_prs","get_pr","create_comment"]},repo:{type:"string"},params:{type:"object"}},required:["action","repo"]},implementationType:"http",implementationConfig:{url:"https://api.github.com",auth:"token"},maxInvocationsPerMinute:100,timeoutMs:15000,version:"2.0.0",tags:["github","integration","code"],createdAt:new Date("2024-02-20T00:00:00Z"),updatedAt:new Date("2024-04-01T09:00:00Z")},{id:"tool-5",organizationId:"demo-org",name:"Calculator",slug:"calculator",description:"Perform mathematical calculations.",category:"COMPUTATION",status:"ACTIVE",parametersSchema:{type:"object",properties:{expression:{type:"string",description:"Math expression to evaluate"}},required:["expression"]},outputSchema:{type:"object",properties:{result:{type:"number"}}},implementationType:"function",implementationConfig:{handler:"evaluateMath"},timeoutMs:5000,version:"1.0.0",tags:["math","utility"],createdAt:new Date("2024-01-10T00:00:00Z"),updatedAt:new Date("2024-01-10T00:00:00Z")}];import{defineSchemaModel as c,ScalarTypeEnum as Z}from"@contractspec/lib.schema";var ds=c({name:"Agent",description:"AI agent configuration",fields:{id:{type:Z.String_unsecure(),isOptional:!1},organizationId:{type:Z.String_unsecure(),isOptional:!1},name:{type:Z.NonEmptyString(),isOptional:!1},slug:{type:Z.String_unsecure(),isOptional:!1},description:{type:Z.String_unsecure(),isOptional:!0},status:{type:C,isOptional:!1},modelProvider:{type:t,isOptional:!1},modelName:{type:Z.NonEmptyString(),isOptional:!1},modelConfig:{type:Z.JSONObject(),isOptional:!0},systemPrompt:{type:Z.String_unsecure(),isOptional:!1},userPromptTemplate:{type:Z.String_unsecure(),isOptional:!0},toolIds:{type:Z.String_unsecure(),isArray:!0,isOptional:!0},toolChoice:{type:T,isOptional:!1,defaultValue:"auto"},maxIterations:{type:Z.Int_unsecure(),isOptional:!1,defaultValue:10},maxTokensPerRun:{type:Z.Int_unsecure(),isOptional:!0},timeoutMs:{type:Z.Int_unsecure(),isOptional:!1,defaultValue:120000},version:{type:Z.NonEmptyString(),isOptional:!1},tags:{type:Z.String_unsecure(),isArray:!0,isOptional:!0},createdAt:{type:Z.DateTime(),isOptional:!1},updatedAt:{type:Z.DateTime(),isOptional:!1}}}),o0=c({name:"AgentSummary",description:"Summary of an agent for list views",fields:{id:{type:Z.String_unsecure(),isOptional:!1},name:{type:Z.NonEmptyString(),isOptional:!1},slug:{type:Z.String_unsecure(),isOptional:!1},description:{type:Z.String_unsecure(),isOptional:!0},status:{type:C,isOptional:!1},modelProvider:{type:t,isOptional:!1},modelName:{type:Z.NonEmptyString(),isOptional:!1},version:{type:Z.NonEmptyString(),isOptional:!1},createdAt:{type:Z.DateTime(),isOptional:!1}}}),l0=c({name:"AgentToolRef",description:"Tool reference in agent context",fields:{id:{type:Z.String_unsecure(),isOptional:!1},name:{type:Z.NonEmptyString(),isOptional:!1},slug:{type:Z.String_unsecure(),isOptional:!1},description:{type:Z.String_unsecure(),isOptional:!1},category:{type:Z.String_unsecure(),isOptional:!1}}}),U0=c({name:"AgentWithTools",description:"Agent with associated tools",fields:{id:{type:Z.String_unsecure(),isOptional:!1},organizationId:{type:Z.String_unsecure(),isOptional:!1},name:{type:Z.NonEmptyString(),isOptional:!1},slug:{type:Z.String_unsecure(),isOptional:!1},description:{type:Z.String_unsecure(),isOptional:!0},status:{type:C,isOptional:!1},modelProvider:{type:t,isOptional:!1},modelName:{type:Z.NonEmptyString(),isOptional:!1},modelConfig:{type:Z.JSONObject(),isOptional:!0},systemPrompt:{type:Z.String_unsecure(),isOptional:!1},userPromptTemplate:{type:Z.String_unsecure(),isOptional:!0},toolIds:{type:Z.String_unsecure(),isArray:!0,isOptional:!0},toolChoice:{type:T,isOptional:!1},maxIterations:{type:Z.Int_unsecure(),isOptional:!1},maxTokensPerRun:{type:Z.Int_unsecure(),isOptional:!0},timeoutMs:{type:Z.Int_unsecure(),isOptional:!1},version:{type:Z.NonEmptyString(),isOptional:!1},tags:{type:Z.String_unsecure(),isArray:!0,isOptional:!0},createdAt:{type:Z.DateTime(),isOptional:!1},updatedAt:{type:Z.DateTime(),isOptional:!1},tools:{type:l0,isArray:!0,isOptional:!0}}}),$0=c({name:"CreateAgentInput",description:"Input for creating an agent",fields:{organizationId:{type:Z.String_unsecure(),isOptional:!1},name:{type:Z.NonEmptyString(),isOptional:!1},slug:{type:Z.String_unsecure(),isOptional:!1},description:{type:Z.String_unsecure(),isOptional:!0},modelProvider:{type:t,isOptional:!1},modelName:{type:Z.NonEmptyString(),isOptional:!1},modelConfig:{type:Z.JSONObject(),isOptional:!0},systemPrompt:{type:Z.String_unsecure(),isOptional:!1},userPromptTemplate:{type:Z.String_unsecure(),isOptional:!0},toolIds:{type:Z.String_unsecure(),isArray:!0,isOptional:!0},toolChoice:{type:T,isOptional:!0},maxIterations:{type:Z.Int_unsecure(),isOptional:!0},maxTokensPerRun:{type:Z.Int_unsecure(),isOptional:!0},timeoutMs:{type:Z.Int_unsecure(),isOptional:!0},tags:{type:Z.String_unsecure(),isArray:!0,isOptional:!0}}}),X0=c({name:"UpdateAgentInput",description:"Input for updating an agent",fields:{agentId:{type:Z.String_unsecure(),isOptional:!1},name:{type:Z.NonEmptyString(),isOptional:!0},description:{type:Z.String_unsecure(),isOptional:!0},status:{type:C,isOptional:!0},modelConfig:{type:Z.JSONObject(),isOptional:!0},systemPrompt:{type:Z.String_unsecure(),isOptional:!0},userPromptTemplate:{type:Z.String_unsecure(),isOptional:!0},toolIds:{type:Z.String_unsecure(),isArray:!0,isOptional:!0},toolChoice:{type:T,isOptional:!0},maxIterations:{type:Z.Int_unsecure(),isOptional:!0},maxTokensPerRun:{type:Z.Int_unsecure(),isOptional:!0},timeoutMs:{type:Z.Int_unsecure(),isOptional:!0},tags:{type:Z.String_unsecure(),isArray:!0,isOptional:!0}}});import{defineCommand as n,defineQuery as _0}from"@contractspec/lib.contracts-spec/operations";import{defineSchemaModel as K,ScalarTypeEnum as Y}from"@contractspec/lib.schema";var h=["@agent-console-team"],v0=n({meta:{key:"agent-console.agent.create",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","create"],description:"Creates a new AI agent configuration.",goal:"Allow users to define new AI agents with specific models and tools.",context:"Called from the agent builder UI when creating a new agent."},io:{input:$0,output:K({name:"CreateAgentOutput",fields:{id:{type:Y.String_unsecure(),isOptional:!1},name:{type:Y.NonEmptyString(),isOptional:!1},slug:{type:Y.String_unsecure(),isOptional:!1},status:{type:C,isOptional:!1}}}),errors:{SLUG_EXISTS:{description:"An agent with this slug already exists in the organization",http:409,gqlCode:"SLUG_EXISTS",when:"Slug is already taken"}}},policy:{auth:"user"},sideEffects:{emits:[{ref:G0.meta,when:"Agent is successfully created"}],audit:["agent-console.agent.created"]},acceptance:{scenarios:[{key:"create-agent-happy-path",given:["User is authenticated","Organization exists"],when:["User submits valid agent configuration"],then:["New agent is created with DRAFT status","AgentCreated event is emitted"]},{key:"create-agent-slug-conflict",given:["User is authenticated","Agent with same slug exists"],when:["User submits agent with duplicate slug"],then:["SLUG_EXISTS error is returned with 409 status"]}],examples:[{key:"basic-create",input:{name:"Support Assistant",slug:"support-assistant",modelProvider:"openai",modelId:"gpt-4"},output:{id:"agent-123",name:"Support Assistant",slug:"support-assistant",status:"draft"}}]}}),k0=n({meta:{key:"agent-console.agent.update",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","update"],description:"Updates an existing AI agent configuration.",goal:"Allow users to modify agent settings and configuration.",context:"Called from the agent settings UI."},io:{input:X0,output:K({name:"UpdateAgentOutput",fields:{id:{type:Y.String_unsecure(),isOptional:!1},name:{type:Y.NonEmptyString(),isOptional:!1},status:{type:C,isOptional:!1},updatedAt:{type:Y.DateTime(),isOptional:!1}}}),errors:{AGENT_NOT_FOUND:{description:"The specified agent does not exist",http:404,gqlCode:"AGENT_NOT_FOUND",when:"Agent ID is invalid"}}},policy:{auth:"user"},sideEffects:{emits:[{key:"agent.updated",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","updated"],when:"Agent is updated",payload:o0}],audit:["agent.updated"]},acceptance:{scenarios:[{key:"update-agent-happy-path",given:["Agent exists","User owns the agent"],when:["User submits updated configuration"],then:["Agent is updated","AgentUpdated event is emitted"]},{key:"update-agent-not-found",given:["Agent does not exist"],when:["User attempts to update"],then:["AGENT_NOT_FOUND error is returned"]}],examples:[{key:"update-name",input:{agentId:"agent-123",name:"Updated Assistant",systemPrompt:"You are a helpful assistant."},output:{id:"agent-123",name:"Updated Assistant",status:"draft",updatedAt:"2025-01-01T00:00:00Z"}}]}}),b0=_0({meta:{key:"agent-console.agent.get",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","get"],description:"Retrieves an agent by its ID.",goal:"View detailed agent configuration.",context:"Called when viewing agent details or editing."},io:{input:K({name:"GetAgentInput",fields:{agentId:{type:Y.String_unsecure(),isOptional:!1},includeTools:{type:Y.Boolean(),isOptional:!0}}}),output:U0,errors:{AGENT_NOT_FOUND:{description:"The specified agent does not exist",http:404,gqlCode:"AGENT_NOT_FOUND",when:"Agent ID is invalid"}}},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-agent-happy-path",given:["Agent exists"],when:["User requests agent by ID"],then:["Agent details are returned"]},{key:"get-agent-with-tools",given:["Agent exists with assigned tools"],when:["User requests agent with includeTools=true"],then:["Agent details with tools list are returned"]}],examples:[{key:"get-basic",input:{agentId:"agent-123",includeTools:!1},output:{id:"agent-123",name:"Support Assistant",status:"active",tools:[]}}]}}),H0=_0({meta:{key:"agent-console.agent.list",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","list"],description:"Lists agents for an organization with optional filtering.",goal:"Browse and search available agents.",context:"Agent list/dashboard view."},io:{input:K({name:"ListAgentsInput",fields:{organizationId:{type:Y.String_unsecure(),isOptional:!1},status:{type:C,isOptional:!0},modelProvider:{type:t,isOptional:!0},search:{type:Y.String_unsecure(),isOptional:!0},limit:{type:Y.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:Y.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:K({name:"ListAgentsOutput",fields:{items:{type:o0,isArray:!0,isOptional:!1},total:{type:Y.Int_unsecure(),isOptional:!1},hasMore:{type:Y.Boolean(),isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"list-agents-happy-path",given:["Organization has agents"],when:["User lists agents"],then:["Paginated list of agents is returned"]},{key:"list-agents-filter-by-status",given:["Organization has agents with mixed statuses"],when:["User filters by status=active"],then:["Only active agents are returned"]}],examples:[{key:"list-basic",input:{organizationId:"org-123",limit:10,offset:0},output:{items:[],total:0,hasMore:!1}}]}}),cs=n({meta:{key:"agent-console.agent.assignTool",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","tool","assign"],description:"Assigns a tool to an agent with optional configuration.",goal:"Enable agents to use specific tools.",context:"Agent configuration UI - tool selection."},io:{input:K({name:"AssignToolToAgentInput",fields:{agentId:{type:Y.String_unsecure(),isOptional:!1},toolId:{type:Y.String_unsecure(),isOptional:!1},config:{type:Y.JSONObject(),isOptional:!0},order:{type:Y.Int_unsecure(),isOptional:!0}}}),output:K({name:"AssignToolToAgentOutput",fields:{agentToolId:{type:Y.String_unsecure(),isOptional:!1},agentId:{type:Y.String_unsecure(),isOptional:!1},toolId:{type:Y.String_unsecure(),isOptional:!1}}}),errors:{TOOL_ALREADY_ASSIGNED:{description:"This tool is already assigned to the agent",http:409,gqlCode:"TOOL_ALREADY_ASSIGNED",when:"Tool assignment already exists"}}},policy:{auth:"user"},sideEffects:{audit:["agent.tool.assigned"]},acceptance:{scenarios:[{key:"assign-tool-happy-path",given:["Agent exists","Tool exists and is not assigned"],when:["User assigns tool to agent"],then:["Tool is assigned","Assignment ID is returned"]},{key:"assign-tool-already-assigned",given:["Tool is already assigned to agent"],when:["User attempts to assign again"],then:["TOOL_ALREADY_ASSIGNED error is returned"]}],examples:[{key:"assign-basic",input:{agentId:"agent-123",toolId:"tool-456"},output:{agentToolId:"at-789",agentId:"agent-123",toolId:"tool-456"}}]}}),rs=n({meta:{key:"agent-console.agent.removeTool",version:"1.0.0",stability:"stable",owners:[...h],tags:["agent","tool","remove"],description:"Removes a tool assignment from an agent.",goal:"Disable specific tools for an agent.",context:"Agent configuration UI - tool management."},io:{input:K({name:"RemoveToolFromAgentInput",fields:{agentId:{type:Y.String_unsecure(),isOptional:!1},toolId:{type:Y.String_unsecure(),isOptional:!1}}}),output:K({name:"RemoveToolFromAgentOutput",fields:{success:{type:Y.Boolean(),isOptional:!1}}})},policy:{auth:"user"},sideEffects:{audit:["agent.tool.removed"]},acceptance:{scenarios:[{key:"remove-tool-happy-path",given:["Agent exists","Tool is assigned to agent"],when:["User removes tool from agent"],then:["Tool is unassigned","Success is returned"]}],examples:[{key:"remove-basic",input:{agentId:"agent-123",toolId:"tool-456"},output:{success:!0}}]}});var u0=N.length+1;async function n0(s){let{organizationId:k,status:g,modelProvider:L,search:z,limit:J=20,offset:P=0}=s,F=N.filter((A)=>A.organizationId===k);if(g)F=F.filter((A)=>A.status===g);if(L)F=F.filter((A)=>A.modelProvider===L);if(z){let A=z.toLowerCase();F=F.filter((H)=>H.name.toLowerCase().includes(A)||H.description?.toLowerCase().includes(A)||H.tags?.some((q)=>q.toLowerCase().includes(A)))}let D=F.length;return{items:F.slice(P,P+J).map((A)=>({id:A.id,name:A.name,slug:A.slug,description:A.description,status:A.status,modelProvider:A.modelProvider,modelName:A.modelName,version:A.version,createdAt:A.createdAt})),total:D,hasMore:P+J<D}}async function a0(s){let k=N.find((L)=>L.id===s.agentId);if(!k)throw Error("AGENT_NOT_FOUND");let g={...k,toolIds:["tool-1","tool-2"]};if(s.includeTools)g.tools=Q.slice(0,2).map((L)=>({id:L.id,name:L.name,slug:L.slug,description:L.description,category:L.category}));return g}async function ss(s){if(N.some((g)=>g.organizationId===s.organizationId&&g.slug===s.slug))throw Error("SLUG_EXISTS");return{id:`agent-${u0++}`,name:s.name,slug:s.slug,status:"DRAFT"}}async function Es(s){let k=N.find((g)=>g.id===s.agentId);if(!k)throw Error("AGENT_NOT_FOUND");return{id:k.id,name:s.name??k.name,status:s.status??k.status,updatedAt:new Date}}import{defineEnum as a}from"@contractspec/lib.schema";var W=a("RunStatus",["QUEUED","IN_PROGRESS","COMPLETED","FAILED","CANCELLED","EXPIRED"]),N0=a("RunStepType",["MESSAGE_CREATION","TOOL_CALL","TOOL_RESULT","ERROR"]),s0=a("LogLevel",["DEBUG","INFO","WARN","ERROR"]),Q0=a("Granularity",["hour","day","week","month"]);import{defineSchemaModel as M,ScalarTypeEnum as v}from"@contractspec/lib.schema";var C0=M({name:"RunInput",description:"Input data for agent execution",fields:{message:{type:v.NonEmptyString(),isOptional:!1},context:{type:v.JSONObject(),isOptional:!0}}}),g0=M({name:"RunStep",description:"Individual step within a run",fields:{id:{type:v.String_unsecure(),isOptional:!1},stepNumber:{type:v.Int_unsecure(),isOptional:!1},type:{type:N0,isOptional:!1},toolId:{type:v.String_unsecure(),isOptional:!0},toolName:{type:v.String_unsecure(),isOptional:!0},input:{type:v.JSONObject(),isOptional:!0},output:{type:v.JSONObject(),isOptional:!0},status:{type:W,isOptional:!1},errorMessage:{type:v.String_unsecure(),isOptional:!0},tokensUsed:{type:v.Int_unsecure(),isOptional:!1,defaultValue:0},durationMs:{type:v.Int_unsecure(),isOptional:!0},startedAt:{type:v.DateTime(),isOptional:!1},completedAt:{type:v.DateTime(),isOptional:!0}}}),q0=M({name:"RunLog",description:"Execution log entry",fields:{id:{type:v.String_unsecure(),isOptional:!1},stepId:{type:v.String_unsecure(),isOptional:!0},level:{type:s0,isOptional:!1},message:{type:v.String_unsecure(),isOptional:!1},data:{type:v.JSONObject(),isOptional:!0},source:{type:v.String_unsecure(),isOptional:!0},traceId:{type:v.String_unsecure(),isOptional:!0},spanId:{type:v.String_unsecure(),isOptional:!0},timestamp:{type:v.DateTime(),isOptional:!1}}}),Ds=M({name:"RunAgentRef",description:"Agent reference in a run",fields:{id:{type:v.String_unsecure(),isOptional:!1},name:{type:v.NonEmptyString(),isOptional:!1},modelProvider:{type:v.String_unsecure(),isOptional:!1},modelName:{type:v.String_unsecure(),isOptional:!1}}}),K0=M({name:"Run",description:"Agent execution instance",fields:{id:{type:v.String_unsecure(),isOptional:!1},organizationId:{type:v.String_unsecure(),isOptional:!1},agentId:{type:v.String_unsecure(),isOptional:!1},userId:{type:v.String_unsecure(),isOptional:!0},sessionId:{type:v.String_unsecure(),isOptional:!0},input:{type:v.JSONObject(),isOptional:!1},output:{type:v.JSONObject(),isOptional:!0},status:{type:W,isOptional:!1},errorMessage:{type:v.String_unsecure(),isOptional:!0},errorCode:{type:v.String_unsecure(),isOptional:!0},totalTokens:{type:v.Int_unsecure(),isOptional:!1,defaultValue:0},promptTokens:{type:v.Int_unsecure(),isOptional:!1,defaultValue:0},completionTokens:{type:v.Int_unsecure(),isOptional:!1,defaultValue:0},totalIterations:{type:v.Int_unsecure(),isOptional:!1,defaultValue:0},durationMs:{type:v.Int_unsecure(),isOptional:!0},estimatedCostUsd:{type:v.Float_unsecure(),isOptional:!0},queuedAt:{type:v.DateTime(),isOptional:!1},startedAt:{type:v.DateTime(),isOptional:!0},completedAt:{type:v.DateTime(),isOptional:!0},metadata:{type:v.JSONObject(),isOptional:!0},steps:{type:g0,isArray:!0,isOptional:!0},logs:{type:q0,isArray:!0,isOptional:!0},agent:{type:Ds,isOptional:!0}}}),D0=M({name:"RunSummary",description:"Summary of a run for list views",fields:{id:{type:v.String_unsecure(),isOptional:!1},agentId:{type:v.String_unsecure(),isOptional:!1},agentName:{type:v.NonEmptyString(),isOptional:!1},status:{type:W,isOptional:!1},totalTokens:{type:v.Int_unsecure(),isOptional:!1},durationMs:{type:v.Int_unsecure(),isOptional:!0},estimatedCostUsd:{type:v.Float_unsecure(),isOptional:!0},queuedAt:{type:v.DateTime(),isOptional:!1},completedAt:{type:v.DateTime(),isOptional:!0}}}),R0=M({name:"TimelineDataPoint",description:"Timeline data point for metrics",fields:{period:{type:v.String_unsecure(),isOptional:!1},runs:{type:v.Int_unsecure(),isOptional:!1},tokens:{type:v.Int_unsecure(),isOptional:!1},costUsd:{type:v.Float_unsecure(),isOptional:!1},avgDurationMs:{type:v.Float_unsecure(),isOptional:!1}}});import{defineCommand as O0,defineQuery as y}from"@contractspec/lib.contracts-spec/operations";import{defineSchemaModel as _,ScalarTypeEnum as j}from"@contractspec/lib.schema";var R=["@agent-console-team"],j0=O0({meta:{key:"agent.run.execute",version:"1.0.0",stability:"stable",owners:[...R],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:_({name:"ExecuteAgentInput",fields:{agentId:{type:j.String_unsecure(),isOptional:!1},input:{type:C0,isOptional:!1},sessionId:{type:j.String_unsecure(),isOptional:!0},metadata:{type:j.JSONObject(),isOptional:!0},stream:{type:j.Boolean(),isOptional:!0},maxIterations:{type:j.Int_unsecure(),isOptional:!0},timeoutMs:{type:j.Int_unsecure(),isOptional:!0}}}),output:_({name:"ExecuteAgentOutput",fields:{runId:{type:j.String_unsecure(),isOptional:!1},status:{type:W,isOptional:!1},estimatedWaitMs:{type:j.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:[...R],tags:["run","started"],when:"Run is queued",payload:D0}],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}}]}}),As=O0({meta:{key:"agent.run.cancel",version:"1.0.0",stability:"stable",owners:[...R],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:_({name:"CancelRunInput",fields:{runId:{type:j.String_unsecure(),isOptional:!1},reason:{type:j.String_unsecure(),isOptional:!0}}}),output:_({name:"CancelRunOutput",fields:{success:{type:j.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:[...R],tags:["run","cancelled"],when:"Run is cancelled",payload:D0}],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"}}]}}),Is=y({meta:{key:"agent.run.get",version:"1.0.0",stability:"stable",owners:[...R],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:_({name:"GetRunInput",fields:{runId:{type:j.String_unsecure(),isOptional:!1},includeSteps:{type:j.Boolean(),isOptional:!0},includeLogs:{type:j.Boolean(),isOptional:!0}}}),output:K0,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:[]}}]}}),z0=y({meta:{key:"agent.run.list",version:"1.0.0",stability:"stable",owners:[...R],tags:["run","list"],description:"Lists runs with optional filtering.",goal:"Browse and search run history.",context:"Run history/dashboard view."},io:{input:_({name:"ListRunsInput",fields:{organizationId:{type:j.String_unsecure(),isOptional:!0},agentId:{type:j.String_unsecure(),isOptional:!0},userId:{type:j.String_unsecure(),isOptional:!0},sessionId:{type:j.String_unsecure(),isOptional:!0},status:{type:W,isOptional:!0},startDate:{type:j.DateTime(),isOptional:!0},endDate:{type:j.DateTime(),isOptional:!0},limit:{type:j.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:j.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:_({name:"ListRunsOutput",fields:{items:{type:D0,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1},hasMore:{type:j.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}}]}}),Z2=y({meta:{key:"agent.run.getSteps",version:"1.0.0",stability:"stable",owners:[...R],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:_({name:"GetRunStepsInput",fields:{runId:{type:j.String_unsecure(),isOptional:!1}}}),output:_({name:"GetRunStepsOutput",fields:{steps:{type:g0,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:[]}}]}}),P2=y({meta:{key:"agent.run.getLogs",version:"1.0.0",stability:"stable",owners:[...R],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:_({name:"GetRunLogsInput",fields:{runId:{type:j.String_unsecure(),isOptional:!1},level:{type:s0,isOptional:!0},stepId:{type:j.String_unsecure(),isOptional:!0},limit:{type:j.Int_unsecure(),isOptional:!0,defaultValue:100},offset:{type:j.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:_({name:"GetRunLogsOutput",fields:{items:{type:q0,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1},hasMore:{type:j.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}}]}}),Zs=y({meta:{key:"agent.run.getMetrics",version:"1.0.0",stability:"stable",owners:[...R],tags:["run","metrics"],description:"Retrieves aggregated metrics for runs within a time period.",goal:"Monitor and analyze agent usage.",context:"Analytics dashboard."},io:{input:_({name:"GetRunMetricsInput",fields:{organizationId:{type:j.String_unsecure(),isOptional:!1},agentId:{type:j.String_unsecure(),isOptional:!0},startDate:{type:j.DateTime(),isOptional:!1},endDate:{type:j.DateTime(),isOptional:!1},granularity:{type:Q0,isOptional:!0,defaultValue:"day"}}}),output:_({name:"GetRunMetricsOutput",fields:{totalRuns:{type:j.Int_unsecure(),isOptional:!1},completedRuns:{type:j.Int_unsecure(),isOptional:!1},failedRuns:{type:j.Int_unsecure(),isOptional:!1},totalTokens:{type:j.Int_unsecure(),isOptional:!1},totalCostUsd:{type:j.Float_unsecure(),isOptional:!1},averageDurationMs:{type:j.Float_unsecure(),isOptional:!1},successRate:{type:j.Float_unsecure(),isOptional:!1},timeline:{type:R0,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:[]}}]}});import{defineEnum as V0}from"@contractspec/lib.schema";var r=V0("ToolCategory",["RETRIEVAL","COMPUTATION","COMMUNICATION","INTEGRATION","UTILITY","CUSTOM"]),d=V0("ToolStatus",["DRAFT","ACTIVE","DEPRECATED","DISABLED"]),x0=V0("ImplementationType",["http","function","workflow"]);import{defineSchemaModel as A0,ScalarTypeEnum as V}from"@contractspec/lib.schema";var W0=A0({name:"Tool",description:"AI tool definition",fields:{id:{type:V.String_unsecure(),isOptional:!1},organizationId:{type:V.String_unsecure(),isOptional:!1},name:{type:V.NonEmptyString(),isOptional:!1},slug:{type:V.String_unsecure(),isOptional:!1},description:{type:V.String_unsecure(),isOptional:!1},category:{type:r,isOptional:!1},status:{type:d,isOptional:!1},parametersSchema:{type:V.JSONObject(),isOptional:!1},outputSchema:{type:V.JSONObject(),isOptional:!0},implementationType:{type:x0,isOptional:!1},implementationConfig:{type:V.JSONObject(),isOptional:!1},maxInvocationsPerMinute:{type:V.Int_unsecure(),isOptional:!0},timeoutMs:{type:V.Int_unsecure(),isOptional:!1,defaultValue:30000},version:{type:V.NonEmptyString(),isOptional:!1},tags:{type:V.String_unsecure(),isArray:!0,isOptional:!0},createdAt:{type:V.DateTime(),isOptional:!1},updatedAt:{type:V.DateTime(),isOptional:!1}}}),I0=A0({name:"ToolSummary",description:"Summary of a tool for list views",fields:{id:{type:V.String_unsecure(),isOptional:!1},name:{type:V.NonEmptyString(),isOptional:!1},slug:{type:V.String_unsecure(),isOptional:!1},description:{type:V.String_unsecure(),isOptional:!1},category:{type:r,isOptional:!1},status:{type:d,isOptional:!1},version:{type:V.NonEmptyString(),isOptional:!1},createdAt:{type:V.DateTime(),isOptional:!1}}}),d0=A0({name:"CreateToolInput",description:"Input for creating a tool",fields:{organizationId:{type:V.String_unsecure(),isOptional:!1},name:{type:V.NonEmptyString(),isOptional:!1},slug:{type:V.String_unsecure(),isOptional:!1},description:{type:V.String_unsecure(),isOptional:!1},category:{type:r,isOptional:!0},parametersSchema:{type:V.JSONObject(),isOptional:!1},outputSchema:{type:V.JSONObject(),isOptional:!0},implementationType:{type:x0,isOptional:!1},implementationConfig:{type:V.JSONObject(),isOptional:!1},maxInvocationsPerMinute:{type:V.Int_unsecure(),isOptional:!0},timeoutMs:{type:V.Int_unsecure(),isOptional:!0},tags:{type:V.String_unsecure(),isArray:!0,isOptional:!0}}}),t0=A0({name:"UpdateToolInput",description:"Input for updating a tool",fields:{toolId:{type:V.String_unsecure(),isOptional:!1},name:{type:V.NonEmptyString(),isOptional:!0},description:{type:V.String_unsecure(),isOptional:!0},status:{type:d,isOptional:!0},parametersSchema:{type:V.JSONObject(),isOptional:!0},outputSchema:{type:V.JSONObject(),isOptional:!0},implementationConfig:{type:V.JSONObject(),isOptional:!0},maxInvocationsPerMinute:{type:V.Int_unsecure(),isOptional:!0},timeoutMs:{type:V.Int_unsecure(),isOptional:!0},tags:{type:V.String_unsecure(),isArray:!0,isOptional:!0}}});import{defineCommand as L0,defineQuery as h0}from"@contractspec/lib.contracts-spec/operations";import{defineSchemaModel as w,ScalarTypeEnum as U}from"@contractspec/lib.schema";var f=["@agent-console-team"],Ps=L0({meta:{key:"agent.tool.create",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","create"],description:"Creates a new AI tool definition.",goal:"Allow users to define new tools that agents can use.",context:"Called from the tool builder UI when creating a new tool."},io:{input:d0,output:w({name:"CreateToolOutput",fields:{id:{type:U.String_unsecure(),isOptional:!1},name:{type:U.NonEmptyString(),isOptional:!1},slug:{type:U.String_unsecure(),isOptional:!1},status:{type:d,isOptional:!1}}}),errors:{SLUG_EXISTS:{description:"A tool with this slug already exists in the organization",http:409,gqlCode:"SLUG_EXISTS",when:"Slug is already taken"}}},policy:{auth:"user"},sideEffects:{emits:[{key:"tool.created",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","created"],when:"Tool is successfully created",payload:I0}],audit:["tool.created"]},acceptance:{scenarios:[{key:"create-tool-happy-path",given:["User is authenticated","Organization exists"],when:["User submits valid tool configuration"],then:["New tool is created","ToolCreated event is emitted"]},{key:"create-tool-slug-conflict",given:["Tool with same slug exists"],when:["User submits tool with duplicate slug"],then:["SLUG_EXISTS error is returned"]}],examples:[{key:"create-api-tool",input:{name:"Weather API",slug:"weather-api",category:"api",description:"Fetches weather data"},output:{id:"tool-123",name:"Weather API",slug:"weather-api",status:"draft"}}]}}),os=L0({meta:{key:"agent.tool.update",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","update"],description:"Updates an existing AI tool definition.",goal:"Allow users to modify tool settings and configuration.",context:"Called from the tool settings UI."},io:{input:t0,output:w({name:"UpdateToolOutput",fields:{id:{type:U.String_unsecure(),isOptional:!1},name:{type:U.NonEmptyString(),isOptional:!1},status:{type:d,isOptional:!1},updatedAt:{type:U.DateTime(),isOptional:!1}}}),errors:{TOOL_NOT_FOUND:{description:"The specified tool does not exist",http:404,gqlCode:"TOOL_NOT_FOUND",when:"Tool ID is invalid"}}},policy:{auth:"user"},sideEffects:{emits:[{key:"tool.updated",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","updated"],when:"Tool is updated",payload:I0}],audit:["tool.updated"]},acceptance:{scenarios:[{key:"update-tool-happy-path",given:["Tool exists","User owns the tool"],when:["User submits updated configuration"],then:["Tool is updated","ToolUpdated event is emitted"]}],examples:[{key:"update-description",input:{toolId:"tool-123",description:"Updated weather API tool"},output:{id:"tool-123",name:"Weather API",status:"draft",updatedAt:"2025-01-01T00:00:00Z"}}]}}),vs=h0({meta:{key:"agent.tool.get",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","get"],description:"Retrieves a tool by its ID.",goal:"View detailed tool configuration.",context:"Called when viewing tool details or editing."},io:{input:w({name:"GetToolInput",fields:{toolId:{type:U.String_unsecure(),isOptional:!1}}}),output:W0,errors:{TOOL_NOT_FOUND:{description:"The specified tool does not exist",http:404,gqlCode:"TOOL_NOT_FOUND",when:"Tool ID is invalid"}}},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-tool-happy-path",given:["Tool exists"],when:["User requests tool by ID"],then:["Tool details are returned"]}],examples:[{key:"get-basic",input:{toolId:"tool-123"},output:{id:"tool-123",name:"Weather API",status:"active",category:"api"}}]}}),B0=h0({meta:{key:"agent.tool.list",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","list"],description:"Lists tools for an organization with optional filtering.",goal:"Browse and search available tools.",context:"Tool list/dashboard view."},io:{input:w({name:"ListToolsInput",fields:{organizationId:{type:U.String_unsecure(),isOptional:!1},category:{type:r,isOptional:!0},status:{type:d,isOptional:!0},search:{type:U.String_unsecure(),isOptional:!0},limit:{type:U.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:U.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:w({name:"ListToolsOutput",fields:{items:{type:I0,isArray:!0,isOptional:!1},total:{type:U.Int_unsecure(),isOptional:!1},hasMore:{type:U.Boolean(),isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"list-tools-happy-path",given:["Organization has tools"],when:["User lists tools"],then:["Paginated list of tools is returned"]}],examples:[{key:"list-by-category",input:{organizationId:"org-123",category:"api",limit:10},output:{items:[],total:0,hasMore:!1}}]}}),ks=L0({meta:{key:"agent.tool.test",version:"1.0.0",stability:"stable",owners:[...f],tags:["tool","test"],description:"Tests a tool with sample input to verify it works correctly.",goal:"Validate tool configuration before deployment.",context:"Tool builder UI - test panel."},io:{input:w({name:"TestToolInput",fields:{toolId:{type:U.String_unsecure(),isOptional:!1},testInput:{type:U.JSONObject(),isOptional:!1}}}),output:w({name:"TestToolOutput",fields:{success:{type:U.Boolean(),isOptional:!1},output:{type:U.JSONObject(),isOptional:!0},error:{type:U.String_unsecure(),isOptional:!0},durationMs:{type:U.Int_unsecure(),isOptional:!1}}}),errors:{TOOL_NOT_FOUND:{description:"The specified tool does not exist",http:404,gqlCode:"TOOL_NOT_FOUND",when:"Tool ID is invalid"},TOOL_EXECUTION_ERROR:{description:"Tool execution failed",http:500,gqlCode:"TOOL_EXECUTION_ERROR",when:"Tool returns an error"}}},policy:{auth:"user"},sideEffects:{audit:["tool.tested"]},acceptance:{scenarios:[{key:"test-tool-success",given:["Tool exists","Tool is configured correctly"],when:["User runs test with valid input"],then:["Tool executes successfully","Output is returned"]},{key:"test-tool-failure",given:["Tool exists","Tool has configuration error"],when:["User runs test"],then:["TOOL_EXECUTION_ERROR is returned"]}],examples:[{key:"test-weather-api",input:{toolId:"tool-123",testInput:{city:"Paris"}},output:{success:!0,output:{temperature:22},durationMs:150}}]}});import{web as Hs}from"@contractspec/lib.runtime-sandbox";var{generateId:M0}=Hs;var w0={queuedAt:"r.queuedAt",totalTokens:"r.totalTokens",durationMs:"r.durationMs",estimatedCostUsd:"r.estimatedCostUsd",status:"r.status",agentName:"a.name"};function Z0(s){return{id:s.id,projectId:s.projectId,organizationId:s.organizationId,name:s.name,description:s.description??void 0,modelProvider:s.modelProvider,modelName:s.modelName,systemPrompt:s.systemPrompt??void 0,temperature:s.temperature,maxTokens:s.maxTokens,status:s.status,createdAt:new Date(s.createdAt),updatedAt:new Date(s.updatedAt)}}function gs(s){return{id:s.id,projectId:s.projectId,organizationId:s.organizationId,name:s.name,description:s.description??void 0,version:s.version,category:s.category,status:s.status,inputSchema:s.inputSchema??void 0,outputSchema:s.outputSchema??void 0,endpoint:s.endpoint??void 0,createdAt:new Date(s.createdAt),updatedAt:new Date(s.updatedAt)}}function f0(s,k){return{id:s.id,projectId:s.projectId,agentId:s.agentId,agentName:k,status:s.status,input:s.input??void 0,output:s.output??void 0,totalTokens:s.totalTokens,promptTokens:s.promptTokens,completionTokens:s.completionTokens,estimatedCostUsd:s.estimatedCostUsd,durationMs:s.durationMs??void 0,errorMessage:s.errorMessage??void 0,queuedAt:new Date(s.queuedAt),startedAt:s.startedAt?new Date(s.startedAt):void 0,completedAt:s.completedAt?new Date(s.completedAt):void 0}}function G2(s){async function k(I){let{projectId:A,organizationId:H,status:q,search:o,limit:x=20,offset:$=0}=I,X="WHERE projectId = ?",G=[A];if(H)X+=" AND organizationId = ?",G.push(H);if(q&&q!=="all")X+=" AND status = ?",G.push(q);if(o)X+=" AND (name LIKE ? OR description LIKE ?)",G.push(`%${o}%`,`%${o}%`);let E=(await s.query(`SELECT COUNT(*) as count FROM agent_definition ${X}`,G)).rows[0]?.count??0,O=(await s.query(`SELECT * FROM agent_definition ${X} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,[...G,x,$])).rows;return{items:O.map(Z0),total:E,hasMore:$+O.length<E}}async function g(I){let A=(await s.query("SELECT * FROM agent_definition WHERE id = ?",[I])).rows;return A[0]?Z0(A[0]):null}async function L(I,A){let H=M0("agent"),q=new Date().toISOString();await s.execute(`INSERT INTO agent_definition (id, projectId, organizationId, name, description, modelProvider, modelName, systemPrompt, temperature, maxTokens, status, createdAt, updatedAt)
|
|
2
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[H,A.projectId,A.organizationId,I.name,I.description??null,I.modelProvider??"openai",I.modelName??"gpt-4",I.systemPrompt??null,I.temperature??0.7,I.maxTokens??4096,"DRAFT",q,q]);let x=(await s.query("SELECT * FROM agent_definition WHERE id = ?",[H])).rows[0];if(!x)throw Error("Failed to retrieve created agent");return Z0(x)}async function z(I){let A=new Date().toISOString(),H=["updatedAt = ?"],q=[A];if(I.name!==void 0)H.push("name = ?"),q.push(I.name);if(I.description!==void 0)H.push("description = ?"),q.push(I.description);if(I.status!==void 0)H.push("status = ?"),q.push(I.status);q.push(I.id),await s.execute(`UPDATE agent_definition SET ${H.join(", ")} WHERE id = ?`,q);let o=(await s.query("SELECT * FROM agent_definition WHERE id = ?",[I.id])).rows;if(!o[0])throw Error("NOT_FOUND");return Z0(o[0])}async function J(I){let{projectId:A,organizationId:H,category:q,status:o,search:x,limit:$=50,offset:X=0}=I,G="WHERE projectId = ?",b=[A];if(H)G+=" AND organizationId = ?",b.push(H);if(q&&q!=="all")G+=" AND category = ?",b.push(q);if(o&&o!=="all")G+=" AND status = ?",b.push(o);if(x)G+=" AND (name LIKE ? OR description LIKE ?)",b.push(`%${x}%`,`%${x}%`);let O=(await s.query(`SELECT COUNT(*) as count FROM agent_tool ${G}`,b)).rows[0]?.count??0,S=(await s.query(`SELECT * FROM agent_tool ${G} ORDER BY name ASC LIMIT ? OFFSET ?`,[...b,$,X])).rows;return{items:S.map(gs),total:O,hasMore:X+S.length<O}}async function P(I){let{projectId:A,agentId:H,status:q,sortBy:o,sortDirection:x="desc",limit:$=20,offset:X=0}=I,G="WHERE r.projectId = ?",b=[A];if(H)G+=" AND r.agentId = ?",b.push(H);if(q&&q!=="all")G+=" AND r.status = ?",b.push(q);let O=(await s.query(`SELECT COUNT(*) as count FROM agent_run r ${G}`,b)).rows[0]?.count??0,S=o?w0[o]:w0.queuedAt,m0=x==="asc"?"ASC":"DESC",Y0=(await s.query(`SELECT r.*, a.name as agentName
|
|
2375
3
|
FROM agent_run r
|
|
2376
4
|
LEFT JOIN agent_definition a ON r.agentId = a.id
|
|
2377
|
-
${
|
|
2378
|
-
ORDER BY ${
|
|
2379
|
-
return {
|
|
2380
|
-
items: rows.map((r) => rowToRun(r, r.agentName)),
|
|
2381
|
-
total,
|
|
2382
|
-
hasMore: offset + rows.length < total
|
|
2383
|
-
};
|
|
2384
|
-
}
|
|
2385
|
-
async function getRunMetrics(input) {
|
|
2386
|
-
let whereClause = "WHERE projectId = ?";
|
|
2387
|
-
const params = [input.projectId];
|
|
2388
|
-
if (input.agentId) {
|
|
2389
|
-
whereClause += " AND agentId = ?";
|
|
2390
|
-
params.push(input.agentId);
|
|
2391
|
-
}
|
|
2392
|
-
if (input.startDate) {
|
|
2393
|
-
whereClause += " AND queuedAt >= ?";
|
|
2394
|
-
params.push(input.startDate.toISOString());
|
|
2395
|
-
}
|
|
2396
|
-
if (input.endDate) {
|
|
2397
|
-
whereClause += " AND queuedAt <= ?";
|
|
2398
|
-
params.push(input.endDate.toISOString());
|
|
2399
|
-
}
|
|
2400
|
-
const result = (await db.query(`SELECT
|
|
5
|
+
${G}
|
|
6
|
+
ORDER BY ${S} ${m0}, r.queuedAt DESC LIMIT ? OFFSET ?`,[...b,$,X])).rows;return{items:Y0.map((F0)=>f0(F0,F0.agentName)),total:O,hasMore:X+Y0.length<O}}async function F(I){let A="WHERE projectId = ?",H=[I.projectId];if(I.agentId)A+=" AND agentId = ?",H.push(I.agentId);if(I.startDate)A+=" AND queuedAt >= ?",H.push(I.startDate.toISOString());if(I.endDate)A+=" AND queuedAt <= ?",H.push(I.endDate.toISOString());let o=(await s.query(`SELECT
|
|
2401
7
|
COUNT(*) as totalRuns,
|
|
2402
8
|
SUM(CASE WHEN status = 'COMPLETED' THEN 1 ELSE 0 END) as completedRuns,
|
|
2403
9
|
AVG(CASE WHEN status = 'COMPLETED' THEN durationMs ELSE NULL END) as avgDuration,
|
|
2404
10
|
COALESCE(SUM(totalTokens), 0) as totalTokens,
|
|
2405
11
|
COALESCE(SUM(estimatedCostUsd), 0) as totalCost
|
|
2406
|
-
FROM agent_run ${
|
|
2407
|
-
const data = result[0];
|
|
2408
|
-
const totalRuns = data?.totalRuns ?? 0;
|
|
2409
|
-
const completedRuns = data?.completedRuns ?? 0;
|
|
2410
|
-
return {
|
|
2411
|
-
totalRuns,
|
|
2412
|
-
successRate: totalRuns > 0 ? completedRuns / totalRuns : 0,
|
|
2413
|
-
averageDurationMs: data?.avgDuration ?? 0,
|
|
2414
|
-
totalTokens: data?.totalTokens ?? 0,
|
|
2415
|
-
totalCostUsd: data?.totalCost ?? 0
|
|
2416
|
-
};
|
|
2417
|
-
}
|
|
2418
|
-
async function executeAgent(input) {
|
|
2419
|
-
const agent = await getAgent(input.agentId);
|
|
2420
|
-
if (!agent)
|
|
2421
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
2422
|
-
if (agent.status !== "ACTIVE")
|
|
2423
|
-
throw new Error("AGENT_NOT_ACTIVE");
|
|
2424
|
-
const id = generateId("run");
|
|
2425
|
-
const now = new Date().toISOString();
|
|
2426
|
-
const pid = input.context?.projectId ?? agent.projectId;
|
|
2427
|
-
await db.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
2428
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [id, pid, input.agentId, "QUEUED", input.message, 0, 0, 0, 0, now]);
|
|
2429
|
-
const rows = (await db.query(`SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?`, [id])).rows;
|
|
2430
|
-
if (!rows[0])
|
|
2431
|
-
throw new Error("Failed to retrieve created run");
|
|
2432
|
-
return rowToRun(rows[0], rows[0].agentName);
|
|
2433
|
-
}
|
|
2434
|
-
return {
|
|
2435
|
-
listAgents,
|
|
2436
|
-
getAgent,
|
|
2437
|
-
createAgent,
|
|
2438
|
-
updateAgent,
|
|
2439
|
-
executeAgent,
|
|
2440
|
-
listTools,
|
|
2441
|
-
listRuns,
|
|
2442
|
-
getRunMetrics
|
|
2443
|
-
};
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
// src/shared/mock-runs.ts
|
|
2447
|
-
var MOCK_RUNS = [
|
|
2448
|
-
{
|
|
2449
|
-
id: "run-1",
|
|
2450
|
-
organizationId: "demo-org",
|
|
2451
|
-
projectId: "demo-project",
|
|
2452
|
-
agentId: "agent-1",
|
|
2453
|
-
agentName: "Customer Support Bot",
|
|
2454
|
-
userId: "user-1",
|
|
2455
|
-
sessionId: "session-1",
|
|
2456
|
-
input: { message: "How do I reset my password?", context: {} },
|
|
2457
|
-
output: { response: "You can reset your password by clicking..." },
|
|
2458
|
-
status: "COMPLETED",
|
|
2459
|
-
totalTokens: 1250,
|
|
2460
|
-
promptTokens: 800,
|
|
2461
|
-
completionTokens: 450,
|
|
2462
|
-
totalIterations: 3,
|
|
2463
|
-
durationMs: 4500,
|
|
2464
|
-
estimatedCostUsd: 0.0025,
|
|
2465
|
-
queuedAt: new Date("2024-04-15T10:00:00Z"),
|
|
2466
|
-
startedAt: new Date("2024-04-15T10:00:01Z"),
|
|
2467
|
-
completedAt: new Date("2024-04-15T10:00:05Z"),
|
|
2468
|
-
steps: [],
|
|
2469
|
-
logs: []
|
|
2470
|
-
},
|
|
2471
|
-
{
|
|
2472
|
-
id: "run-2",
|
|
2473
|
-
organizationId: "demo-org",
|
|
2474
|
-
projectId: "demo-project",
|
|
2475
|
-
agentId: "agent-2",
|
|
2476
|
-
agentName: "Code Review Assistant",
|
|
2477
|
-
userId: "user-2",
|
|
2478
|
-
input: { message: "Review PR #123", context: { prNumber: 123 } },
|
|
2479
|
-
status: "IN_PROGRESS",
|
|
2480
|
-
totalTokens: 3500,
|
|
2481
|
-
promptTokens: 3000,
|
|
2482
|
-
completionTokens: 500,
|
|
2483
|
-
totalIterations: 5,
|
|
2484
|
-
queuedAt: new Date("2024-04-15T10:30:00Z"),
|
|
2485
|
-
startedAt: new Date("2024-04-15T10:30:02Z"),
|
|
2486
|
-
steps: [],
|
|
2487
|
-
logs: []
|
|
2488
|
-
},
|
|
2489
|
-
{
|
|
2490
|
-
id: "run-3",
|
|
2491
|
-
organizationId: "demo-org",
|
|
2492
|
-
projectId: "demo-project",
|
|
2493
|
-
agentId: "agent-1",
|
|
2494
|
-
agentName: "Customer Support Bot",
|
|
2495
|
-
userId: "user-1",
|
|
2496
|
-
input: { message: "What are your business hours?" },
|
|
2497
|
-
output: { response: "Our business hours are 9 AM to 5 PM EST..." },
|
|
2498
|
-
status: "COMPLETED",
|
|
2499
|
-
totalTokens: 800,
|
|
2500
|
-
promptTokens: 500,
|
|
2501
|
-
completionTokens: 300,
|
|
2502
|
-
totalIterations: 2,
|
|
2503
|
-
durationMs: 2100,
|
|
2504
|
-
estimatedCostUsd: 0.0012,
|
|
2505
|
-
queuedAt: new Date("2024-04-15T09:00:00Z"),
|
|
2506
|
-
startedAt: new Date("2024-04-15T09:00:01Z"),
|
|
2507
|
-
completedAt: new Date("2024-04-15T09:00:03Z"),
|
|
2508
|
-
steps: [],
|
|
2509
|
-
logs: []
|
|
2510
|
-
},
|
|
2511
|
-
{
|
|
2512
|
-
id: "run-4",
|
|
2513
|
-
organizationId: "demo-org",
|
|
2514
|
-
projectId: "demo-project",
|
|
2515
|
-
agentId: "agent-3",
|
|
2516
|
-
agentName: "Data Analyst",
|
|
2517
|
-
userId: "user-3",
|
|
2518
|
-
input: { message: "Generate sales report for Q1" },
|
|
2519
|
-
status: "FAILED",
|
|
2520
|
-
errorMessage: "Database connection timeout",
|
|
2521
|
-
errorCode: "DB_TIMEOUT",
|
|
2522
|
-
totalTokens: 2000,
|
|
2523
|
-
promptTokens: 1500,
|
|
2524
|
-
completionTokens: 500,
|
|
2525
|
-
totalIterations: 8,
|
|
2526
|
-
durationMs: 45000,
|
|
2527
|
-
queuedAt: new Date("2024-04-14T15:00:00Z"),
|
|
2528
|
-
startedAt: new Date("2024-04-14T15:00:05Z"),
|
|
2529
|
-
completedAt: new Date("2024-04-14T15:00:50Z"),
|
|
2530
|
-
steps: [],
|
|
2531
|
-
logs: []
|
|
2532
|
-
},
|
|
2533
|
-
{
|
|
2534
|
-
id: "run-5",
|
|
2535
|
-
organizationId: "demo-org",
|
|
2536
|
-
projectId: "demo-project",
|
|
2537
|
-
agentId: "agent-2",
|
|
2538
|
-
agentName: "Code Review Assistant",
|
|
2539
|
-
userId: "user-2",
|
|
2540
|
-
input: { message: "Review PR #120" },
|
|
2541
|
-
output: { response: "Code review complete. 3 suggestions..." },
|
|
2542
|
-
status: "COMPLETED",
|
|
2543
|
-
totalTokens: 5200,
|
|
2544
|
-
promptTokens: 4000,
|
|
2545
|
-
completionTokens: 1200,
|
|
2546
|
-
totalIterations: 7,
|
|
2547
|
-
durationMs: 15000,
|
|
2548
|
-
estimatedCostUsd: 0.0156,
|
|
2549
|
-
queuedAt: new Date("2024-04-14T11:00:00Z"),
|
|
2550
|
-
startedAt: new Date("2024-04-14T11:00:03Z"),
|
|
2551
|
-
completedAt: new Date("2024-04-14T11:00:18Z"),
|
|
2552
|
-
steps: [],
|
|
2553
|
-
logs: []
|
|
2554
|
-
}
|
|
2555
|
-
];
|
|
2556
|
-
|
|
2557
|
-
// src/run/run.handler.ts
|
|
2558
|
-
var nextMockRunId = MOCK_RUNS.length + 1;
|
|
2559
|
-
async function mockListRunsHandler(input) {
|
|
2560
|
-
const { agentId, status, limit = 20, offset = 0 } = input;
|
|
2561
|
-
let filtered = [...MOCK_RUNS];
|
|
2562
|
-
if (agentId)
|
|
2563
|
-
filtered = filtered.filter((r) => r.agentId === agentId);
|
|
2564
|
-
if (status)
|
|
2565
|
-
filtered = filtered.filter((r) => r.status === status);
|
|
2566
|
-
const total = filtered.length;
|
|
2567
|
-
const items = filtered.slice(offset, offset + limit).map((r) => {
|
|
2568
|
-
const agent = MOCK_AGENTS.find((a) => a.id === r.agentId);
|
|
2569
|
-
return {
|
|
2570
|
-
id: r.id,
|
|
2571
|
-
agentId: r.agentId,
|
|
2572
|
-
agentName: agent?.name ?? "Unknown",
|
|
2573
|
-
status: r.status,
|
|
2574
|
-
totalTokens: r.totalTokens,
|
|
2575
|
-
durationMs: r.durationMs,
|
|
2576
|
-
estimatedCostUsd: r.estimatedCostUsd,
|
|
2577
|
-
queuedAt: r.queuedAt,
|
|
2578
|
-
completedAt: r.completedAt
|
|
2579
|
-
};
|
|
2580
|
-
});
|
|
2581
|
-
return { items, total, hasMore: offset + limit < total };
|
|
2582
|
-
}
|
|
2583
|
-
async function mockGetRunHandler(input) {
|
|
2584
|
-
const run = MOCK_RUNS.find((r) => r.id === input.runId);
|
|
2585
|
-
if (!run)
|
|
2586
|
-
throw new Error("RUN_NOT_FOUND");
|
|
2587
|
-
const agent = MOCK_AGENTS.find((a) => a.id === run.agentId);
|
|
2588
|
-
return {
|
|
2589
|
-
...run,
|
|
2590
|
-
agent: agent ? {
|
|
2591
|
-
id: agent.id,
|
|
2592
|
-
name: agent.name,
|
|
2593
|
-
modelProvider: agent.modelProvider,
|
|
2594
|
-
modelName: agent.modelName
|
|
2595
|
-
} : undefined,
|
|
2596
|
-
steps: input.includeSteps ? run.steps : undefined,
|
|
2597
|
-
logs: input.includeLogs ? run.logs : undefined
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2600
|
-
async function mockExecuteAgentHandler(input) {
|
|
2601
|
-
const agent = MOCK_AGENTS.find((a) => a.id === input.agentId);
|
|
2602
|
-
if (!agent)
|
|
2603
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
2604
|
-
if (agent.status !== "ACTIVE")
|
|
2605
|
-
throw new Error("AGENT_NOT_ACTIVE");
|
|
2606
|
-
return {
|
|
2607
|
-
runId: `run-${nextMockRunId++}`,
|
|
2608
|
-
status: "QUEUED",
|
|
2609
|
-
estimatedWaitMs: 500
|
|
2610
|
-
};
|
|
2611
|
-
}
|
|
2612
|
-
async function mockCancelRunHandler(input) {
|
|
2613
|
-
const run = MOCK_RUNS.find((r) => r.id === input.runId);
|
|
2614
|
-
if (!run)
|
|
2615
|
-
throw new Error("RUN_NOT_FOUND");
|
|
2616
|
-
if (!["QUEUED", "IN_PROGRESS"].includes(run.status))
|
|
2617
|
-
throw new Error("RUN_NOT_CANCELLABLE");
|
|
2618
|
-
return { success: true, status: "CANCELLED" };
|
|
2619
|
-
}
|
|
2620
|
-
|
|
2621
|
-
// src/tool/tool.handler.ts
|
|
2622
|
-
var nextMockToolId = MOCK_TOOLS.length + 1;
|
|
2623
|
-
async function mockListToolsHandler(input) {
|
|
2624
|
-
const {
|
|
2625
|
-
organizationId,
|
|
2626
|
-
category,
|
|
2627
|
-
status,
|
|
2628
|
-
search,
|
|
2629
|
-
limit = 20,
|
|
2630
|
-
offset = 0
|
|
2631
|
-
} = input;
|
|
2632
|
-
let filtered = MOCK_TOOLS.filter((t) => t.organizationId === organizationId);
|
|
2633
|
-
if (category)
|
|
2634
|
-
filtered = filtered.filter((t) => t.category === category);
|
|
2635
|
-
if (status)
|
|
2636
|
-
filtered = filtered.filter((t) => t.status === status);
|
|
2637
|
-
if (search) {
|
|
2638
|
-
const q = search.toLowerCase();
|
|
2639
|
-
filtered = filtered.filter((t) => t.name.toLowerCase().includes(q) || t.description.toLowerCase().includes(q));
|
|
2640
|
-
}
|
|
2641
|
-
const total = filtered.length;
|
|
2642
|
-
const items = filtered.slice(offset, offset + limit).map((t) => ({
|
|
2643
|
-
id: t.id,
|
|
2644
|
-
name: t.name,
|
|
2645
|
-
slug: t.slug,
|
|
2646
|
-
description: t.description,
|
|
2647
|
-
category: t.category,
|
|
2648
|
-
status: t.status,
|
|
2649
|
-
version: t.version,
|
|
2650
|
-
createdAt: t.createdAt
|
|
2651
|
-
}));
|
|
2652
|
-
return { items, total, hasMore: offset + limit < total };
|
|
2653
|
-
}
|
|
2654
|
-
async function mockGetToolHandler(input) {
|
|
2655
|
-
const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
|
|
2656
|
-
if (!tool)
|
|
2657
|
-
throw new Error("TOOL_NOT_FOUND");
|
|
2658
|
-
return tool;
|
|
2659
|
-
}
|
|
2660
|
-
async function mockCreateToolHandler(input) {
|
|
2661
|
-
const exists = MOCK_TOOLS.some((t) => t.organizationId === input.organizationId && t.slug === input.slug);
|
|
2662
|
-
if (exists)
|
|
2663
|
-
throw new Error("SLUG_EXISTS");
|
|
2664
|
-
return {
|
|
2665
|
-
id: `tool-${nextMockToolId++}`,
|
|
2666
|
-
name: input.name,
|
|
2667
|
-
slug: input.slug,
|
|
2668
|
-
status: "DRAFT"
|
|
2669
|
-
};
|
|
2670
|
-
}
|
|
2671
|
-
async function mockUpdateToolHandler(input) {
|
|
2672
|
-
const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
|
|
2673
|
-
if (!tool)
|
|
2674
|
-
throw new Error("TOOL_NOT_FOUND");
|
|
2675
|
-
return {
|
|
2676
|
-
id: tool.id,
|
|
2677
|
-
name: input.name ?? tool.name,
|
|
2678
|
-
status: input.status ?? tool.status,
|
|
2679
|
-
updatedAt: new Date
|
|
2680
|
-
};
|
|
2681
|
-
}
|
|
2682
|
-
async function mockTestToolHandler(input) {
|
|
2683
|
-
const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
|
|
2684
|
-
if (!tool)
|
|
2685
|
-
throw new Error("TOOL_NOT_FOUND");
|
|
2686
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2687
|
-
return {
|
|
2688
|
-
success: true,
|
|
2689
|
-
output: { result: "Test successful", input: input.testInput },
|
|
2690
|
-
durationMs: 100
|
|
2691
|
-
};
|
|
2692
|
-
}
|
|
2693
|
-
// src/shared/demo-runtime-seed.ts
|
|
2694
|
-
var AGENT_CONSOLE_DEMO_ORGANIZATION_ID = "demo-org";
|
|
2695
|
-
var AGENT_CONSOLE_DEMO_PROJECT_ID = "agent-console-demo";
|
|
2696
|
-
function slugify(name) {
|
|
2697
|
-
return name.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
2698
|
-
}
|
|
2699
|
-
function cloneAgent(agent) {
|
|
2700
|
-
return { ...agent };
|
|
2701
|
-
}
|
|
2702
|
-
function cloneTool(tool) {
|
|
2703
|
-
return { ...tool };
|
|
2704
|
-
}
|
|
2705
|
-
function cloneRun(run) {
|
|
2706
|
-
return { ...run };
|
|
2707
|
-
}
|
|
2708
|
-
function createDefaultNow() {
|
|
2709
|
-
let tick = 0;
|
|
2710
|
-
const base = Date.parse("2026-03-20T09:00:00.000Z");
|
|
2711
|
-
return () => new Date(base + tick++ * 60000);
|
|
2712
|
-
}
|
|
2713
|
-
function normalizeProvider(provider) {
|
|
2714
|
-
return provider.toLowerCase();
|
|
2715
|
-
}
|
|
2716
|
-
function normalizeRunStatus(status) {
|
|
2717
|
-
return status === "IN_PROGRESS" ? "RUNNING" : status;
|
|
2718
|
-
}
|
|
2719
|
-
function createSeedState(projectId, organizationId) {
|
|
2720
|
-
const agents = MOCK_AGENTS.map((agent) => ({
|
|
2721
|
-
id: agent.id,
|
|
2722
|
-
projectId,
|
|
2723
|
-
organizationId,
|
|
2724
|
-
name: agent.name,
|
|
2725
|
-
slug: agent.slug,
|
|
2726
|
-
description: agent.description,
|
|
2727
|
-
modelProvider: normalizeProvider(agent.modelProvider),
|
|
2728
|
-
modelName: agent.modelName,
|
|
2729
|
-
systemPrompt: agent.systemPrompt,
|
|
2730
|
-
temperature: typeof agent.modelConfig?.temperature === "number" ? agent.modelConfig.temperature : 0.4,
|
|
2731
|
-
maxTokens: 8192,
|
|
2732
|
-
status: agent.status,
|
|
2733
|
-
createdAt: agent.createdAt,
|
|
2734
|
-
updatedAt: agent.updatedAt
|
|
2735
|
-
}));
|
|
2736
|
-
const tools = MOCK_TOOLS.map((tool) => ({
|
|
2737
|
-
id: tool.id,
|
|
2738
|
-
projectId,
|
|
2739
|
-
organizationId,
|
|
2740
|
-
name: tool.name,
|
|
2741
|
-
description: tool.description,
|
|
2742
|
-
version: tool.version,
|
|
2743
|
-
category: tool.category,
|
|
2744
|
-
status: tool.status,
|
|
2745
|
-
inputSchema: JSON.stringify(tool.parametersSchema),
|
|
2746
|
-
outputSchema: tool.outputSchema ? JSON.stringify(tool.outputSchema) : undefined,
|
|
2747
|
-
endpoint: typeof tool.implementationConfig?.url === "string" ? tool.implementationConfig.url : undefined,
|
|
2748
|
-
createdAt: tool.createdAt,
|
|
2749
|
-
updatedAt: tool.updatedAt
|
|
2750
|
-
}));
|
|
2751
|
-
const agentNames = new Map(agents.map((agent) => [agent.id, agent.name]));
|
|
2752
|
-
const runs = MOCK_RUNS.map((run) => ({
|
|
2753
|
-
id: run.id,
|
|
2754
|
-
projectId,
|
|
2755
|
-
agentId: run.agentId,
|
|
2756
|
-
agentName: agentNames.get(run.agentId) ?? run.agentName ?? "Unknown agent",
|
|
2757
|
-
status: normalizeRunStatus(run.status),
|
|
2758
|
-
input: JSON.stringify(run.input),
|
|
2759
|
-
output: run.output ? JSON.stringify(run.output) : undefined,
|
|
2760
|
-
totalTokens: run.totalTokens,
|
|
2761
|
-
promptTokens: run.promptTokens,
|
|
2762
|
-
completionTokens: run.completionTokens,
|
|
2763
|
-
estimatedCostUsd: run.estimatedCostUsd ?? 0,
|
|
2764
|
-
durationMs: run.durationMs,
|
|
2765
|
-
errorMessage: run.errorMessage,
|
|
2766
|
-
queuedAt: run.queuedAt,
|
|
2767
|
-
startedAt: run.startedAt,
|
|
2768
|
-
completedAt: run.completedAt
|
|
2769
|
-
}));
|
|
2770
|
-
return { agents, tools, runs };
|
|
2771
|
-
}
|
|
2772
|
-
function summarizeRunMetrics(runs) {
|
|
2773
|
-
const totalRuns = runs.length;
|
|
2774
|
-
const completedRuns = runs.filter((run) => run.status === "COMPLETED").length;
|
|
2775
|
-
const completedDurations = runs.map((run) => run.durationMs).filter((duration) => typeof duration === "number");
|
|
2776
|
-
return {
|
|
2777
|
-
totalRuns,
|
|
2778
|
-
successRate: totalRuns === 0 ? 0 : completedRuns / totalRuns,
|
|
2779
|
-
averageDurationMs: completedDurations.length === 0 ? 0 : Math.round(completedDurations.reduce((sum, duration) => sum + duration, 0) / completedDurations.length),
|
|
2780
|
-
totalTokens: runs.reduce((sum, run) => sum + run.totalTokens, 0),
|
|
2781
|
-
totalCostUsd: runs.reduce((sum, run) => sum + run.estimatedCostUsd, 0)
|
|
2782
|
-
};
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
// src/shared/demo-runtime.ts
|
|
2786
|
-
function createAgentConsoleDemoHandlers(options) {
|
|
2787
|
-
const projectId = options.projectId;
|
|
2788
|
-
const organizationId = options.organizationId ?? AGENT_CONSOLE_DEMO_ORGANIZATION_ID;
|
|
2789
|
-
const now = options.now ?? createDefaultNow();
|
|
2790
|
-
const state = createSeedState(projectId, organizationId);
|
|
2791
|
-
let agentIndex = state.agents.length + 1;
|
|
2792
|
-
let runIndex = state.runs.length + 1;
|
|
2793
|
-
const nextId = (kind) => {
|
|
2794
|
-
const nextIndex = kind === "agent" ? agentIndex++ : runIndex++;
|
|
2795
|
-
return options.idFactory?.(kind, nextIndex) ?? `${kind}-demo-${nextIndex}`;
|
|
2796
|
-
};
|
|
2797
|
-
return {
|
|
2798
|
-
async listAgents(input) {
|
|
2799
|
-
const filtered = state.agents.filter((agent) => agent.projectId === input.projectId).filter((agent) => !input.organizationId || agent.organizationId === input.organizationId).filter((agent) => !input.status || input.status === "all" || agent.status === input.status).filter((agent) => {
|
|
2800
|
-
if (!input.search)
|
|
2801
|
-
return true;
|
|
2802
|
-
const query = input.search.toLowerCase();
|
|
2803
|
-
return agent.name.toLowerCase().includes(query) || (agent.description ?? "").toLowerCase().includes(query);
|
|
2804
|
-
}).sort((left, right) => right.updatedAt.getTime() - left.updatedAt.getTime());
|
|
2805
|
-
const limit = input.limit ?? 20;
|
|
2806
|
-
const offset = input.offset ?? 0;
|
|
2807
|
-
const items = filtered.slice(offset, offset + limit).map(cloneAgent);
|
|
2808
|
-
return {
|
|
2809
|
-
items,
|
|
2810
|
-
total: filtered.length,
|
|
2811
|
-
hasMore: offset + items.length < filtered.length
|
|
2812
|
-
};
|
|
2813
|
-
},
|
|
2814
|
-
async getAgent(id) {
|
|
2815
|
-
const agent = state.agents.find((item) => item.id === id);
|
|
2816
|
-
return agent ? cloneAgent(agent) : null;
|
|
2817
|
-
},
|
|
2818
|
-
async createAgent(input, context) {
|
|
2819
|
-
const name = input.name.trim();
|
|
2820
|
-
const slug = slugify(name);
|
|
2821
|
-
const duplicate = state.agents.find((agent2) => agent2.projectId === context.projectId && agent2.organizationId === context.organizationId && (agent2.slug === slug || agent2.name.toLowerCase() === name.toLowerCase()));
|
|
2822
|
-
if (duplicate)
|
|
2823
|
-
throw new Error("AGENT_NAME_OR_SLUG_EXISTS");
|
|
2824
|
-
const timestamp = now();
|
|
2825
|
-
const agent = {
|
|
2826
|
-
id: nextId("agent"),
|
|
2827
|
-
projectId: context.projectId,
|
|
2828
|
-
organizationId: context.organizationId,
|
|
2829
|
-
name,
|
|
2830
|
-
slug,
|
|
2831
|
-
description: input.description,
|
|
2832
|
-
modelProvider: input.modelProvider ?? "openai",
|
|
2833
|
-
modelName: input.modelName ?? "gpt-5.4",
|
|
2834
|
-
systemPrompt: input.systemPrompt,
|
|
2835
|
-
temperature: input.temperature ?? 0.4,
|
|
2836
|
-
maxTokens: input.maxTokens ?? 8192,
|
|
2837
|
-
status: "DRAFT",
|
|
2838
|
-
createdAt: timestamp,
|
|
2839
|
-
updatedAt: timestamp
|
|
2840
|
-
};
|
|
2841
|
-
state.agents.unshift(agent);
|
|
2842
|
-
return cloneAgent(agent);
|
|
2843
|
-
},
|
|
2844
|
-
async updateAgent(input) {
|
|
2845
|
-
const agent = state.agents.find((item) => item.id === input.id);
|
|
2846
|
-
if (!agent)
|
|
2847
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
2848
|
-
const nextName = input.name;
|
|
2849
|
-
if (nextName && slugify(nextName) !== agent.slug) {
|
|
2850
|
-
const duplicate = state.agents.find((item) => item.id !== agent.id && item.projectId === agent.projectId && item.organizationId === agent.organizationId && (item.slug === slugify(nextName) || item.name.toLowerCase() === nextName.toLowerCase()));
|
|
2851
|
-
if (duplicate)
|
|
2852
|
-
throw new Error("AGENT_NAME_OR_SLUG_EXISTS");
|
|
2853
|
-
agent.slug = slugify(nextName);
|
|
2854
|
-
agent.name = nextName;
|
|
2855
|
-
}
|
|
2856
|
-
if (input.description !== undefined)
|
|
2857
|
-
agent.description = input.description;
|
|
2858
|
-
if (input.status)
|
|
2859
|
-
agent.status = input.status;
|
|
2860
|
-
agent.updatedAt = now();
|
|
2861
|
-
return cloneAgent(agent);
|
|
2862
|
-
},
|
|
2863
|
-
async executeAgent(input) {
|
|
2864
|
-
const agent = state.agents.find((item) => item.id === input.agentId);
|
|
2865
|
-
if (!agent)
|
|
2866
|
-
throw new Error("AGENT_NOT_FOUND");
|
|
2867
|
-
if (agent.status !== "ACTIVE")
|
|
2868
|
-
throw new Error("AGENT_NOT_ACTIVE");
|
|
2869
|
-
const queuedAt = now();
|
|
2870
|
-
const startedAt = now();
|
|
2871
|
-
const completedAt = now();
|
|
2872
|
-
const durationMs = 2200 + input.message.length * 12;
|
|
2873
|
-
const promptTokens = 600 + input.message.length * 3;
|
|
2874
|
-
const completionTokens = 240 + agent.name.length * 4;
|
|
2875
|
-
const run = {
|
|
2876
|
-
id: nextId("run"),
|
|
2877
|
-
projectId: input.context?.projectId ?? agent.projectId,
|
|
2878
|
-
agentId: agent.id,
|
|
2879
|
-
agentName: agent.name,
|
|
2880
|
-
status: "COMPLETED",
|
|
2881
|
-
input: input.message,
|
|
2882
|
-
output: `Deterministic demo reply from ${agent.name}: ${input.message}`,
|
|
2883
|
-
totalTokens: promptTokens + completionTokens,
|
|
2884
|
-
promptTokens,
|
|
2885
|
-
completionTokens,
|
|
2886
|
-
estimatedCostUsd: Number(((promptTokens + completionTokens) / 1e6).toFixed(4)),
|
|
2887
|
-
durationMs,
|
|
2888
|
-
queuedAt,
|
|
2889
|
-
startedAt,
|
|
2890
|
-
completedAt
|
|
2891
|
-
};
|
|
2892
|
-
state.runs.unshift(run);
|
|
2893
|
-
return cloneRun(run);
|
|
2894
|
-
},
|
|
2895
|
-
async listTools(input) {
|
|
2896
|
-
const filtered = state.tools.filter((tool) => tool.projectId === input.projectId).filter((tool) => !input.organizationId || tool.organizationId === input.organizationId).filter((tool) => !input.category || input.category === "all" || tool.category === input.category).filter((tool) => !input.status || input.status === "all" || tool.status === input.status).filter((tool) => {
|
|
2897
|
-
if (!input.search)
|
|
2898
|
-
return true;
|
|
2899
|
-
const query = input.search.toLowerCase();
|
|
2900
|
-
return tool.name.toLowerCase().includes(query) || (tool.description ?? "").toLowerCase().includes(query);
|
|
2901
|
-
}).sort((left, right) => left.name.localeCompare(right.name));
|
|
2902
|
-
const limit = input.limit ?? 50;
|
|
2903
|
-
const offset = input.offset ?? 0;
|
|
2904
|
-
const items = filtered.slice(offset, offset + limit).map(cloneTool);
|
|
2905
|
-
return {
|
|
2906
|
-
items,
|
|
2907
|
-
total: filtered.length,
|
|
2908
|
-
hasMore: offset + items.length < filtered.length
|
|
2909
|
-
};
|
|
2910
|
-
},
|
|
2911
|
-
async listRuns(input) {
|
|
2912
|
-
const filtered = state.runs.filter((run) => run.projectId === input.projectId).filter((run) => !input.agentId || run.agentId === input.agentId).filter((run) => !input.status || input.status === "all" || run.status === input.status).sort((left, right) => right.queuedAt.getTime() - left.queuedAt.getTime());
|
|
2913
|
-
const limit = input.limit ?? 20;
|
|
2914
|
-
const offset = input.offset ?? 0;
|
|
2915
|
-
const items = filtered.slice(offset, offset + limit).map(cloneRun);
|
|
2916
|
-
return {
|
|
2917
|
-
items,
|
|
2918
|
-
total: filtered.length,
|
|
2919
|
-
hasMore: offset + items.length < filtered.length
|
|
2920
|
-
};
|
|
2921
|
-
},
|
|
2922
|
-
async getRunMetrics(input) {
|
|
2923
|
-
const filtered = state.runs.filter((run) => {
|
|
2924
|
-
if (run.projectId !== input.projectId)
|
|
2925
|
-
return false;
|
|
2926
|
-
if (input.agentId && run.agentId !== input.agentId)
|
|
2927
|
-
return false;
|
|
2928
|
-
if (input.startDate && run.queuedAt < input.startDate)
|
|
2929
|
-
return false;
|
|
2930
|
-
if (input.endDate && run.queuedAt > input.endDate)
|
|
2931
|
-
return false;
|
|
2932
|
-
return true;
|
|
2933
|
-
});
|
|
2934
|
-
return summarizeRunMetrics(filtered);
|
|
2935
|
-
}
|
|
2936
|
-
};
|
|
2937
|
-
}
|
|
2938
|
-
export {
|
|
2939
|
-
mockListToolsHandler,
|
|
2940
|
-
mockListRunsHandler,
|
|
2941
|
-
mockListAgentsHandler,
|
|
2942
|
-
mockGetToolHandler,
|
|
2943
|
-
mockGetRunHandler,
|
|
2944
|
-
mockGetAgentHandler,
|
|
2945
|
-
mockExecuteAgentHandler,
|
|
2946
|
-
mockCreateToolHandler,
|
|
2947
|
-
mockCreateAgentHandler,
|
|
2948
|
-
createAgentHandlers,
|
|
2949
|
-
createAgentConsoleDemoHandlers
|
|
2950
|
-
};
|
|
12
|
+
FROM agent_run ${A}`,H)).rows[0],x=o?.totalRuns??0,$=o?.completedRuns??0;return{totalRuns:x,successRate:x>0?$/x:0,averageDurationMs:o?.avgDuration??0,totalTokens:o?.totalTokens??0,totalCostUsd:o?.totalCost??0}}async function D(I){let A=await g(I.agentId);if(!A)throw Error("AGENT_NOT_FOUND");if(A.status!=="ACTIVE")throw Error("AGENT_NOT_ACTIVE");let H=M0("run"),q=new Date().toISOString(),o=I.context?.projectId??A.projectId;await s.execute(`INSERT INTO agent_run (id, projectId, agentId, status, input, totalTokens, promptTokens, completionTokens, estimatedCostUsd, queuedAt)
|
|
13
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,[H,o,I.agentId,"QUEUED",I.message,0,0,0,0,q]);let x=(await s.query("SELECT r.*, a.name as agentName FROM agent_run r LEFT JOIN agent_definition a ON r.agentId = a.id WHERE r.id = ?",[H])).rows;if(!x[0])throw Error("Failed to retrieve created run");return f0(x[0],x[0].agentName)}return{listAgents:k,getAgent:g,createAgent:L,updateAgent:z,executeAgent:D,listTools:J,listRuns:P,getRunMetrics:F}}var i=[{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 qs=i.length+1;async function js(s){let{agentId:k,status:g,limit:L=20,offset:z=0}=s,J=[...i];if(k)J=J.filter((D)=>D.agentId===k);if(g)J=J.filter((D)=>D.status===g);let P=J.length;return{items:J.slice(z,z+L).map((D)=>{let I=N.find((A)=>A.id===D.agentId);return{id:D.id,agentId:D.agentId,agentName:I?.name??"Unknown",status:D.status,totalTokens:D.totalTokens,durationMs:D.durationMs,estimatedCostUsd:D.estimatedCostUsd,queuedAt:D.queuedAt,completedAt:D.completedAt}}),total:P,hasMore:z+L<P}}async function zs(s){let k=i.find((L)=>L.id===s.runId);if(!k)throw Error("RUN_NOT_FOUND");let g=N.find((L)=>L.id===k.agentId);return{...k,agent:g?{id:g.id,name:g.name,modelProvider:g.modelProvider,modelName:g.modelName}:void 0,steps:s.includeSteps?k.steps:void 0,logs:s.includeLogs?k.logs:void 0}}async function Vs(s){let k=N.find((g)=>g.id===s.agentId);if(!k)throw Error("AGENT_NOT_FOUND");if(k.status!=="ACTIVE")throw Error("AGENT_NOT_ACTIVE");return{runId:`run-${qs++}`,status:"QUEUED",estimatedWaitMs:500}}async function N2(s){let k=i.find((g)=>g.id===s.runId);if(!k)throw Error("RUN_NOT_FOUND");if(!["QUEUED","IN_PROGRESS"].includes(k.status))throw Error("RUN_NOT_CANCELLABLE");return{success:!0,status:"CANCELLED"}}var xs=Q.length+1;async function Ls(s){let{organizationId:k,category:g,status:L,search:z,limit:J=20,offset:P=0}=s,F=Q.filter((A)=>A.organizationId===k);if(g)F=F.filter((A)=>A.category===g);if(L)F=F.filter((A)=>A.status===L);if(z){let A=z.toLowerCase();F=F.filter((H)=>H.name.toLowerCase().includes(A)||H.description.toLowerCase().includes(A))}let D=F.length;return{items:F.slice(P,P+J).map((A)=>({id:A.id,name:A.name,slug:A.slug,description:A.description,category:A.category,status:A.status,version:A.version,createdAt:A.createdAt})),total:D,hasMore:P+J<D}}async function Bs(s){let k=Q.find((g)=>g.id===s.toolId);if(!k)throw Error("TOOL_NOT_FOUND");return k}async function Js(s){if(Q.some((g)=>g.organizationId===s.organizationId&&g.slug===s.slug))throw Error("SLUG_EXISTS");return{id:`tool-${xs++}`,name:s.name,slug:s.slug,status:"DRAFT"}}async function R2(s){let k=Q.find((g)=>g.id===s.toolId);if(!k)throw Error("TOOL_NOT_FOUND");return{id:k.id,name:s.name??k.name,status:s.status??k.status,updatedAt:new Date}}async function O2(s){if(!Q.find((g)=>g.id===s.toolId))throw Error("TOOL_NOT_FOUND");return await new Promise((g)=>setTimeout(g,100)),{success:!0,output:{result:"Test successful",input:s.testInput},durationMs:100}}var i0="demo-org",M2="agent-console-demo";function m(s){return s.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function e(s){return{...s}}function c0(s){return{...s}}function J0(s){return{...s}}function r0(){let s=0,k=Date.parse("2026-03-20T09:00:00.000Z");return()=>new Date(k+s++*60000)}function Ys(s){return s.toLowerCase()}function Fs(s){return s==="IN_PROGRESS"?"RUNNING":s}function T0(s,k){let g=N.map((P)=>({id:P.id,projectId:s,organizationId:k,name:P.name,slug:P.slug,description:P.description,modelProvider:Ys(P.modelProvider),modelName:P.modelName,systemPrompt:P.systemPrompt,temperature:typeof P.modelConfig?.temperature==="number"?P.modelConfig.temperature:0.4,maxTokens:8192,status:P.status,createdAt:P.createdAt,updatedAt:P.updatedAt})),L=Q.map((P)=>({id:P.id,projectId:s,organizationId:k,name:P.name,description:P.description,version:P.version,category:P.category,status:P.status,inputSchema:JSON.stringify(P.parametersSchema),outputSchema:P.outputSchema?JSON.stringify(P.outputSchema):void 0,endpoint:typeof P.implementationConfig?.url==="string"?P.implementationConfig.url:void 0,createdAt:P.createdAt,updatedAt:P.updatedAt})),z=new Map(g.map((P)=>[P.id,P.name])),J=i.map((P)=>({id:P.id,projectId:s,agentId:P.agentId,agentName:z.get(P.agentId)??P.agentName??"Unknown agent",status:Fs(P.status),input:JSON.stringify(P.input),output:P.output?JSON.stringify(P.output):void 0,totalTokens:P.totalTokens,promptTokens:P.promptTokens,completionTokens:P.completionTokens,estimatedCostUsd:P.estimatedCostUsd??0,durationMs:P.durationMs,errorMessage:P.errorMessage,queuedAt:P.queuedAt,startedAt:P.startedAt,completedAt:P.completedAt}));return{agents:g,tools:L,runs:J}}function y0(s){let k=s.length,g=s.filter((z)=>z.status==="COMPLETED").length,L=s.map((z)=>z.durationMs).filter((z)=>typeof z==="number");return{totalRuns:k,successRate:k===0?0:g/k,averageDurationMs:L.length===0?0:Math.round(L.reduce((z,J)=>z+J,0)/L.length),totalTokens:s.reduce((z,J)=>z+J.totalTokens,0),totalCostUsd:s.reduce((z,J)=>z+J.estimatedCostUsd,0)}}function Gs(s){let k=s.projectId,g=s.organizationId??i0,L=s.now??r0(),z=T0(k,g),J=z.agents.length+1,P=z.runs.length+1,F=(D)=>{let I=D==="agent"?J++:P++;return s.idFactory?.(D,I)??`${D}-demo-${I}`};return{async listAgents(D){let I=z.agents.filter((o)=>o.projectId===D.projectId).filter((o)=>!D.organizationId||o.organizationId===D.organizationId).filter((o)=>!D.status||D.status==="all"||o.status===D.status).filter((o)=>{if(!D.search)return!0;let x=D.search.toLowerCase();return o.name.toLowerCase().includes(x)||(o.description??"").toLowerCase().includes(x)}).sort((o,x)=>x.updatedAt.getTime()-o.updatedAt.getTime()),A=D.limit??20,H=D.offset??0,q=I.slice(H,H+A).map(e);return{items:q,total:I.length,hasMore:H+q.length<I.length}},async getAgent(D){let I=z.agents.find((A)=>A.id===D);return I?e(I):null},async createAgent(D,I){let A=D.name.trim(),H=m(A);if(z.agents.find(($)=>$.projectId===I.projectId&&$.organizationId===I.organizationId&&($.slug===H||$.name.toLowerCase()===A.toLowerCase())))throw Error("AGENT_NAME_OR_SLUG_EXISTS");let o=L(),x={id:F("agent"),projectId:I.projectId,organizationId:I.organizationId,name:A,slug:H,description:D.description,modelProvider:D.modelProvider??"openai",modelName:D.modelName??"gpt-5.4",systemPrompt:D.systemPrompt,temperature:D.temperature??0.4,maxTokens:D.maxTokens??8192,status:"DRAFT",createdAt:o,updatedAt:o};return z.agents.unshift(x),e(x)},async updateAgent(D){let I=z.agents.find((H)=>H.id===D.id);if(!I)throw Error("AGENT_NOT_FOUND");let A=D.name;if(A&&m(A)!==I.slug){if(z.agents.find((q)=>q.id!==I.id&&q.projectId===I.projectId&&q.organizationId===I.organizationId&&(q.slug===m(A)||q.name.toLowerCase()===A.toLowerCase())))throw Error("AGENT_NAME_OR_SLUG_EXISTS");I.slug=m(A),I.name=A}if(D.description!==void 0)I.description=D.description;if(D.status)I.status=D.status;return I.updatedAt=L(),e(I)},async executeAgent(D){let I=z.agents.find((G)=>G.id===D.agentId);if(!I)throw Error("AGENT_NOT_FOUND");if(I.status!=="ACTIVE")throw Error("AGENT_NOT_ACTIVE");let A=L(),H=L(),q=L(),o=2200+D.message.length*12,x=600+D.message.length*3,$=240+I.name.length*4,X={id:F("run"),projectId:D.context?.projectId??I.projectId,agentId:I.id,agentName:I.name,status:"COMPLETED",input:D.message,output:`Deterministic demo reply from ${I.name}: ${D.message}`,totalTokens:x+$,promptTokens:x,completionTokens:$,estimatedCostUsd:Number(((x+$)/1e6).toFixed(4)),durationMs:o,queuedAt:A,startedAt:H,completedAt:q};return z.runs.unshift(X),J0(X)},async listTools(D){let I=z.tools.filter((o)=>o.projectId===D.projectId).filter((o)=>!D.organizationId||o.organizationId===D.organizationId).filter((o)=>!D.category||D.category==="all"||o.category===D.category).filter((o)=>!D.status||D.status==="all"||o.status===D.status).filter((o)=>{if(!D.search)return!0;let x=D.search.toLowerCase();return o.name.toLowerCase().includes(x)||(o.description??"").toLowerCase().includes(x)}).sort((o,x)=>o.name.localeCompare(x.name)),A=D.limit??50,H=D.offset??0,q=I.slice(H,H+A).map(c0);return{items:q,total:I.length,hasMore:H+q.length<I.length}},async listRuns(D){let I=z.runs.filter((o)=>o.projectId===D.projectId).filter((o)=>!D.agentId||o.agentId===D.agentId).filter((o)=>!D.status||D.status==="all"||o.status===D.status).sort((o,x)=>x.queuedAt.getTime()-o.queuedAt.getTime()),A=D.limit??20,H=D.offset??0,q=I.slice(H,H+A).map(J0);return{items:q,total:I.length,hasMore:H+q.length<I.length}},async getRunMetrics(D){let I=z.runs.filter((A)=>{if(A.projectId!==D.projectId)return!1;if(D.agentId&&A.agentId!==D.agentId)return!1;if(D.startDate&&A.queuedAt<D.startDate)return!1;if(D.endDate&&A.queuedAt>D.endDate)return!1;return!0});return y0(I)}}}export{Ls as mockListToolsHandler,js as mockListRunsHandler,n0 as mockListAgentsHandler,Bs as mockGetToolHandler,zs as mockGetRunHandler,a0 as mockGetAgentHandler,Vs as mockExecuteAgentHandler,Js as mockCreateToolHandler,ss as mockCreateAgentHandler,G2 as createAgentHandlers,Gs as createAgentConsoleDemoHandlers};
|