@dan-ai-studio/dshopencodego 0.1.48 → 0.1.49

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/README.en.md CHANGED
@@ -247,7 +247,7 @@ npm test # contract tests against a real local HTTP mock gateway
247
247
 
248
248
  **Order matters**: `npm run build` must come before `npm test` — `tests/pack-contents.spec.ts` walks every `exports` target, and whether `lib/` exists decides whether that check runs or is silently skipped (it does not fail, it just stops protecting you). `package.json` no longer carries `prepare`, so `npm ci` will not build for you; all three CI workflows run `npm run build` explicitly.
249
249
 
250
- The suite covers configuration validation, the protocol ladder, gateway and online metadata, the catalog projection, the adapter on the wire (all three protocols), Remote contracts and services, session-header invariants, usage windows and the meter, the client controller and usage pill, both halves' mounting and registration, the error mapping for stream idle timeouts and aborts, the exit-code contract of the verification scripts, and several **structural invariants** (inject declarations match the source's reads, peer coverage holds both ways, the READMEs match the manifest, and the READMEs' claims about the upstream match the upstream actually installed). That is **46 test files** — a number `tests/readme-consistency.spec.ts` checks against the `tests/` directory, so it cannot drift.
250
+ The suite covers configuration validation, the protocol ladder, gateway and online metadata, the catalog projection, the adapter on the wire (all three protocols), Remote contracts and services, session-header invariants, usage windows and the meter, the client controller and usage pill, both halves' mounting and registration, the error mapping for stream idle timeouts and aborts, the exit-code contract of the verification scripts, and several **structural invariants** (inject declarations match the source's reads, peer coverage holds both ways, the READMEs match the manifest, and the READMEs' claims about the upstream match the upstream actually installed). That is **47 test files** — a number `tests/readme-consistency.spec.ts` checks against the `tests/` directory, so it cannot drift.
251
251
 
252
252
  ## Releasing (maintainers)
253
253
 
package/README.md CHANGED
@@ -247,7 +247,7 @@ npm test # 契约测试:真实 HTTP mock 网关,断言请求头/
247
247
 
248
248
  **顺序有讲究**:`npm run build` 要排在 `npm test` 之前——`tests/pack-contents.spec.ts` 会遍历 `exports` 的每个目标,`lib/` 存在与否决定这条检查是执行还是被跳过(不报错,但会少一层保护)。`package.json` 已移除 `prepare`,因此 `npm ci` 不会再替你隐式构建;三个 CI workflow 都显式跑了 `npm run build`。
249
249
 
250
- 测试覆盖配置校验、协议阶梯、网关与在线元数据、目录投影、适配器(三种协议的线上请求)、Remote 契约与服务、会话头不变量、用量窗口与计量、客户端控制器与用量组件、两半的挂载与登记、流空闲超时与中止的错误映射、验证脚本的退出码契约、以及几条**结构性不变量**(inject 声明与源码读取一致、peer 覆盖双向、README 与 manifest 一致、README 对上游的断言与实装的上游一致)。共 **46 个测试文件**——这个数字由 `tests/readme-consistency.spec.ts` 对着 `tests/` 目录校验,不会漂移。
250
+ 测试覆盖配置校验、协议阶梯、网关与在线元数据、目录投影、适配器(三种协议的线上请求)、Remote 契约与服务、会话头不变量、用量窗口与计量、客户端控制器与用量组件、两半的挂载与登记、流空闲超时与中止的错误映射、验证脚本的退出码契约、以及几条**结构性不变量**(inject 声明与源码读取一致、peer 覆盖双向、README 与 manifest 一致、README 对上游的断言与实装的上游一致)。共 **47 个测试文件**——这个数字由 `tests/readme-consistency.spec.ts` 对着 `tests/` 目录校验,不会漂移。
251
251
 
252
252
  ## 发布(维护者)
253
253
 
