waypoi 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/instructions/ui.instructions.md +42 -0
- package/.github/workflows/ci.yml +35 -0
- package/.github/workflows/publish.yml +71 -0
- package/.github/workflows/release.yml +48 -0
- package/.playwright-mcp/console-2026-04-04T01-41-10-746Z.log +2 -0
- package/.playwright-mcp/console-2026-04-04T01-41-28-799Z.log +3 -0
- package/.playwright-mcp/console-2026-04-05T02-26-51-909Z.log +76 -0
- package/.playwright-mcp/page-2026-04-04T01-41-10-816Z.yml +1 -0
- package/.playwright-mcp/page-2026-04-04T01-41-29-141Z.yml +77 -0
- package/.playwright-mcp/page-2026-04-04T01-41-42-633Z.yml +190 -0
- package/.playwright-mcp/page-2026-04-04T01-42-03-929Z.yml +262 -0
- package/.playwright-mcp/page-2026-04-04T02-12-54-813Z.yml +6 -0
- package/.playwright-mcp/page-2026-04-04T02-14-58-600Z.yml +190 -0
- package/.playwright-mcp/page-2026-04-04T02-15-03-923Z.yml +190 -0
- package/.playwright-mcp/page-2026-04-04T02-15-07-426Z.yml +190 -0
- package/.playwright-mcp/page-2026-04-04T02-15-25-729Z.yml +262 -0
- package/.playwright-mcp/page-2026-04-04T02-16-22-984Z.yml +262 -0
- package/.playwright-mcp/page-2026-04-04T02-17-00-599Z.yml +190 -0
- package/.playwright-mcp/page-2026-04-04T02-17-50-874Z.yml +190 -0
- package/.playwright-mcp/page-2026-04-05T02-26-55-570Z.yml +6 -0
- package/AGENTS.md +48 -0
- package/CHANGELOG.md +131 -0
- package/README.md +552 -0
- package/assets/agent-mode.png +0 -0
- package/assets/categorize.png +0 -0
- package/assets/dashboard.png +0 -0
- package/assets/endpoint-proxy.png +0 -0
- package/assets/icon.png +0 -0
- package/assets/mcp-generate-image.png +0 -0
- package/assets/mcp-understand-image.png +0 -0
- package/assets/peek-token-flow.png +0 -0
- package/assets/playground.png +0 -0
- package/assets/sankey.png +0 -0
- package/cli/index.ts +2805 -0
- package/cli/legacyRewrite.ts +108 -0
- package/cli/modelRef.ts +24 -0
- package/dist/cli/index.js +2536 -0
- package/dist/cli/legacyRewrite.js +92 -0
- package/dist/cli/modelRef.js +20 -0
- package/dist/src/benchmark/artifacts.js +131 -0
- package/dist/src/benchmark/capabilityClassifier.js +81 -0
- package/dist/src/benchmark/capabilityStore.js +144 -0
- package/dist/src/benchmark/config.js +238 -0
- package/dist/src/benchmark/gates.js +118 -0
- package/dist/src/benchmark/jobs.js +252 -0
- package/dist/src/benchmark/runner.js +1847 -0
- package/dist/src/benchmark/schema.js +353 -0
- package/dist/src/benchmark/suites.js +314 -0
- package/dist/src/benchmark/tinyQaDataset.js +422 -0
- package/dist/src/benchmark/types.js +25 -0
- package/dist/src/config.js +47 -0
- package/dist/src/index.js +178 -0
- package/dist/src/mcp/client.js +215 -0
- package/dist/src/mcp/discovery.js +226 -0
- package/dist/src/mcp/policy.js +65 -0
- package/dist/src/mcp/registry.js +129 -0
- package/dist/src/mcp/service.js +460 -0
- package/dist/src/middleware/auth.js +179 -0
- package/dist/src/middleware/requestCapture.js +192 -0
- package/dist/src/middleware/requestStats.js +118 -0
- package/dist/src/pools/builder.js +132 -0
- package/dist/src/pools/repository.js +69 -0
- package/dist/src/pools/scheduler.js +360 -0
- package/dist/src/pools/types.js +2 -0
- package/dist/src/protocols/adapters/dashscope.js +267 -0
- package/dist/src/protocols/adapters/inferenceV2.js +346 -0
- package/dist/src/protocols/adapters/openai.js +27 -0
- package/dist/src/protocols/registry.js +99 -0
- package/dist/src/protocols/types.js +2 -0
- package/dist/src/providers/health.js +153 -0
- package/dist/src/providers/importer.js +289 -0
- package/dist/src/providers/modelRegistry.js +313 -0
- package/dist/src/providers/repository.js +361 -0
- package/dist/src/providers/types.js +2 -0
- package/dist/src/routes/admin.js +531 -0
- package/dist/src/routes/audio.js +295 -0
- package/dist/src/routes/chat.js +240 -0
- package/dist/src/routes/embeddings.js +157 -0
- package/dist/src/routes/images.js +288 -0
- package/dist/src/routes/mcp.js +256 -0
- package/dist/src/routes/mcpService.js +100 -0
- package/dist/src/routes/models.js +48 -0
- package/dist/src/routes/responses.js +711 -0
- package/dist/src/routes/sessions.js +450 -0
- package/dist/src/routes/stats.js +270 -0
- package/dist/src/routes/ui.js +97 -0
- package/dist/src/routes/videos.js +107 -0
- package/dist/src/routing/router.js +338 -0
- package/dist/src/services/imageGeneration.js +280 -0
- package/dist/src/services/imageUnderstanding.js +352 -0
- package/dist/src/services/videoGeneration.js +79 -0
- package/dist/src/storage/captureRepository.js +1591 -0
- package/dist/src/storage/files.js +157 -0
- package/dist/src/storage/imageCache.js +346 -0
- package/dist/src/storage/repositories.js +388 -0
- package/dist/src/storage/sessionRepository.js +370 -0
- package/dist/src/storage/statsRepository.js +204 -0
- package/dist/src/transport/httpClient.js +126 -0
- package/dist/src/types.js +2 -0
- package/dist/src/utils/messageMedia.js +285 -0
- package/dist/src/utils/modelCapabilities.js +108 -0
- package/dist/src/utils/modelDiscovery.js +170 -0
- package/dist/src/version.js +5 -0
- package/dist/src/workers/captureRetention.js +25 -0
- package/dist/src/workers/configWatcher.js +91 -0
- package/dist/src/workers/healthChecker.js +21 -0
- package/dist/src/workers/statsRotation.js +41 -0
- package/docs/LLM/output_schema.md +312 -0
- package/docs/benchmark.md +208 -0
- package/docs/mcp-guidelines.md +125 -0
- package/docs/mcp-service.md +178 -0
- package/docs/opencode.md +86 -0
- package/docs/providers.md +79 -0
- package/examples/benchmark.config.yaml +28 -0
- package/examples/providers/alibaba-dashscope.yaml +88 -0
- package/examples/providers/alibaba-llm.yaml +64 -0
- package/examples/providers/alibaba-registry.yaml +7 -0
- package/examples/providers/inference-v2-ray.yaml +29 -0
- package/examples/scenarios/assets/omni-call-sample.wav +0 -0
- package/examples/scenarios/custom.jsonl +5 -0
- package/examples/scenarios/custom.yaml +40 -0
- package/model-form-v2.png +0 -0
- package/package.json +66 -0
- package/provider-form-v2.png +0 -0
- package/provider-form.png +0 -0
- package/scripts/manual-test.sh +11 -0
- package/scripts/version-from-git.js +23 -0
- package/src/benchmark/artifacts.ts +149 -0
- package/src/benchmark/capabilityClassifier.ts +99 -0
- package/src/benchmark/capabilityStore.ts +174 -0
- package/src/benchmark/config.ts +337 -0
- package/src/benchmark/gates.ts +164 -0
- package/src/benchmark/jobs.ts +312 -0
- package/src/benchmark/runner.ts +2519 -0
- package/src/benchmark/schema.ts +443 -0
- package/src/benchmark/suites.ts +323 -0
- package/src/benchmark/tinyQaDataset.ts +428 -0
- package/src/benchmark/types.ts +442 -0
- package/src/config.ts +44 -0
- package/src/index.ts +195 -0
- package/src/mcp/client.ts +305 -0
- package/src/mcp/discovery.ts +266 -0
- package/src/mcp/policy.ts +105 -0
- package/src/mcp/registry.ts +164 -0
- package/src/mcp/service.ts +611 -0
- package/src/middleware/auth.ts +251 -0
- package/src/middleware/requestCapture.ts +245 -0
- package/src/middleware/requestStats.ts +163 -0
- package/src/pools/builder.ts +159 -0
- package/src/pools/repository.ts +71 -0
- package/src/pools/scheduler.ts +425 -0
- package/src/pools/types.ts +117 -0
- package/src/protocols/adapters/dashscope.ts +335 -0
- package/src/protocols/adapters/inferenceV2.ts +428 -0
- package/src/protocols/adapters/openai.ts +32 -0
- package/src/protocols/registry.ts +117 -0
- package/src/protocols/types.ts +81 -0
- package/src/providers/health.ts +207 -0
- package/src/providers/importer.ts +402 -0
- package/src/providers/modelRegistry.ts +415 -0
- package/src/providers/repository.ts +439 -0
- package/src/providers/types.ts +113 -0
- package/src/routes/admin.ts +666 -0
- package/src/routes/audio.ts +372 -0
- package/src/routes/chat.ts +301 -0
- package/src/routes/embeddings.ts +197 -0
- package/src/routes/images.ts +356 -0
- package/src/routes/mcp.ts +320 -0
- package/src/routes/mcpService.ts +114 -0
- package/src/routes/models.ts +50 -0
- package/src/routes/responses.ts +872 -0
- package/src/routes/sessions.ts +558 -0
- package/src/routes/stats.ts +312 -0
- package/src/routes/ui.ts +96 -0
- package/src/routes/videos.ts +132 -0
- package/src/routing/router.ts +501 -0
- package/src/services/imageGeneration.ts +396 -0
- package/src/services/imageUnderstanding.ts +449 -0
- package/src/services/videoGeneration.ts +127 -0
- package/src/storage/captureRepository.ts +1835 -0
- package/src/storage/files.ts +178 -0
- package/src/storage/imageCache.ts +405 -0
- package/src/storage/repositories.ts +494 -0
- package/src/storage/sessionRepository.ts +419 -0
- package/src/storage/statsRepository.ts +238 -0
- package/src/transport/httpClient.ts +145 -0
- package/src/types.ts +322 -0
- package/src/utils/messageMedia.ts +293 -0
- package/src/utils/modelCapabilities.ts +161 -0
- package/src/utils/modelDiscovery.ts +203 -0
- package/src/workers/captureRetention.ts +25 -0
- package/src/workers/configWatcher.ts +115 -0
- package/src/workers/healthChecker.ts +22 -0
- package/src/workers/statsRotation.ts +49 -0
- package/tests/benchmarkAdminRoutes.test.ts +82 -0
- package/tests/benchmarkBasics.test.ts +116 -0
- package/tests/captureAdminRoutes.test.ts +420 -0
- package/tests/captureRepository.test.ts +797 -0
- package/tests/cliLegacyRewrite.test.ts +45 -0
- package/tests/imageGeneration.service.test.ts +107 -0
- package/tests/imageUnderstanding.service.test.ts +123 -0
- package/tests/mcpPolicy.test.ts +105 -0
- package/tests/mcpService.test.ts +1245 -0
- package/tests/modelRef.test.ts +23 -0
- package/tests/modelsRoutes.test.ts +154 -0
- package/tests/sessionMediaCache.test.ts +167 -0
- package/tests/statsRoutes.test.ts +323 -0
- package/tsconfig.json +15 -0
- package/ui/index.html +16 -0
- package/ui/package-lock.json +8521 -0
- package/ui/package.json +52 -0
- package/ui/postcss.config.js +6 -0
- package/ui/public/assets/apple-touch-icon.png +0 -0
- package/ui/public/assets/favicon-16.png +0 -0
- package/ui/public/assets/favicon-32.png +0 -0
- package/ui/public/assets/icon-192.png +0 -0
- package/ui/public/assets/icon-512.png +0 -0
- package/ui/src/App.tsx +27 -0
- package/ui/src/api/client.ts +1503 -0
- package/ui/src/components/EndpointUsageGuide.tsx +361 -0
- package/ui/src/components/Layout.tsx +124 -0
- package/ui/src/components/MessageContent.tsx +365 -0
- package/ui/src/components/ToolCallMessage.tsx +179 -0
- package/ui/src/components/ToolPicker.tsx +442 -0
- package/ui/src/components/messageContentParser.test.ts +41 -0
- package/ui/src/components/messageContentParser.ts +73 -0
- package/ui/src/components/thinkingPreview.test.ts +27 -0
- package/ui/src/components/thinkingPreview.ts +15 -0
- package/ui/src/components/toMermaidSankey.test.ts +78 -0
- package/ui/src/components/toMermaidSankey.ts +56 -0
- package/ui/src/components/ui/button.tsx +58 -0
- package/ui/src/components/ui/input.tsx +21 -0
- package/ui/src/components/ui/textarea.tsx +21 -0
- package/ui/src/lib/utils.ts +6 -0
- package/ui/src/main.tsx +9 -0
- package/ui/src/pages/AgentPlayground.tsx +2010 -0
- package/ui/src/pages/Benchmark.tsx +988 -0
- package/ui/src/pages/Dashboard.tsx +581 -0
- package/ui/src/pages/Peek.tsx +962 -0
- package/ui/src/pages/Settings.tsx +2013 -0
- package/ui/src/pages/agentPlaygroundPayload.test.ts +109 -0
- package/ui/src/pages/agentPlaygroundPayload.ts +97 -0
- package/ui/src/pages/agentThinkingContent.test.ts +50 -0
- package/ui/src/pages/agentThinkingContent.ts +57 -0
- package/ui/src/pages/dashboardTokenUsage.test.ts +66 -0
- package/ui/src/pages/dashboardTokenUsage.ts +36 -0
- package/ui/src/pages/imageUpload.test.ts +39 -0
- package/ui/src/pages/imageUpload.ts +71 -0
- package/ui/src/pages/peekFilters.test.ts +29 -0
- package/ui/src/pages/peekFilters.ts +13 -0
- package/ui/src/pages/peekMedia.test.ts +58 -0
- package/ui/src/pages/peekMedia.ts +148 -0
- package/ui/src/pages/sessionAutoTitle.test.ts +128 -0
- package/ui/src/pages/sessionAutoTitle.ts +106 -0
- package/ui/src/stores/settings.ts +58 -0
- package/ui/src/styles/globals.css +223 -0
- package/ui/src/vite-env.d.ts +8 -0
- package/ui/tailwind.config.js +106 -0
- package/ui/tsconfig.json +32 -0
- package/ui/vite.config.ts +37 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerAdminRoutes = registerAdminRoutes;
|
|
4
|
+
const registry_1 = require("../protocols/registry");
|
|
5
|
+
const repository_1 = require("../providers/repository");
|
|
6
|
+
const repository_2 = require("../pools/repository");
|
|
7
|
+
const builder_1 = require("../pools/builder");
|
|
8
|
+
const runner_1 = require("../benchmark/runner");
|
|
9
|
+
const jobs_1 = require("../benchmark/jobs");
|
|
10
|
+
const capabilityStore_1 = require("../benchmark/capabilityStore");
|
|
11
|
+
const modelDiscovery_1 = require("../utils/modelDiscovery");
|
|
12
|
+
const captureRepository_1 = require("../storage/captureRepository");
|
|
13
|
+
const fs_1 = require("fs");
|
|
14
|
+
async function registerAdminRoutes(app, paths, env) {
|
|
15
|
+
app.addHook("onRequest", async (req, reply) => {
|
|
16
|
+
if (!req.url.startsWith("/admin")) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!isAuthorized(req, env.adminToken)) {
|
|
20
|
+
reply.code(401).send({ error: { message: "Unauthorized" } });
|
|
21
|
+
return reply;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
app.get("/admin/meta", async (_req, reply) => {
|
|
25
|
+
reply.send({
|
|
26
|
+
name: "waypoi",
|
|
27
|
+
version: env.version ?? "0.0.0",
|
|
28
|
+
now: new Date().toISOString(),
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
app.get("/admin/protocols", async (_req, reply) => {
|
|
32
|
+
reply.send({ data: (0, registry_1.listAllProtocolAdapters)() });
|
|
33
|
+
});
|
|
34
|
+
app.get("/admin/providers", async (_req, reply) => {
|
|
35
|
+
const providers = await (0, repository_1.listProviders)(paths);
|
|
36
|
+
reply.send(providers);
|
|
37
|
+
});
|
|
38
|
+
app.get("/admin/providers/:id", async (req, reply) => {
|
|
39
|
+
const { id } = req.params;
|
|
40
|
+
const provider = await (0, repository_1.getProviderById)(paths, id);
|
|
41
|
+
if (!provider) {
|
|
42
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
reply.send(provider);
|
|
46
|
+
});
|
|
47
|
+
app.post("/admin/providers", async (req, reply) => {
|
|
48
|
+
const body = req.body;
|
|
49
|
+
if (!body?.id || !body?.baseUrl || !body?.protocol) {
|
|
50
|
+
reply.code(400).send({ error: { message: "id, baseUrl, and protocol are required" } });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const provider = {
|
|
54
|
+
id: body.id,
|
|
55
|
+
name: body.name ?? body.id,
|
|
56
|
+
description: body.description,
|
|
57
|
+
docs: body.docs,
|
|
58
|
+
protocol: body.protocol,
|
|
59
|
+
protocolRaw: body.protocolRaw,
|
|
60
|
+
protocolConfig: body.protocolConfig,
|
|
61
|
+
baseUrl: body.baseUrl,
|
|
62
|
+
insecureTls: body.insecureTls,
|
|
63
|
+
autoInsecureTlsDomains: body.autoInsecureTlsDomains ?? [],
|
|
64
|
+
enabled: body.enabled ?? true,
|
|
65
|
+
supportsRouting: body.supportsRouting ?? true,
|
|
66
|
+
auth: body.auth,
|
|
67
|
+
envVar: body.envVar,
|
|
68
|
+
apiKey: body.apiKey,
|
|
69
|
+
limits: body.limits,
|
|
70
|
+
models: [],
|
|
71
|
+
importedAt: new Date().toISOString(),
|
|
72
|
+
};
|
|
73
|
+
const saved = await (0, repository_1.upsertProvider)(paths, provider);
|
|
74
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
75
|
+
reply.code(201).send(saved);
|
|
76
|
+
});
|
|
77
|
+
app.patch("/admin/providers/:id", async (req, reply) => {
|
|
78
|
+
const { id } = req.params;
|
|
79
|
+
const body = req.body;
|
|
80
|
+
if (!body) {
|
|
81
|
+
reply.code(400).send({ error: { message: "payload required" } });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const updated = await (0, repository_1.updateProvider)(paths, id, body);
|
|
85
|
+
if (!updated) {
|
|
86
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
90
|
+
reply.send(updated);
|
|
91
|
+
});
|
|
92
|
+
app.delete("/admin/providers/:id", async (req, reply) => {
|
|
93
|
+
const { id } = req.params;
|
|
94
|
+
const removed = await (0, repository_1.deleteProvider)(paths, id);
|
|
95
|
+
if (!removed) {
|
|
96
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
100
|
+
reply.send({ deleted: removed.id });
|
|
101
|
+
});
|
|
102
|
+
app.post("/admin/providers/:id/enable", async (req, reply) => {
|
|
103
|
+
const { id } = req.params;
|
|
104
|
+
const provider = await (0, repository_1.setProviderEnabled)(paths, id, true);
|
|
105
|
+
if (!provider) {
|
|
106
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
110
|
+
reply.send(provider);
|
|
111
|
+
});
|
|
112
|
+
app.post("/admin/providers/:id/disable", async (req, reply) => {
|
|
113
|
+
const { id } = req.params;
|
|
114
|
+
const provider = await (0, repository_1.setProviderEnabled)(paths, id, false);
|
|
115
|
+
if (!provider) {
|
|
116
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
120
|
+
reply.send(provider);
|
|
121
|
+
});
|
|
122
|
+
app.get("/admin/providers/:id/models", async (req, reply) => {
|
|
123
|
+
const { id } = req.params;
|
|
124
|
+
const models = await (0, repository_1.listProviderModels)(paths, id);
|
|
125
|
+
if (!models) {
|
|
126
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
reply.send(models);
|
|
130
|
+
});
|
|
131
|
+
app.post("/admin/providers/:id/models/discover", async (req, reply) => {
|
|
132
|
+
const { id } = req.params;
|
|
133
|
+
const body = req.body;
|
|
134
|
+
const provider = await (0, repository_1.getProviderById)(paths, id);
|
|
135
|
+
if (!provider) {
|
|
136
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const baseUrl = body?.baseUrl?.trim() || provider.baseUrl;
|
|
140
|
+
if (!baseUrl) {
|
|
141
|
+
reply.code(400).send({ error: { message: "baseUrl is required" } });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
const models = await (0, modelDiscovery_1.discoverUpstreamModels)({
|
|
146
|
+
baseUrl,
|
|
147
|
+
apiKey: body?.apiKey?.trim() || provider.apiKey,
|
|
148
|
+
insecureTls: body?.insecureTls === true
|
|
149
|
+
? true
|
|
150
|
+
: (0, repository_1.getEffectiveModelInsecureTls)(provider, { insecureTls: undefined }),
|
|
151
|
+
auth: provider.auth,
|
|
152
|
+
});
|
|
153
|
+
reply.send({ baseUrl, models });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
const message = error instanceof Error && error.message ? error.message : "model discovery failed";
|
|
157
|
+
reply.code(502).send({ error: { message } });
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
app.post("/admin/providers/:id/models", async (req, reply) => {
|
|
161
|
+
const { id } = req.params;
|
|
162
|
+
const body = req.body;
|
|
163
|
+
if (!body?.modelId || !body?.upstreamModel || !body?.endpointType || !body?.capabilities) {
|
|
164
|
+
reply.code(400).send({
|
|
165
|
+
error: {
|
|
166
|
+
message: "modelId, upstreamModel, endpointType, and capabilities are required",
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const provider = await (0, repository_1.getProviderById)(paths, id);
|
|
172
|
+
if (!provider) {
|
|
173
|
+
reply.code(404).send({ error: { message: "provider not found" } });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const record = {
|
|
177
|
+
providerModelId: body.providerModelId ?? `${id}/${body.modelId}`,
|
|
178
|
+
providerId: id,
|
|
179
|
+
modelId: body.modelId,
|
|
180
|
+
upstreamModel: body.upstreamModel,
|
|
181
|
+
baseUrl: body.baseUrl || provider.baseUrl,
|
|
182
|
+
apiKey: body.apiKey,
|
|
183
|
+
insecureTls: body.insecureTls,
|
|
184
|
+
enabled: body.enabled ?? true,
|
|
185
|
+
aliases: body.aliases ?? [],
|
|
186
|
+
free: body.free ?? true,
|
|
187
|
+
modalities: body.modalities ?? [],
|
|
188
|
+
capabilities: body.capabilities,
|
|
189
|
+
endpointType: body.endpointType,
|
|
190
|
+
limits: body.limits,
|
|
191
|
+
};
|
|
192
|
+
const result = await (0, repository_1.upsertProviderModel)(paths, id, record);
|
|
193
|
+
if (!result) {
|
|
194
|
+
reply.code(500).send({ error: { message: "failed to add model" } });
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
198
|
+
reply.code(result.created ? 201 : 200).send(record);
|
|
199
|
+
});
|
|
200
|
+
app.patch("/admin/providers/:id/models/:modelRef", async (req, reply) => {
|
|
201
|
+
const { id, modelRef } = req.params;
|
|
202
|
+
const body = req.body;
|
|
203
|
+
if (!body) {
|
|
204
|
+
reply.code(400).send({ error: { message: "payload required" } });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const updated = await (0, repository_1.updateProviderModel)(paths, id, modelRef, body);
|
|
208
|
+
if (!updated) {
|
|
209
|
+
reply.code(404).send({ error: { message: "model not found" } });
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
213
|
+
reply.send(updated);
|
|
214
|
+
});
|
|
215
|
+
app.delete("/admin/providers/:id/models/:modelRef", async (req, reply) => {
|
|
216
|
+
const { id, modelRef } = req.params;
|
|
217
|
+
const removed = await (0, repository_1.deleteProviderModel)(paths, id, modelRef);
|
|
218
|
+
if (!removed) {
|
|
219
|
+
reply.code(404).send({ error: { message: "model not found" } });
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
223
|
+
reply.send({ deleted: removed.providerModelId });
|
|
224
|
+
});
|
|
225
|
+
app.post("/admin/providers/:id/models/:modelRef/enable", async (req, reply) => {
|
|
226
|
+
const { id, modelRef } = req.params;
|
|
227
|
+
const model = await (0, repository_1.setProviderModelEnabled)(paths, id, modelRef, true);
|
|
228
|
+
if (!model) {
|
|
229
|
+
reply.code(404).send({ error: { message: "model not found" } });
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
233
|
+
reply.send(model);
|
|
234
|
+
});
|
|
235
|
+
app.post("/admin/providers/:id/models/:modelRef/disable", async (req, reply) => {
|
|
236
|
+
const { id, modelRef } = req.params;
|
|
237
|
+
const model = await (0, repository_1.setProviderModelEnabled)(paths, id, modelRef, false);
|
|
238
|
+
if (!model) {
|
|
239
|
+
reply.code(404).send({ error: { message: "model not found" } });
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
await (0, builder_1.rebuildDefaultPools)(paths);
|
|
243
|
+
reply.send(model);
|
|
244
|
+
});
|
|
245
|
+
app.get("/admin/pools", async (_req, reply) => {
|
|
246
|
+
const pools = await (0, repository_2.listPools)(paths);
|
|
247
|
+
reply.send(pools);
|
|
248
|
+
});
|
|
249
|
+
app.post("/admin/pools", async (req, reply) => {
|
|
250
|
+
const body = req.body ?? {};
|
|
251
|
+
if (!body.id?.trim()) {
|
|
252
|
+
reply.code(400).send({ error: { message: "Pool ID is required" } });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const existing = await (0, repository_2.listPools)(paths);
|
|
256
|
+
if (existing.some((p) => p.id === body.id)) {
|
|
257
|
+
reply.code(409).send({ error: { message: "A pool with this ID already exists" } });
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const pool = {
|
|
261
|
+
id: body.id.trim(),
|
|
262
|
+
name: body.name?.trim() || body.id.trim(),
|
|
263
|
+
aliases: body.aliases ?? [body.id.trim()],
|
|
264
|
+
enabled: body.enabled !== false,
|
|
265
|
+
strategy: body.strategy ?? "highest_rank_available",
|
|
266
|
+
requiredInput: body.requiredInput ?? [],
|
|
267
|
+
requiredOutput: body.requiredOutput ?? [],
|
|
268
|
+
scoreFallback: typeof body.scoreFallback === "number" ? body.scoreFallback : 20,
|
|
269
|
+
candidates: [],
|
|
270
|
+
candidateSelection: body.candidateSelection ?? [],
|
|
271
|
+
userDefined: true,
|
|
272
|
+
updatedAt: new Date().toISOString(),
|
|
273
|
+
};
|
|
274
|
+
existing.push(pool);
|
|
275
|
+
await (0, repository_2.savePools)(paths, existing);
|
|
276
|
+
reply.code(201).send(pool);
|
|
277
|
+
});
|
|
278
|
+
app.put("/admin/pools/:id", async (req, reply) => {
|
|
279
|
+
const { id } = req.params;
|
|
280
|
+
const body = req.body ?? {};
|
|
281
|
+
const pools = await (0, repository_2.listPools)(paths);
|
|
282
|
+
const idx = pools.findIndex((p) => p.id === id);
|
|
283
|
+
if (idx === -1) {
|
|
284
|
+
reply.code(404).send({ error: { message: "Pool not found" } });
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const existing = pools[idx];
|
|
288
|
+
if (!existing.userDefined) {
|
|
289
|
+
reply.code(403).send({ error: { message: "Cannot modify auto-generated pools" } });
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
pools[idx] = {
|
|
293
|
+
...existing,
|
|
294
|
+
name: body.name !== undefined ? body.name.trim() : existing.name,
|
|
295
|
+
aliases: body.aliases ?? existing.aliases,
|
|
296
|
+
enabled: body.enabled !== undefined ? body.enabled : existing.enabled,
|
|
297
|
+
strategy: body.strategy ?? existing.strategy,
|
|
298
|
+
requiredInput: body.requiredInput ?? existing.requiredInput,
|
|
299
|
+
requiredOutput: body.requiredOutput ?? existing.requiredOutput,
|
|
300
|
+
scoreFallback: typeof body.scoreFallback === "number" ? body.scoreFallback : existing.scoreFallback,
|
|
301
|
+
candidateSelection: body.candidateSelection ?? existing.candidateSelection,
|
|
302
|
+
updatedAt: new Date().toISOString(),
|
|
303
|
+
};
|
|
304
|
+
await (0, repository_2.savePools)(paths, pools);
|
|
305
|
+
reply.send(pools[idx]);
|
|
306
|
+
});
|
|
307
|
+
app.delete("/admin/pools/:id", async (req, reply) => {
|
|
308
|
+
const { id } = req.params;
|
|
309
|
+
const pools = await (0, repository_2.listPools)(paths);
|
|
310
|
+
const idx = pools.findIndex((p) => p.id === id);
|
|
311
|
+
if (idx === -1) {
|
|
312
|
+
reply.code(404).send({ error: { message: "Pool not found" } });
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (!pools[idx].userDefined) {
|
|
316
|
+
reply.code(403).send({ error: { message: "Cannot delete auto-generated pools" } });
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
pools.splice(idx, 1);
|
|
320
|
+
await (0, repository_2.savePools)(paths, pools);
|
|
321
|
+
reply.send({ deleted: id });
|
|
322
|
+
});
|
|
323
|
+
app.post("/admin/pools/:id/toggle", async (req, reply) => {
|
|
324
|
+
const { id } = req.params;
|
|
325
|
+
const pools = await (0, repository_2.listPools)(paths);
|
|
326
|
+
const pool = pools.find((p) => p.id === id);
|
|
327
|
+
if (!pool) {
|
|
328
|
+
reply.code(404).send({ error: { message: "Pool not found" } });
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
pool.enabled = !pool.enabled;
|
|
332
|
+
pool.updatedAt = new Date().toISOString();
|
|
333
|
+
await (0, repository_2.savePools)(paths, pools);
|
|
334
|
+
reply.send(pool);
|
|
335
|
+
});
|
|
336
|
+
app.post("/admin/pools/rebuild", async (_req, reply) => {
|
|
337
|
+
const pools = await (0, builder_1.rebuildDefaultPools)(paths);
|
|
338
|
+
reply.send({ rebuilt: pools.length, pools });
|
|
339
|
+
});
|
|
340
|
+
app.post("/admin/benchmarks/runs", async (req, reply) => {
|
|
341
|
+
if ((0, jobs_1.hasRunningBenchmarkRun)()) {
|
|
342
|
+
reply.code(409).send({
|
|
343
|
+
error: { message: "A benchmark run is already in progress" },
|
|
344
|
+
});
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const body = req.body ?? {};
|
|
348
|
+
const run = await (0, jobs_1.startBenchmarkRun)(paths, {
|
|
349
|
+
suite: body.suite,
|
|
350
|
+
exampleId: body.exampleId,
|
|
351
|
+
scenarioPath: body.scenarioPath,
|
|
352
|
+
modelOverride: body.modelOverride,
|
|
353
|
+
outPath: body.outPath,
|
|
354
|
+
configPath: body.configPath,
|
|
355
|
+
profile: body.profile,
|
|
356
|
+
baselinePath: body.baselinePath,
|
|
357
|
+
executionMode: body.executionMode,
|
|
358
|
+
updateCapCache: body.updateCapCache,
|
|
359
|
+
capTtlDays: body.capTtlDays,
|
|
360
|
+
temperature: body.temperature,
|
|
361
|
+
top_p: body.top_p,
|
|
362
|
+
max_tokens: body.max_tokens,
|
|
363
|
+
presence_penalty: body.presence_penalty,
|
|
364
|
+
frequency_penalty: body.frequency_penalty,
|
|
365
|
+
seed: body.seed,
|
|
366
|
+
stop: body.stop,
|
|
367
|
+
});
|
|
368
|
+
reply.code(202).send(run);
|
|
369
|
+
});
|
|
370
|
+
app.get("/admin/benchmarks/runs", async (_req, reply) => {
|
|
371
|
+
const items = await (0, jobs_1.listBenchmarkRuns)(paths);
|
|
372
|
+
reply.send({
|
|
373
|
+
object: "list",
|
|
374
|
+
data: items,
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
app.get("/admin/benchmarks/examples", async (req, reply) => {
|
|
378
|
+
const suite = (req.query?.suite ?? "showcase").trim() || "showcase";
|
|
379
|
+
reply.send({
|
|
380
|
+
object: "list",
|
|
381
|
+
suite,
|
|
382
|
+
data: (0, runner_1.listBenchmarkExamples)(suite),
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
app.get("/admin/benchmarks/runs/:id", async (req, reply) => {
|
|
386
|
+
const { id } = req.params;
|
|
387
|
+
const run = (0, jobs_1.getBenchmarkRun)(id);
|
|
388
|
+
if (run) {
|
|
389
|
+
reply.send(run);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const historical = await (0, jobs_1.getArtifactBenchmarkRun)(paths, id);
|
|
393
|
+
if (!historical) {
|
|
394
|
+
reply.code(404).send({ error: { message: "benchmark run not found" } });
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
reply.send(historical);
|
|
398
|
+
});
|
|
399
|
+
app.get("/admin/benchmarks/runs/:id/events", async (req, reply) => {
|
|
400
|
+
const { id } = req.params;
|
|
401
|
+
const run = (0, jobs_1.getBenchmarkRun)(id);
|
|
402
|
+
if (!run) {
|
|
403
|
+
reply.code(404).send({ error: { message: "benchmark run not found" } });
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
reply.raw.writeHead(200, {
|
|
407
|
+
"Content-Type": "text/event-stream",
|
|
408
|
+
"Cache-Control": "no-cache, no-transform",
|
|
409
|
+
Connection: "keep-alive",
|
|
410
|
+
"X-Accel-Buffering": "no",
|
|
411
|
+
});
|
|
412
|
+
const sendEvent = (event) => {
|
|
413
|
+
reply.raw.write(`data: ${JSON.stringify(event)}\n\n`);
|
|
414
|
+
};
|
|
415
|
+
for (const event of (0, jobs_1.listBenchmarkRunEvents)(id)) {
|
|
416
|
+
sendEvent(event);
|
|
417
|
+
}
|
|
418
|
+
const unsubscribe = (0, jobs_1.subscribeBenchmarkRunEvents)(id, (event) => {
|
|
419
|
+
sendEvent(event);
|
|
420
|
+
});
|
|
421
|
+
const heartbeat = setInterval(() => {
|
|
422
|
+
reply.raw.write(": ping\n\n");
|
|
423
|
+
}, 15_000);
|
|
424
|
+
req.raw.on("close", () => {
|
|
425
|
+
clearInterval(heartbeat);
|
|
426
|
+
unsubscribe();
|
|
427
|
+
reply.raw.end();
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
app.get("/admin/benchmarks/capabilities", async (req, reply) => {
|
|
431
|
+
const ttlParam = Number(req.query?.ttlDays);
|
|
432
|
+
const ttlDays = Number.isFinite(ttlParam) && ttlParam > 0 ? Math.floor(ttlParam) : 7;
|
|
433
|
+
const data = await (0, capabilityStore_1.listCapabilitySnapshots)(paths, ttlDays);
|
|
434
|
+
reply.send((0, capabilityStore_1.toCapabilityMatrix)(data));
|
|
435
|
+
});
|
|
436
|
+
app.get("/admin/benchmarks/capabilities/:modelId", async (req, reply) => {
|
|
437
|
+
const { modelId } = req.params;
|
|
438
|
+
const ttlParam = Number(req.query?.ttlDays);
|
|
439
|
+
const ttlDays = Number.isFinite(ttlParam) && ttlParam > 0 ? Math.floor(ttlParam) : 7;
|
|
440
|
+
const model = await (0, capabilityStore_1.getCapabilitySnapshotByModel)(paths, modelId, ttlDays);
|
|
441
|
+
if (!model) {
|
|
442
|
+
reply.code(404).send({ error: { message: "capability snapshot not found" } });
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
reply.send(model);
|
|
446
|
+
});
|
|
447
|
+
app.get("/admin/capture/config", async (_req, reply) => {
|
|
448
|
+
const config = await (0, captureRepository_1.getCaptureConfig)(paths);
|
|
449
|
+
reply.send(config);
|
|
450
|
+
});
|
|
451
|
+
app.put("/admin/capture/config", async (req, reply) => {
|
|
452
|
+
const next = await (0, captureRepository_1.updateCaptureConfig)(paths, req.body ?? {});
|
|
453
|
+
reply.send(next);
|
|
454
|
+
});
|
|
455
|
+
app.get("/admin/capture/records", async (req, reply) => {
|
|
456
|
+
const query = req.query;
|
|
457
|
+
const parsed = Number(query?.limit);
|
|
458
|
+
const limit = Number.isFinite(parsed) ? Math.max(1, Math.min(50, Math.floor(parsed))) : 5;
|
|
459
|
+
const offsetParsed = Number(query?.offset);
|
|
460
|
+
const offset = Number.isFinite(offsetParsed) ? Math.max(0, Math.floor(offsetParsed)) : 0;
|
|
461
|
+
const timeZone = normalizeTimeZone(query?.timeZone);
|
|
462
|
+
const result = await (0, captureRepository_1.listCaptureRecords)(paths, {
|
|
463
|
+
limit,
|
|
464
|
+
offset,
|
|
465
|
+
date: typeof query?.date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(query.date) ? query.date : undefined,
|
|
466
|
+
timeZone,
|
|
467
|
+
});
|
|
468
|
+
reply.send({ object: "list", data: result.data, total: result.total });
|
|
469
|
+
});
|
|
470
|
+
app.get("/admin/capture/calendar", async (req, reply) => {
|
|
471
|
+
const query = req.query;
|
|
472
|
+
const timeZone = normalizeTimeZone(query?.timeZone);
|
|
473
|
+
const month = typeof query?.month === "string" && /^\d{4}-\d{2}$/.test(query.month)
|
|
474
|
+
? query.month
|
|
475
|
+
: formatDateForTimeZone(new Date(), timeZone).slice(0, 7);
|
|
476
|
+
const days = await (0, captureRepository_1.getCaptureCalendarMonth)(paths, month, timeZone);
|
|
477
|
+
reply.send({ month, days });
|
|
478
|
+
});
|
|
479
|
+
app.get("/admin/capture/records/:id", async (req, reply) => {
|
|
480
|
+
const { id } = req.params;
|
|
481
|
+
const record = await (0, captureRepository_1.getCaptureRecordById)(paths, id);
|
|
482
|
+
if (!record) {
|
|
483
|
+
reply.code(404).send({ error: { message: "capture record not found" } });
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
reply.send(record);
|
|
487
|
+
});
|
|
488
|
+
app.get("/admin/capture/blobs/:hash", async (req, reply) => {
|
|
489
|
+
const { hash } = req.params;
|
|
490
|
+
const located = await (0, captureRepository_1.findCaptureBlobPath)(paths, hash);
|
|
491
|
+
if (!located) {
|
|
492
|
+
reply.code(404).send({ error: { message: "capture blob not found" } });
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
const buffer = await fs_1.promises.readFile(located.path);
|
|
496
|
+
reply.header("content-type", located.mime);
|
|
497
|
+
reply.send(buffer);
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
function isAuthorized(req, token) {
|
|
501
|
+
if (token) {
|
|
502
|
+
const header = req.headers.authorization ?? "";
|
|
503
|
+
return header === `Bearer ${token}`;
|
|
504
|
+
}
|
|
505
|
+
const remote = req.socket.remoteAddress ?? "";
|
|
506
|
+
return remote === "127.0.0.1" || remote === "::1";
|
|
507
|
+
}
|
|
508
|
+
function formatDateForTimeZone(value, timeZone) {
|
|
509
|
+
const formatter = new Intl.DateTimeFormat("en-CA", {
|
|
510
|
+
timeZone,
|
|
511
|
+
year: "numeric",
|
|
512
|
+
month: "2-digit",
|
|
513
|
+
day: "2-digit",
|
|
514
|
+
});
|
|
515
|
+
const parts = formatter.formatToParts(value);
|
|
516
|
+
const year = parts.find((part) => part.type === "year")?.value ?? "0000";
|
|
517
|
+
const month = parts.find((part) => part.type === "month")?.value ?? "00";
|
|
518
|
+
const day = parts.find((part) => part.type === "day")?.value ?? "00";
|
|
519
|
+
return `${year}-${month}-${day}`;
|
|
520
|
+
}
|
|
521
|
+
function normalizeTimeZone(input) {
|
|
522
|
+
if (!input)
|
|
523
|
+
return "UTC";
|
|
524
|
+
try {
|
|
525
|
+
new Intl.DateTimeFormat("en-US", { timeZone: input });
|
|
526
|
+
return input;
|
|
527
|
+
}
|
|
528
|
+
catch {
|
|
529
|
+
return "UTC";
|
|
530
|
+
}
|
|
531
|
+
}
|