@oya-ai/cli 1.0.209 → 1.0.213

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 (2) hide show
  1. package/dist/index.js +35 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1049,8 +1049,10 @@ var FLEETS = {
1049
1049
  "oya-cloud": oyaCloud,
1050
1050
  "oya-selfhosted": governedDocker,
1051
1051
  k8s: kubernetes,
1052
- "docker-workers": (v) => {
1053
- v.OYA_BROWSER_PROVIDER = "oya-selfhosted";
1052
+ // Always-on workers dial in on their own, so no provider is named: a bare start()
1053
+ // then borrows a connected worker. Naming oya-selfhosted sent every start to the
1054
+ // managed launcher, which this fleet does not run, and start() failed on a fresh install.
1055
+ "docker-workers": () => {
1054
1056
  }
1055
1057
  };
1056
1058
  function fleetSettings(v, input) {
@@ -1260,6 +1262,7 @@ function nativeContext() {
1260
1262
  async function provisionDocker(root, a) {
1261
1263
  if (a.fleet === "oya-selfhosted") await provisionGoverned(root);
1262
1264
  const scale = a.fleet === "docker-workers" ? ["--scale", `browser=${a.workers}`] : ["--scale", "browser=0"];
1265
+ if (a.fleet === "docker-workers") await run("docker", ["compose", "pull", "--quiet", "browser"], { cwd: root });
1263
1266
  await run("docker", ["compose", "up", "-d", "--build", ...scale], { cwd: root });
1264
1267
  }
1265
1268
  async function isReady(url) {
@@ -1334,11 +1337,17 @@ function openaiFromEnv(env2) {
1334
1337
  const llm = { provider: "openai", baseUrl: env2.OPENAI_BASE_URL || base, model: env2.CHAT_MODEL || model };
1335
1338
  return { llm, secrets: { OPENAI_API_KEY: env2.OPENAI_API_KEY || "" } };
1336
1339
  }
1340
+ var KEYED_PROVIDERS = [
1341
+ ["ANTHROPIC_API_KEY", "anthropic"],
1342
+ ["GEMINI_API_KEY", "gemini"]
1343
+ ];
1337
1344
  function llmFromEnv(env2) {
1338
1345
  if (env2.OPENAI_API_KEY) return openaiFromEnv(env2);
1339
- if (!env2.ANTHROPIC_API_KEY) return { llm: NO_LLM, secrets: {} };
1340
- const { base, model } = LLM_PRESETS.anthropic;
1341
- return { llm: { provider: "anthropic", baseUrl: base, model }, secrets: { OPENAI_API_KEY: env2.ANTHROPIC_API_KEY } };
1346
+ const found = KEYED_PROVIDERS.find(([name2]) => env2[name2]);
1347
+ if (!found) return { llm: NO_LLM, secrets: {} };
1348
+ const [name, provider] = found;
1349
+ const { base, model } = LLM_PRESETS[provider];
1350
+ return { llm: { provider, baseUrl: base, model }, secrets: { OPENAI_API_KEY: env2[name] } };
1342
1351
  }
1343
1352
  var LOCAL = {
1344
1353
  version: 1,
@@ -1636,18 +1645,20 @@ function saveKey(apiKey, baseUrl) {
1636
1645
  var OPTIONS_ORIGIN = { apiKeyFrom: "the apiKey option", baseUrlFrom: "the baseUrl option", savedKey: false };
1637
1646
  var Http = class {
1638
1647
  /** Stores where to call, with which key, how long to wait, which fetch to use, and where the key and address came from. */
1639
- constructor(baseUrl, apiKey, timeoutMs, fetchImpl, origin3 = OPTIONS_ORIGIN) {
1648
+ constructor(baseUrl, apiKey, timeoutMs, fetchImpl, origin3 = OPTIONS_ORIGIN, defaults = {}) {
1640
1649
  this.baseUrl = baseUrl;
1641
1650
  this.apiKey = apiKey;
1642
1651
  this.timeoutMs = timeoutMs;
1643
1652
  this.fetchImpl = fetchImpl;
1644
1653
  this.origin = origin3;
1654
+ this.defaults = defaults;
1645
1655
  }
1646
1656
  baseUrl;
1647
1657
  apiKey;
1648
1658
  timeoutMs;
1649
1659
  fetchImpl;
1650
1660
  origin;
1661
+ defaults;
1651
1662
  /** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
1652
1663
  async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
1653
1664
  const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
@@ -1655,7 +1666,11 @@ var Http = class {
1655
1666
  }
1656
1667
  /** The fetch options for one call, with this client's key on them. */
1657
1668
  init(method, body, timeoutMs, headers) {
1658
- return requestInit(method, body, timeoutMs, { Authorization: `Bearer ${this.apiKey}`, ...headers });
1669
+ return requestInit(method, body, timeoutMs, {
1670
+ Authorization: `Bearer ${this.apiKey}`,
1671
+ ...this.defaults,
1672
+ ...headers
1673
+ });
1659
1674
  }
1660
1675
  /**
1661
1676
  * fetch's own failures say only "fetch failed" or "The operation was
@@ -1740,7 +1755,7 @@ function deploymentOf2(url) {
1740
1755
  }
1741
1756
  }
1742
1757
  function noKey(saved, address) {
1743
- if (!saved.apiKey) return "No API key. Pass { apiKey }, set OYA_API_KEY, or run `npx @oya-ai/cli login`.";
1758
+ if (!saved.apiKey) return "No API key. Get one at https://oyabrowser.com, then set OYA_API_KEY or pass { apiKey }.";
1744
1759
  const why = `the key saved in ~/.oya/config.json is for ${saved.baseUrl} and is only sent there`;
1745
1760
  return `No API key for ${address}: ${why}. Pass { apiKey }, set OYA_API_KEY, or run \`npx @oya-ai/cli login --url ${address}\`.`;
1746
1761
  }
@@ -1752,7 +1767,18 @@ function createHttp(options) {
1752
1767
  if (!fetchImpl) throw new Error("No fetch available, pass { fetch } or use Node 18+.");
1753
1768
  const origin3 = { apiKeyFrom: key.from, baseUrlFrom: address.from, savedKey: !!saved.apiKey };
1754
1769
  const timeout = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
1755
- return new Http(webAddress(address), key.value, timeout, fetchImpl.bind(globalThis), origin3);
1770
+ return new Http(webAddress(address), key.value, timeout, fetchImpl.bind(globalThis), origin3, modelHeaders(options));
1771
+ }
1772
+ var MODEL_FIX = "Check the model option.";
1773
+ function modelHeaders({ model }) {
1774
+ if (!model) return {};
1775
+ const fields = [
1776
+ ["provider", "X-Oya-Llm-Provider"],
1777
+ ["name", "X-Oya-Llm-Model"],
1778
+ ["apiKey", "X-Oya-Llm-Api-Key"]
1779
+ ];
1780
+ const set = fields.filter(([field]) => model[field]);
1781
+ return Object.fromEntries(set.map(([field, name]) => [name, headerSafe(model[field], `model.${field}`, MODEL_FIX)]));
1756
1782
  }
1757
1783
  var LOCAL_HOST = /^(localhost|127\.)/i;
1758
1784
  function webAddress({ value, from }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oya-ai/cli",
3
- "version": "1.0.209",
3
+ "version": "1.0.213",
4
4
  "description": "Command line for the Oya browser control plane.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://oyabrowser.com",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "devDependencies": {
53
- "@oya-ai/browser": "1.0.209",
53
+ "@oya-ai/browser": "1.0.213",
54
54
  "@types/node": "^20.19.43",
55
55
  "tsup": "^9.0.0",
56
56
  "typescript": "^6.0.3"