@contractspec/example.agent-console 3.7.7 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +126 -105
- package/AGENTS.md +3 -1
- package/CHANGELOG.md +29 -0
- package/README.md +46 -9
- package/dist/agent/agent.handler.d.ts +3 -0
- package/dist/agent/agent.handler.js +730 -1
- package/dist/agent/index.js +73 -72
- package/dist/agent.feature.js +179 -0
- package/dist/browser/agent/agent.handler.js +730 -1
- package/dist/browser/agent/index.js +73 -72
- package/dist/browser/agent.feature.js +179 -0
- package/dist/browser/docs/agent-console.docblock.js +11 -8
- package/dist/browser/docs/index.js +11 -8
- package/dist/browser/example.js +2 -3
- package/dist/browser/handlers/agent.handlers.js +1883 -2
- package/dist/browser/handlers/index.js +2142 -8
- package/dist/browser/index.js +3347 -2433
- package/dist/browser/presentations/index.js +49 -49
- package/dist/browser/run/index.js +818 -812
- package/dist/browser/run/run.handler.js +666 -1
- package/dist/browser/shared/index.js +293 -1
- package/dist/browser/shared/mock-runs.js +5 -0
- package/dist/browser/tool/index.js +331 -331
- package/dist/browser/tool/tool.handler.js +479 -3
- package/dist/browser/ui/AgentDashboard.js +1204 -319
- package/dist/browser/ui/AgentDashboard.visualizations.js +217 -0
- package/dist/browser/ui/AgentRunList.js +359 -127
- package/dist/browser/ui/hooks/index.js +468 -18
- package/dist/browser/ui/hooks/useAgentMutations.js +443 -8
- package/dist/browser/ui/hooks/useRunList.js +25 -10
- package/dist/browser/ui/index.js +1293 -390
- package/dist/browser/ui/renderers/agent-list.markdown.js +14 -5
- package/dist/browser/ui/renderers/dashboard.markdown.js +207 -36
- package/dist/browser/ui/renderers/index.js +245 -49
- package/dist/browser/ui/renderers/run-list.markdown.js +9 -4
- package/dist/browser/ui/renderers/tool-registry.markdown.js +15 -4
- package/dist/browser/ui/views/RunDataTable.js +326 -0
- package/dist/browser/ui/views/RunListView.js +359 -127
- package/dist/browser/ui/views/index.js +406 -174
- package/dist/browser/ui/views/run-data-table.columns.js +271 -0
- package/dist/browser/ui/views/run-list.shared.js +177 -0
- package/dist/browser/visualizations/catalog.js +134 -0
- package/dist/browser/visualizations/index.js +187 -0
- package/dist/browser/visualizations/selectors.js +181 -0
- package/dist/docs/agent-console.docblock.js +11 -8
- package/dist/docs/index.js +11 -8
- package/dist/example.js +2 -3
- package/dist/example.test.d.ts +1 -0
- package/dist/handlers/agent.handlers.d.ts +2 -0
- package/dist/handlers/agent.handlers.js +1883 -2
- package/dist/handlers/index.d.ts +1 -3
- package/dist/handlers/index.js +2142 -8
- package/dist/handlers/mock-handlers.test.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3347 -2433
- package/dist/node/agent/agent.handler.js +730 -1
- package/dist/node/agent/index.js +73 -72
- package/dist/node/agent.feature.js +179 -0
- package/dist/node/docs/agent-console.docblock.js +11 -8
- package/dist/node/docs/index.js +11 -8
- package/dist/node/example.js +2 -3
- package/dist/node/handlers/agent.handlers.js +1883 -2
- package/dist/node/handlers/index.js +2142 -8
- package/dist/node/index.js +3347 -2433
- package/dist/node/presentations/index.js +49 -49
- package/dist/node/run/index.js +818 -812
- package/dist/node/run/run.handler.js +666 -1
- package/dist/node/shared/index.js +293 -1
- package/dist/node/shared/mock-runs.js +5 -0
- package/dist/node/tool/index.js +331 -331
- package/dist/node/tool/tool.handler.js +479 -3
- package/dist/node/ui/AgentDashboard.js +1204 -319
- package/dist/node/ui/AgentDashboard.visualizations.js +217 -0
- package/dist/node/ui/AgentRunList.js +359 -127
- package/dist/node/ui/hooks/index.js +468 -18
- package/dist/node/ui/hooks/useAgentMutations.js +443 -8
- package/dist/node/ui/hooks/useRunList.js +25 -10
- package/dist/node/ui/index.js +1293 -390
- package/dist/node/ui/renderers/agent-list.markdown.js +14 -5
- package/dist/node/ui/renderers/dashboard.markdown.js +207 -36
- package/dist/node/ui/renderers/index.js +245 -49
- package/dist/node/ui/renderers/run-list.markdown.js +9 -4
- package/dist/node/ui/renderers/tool-registry.markdown.js +15 -4
- package/dist/node/ui/views/RunDataTable.js +326 -0
- package/dist/node/ui/views/RunListView.js +359 -127
- package/dist/node/ui/views/index.js +406 -174
- package/dist/node/ui/views/run-data-table.columns.js +271 -0
- package/dist/node/ui/views/run-list.shared.js +177 -0
- package/dist/node/visualizations/catalog.js +134 -0
- package/dist/node/visualizations/index.js +187 -0
- package/dist/node/visualizations/selectors.js +181 -0
- package/dist/presentations/index.js +49 -49
- package/dist/proof/index.d.ts +2 -0
- package/dist/proof/meetup-proof.d.ts +10 -0
- package/dist/proof/meetup-proof.runtime.d.ts +22 -0
- package/dist/proof/meetup-proof.scenario.d.ts +2 -0
- package/dist/proof/meetup-proof.suite.d.ts +1 -0
- package/dist/proof/meetup-proof.test.d.ts +1 -0
- package/dist/run/index.js +818 -812
- package/dist/run/run.handler.d.ts +4 -0
- package/dist/run/run.handler.js +666 -1
- package/dist/shared/demo-dashboard-data.d.ts +16 -0
- package/dist/shared/demo-runtime-seed.d.ts +17 -0
- package/dist/shared/demo-runtime.d.ts +8 -0
- package/dist/shared/demo-runtime.test.d.ts +1 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.js +293 -1
- package/dist/shared/mock-runs.d.ts +4 -0
- package/dist/shared/mock-runs.js +5 -0
- package/dist/tool/index.js +331 -331
- package/dist/tool/tool.handler.d.ts +4 -1
- package/dist/tool/tool.handler.js +479 -3
- package/dist/ui/AgentDashboard.js +1204 -319
- package/dist/ui/AgentDashboard.sandbox.test.d.ts +1 -0
- package/dist/ui/AgentDashboard.visualizations.d.ts +4 -0
- package/dist/ui/AgentDashboard.visualizations.js +218 -0
- package/dist/ui/AgentRunList.js +359 -127
- package/dist/ui/hooks/index.js +468 -18
- package/dist/ui/hooks/useAgentMutations.js +443 -8
- package/dist/ui/hooks/useRunList.d.ts +8 -2
- package/dist/ui/hooks/useRunList.js +25 -10
- package/dist/ui/index.js +1293 -390
- package/dist/ui/renderers/agent-list.markdown.js +14 -5
- package/dist/ui/renderers/dashboard.markdown.js +207 -36
- package/dist/ui/renderers/index.js +245 -49
- package/dist/ui/renderers/run-list.markdown.js +9 -4
- package/dist/ui/renderers/tool-registry.markdown.d.ts +1 -1
- package/dist/ui/renderers/tool-registry.markdown.js +15 -4
- package/dist/ui/views/RunDataTable.d.ts +18 -0
- package/dist/ui/views/RunDataTable.js +327 -0
- package/dist/ui/views/RunListView.js +359 -127
- package/dist/ui/views/index.js +406 -174
- package/dist/ui/views/run-data-table.columns.d.ts +3 -0
- package/dist/ui/views/run-data-table.columns.js +272 -0
- package/dist/ui/views/run-list.shared.d.ts +14 -0
- package/dist/ui/views/run-list.shared.js +178 -0
- package/dist/visualizations/catalog.d.ts +10 -0
- package/dist/visualizations/catalog.js +135 -0
- package/dist/visualizations/index.d.ts +2 -0
- package/dist/visualizations/index.js +188 -0
- package/dist/visualizations/selectors.d.ts +3 -0
- package/dist/visualizations/selectors.js +182 -0
- package/dist/visualizations/selectors.test.d.ts +1 -0
- package/package.json +112 -10
- package/proofs/agent-console-meetup.replay.json +220 -0
- package/src/agent/agent.handler.ts +18 -1
- package/src/agent.feature.ts +3 -0
- package/src/docs/agent-console.docblock.ts +11 -8
- package/src/example.test.ts +75 -0
- package/src/example.ts +2 -3
- package/src/handlers/agent.handlers.ts +55 -2
- package/src/handlers/index.ts +18 -2
- package/src/handlers/mock-handlers.test.ts +77 -0
- package/src/index.ts +2 -0
- package/src/proof/index.ts +2 -0
- package/src/proof/meetup-proof.runtime.ts +196 -0
- package/src/proof/meetup-proof.scenario.ts +99 -0
- package/src/proof/meetup-proof.suite.ts +29 -0
- package/src/proof/meetup-proof.test.ts +28 -0
- package/src/proof/meetup-proof.ts +130 -0
- package/src/run/run.handler.ts +17 -1
- package/src/shared/demo-dashboard-data.ts +58 -0
- package/src/shared/demo-runtime-seed.ts +139 -0
- package/src/shared/demo-runtime.test.ts +169 -0
- package/src/shared/demo-runtime.ts +260 -0
- package/src/shared/index.ts +11 -0
- package/src/shared/mock-runs.ts +5 -0
- package/src/tool/tool.handler.ts +21 -4
- package/src/ui/AgentDashboard.sandbox.test.tsx +312 -0
- package/src/ui/AgentDashboard.tsx +4 -1
- package/src/ui/AgentDashboard.visualizations.tsx +35 -0
- package/src/ui/hooks/useAgentMutations.ts +19 -11
- package/src/ui/hooks/useRunList.ts +41 -9
- package/src/ui/renderers/agent-list.markdown.ts +31 -12
- package/src/ui/renderers/dashboard.markdown.ts +37 -42
- package/src/ui/renderers/run-list.markdown.ts +16 -8
- package/src/ui/renderers/tool-registry.markdown.ts +21 -9
- package/src/ui/views/RunDataTable.tsx +74 -0
- package/src/ui/views/RunListView.tsx +37 -111
- package/src/ui/views/run-data-table.columns.tsx +102 -0
- package/src/ui/views/run-list.shared.tsx +139 -0
- package/src/visualizations/catalog.ts +132 -0
- package/src/visualizations/index.ts +2 -0
- package/src/visualizations/selectors.test.ts +12 -0
- package/src/visualizations/selectors.ts +70 -0
- package/tsdown.config.js +17 -0
|
@@ -1,3 +1,135 @@
|
|
|
1
|
+
// src/agent/agent.enum.ts
|
|
2
|
+
import { defineEnum } from "@contractspec/lib.schema";
|
|
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
|
+
|
|
1
133
|
// src/shared/mock-agents.ts
|
|
2
134
|
var MOCK_AGENTS = [
|
|
3
135
|
{
|
|
@@ -222,7 +354,604 @@ var MOCK_TOOLS = [
|
|
|
222
354
|
}
|
|
223
355
|
];
|
|
224
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
|
+
|
|
225
953
|
// src/agent/agent.handler.ts
|
|
954
|
+
var nextMockAgentId = MOCK_AGENTS.length + 1;
|
|
226
955
|
async function mockListAgentsHandler(input) {
|
|
227
956
|
const {
|
|
228
957
|
organizationId,
|
|
@@ -276,7 +1005,7 @@ async function mockCreateAgentHandler(input) {
|
|
|
276
1005
|
if (exists)
|
|
277
1006
|
throw new Error("SLUG_EXISTS");
|
|
278
1007
|
return {
|
|
279
|
-
id: `agent-${
|
|
1008
|
+
id: `agent-${nextMockAgentId++}`,
|
|
280
1009
|
name: input.name,
|
|
281
1010
|
slug: input.slug,
|
|
282
1011
|
status: "DRAFT"
|
|
@@ -294,9 +1023,1152 @@ async function mockUpdateAgentHandler(input) {
|
|
|
294
1023
|
};
|
|
295
1024
|
}
|
|
296
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
|
+
|
|
297
2161
|
// src/handlers/agent.handlers.ts
|
|
298
2162
|
import { web } from "@contractspec/lib.runtime-sandbox";
|
|
299
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
|
+
};
|
|
300
2172
|
function rowToAgent(row) {
|
|
301
2173
|
return {
|
|
302
2174
|
id: row.id,
|
|
@@ -476,7 +2348,15 @@ function createAgentHandlers(db) {
|
|
|
476
2348
|
};
|
|
477
2349
|
}
|
|
478
2350
|
async function listRuns(input) {
|
|
479
|
-
const {
|
|
2351
|
+
const {
|
|
2352
|
+
projectId,
|
|
2353
|
+
agentId,
|
|
2354
|
+
status,
|
|
2355
|
+
sortBy,
|
|
2356
|
+
sortDirection = "desc",
|
|
2357
|
+
limit = 20,
|
|
2358
|
+
offset = 0
|
|
2359
|
+
} = input;
|
|
480
2360
|
let whereClause = "WHERE r.projectId = ?";
|
|
481
2361
|
const params = [projectId];
|
|
482
2362
|
if (agentId) {
|
|
@@ -489,11 +2369,13 @@ function createAgentHandlers(db) {
|
|
|
489
2369
|
}
|
|
490
2370
|
const countResult = (await db.query(`SELECT COUNT(*) as count FROM agent_run r ${whereClause}`, params)).rows;
|
|
491
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";
|
|
492
2374
|
const rows = (await db.query(`SELECT r.*, a.name as agentName
|
|
493
2375
|
FROM agent_run r
|
|
494
2376
|
LEFT JOIN agent_definition a ON r.agentId = a.id
|
|
495
2377
|
${whereClause}
|
|
496
|
-
ORDER BY r.queuedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
2378
|
+
ORDER BY ${sortColumn} ${direction}, r.queuedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
|
|
497
2379
|
return {
|
|
498
2380
|
items: rows.map((r) => rowToRun(r, r.agentName)),
|
|
499
2381
|
total,
|
|
@@ -566,6 +2448,7 @@ var MOCK_RUNS = [
|
|
|
566
2448
|
{
|
|
567
2449
|
id: "run-1",
|
|
568
2450
|
organizationId: "demo-org",
|
|
2451
|
+
projectId: "demo-project",
|
|
569
2452
|
agentId: "agent-1",
|
|
570
2453
|
agentName: "Customer Support Bot",
|
|
571
2454
|
userId: "user-1",
|
|
@@ -588,6 +2471,7 @@ var MOCK_RUNS = [
|
|
|
588
2471
|
{
|
|
589
2472
|
id: "run-2",
|
|
590
2473
|
organizationId: "demo-org",
|
|
2474
|
+
projectId: "demo-project",
|
|
591
2475
|
agentId: "agent-2",
|
|
592
2476
|
agentName: "Code Review Assistant",
|
|
593
2477
|
userId: "user-2",
|
|
@@ -605,6 +2489,7 @@ var MOCK_RUNS = [
|
|
|
605
2489
|
{
|
|
606
2490
|
id: "run-3",
|
|
607
2491
|
organizationId: "demo-org",
|
|
2492
|
+
projectId: "demo-project",
|
|
608
2493
|
agentId: "agent-1",
|
|
609
2494
|
agentName: "Customer Support Bot",
|
|
610
2495
|
userId: "user-1",
|
|
@@ -626,6 +2511,7 @@ var MOCK_RUNS = [
|
|
|
626
2511
|
{
|
|
627
2512
|
id: "run-4",
|
|
628
2513
|
organizationId: "demo-org",
|
|
2514
|
+
projectId: "demo-project",
|
|
629
2515
|
agentId: "agent-3",
|
|
630
2516
|
agentName: "Data Analyst",
|
|
631
2517
|
userId: "user-3",
|
|
@@ -647,6 +2533,7 @@ var MOCK_RUNS = [
|
|
|
647
2533
|
{
|
|
648
2534
|
id: "run-5",
|
|
649
2535
|
organizationId: "demo-org",
|
|
2536
|
+
projectId: "demo-project",
|
|
650
2537
|
agentId: "agent-2",
|
|
651
2538
|
agentName: "Code Review Assistant",
|
|
652
2539
|
userId: "user-2",
|
|
@@ -668,6 +2555,7 @@ var MOCK_RUNS = [
|
|
|
668
2555
|
];
|
|
669
2556
|
|
|
670
2557
|
// src/run/run.handler.ts
|
|
2558
|
+
var nextMockRunId = MOCK_RUNS.length + 1;
|
|
671
2559
|
async function mockListRunsHandler(input) {
|
|
672
2560
|
const { agentId, status, limit = 20, offset = 0 } = input;
|
|
673
2561
|
let filtered = [...MOCK_RUNS];
|
|
@@ -716,7 +2604,7 @@ async function mockExecuteAgentHandler(input) {
|
|
|
716
2604
|
if (agent.status !== "ACTIVE")
|
|
717
2605
|
throw new Error("AGENT_NOT_ACTIVE");
|
|
718
2606
|
return {
|
|
719
|
-
runId: `run-${
|
|
2607
|
+
runId: `run-${nextMockRunId++}`,
|
|
720
2608
|
status: "QUEUED",
|
|
721
2609
|
estimatedWaitMs: 500
|
|
722
2610
|
};
|
|
@@ -731,6 +2619,7 @@ async function mockCancelRunHandler(input) {
|
|
|
731
2619
|
}
|
|
732
2620
|
|
|
733
2621
|
// src/tool/tool.handler.ts
|
|
2622
|
+
var nextMockToolId = MOCK_TOOLS.length + 1;
|
|
734
2623
|
async function mockListToolsHandler(input) {
|
|
735
2624
|
const {
|
|
736
2625
|
organizationId,
|
|
@@ -773,7 +2662,7 @@ async function mockCreateToolHandler(input) {
|
|
|
773
2662
|
if (exists)
|
|
774
2663
|
throw new Error("SLUG_EXISTS");
|
|
775
2664
|
return {
|
|
776
|
-
id: `tool-${
|
|
2665
|
+
id: `tool-${nextMockToolId++}`,
|
|
777
2666
|
name: input.name,
|
|
778
2667
|
slug: input.slug,
|
|
779
2668
|
status: "DRAFT"
|
|
@@ -794,12 +2683,256 @@ async function mockTestToolHandler(input) {
|
|
|
794
2683
|
const tool = MOCK_TOOLS.find((t) => t.id === input.toolId);
|
|
795
2684
|
if (!tool)
|
|
796
2685
|
throw new Error("TOOL_NOT_FOUND");
|
|
797
|
-
const startTime = Date.now();
|
|
798
2686
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
799
2687
|
return {
|
|
800
2688
|
success: true,
|
|
801
2689
|
output: { result: "Test successful", input: input.testInput },
|
|
802
|
-
durationMs:
|
|
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
|
+
}
|
|
803
2936
|
};
|
|
804
2937
|
}
|
|
805
2938
|
export {
|
|
@@ -812,5 +2945,6 @@ export {
|
|
|
812
2945
|
mockExecuteAgentHandler,
|
|
813
2946
|
mockCreateToolHandler,
|
|
814
2947
|
mockCreateAgentHandler,
|
|
815
|
-
createAgentHandlers
|
|
2948
|
+
createAgentHandlers,
|
|
2949
|
+
createAgentConsoleDemoHandlers
|
|
816
2950
|
};
|