ai-speedometer-headless 2.3.3 → 2.3.4

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.
@@ -3,17 +3,39 @@ import { createRequire } from "node:module";
3
3
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
4
4
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
5
 
6
+ // ../../node_modules/.bun/xdg-basedir@5.1.0/node_modules/xdg-basedir/index.js
7
+ import os from "os";
8
+ import path from "path";
9
+ var homeDirectory, env, xdgData, xdgConfig, xdgState, xdgCache, xdgRuntime, xdgDataDirectories, xdgConfigDirectories;
10
+ var init_xdg_basedir = __esm(() => {
11
+ homeDirectory = os.homedir();
12
+ ({ env } = process);
13
+ xdgData = env.XDG_DATA_HOME || (homeDirectory ? path.join(homeDirectory, ".local", "share") : undefined);
14
+ xdgConfig = env.XDG_CONFIG_HOME || (homeDirectory ? path.join(homeDirectory, ".config") : undefined);
15
+ xdgState = env.XDG_STATE_HOME || (homeDirectory ? path.join(homeDirectory, ".local", "state") : undefined);
16
+ xdgCache = env.XDG_CACHE_HOME || (homeDirectory ? path.join(homeDirectory, ".cache") : undefined);
17
+ xdgRuntime = env.XDG_RUNTIME_DIR || undefined;
18
+ xdgDataDirectories = (env.XDG_DATA_DIRS || "/usr/local/share/:/usr/share/").split(":");
19
+ if (xdgData) {
20
+ xdgDataDirectories.unshift(xdgData);
21
+ }
22
+ xdgConfigDirectories = (env.XDG_CONFIG_DIRS || "/etc/xdg").split(":");
23
+ if (xdgConfig) {
24
+ xdgConfigDirectories.unshift(xdgConfig);
25
+ }
26
+ });
27
+
6
28
  // ../core/src/ai-config.ts
7
29
  import fs2 from "fs";
