Commit Graph
8 Commits
Author SHA1 Message Date
Loongphy 76c3b7201b feat: raise max output tokens to 128K (documented upstream ceiling)
Aliyun Model Studio (the upstream behind Qoder's CN catalog) documents
Max Output Length = 131072 for every model we expose, in both normal and
thinking modes (thinking chain alone goes to 262144):
  qwen3.8-max/flash, qwen3.7-max/plus/flash — all 131072.

The previous 32768 default (copied from qodercli's conservative 32e3) used
only 1/4 of the supported output budget. That truncates reasoning chains in
thinking mode (where the chain counts against output) and risks cutting long
generations / compaction summaries. qodercli caps its own UI at 65536, still
below the documented ceiling.

- models.ts: introduce MAX_OUTPUT_TOKENS = 131072 as the single source of
  truth; all 24 staticModels entries + the lazy-loaded CN entry now reference
  it. Remove the dead max_output_tokens field from the CN placeholder entry.
- stream.ts: maxTokens defaults to MAX_OUTPUT_TOKENS; still capped lower by
  options.maxTokens (e.g. pi compaction passes 40000).

Verified against the real CN endpoint: max_tokens=131072 returns 200 / stop
(accepted, not rejected); an xhigh reasoning run completes with
finish_reason=stop (not truncated). Field placement + reasoning_effort send
also confirmed working in the same request.
2026-08-28 19:36:59 +08:00
Loongphy 112da4deaf refactor: drop dead max_output_tokens, simplify maxTokens to 32K + pi cap
Qoder's /model/list catalog never returns max_output_tokens (the field does
not exist on any entry — only max_input_tokens is present), so the per-model
lookup `entry.max_output_tokens || 32768` was dead code that always fell back
to the 32768 literal.

- models.ts: remove max_output_tokens from QoderModelEntry; maxTokens is now a
  flat 32768 (matches qodercli's 32e3 fallback).
- stream.ts: remove the now-unused maxOutputTokens variable and its always-true
  branch; maxTokens = 32768, capped lower only by options.maxTokens (e.g. pi
  compaction passes 40000). pi-ai's maxTokens setting still has an outlet.
- stream.ts fallback modelConfig: drop the dead max_output_tokens: 32768 field.

qodercli does conditionally send max_tokens (user setting → generation config
→ 32K fallback), but the field is not required by the upstream API. Keeping it
gives pi-ai's options.maxTokens a place to flow through.
2026-08-28 19:07:16 +08:00
Loongphy 5393c24b7e feat: send reasoning_effort + enable_thinking to Qoder upstream
The picker was fixed to show thinking levels, but the chosen level was never
forwarded: stream.ts only used options.reasoning to toggle the local thinking
parser, so every request let the model default-decide its reasoning effort.

Reverse-engineered @qoder-ai/qodercli (bundle/qodercli.js) to confirm the
request shape: the chat body's `parameters` object carries `reasoning_effort`
("none"|"low"|"medium"|"high"|"xhigh"|"max") and `enable_thinking` (bool)
alongside `max_tokens`. qodercli's Zlr() sets reasoning_effort = zN(req)
(reasoning.enabled===false ? "none" : reasoning.effort) and enable_thinking.

Implementation follows the pi-ai OpenAI provider pattern:
  - clampThinkingLevel(model, options.reasoning) clamps the requested level to
    what the model advertises via thinkingLevelMap (returns "off" when
    unsupported or disabled);
  - map the clamped level to the upstream effort name via thinkingLevelMap,
    falling back to the pi level name (Qoder effort names already match pi);
  - effort-based models (thinking_config.enabled.efforts present, e.g.
    qwen3.8-max) get reasoning_effort + enable_thinking=true;
  - toggle-only models (qwen3.7-max: enabled/disabled, no efforts) get
    enable_thinking=true only — no reasoning_effort, since they accept no level;
  - no level / clamped to off: enable_thinking=false to explicitly disable.

Qoder has no "minimal" effort; clampThinkingLevel handles stepping it down
based on the model's thinkingLevelMap (minimal is pinned to null for effort
models, so it clamps to the next supported level).
2026-08-28 18:57:56 +08:00
Loongphy 88cf414a8e feat(cn): map Qoder thinking_config to pi thinkingLevelMap for the picker
The catalog API returns each model's supported thinking efforts
(thinking_config.enabled.efforts, e.g. low/medium/xhigh for qwen3.8), but the
provider never populated Model.thinkingLevelMap, so pi's getSupportedThinkingLevels
hid xhigh/max (they require a non-undefined map entry) and the picker topped out
at "high" even for models that support xhigh.

Parse thinking_config at catalog fetch time and build the map:

- effort-based models (qwen3.8-max/flash, DeepSeek, GLM): each supported
  effort maps to its same-named pi level; unsupported levels pin to null
  (hidden). xhigh is now exposed. "off" is selectable when the catalog also
  advertises a "disabled" option.
- toggle-only models (qwen3.7-max/plus: enabled/disabled, no efforts):
  every pi level is exposed and maps to "enabled" so picking any level turns
  thinking on; "off" selectable when "disabled" is advertised.
- models without thinking_config (qwen3.7-flash): no map, pi falls back to its
  default level set.

Qoder effort keys are already pi level names (low/medium/high/xhigh/max), so
the mapping is by identity — no translation table.

This is display-layer only: it fixes which thinking levels the picker shows.
Sending the chosen effort upstream is a separate change that needs the exact
request field from a qoder-cli capture; the map values ("low"/"xhigh"/
"enabled"/"disabled") are placeholders that will be mapped to the request
shape once confirmed.
2026-08-28 17:27:07 +08:00
Loongphy cc461cd145 refactor: drop redundant max_input_tokens, default context fallback to 200K
max_input_tokens (180K) was only used to seed the context window before
context_config options overrode it. Every live CN model exposes selectable
contexts (200K/400K/1M) whose smallest option already exceeds 180K, so the
seed only ever acted as a redundant floor and was never the final value.

- updateQoderModelsCache: derive contextWindow from the largest
  context_config option directly; fall back to 200K when no context_config is
  present (was 180K via max_input_tokens).
- staticCnModels: the Auto entry (the no-context fallback) now uses 200K too,
  matching the dynamic fallback; its description no longer references the
  stale 180K live-catalog note.
2026-08-28 10:11:37 +08:00
Loongphy b462207447 feat(cn): expose upstream display_name as model id, drop key mapping tables
The CN model picker used to translate Qoder's internal keys (qfmodel,
qmodel_latest, ...) into hardcoded "friendly" ids (qwen3.6-flash, ...) via a
manual mapping table, with the display label hardcoded alongside. Both
sides rotted independently of upstream: when Qoder upgraded qfmodel to
Qwen3.8-Flash the label stayed "Qwen 3.6 Flash", and new keys (qmodel_38max,
q37fmodel) had no entry so their raw key leaked into the picker as the id.

