@picassohq/cli 1.0.3 → 1.0.5

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 (64) hide show
  1. package/dist/build-info.json +2 -1
  2. package/dist/index.js +1860 -1316
  3. package/package.json +1 -1
  4. package/runtime/dsh/picasso-ecosystem.cordis.patch.yml +4 -7
  5. package/runtime/dsh/picasso-sdk.patch.yml +47 -0
  6. package/runtime/engine-manifest.json +37 -16
  7. package/runtime/packages/picasso-compaction/cordis.patch.yml +4 -0
  8. package/runtime/packages/picasso-compaction/index.js +875 -0
  9. package/runtime/packages/picasso-compaction/package.json +27 -0
  10. package/runtime/packages/picasso-hooks/cordis.patch.yml +4 -0
  11. package/runtime/packages/picasso-hooks/index.js +302 -0
  12. package/runtime/packages/picasso-hooks/lifecycle-events.js +651 -0
  13. package/runtime/packages/picasso-hooks/package.json +29 -0
  14. package/runtime/packages/picasso-lean-context/argument-repair.js +422 -0
  15. package/runtime/packages/picasso-lean-context/glob-walk.js +518 -0
  16. package/runtime/packages/picasso-lean-context/index.js +159 -11
  17. package/runtime/packages/picasso-memory/index.js +66 -24
  18. package/runtime/packages/picasso-model-router/connections.js +213 -10
  19. package/runtime/packages/picasso-model-router/index.js +128 -1
  20. package/runtime/packages/picasso-model-router/package.json +3 -1
  21. package/runtime/packages/picasso-model-router/thinking-default.js +236 -0
  22. package/runtime/packages/picasso-progress-reports/index.js +128 -18
  23. package/runtime/packages/picasso-sdk-server/command-runs.js +37 -0
  24. package/runtime/packages/picasso-sdk-server/ignore-file.js +5 -1
  25. package/runtime/packages/picasso-sdk-server/index.js +11 -3
  26. package/runtime/packages/picasso-sdk-server/package.json +1 -0
  27. package/runtime/packages/picasso-sdk-server/wave2-hooks.js +26 -6
  28. package/runtime/packages/picasso-web-search/backends.js +245 -195
  29. package/runtime/packages/picasso-web-search/config.js +75 -27
  30. package/runtime/packages/picasso-web-search/cordis.patch.yml +2 -1
  31. package/runtime/packages/picasso-web-search/failure.js +7 -1
  32. package/runtime/packages/picasso-web-search/index.js +7 -5
  33. package/runtime/packages/picasso-web-search/package.json +6 -0
  34. package/runtime/packages/picasso-web-search/requests.js +339 -0
  35. package/runtime/packages/picasso-web-search/router.js +17 -12
  36. package/runtime/packages/picasso-x-reader/settings.js +4 -1
  37. package/runtime/plugins/picasso-auto-approve/index.js +21 -8
  38. package/runtime/plugins/picasso-compaction/index.js +875 -0
  39. package/runtime/plugins/picasso-compaction/package.json +27 -0
  40. package/runtime/plugins/picasso-hooks/index.js +302 -0
  41. package/runtime/plugins/picasso-hooks/lifecycle-events.js +651 -0
  42. package/runtime/plugins/picasso-hooks/package.json +29 -0
  43. package/runtime/plugins/picasso-lean-context/argument-repair.js +422 -0
  44. package/runtime/plugins/picasso-lean-context/glob-walk.js +518 -0
  45. package/runtime/plugins/picasso-lean-context/index.js +159 -11
  46. package/runtime/plugins/picasso-memory/index.js +66 -24
  47. package/runtime/plugins/picasso-model-router/connections.js +213 -10
  48. package/runtime/plugins/picasso-model-router/index.js +128 -1
  49. package/runtime/plugins/picasso-model-router/package.json +3 -1
  50. package/runtime/plugins/picasso-model-router/thinking-default.js +236 -0
  51. package/runtime/plugins/picasso-progress-reports/index.js +128 -18
  52. package/runtime/plugins/picasso-provider-models/index.js +236 -4
  53. package/runtime/plugins/picasso-trackers/index.js +12 -2
  54. package/runtime/plugins/picasso-web-search/backends.js +245 -195
  55. package/runtime/plugins/picasso-web-search/config.js +75 -27
  56. package/runtime/plugins/picasso-web-search/failure.js +7 -1
  57. package/runtime/plugins/picasso-web-search/index.js +7 -5
  58. package/runtime/plugins/picasso-web-search/package.json +6 -0
  59. package/runtime/plugins/picasso-web-search/requests.js +339 -0
  60. package/runtime/plugins/picasso-web-search/router.js +17 -12
  61. package/runtime/plugins/picasso-x-reader/settings.js +4 -1
  62. package/runtime/relay/main.mjs +3877 -1989
  63. package/runtime/relay/model-listing.mjs +337 -26
  64. package/runtime/relay/versions-routes.mjs +86 -20
