@contractspec/example.agent-console 3.7.6 → 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 +52 -31
- package/CHANGELOG.md +29 -0
- package/README.md +112 -83
- package/dist/agent/agent.event.js +1 -1
- package/dist/agent/agent.handler.d.ts +3 -0
- package/dist/agent/agent.handler.js +730 -1
- package/dist/agent/agent.operation.js +1 -1
- package/dist/agent/index.d.ts +5 -5
- package/dist/agent/index.js +74 -73
- package/dist/agent.feature.js +179 -0
- package/dist/browser/agent/agent.event.js +1 -1
- package/dist/browser/agent/agent.handler.js +730 -1
- package/dist/browser/agent/agent.operation.js +1 -1
- package/dist/browser/agent/index.js +74 -73
- 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 +4075 -3161
- package/dist/browser/presentations/index.js +51 -51
- package/dist/browser/run/index.js +380 -374
- package/dist/browser/run/run.event.js +2 -2
- package/dist/browser/run/run.handler.js +666 -1
- package/dist/browser/run/run.presentation.js +2 -2
- package/dist/browser/shared/index.js +293 -1
- package/dist/browser/shared/mock-runs.js +5 -0
- package/dist/browser/tool/index.js +161 -161
- package/dist/browser/tool/tool.event.js +1 -1
- package/dist/browser/tool/tool.handler.js +479 -3
- package/dist/browser/tool/tool.presentation.js +2 -2
- package/dist/browser/ui/AgentDashboard.js +1816 -931
- package/dist/browser/ui/AgentDashboard.visualizations.js +217 -0
- package/dist/browser/ui/AgentRunList.js +360 -128
- package/dist/browser/ui/AgentToolRegistry.js +9 -9
- package/dist/browser/ui/hooks/index.js +611 -161
- package/dist/browser/ui/hooks/useAgentList.js +1 -1
- package/dist/browser/ui/hooks/useAgentMutations.js +444 -9
- package/dist/browser/ui/hooks/useRunList.js +26 -11
- package/dist/browser/ui/hooks/useToolList.js +1 -1
- package/dist/browser/ui/index.js +2161 -1258
- package/dist/browser/ui/modals/AgentActionsModal.js +13 -13
- package/dist/browser/ui/modals/CreateAgentModal.js +15 -15
- package/dist/browser/ui/modals/index.js +297 -297
- package/dist/browser/ui/renderers/agent-list.markdown.js +14 -5
- package/dist/browser/ui/renderers/agent-list.renderer.js +7 -7
- package/dist/browser/ui/renderers/dashboard.markdown.js +207 -36
- package/dist/browser/ui/renderers/index.js +359 -163
- 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/AgentListView.js +7 -7
- package/dist/browser/ui/views/RunDataTable.js +326 -0
- package/dist/browser/ui/views/RunListView.js +360 -128
- package/dist/browser/ui/views/ToolRegistryView.js +9 -9
- package/dist/browser/ui/views/index.js +478 -246
- 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 +2 -4
- package/dist/handlers/index.js +2142 -8
- package/dist/handlers/mock-handlers.test.d.ts +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4075 -3161
- package/dist/node/agent/agent.event.js +1 -1
- package/dist/node/agent/agent.handler.js +730 -1
- package/dist/node/agent/agent.operation.js +1 -1
- package/dist/node/agent/index.js +74 -73
- 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 +4075 -3161
- package/dist/node/presentations/index.js +51 -51
- package/dist/node/run/index.js +380 -374
- package/dist/node/run/run.event.js +2 -2
- package/dist/node/run/run.handler.js +666 -1
- package/dist/node/run/run.presentation.js +2 -2
- package/dist/node/shared/index.js +293 -1
- package/dist/node/shared/mock-runs.js +5 -0
- package/dist/node/tool/index.js +161 -161
- package/dist/node/tool/tool.event.js +1 -1
- package/dist/node/tool/tool.handler.js +479 -3
- package/dist/node/tool/tool.presentation.js +2 -2
- package/dist/node/ui/AgentDashboard.js +1816 -931
- package/dist/node/ui/AgentDashboard.visualizations.js +217 -0
- package/dist/node/ui/AgentRunList.js +360 -128
- package/dist/node/ui/AgentToolRegistry.js +9 -9
- package/dist/node/ui/hooks/index.js +611 -161
- package/dist/node/ui/hooks/useAgentList.js +1 -1
- package/dist/node/ui/hooks/useAgentMutations.js +444 -9
- package/dist/node/ui/hooks/useRunList.js +26 -11
- package/dist/node/ui/hooks/useToolList.js +1 -1
- package/dist/node/ui/index.js +2161 -1258
- package/dist/node/ui/modals/AgentActionsModal.js +13 -13
- package/dist/node/ui/modals/CreateAgentModal.js +15 -15
- package/dist/node/ui/modals/index.js +297 -297
- package/dist/node/ui/renderers/agent-list.markdown.js +14 -5
- package/dist/node/ui/renderers/agent-list.renderer.js +7 -7
- package/dist/node/ui/renderers/dashboard.markdown.js +207 -36
- package/dist/node/ui/renderers/index.js +359 -163
- 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/AgentListView.js +7 -7
- package/dist/node/ui/views/RunDataTable.js +326 -0
- package/dist/node/ui/views/RunListView.js +360 -128
- package/dist/node/ui/views/ToolRegistryView.js +9 -9
- package/dist/node/ui/views/index.js +478 -246
- 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.d.ts +3 -5
- package/dist/presentations/index.js +51 -51
- 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.d.ts +7 -7
- package/dist/run/index.js +380 -374
- package/dist/run/run.event.js +2 -2
- package/dist/run/run.handler.d.ts +7 -0
- package/dist/run/run.handler.js +666 -1
- package/dist/run/run.presentation.js +2 -2
- 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 +4 -1
- 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.d.ts +7 -7
- package/dist/tool/index.js +161 -161
- package/dist/tool/tool.event.js +1 -1
- package/dist/tool/tool.handler.d.ts +3 -0
- package/dist/tool/tool.handler.js +479 -3
- package/dist/tool/tool.presentation.js +2 -2
- package/dist/ui/AgentDashboard.js +1816 -931
- 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 +360 -128
- package/dist/ui/AgentToolRegistry.js +9 -9
- package/dist/ui/hooks/index.d.ts +4 -4
- package/dist/ui/hooks/index.js +611 -161
- package/dist/ui/hooks/useAgentList.d.ts +5 -0
- package/dist/ui/hooks/useAgentList.js +1 -1
- package/dist/ui/hooks/useAgentMutations.d.ts +9 -2
- package/dist/ui/hooks/useAgentMutations.js +444 -9
- package/dist/ui/hooks/useRunList.d.ts +13 -2
- package/dist/ui/hooks/useRunList.js +26 -11
- package/dist/ui/hooks/useToolList.d.ts +5 -0
- package/dist/ui/hooks/useToolList.js +1 -1
- package/dist/ui/index.d.ts +3 -3
- package/dist/ui/index.js +2161 -1258
- package/dist/ui/modals/AgentActionsModal.js +13 -13
- package/dist/ui/modals/CreateAgentModal.js +15 -15
- package/dist/ui/modals/index.d.ts +1 -1
- package/dist/ui/modals/index.js +297 -297
- package/dist/ui/renderers/agent-list.markdown.d.ts +5 -0
- package/dist/ui/renderers/agent-list.markdown.js +14 -5
- package/dist/ui/renderers/agent-list.renderer.js +7 -7
- package/dist/ui/renderers/dashboard.markdown.d.ts +5 -0
- package/dist/ui/renderers/dashboard.markdown.js +207 -36
- package/dist/ui/renderers/index.d.ts +2 -2
- package/dist/ui/renderers/index.js +359 -163
- package/dist/ui/renderers/run-list.markdown.d.ts +5 -0
- package/dist/ui/renderers/run-list.markdown.js +9 -4
- package/dist/ui/renderers/tool-registry.markdown.d.ts +6 -1
- package/dist/ui/renderers/tool-registry.markdown.js +15 -4
- package/dist/ui/views/AgentListView.js +7 -7
- package/dist/ui/views/RunDataTable.d.ts +18 -0
- package/dist/ui/views/RunDataTable.js +327 -0
- package/dist/ui/views/RunListView.js +360 -128
- package/dist/ui/views/ToolRegistryView.js +9 -9
- package/dist/ui/views/index.js +478 -246
- 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 +114 -12
- package/proofs/agent-console-meetup.replay.json +220 -0
- package/src/agent/agent.entity.ts +111 -111
- package/src/agent/agent.enum.ts +12 -12
- package/src/agent/agent.event.ts +91 -91
- package/src/agent/agent.handler.ts +144 -127
- package/src/agent/agent.operation.ts +400 -400
- package/src/agent/agent.presentation.ts +62 -62
- package/src/agent/agent.schema.ts +175 -175
- package/src/agent/agent.test-spec.ts +48 -48
- package/src/agent/index.ts +46 -51
- package/src/agent.capability.ts +11 -11
- package/src/agent.feature.ts +134 -131
- package/src/docs/agent-console.docblock.ts +52 -49
- package/src/example.test.ts +75 -0
- package/src/example.ts +34 -35
- package/src/handlers/agent.handlers.ts +576 -522
- package/src/handlers/index.ts +30 -14
- package/src/handlers/mock-handlers.test.ts +77 -0
- package/src/index.ts +10 -9
- package/src/presentations/index.ts +11 -13
- 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/index.ts +49 -54
- package/src/run/run.entity.ts +137 -137
- package/src/run/run.enum.ts +18 -18
- package/src/run/run.event.ts +174 -174
- package/src/run/run.handler.ts +113 -96
- package/src/run/run.operation.ts +474 -474
- package/src/run/run.presentation.ts +42 -42
- package/src/run/run.schema.ts +126 -126
- package/src/run/run.test-spec.ts +48 -48
- package/src/seeders/index.ts +21 -21
- 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 +12 -1
- package/src/shared/mock-agents.ts +76 -76
- package/src/shared/mock-runs.ts +107 -102
- package/src/shared/mock-tools.ts +140 -140
- package/src/shared/overlay-types.ts +23 -23
- package/src/tool/index.ts +39 -44
- package/src/tool/tool.entity.ts +73 -73
- package/src/tool/tool.enum.ts +13 -13
- package/src/tool/tool.event.ts +80 -80
- package/src/tool/tool.handler.ts +124 -107
- package/src/tool/tool.operation.ts +328 -328
- package/src/tool/tool.presentation.ts +43 -43
- package/src/tool/tool.schema.ts +106 -106
- package/src/tool/tool.test-spec.ts +48 -48
- package/src/ui/AgentDashboard.sandbox.test.tsx +312 -0
- package/src/ui/AgentDashboard.tsx +351 -348
- package/src/ui/AgentDashboard.visualizations.tsx +35 -0
- package/src/ui/hooks/index.ts +7 -7
- package/src/ui/hooks/useAgentList.ts +57 -56
- package/src/ui/hooks/useAgentMutations.ts +168 -159
- package/src/ui/hooks/useRunList.ts +90 -57
- package/src/ui/hooks/useToolList.ts +102 -101
- package/src/ui/index.ts +6 -9
- package/src/ui/modals/AgentActionsModal.tsx +262 -262
- package/src/ui/modals/CreateAgentModal.tsx +232 -232
- package/src/ui/modals/index.ts +1 -1
- package/src/ui/overlays/demo-overlays.ts +52 -52
- package/src/ui/renderers/agent-list.markdown.ts +81 -61
- package/src/ui/renderers/agent-list.renderer.tsx +14 -14
- package/src/ui/renderers/dashboard.markdown.ts +135 -139
- package/src/ui/renderers/index.ts +3 -4
- package/src/ui/renderers/run-list.markdown.ts +56 -47
- package/src/ui/renderers/tool-registry.markdown.ts +79 -66
- package/src/ui/views/AgentListView.tsx +90 -90
- package/src/ui/views/RunDataTable.tsx +74 -0
- package/src/ui/views/RunListView.tsx +84 -158
- package/src/ui/views/ToolRegistryView.tsx +113 -113
- 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/tsconfig.json +7 -8
- package/tsdown.config.js +24 -3
|
@@ -1,150 +1,349 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
1
|
+
// src/shared/mock-agents.ts
|
|
2
|
+
var MOCK_AGENTS = [
|
|
3
|
+
{
|
|
4
|
+
id: "agent-1",
|
|
5
|
+
organizationId: "demo-org",
|
|
6
|
+
name: "Customer Support Bot",
|
|
7
|
+
slug: "customer-support-bot",
|
|
8
|
+
description: "Handles tier-1 customer inquiries and routes complex issues.",
|
|
9
|
+
status: "ACTIVE",
|
|
10
|
+
modelProvider: "OPENAI",
|
|
11
|
+
modelName: "gpt-4o-mini",
|
|
12
|
+
modelConfig: { temperature: 0.7 },
|
|
13
|
+
systemPrompt: "You are a helpful customer support assistant.",
|
|
14
|
+
toolChoice: "auto",
|
|
15
|
+
maxIterations: 10,
|
|
16
|
+
timeoutMs: 120000,
|
|
17
|
+
version: "1.0.0",
|
|
18
|
+
tags: ["support", "tier-1"],
|
|
19
|
+
createdAt: new Date("2024-01-15T10:00:00Z"),
|
|
20
|
+
updatedAt: new Date("2024-03-20T14:30:00Z")
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "agent-2",
|
|
24
|
+
organizationId: "demo-org",
|
|
25
|
+
name: "Code Review Assistant",
|
|
26
|
+
slug: "code-review-assistant",
|
|
27
|
+
description: "Reviews pull requests and provides actionable feedback.",
|
|
28
|
+
status: "ACTIVE",
|
|
29
|
+
modelProvider: "ANTHROPIC",
|
|
30
|
+
modelName: "claude-sonnet-4-20250514",
|
|
31
|
+
modelConfig: { temperature: 0.3 },
|
|
32
|
+
systemPrompt: "You are a code review expert.",
|
|
33
|
+
toolChoice: "auto",
|
|
34
|
+
maxIterations: 15,
|
|
35
|
+
timeoutMs: 180000,
|
|
36
|
+
version: "2.1.0",
|
|
37
|
+
tags: ["code", "review", "dev"],
|
|
38
|
+
createdAt: new Date("2024-02-10T09:00:00Z"),
|
|
39
|
+
updatedAt: new Date("2024-04-05T11:15:00Z")
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "agent-3",
|
|
43
|
+
organizationId: "demo-org",
|
|
44
|
+
name: "Data Analyst",
|
|
45
|
+
slug: "data-analyst",
|
|
46
|
+
description: "Queries databases and generates insights from data.",
|
|
47
|
+
status: "PAUSED",
|
|
48
|
+
modelProvider: "OPENAI",
|
|
49
|
+
modelName: "gpt-4o",
|
|
50
|
+
modelConfig: { temperature: 0.5 },
|
|
51
|
+
systemPrompt: "You are a data analyst expert in SQL and analytics.",
|
|
52
|
+
toolChoice: "required",
|
|
53
|
+
maxIterations: 20,
|
|
54
|
+
timeoutMs: 300000,
|
|
55
|
+
version: "1.2.0",
|
|
56
|
+
tags: ["data", "analytics", "sql"],
|
|
57
|
+
createdAt: new Date("2024-03-01T08:00:00Z"),
|
|
58
|
+
updatedAt: new Date("2024-04-10T16:45:00Z")
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "agent-4",
|
|
62
|
+
organizationId: "demo-org",
|
|
63
|
+
name: "Meeting Scheduler",
|
|
64
|
+
slug: "meeting-scheduler",
|
|
65
|
+
description: "Schedules meetings and manages calendar conflicts.",
|
|
66
|
+
status: "DRAFT",
|
|
67
|
+
modelProvider: "GOOGLE",
|
|
68
|
+
modelName: "gemini-2.0-flash",
|
|
69
|
+
modelConfig: { temperature: 0.2 },
|
|
70
|
+
systemPrompt: "You help schedule and organize meetings efficiently.",
|
|
71
|
+
toolChoice: "auto",
|
|
72
|
+
maxIterations: 5,
|
|
73
|
+
timeoutMs: 60000,
|
|
74
|
+
version: "0.1.0",
|
|
75
|
+
tags: ["calendar", "scheduling"],
|
|
76
|
+
createdAt: new Date("2024-04-01T12:00:00Z"),
|
|
77
|
+
updatedAt: new Date("2024-04-01T12:00:00Z")
|
|
78
|
+
}
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
// src/shared/mock-tools.ts
|
|
82
|
+
var MOCK_TOOLS = [
|
|
83
|
+
{
|
|
84
|
+
id: "tool-1",
|
|
85
|
+
organizationId: "demo-org",
|
|
86
|
+
name: "Web Search",
|
|
87
|
+
slug: "web-search",
|
|
88
|
+
description: "Search the web for real-time information using Brave API.",
|
|
89
|
+
category: "RETRIEVAL",
|
|
90
|
+
status: "ACTIVE",
|
|
91
|
+
parametersSchema: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
query: { type: "string", description: "Search query" },
|
|
95
|
+
numResults: { type: "number", default: 10 }
|
|
96
|
+
},
|
|
97
|
+
required: ["query"]
|
|
98
|
+
},
|
|
99
|
+
outputSchema: { type: "array", items: { type: "object" } },
|
|
100
|
+
implementationType: "http",
|
|
101
|
+
implementationConfig: {
|
|
102
|
+
url: "https://api.brave.com/search",
|
|
103
|
+
method: "GET"
|
|
104
|
+
},
|
|
105
|
+
maxInvocationsPerMinute: 60,
|
|
106
|
+
timeoutMs: 30000,
|
|
107
|
+
version: "1.0.0",
|
|
108
|
+
tags: ["search", "web"],
|
|
109
|
+
createdAt: new Date("2024-01-01T00:00:00Z"),
|
|
110
|
+
updatedAt: new Date("2024-02-15T10:00:00Z")
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: "tool-2",
|
|
114
|
+
organizationId: "demo-org",
|
|
115
|
+
name: "SQL Query",
|
|
116
|
+
slug: "sql-query",
|
|
117
|
+
description: "Execute read-only SQL queries against the data warehouse.",
|
|
118
|
+
category: "RETRIEVAL",
|
|
119
|
+
status: "ACTIVE",
|
|
120
|
+
parametersSchema: {
|
|
121
|
+
type: "object",
|
|
122
|
+
properties: {
|
|
123
|
+
query: { type: "string", description: "SQL query" },
|
|
124
|
+
maxRows: { type: "number", default: 100 }
|
|
125
|
+
},
|
|
126
|
+
required: ["query"]
|
|
127
|
+
},
|
|
128
|
+
outputSchema: { type: "object" },
|
|
129
|
+
implementationType: "function",
|
|
130
|
+
implementationConfig: { handler: "executeSqlQuery" },
|
|
131
|
+
maxInvocationsPerMinute: 30,
|
|
132
|
+
timeoutMs: 60000,
|
|
133
|
+
version: "1.1.0",
|
|
134
|
+
tags: ["sql", "database"],
|
|
135
|
+
createdAt: new Date("2024-01-05T00:00:00Z"),
|
|
136
|
+
updatedAt: new Date("2024-03-10T14:00:00Z")
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "tool-3",
|
|
140
|
+
organizationId: "demo-org",
|
|
141
|
+
name: "Email Sender",
|
|
142
|
+
slug: "email-sender",
|
|
143
|
+
description: "Send emails via SMTP or API.",
|
|
144
|
+
category: "COMMUNICATION",
|
|
145
|
+
status: "ACTIVE",
|
|
146
|
+
parametersSchema: {
|
|
147
|
+
type: "object",
|
|
148
|
+
properties: {
|
|
149
|
+
to: { type: "string" },
|
|
150
|
+
subject: { type: "string" },
|
|
151
|
+
body: { type: "string" }
|
|
152
|
+
},
|
|
153
|
+
required: ["to", "subject", "body"]
|
|
154
|
+
},
|
|
155
|
+
implementationType: "http",
|
|
156
|
+
implementationConfig: { url: "/api/send-email", method: "POST" },
|
|
157
|
+
maxInvocationsPerMinute: 10,
|
|
158
|
+
timeoutMs: 30000,
|
|
159
|
+
version: "1.0.0",
|
|
160
|
+
tags: ["email", "communication"],
|
|
161
|
+
createdAt: new Date("2024-02-01T00:00:00Z"),
|
|
162
|
+
updatedAt: new Date("2024-02-01T00:00:00Z")
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "tool-4",
|
|
166
|
+
organizationId: "demo-org",
|
|
167
|
+
name: "GitHub Integration",
|
|
168
|
+
slug: "github-integration",
|
|
169
|
+
description: "Interact with GitHub repositories, PRs, and issues.",
|
|
170
|
+
category: "INTEGRATION",
|
|
171
|
+
status: "ACTIVE",
|
|
172
|
+
parametersSchema: {
|
|
173
|
+
type: "object",
|
|
174
|
+
properties: {
|
|
175
|
+
action: {
|
|
176
|
+
type: "string",
|
|
177
|
+
enum: ["list_prs", "get_pr", "create_comment"]
|
|
178
|
+
},
|
|
179
|
+
repo: { type: "string" },
|
|
180
|
+
params: { type: "object" }
|
|
181
|
+
},
|
|
182
|
+
required: ["action", "repo"]
|
|
183
|
+
},
|
|
184
|
+
implementationType: "http",
|
|
185
|
+
implementationConfig: { url: "https://api.github.com", auth: "token" },
|
|
186
|
+
maxInvocationsPerMinute: 100,
|
|
187
|
+
timeoutMs: 15000,
|
|
188
|
+
version: "2.0.0",
|
|
189
|
+
tags: ["github", "integration", "code"],
|
|
190
|
+
createdAt: new Date("2024-02-20T00:00:00Z"),
|
|
191
|
+
updatedAt: new Date("2024-04-01T09:00:00Z")
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: "tool-5",
|
|
195
|
+
organizationId: "demo-org",
|
|
196
|
+
name: "Calculator",
|
|
197
|
+
slug: "calculator",
|
|
198
|
+
description: "Perform mathematical calculations.",
|
|
199
|
+
category: "COMPUTATION",
|
|
200
|
+
status: "ACTIVE",
|
|
201
|
+
parametersSchema: {
|
|
202
|
+
type: "object",
|
|
203
|
+
properties: {
|
|
204
|
+
expression: {
|
|
205
|
+
type: "string",
|
|
206
|
+
description: "Math expression to evaluate"
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
required: ["expression"]
|
|
210
|
+
},
|
|
211
|
+
outputSchema: {
|
|
212
|
+
type: "object",
|
|
213
|
+
properties: { result: { type: "number" } }
|
|
214
|
+
},
|
|
215
|
+
implementationType: "function",
|
|
216
|
+
implementationConfig: { handler: "evaluateMath" },
|
|
217
|
+
timeoutMs: 5000,
|
|
218
|
+
version: "1.0.0",
|
|
219
|
+
tags: ["math", "utility"],
|
|
220
|
+
createdAt: new Date("2024-01-10T00:00:00Z"),
|
|
221
|
+
updatedAt: new Date("2024-01-10T00:00:00Z")
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
|
|
225
|
+
// src/shared/mock-runs.ts
|
|
226
|
+
var MOCK_RUNS = [
|
|
227
|
+
{
|
|
228
|
+
id: "run-1",
|
|
229
|
+
organizationId: "demo-org",
|
|
230
|
+
projectId: "demo-project",
|
|
231
|
+
agentId: "agent-1",
|
|
232
|
+
agentName: "Customer Support Bot",
|
|
233
|
+
userId: "user-1",
|
|
234
|
+
sessionId: "session-1",
|
|
235
|
+
input: { message: "How do I reset my password?", context: {} },
|
|
236
|
+
output: { response: "You can reset your password by clicking..." },
|
|
237
|
+
status: "COMPLETED",
|
|
238
|
+
totalTokens: 1250,
|
|
239
|
+
promptTokens: 800,
|
|
240
|
+
completionTokens: 450,
|
|
241
|
+
totalIterations: 3,
|
|
242
|
+
durationMs: 4500,
|
|
243
|
+
estimatedCostUsd: 0.0025,
|
|
244
|
+
queuedAt: new Date("2024-04-15T10:00:00Z"),
|
|
245
|
+
startedAt: new Date("2024-04-15T10:00:01Z"),
|
|
246
|
+
completedAt: new Date("2024-04-15T10:00:05Z"),
|
|
247
|
+
steps: [],
|
|
248
|
+
logs: []
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: "run-2",
|
|
252
|
+
organizationId: "demo-org",
|
|
253
|
+
projectId: "demo-project",
|
|
254
|
+
agentId: "agent-2",
|
|
255
|
+
agentName: "Code Review Assistant",
|
|
256
|
+
userId: "user-2",
|
|
257
|
+
input: { message: "Review PR #123", context: { prNumber: 123 } },
|
|
258
|
+
status: "IN_PROGRESS",
|
|
259
|
+
totalTokens: 3500,
|
|
260
|
+
promptTokens: 3000,
|
|
261
|
+
completionTokens: 500,
|
|
262
|
+
totalIterations: 5,
|
|
263
|
+
queuedAt: new Date("2024-04-15T10:30:00Z"),
|
|
264
|
+
startedAt: new Date("2024-04-15T10:30:02Z"),
|
|
265
|
+
steps: [],
|
|
266
|
+
logs: []
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: "run-3",
|
|
270
|
+
organizationId: "demo-org",
|
|
271
|
+
projectId: "demo-project",
|
|
272
|
+
agentId: "agent-1",
|
|
273
|
+
agentName: "Customer Support Bot",
|
|
274
|
+
userId: "user-1",
|
|
275
|
+
input: { message: "What are your business hours?" },
|
|
276
|
+
output: { response: "Our business hours are 9 AM to 5 PM EST..." },
|
|
277
|
+
status: "COMPLETED",
|
|
278
|
+
totalTokens: 800,
|
|
279
|
+
promptTokens: 500,
|
|
280
|
+
completionTokens: 300,
|
|
281
|
+
totalIterations: 2,
|
|
282
|
+
durationMs: 2100,
|
|
283
|
+
estimatedCostUsd: 0.0012,
|
|
284
|
+
queuedAt: new Date("2024-04-15T09:00:00Z"),
|
|
285
|
+
startedAt: new Date("2024-04-15T09:00:01Z"),
|
|
286
|
+
completedAt: new Date("2024-04-15T09:00:03Z"),
|
|
287
|
+
steps: [],
|
|
288
|
+
logs: []
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: "run-4",
|
|
292
|
+
organizationId: "demo-org",
|
|
293
|
+
projectId: "demo-project",
|
|
294
|
+
agentId: "agent-3",
|
|
295
|
+
agentName: "Data Analyst",
|
|
296
|
+
userId: "user-3",
|
|
297
|
+
input: { message: "Generate sales report for Q1" },
|
|
298
|
+
status: "FAILED",
|
|
299
|
+
errorMessage: "Database connection timeout",
|
|
300
|
+
errorCode: "DB_TIMEOUT",
|
|
301
|
+
totalTokens: 2000,
|
|
302
|
+
promptTokens: 1500,
|
|
303
|
+
completionTokens: 500,
|
|
304
|
+
totalIterations: 8,
|
|
305
|
+
durationMs: 45000,
|
|
306
|
+
queuedAt: new Date("2024-04-14T15:00:00Z"),
|
|
307
|
+
startedAt: new Date("2024-04-14T15:00:05Z"),
|
|
308
|
+
completedAt: new Date("2024-04-14T15:00:50Z"),
|
|
309
|
+
steps: [],
|
|
310
|
+
logs: []
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
id: "run-5",
|
|
314
|
+
organizationId: "demo-org",
|
|
315
|
+
projectId: "demo-project",
|
|
316
|
+
agentId: "agent-2",
|
|
317
|
+
agentName: "Code Review Assistant",
|
|
318
|
+
userId: "user-2",
|
|
319
|
+
input: { message: "Review PR #120" },
|
|
320
|
+
output: { response: "Code review complete. 3 suggestions..." },
|
|
321
|
+
status: "COMPLETED",
|
|
322
|
+
totalTokens: 5200,
|
|
323
|
+
promptTokens: 4000,
|
|
324
|
+
completionTokens: 1200,
|
|
325
|
+
totalIterations: 7,
|
|
326
|
+
durationMs: 15000,
|
|
327
|
+
estimatedCostUsd: 0.0156,
|
|
328
|
+
queuedAt: new Date("2024-04-14T11:00:00Z"),
|
|
329
|
+
startedAt: new Date("2024-04-14T11:00:03Z"),
|
|
330
|
+
completedAt: new Date("2024-04-14T11:00:18Z"),
|
|
331
|
+
steps: [],
|
|
332
|
+
logs: []
|
|
333
|
+
}
|
|
334
|
+
];
|
|
335
|
+
|
|
336
|
+
// src/ui/hooks/useAgentList.ts
|
|
3
337
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
4
|
-
|
|
338
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
339
|
+
function useAgentList(options = {}) {
|
|
5
340
|
const { handlers, projectId } = useTemplateRuntime();
|
|
6
341
|
const { agent } = handlers;
|
|
7
342
|
const [data, setData] = useState(null);
|
|
8
|
-
const [metrics, setMetrics] = useState(null);
|
|
9
343
|
const [loading, setLoading] = useState(true);
|
|
10
344
|
const [error, setError] = useState(null);
|
|
11
345
|
const [page, setPage] = useState(1);
|
|
12
346
|
const fetchData = useCallback(async () => {
|
|
13
|
-
setLoading(true);
|
|
14
|
-
setError(null);
|
|
15
|
-
try {
|
|
16
|
-
const [runsResult, metricsResult] = await Promise.all([
|
|
17
|
-
agent.listRuns({
|
|
18
|
-
projectId,
|
|
19
|
-
agentId: options.agentId,
|
|
20
|
-
status: options.status === "all" ? undefined : options.status,
|
|
21
|
-
limit: options.limit ?? 20,
|
|
22
|
-
offset: (page - 1) * (options.limit ?? 20)
|
|
23
|
-
}),
|
|
24
|
-
agent.getRunMetrics({
|
|
25
|
-
projectId,
|
|
26
|
-
agentId: options.agentId,
|
|
27
|
-
startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000),
|
|
28
|
-
endDate: new Date
|
|
29
|
-
})
|
|
30
|
-
]);
|
|
31
|
-
setData(runsResult);
|
|
32
|
-
setMetrics(metricsResult);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
35
|
-
} finally {
|
|
36
|
-
setLoading(false);
|
|
37
|
-
}
|
|
38
|
-
}, [agent, projectId, options.agentId, options.status, options.limit, page]);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
fetchData();
|
|
41
|
-
}, [fetchData]);
|
|
42
|
-
return {
|
|
43
|
-
data,
|
|
44
|
-
metrics,
|
|
45
|
-
loading,
|
|
46
|
-
error,
|
|
47
|
-
page,
|
|
48
|
-
refetch: fetchData,
|
|
49
|
-
nextPage: () => setPage((p) => p + 1),
|
|
50
|
-
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// src/ui/hooks/useToolList.ts
|
|
55
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useState as useState2 } from "react";
|
|
56
|
-
import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
|
|
57
|
-
function useToolList(options = {}) {
|
|
58
|
-
const { handlers, projectId } = useTemplateRuntime2();
|
|
59
|
-
const { agent } = handlers;
|
|
60
|
-
const [data, setData] = useState2(null);
|
|
61
|
-
const [loading, setLoading] = useState2(true);
|
|
62
|
-
const [error, setError] = useState2(null);
|
|
63
|
-
const [page, setPage] = useState2(1);
|
|
64
|
-
const fetchData = useCallback2(async () => {
|
|
65
|
-
setLoading(true);
|
|
66
|
-
setError(null);
|
|
67
|
-
try {
|
|
68
|
-
const result = await agent.listTools({
|
|
69
|
-
projectId,
|
|
70
|
-
search: options.search,
|
|
71
|
-
category: options.category,
|
|
72
|
-
status: options.status === "all" ? undefined : options.status,
|
|
73
|
-
limit: options.limit ?? 50,
|
|
74
|
-
offset: (page - 1) * (options.limit ?? 50)
|
|
75
|
-
});
|
|
76
|
-
setData(result);
|
|
77
|
-
} catch (err) {
|
|
78
|
-
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
79
|
-
} finally {
|
|
80
|
-
setLoading(false);
|
|
81
|
-
}
|
|
82
|
-
}, [
|
|
83
|
-
agent,
|
|
84
|
-
projectId,
|
|
85
|
-
options.search,
|
|
86
|
-
options.category,
|
|
87
|
-
options.status,
|
|
88
|
-
options.limit,
|
|
89
|
-
page
|
|
90
|
-
]);
|
|
91
|
-
useEffect2(() => {
|
|
92
|
-
fetchData();
|
|
93
|
-
}, [fetchData]);
|
|
94
|
-
const { stats, groupedByCategory, categoryStats } = useMemo(() => {
|
|
95
|
-
if (!data)
|
|
96
|
-
return { stats: null, groupedByCategory: {}, categoryStats: [] };
|
|
97
|
-
const items = data.items;
|
|
98
|
-
const active = items.filter((t) => t.status === "ACTIVE").length;
|
|
99
|
-
const deprecated = items.filter((t) => t.status === "DEPRECATED").length;
|
|
100
|
-
const disabled = items.filter((t) => t.status === "DISABLED").length;
|
|
101
|
-
const grouped = {};
|
|
102
|
-
const byCategory = {};
|
|
103
|
-
items.forEach((t) => {
|
|
104
|
-
const cat = t.category;
|
|
105
|
-
if (!grouped[cat])
|
|
106
|
-
grouped[cat] = [];
|
|
107
|
-
grouped[cat].push(t);
|
|
108
|
-
byCategory[cat] = (byCategory[cat] || 0) + 1;
|
|
109
|
-
});
|
|
110
|
-
const catStats = Object.entries(byCategory).map(([category, count]) => ({ category, count })).sort((a, b) => b.count - a.count);
|
|
111
|
-
return {
|
|
112
|
-
stats: {
|
|
113
|
-
total: data.total,
|
|
114
|
-
active,
|
|
115
|
-
deprecated,
|
|
116
|
-
disabled,
|
|
117
|
-
topCategories: catStats.slice(0, 5)
|
|
118
|
-
},
|
|
119
|
-
groupedByCategory: grouped,
|
|
120
|
-
categoryStats: catStats
|
|
121
|
-
};
|
|
122
|
-
}, [data]);
|
|
123
|
-
return {
|
|
124
|
-
data,
|
|
125
|
-
loading,
|
|
126
|
-
error,
|
|
127
|
-
stats,
|
|
128
|
-
groupedByCategory,
|
|
129
|
-
categoryStats,
|
|
130
|
-
page,
|
|
131
|
-
refetch: fetchData,
|
|
132
|
-
nextPage: () => setPage((p) => p + 1),
|
|
133
|
-
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/ui/hooks/useAgentList.ts
|
|
138
|
-
import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo2, useState as useState3 } from "react";
|
|
139
|
-
import { useTemplateRuntime as useTemplateRuntime3 } from "@contractspec/lib.example-shared-ui";
|
|
140
|
-
function useAgentList(options = {}) {
|
|
141
|
-
const { handlers, projectId } = useTemplateRuntime3();
|
|
142
|
-
const { agent } = handlers;
|
|
143
|
-
const [data, setData] = useState3(null);
|
|
144
|
-
const [loading, setLoading] = useState3(true);
|
|
145
|
-
const [error, setError] = useState3(null);
|
|
146
|
-
const [page, setPage] = useState3(1);
|
|
147
|
-
const fetchData = useCallback3(async () => {
|
|
148
347
|
setLoading(true);
|
|
149
348
|
setError(null);
|
|
150
349
|
try {
|
|
@@ -162,10 +361,10 @@ function useAgentList(options = {}) {
|
|
|
162
361
|
setLoading(false);
|
|
163
362
|
}
|
|
164
363
|
}, [agent, projectId, options.search, options.status, options.limit, page]);
|
|
165
|
-
|
|
364
|
+
useEffect(() => {
|
|
166
365
|
fetchData();
|
|
167
366
|
}, [fetchData]);
|
|
168
|
-
const stats =
|
|
367
|
+
const stats = useMemo(() => {
|
|
169
368
|
if (!data)
|
|
170
369
|
return null;
|
|
171
370
|
return {
|
|
@@ -188,44 +387,141 @@ function useAgentList(options = {}) {
|
|
|
188
387
|
}
|
|
189
388
|
|
|
190
389
|
// src/ui/hooks/useAgentMutations.ts
|
|
191
|
-
import {
|
|
192
|
-
import {
|
|
390
|
+
import { useTemplateRuntime as useTemplateRuntime2 } from "@contractspec/lib.example-shared-ui";
|
|
391
|
+
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
392
|
+
|
|
393
|
+
// src/shared/demo-runtime-seed.ts
|
|
394
|
+
var AGENT_CONSOLE_DEMO_ORGANIZATION_ID = "demo-org";
|
|
395
|
+
var AGENT_CONSOLE_DEMO_PROJECT_ID = "agent-console-demo";
|
|
396
|
+
function slugify(name) {
|
|
397
|
+
return name.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
398
|
+
}
|
|
399
|
+
function cloneAgent(agent) {
|
|
400
|
+
return { ...agent };
|
|
401
|
+
}
|
|
402
|
+
function cloneTool(tool) {
|
|
403
|
+
return { ...tool };
|
|
404
|
+
}
|
|
405
|
+
function cloneRun(run) {
|
|
406
|
+
return { ...run };
|
|
407
|
+
}
|
|
408
|
+
function createDefaultNow() {
|
|
409
|
+
let tick = 0;
|
|
410
|
+
const base = Date.parse("2026-03-20T09:00:00.000Z");
|
|
411
|
+
return () => new Date(base + tick++ * 60000);
|
|
412
|
+
}
|
|
413
|
+
function normalizeProvider(provider) {
|
|
414
|
+
return provider.toLowerCase();
|
|
415
|
+
}
|
|
416
|
+
function normalizeRunStatus(status) {
|
|
417
|
+
return status === "IN_PROGRESS" ? "RUNNING" : status;
|
|
418
|
+
}
|
|
419
|
+
function createSeedState(projectId, organizationId) {
|
|
420
|
+
const agents = MOCK_AGENTS.map((agent) => ({
|
|
421
|
+
id: agent.id,
|
|
422
|
+
projectId,
|
|
423
|
+
organizationId,
|
|
424
|
+
name: agent.name,
|
|
425
|
+
slug: agent.slug,
|
|
426
|
+
description: agent.description,
|
|
427
|
+
modelProvider: normalizeProvider(agent.modelProvider),
|
|
428
|
+
modelName: agent.modelName,
|
|
429
|
+
systemPrompt: agent.systemPrompt,
|
|
430
|
+
temperature: typeof agent.modelConfig?.temperature === "number" ? agent.modelConfig.temperature : 0.4,
|
|
431
|
+
maxTokens: 8192,
|
|
432
|
+
status: agent.status,
|
|
433
|
+
createdAt: agent.createdAt,
|
|
434
|
+
updatedAt: agent.updatedAt
|
|
435
|
+
}));
|
|
436
|
+
const tools = MOCK_TOOLS.map((tool) => ({
|
|
437
|
+
id: tool.id,
|
|
438
|
+
projectId,
|
|
439
|
+
organizationId,
|
|
440
|
+
name: tool.name,
|
|
441
|
+
description: tool.description,
|
|
442
|
+
version: tool.version,
|
|
443
|
+
category: tool.category,
|
|
444
|
+
status: tool.status,
|
|
445
|
+
inputSchema: JSON.stringify(tool.parametersSchema),
|
|
446
|
+
outputSchema: tool.outputSchema ? JSON.stringify(tool.outputSchema) : undefined,
|
|
447
|
+
endpoint: typeof tool.implementationConfig?.url === "string" ? tool.implementationConfig.url : undefined,
|
|
448
|
+
createdAt: tool.createdAt,
|
|
449
|
+
updatedAt: tool.updatedAt
|
|
450
|
+
}));
|
|
451
|
+
const agentNames = new Map(agents.map((agent) => [agent.id, agent.name]));
|
|
452
|
+
const runs = MOCK_RUNS.map((run) => ({
|
|
453
|
+
id: run.id,
|
|
454
|
+
projectId,
|
|
455
|
+
agentId: run.agentId,
|
|
456
|
+
agentName: agentNames.get(run.agentId) ?? run.agentName ?? "Unknown agent",
|
|
457
|
+
status: normalizeRunStatus(run.status),
|
|
458
|
+
input: JSON.stringify(run.input),
|
|
459
|
+
output: run.output ? JSON.stringify(run.output) : undefined,
|
|
460
|
+
totalTokens: run.totalTokens,
|
|
461
|
+
promptTokens: run.promptTokens,
|
|
462
|
+
completionTokens: run.completionTokens,
|
|
463
|
+
estimatedCostUsd: run.estimatedCostUsd ?? 0,
|
|
464
|
+
durationMs: run.durationMs,
|
|
465
|
+
errorMessage: run.errorMessage,
|
|
466
|
+
queuedAt: run.queuedAt,
|
|
467
|
+
startedAt: run.startedAt,
|
|
468
|
+
completedAt: run.completedAt
|
|
469
|
+
}));
|
|
470
|
+
return { agents, tools, runs };
|
|
471
|
+
}
|
|
472
|
+
function summarizeRunMetrics(runs) {
|
|
473
|
+
const totalRuns = runs.length;
|
|
474
|
+
const completedRuns = runs.filter((run) => run.status === "COMPLETED").length;
|
|
475
|
+
const completedDurations = runs.map((run) => run.durationMs).filter((duration) => typeof duration === "number");
|
|
476
|
+
return {
|
|
477
|
+
totalRuns,
|
|
478
|
+
successRate: totalRuns === 0 ? 0 : completedRuns / totalRuns,
|
|
479
|
+
averageDurationMs: completedDurations.length === 0 ? 0 : Math.round(completedDurations.reduce((sum, duration) => sum + duration, 0) / completedDurations.length),
|
|
480
|
+
totalTokens: runs.reduce((sum, run) => sum + run.totalTokens, 0),
|
|
481
|
+
totalCostUsd: runs.reduce((sum, run) => sum + run.estimatedCostUsd, 0)
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// src/ui/hooks/useAgentMutations.ts
|
|
486
|
+
function normalizeMutationError(error, fallbackMessage) {
|
|
487
|
+
return error instanceof Error ? error : new Error(fallbackMessage);
|
|
488
|
+
}
|
|
193
489
|
function useAgentMutations(options = {}) {
|
|
194
|
-
const { handlers, projectId } =
|
|
490
|
+
const { handlers, projectId } = useTemplateRuntime2();
|
|
195
491
|
const { agent } = handlers;
|
|
196
|
-
const [createState, setCreateState] =
|
|
492
|
+
const [createState, setCreateState] = useState2({
|
|
197
493
|
loading: false,
|
|
198
494
|
error: null,
|
|
199
495
|
data: null
|
|
200
496
|
});
|
|
201
|
-
const [updateState, setUpdateState] =
|
|
497
|
+
const [updateState, setUpdateState] = useState2({
|
|
202
498
|
loading: false,
|
|
203
499
|
error: null,
|
|
204
500
|
data: null
|
|
205
501
|
});
|
|
206
|
-
const [executeState, setExecuteState] =
|
|
502
|
+
const [executeState, setExecuteState] = useState2({
|
|
207
503
|
loading: false,
|
|
208
504
|
error: null,
|
|
209
505
|
data: null
|
|
210
506
|
});
|
|
211
|
-
const createAgent =
|
|
507
|
+
const createAgent = useCallback2(async (input) => {
|
|
212
508
|
setCreateState({ loading: true, error: null, data: null });
|
|
213
509
|
try {
|
|
214
510
|
const result = await agent.createAgent(input, {
|
|
215
511
|
projectId,
|
|
216
|
-
organizationId:
|
|
512
|
+
organizationId: AGENT_CONSOLE_DEMO_ORGANIZATION_ID
|
|
217
513
|
});
|
|
218
514
|
setCreateState({ loading: false, error: null, data: result });
|
|
219
515
|
options.onSuccess?.();
|
|
220
516
|
return result;
|
|
221
517
|
} catch (err) {
|
|
222
|
-
const error = err
|
|
518
|
+
const error = normalizeMutationError(err, "Failed to create agent");
|
|
223
519
|
setCreateState({ loading: false, error, data: null });
|
|
224
520
|
options.onError?.(error);
|
|
225
|
-
|
|
521
|
+
throw error;
|
|
226
522
|
}
|
|
227
523
|
}, [agent, projectId, options]);
|
|
228
|
-
const updateAgent =
|
|
524
|
+
const updateAgent = useCallback2(async (input) => {
|
|
229
525
|
setUpdateState({ loading: true, error: null, data: null });
|
|
230
526
|
try {
|
|
231
527
|
const result = await agent.updateAgent(input);
|
|
@@ -233,37 +529,40 @@ function useAgentMutations(options = {}) {
|
|
|
233
529
|
options.onSuccess?.();
|
|
234
530
|
return result;
|
|
235
531
|
} catch (err) {
|
|
236
|
-
const error = err
|
|
532
|
+
const error = normalizeMutationError(err, "Failed to update agent");
|
|
237
533
|
setUpdateState({ loading: false, error, data: null });
|
|
238
534
|
options.onError?.(error);
|
|
239
|
-
|
|
535
|
+
throw error;
|
|
240
536
|
}
|
|
241
537
|
}, [agent, options]);
|
|
242
|
-
const activateAgent =
|
|
538
|
+
const activateAgent = useCallback2(async (agentId) => {
|
|
243
539
|
return updateAgent({ id: agentId, status: "ACTIVE" });
|
|
244
540
|
}, [updateAgent]);
|
|
245
|
-
const pauseAgent =
|
|
541
|
+
const pauseAgent = useCallback2(async (agentId) => {
|
|
246
542
|
return updateAgent({ id: agentId, status: "PAUSED" });
|
|
247
543
|
}, [updateAgent]);
|
|
248
|
-
const archiveAgent =
|
|
544
|
+
const archiveAgent = useCallback2(async (agentId) => {
|
|
249
545
|
return updateAgent({ id: agentId, status: "ARCHIVED" });
|
|
250
546
|
}, [updateAgent]);
|
|
251
|
-
const executeAgent =
|
|
547
|
+
const executeAgent = useCallback2(async (input) => {
|
|
252
548
|
setExecuteState({ loading: true, error: null, data: null });
|
|
253
549
|
try {
|
|
254
550
|
const result = await agent.executeAgent({
|
|
255
551
|
agentId: input.agentId,
|
|
256
552
|
message: input.message,
|
|
257
|
-
context: {
|
|
553
|
+
context: {
|
|
554
|
+
projectId,
|
|
555
|
+
organizationId: AGENT_CONSOLE_DEMO_ORGANIZATION_ID
|
|
556
|
+
}
|
|
258
557
|
});
|
|
259
558
|
setExecuteState({ loading: false, error: null, data: result });
|
|
260
559
|
options.onSuccess?.();
|
|
261
560
|
return result;
|
|
262
561
|
} catch (err) {
|
|
263
|
-
const error = err
|
|
562
|
+
const error = normalizeMutationError(err, "Failed to execute agent");
|
|
264
563
|
setExecuteState({ loading: false, error, data: null });
|
|
265
564
|
options.onError?.(error);
|
|
266
|
-
|
|
565
|
+
throw error;
|
|
267
566
|
}
|
|
268
567
|
}, [agent, projectId, options]);
|
|
269
568
|
return {
|
|
@@ -280,6 +579,157 @@ function useAgentMutations(options = {}) {
|
|
|
280
579
|
};
|
|
281
580
|
}
|
|
282
581
|
|
|
582
|
+
// src/ui/hooks/useRunList.ts
|
|
583
|
+
import { useTemplateRuntime as useTemplateRuntime3 } from "@contractspec/lib.example-shared-ui";
|
|
584
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useState as useState3 } from "react";
|
|
585
|
+
function useRunList(options = {}) {
|
|
586
|
+
const { handlers, projectId } = useTemplateRuntime3();
|
|
587
|
+
const { agent } = handlers;
|
|
588
|
+
const [data, setData] = useState3(null);
|
|
589
|
+
const [metrics, setMetrics] = useState3(null);
|
|
590
|
+
const [loading, setLoading] = useState3(true);
|
|
591
|
+
const [error, setError] = useState3(null);
|
|
592
|
+
const [internalPageIndex, setInternalPageIndex] = useState3(0);
|
|
593
|
+
const pageSize = options.pageSize ?? options.limit ?? 20;
|
|
594
|
+
const pageIndex = options.pageIndex ?? internalPageIndex;
|
|
595
|
+
const [sort] = options.sorting ?? [];
|
|
596
|
+
const fetchData = useCallback3(async () => {
|
|
597
|
+
setLoading(true);
|
|
598
|
+
setError(null);
|
|
599
|
+
try {
|
|
600
|
+
const [runsResult, metricsResult] = await Promise.all([
|
|
601
|
+
agent.listRuns({
|
|
602
|
+
projectId,
|
|
603
|
+
agentId: options.agentId,
|
|
604
|
+
status: options.status === "all" ? undefined : options.status,
|
|
605
|
+
sortBy: sort?.id,
|
|
606
|
+
sortDirection: sort ? sort.desc ? "desc" : "asc" : undefined,
|
|
607
|
+
limit: pageSize,
|
|
608
|
+
offset: pageIndex * pageSize
|
|
609
|
+
}),
|
|
610
|
+
agent.getRunMetrics({
|
|
611
|
+
projectId,
|
|
612
|
+
agentId: options.agentId
|
|
613
|
+
})
|
|
614
|
+
]);
|
|
615
|
+
setData(runsResult);
|
|
616
|
+
setMetrics(metricsResult);
|
|
617
|
+
} catch (err) {
|
|
618
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
619
|
+
} finally {
|
|
620
|
+
setLoading(false);
|
|
621
|
+
}
|
|
622
|
+
}, [
|
|
623
|
+
agent,
|
|
624
|
+
pageIndex,
|
|
625
|
+
pageSize,
|
|
626
|
+
projectId,
|
|
627
|
+
options.agentId,
|
|
628
|
+
options.status,
|
|
629
|
+
sort?.desc,
|
|
630
|
+
sort?.id
|
|
631
|
+
]);
|
|
632
|
+
useEffect2(() => {
|
|
633
|
+
fetchData();
|
|
634
|
+
}, [fetchData]);
|
|
635
|
+
const hasControlledPagination = options.pageIndex !== undefined;
|
|
636
|
+
return {
|
|
637
|
+
data,
|
|
638
|
+
metrics,
|
|
639
|
+
loading,
|
|
640
|
+
error,
|
|
641
|
+
page: pageIndex + 1,
|
|
642
|
+
pageIndex,
|
|
643
|
+
pageSize,
|
|
644
|
+
refetch: fetchData,
|
|
645
|
+
nextPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => current + 1),
|
|
646
|
+
prevPage: hasControlledPagination ? undefined : () => setInternalPageIndex((current) => Math.max(0, current - 1))
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/ui/hooks/useToolList.ts
|
|
651
|
+
import { useTemplateRuntime as useTemplateRuntime4 } from "@contractspec/lib.example-shared-ui";
|
|
652
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useMemo as useMemo2, useState as useState4 } from "react";
|
|
653
|
+
function useToolList(options = {}) {
|
|
654
|
+
const { handlers, projectId } = useTemplateRuntime4();
|
|
655
|
+
const { agent } = handlers;
|
|
656
|
+
const [data, setData] = useState4(null);
|
|
657
|
+
const [loading, setLoading] = useState4(true);
|
|
658
|
+
const [error, setError] = useState4(null);
|
|
659
|
+
const [page, setPage] = useState4(1);
|
|
660
|
+
const fetchData = useCallback4(async () => {
|
|
661
|
+
setLoading(true);
|
|
662
|
+
setError(null);
|
|
663
|
+
try {
|
|
664
|
+
const result = await agent.listTools({
|
|
665
|
+
projectId,
|
|
666
|
+
search: options.search,
|
|
667
|
+
category: options.category,
|
|
668
|
+
status: options.status === "all" ? undefined : options.status,
|
|
669
|
+
limit: options.limit ?? 50,
|
|
670
|
+
offset: (page - 1) * (options.limit ?? 50)
|
|
671
|
+
});
|
|
672
|
+
setData(result);
|
|
673
|
+
} catch (err) {
|
|
674
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
675
|
+
} finally {
|
|
676
|
+
setLoading(false);
|
|
677
|
+
}
|
|
678
|
+
}, [
|
|
679
|
+
agent,
|
|
680
|
+
projectId,
|
|
681
|
+
options.search,
|
|
682
|
+
options.category,
|
|
683
|
+
options.status,
|
|
684
|
+
options.limit,
|
|
685
|
+
page
|
|
686
|
+
]);
|
|
687
|
+
useEffect3(() => {
|
|
688
|
+
fetchData();
|
|
689
|
+
}, [fetchData]);
|
|
690
|
+
const { stats, groupedByCategory, categoryStats } = useMemo2(() => {
|
|
691
|
+
if (!data)
|
|
692
|
+
return { stats: null, groupedByCategory: {}, categoryStats: [] };
|
|
693
|
+
const items = data.items;
|
|
694
|
+
const active = items.filter((t) => t.status === "ACTIVE").length;
|
|
695
|
+
const deprecated = items.filter((t) => t.status === "DEPRECATED").length;
|
|
696
|
+
const disabled = items.filter((t) => t.status === "DISABLED").length;
|
|
697
|
+
const grouped = {};
|
|
698
|
+
const byCategory = {};
|
|
699
|
+
items.forEach((t) => {
|
|
700
|
+
const cat = t.category;
|
|
701
|
+
if (!grouped[cat])
|
|
702
|
+
grouped[cat] = [];
|
|
703
|
+
grouped[cat].push(t);
|
|
704
|
+
byCategory[cat] = (byCategory[cat] || 0) + 1;
|
|
705
|
+
});
|
|
706
|
+
const catStats = Object.entries(byCategory).map(([category, count]) => ({ category, count })).sort((a, b) => b.count - a.count);
|
|
707
|
+
return {
|
|
708
|
+
stats: {
|
|
709
|
+
total: data.total,
|
|
710
|
+
active,
|
|
711
|
+
deprecated,
|
|
712
|
+
disabled,
|
|
713
|
+
topCategories: catStats.slice(0, 5)
|
|
714
|
+
},
|
|
715
|
+
groupedByCategory: grouped,
|
|
716
|
+
categoryStats: catStats
|
|
717
|
+
};
|
|
718
|
+
}, [data]);
|
|
719
|
+
return {
|
|
720
|
+
data,
|
|
721
|
+
loading,
|
|
722
|
+
error,
|
|
723
|
+
stats,
|
|
724
|
+
groupedByCategory,
|
|
725
|
+
categoryStats,
|
|
726
|
+
page,
|
|
727
|
+
refetch: fetchData,
|
|
728
|
+
nextPage: () => setPage((p) => p + 1),
|
|
729
|
+
prevPage: () => page > 1 && setPage((p) => p - 1)
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
|
|
283
733
|
// src/ui/hooks/index.ts
|
|
284
734
|
"use client";
|
|
285
735
|
export {
|