package/lib/client.js CHANGED
@@ -128,6 +128,7 @@ function parseCatalogReading(value) {
128
128
  stale: row["stale"],
129
129
  ...typeof row["error"] === "string" ? { error: row["error"] } : {},
130
130
  degradations: parseDegradations(row["degradations"]),
131
+ ...typeof row["factsCachedAt"] === "number" ? { factsCachedAt: row["factsCachedAt"] } : {},
131
132
  fetchedAtMs: row["fetchedAtMs"],
132
133
  quotaSource: quotaSource ?? "seed",
133
134
  counts: {
@@ -335,6 +336,7 @@ var en = {
335
336
  catalogDeprecated: "deprecated",
336
337
  catalogUnconfigured: "not configurable",
337
338
  quotaSeed: "Allowances are the built-in snapshot, transcribed",
339
+ factsCached: "Model metadata is from the last successful reading,",
338
340
  refreshLabel: "Catalog refresh (minutes)",
339
341
  refreshHint: "How long requests and the model picker reuse one listing.",
340
342
  writeRejected: "The settings write was rejected (the namespace was reloaded) \u2014 try again",
@@ -434,6 +436,7 @@ var zh = {
434
436
  catalogDeprecated: "\u5DF2\u5F03\u7528",
435
437
  catalogUnconfigured: "\u65E0\u6CD5\u914D\u7F6E",
436
438
  quotaSeed: "\u989D\u5EA6\u6765\u81EA\u5185\u7F6E\u5FEB\u7167\uFF0C\u8F6C\u5199\u4E8E",
439
+ factsCached: "\u6A21\u578B\u5143\u6570\u636E\u6765\u81EA\u4E0A\u6B21\u6210\u529F\u83B7\u53D6\uFF0C",
437
440
  refreshLabel: "\u76EE\u5F55\u5237\u65B0\uFF08\u5206\u949F\uFF09",
438
441
  refreshHint: "\u8BF7\u6C42\u4E0E\u6A21\u578B\u9009\u62E9\u5668\u590D\u7528\u540C\u4E00\u4EFD\u5217\u8868\u7684\u65F6\u957F\u3002",
439
442
  writeRejected: "\u8BBE\u7F6E\u5199\u5165\u88AB\u62D2\u7EDD\uFF08\u5DF2\u91CD\u65B0\u8F7D\u5165\uFF09\uFF0C\u8BF7\u91CD\u8BD5",
@@ -1244,6 +1247,11 @@ function Section({ controller, t, getLocale }) {
1244
1247
  " ",
1245
1248
  SEED_TRANSCRIBED
1246
1249
  ] }),
1250
+ reading !== void 0 && reading.factsCachedAt !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: section_default.hint, children: [
1251
+ t("factsCached"),
1252
+ " ",
1253
+ new Date(reading.factsCachedAt).toISOString().slice(0, 10)
1254
+ ] }),
1247
1255
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: section_default.row, children: [
1248
1256
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: section_default.hint, htmlFor: "dshopencodego-refresh", children: t("refreshLabel") }),
1249
1257
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
package/lib/index.js CHANGED
@@ -17788,8 +17788,8 @@ function getBunSandboxEnvValue(name2) {
17788
17788
  if (procEnvCache === null) {
17789
17789
  procEnvCache = /* @__PURE__ */ new Map();
17790
17790
  try {
17791
- const { readFileSync: readFileSync2 } = __require("node:fs");
17792
- const data = readFileSync2("/proc/self/environ", "utf-8");
17791
+ const { readFileSync: readFileSync3 } = __require("node:fs");
17792
+ const data = readFileSync3("/proc/self/environ", "utf-8");
17793
17793
  for (const entry of data.split("\0")) {
17794
17794
  const idx = entry.indexOf("=");
17795
17795
  if (idx > 0) {
@@ -42463,7 +42463,7 @@ Check your ChatGPT usage: ${CHATGPT_USAGE_URL}` : errorMessage;
42463
42463
 
42464
42464
  // src/index.ts
42465
42465
  import { homedir } from "node:os";
42466
- import { join as join3 } from "node:path";
42466
+ import { join as join4 } from "node:path";
42467
42467
  import { credentialRef } from "@deepseek-ai/dsh-credentials";
42468
42468
  import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
42469
42469
  import * as llm2 from "@deepseek-ai/dsh-llm";
@@ -42530,6 +42530,8 @@ var CONSOLE_BASE_URL = "https://opencode.ai/inference/v1";
42530
42530
  var MODEL_METADATA_URL = "https://models.dev/api.json";
42531
42531
  var MODEL_METADATA_PROVIDER = "opencode-go";
42532
42532
  var METADATA_FETCH_TIMEOUT_MS = 1e4;
42533
+ var MODEL_METADATA_TIMEOUT_MS = 3e4;
42534
+ var METADATA_RETRY_DELAY_MS = 1500;
42533
42535
  var MODEL_LISTING_MAX_BYTES = 1024 * 1024;
42534
42536
  var MODEL_METADATA_MAX_BYTES = 16 * 1024 * 1024;
42535
42537
  var UNKNOWN_MODEL_PROBE_COOLDOWN_MS = 5 * 6e4;
@@ -42551,7 +42553,8 @@ async function readBoundedJson(response, url, maxBytes) {
42551
42553
  text = await readBoundedText(response, maxBytes);
42552
42554
  } catch (error) {
42553
42555
  if (error instanceof LlmError) throw error;
42554
- throw new LlmError(`could not read ${url}`, "DISCOVERY_FAILED", { cause: error });
42556
+ const detail = error instanceof Error ? error.message : String(error);
42557
+ throw new LlmError(`could not read ${url}: ${detail}`, "DISCOVERY_FAILED", { cause: error });
42555
42558
  }
42556
42559
  try {
42557
42560
  return JSON.parse(text);
@@ -43053,6 +43056,43 @@ function toPiModel(facts, baseURL) {
43053
43056
  };
43054
43057
  }
43055
43058
 
43059
+ // src/catalog/metadata-cache.ts
43060
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
43061
+ import { join as join3 } from "node:path";
43062
+ var CACHE_FILE2 = "models-dev-facts.json";
43063
+ var CACHE_VERSION2 = 1;
43064
+ function readFactsCache(cacheDir) {
43065
+ if (cacheDir === void 0) return void 0;
43066
+ try {
43067
+ const parsed = JSON.parse(readFileSync2(join3(cacheDir, CACHE_FILE2), "utf8"));
43068
+ if (parsed.version !== CACHE_VERSION2 || parsed.facts === null || typeof parsed.facts !== "object") return void 0;
43069
+ const facts = /* @__PURE__ */ new Map();
43070
+ for (const [id, fact] of Object.entries(parsed.facts)) {
43071
+ if (fact === null || typeof fact !== "object") continue;
43072
+ if (typeof fact.id !== "string" || typeof fact.api !== "string") continue;
43073
+ facts.set(id, fact);
43074
+ }
43075
+ if (facts.size === 0) return void 0;
43076
+ return { facts, updatedAt: typeof parsed.updatedAt === "number" ? parsed.updatedAt : 0 };
43077
+ } catch {
43078
+ return void 0;
43079
+ }
43080
+ }
43081
+ function writeFactsCache(cacheDir, facts) {
43082
+ if (cacheDir === void 0 || facts.size === 0) return;
43083
+ try {
43084
+ mkdirSync2(cacheDir, { recursive: true });
43085
+ const file = {
43086
+ version: CACHE_VERSION2,
43087
+ facts: Object.fromEntries(facts),
43088
+ updatedAt: Date.now()
43089
+ };
43090
+ writeFileSync2(join3(cacheDir, CACHE_FILE2), `${JSON.stringify(file)}
43091
+ `, "utf8");
43092
+ } catch {
43093
+ }
43094
+ }
43095
+
43056
43096
  // src/catalog/index.ts
43057
43097
  function reasonText(reason) {
43058
43098
  if (reason instanceof Error) return reason.message;
@@ -43101,12 +43141,27 @@ var OpencodeGoCatalog = class {
43101
43141
  metadataDocument;
43102
43142
  metadataETag;
43103
43143
  lastMetadata;
43144
+ /**
43145
+ * The facts a previous successful read produced, read from disk.
43146
+ *
43147
+ * This is what a cold process falls back on when the online metadata cannot
43148
+ * be read. Without it a degraded catalog declares every model unable to
43149
+ * think, and the host refuses the effort the session is already using.
43150
+ */
43151
+ cachedMetadata;
43152
+ /** When the cached facts were written, for the page to show. */
43153
+ cachedAt;
43104
43154
  /** The last parsed documentation; retained across failed fetches. */
43105
43155
  document;
43106
43156
  /** Ids that already forced a revalidation, with the time they did. */
43107
43157
  probedAt = /* @__PURE__ */ new Map();
43108
43158
  constructor(options) {
43109
43159
  this.options = options;
43160
+ const cached = readFactsCache(options.cacheDir);
43161
+ if (cached !== void 0) {
43162
+ this.cachedMetadata = { models: cached.facts, errors: /* @__PURE__ */ new Map() };
43163
+ this.cachedAt = cached.updatedAt;
43164
+ }
43110
43165
  }
43111
43166
  /**
43112
43167
  * The cached snapshot, refreshed when it is older than the configured TTL.
@@ -43220,15 +43275,18 @@ var OpencodeGoCatalog = class {
43220
43275
  ...this.documentQuotas()
43221
43276
  };
43222
43277
  }
43278
+ const fromCache = metadata.status !== "fulfilled" && this.lastMetadata === void 0;
43279
+ const online = metadata.status === "fulfilled" ? metadata.value : this.lastMetadata ?? this.cachedMetadata;
43223
43280
  return this.assemble(
43224
43281
  listing.value,
43225
- metadata.status === "fulfilled" ? metadata.value : this.lastMetadata,
43282
+ online,
43226
43283
  builtin,
43227
- degradations
43284
+ degradations,
43285
+ fromCache ? this.cachedAt : void 0
43228
43286
  );
43229
43287
  }
43230
43288
  /** Merge the listing with the metadata document and the installed entries. */
43231
- assemble(ids, online, builtin, degradations = []) {
43289
+ assemble(ids, online, builtin, degradations = [], factsCachedAt) {
43232
43290
  const facts = /* @__PURE__ */ new Map();
43233
43291
  const unavailable = /* @__PURE__ */ new Map();
43234
43292
  for (const id of ids) {
@@ -43260,6 +43318,7 @@ var OpencodeGoCatalog = class {
43260
43318
  provider: buildProvider2(this.options.baseURL, [...facts.values()].map((fact) => toPiModel(fact, this.options.baseURL))),
43261
43319
  live: true,
43262
43320
  ...degradations.length === 0 ? {} : { degradations },
43321
+ ...factsCachedAt === void 0 ? {} : { factsCachedAt },
43263
43322
  fetchedAtMs: Date.now(),
43264
43323
  ...this.documentQuotas()
43265
43324
  };
@@ -43316,8 +43375,18 @@ var OpencodeGoCatalog = class {
43316
43375
  releaseDate: void 0
43317
43376
  };
43318
43377
  }
43319
- /** Conditional metadata GET: an unchanged document keeps its parsed form. */
43320
- async refreshMetadata(builtin) {
43378
+ /**
43379
+ * Read the model metadata document, once.
43380
+ *
43381
+ * The document is megabytes, so its budget is longer than the other two
43382
+ * reads' — and the host that runs this is not always a plain Node process:
43383
+ * the desktop build fetches over the browser's network stack, where the
43384
+ * same document that a shell reads in half a second can take long enough
43385
+ * to outrun a budget set for kilobyte-sized documents.
43386
+ * @param builtin - the installed catalog, for the parse.
43387
+ * @returns the parsed metadata.
43388
+ */
43389
+ async readMetadataDocument(builtin) {
43321
43390
  const response = await fetch(MODEL_METADATA_URL, {
43322
43391
  redirect: "error",
43323
43392
  headers: {
@@ -43326,7 +43395,7 @@ var OpencodeGoCatalog = class {
43326
43395
  "cache-control": "no-cache",
43327
43396
  ...this.metadataETag === void 0 ? {} : { "if-none-match": this.metadataETag }
43328
43397
  },
43329
- signal: AbortSignal.timeout(METADATA_FETCH_TIMEOUT_MS)
43398
+ signal: AbortSignal.timeout(MODEL_METADATA_TIMEOUT_MS)
43330
43399
  });
43331
43400
  if (response.status === 304 && this.metadataDocument !== void 0) {
43332
43401
  await response.body?.cancel().catch(() => {
@@ -43353,8 +43422,36 @@ var OpencodeGoCatalog = class {
43353
43422
  overrides: this.options.overrides
43354
43423
  });
43355
43424
  this.lastMetadata = parsed;
43425
+ writeFactsCache(this.options.cacheDir, parsed.models);
43356
43426
  return parsed;
43357
43427
  }
43428
+ /**
43429
+ * Read the model metadata document, retrying once.
43430
+ *
43431
+ * The failure this answers is not a broken network: the same document is
43432
+ * reachable from a browser on the same machine while the host cannot read
43433
+ * it. It is the host being busy — a plugin reload rewrites modules, unpacks
43434
+ * packages, and rebuilds the runtime while the catalog asks for the
43435
+ * document, and the request that loses that race is a timeout, not a
43436
+ * refusal. A second attempt, a moment later, is the same request on a host
43437
+ * that has finished what it was doing.
43438
+ * @param builtin - the installed catalog, for the parse.
43439
+ * @returns the parsed metadata.
43440
+ */
43441
+ async refreshMetadata(builtin) {
43442
+ try {
43443
+ return await this.readMetadataDocument(builtin);
43444
+ } catch (first) {
43445
+ await new Promise((resolve3) => {
43446
+ setTimeout(resolve3, METADATA_RETRY_DELAY_MS);
43447
+ });
43448
+ try {
43449
+ return await this.readMetadataDocument(builtin);
43450
+ } catch (second) {
43451
+ throw new Error(`${reasonText(first)}; retry: ${reasonText(second)}`);
43452
+ }
43453
+ }
43454
+ }
43358
43455
  };
43359
43456
  function inferFamily(id) {
43360
43457
  const lower = id.toLowerCase();
@@ -45458,6 +45555,7 @@ function parseCatalogReading(value) {
45458
45555
  stale: row["stale"],
45459
45556
  ...typeof row["error"] === "string" ? { error: row["error"] } : {},
45460
45557
  degradations: parseDegradations(row["degradations"]),
45558
+ ...typeof row["factsCachedAt"] === "number" ? { factsCachedAt: row["factsCachedAt"] } : {},
45461
45559
  fetchedAtMs: row["fetchedAtMs"],
45462
45560
  quotaSource: quotaSource ?? "seed",
45463
45561
  counts: {
@@ -45699,6 +45797,7 @@ function catalogReading(snapshot2, visibility, listingFailure, now) {
45699
45797
  stale: !snapshot2.live,
45700
45798
  ...!snapshot2.live && listingFailure !== void 0 ? { error: listingFailure } : {},
45701
45799
  degradations: snapshot2.degradations ?? [],
45800
+ ...snapshot2.factsCachedAt === void 0 ? {} : { factsCachedAt: snapshot2.factsCachedAt },
45702
45801
  fetchedAtMs: snapshot2.fetchedAtMs,
45703
45802
  quotaSource: documentQuotas === void 0 ? "seed" : "document",
45704
45803
  counts: {
@@ -45867,7 +45966,7 @@ function createUpdateChecker(deps) {
45867
45966
  }
45868
45967
 
45869
45968
  // src/update/version.ts
45870
- var PLUGIN_VERSION = true ? "0.1.48" : "0.0.0-dev";
45969
+ var PLUGIN_VERSION = true ? "0.1.49" : "0.0.0-dev";
45871
45970
 
45872
45971
  // src/update/service.ts
45873
45972
  import { TypertRemoteService as TypertRemoteService2 } from "@deepseek-ai/dsh-typert-protocol";
@@ -46013,8 +46112,8 @@ function resolveCacheDir(ctx) {
46013
46112
  }
46014
46113
  }
46015
46114
  const configured = process.env.DSH_HOME?.trim();
46016
- const root = configured !== void 0 && configured.length > 0 ? configured : join3(homedir(), ".dsh");
46017
- return join3(root, "cache", "@dan-ai-studio/dshopencodego");
46115
+ const root = configured !== void 0 && configured.length > 0 ? configured : join4(homedir(), ".dsh");
46116
+ return join4(root, "cache", "@dan-ai-studio/dshopencodego");
46018
46117
  }
46019
46118
  function apply(ctx, raw) {
46020
46119
  const live = isLiveConfig(raw) ? raw : void 0;
@@ -11,8 +11,28 @@ export declare const CONSOLE_BASE_URL = "https://opencode.ai/inference/v1";
11
11
  export declare const MODEL_METADATA_URL = "https://models.dev/api.json";
12
12
  /** The models.dev provider key this plugin reads. */
13
13
  export declare const MODEL_METADATA_PROVIDER = "opencode-go";
14
- /** Timeout for the two metadata GETs. */
14
+ /** Timeout for the two small metadata GETs. */
15
15
  export declare const METADATA_FETCH_TIMEOUT_MS = 10000;
16
+ /**
17
+ * Timeout for the model metadata document.
18
+ *
19
+ * It is the one read measured in megabytes — 5.9 MB for the whole of
20
+ * models.dev, of which this plugin uses one provider — and the host that
21
+ * fetches it is not always a plain Node process. The desktop build fetches
22
+ * over the browser's network stack, where the same document a shell reads in
23
+ * half a second can outrun a budget set for kilobyte-sized documents. The
24
+ * longer budget costs nothing when the read succeeds; it is the difference
25
+ * between a catalog and a degraded one.
26
+ */
27
+ export declare const MODEL_METADATA_TIMEOUT_MS = 30000;
28
+ /**
29
+ * How long to wait before the one retry of the metadata read.
30
+ *
31
+ * Long enough for the host to finish whatever it was doing — a plugin
32
+ * reload, a package unpack — and short enough that a genuinely unreachable
33
+ * document still fails inside the catalog build.
34
+ */
35
+ export declare const METADATA_RETRY_DELAY_MS = 1500;
16
36
  /** Response caps: the listing is tiny, the metadata document is not. */
17
37
  export declare const MODEL_LISTING_MAX_BYTES: number;
18
38
  export declare const MODEL_METADATA_MAX_BYTES: number;
@@ -73,6 +73,15 @@ export interface CatalogSnapshot {
73
73
  * a user cannot act on.
74
74
  */
75
75
  readonly degradations?: readonly CatalogDegradation[];
76
+ /**
77
+ * When the facts in this snapshot were written, when they came from disk
78
+ * rather than from a live read.
79
+ *
80
+ * The listing is always live; the metadata behind it may be older. The page
81
+ * says so, because a capacity that was true last week reads exactly like
82
+ * one that is true now.
83
+ */
84
+ readonly factsCachedAt?: number;
76
85
  readonly fetchedAtMs: number;
77
86
  }
78
87
  /** Observers the plugin logs through. */
@@ -126,6 +135,16 @@ export declare class OpencodeGoCatalog {
126
135
  private metadataDocument;
127
136
  private metadataETag;
128
137
  private lastMetadata;
138
+ /**
139
+ * The facts a previous successful read produced, read from disk.
140
+ *
141
+ * This is what a cold process falls back on when the online metadata cannot
142
+ * be read. Without it a degraded catalog declares every model unable to
143
+ * think, and the host refuses the effort the session is already using.
144
+ */
145
+ private cachedMetadata;
146
+ /** When the cached facts were written, for the page to show. */
147
+ private readonly cachedAt;
129
148
  /** The last parsed documentation; retained across failed fetches. */
130
149
  private document;
131
150
  /** Ids that already forced a revalidation, with the time they did. */
@@ -193,7 +212,31 @@ export declare class OpencodeGoCatalog {
193
212
  private withDocumentedProtocol;
194
213
  /** Facts for an id no source describes, from the ladder and the route defaults. */
195
214
  private inferredFacts;
196
- /** Conditional metadata GET: an unchanged document keeps its parsed form. */
215
+ /**
216
+ * Read the model metadata document, once.
217
+ *
218
+ * The document is megabytes, so its budget is longer than the other two
219
+ * reads' — and the host that runs this is not always a plain Node process:
220
+ * the desktop build fetches over the browser's network stack, where the
221
+ * same document that a shell reads in half a second can take long enough
222
+ * to outrun a budget set for kilobyte-sized documents.
223
+ * @param builtin - the installed catalog, for the parse.
224
+ * @returns the parsed metadata.
225
+ */
226
+ private readMetadataDocument;
227
+ /**
228
+ * Read the model metadata document, retrying once.
229
+ *
230
+ * The failure this answers is not a broken network: the same document is
231
+ * reachable from a browser on the same machine while the host cannot read
232
+ * it. It is the host being busy — a plugin reload rewrites modules, unpacks
233
+ * packages, and rebuilds the runtime while the catalog asks for the
234
+ * document, and the request that loses that race is a timeout, not a
235
+ * refusal. A second attempt, a moment later, is the same request on a host
236
+ * that has finished what it was doing.
237
+ * @param builtin - the installed catalog, for the parse.
238
+ * @returns the parsed metadata.
239
+ */
197
240
  private refreshMetadata;
198
241
  }
199
242
  /**
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Keeping what the last successful metadata read said.
3
+ *
4
+ * The online metadata is the only source that states which models can think
5
+ * and at which levels. When it cannot be read, the plugin still knows some of
6
+ * that — from the last time it could — and throwing that away turns a
7
+ * degraded catalog into a broken one: a model that does think is declared
8
+ * unable to think, the host's own check refuses the effort the session is
9
+ * already using, and the run fails before it starts.
10
+ *
11
+ * So the parsed facts are written down. What is written is deliberately
12
+ * small: the capabilities, the capacities, the prices — not the document.
13
+ * The listing stays the authority on which models exist, so a stale file can
14
+ * never introduce a model the gateway does not serve; it can only describe
15
+ * the ones it does, with what was true when the file was written.
16
+ *
17
+ * @module @dan-ai-studio/dshopencodego/catalog/metadata-cache
18
+ */
19
+ import type { ModelFacts } from './metadata.ts';
20
+ /**
21
+ * The facts a previous successful read produced.
22
+ *
23
+ * A cache that cannot be read is no cache: the caller then has nothing to
24
+ * fall back on and says so, rather than pretending the models have no
25
+ * capabilities.
26
+ * @param cacheDir - the plugin's cache directory.
27
+ * @returns the remembered facts and when they were written, or undefined.
28
+ */
29
+ export declare function readFactsCache(cacheDir: string | undefined): {
30
+ readonly facts: ReadonlyMap<string, ModelFacts>;
31
+ readonly updatedAt: number;
32
+ } | undefined;
33
+ /**
34
+ * Remember the facts a successful read produced.
35
+ *
36
+ * A cache directory that cannot be written costs a degraded catalog after the
37
+ * next restart, and nothing else: the run continues with what it has.
38
+ * @param cacheDir - the plugin's cache directory.
39
+ * @param facts - the parsed facts to remember.
40
+ */
41
+ export declare function writeFactsCache(cacheDir: string | undefined, facts: ReadonlyMap<string, ModelFacts>): void;
@@ -29,6 +29,15 @@ export interface CatalogReading {
29
29
  * difference between a user who can act and a user who cannot.
30
30
  */
31
31
  readonly degradations: readonly CatalogDegradation[];
32
+ /**
33
+ * When the model metadata behind this reading was written, when it came
34
+ * from disk rather than from a live read.
35
+ *
36
+ * The listing is live; the capacities, prices, and thinking levels behind
37
+ * it may not be. The page shows this, because a stale number reads exactly
38
+ * like a current one.
39
+ */
40
+ readonly factsCachedAt?: number;
32
41
  /** When the underlying snapshot was built. */
33
42
  readonly fetchedAtMs: number;
34
43
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dan-ai-studio/dshopencodego",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "description": "OpenCode Go provider for DeepSeek Harness: live gateway catalog, per-conversation session header, usage",
5
5
  "type": "module",
6
6
  "license": "MIT",