@@ -237,6 +237,297 @@ function catalogModel(query) {
237
237
  return { ...facts, ...own === void 0 && documented === void 0 ? { viaOtherProvider: true } : {}, sources };
238
238
  }
239
239
 
240
+ // src/catalogue-listing.ts
241
+ import { createHash, createHmac, createSign } from "node:crypto";
242
+ import { readFileSync } from "node:fs";
243
+ import { homedir } from "node:os";
244
+ import { join } from "node:path";
245
+ var LIVE_LISTED_ROUTES = ["amazon-bedrock", "google-vertex"];
246
+ function isLiveListedRoute(route) {
247
+ return LIVE_LISTED_ROUTES.includes(route);
248
+ }
249
+ var LABELS = { "amazon-bedrock": "Amazon Bedrock", "google-vertex": "Vertex AI" };
250
+ var label = (route) => LABELS[route] ?? route;
251
+ var str = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
252
+ var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
253
+ var MAX_PAGES = 10;
254
+ function addByHandHint(route) {
255
+ return `You can add model ids by hand: picasso provider models ${route} --add <id>.`;
256
+ }
257
+ function failure(route, code, what) {
258
+ return { ok: false, route, code, message: `${what} ${addByHandHint(route)}` };
259
+ }
260
+ function httpFailure(route, status) {
261
+ if (status === 401 || status === 403) {
262
+ return failure(route, "models/listing-refused", `${label(route)} refused to list models for this key (HTTP ${status}); the key may lack permission to list models.`);
263
+ }
264
+ if (status === 429) return failure(route, "models/listing-rate-limited", `${label(route)} is limiting requests (HTTP 429); try again in a minute.`);
265
+ return failure(route, "models/listing-failed", `${label(route)} could not list models (HTTP ${status}).`);
266
+ }
267
+ var sha256Hex = (value) => createHash("sha256").update(value, "utf8").digest("hex");
268
+ var hmac = (key, value) => createHmac("sha256", key).update(value, "utf8").digest();
269
+ function awsEncode(value) {
270
+ return encodeURIComponent(value).replace(/[!'()*]/gu, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
271
+ }
272
+ function amzDate(now) {
273
+ return now.toISOString().replace(/[-:]/gu, "").replace(/\.\d{3}/u, "");
274
+ }
275
+ function signV4(input) {
276
+ const url = new URL(input.url);
277
+ const date = amzDate(input.now);
278
+ const day = date.slice(0, 8);
279
+ const payloadHash = sha256Hex(input.body ?? "");
280
+ const headers = { ...input.headers ?? {}, host: url.host, "x-amz-date": date };
281
+ if (input.credentials.sessionToken !== void 0) headers["x-amz-security-token"] = input.credentials.sessionToken;
282
+ const names = Object.keys(headers).map((name) => name.toLowerCase()).sort();
283
+ const lower = Object.fromEntries(Object.entries(headers).map(([name, value]) => [name.toLowerCase(), value]));
284
+ const canonicalHeaders = names.map((name) => `${name}:${String(lower[name]).trim().replace(/\s+/gu, " ")}
285
+ `).join("");
286
+ const signedHeaders = names.join(";");
287
+ const path = url.pathname.split("/").map((segment) => awsEncode(decodeURIComponent(segment))).join("/") || "/";
288
+ const query = [...url.searchParams.entries()].map(([key, value]) => [awsEncode(key), awsEncode(value)]).sort(([a, av], [b, bv]) => a < b ? -1 : a > b ? 1 : av < bv ? -1 : av > bv ? 1 : 0).map(([key, value]) => `${key}=${value}`).join("&");
289
+ const canonicalRequest = [input.method.toUpperCase(), path, query, canonicalHeaders, signedHeaders, payloadHash].join("\n");
290
+ const scope = `${day}/${input.region}/${input.service}/aws4_request`;
291
+ const stringToSign = ["AWS4-HMAC-SHA256", date, scope, sha256Hex(canonicalRequest)].join("\n");
292
+ const signingKey = hmac(hmac(hmac(hmac(`AWS4${input.credentials.secretAccessKey}`, day), input.region), input.service), "aws4_request");
293
+ const signature = createHmac("sha256", signingKey).update(stringToSign, "utf8").digest("hex");
294
+ return {
295
+ headers: {
296
+ ...headers,
297
+ authorization: `AWS4-HMAC-SHA256 Credential=${input.credentials.accessKeyId}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`
298
+ },
299
+ canonicalRequest,
300
+ stringToSign
301
+ };
302
+ }
303
+ function bedrockRegion(env) {
304
+ return str(env["AWS_REGION"]) ?? str(env["AWS_DEFAULT_REGION"]) ?? "us-east-1";
305
+ }
306
+ function bedrockAuth(env) {
307
+ const token = str(env["AWS_BEARER_TOKEN_BEDROCK"]);
308
+ if (token !== void 0) return { kind: "bearer", token };
309
+ const accessKeyId = str(env["AWS_ACCESS_KEY_ID"]);
310
+ const secretAccessKey = str(env["AWS_SECRET_ACCESS_KEY"]);
311
+ if (accessKeyId === void 0 || secretAccessKey === void 0) return void 0;
312
+ const sessionToken = str(env["AWS_SESSION_TOKEN"]);
313
+ return { kind: "sigv4", credentials: { accessKeyId, secretAccessKey, ...sessionToken === void 0 ? {} : { sessionToken } } };
314
+ }
315
+ var textIn = (value, wanted) => Array.isArray(value) && value.some((entry) => typeof entry === "string" && entry.toUpperCase() === wanted);
316
+ async function listBedrockModels(options = {}) {
317
+ const route = "amazon-bedrock";
318
+ const env = options.env ?? process.env;
319
+ const fetcher = options.fetch ?? ((url, init) => fetch(url, init));
320
+ const now = options.now ?? (() => /* @__PURE__ */ new Date());
321
+ const auth = bedrockAuth(env);
322
+ if (auth === void 0) {
323
+ return failure(route, "models/no-credentials", "Amazon Bedrock has no key here to list its models with (AWS_BEARER_TOKEN_BEDROCK, or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY).");
324
+ }
325
+ const region = bedrockRegion(env);
326
+ if (!/^[a-z]{2}(?:-[a-z]+)+-\d$/u.test(region)) return failure(route, "models/bad-region", `"${region}" is not an AWS region.`);
327
+ const base = `https://bedrock.${region}.amazonaws.com`;
328
+ const get = async (url) => {
329
+ const headers = { accept: "application/json" };
330
+ const signed = auth.kind === "bearer" ? { ...headers, authorization: `Bearer ${auth.token}` } : signV4({ method: "GET", url, region, service: "bedrock", credentials: auth.credentials, now: now(), headers }).headers;
331
+ const { host: _host, ...sent } = signed;
332
+ let response;
333
+ try {
334
+ response = await fetcher(url, { method: "GET", headers: sent });
335
+ } catch {
336
+ return { ok: false, listing: failure(route, "models/listing-unreachable", `Amazon Bedrock could not be reached in ${region}.`) };
337
+ }
338
+ if (!response.ok) return { ok: false, listing: httpFailure(route, response.status) };
339
+ try {
340
+ return { ok: true, body: await response.json() };
341
+ } catch {
342
+ return { ok: false, listing: failure(route, "models/listing-unreadable", "Amazon Bedrock answered with a model list Picasso cannot read.") };
343
+ }
344
+ };
345
+ const foundation = await get(`${base}/foundation-models?byOutputModality=TEXT`);
346
+ if (!foundation.ok) return foundation.listing;
347
+ const summaries = isRecord(foundation.body) && Array.isArray(foundation.body["modelSummaries"]) ? foundation.body["modelSummaries"].filter(isRecord) : [];
348
+ const textModels = /* @__PURE__ */ new Map();
349
+ for (const summary of summaries) {
350
+ const id = str(summary["modelId"]);
351
+ if (id === void 0) continue;
352
+ if (!textIn(summary["inputModalities"], "TEXT") || !textIn(summary["outputModalities"], "TEXT") || textIn(summary["outputModalities"], "EMBEDDING")) continue;
353
+ const lifecycle = isRecord(summary["modelLifecycle"]) ? str(summary["modelLifecycle"]["status"]) : void 0;
354
+ if (lifecycle !== void 0 && lifecycle.toUpperCase() !== "ACTIVE") continue;
355
+ textModels.set(id, summary);
356
+ }
357
+ const models = [];
358
+ for (const [id, summary] of textModels) {
359
+ const inference = Array.isArray(summary["inferenceTypesSupported"]) ? summary["inferenceTypesSupported"] : void 0;
360
+ if (inference !== void 0 && !textIn(inference, "ON_DEMAND")) continue;
361
+ const name = str(summary["modelName"]);
362
+ const provider = str(summary["providerName"]);
363
+ models.push({
364
+ id,
365
+ ...name === void 0 ? {} : { name: provider === void 0 || name.startsWith(provider) ? name : `${provider} ${name}` },
366
+ ...textIn(summary["inputModalities"], "IMAGE") ? { images: true } : {},
367
+ kind: "foundation"
368
+ });
369
+ }
370
+ let token;
371
+ for (let page = 0; page < MAX_PAGES; page += 1) {
372
+ const url = `${base}/inference-profiles?maxResults=1000${token === void 0 ? "" : `&nextToken=${encodeURIComponent(token)}`}`;
373
+ const profiles = await get(url);
374
+ if (!profiles.ok) return profiles.listing;
375
+ const body = isRecord(profiles.body) ? profiles.body : {};
376
+ for (const profile of Array.isArray(body["inferenceProfileSummaries"]) ? body["inferenceProfileSummaries"].filter(isRecord) : []) {
377
+ const id = str(profile["inferenceProfileId"]);
378
+ if (id === void 0 || models.some((model) => model.id === id)) continue;
379
+ const status = str(profile["status"]);
380
+ if (status !== void 0 && status.toUpperCase() !== "ACTIVE") continue;
381
+ const underlying = (Array.isArray(profile["models"]) ? profile["models"].filter(isRecord) : []).flatMap((model) => {
382
+ const arn = str(model["modelArn"]);
383
+ const match = arn === void 0 ? null : /foundation-model\/(.+)$/u.exec(arn);
384
+ return match?.[1] === void 0 ? [] : [match[1]];
385
+ });
386
+ const text2 = underlying.filter((modelId) => textModels.has(modelId));
387
+ if (underlying.length > 0 && text2.length === 0) continue;
388
+ const first = text2[0] === void 0 ? void 0 : textModels.get(text2[0]);
389
+ const name = str(profile["inferenceProfileName"]);
390
+ models.push({
391
+ id,
392
+ ...name === void 0 ? {} : { name },
393
+ ...first !== void 0 && textIn(first["inputModalities"], "IMAGE") ? { images: true } : {},
394
+ kind: "inference-profile"
395
+ });
396
+ }
397
+ token = str(body["nextToken"]);
398
+ if (token === void 0) break;
399
+ }
400
+ if (models.length === 0) return failure(route, "models/listing-empty", `Amazon Bedrock listed no chat models this key can use in ${region}.`);
401
+ return { ok: true, route, models, region };
402
+ }
403
+ function defaultAdcFile(env) {
404
+ const explicit = str(env["GOOGLE_APPLICATION_CREDENTIALS"]);
405
+ if (explicit !== void 0) return explicit;
406
+ const config = str(env["CLOUDSDK_CONFIG"]) ?? join(str(env["HOME"]) ?? homedir(), ".config", "gcloud");
407
+ return join(config, "application_default_credentials.json");
408
+ }
409
+ function readAdc(options, env) {
410
+ const file = options.adcFile ?? defaultAdcFile(env);
411
+ try {
412
+ const parsed = JSON.parse((options.readFile ?? ((path) => readFileSync(path, "utf8")))(file));
413
+ return isRecord(parsed) ? parsed : void 0;
414
+ } catch {
415
+ return void 0;
416
+ }
417
+ }
418
+ var base64Url = (value) => Buffer.from(value).toString("base64url");
419
+ async function adcAccessToken(adc, fetcher, now) {
420
+ const type = str(adc["type"]);
421
+ let body;
422
+ let tokenUri = "https://oauth2.googleapis.com/token";
423
+ if (type === "authorized_user") {
424
+ const clientId = str(adc["client_id"]);
425
+ const clientSecret = str(adc["client_secret"]);
426
+ const refreshToken = str(adc["refresh_token"]);
427
+ if (clientId === void 0 || clientSecret === void 0 || refreshToken === void 0) return void 0;
428
+ body = new URLSearchParams({ grant_type: "refresh_token", client_id: clientId, client_secret: clientSecret, refresh_token: refreshToken });
429
+ } else if (type === "service_account") {
430
+ const email = str(adc["client_email"]);
431
+ const key = str(adc["private_key"]);
432
+ tokenUri = str(adc["token_uri"]) ?? tokenUri;
433
+ if (email === void 0 || key === void 0 || !/^https:\/\/[^/]+\.googleapis\.com\//u.test(tokenUri)) return void 0;
434
+ const issued = Math.floor(now.getTime() / 1e3);
435
+ const claims = { iss: email, scope: "https://www.googleapis.com/auth/cloud-platform", aud: tokenUri, iat: issued, exp: issued + 3600 };
436
+ const unsigned = `${base64Url(JSON.stringify({ alg: "RS256", typ: "JWT" }))}.${base64Url(JSON.stringify(claims))}`;
437
+ let signature;
438
+ try {
439
+ signature = createSign("RSA-SHA256").update(unsigned).sign(key, "base64url");
440
+ } catch {
441
+ return void 0;
442
+ }
443
+ body = new URLSearchParams({ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer", assertion: `${unsigned}.${signature}` });
444
+ } else {
445
+ return void 0;
446
+ }
447
+ try {
448
+ const response = await fetcher(tokenUri, { method: "POST", headers: { "content-type": "application/x-www-form-urlencoded" }, body: body.toString() });
449
+ if (!response.ok) return void 0;
450
+ const json = await response.json();
451
+ return isRecord(json) ? str(json["access_token"]) : void 0;
452
+ } catch {
453
+ return void 0;
454
+ }
455
+ }
456
+ function isVertexChatModel(id) {
457
+ return /^gemini-/u.test(id) && !/(?:embedding|image|tts|live|native-audio|audio-dialog)/u.test(id);
458
+ }
459
+ function vertexName(id) {
460
+ return id.split("-").map((part) => /^\d/u.test(part) ? part : part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
461
+ }
462
+ async function listVertexModels(options = {}) {
463
+ const route = "google-vertex";
464
+ const env = options.env ?? process.env;
465
+ const fetcher = options.fetch ?? ((url, init) => fetch(url, init));
466
+ const now = options.now ?? (() => /* @__PURE__ */ new Date());
467
+ const location = str(env["GOOGLE_CLOUD_LOCATION"]) ?? "us-central1";
468
+ if (!/^[a-z0-9-]+$/u.test(location)) return failure(route, "models/bad-location", `"${location}" is not a Google Cloud location.`);
469
+ const apiKey = str(env["GOOGLE_CLOUD_API_KEY"]);
470
+ const adc = apiKey === void 0 ? readAdc(options, env) : void 0;
471
+ const project = str(env["GOOGLE_CLOUD_PROJECT"]) ?? (adc === void 0 ? void 0 : str(adc["quota_project_id"]) ?? str(adc["project_id"]));
472
+ const headers = { accept: "application/json" };
473
+ if (apiKey !== void 0) headers["x-goog-api-key"] = apiKey;
474
+ else {
475
+ const token = adc === void 0 ? void 0 : await adcAccessToken(adc, fetcher, now());
476
+ if (token === void 0) {
477
+ return failure(route, "models/no-credentials", "Vertex AI has no key or Google Cloud sign-in here to list its models with (GOOGLE_CLOUD_API_KEY, or `gcloud auth application-default login`).");
478
+ }
479
+ headers["authorization"] = `Bearer ${token}`;
480
+ if (project !== void 0) headers["x-goog-user-project"] = project;
481
+ }
482
+ const host = location === "global" ? "aiplatform.googleapis.com" : `${location}-aiplatform.googleapis.com`;
483
+ const models = [];
484
+ let pageToken;
485
+ for (let page = 0; page < MAX_PAGES; page += 1) {
486
+ const url = `https://${host}/v1beta1/publishers/google/models?pageSize=200${pageToken === void 0 ? "" : `&pageToken=${encodeURIComponent(pageToken)}`}`;
487
+ let response;
488
+ try {
489
+ response = await fetcher(url, { method: "GET", headers });
490
+ } catch {
491
+ return failure(route, "models/listing-unreachable", `Vertex AI could not be reached in ${location}.`);
492
+ }
493
+ if (!response.ok) return httpFailure(route, response.status);
494
+ let body;
495
+ try {
496
+ body = await response.json();
497
+ } catch {
498
+ return failure(route, "models/listing-unreadable", "Vertex AI answered with a model list Picasso cannot read.");
499
+ }
500
+ const record = isRecord(body) ? body : {};
501
+ for (const entry of Array.isArray(record["publisherModels"]) ? record["publisherModels"].filter(isRecord) : []) {
502
+ const id = str(entry["name"])?.split("/").at(-1);
503
+ if (id === void 0 || !isVertexChatModel(id) || models.some((model) => model.id === id)) continue;
504
+ const stage = str(entry["launchStage"]);
505
+ if (stage !== void 0 && /DEPRECATED|LEGACY/u.test(stage.toUpperCase())) continue;
506
+ models.push({ id, name: vertexName(id), images: true, kind: "publisher" });
507
+ }
508
+ pageToken = str(record["nextPageToken"]);
509
+ if (pageToken === void 0) break;
510
+ }
511
+ if (models.length === 0) return failure(route, "models/listing-empty", `Vertex AI listed no chat models in ${location}.`);
512
+ return { ok: true, route, models, location, ...project === void 0 ? {} : { project } };
513
+ }
514
+ async function listCatalogueRoute(route, options = {}) {
515
+ if (route === "amazon-bedrock") return listBedrockModels(options);
516
+ if (route === "google-vertex") return listVertexModels(options);
517
+ return void 0;
518
+ }
519
+ function parseEnvFile(text2) {
520
+ const out = {};
521
+ for (const line of text2.split(/\r?\n/u)) {
522
+ const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/u.exec(line);
523
+ if (match === null || match[1] === void 0) continue;
524
+ let value = match[2] ?? "";
525
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
526
+ out[match[1]] = value;
527
+ }
528
+ return out;
529
+ }
530
+
240
531
  // src/model-listing.ts
241
532
  var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
242
533
  var CLAUDE_THINKING_LEVELS = ["low", "medium", "high", "xhigh", "max"];
@@ -368,11 +659,11 @@ async function readCapped(response, cap) {
368
659
  return Buffer.concat(chunks).toString("utf8");
369
660
  }
370
661
  function nextPage(first, body, pageNumber) {
371
- if (!isRecord(body)) return void 0;
662
+ if (!isRecord2(body)) return void 0;
372
663
  if (body["has_more"] === true && typeof body["last_id"] === "string" && body["last_id"]) return `${first}&after_id=${encodeURIComponent(body["last_id"])}`;
373
664
  if (typeof body["nextPageToken"] === "string" && body["nextPageToken"]) return `${first}&pageToken=${encodeURIComponent(body["nextPageToken"])}`;
374
665
  if (Array.isArray(body["result"])) {
375
- const info = isRecord(body["result_info"]) ? body["result_info"] : {};
666
+ const info = isRecord2(body["result_info"]) ? body["result_info"] : {};
376
667
  const count = body["result"].length;
377
668
  const current = capacity(info["page"]) ?? pageNumber;
378
669
  const perPage = capacity(info["per_page"]) ?? CLOUDFLARE_PER_PAGE;
@@ -394,32 +685,48 @@ function mergeModels(earlier, later) {
394
685
  }
395
686
  function readAdvertised(body, api, options = {}) {
396
687
  let listed;
397
- if (Array.isArray(body)) listed = body.filter(isRecord).map((raw) => ({ raw }));
398
- else if (!isRecord(body)) return void 0;
399
- else if (Array.isArray(body["result"])) listed = body["result"].filter(isRecord).map((raw) => ({ key: text(raw["name"]) ?? text(raw["id"]), raw }));
400
- else if (Array.isArray(body["data"])) listed = body["data"].filter(isRecord).map((raw) => ({ raw }));
401
- else if (Array.isArray(body["models"])) listed = body["models"].filter(isRecord).map((raw) => ({ key: text(raw["name"])?.replace(/^models\//u, "") ?? text(raw["id"]), raw }));
402
- else if (isRecord(body["models"])) listed = Object.entries(body["models"]).flatMap(([key, raw]) => isRecord(raw) ? [{ key, raw }] : []);
688
+ if (Array.isArray(body)) listed = body.filter(isRecord2).map((raw) => ({ raw }));
689
+ else if (!isRecord2(body)) return void 0;
690
+ else if (Array.isArray(body["result"])) listed = body["result"].filter(isRecord2).map((raw) => ({ key: text(raw["name"]) ?? text(raw["id"]), raw }));
691
+ else if (Array.isArray(body["data"])) listed = body["data"].filter(isRecord2).map((raw) => ({ raw }));
692
+ else if (Array.isArray(body["models"])) listed = body["models"].filter(isRecord2).map((raw) => ({ key: text(raw["name"])?.replace(/^models\//u, "") ?? text(raw["id"]), raw }));
693
+ else if (isRecord2(body["models"])) listed = Object.entries(body["models"]).flatMap(([key, raw]) => isRecord2(raw) ? [{ key, raw }] : []);
403
694
  else return void 0;
404
695
  const models = listed.flatMap(({ key, raw }) => {
405
696
  const named = text(key) ?? text(raw["id"]);
406
697
  const id = options.stripModelsPrefix === true ? named?.replace(/^models\//u, "") : named;
407
698
  if (!id || !chatCapable({ ...raw, id })) return [];
408
- const limit = isRecord(raw["limit"]) ? raw["limit"] : {};
409
- const top = isRecord(raw["top_provider"]) ? raw["top_provider"] : {};
699
+ const limit = isRecord2(raw["limit"]) ? raw["limit"] : {};
700
+ const top = isRecord2(raw["top_provider"]) ? raw["top_provider"] : {};
410
701
  const props = propertyValues(raw["properties"]);
411
702
  const contextWindow = capacity(raw["context_window"], raw["context_length"], raw["contextWindow"], raw["max_input_tokens"], raw["max_context_length"], raw["inputTokenLimit"], limit["context"], top["context_length"], props["context_window"], props["max_input_tokens"]);
412
703
  const maxOutput = capacity(raw["max_output_tokens"], raw["max_completion_tokens"], raw["outputTokenLimit"], raw["maxOutput"], raw["max_tokens"], limit["output"], top["max_completion_tokens"]);
413
704
  const reasoningEfforts = advertisedEfforts(raw, api);
414
- return [{ id, ...contextWindow !== void 0 ? { contextWindow } : {}, ...maxOutput !== void 0 ? { maxOutput } : {}, ...reasoningEfforts ? { reasoningEfforts } : {} }];
705
+ const input = listedInput(raw);
706
+ return [{
707
+ id,
708
+ ...contextWindow !== void 0 ? { contextWindow } : {},
709
+ ...maxOutput !== void 0 ? { maxOutput } : {},
710
+ ...input !== void 0 ? { input } : {},
711
+ ...reasoningEfforts ? { reasoningEfforts } : {}
712
+ }];
415
713
  });
416
714
  return mergeModels([], models);
417
715
  }
716
+ function listedInput(raw) {
717
+ const architecture = isRecord2(raw["architecture"]) ? raw["architecture"] : {};
718
+ const modalities = isRecord2(raw["modalities"]) ? raw["modalities"] : {};
719
+ const stated = [raw["input_modalities"], architecture["input_modalities"], raw["supported_input_types"], modalities["input"]].find(
720
+ (value) => Array.isArray(value) && value.some((item) => typeof item === "string")
721
+ );
722
+ if (stated === void 0) return void 0;
723
+ return stated.some((item) => typeof item === "string" && item.toLowerCase() === "image") ? ["text", "image"] : ["text"];
724
+ }
418
725
  function propertyValues(value) {
419
726
  const out = {};
420
727
  if (!Array.isArray(value)) return out;
421
728
  for (const item of value) {
422
- if (!isRecord(item) || typeof item["property_id"] !== "string") continue;
729
+ if (!isRecord2(item) || typeof item["property_id"] !== "string") continue;
423
730
  const number = Number(item["value"]);
424
731
  if (Number.isSafeInteger(number) && number > 0) out[item["property_id"]] = number;
425
732
  }
@@ -428,16 +735,16 @@ function propertyValues(value) {
428
735
  var NON_CHAT_ID = /(?:^|[-_./])(?:embed|embedding|embeddings|whisper|tts|transcribe|dall-e|gpt-image|moderation|moderations|rerank|reranker|realtime|sora|imagen|veo|davinci-002|babbage-002)(?:[-_./\d]|$)/u;
429
736
  var NON_CHAT_KIND = /* @__PURE__ */ new Set(["embedding", "embeddings", "image", "image_generation", "audio", "audio_speech", "audio_transcription", "speech", "tts", "moderation", "moderations", "rerank", "video", "video_generation", "ocr"]);
430
737
  function chatCapable(entry) {
431
- const capabilities = isRecord(entry["capabilities"]) ? entry["capabilities"] : {};
738
+ const capabilities = isRecord2(entry["capabilities"]) ? entry["capabilities"] : {};
432
739
  if (capabilities["completion_chat"] === false) return false;
433
740
  const methods = entry["supportedGenerationMethods"];
434
741
  if (Array.isArray(methods) && !methods.includes("generateContent") && !methods.includes("streamGenerateContent")) return false;
435
- const architecture = isRecord(entry["architecture"]) ? entry["architecture"] : {};
742
+ const architecture = isRecord2(entry["architecture"]) ? entry["architecture"] : {};
436
743
  const outputs = Array.isArray(architecture["output_modalities"]) ? architecture["output_modalities"] : void 0;
437
744
  if (outputs !== void 0 && outputs.length > 0 && !outputs.includes("text")) return false;
438
745
  const modality = typeof architecture["modality"] === "string" ? architecture["modality"] : void 0;
439
746
  if (outputs === void 0 && modality?.includes("->") && !(modality.split("->")[1] ?? "").includes("text")) return false;
440
- const task = isRecord(entry["task"]) ? text(entry["task"]["name"]) : void 0;
747
+ const task = isRecord2(entry["task"]) ? text(entry["task"]["name"]) : void 0;
441
748
  if (task !== void 0 && task !== "Text Generation") return false;
442
749
  for (const kind of [entry["type"], entry["mode"]]) if (typeof kind === "string" && NON_CHAT_KIND.has(kind.toLowerCase())) return false;
443
750
  const id = text(entry["id"]);
@@ -445,12 +752,12 @@ function chatCapable(entry) {
445
752
  }
446
753
  function advertisedEfforts(entry, api) {
447
754
  const allowed = api === "anthropic-messages" ? CLAUDE_THINKING_LEVELS : THINKING_LEVELS.filter((level) => level !== "off");
448
- const reasoning = isRecord(entry["reasoning"]) ? entry["reasoning"] : {};
449
- const capabilities = isRecord(entry["capabilities"]) ? entry["capabilities"] : {};
450
- const thinking = isRecord(capabilities["thinking"]) ? capabilities["thinking"] : {};
451
- const effort = isRecord(capabilities["effort"]) ? capabilities["effort"] : void 0;
755
+ const reasoning = isRecord2(entry["reasoning"]) ? entry["reasoning"] : {};
756
+ const capabilities = isRecord2(entry["capabilities"]) ? entry["capabilities"] : {};
757
+ const thinking = isRecord2(capabilities["thinking"]) ? capabilities["thinking"] : {};
758
+ const effort = isRecord2(capabilities["effort"]) ? capabilities["effort"] : void 0;
452
759
  if (effort !== void 0 && effort["supported"] !== false) {
453
- const levels2 = allowed.filter((level) => isRecord(effort[level]) && effort[level]["supported"] === true);
760
+ const levels2 = allowed.filter((level) => isRecord2(effort[level]) && effort[level]["supported"] === true);
454
761
  if (levels2.length > 0) return dict(levels2);
455
762
  }
456
763
  const candidates = [
@@ -491,7 +798,7 @@ function sourced(id, found, route, lookup, saved = {}) {
491
798
  };
492
799
  }
493
800
  function withoutSaved(facts, saved) {
494
- const has = (value) => typeof value === "number" && value > 0 || isRecord(value) && Object.keys(value).length > 0;
801
+ const has = (value) => typeof value === "number" && value > 0 || isRecord2(value) && Object.keys(value).length > 0;
495
802
  const { contextWindow, maxOutput, reasoningEfforts, ...rest } = facts;
496
803
  const sources = { ...facts.sources };
497
804
  if (has(saved["contextWindow"])) delete sources.contextWindow;
@@ -561,7 +868,7 @@ function describedModel(model, route, lookup = catalogModel) {
561
868
  };
562
869
  }
563
870
  function declaredLevels(value) {
564
- if (!isRecord(value)) return [];
871
+ if (!isRecord2(value)) return [];
565
872
  return THINKING_LEVELS.filter((level) => level in value);
566
873
  }
567
874
  function requestedEfforts(value) {
@@ -569,7 +876,7 @@ function requestedEfforts(value) {
569
876
  const levels2 = value.filter((level) => typeof level === "string" && THINKING_LEVELS.includes(level) && level !== "off");
570
877
  return levels2.length > 0 ? dict(levels2) : void 0;
571
878
  }
572
- if (isRecord(value)) {
879
+ if (isRecord2(value)) {
573
880
  const entries = THINKING_LEVELS.flatMap((level) => level !== "off" && typeof value[level] === "string" && value[level] ? [[level, value[level]]] : []);
574
881
  return entries.length > 0 ? Object.fromEntries(entries) : void 0;
575
882
  }
@@ -579,14 +886,14 @@ function levelNames(value) {
579
886
  if (Array.isArray(value)) {
580
887
  return value.flatMap((item) => {
581
888
  if (typeof item === "string") return [item.toLowerCase()];
582
- if (isRecord(item)) {
889
+ if (isRecord2(item)) {
583
890
  const name = text(item["effort"]) ?? text(item["level"]) ?? text(item["id"]) ?? text(item["name"]);
584
891
  return name ? [name.toLowerCase()] : [];
585
892
  }
586
893
  return [];
587
894
  });
588
895
  }
589
- if (isRecord(value)) return Object.entries(value).filter(([, wire]) => wire !== false).map(([level]) => level.toLowerCase());
896
+ if (isRecord2(value)) return Object.entries(value).filter(([, wire]) => wire !== false).map(([level]) => level.toLowerCase());
590
897
  return [];
591
898
  }
592
899
  var dict = (levels2) => Object.fromEntries(THINKING_LEVELS.filter((level) => levels2.includes(level)).map((level) => [level, level]));
@@ -595,10 +902,11 @@ function capacity(...values) {
595
902
  return void 0;
596
903
  }
597
904
  var sameValue = (left, right) => JSON.stringify(left) === JSON.stringify(right);
598
- var isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
905
+ var isRecord2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
599
906
  var text = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
600
907
  export {
601
908
  CLAUDE_THINKING_LEVELS,
909
+ LIVE_LISTED_ROUTES,
602
910
  THINKING_LEVELS,
603
911
  advertisedEfforts,
604
912
  chatCapable,
@@ -607,7 +915,10 @@ export {
607
915
  describedModel,
608
916
  fetchModelListing,
609
917
  isGeminiEndpoint,
918
+ isLiveListedRoute,
919
+ listCatalogueRoute,
610
920
  listingUrl,
921
+ parseEnvFile,
611
922
  readAdvertised,
612
923
  requestedEfforts,
613
924
  syncDeclaredModels