8
- import path2 from "path";
9
- import { homedir as homedir2 } from "os";
30
+ import path3 from "path";
31
+ import { homedir as homedir3 } from "os";
10
32
  var getAIConfigPaths = () => {
11
- const aiConfigDir = process.env.XDG_CONFIG_HOME || path2.join(homedir2(), ".config");
12
- const aiSpeedometerConfigDir = path2.join(aiConfigDir, "ai-speedometer");
33
+ const aiConfigDir = process.env.XDG_CONFIG_HOME || xdgConfig || path3.join(homedir3(), ".config");
34
+ const aiSpeedometerConfigDir = path3.join(aiConfigDir, "ai-speedometer");
13
35
  return {
14
36
  configDir: aiSpeedometerConfigDir,
15
- configJson: path2.join(aiSpeedometerConfigDir, "ai-benchmark-config.json"),
16
- recentModelsCache: path2.join(aiSpeedometerConfigDir, "recent-models.json")
37
+ configJson: path3.join(aiSpeedometerConfigDir, "ai-benchmark-config.json"),
38
+ recentModelsCache: path3.join(aiSpeedometerConfigDir, "recent-models.json")
17
39
  };
18
40
  }, readAIConfig = async () => {
19
41
  const { configJson } = getAIConfigPaths();
@@ -31,17 +53,20 @@ var getAIConfigPaths = () => {
31
53
  const config = await readAIConfig();
32
54
  return config.customProviders || [];
33
55
  };
34
- var init_ai_config = () => {};
56
+ var init_ai_config = __esm(() => {
57
+ init_xdg_basedir();
58
+ });
35
59
 
36
60
  // ../core/src/opencode-integration.ts
61
+ init_xdg_basedir();
37
62
  import fs3 from "fs";
38
- import path3 from "path";
39
- import { homedir as homedir3 } from "os";
63
+ import path4 from "path";
40
64
 
41
65
  // ../core/src/models-dev.ts
66
+ init_xdg_basedir();
42
67
  import fs from "fs";
43
- import path from "path";
44
- import { homedir } from "os";
68
+ import path2 from "path";
69
+ import { homedir as homedir2 } from "os";
45
70
 
46
71
  // ../core/custom-verified-providers.json
47
72
  var custom_verified_providers_default = {
@@ -166,8 +191,9 @@ var custom_verified_providers_default = {
166
191
  };
167
192
 
168
193
  // ../core/src/models-dev.ts
169
- var CACHE_DIR = path.join(homedir(), ".cache", "ai-speedometer");
170
- var CACHE_FILE = path.join(CACHE_DIR, "models.json");
194
+ var cacheBase = process.env.XDG_CACHE_HOME || xdgCache || path2.join(homedir2(), ".cache");
195
+ var CACHE_DIR = path2.join(cacheBase, "ai-speedometer");
196
+ var CACHE_FILE = path2.join(CACHE_DIR, "models.json");
171
197
  var FALLBACK_PROVIDERS = [
172
198
  {
173
199
  id: "openai",
@@ -254,7 +280,7 @@ async function fetchFromAPI() {
254
280
  }
255
281
  function getCustomProvidersJson() {
256
282
  let data = custom_verified_providers_default;
257
- const customProvidersPath = path.join(process.cwd(), "custom-verified-providers.json");
283
+ const customProvidersPath = path2.join(process.cwd(), "custom-verified-providers.json");
258
284
  if (fs.existsSync(customProvidersPath)) {
259
285
  try {
260
286
  data = JSON.parse(fs.readFileSync(customProvidersPath, "utf8"));
@@ -361,14 +387,14 @@ async function getAllProviders() {
361
387
  init_ai_config();
362
388
  import { parse as parseJsonc } from "jsonc-parser";
363
389
  var getXDGPaths = () => ({
364
- data: path3.join(process.env.XDG_DATA_HOME || path3.join(homedir3(), ".local", "share"), "opencode"),
365
- config: path3.join(process.env.XDG_CONFIG_HOME || path3.join(homedir3(), ".config"), "opencode")
390
+ data: path4.join(process.env.XDG_DATA_HOME || xdgData || path4.join(path4.join(process.env.HOME || process.env.USERPROFILE || "."), ".local", "share"), "opencode"),
391
+ config: path4.join(process.env.XDG_CONFIG_HOME || xdgConfig || path4.join(path4.join(process.env.HOME || process.env.USERPROFILE || "."), ".config"), "opencode")
366
392
  });
367
393
  var getFilePaths = () => {
368
394
  const paths = getXDGPaths();
369
395
  return {
370
- authJson: path3.join(paths.data, "auth.json"),
371
- opencodeJson: path3.join(paths.config, "opencode.json")
396
+ authJson: path4.join(paths.data, "auth.json"),
397
+ opencodeJson: path4.join(paths.config, "opencode.json")
372
398
  };
373
399
  };
374
400
  var readAuthJson = async () => {
@@ -390,11 +416,11 @@ var readAuthJson = async () => {
390
416
  }
391
417
  };
392
418
  var readOpencodeGlobalConfig = () => {
393
- const configDir = path3.join(process.env.XDG_CONFIG_HOME || path3.join(homedir3(), ".config"), "opencode");
419
+ const configDir = path4.join(process.env.XDG_CONFIG_HOME || path4.join(homedir(), ".config"), "opencode");
394
420
  const candidates = ["config.json", "opencode.json", "opencode.jsonc"];
395
421
  let merged = {};
396
422
  for (const filename of candidates) {
397
- const filePath = path3.join(configDir, filename);
423
+ const filePath = path4.join(configDir, filename);
398
424
  try {
399
425
  if (!fs3.existsSync(filePath))
400
426
  continue;
@@ -542,6 +568,7 @@ var getAllAvailableProviders = async (includeAllProviders = false) => {
542
568
 
543
569
  // ../core/src/constants.ts
544
570
  import { execSync } from "child_process";
571
+ import { readFileSync } from "fs";
545
572
  var TEST_PROMPT = `Explain the concept of recursion in programming and provide a simple example in Python, in about 300 words. Do not use any tools — just reply in text.`;
546
573
  var PROMPT_BEAST = `You are opencode, an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user.
547
574
 
@@ -1560,10 +1587,10 @@ function getOpencodeVersion() {
1560
1587
  return v;
1561
1588
  } catch {
1562
1589
  try {
1563
- return execSync(`grep -E '^\\s*"version"' /home/idc/proj/opencode/packages/opencode/package.json | sed 's/.*: "\\([^"]*\\)".*/\\1/'`, {
1564
- encoding: "utf8",
1565
- stdio: ["ignore", "pipe", "ignore"]
1566
- }).trim();
1590
+ const pkgJson = readFileSync("/home/idc/proj/opencode/packages/opencode/package.json", "utf8");
1591
+ const parsed = JSON.parse(pkgJson);
1592
+ if (parsed.version)
1593
+ return parsed.version;
1567
1594
  } catch {}
1568
1595
  }
1569
1596
  return "1.14.37";
@@ -1714,11 +1741,24 @@ async function benchmarkSingleModelRest(model, logger) {
1714
1741
  };
1715
1742
  });
1716
1743
  }
1717
- const response = await fetch(url, {
1744
+ let response = await fetch(url, {
1718
1745
  method: "POST",
1719
1746
  headers,
1720
1747
  body: JSON.stringify(body)
1721
1748
  });
1749
+ if (!response.ok && (response.status === 400 || response.status === 422)) {
1750
+ const errText = await response.text();
1751
+ if (errText.includes("2013") || errText.includes("invalid params") || errText.includes("invalid chat setting")) {
1752
+ delete body["tools"];
1753
+ delete body["tool_choice"];
1754
+ delete body["stream_options"];
1755
+ response = await fetch(url, {
1756
+ method: "POST",
1757
+ headers,
1758
+ body: JSON.stringify(body)
1759
+ });
1760
+ }
1761
+ }
1722
1762
  if (!response.ok) {
1723
1763
  const errBody = await response.text();
1724
1764
  let errDetail = "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-speedometer-headless",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "description": "Headless CLI for benchmarking AI models — runs on Node.js and Bun, no TUI dependencies",
5
5
  "bin": {
6
6
  "ai-speedometer-headless": "dist/ai-speedometer-headless"
@@ -10,7 +10,7 @@
10
10
  "bun": ">=1.0.0"
11
11
  },
12
12
  "scripts": {
13
- "build": "bun build src/headless-entry.ts --outdir dist --target node --external 'jsonc-parser' && printf '#!/usr/bin/env node\\n' | cat - dist/headless-entry.js > dist/ai-speedometer-headless && chmod +x dist/ai-speedometer-headless && rm dist/headless-entry.js",
13
+ "build": "node ../../scripts/build-headless.mjs",
14
14
  "typecheck": "bun tsc --noEmit",
15
15
  "prepublishOnly": "bun run build"
16
16
  },