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.
Files changed (260) hide show
  1. package/.github/instructions/ui.instructions.md +42 -0
  2. package/.github/workflows/ci.yml +35 -0
  3. package/.github/workflows/publish.yml +71 -0
  4. package/.github/workflows/release.yml +48 -0
  5. package/.playwright-mcp/console-2026-04-04T01-41-10-746Z.log +2 -0
  6. package/.playwright-mcp/console-2026-04-04T01-41-28-799Z.log +3 -0
  7. package/.playwright-mcp/console-2026-04-05T02-26-51-909Z.log +76 -0
  8. package/.playwright-mcp/page-2026-04-04T01-41-10-816Z.yml +1 -0
  9. package/.playwright-mcp/page-2026-04-04T01-41-29-141Z.yml +77 -0
  10. package/.playwright-mcp/page-2026-04-04T01-41-42-633Z.yml +190 -0
  11. package/.playwright-mcp/page-2026-04-04T01-42-03-929Z.yml +262 -0
  12. package/.playwright-mcp/page-2026-04-04T02-12-54-813Z.yml +6 -0
  13. package/.playwright-mcp/page-2026-04-04T02-14-58-600Z.yml +190 -0
  14. package/.playwright-mcp/page-2026-04-04T02-15-03-923Z.yml +190 -0
  15. package/.playwright-mcp/page-2026-04-04T02-15-07-426Z.yml +190 -0
  16. package/.playwright-mcp/page-2026-04-04T02-15-25-729Z.yml +262 -0
  17. package/.playwright-mcp/page-2026-04-04T02-16-22-984Z.yml +262 -0
  18. package/.playwright-mcp/page-2026-04-04T02-17-00-599Z.yml +190 -0
  19. package/.playwright-mcp/page-2026-04-04T02-17-50-874Z.yml +190 -0
  20. package/.playwright-mcp/page-2026-04-05T02-26-55-570Z.yml +6 -0
  21. package/AGENTS.md +48 -0
  22. package/CHANGELOG.md +131 -0
  23. package/README.md +552 -0
  24. package/assets/agent-mode.png +0 -0
  25. package/assets/categorize.png +0 -0
  26. package/assets/dashboard.png +0 -0
  27. package/assets/endpoint-proxy.png +0 -0
  28. package/assets/icon.png +0 -0
  29. package/assets/mcp-generate-image.png +0 -0
  30. package/assets/mcp-understand-image.png +0 -0
  31. package/assets/peek-token-flow.png +0 -0
  32. package/assets/playground.png +0 -0
  33. package/assets/sankey.png +0 -0
  34. package/cli/index.ts +2805 -0
  35. package/cli/legacyRewrite.ts +108 -0
  36. package/cli/modelRef.ts +24 -0
  37. package/dist/cli/index.js +2536 -0
  38. package/dist/cli/legacyRewrite.js +92 -0
  39. package/dist/cli/modelRef.js +20 -0
  40. package/dist/src/benchmark/artifacts.js +131 -0
  41. package/dist/src/benchmark/capabilityClassifier.js +81 -0
  42. package/dist/src/benchmark/capabilityStore.js +144 -0
  43. package/dist/src/benchmark/config.js +238 -0
  44. package/dist/src/benchmark/gates.js +118 -0
  45. package/dist/src/benchmark/jobs.js +252 -0
  46. package/dist/src/benchmark/runner.js +1847 -0
  47. package/dist/src/benchmark/schema.js +353 -0
  48. package/dist/src/benchmark/suites.js +314 -0
  49. package/dist/src/benchmark/tinyQaDataset.js +422 -0
  50. package/dist/src/benchmark/types.js +25 -0
  51. package/dist/src/config.js +47 -0
  52. package/dist/src/index.js +178 -0
  53. package/dist/src/mcp/client.js +215 -0
  54. package/dist/src/mcp/discovery.js +226 -0
  55. package/dist/src/mcp/policy.js +65 -0
  56. package/dist/src/mcp/registry.js +129 -0
  57. package/dist/src/mcp/service.js +460 -0
  58. package/dist/src/middleware/auth.js +179 -0
  59. package/dist/src/middleware/requestCapture.js +192 -0
  60. package/dist/src/middleware/requestStats.js +118 -0
  61. package/dist/src/pools/builder.js +132 -0
  62. package/dist/src/pools/repository.js +69 -0
  63. package/dist/src/pools/scheduler.js +360 -0
  64. package/dist/src/pools/types.js +2 -0
  65. package/dist/src/protocols/adapters/dashscope.js +267 -0
  66. package/dist/src/protocols/adapters/inferenceV2.js +346 -0
  67. package/dist/src/protocols/adapters/openai.js +27 -0
  68. package/dist/src/protocols/registry.js +99 -0
  69. package/dist/src/protocols/types.js +2 -0
  70. package/dist/src/providers/health.js +153 -0
  71. package/dist/src/providers/importer.js +289 -0
  72. package/dist/src/providers/modelRegistry.js +313 -0
  73. package/dist/src/providers/repository.js +361 -0
  74. package/dist/src/providers/types.js +2 -0
  75. package/dist/src/routes/admin.js +531 -0
  76. package/dist/src/routes/audio.js +295 -0
  77. package/dist/src/routes/chat.js +240 -0
  78. package/dist/src/routes/embeddings.js +157 -0
  79. package/dist/src/routes/images.js +288 -0
  80. package/dist/src/routes/mcp.js +256 -0
  81. package/dist/src/routes/mcpService.js +100 -0
  82. package/dist/src/routes/models.js +48 -0
  83. package/dist/src/routes/responses.js +711 -0
  84. package/dist/src/routes/sessions.js +450 -0
  85. package/dist/src/routes/stats.js +270 -0
  86. package/dist/src/routes/ui.js +97 -0
  87. package/dist/src/routes/videos.js +107 -0
  88. package/dist/src/routing/router.js +338 -0
  89. package/dist/src/services/imageGeneration.js +280 -0
  90. package/dist/src/services/imageUnderstanding.js +352 -0
  91. package/dist/src/services/videoGeneration.js +79 -0
  92. package/dist/src/storage/captureRepository.js +1591 -0
  93. package/dist/src/storage/files.js +157 -0
  94. package/dist/src/storage/imageCache.js +346 -0
  95. package/dist/src/storage/repositories.js +388 -0
  96. package/dist/src/storage/sessionRepository.js +370 -0
  97. package/dist/src/storage/statsRepository.js +204 -0
  98. package/dist/src/transport/httpClient.js +126 -0
  99. package/dist/src/types.js +2 -0
  100. package/dist/src/utils/messageMedia.js +285 -0
  101. package/dist/src/utils/modelCapabilities.js +108 -0
  102. package/dist/src/utils/modelDiscovery.js +170 -0
  103. package/dist/src/version.js +5 -0
  104. package/dist/src/workers/captureRetention.js +25 -0
  105. package/dist/src/workers/configWatcher.js +91 -0
  106. package/dist/src/workers/healthChecker.js +21 -0
  107. package/dist/src/workers/statsRotation.js +41 -0
  108. package/docs/LLM/output_schema.md +312 -0
  109. package/docs/benchmark.md +208 -0
  110. package/docs/mcp-guidelines.md +125 -0
  111. package/docs/mcp-service.md +178 -0
  112. package/docs/opencode.md +86 -0
  113. package/docs/providers.md +79 -0
  114. package/examples/benchmark.config.yaml +28 -0
  115. package/examples/providers/alibaba-dashscope.yaml +88 -0
  116. package/examples/providers/alibaba-llm.yaml +64 -0
  117. package/examples/providers/alibaba-registry.yaml +7 -0
  118. package/examples/providers/inference-v2-ray.yaml +29 -0
  119. package/examples/scenarios/assets/omni-call-sample.wav +0 -0
  120. package/examples/scenarios/custom.jsonl +5 -0
  121. package/examples/scenarios/custom.yaml +40 -0
  122. package/model-form-v2.png +0 -0
  123. package/package.json +66 -0
  124. package/provider-form-v2.png +0 -0
  125. package/provider-form.png +0 -0
  126. package/scripts/manual-test.sh +11 -0
  127. package/scripts/version-from-git.js +23 -0
  128. package/src/benchmark/artifacts.ts +149 -0
  129. package/src/benchmark/capabilityClassifier.ts +99 -0
  130. package/src/benchmark/capabilityStore.ts +174 -0
  131. package/src/benchmark/config.ts +337 -0
  132. package/src/benchmark/gates.ts +164 -0
  133. package/src/benchmark/jobs.ts +312 -0
  134. package/src/benchmark/runner.ts +2519 -0
  135. package/src/benchmark/schema.ts +443 -0
  136. package/src/benchmark/suites.ts +323 -0
  137. package/src/benchmark/tinyQaDataset.ts +428 -0
  138. package/src/benchmark/types.ts +442 -0
  139. package/src/config.ts +44 -0
  140. package/src/index.ts +195 -0
  141. package/src/mcp/client.ts +305 -0
  142. package/src/mcp/discovery.ts +266 -0
  143. package/src/mcp/policy.ts +105 -0
  144. package/src/mcp/registry.ts +164 -0
  145. package/src/mcp/service.ts +611 -0
  146. package/src/middleware/auth.ts +251 -0
  147. package/src/middleware/requestCapture.ts +245 -0
  148. package/src/middleware/requestStats.ts +163 -0
  149. package/src/pools/builder.ts +159 -0
  150. package/src/pools/repository.ts +71 -0
  151. package/src/pools/scheduler.ts +425 -0
  152. package/src/pools/types.ts +117 -0
  153. package/src/protocols/adapters/dashscope.ts +335 -0
  154. package/src/protocols/adapters/inferenceV2.ts +428 -0
  155. package/src/protocols/adapters/openai.ts +32 -0
  156. package/src/protocols/registry.ts +117 -0
  157. package/src/protocols/types.ts +81 -0
  158. package/src/providers/health.ts +207 -0
  159. package/src/providers/importer.ts +402 -0
  160. package/src/providers/modelRegistry.ts +415 -0
  161. package/src/providers/repository.ts +439 -0
  162. package/src/providers/types.ts +113 -0
  163. package/src/routes/admin.ts +666 -0
  164. package/src/routes/audio.ts +372 -0
  165. package/src/routes/chat.ts +301 -0
  166. package/src/routes/embeddings.ts +197 -0
  167. package/src/routes/images.ts +356 -0
  168. package/src/routes/mcp.ts +320 -0
  169. package/src/routes/mcpService.ts +114 -0
  170. package/src/routes/models.ts +50 -0
  171. package/src/routes/responses.ts +872 -0
  172. package/src/routes/sessions.ts +558 -0
  173. package/src/routes/stats.ts +312 -0
  174. package/src/routes/ui.ts +96 -0
  175. package/src/routes/videos.ts +132 -0
  176. package/src/routing/router.ts +501 -0
  177. package/src/services/imageGeneration.ts +396 -0
  178. package/src/services/imageUnderstanding.ts +449 -0
  179. package/src/services/videoGeneration.ts +127 -0
  180. package/src/storage/captureRepository.ts +1835 -0
  181. package/src/storage/files.ts +178 -0
  182. package/src/storage/imageCache.ts +405 -0
  183. package/src/storage/repositories.ts +494 -0
  184. package/src/storage/sessionRepository.ts +419 -0
  185. package/src/storage/statsRepository.ts +238 -0
  186. package/src/transport/httpClient.ts +145 -0
  187. package/src/types.ts +322 -0
  188. package/src/utils/messageMedia.ts +293 -0
  189. package/src/utils/modelCapabilities.ts +161 -0
  190. package/src/utils/modelDiscovery.ts +203 -0
  191. package/src/workers/captureRetention.ts +25 -0
  192. package/src/workers/configWatcher.ts +115 -0
  193. package/src/workers/healthChecker.ts +22 -0
  194. package/src/workers/statsRotation.ts +49 -0
  195. package/tests/benchmarkAdminRoutes.test.ts +82 -0
  196. package/tests/benchmarkBasics.test.ts +116 -0
  197. package/tests/captureAdminRoutes.test.ts +420 -0
  198. package/tests/captureRepository.test.ts +797 -0
  199. package/tests/cliLegacyRewrite.test.ts +45 -0
  200. package/tests/imageGeneration.service.test.ts +107 -0
  201. package/tests/imageUnderstanding.service.test.ts +123 -0
  202. package/tests/mcpPolicy.test.ts +105 -0
  203. package/tests/mcpService.test.ts +1245 -0
  204. package/tests/modelRef.test.ts +23 -0
  205. package/tests/modelsRoutes.test.ts +154 -0
  206. package/tests/sessionMediaCache.test.ts +167 -0
  207. package/tests/statsRoutes.test.ts +323 -0
  208. package/tsconfig.json +15 -0
  209. package/ui/index.html +16 -0
  210. package/ui/package-lock.json +8521 -0
  211. package/ui/package.json +52 -0
  212. package/ui/postcss.config.js +6 -0
  213. package/ui/public/assets/apple-touch-icon.png +0 -0
  214. package/ui/public/assets/favicon-16.png +0 -0
  215. package/ui/public/assets/favicon-32.png +0 -0
  216. package/ui/public/assets/icon-192.png +0 -0
  217. package/ui/public/assets/icon-512.png +0 -0
  218. package/ui/src/App.tsx +27 -0
  219. package/ui/src/api/client.ts +1503 -0
  220. package/ui/src/components/EndpointUsageGuide.tsx +361 -0
  221. package/ui/src/components/Layout.tsx +124 -0
  222. package/ui/src/components/MessageContent.tsx +365 -0
  223. package/ui/src/components/ToolCallMessage.tsx +179 -0
  224. package/ui/src/components/ToolPicker.tsx +442 -0
  225. package/ui/src/components/messageContentParser.test.ts +41 -0
  226. package/ui/src/components/messageContentParser.ts +73 -0
  227. package/ui/src/components/thinkingPreview.test.ts +27 -0
  228. package/ui/src/components/thinkingPreview.ts +15 -0
  229. package/ui/src/components/toMermaidSankey.test.ts +78 -0
  230. package/ui/src/components/toMermaidSankey.ts +56 -0
  231. package/ui/src/components/ui/button.tsx +58 -0
  232. package/ui/src/components/ui/input.tsx +21 -0
  233. package/ui/src/components/ui/textarea.tsx +21 -0
  234. package/ui/src/lib/utils.ts +6 -0
  235. package/ui/src/main.tsx +9 -0
  236. package/ui/src/pages/AgentPlayground.tsx +2010 -0
  237. package/ui/src/pages/Benchmark.tsx +988 -0
  238. package/ui/src/pages/Dashboard.tsx +581 -0
  239. package/ui/src/pages/Peek.tsx +962 -0
  240. package/ui/src/pages/Settings.tsx +2013 -0
  241. package/ui/src/pages/agentPlaygroundPayload.test.ts +109 -0
  242. package/ui/src/pages/agentPlaygroundPayload.ts +97 -0
  243. package/ui/src/pages/agentThinkingContent.test.ts +50 -0
  244. package/ui/src/pages/agentThinkingContent.ts +57 -0
  245. package/ui/src/pages/dashboardTokenUsage.test.ts +66 -0
  246. package/ui/src/pages/dashboardTokenUsage.ts +36 -0
  247. package/ui/src/pages/imageUpload.test.ts +39 -0
  248. package/ui/src/pages/imageUpload.ts +71 -0
  249. package/ui/src/pages/peekFilters.test.ts +29 -0
  250. package/ui/src/pages/peekFilters.ts +13 -0
  251. package/ui/src/pages/peekMedia.test.ts +58 -0
  252. package/ui/src/pages/peekMedia.ts +148 -0
  253. package/ui/src/pages/sessionAutoTitle.test.ts +128 -0
  254. package/ui/src/pages/sessionAutoTitle.ts +106 -0
  255. package/ui/src/stores/settings.ts +58 -0
  256. package/ui/src/styles/globals.css +223 -0
  257. package/ui/src/vite-env.d.ts +8 -0
  258. package/ui/tailwind.config.js +106 -0
  259. package/ui/tsconfig.json +32 -0
  260. package/ui/vite.config.ts +37 -0
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ BASE_URL=${BASE_URL:-http://localhost:9469}
5
+ MODEL=${MODEL:-local-default}
6
+
7
+ curl -sS "$BASE_URL/v1/models" | jq .
8
+
9
+ curl -sS "$BASE_URL/v1/chat/completions" \
10
+ -H "Content-Type: application/json" \
11
+ -d '{"model":"'"$MODEL"'","messages":[{"role":"user","content":"Hello"}]}' | jq .
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require("child_process");
3
+ const { writeFileSync } = require("fs");
4
+ const { join } = require("path");
5
+
6
+ const root = join(__dirname, "..");
7
+
8
+ let version;
9
+ try {
10
+ version = execSync("git describe --tags --abbrev=0", {
11
+ cwd: root,
12
+ encoding: "utf8",
13
+ }).trim();
14
+ if (version.startsWith("v")) version = version.slice(1);
15
+ } catch {
16
+ version = "0.0.0";
17
+ }
18
+
19
+ const content = `// Auto-generated from git tags. Do not edit manually.
20
+ export const VERSION = ${JSON.stringify(version)};
21
+ `;
22
+
23
+ writeFileSync(join(root, "src", "version.ts"), content, "utf8");
@@ -0,0 +1,149 @@
1
+ import { promises as fs } from "fs";
2
+ import path from "path";
3
+ import { StoragePaths } from "../storage/files";
4
+ import { BenchmarkReport } from "./types";
5
+
6
+ export async function writeBenchmarkArtifacts(
7
+ paths: StoragePaths,
8
+ report: BenchmarkReport,
9
+ outPath?: string
10
+ ): Promise<{ jsonPath: string; textPath: string }> {
11
+ const timestamp = timestampForFileName();
12
+ const defaultDir = path.join(paths.baseDir, "benchmarks");
13
+ const destination = outPath && outPath.trim().length > 0 ? path.resolve(outPath) : defaultDir;
14
+
15
+ let jsonPath: string;
16
+ let textPath: string;
17
+
18
+ if (destination.endsWith(".json")) {
19
+ jsonPath = destination;
20
+ textPath = destination.replace(/\.json$/i, ".txt");
21
+ } else if (destination.endsWith(".txt")) {
22
+ textPath = destination;
23
+ jsonPath = destination.replace(/\.txt$/i, ".json");
24
+ } else {
25
+ jsonPath = path.join(destination, `bench-${timestamp}.json`);
26
+ textPath = path.join(destination, `bench-${timestamp}.txt`);
27
+ }
28
+
29
+ await fs.mkdir(path.dirname(jsonPath), { recursive: true });
30
+ await fs.mkdir(path.dirname(textPath), { recursive: true });
31
+
32
+ await fs.writeFile(jsonPath, JSON.stringify(report, null, 2), "utf8");
33
+ await fs.writeFile(textPath, renderTextSummary(report), "utf8");
34
+
35
+ return { jsonPath, textPath };
36
+ }
37
+
38
+ function renderTextSummary(report: BenchmarkReport): string {
39
+ const lines: string[] = [];
40
+
41
+ lines.push("Waypoi Benchmark Report");
42
+ lines.push(`Run ID: ${report.id}`);
43
+ lines.push(`Created: ${report.createdAt}`);
44
+ lines.push(`Profile: ${report.profile}`);
45
+ lines.push(`Mode: ${report.executionMode}`);
46
+ if (report.suite) lines.push(`Suite: ${report.suite}`);
47
+ if (report.exampleId) lines.push(`Example: ${report.exampleId}`);
48
+ if (report.scenarioPath) lines.push(`Scenario File: ${report.scenarioPath}`);
49
+ if (report.modelOverride) lines.push(`Model Override: ${report.modelOverride}`);
50
+ lines.push("");
51
+
52
+ lines.push("Overall");
53
+ lines.push(`- Scenarios: ${report.total}`);
54
+ lines.push(`- Executed: ${report.executed}`);
55
+ lines.push(`- Skipped: ${report.skipped}`);
56
+ lines.push(`- Success: ${report.succeeded}`);
57
+ lines.push(`- Failed: ${report.failed}`);
58
+ lines.push(`- Success Rate: ${(report.successRate * 100).toFixed(1)}%`);
59
+ lines.push(`- Avg Latency: ${report.avgLatencyMs}ms`);
60
+ lines.push(`- P95 Latency: ${report.p95LatencyMs}ms`);
61
+ lines.push(`- Tokens: ${report.totalTokens}`);
62
+ lines.push(`- Tool Calls: ${report.totalToolCalls}`);
63
+ lines.push(`- Throughput: ${report.avgThroughputTokensPerSec.toFixed(2)} tokens/s`);
64
+ lines.push("");
65
+
66
+ lines.push("Gates");
67
+ lines.push(`- Hard: ${report.gateResults.hard.passed ? "PASS" : "FAIL"}`);
68
+ for (const message of report.gateResults.hard.messages) {
69
+ lines.push(` - ${message}`);
70
+ }
71
+ lines.push(`- Soft: ${report.gateResults.soft.passed ? "PASS" : "WARN"}`);
72
+ for (const message of report.gateResults.soft.messages) {
73
+ lines.push(` - ${message}`);
74
+ }
75
+ lines.push("");
76
+
77
+ lines.push("By Mode");
78
+ for (const [mode, summary] of Object.entries(report.modeSummary)) {
79
+ lines.push(
80
+ `- ${mode}: total=${summary.total} executed=${summary.executed} skipped=${summary.skipped} passed=${summary.passed} failed=${summary.failed}`
81
+ );
82
+ }
83
+ lines.push("");
84
+
85
+ lines.push("Scenario Results");
86
+ for (const scenario of report.results) {
87
+ if (scenario.status === "skipped") {
88
+ lines.push(`- ${scenario.id} [${scenario.mode}] SKIPPED: ${scenario.skippedReason ?? "not applicable"}`);
89
+ continue;
90
+ }
91
+ lines.push(
92
+ `- ${scenario.id} [${scenario.mode}] ${scenario.status.toUpperCase()} passRate=${(scenario.passRate * 100).toFixed(1)}% p95=${scenario.p95LatencyMs}ms tokens=${scenario.totalTokens} tools=${scenario.totalToolCalls} attempts=${scenario.candidateAttempts} failovers=${scenario.failovers} rateLimitSwitches=${scenario.rateLimitSwitches}`
93
+ );
94
+ for (const reason of scenario.errorReasons) {
95
+ lines.push(` - ${reason}`);
96
+ }
97
+ }
98
+
99
+ if (report.scenarioDetails.length > 0) {
100
+ lines.push("");
101
+ lines.push("Showcase Details");
102
+ for (const detail of report.scenarioDetails) {
103
+ lines.push(`- ${detail.example?.title ?? detail.id} [${detail.status}]`);
104
+ lines.push(` model=${detail.model}`);
105
+ lines.push(` verdict=${detail.verdict}`);
106
+ if (detail.usedToolNames.length > 0) {
107
+ lines.push(` tools=${detail.usedToolNames.join(", ")}`);
108
+ }
109
+ if (detail.finalResponsePreview) {
110
+ lines.push(` final=${detail.finalResponsePreview}`);
111
+ }
112
+ }
113
+ }
114
+
115
+ if (report.topFailureReasons.length > 0) {
116
+ lines.push("");
117
+ lines.push("Top Failure Reasons");
118
+ for (const item of report.topFailureReasons) {
119
+ lines.push(`- ${item.reason} (${item.count})`);
120
+ }
121
+ }
122
+
123
+ if (report.warnings.length > 0) {
124
+ lines.push("");
125
+ lines.push("Warnings");
126
+ for (const warning of report.warnings) {
127
+ lines.push(`- ${warning}`);
128
+ }
129
+ }
130
+
131
+ if (report.capabilityMatrix && report.capabilityMatrix.models.length > 0) {
132
+ lines.push("");
133
+ lines.push("Capability Matrix");
134
+ lines.push(`- TTL Days: ${report.capabilityMatrix.ttlDays}`);
135
+ for (const model of report.capabilityMatrix.models) {
136
+ lines.push(`- ${model.model} (${model.freshness}) verified=${model.lastVerifiedAt}`);
137
+ lines.push(
138
+ ` chat=${model.findings.chat_basic.status} tools=${model.findings.chat_tool_calls.status} embed=${model.findings.embeddings.status} image=${model.findings.images_generation.status} audio_in=${model.findings.audio_transcription.status} audio_out=${model.findings.audio_speech.status}`
139
+ );
140
+ }
141
+ }
142
+
143
+ lines.push("");
144
+ return `${lines.join("\n")}\n`;
145
+ }
146
+
147
+ function timestampForFileName(): string {
148
+ return new Date().toISOString().replace(/[:.]/g, "-");
149
+ }
@@ -0,0 +1,99 @@
1
+ import { BenchmarkCapabilityStatus } from "./types";
2
+
3
+ const UNSUPPORTED_SIGNAL_PATTERNS = [
4
+ /unsupported/i,
5
+ /not\s+supported/i,
6
+ /not\s+implemented/i,
7
+ /unknown\s+parameter/i,
8
+ /invalid\s+parameter/i,
9
+ /unrecognized\s+parameter/i,
10
+ /does\s+not\s+support/i,
11
+ /modality\s+not\s+supported/i,
12
+ /endpoint\s+not\s+found/i,
13
+ /route\s+not\s+found/i,
14
+ ];
15
+
16
+ const MISCONFIGURED_SIGNAL_PATTERNS = [
17
+ /api\s*key/i,
18
+ /missing\s+api\s*key/i,
19
+ /authorization/i,
20
+ /unauthorized/i,
21
+ /forbidden/i,
22
+ /invalid\s+auth/i,
23
+ /invalid\s+api\s*key/i,
24
+ /model\s+not\s+found/i,
25
+ /unknown\s+model/i,
26
+ /no\s+such\s+model/i,
27
+ /credential/i,
28
+ /token/i,
29
+ ];
30
+
31
+ const TRANSIENT_SIGNAL_PATTERNS = [
32
+ /timeout/i,
33
+ /timed\s*out/i,
34
+ /econnreset/i,
35
+ /econnrefused/i,
36
+ /enotfound/i,
37
+ /network/i,
38
+ /temporar/i,
39
+ /rate\s*limit/i,
40
+ /too\s+many\s+requests/i,
41
+ ];
42
+
43
+ export interface CapabilityClassificationInput {
44
+ success: boolean;
45
+ statusCode?: number;
46
+ error?: string;
47
+ }
48
+
49
+ export function classifyCapabilityStatus(input: CapabilityClassificationInput): BenchmarkCapabilityStatus {
50
+ if (input.success) {
51
+ return "supported";
52
+ }
53
+
54
+ const statusCode = Number.isFinite(input.statusCode) ? input.statusCode : undefined;
55
+ const error = (input.error ?? "").toLowerCase();
56
+
57
+ if (statusCode === 401 || statusCode === 403) {
58
+ return "misconfigured";
59
+ }
60
+
61
+ if (statusCode === 404) {
62
+ if (MISCONFIGURED_SIGNAL_PATTERNS.some((pattern) => pattern.test(error))) {
63
+ return "misconfigured";
64
+ }
65
+ return "unsupported";
66
+ }
67
+
68
+ if (statusCode === 429) {
69
+ return "unknown";
70
+ }
71
+
72
+ if (statusCode !== undefined && statusCode >= 500) {
73
+ return "unknown";
74
+ }
75
+
76
+ if (statusCode === 400) {
77
+ if (MISCONFIGURED_SIGNAL_PATTERNS.some((pattern) => pattern.test(error))) {
78
+ return "misconfigured";
79
+ }
80
+ if (UNSUPPORTED_SIGNAL_PATTERNS.some((pattern) => pattern.test(error))) {
81
+ return "unsupported";
82
+ }
83
+ return "unknown";
84
+ }
85
+
86
+ if (MISCONFIGURED_SIGNAL_PATTERNS.some((pattern) => pattern.test(error))) {
87
+ return "misconfigured";
88
+ }
89
+
90
+ if (UNSUPPORTED_SIGNAL_PATTERNS.some((pattern) => pattern.test(error))) {
91
+ return "unsupported";
92
+ }
93
+
94
+ if (TRANSIENT_SIGNAL_PATTERNS.some((pattern) => pattern.test(error))) {
95
+ return "unknown";
96
+ }
97
+
98
+ return "unknown";
99
+ }
@@ -0,0 +1,174 @@
1
+ import { createHash } from "crypto";
2
+ import { promises as fs } from "fs";
3
+ import path from "path";
4
+ import { StoragePaths } from "../storage/files";
5
+ import {
6
+ BenchmarkCapabilityFreshness,
7
+ BenchmarkCapabilityMatrix,
8
+ BenchmarkCapabilityStatus,
9
+ BenchmarkModelCapabilitySnapshot,
10
+ } from "./types";
11
+
12
+ const DEFAULT_TTL_DAYS = 7;
13
+
14
+ export interface CapabilityStoreListResult {
15
+ generatedAt: string;
16
+ ttlDays: number;
17
+ models: BenchmarkModelCapabilitySnapshot[];
18
+ }
19
+
20
+ export function capabilityCacheDir(paths: StoragePaths): string {
21
+ return path.join(paths.baseDir, "capabilities");
22
+ }
23
+
24
+ export function computeConfigFingerprint(input: unknown): string {
25
+ const raw = JSON.stringify(input ?? {});
26
+ return createHash("sha256").update(raw).digest("hex").slice(0, 16);
27
+ }
28
+
29
+ export async function writeCapabilitySnapshots(
30
+ paths: StoragePaths,
31
+ snapshots: BenchmarkModelCapabilitySnapshot[]
32
+ ): Promise<void> {
33
+ const dir = capabilityCacheDir(paths);
34
+ await fs.mkdir(dir, { recursive: true });
35
+
36
+ for (const snapshot of snapshots) {
37
+ const filePath = path.join(dir, capabilityFileName(snapshot.providerId, snapshot.modelId));
38
+ await fs.writeFile(filePath, JSON.stringify(snapshot, null, 2), "utf8");
39
+ }
40
+ }
41
+
42
+ export async function listCapabilitySnapshots(
43
+ paths: StoragePaths,
44
+ ttlDays = DEFAULT_TTL_DAYS
45
+ ): Promise<CapabilityStoreListResult> {
46
+ const dir = capabilityCacheDir(paths);
47
+ let files: string[] = [];
48
+ try {
49
+ files = await fs.readdir(dir);
50
+ } catch (error) {
51
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") {
52
+ return {
53
+ generatedAt: new Date().toISOString(),
54
+ ttlDays,
55
+ models: [],
56
+ };
57
+ }
58
+ throw error;
59
+ }
60
+
61
+ const snapshots: BenchmarkModelCapabilitySnapshot[] = [];
62
+ for (const file of files) {
63
+ if (!file.endsWith(".json")) {
64
+ continue;
65
+ }
66
+
67
+ try {
68
+ const raw = await fs.readFile(path.join(dir, file), "utf8");
69
+ const parsed = JSON.parse(raw) as Partial<BenchmarkModelCapabilitySnapshot>;
70
+ const normalized = normalizeSnapshot(parsed, ttlDays);
71
+ if (normalized) {
72
+ snapshots.push(normalized);
73
+ }
74
+ } catch {
75
+ // Ignore malformed cache entries.
76
+ }
77
+ }
78
+
79
+ snapshots.sort((a, b) => `${a.providerId}/${a.modelId}`.localeCompare(`${b.providerId}/${b.modelId}`));
80
+
81
+ return {
82
+ generatedAt: new Date().toISOString(),
83
+ ttlDays,
84
+ models: snapshots,
85
+ };
86
+ }
87
+
88
+ export async function getCapabilitySnapshotByModel(
89
+ paths: StoragePaths,
90
+ model: string,
91
+ ttlDays = DEFAULT_TTL_DAYS
92
+ ): Promise<BenchmarkModelCapabilitySnapshot | null> {
93
+ const all = await listCapabilitySnapshots(paths, ttlDays);
94
+ return all.models.find((item) => item.model === model || `${item.providerId}/${item.modelId}` === model) ?? null;
95
+ }
96
+
97
+ function capabilityFileName(providerId: string, modelId: string): string {
98
+ return `${sanitizeSegment(providerId)}__${sanitizeSegment(modelId)}.json`;
99
+ }
100
+
101
+ function sanitizeSegment(value: string): string {
102
+ return value.replace(/[^a-zA-Z0-9._-]/g, "_");
103
+ }
104
+
105
+ function normalizeSnapshot(
106
+ input: Partial<BenchmarkModelCapabilitySnapshot>,
107
+ ttlDays: number
108
+ ): BenchmarkModelCapabilitySnapshot | null {
109
+ if (!input || typeof input !== "object") {
110
+ return null;
111
+ }
112
+ if (!input.providerId || !input.modelId || !input.model || !input.lastVerifiedAt) {
113
+ return null;
114
+ }
115
+
116
+ const verifiedAtMs = Date.parse(input.lastVerifiedAt);
117
+ if (!Number.isFinite(verifiedAtMs)) {
118
+ return null;
119
+ }
120
+
121
+ const ttlMs = ttlDays * 24 * 60 * 60 * 1000;
122
+ const expiresAt = input.expiresAt && Number.isFinite(Date.parse(input.expiresAt))
123
+ ? input.expiresAt
124
+ : new Date(verifiedAtMs + ttlMs).toISOString();
125
+ const freshness = computeFreshness(expiresAt);
126
+
127
+ return {
128
+ model: input.model,
129
+ providerId: input.providerId,
130
+ modelId: input.modelId,
131
+ configFingerprint: input.configFingerprint ?? "unknown",
132
+ confidence: clamp01(input.confidence ?? 0),
133
+ lastVerifiedAt: input.lastVerifiedAt,
134
+ expiresAt,
135
+ freshness,
136
+ findings: (input.findings ?? {}) as BenchmarkModelCapabilitySnapshot["findings"],
137
+ };
138
+ }
139
+
140
+ function computeFreshness(expiresAt: string): BenchmarkCapabilityFreshness {
141
+ const expiryMs = Date.parse(expiresAt);
142
+ if (!Number.isFinite(expiryMs)) {
143
+ return "stale";
144
+ }
145
+ return Date.now() <= expiryMs ? "fresh" : "stale";
146
+ }
147
+
148
+ function clamp01(value: number): number {
149
+ if (!Number.isFinite(value)) return 0;
150
+ if (value < 0) return 0;
151
+ if (value > 1) return 1;
152
+ return Number(value.toFixed(3));
153
+ }
154
+
155
+ export function statusRank(status: BenchmarkCapabilityStatus): number {
156
+ switch (status) {
157
+ case "supported":
158
+ return 4;
159
+ case "unsupported":
160
+ return 3;
161
+ case "misconfigured":
162
+ return 2;
163
+ case "unknown":
164
+ return 1;
165
+ }
166
+ }
167
+
168
+ export function toCapabilityMatrix(result: CapabilityStoreListResult): BenchmarkCapabilityMatrix {
169
+ return {
170
+ generatedAt: result.generatedAt,
171
+ ttlDays: result.ttlDays,
172
+ models: result.models,
173
+ };
174
+ }