@koreanhole/opencodex 3.2.3 → 3.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koreanhole/opencodex",
3
- "version": "3.2.3",
3
+ "version": "3.2.5",
4
4
  "description": "Full opencodex runtime with Cline JSON and Gemini CLI headless provider adapters",
5
5
  "type": "module",
6
6
  "main": "./bin/package-main.mjs",
@@ -69,6 +69,7 @@ interface CacheEntry {
69
69
 
70
70
  const cache = new Map<string, CacheEntry>();
71
71
  const failureCache = new Map<string, number>();
72
+ const DEFAULT_GEMINI_CONTEXT = 1_048_576;
72
73
 
73
74
  export function resetGeminiLiveModelsCacheForTests(): void {
74
75
  cache.clear();
@@ -91,6 +92,23 @@ function staleResult(fingerprint: string, entry: CacheEntry | undefined): Gemini
91
92
  };
92
93
  }
93
94
 
95
+ function defaultModelInfo(metadata: GeminiMetadataResult, models: readonly OcxProviderModel[]): OcxProviderModel {
96
+ const contexts = models.flatMap(model => model.contextWindowTokens !== undefined ? [model.contextWindowTokens] : []);
97
+ const context = contexts.length > 0
98
+ ? Math.min(...contexts)
99
+ : metadata.defaultTokenLimit ?? DEFAULT_GEMINI_CONTEXT;
100
+ return {
101
+ id: "default",
102
+ name: "Gemini default",
103
+ description: "Gemini CLI default model",
104
+ supportedReasoningLevels: [],
105
+ contextWindowTokens: context,
106
+ maxContextWindowTokens: context,
107
+ inputModalities: ["text"],
108
+ loadSession: false,
109
+ };
110
+ }
111
+
94
112
  async function discoverRuntimeModels(input: {
95
113
  binary: string;
96
114
  env: NodeJS.ProcessEnv;
@@ -192,8 +210,26 @@ export async function discoverGeminiLiveModels(options: GeminiLiveModelsOptions
192
210
  if (current) current.lastFailureAt = timestamp;
193
211
  const detail = metadata.warning
194
212
  ?? (runtimeError instanceof Error ? runtimeError.message : "Gemini runtime models were not found.");
195
- return staleResult(fingerprint, current)
196
- ?? { ok: false, reason: "transport", detail, fingerprint };
213
+ const stale = staleResult(fingerprint, current);
214
+ if (stale) return stale;
215
+ const fallback = defaultModelInfo(metadata, []);
216
+ const result: GeminiLiveModelsResult = {
217
+ ok: true,
218
+ models: ["default"],
219
+ modelInfo: [fallback],
220
+ source: "default",
221
+ fingerprint,
222
+ metadataWarning: detail,
223
+ };
224
+ cache.set(fingerprint, {
225
+ models: ["default"],
226
+ modelInfo: [fallback],
227
+ source: "default",
228
+ fetchedAt: timestamp,
229
+ lastFailureAt: timestamp,
230
+ metadataWarning: detail,
231
+ });
232
+ return result;
197
233
  }
198
234
 
199
235
  await recordGeminiCompressionThreshold(fingerprint, metadata.compressionThreshold, sourceEnv);
@@ -216,9 +252,10 @@ export async function discoverGeminiLiveModels(options: GeminiLiveModelsOptions
216
252
  loadSession: false,
217
253
  };
218
254
  });
255
+ const modelInfoWithDefault = [defaultModelInfo(metadata, modelInfo), ...modelInfo.filter(model => model.id !== "default")];
219
256
  const warning = metadata.warning
220
257
  ?? (runtimeError ? "Gemini runtime model discovery failed; using installed CLI metadata." : undefined);
221
- cache.set(fingerprint, { models: ids, modelInfo, source: "models", fetchedAt: timestamp, ...(warning ? { metadataWarning: warning } : {}) });
258
+ cache.set(fingerprint, { models: ids, modelInfo: modelInfoWithDefault, source: "models", fetchedAt: timestamp, ...(warning ? { metadataWarning: warning } : {}) });
222
259
  failureCache.delete(fingerprint);
223
- return { ok: true, models: ids, modelInfo, source: "models", fingerprint, ...(warning ? { metadataWarning: warning } : {}) };
260
+ return { ok: true, models: ids, modelInfo: modelInfoWithDefault, source: "models", fingerprint, ...(warning ? { metadataWarning: warning } : {}) };
224
261
  }
@@ -179,13 +179,13 @@ function defaultModel(): OcxProviderModel {
179
179
  }
180
180
 
181
181
  function normalizedModels(models: readonly OcxProviderModel[]): OcxProviderModel[] {
182
- const seen = new Set<string>();
183
- const out: OcxProviderModel[] = [];
184
- for (const model of [defaultModel(), ...models]) {
185
- if (!seen.has(model.id)) {
186
- seen.add(model.id);
187
- out.push(model);
188
- }
182
+ const defaultInfo = models.find(model => model.id === "default");
183
+ const out: OcxProviderModel[] = [{ ...defaultModel(), ...(defaultInfo ?? {}), id: "default" }];
184
+ const seen = new Set<string>(["default"]);
185
+ for (const model of models) {
186
+ if (model.id === "default" || seen.has(model.id)) continue;
187
+ seen.add(model.id);
188
+ out.push(model);
189
189
  }
190
190
  return out;
191
191
  }
@@ -394,7 +394,8 @@ export function modelList(
394
394
  }));
395
395
  }
396
396
  if (scope) {
397
- const entries = ["default", ...(known[scope] ?? []).filter(entry => modelIdOf(entry) !== "default")];
397
+ const defaultEntry = (known[scope] ?? []).find(entry => modelIdOf(entry) === "default") ?? "default";
398
+ const entries = [defaultEntry, ...(known[scope] ?? []).filter(entry => modelIdOf(entry) !== "default")];
398
399
  const rows: Array<Record<string, unknown>> = [];
399
400
  const seen = new Set<string>();
400
401
  for (const entry of entries) {
@@ -439,7 +440,8 @@ export function modelList(
439
440
  display_name: "Configured default provider",
440
441
  }];
441
442
  for (const providerId of [CLINE_PROVIDER_ID, GEMINI_PROVIDER_ID] as const) {
442
- const entries = ["default", ...(known[providerId] ?? []).filter(entry => modelIdOf(entry) !== "default")];
443
+ const defaultEntry = (known[providerId] ?? []).find(entry => modelIdOf(entry) === "default") ?? "default";
444
+ const entries = [defaultEntry, ...(known[providerId] ?? []).filter(entry => modelIdOf(entry) !== "default")];
443
445
  const seen = new Set<string>();
444
446
  for (const entry of entries) {
445
447
  const id = modelIdOf(entry);