@kenkaiiii/gg-core 5.55.1 → 5.56.1

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/dist/index.d.cts CHANGED
@@ -15,8 +15,8 @@ declare function getNextThinkingLevel(provider: Provider, model: string, current
15
15
  * provider in gg-ai's stream.ts); the only per-server difference is where the
16
16
  * *capabilities* come from, because `GET /v1/models` reports nothing useful:
17
17
  *
18
- * - Ollama → `POST /api/show` `capabilities[]` + `model_info["<arch>.context_length"]`
19
- * - LM Studio → `GET /api/v0/models` `type`, `state`, `max_context_length`
18
+ * - Ollama → `/api/show` + `/api/ps` → capabilities + running context
19
+ * - LM Studio → `/api/v1/models` (v0 fallback) capabilities + loaded context
20
20
  * - llama.cpp → `GET /props` → `default_generation_settings.n_ctx`
21
21
  * - vLLM/other → nothing; `max_model_len` sometimes rides the model object.
22
22
  *
@@ -70,7 +70,7 @@ declare const DEFAULT_LOCAL_ENDPOINTS: readonly LocalEndpoint[];
70
70
  * conservative: over-guessing means the provider 400s mid-run at a point
71
71
  * auto-compaction already sailed past, while under-guessing only compacts early.
72
72
  */
73
- declare const FALLBACK_CONTEXT_WINDOW = 8192;
73
+ declare const FALLBACK_CONTEXT_WINDOW = 4096;
74
74
  /** Placeholder token for endpoints with no key — these servers ignore it. */
75
75
  declare const LOCAL_API_KEY_PLACEHOLDER = "local";
76
76
  /**
package/dist/index.d.ts CHANGED
@@ -15,8 +15,8 @@ declare function getNextThinkingLevel(provider: Provider, model: string, current
15
15
  * provider in gg-ai's stream.ts); the only per-server difference is where the
16
16
  * *capabilities* come from, because `GET /v1/models` reports nothing useful:
17
17
  *
18
- * - Ollama → `POST /api/show` `capabilities[]` + `model_info["<arch>.context_length"]`
19
- * - LM Studio → `GET /api/v0/models` `type`, `state`, `max_context_length`
18
+ * - Ollama → `/api/show` + `/api/ps` → capabilities + running context
19
+ * - LM Studio → `/api/v1/models` (v0 fallback) capabilities + loaded context
20
20
  * - llama.cpp → `GET /props` → `default_generation_settings.n_ctx`
21
21
  * - vLLM/other → nothing; `max_model_len` sometimes rides the model object.
22
22
  *
@@ -70,7 +70,7 @@ declare const DEFAULT_LOCAL_ENDPOINTS: readonly LocalEndpoint[];
70
70
  * conservative: over-guessing means the provider 400s mid-run at a point
71
71
  * auto-compaction already sailed past, while under-guessing only compacts early.
72
72
  */
73
- declare const FALLBACK_CONTEXT_WINDOW = 8192;
73
+ declare const FALLBACK_CONTEXT_WINDOW = 4096;
74
74
  /** Placeholder token for endpoints with no key — these servers ignore it. */
75
75
  declare const LOCAL_API_KEY_PLACEHOLDER = "local";
76
76
  /**
package/dist/index.js CHANGED
@@ -54,7 +54,7 @@ import {
54
54
  registerRuntimeModels,
55
55
  usesOpenAICodexTransport,
56
56
  withFileLock
57
- } from "./chunk-WPX6Z5NG.js";
57
+ } from "./chunk-PSLSIL3V.js";
58
58
  import {
59
59
  getAppPaths
60
60
  } from "./chunk-EAIPT76S.js";
@@ -69,7 +69,8 @@ var OPENAI_GPT_56_THINKING_LEVELS = [
69
69
  "max",
70
70
  "ultra"
71
71
  ];
72
- var SAKANA_THINKING_LEVELS = ["high", "xhigh"];
72
+ var SAKANA_THINKING_LEVELS = ["high", "xhigh", "max"];
73
+ var DEEPSEEK_THINKING_LEVELS = ["low", "high", "max"];
73
74
  var XAI_THINKING_LEVELS = ["low", "medium", "high", "xhigh"];
74
75
  var ANTHROPIC_XHIGH_THINKING_LEVELS = [
75
76
  "low",
@@ -133,6 +134,7 @@ function getSupportedThinkingLevels(provider, model) {
133
134
  return XAI_THINKING_LEVELS.slice(0, maxIndex2 + 1);
134
135
  }
135
136
  if (isMoonshotK3Model(provider, model)) return MOONSHOT_K3_THINKING_LEVELS;
137
+ if (provider === "deepseek") return DEEPSEEK_THINKING_LEVELS;
136
138
  if (isGlmModel(provider)) {
137
139
  const maxIndex2 = GLM_THINKING_LEVELS.indexOf(maxLevel);
138
140
  if (maxIndex2 === -1) return GLM_THINKING_LEVELS;
@@ -149,7 +151,7 @@ function isThinkingLevelSupported(provider, model, level) {
149
151
  }
150
152
  function getNextThinkingLevel(provider, model, current) {
151
153
  const supportedLevels = getSupportedThinkingLevels(provider, model);
152
- const shouldCycleLevels = isOpenAIGptModel(provider, model) || isAnthropicAdaptiveModel(provider, model) || isSakanaModel(provider) || isXaiModel(provider) || isMoonshotK3Model(provider, model) || isGlmModel(provider) || // Local servers take a real effort level, not just on/off: Ollama accepts
154
+ const shouldCycleLevels = isOpenAIGptModel(provider, model) || isAnthropicAdaptiveModel(provider, model) || isSakanaModel(provider) || isXaiModel(provider) || isMoonshotK3Model(provider, model) || isGlmModel(provider) || provider === "deepseek" || // Local servers take a real effort level, not just on/off: Ollama accepts
153
155
  // low/medium/high on `reasoning_effort` (verified against 0.32) and the
154
156
  // other OpenAI-compatible servers use the same three. A model that can't
155
157
  // reason at all already has no supported levels, so it never gets here.
@@ -167,7 +169,7 @@ function getNextThinkingLevel(provider, model, current) {
167
169
  var DEFAULT_LOCAL_ENDPOINTS = [
168
170
  { id: "ollama", label: "Ollama", baseUrl: "http://127.0.0.1:11434/v1", kind: "ollama" }
169
171
  ];
170
- var FALLBACK_CONTEXT_WINDOW = 8192;
172
+ var FALLBACK_CONTEXT_WINDOW = 4096;
171
173
  var LOCAL_API_KEY_PLACEHOLDER = "local";
172
174
  var DEFAULT_PROBE_TIMEOUT_MS = 1200;
173
175
  var ENRICH_CONCURRENCY = 6;
@@ -260,7 +262,7 @@ async function enrich(endpoint, entries, options) {
260
262
  return entries.map((entry) => genericModel(endpoint, entry));
261
263
  }
262
264
  function genericModel(endpoint, entry) {
263
- const declared = typeof entry.max_model_len === "number" ? entry.max_model_len : void 0;
265
+ const declared = contextLength(entry.max_model_len);
264
266
  return {
265
267
  rawId: entry.id,
266
268
  endpointId: endpoint.id,
@@ -273,16 +275,23 @@ function genericModel(endpoint, entry) {
273
275
  }
274
276
  async function enrichOllama(endpoint, entries, options) {
275
277
  const showUrl = `${endpointRoot(endpoint.baseUrl)}/api/show`;
278
+ const running = await fetchJson(
279
+ `${endpointRoot(endpoint.baseUrl)}/api/ps`,
280
+ endpoint,
281
+ options
282
+ );
283
+ const runningModels = Array.isArray(running?.models) ? running.models : [];
276
284
  const enriched = await mapLimited(entries, ENRICH_CONCURRENCY, async (entry) => {
277
285
  const show = await fetchJson(showUrl, endpoint, {
278
286
  ...options,
279
287
  method: "POST",
280
288
  body: { model: entry.id }
281
289
  });
282
- if (!show) return genericModel(endpoint, entry);
283
- const caps = show.capabilities ?? [];
290
+ const caps = Array.isArray(show?.capabilities) ? show.capabilities : [];
284
291
  if (caps.includes("embedding") && !caps.includes("completion")) return void 0;
285
- const ctx = ollamaContextLength(show.model_info);
292
+ const ctx = contextLength(
293
+ runningModels.find((model) => model?.name === entry.id || model?.model === entry.id)?.context_length
294
+ );
286
295
  return {
287
296
  rawId: entry.id,
288
297
  endpointId: endpoint.id,
@@ -290,38 +299,61 @@ async function enrichOllama(endpoint, entries, options) {
290
299
  contextWindowKnown: ctx !== void 0,
291
300
  // Ollama reports capabilities honestly, so trust it here rather than
292
301
  // using the optimistic generic default.
293
- supportsTools: caps.includes("tools"),
302
+ supportsTools: show ? caps.includes("tools") : true,
294
303
  supportsImages: caps.includes("vision"),
295
304
  supportsThinking: caps.includes("thinking")
296
305
  };
297
306
  });
298
307
  return enriched.filter((model) => model !== void 0);
299
308
  }
300
- function ollamaContextLength(info) {
301
- if (!info) return void 0;
302
- for (const [key, value] of Object.entries(info)) {
303
- if (key.endsWith(".context_length") && typeof value === "number" && value > 0) return value;
304
- }
305
- return void 0;
309
+ function contextLength(value) {
310
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
306
311
  }
307
312
  async function enrichLmStudio(endpoint, entries, options) {
308
- const detail = await fetchJson(
309
- `${endpointRoot(endpoint.baseUrl)}/api/v0/models`,
310
- endpoint,
311
- options
312
- );
313
- if (!detail?.data) return entries.map((entry) => genericModel(endpoint, entry));
314
- const byId = new Map(detail.data.filter((m) => m.id).map((m) => [m.id, m]));
313
+ const root = endpointRoot(endpoint.baseUrl);
314
+ const detail = await fetchJson(`${root}/api/v1/models`, endpoint, options);
315
+ const byId = /* @__PURE__ */ new Map();
316
+ if (Array.isArray(detail?.models)) {
317
+ for (const model of detail.models) {
318
+ if (typeof model?.key !== "string") continue;
319
+ const instances = Array.isArray(model.loaded_instances) ? model.loaded_instances : [];
320
+ const contexts = instances.map((instance) => contextLength(instance?.config?.context_length));
321
+ const ctx = contexts.length && contexts.every((value) => value !== void 0) ? contexts.reduce((min, value) => Math.min(min, value)) : void 0;
322
+ const info = {
323
+ id: model.key,
324
+ type: model.type === "llm" && model.capabilities?.vision === true ? "vlm" : model.type,
325
+ state: instances.length ? "loaded" : "not-loaded",
326
+ loaded_context_length: ctx
327
+ };
328
+ byId.set(model.key, info);
329
+ for (const instance of instances) {
330
+ if (typeof instance?.id === "string" && instance.id !== model.key) {
331
+ byId.set(instance.id, {
332
+ ...info,
333
+ id: instance.id,
334
+ loaded_context_length: contextLength(instance.config?.context_length)
335
+ });
336
+ }
337
+ }
338
+ }
339
+ } else {
340
+ const legacy = await fetchJson(`${root}/api/v0/models`, endpoint, options);
341
+ if (Array.isArray(legacy?.data)) {
342
+ for (const model of legacy.data) {
343
+ if (typeof model?.id === "string") byId.set(model.id, model);
344
+ }
345
+ }
346
+ }
315
347
  const models = [];
316
348
  for (const entry of entries) {
317
349
  const info = byId.get(entry.id);
318
350
  if (info && info.type !== "llm" && info.type !== "vlm") continue;
319
- const ctx = info?.max_context_length;
351
+ const ctx = info?.state === "loaded" ? contextLength(info.loaded_context_length) : void 0;
320
352
  models.push({
321
353
  rawId: entry.id,
322
354
  endpointId: endpoint.id,
323
- contextWindow: typeof ctx === "number" && ctx > 0 ? ctx : FALLBACK_CONTEXT_WINDOW,
324
- contextWindowKnown: typeof ctx === "number" && ctx > 0,
355
+ contextWindow: ctx ?? FALLBACK_CONTEXT_WINDOW,
356
+ contextWindowKnown: ctx !== void 0,
325
357
  // LM Studio doesn't report tool support; it gates per-model at request time.
326
358
  supportsTools: true,
327
359
  supportsImages: info?.type === "vlm",
@@ -337,8 +369,8 @@ async function enrichLlamaCpp(endpoint, entries, options) {
337
369
  endpoint,
338
370
  options
339
371
  );
340
- const nCtx = props?.default_generation_settings?.n_ctx;
341
- const known = typeof nCtx === "number" && nCtx > 0;
372
+ const nCtx = contextLength(props?.default_generation_settings?.n_ctx);
373
+ const known = nCtx !== void 0;
342
374
  return entries.map((entry) => ({
343
375
  ...genericModel(endpoint, entry),
344
376
  contextWindow: known ? nCtx : FALLBACK_CONTEXT_WINDOW,