The catalog API already returns every key with its display_name, so the
mapping table duplicates data the server provides and can only ever be stale.

Rework: use the upstream display_name (whitespace-stripped) directly as the
pi-visible Model.id, and read the request-time upstream key back from the
cached model config at send time. No key<->friendlyId table is needed.

- cosy.ts: remove qoderCNFriendlyModels, getQoderCNDirectModel,
  getQoderCNFriendlyModelInfo, toQoderCNFriendlyModel, prettifyQoderCNModelName.
  Add toQoderCNModelId(display) = display with whitespace stripped.
- models.ts: updateQoderModelsCache now sets CN model id =
  toQoderCNModelId(display_name); the original key is still stored in configs
  (keyed by both key and id) and read back via getCachedModelConfig. Simplify
  the CN fallback in getCachedModelConfig (drop the stale reasoning set).
  staticCnModels ids/names rewritten to the display_name form.
- stream.ts: the upstream key comes from modelConfig.key (the cached entry)
  instead of a reverse-lookup table; falls back to model.id for the
  international site, which already uses the key as id.
- index.ts: modelsForProvider no longer re-maps CN models through a friendly
  transform — the cached/static ids are already the display name.

Trade-off: a renamed/upgraded model changes its id, so a previously saved
default model may no longer resolve after an upstream rename and the user
reselects. This is expected: users should learn about new models. This is
accepted.

Tests updated for the new contract; e2e against the live CN catalog confirms
id=Qwen3.8-Flash resolves to send key=qfmodel with no mapping table.
2026-08-28 08:16:36 +08:00
LoongphyandOyster Lee 6956615f66 fix: pi.extensions path should point to dist/index.js instead of src/index.ts
The "files" field in package.json only includes "dist" and "README.md",
so src/index.ts is not available in the published npm package.

This was introduced in commit 1b110a6 ("fix index") which changed
the path from the correct "./dist/index.js" to "./src/index.ts".
2026-08-03 06:50:04 +08:00
Loongphy 6d9635e52c fix: pi.extensions path should point to dist/index.js instead of src/index.ts
The "files" field in package.json only includes "dist" and "README.md",
so src/index.ts is not available in the published npm package.

This was introduced in commit 1b110a6 ("fix index") which changed
the path from the correct "./dist/index.js" to "./src/index.ts".
2026-07-31 06:37:45 +08:00