Commit Graph
90 Commits
Author SHA1 Message Date
dependabot[bot]andGitHub 842750054e build(deps-dev): bump postcss
Bumps the npm_and_yarn group with 1 update in the / directory: [postcss](https://github.com/postcss/postcss).


Updates `postcss` from 8.5.15 to 8.5.25
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.5.15...8.5.25)

---
updated-dependencies:
- dependency-name: postcss
  dependency-version: 8.5.25
  dependency-type: indirect
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-07-30 11:16:19 +00:00
Simon ShiandGitHub a333aaf812 Merge pull request #10 from het-e2m/patch-1
feat: add latest Qoder frontier models
2026-07-30 19:15:27 +08:00
Simon ShiandGitHub 8b328aea1d Merge pull request #9 from unship/fix/stability
fix(stream): stop silently swallowing upstream errors and session-lock stalls
2026-07-30 19:15:07 +08:00
liyanan 37ce615e62 test(stream): assert usage input excludes cached/written tokens
Follow the fix in stream.ts: prompt_tokens (42) includes cached_tokens (5),
so input = 42 - 5 - 10 = 27. Use cache_write_tokens (not cacheable_tokens)
for cacheWrite, and keep cacheable_tokens:99 in the payload to prove it is
no longer mapped to cacheWrite.
2026-07-30 12:42:27 +08:00
liyanan d4c31fcc4e fix(stream): map usage to pi-core's cache convention (input excludes cached tokens)
pi-core computes promptTokens = input + cacheRead + cacheWrite (Anthropic
convention: input EXCLUDES cached/written tokens), but qoder follows OpenAI
semantics where prompt_tokens INCLUDES cached_tokens. pi-ai's own OpenAI
provider subtracts them; this provider didn't, which under-reported the
cache rate (45% vs the true ~83%) and tripped pi-core's miss detector on
every cached turn.

- input = max(0, prompt_tokens - cacheRead - cache_write_tokens)
- cacheWrite reads cache_write_tokens, not cacheable_tokens (a capacity
  metric that is 0 even on first-turn writes, not a write count)
2026-07-30 12:42:22 +08:00
liyanan 1b110a6291 fix index 2026-07-28 15:46:08 +08:00
liyanan 47141df66e fix: strip thinking tag artifacts leaked into reasoning_content
Qoder's backend sometimes routes a literal <thinking> opener into
reasoning_content while the matching closer lands in the content
stream, leaving tag fragments in the thinking block. Strip them during
streaming and add live repro scripts.
2026-07-28 10:21:28 +08:00
liyanan 85ec02ca8a fix: reuse pi session id as qoder session_id to enable prompt caching
A fresh random session_id on every request meant the Qoder server could
never match a previous cache entry, so cacheRead was ~0% in all agentic
sessions. Ablation testing showed a stable session_id alone raises the
turn-2 cache hit rate from 0% to ~99.6% of prompt tokens (affinity
headers alone contribute nothing). The previously observed "406 Session
blocked" no longer reproduces with a per-pi-session stable id.
2026-07-28 10:21:20 +08:00
het-e2mandGitHub 46bf89a5ac docs: list latest Qoder frontier models
Updated model names and versions in the README.
2026-07-27 14:19:37 +05:30
het-e2mandGitHub 939862023b feat: add latest Qoder frontier models 2026-07-27 14:18:18 +05:30
liyanan 273368fc0e fix: prevent provider_error 400 on dmodel/ultimate by using content placeholder
When assistant messages contain only tool_calls (no text/thinking), transform.ts
was setting content to null. Qoder's gateway drops these null-content assistant
messages, orphaning the following tool_result and causing upstream rejections:
- dmodel (OpenAI): 'tool must follow a message with tool_calls'
- ultimate (Anthropic): 'unexpected tool_use_id in tool_result blocks'

Analysis of 28 historical sessions showed 100% failure rate on dmodel and 75%
on ultimate for this pattern, while auto/GLM5.2 (GLM upstream) tolerated it.

Fix: inject a single-space placeholder when tool_calls are present but content
is empty, so the gateway preserves the assistant message and tool pairing stays
valid.

Also fixes pre-existing lint formatting in stream.ts and package.json.
Adds regression test for the full assistant+toolResult pairing scenario.
2026-07-26 15:26:13 +08:00
liyanan 6964615056 fix: inject system prompt as role:system message (server ignores top-level system field)
Verified via behavior test against Qoder API (ultimate model):
- system field with a directive: model ignores it (prompt_tokens=15, normal reply)
- same directive in messages[0] role:system: model obeys (prompt_tokens=97, marker reply)

The server's top-level `system` field in the request body is never fed to
the model, so pi's systemPrompt (language prefs, tool rules, agent instructions)
was silently dropped. Inject it as a leading role:system message instead, which
the server honors.
2026-07-26 07:16:40 +08:00
liyanan b8980b68b8 fix(stream): stop silently swallowing upstream errors and session-lock stalls
Three stability fixes for the streaming layer. Together they eliminate
the "agent silently stops mid-task" failure mode users hit during agentic
loops.

1. Surface upstream errors instead of swallowing them

The SSE parsing loop wrapped every line in try { ... } catch {}, which
silently dropped the throw raised when Qoder returned an error envelope
(e.g. 406 Session blocked, provider_error). The stream then completed
with empty content and stopReason "stop", so pi saw a clean stop instead
of an error and never retried or informed the user.

The catch now only skips genuinely malformed SSE lines (SyntaxError) and
re-throws everything else so the outer handler can set stopReason "error"
+ errorMessage. A QODER_DEBUG env var logs skipped lines for diagnosis.

2. Stop overwriting the real finish_reason with "stop"

At end-of-stream the code unconditionally did:
    output.stopReason = toolCalls.length ? "toolUse" : "stop"
clobbering any meaningful finish_reason ("length", "content_filter", ...)
captured earlier. Now only toolUse is forced when tool calls are present;
otherwise the upstream finish_reason is preserved (defaults to "stop").
The done event reason cast now includes "length".

3. Give each request a fresh server-side session id

session_id was stableHash("qoder-session", userID, qoderModel) —
constant across all requests for a given user+model. Qoder enforces a
per-session lock and replies 406 Session blocked when a second request
arrives before the previous one fully drains server-side, which happens
routinely in tight agentic tool loops. Appending crypto.randomUUID()
makes every request use a fresh session. We send full conversation
history on each request, so losing server-side session continuity is
safe.

4. Capture upstream usage, responseId and responseModel

The provider reported all-zero usage and no responseId/responseModel.
Now the finish chunk usage (prompt/completion/total tokens, cache
read/write) is mapped into output.usage, and id/model into
responseId/responseModel, so pi sees real token accounting and can
correlate responses.

Add stream.test.ts with regression coverage for the 406 path, the
finish_reason preservation, the toolUse stop reason, and usage/response
metadata capture.
2026-07-25 20:55:40 +08:00
Simon Shi 077e651fc7 fix: expose full Qoder model catalog 2026-07-22 20:06:05 +09:00
Simon Shi ef672a5461 fix: refresh Qoder models before startup 2026-07-22 19:54:46 +09:00
Simon Shi 55e87cbdef fix: stop adding auto as Qoder model fallback 2026-07-22 19:42:46 +09:00
Simon Shi 1c44a09141 fix: safely handle missing AuthStorage export and bump version to 0.2.6 2026-07-22 13:03:48 +08:00
Simon Shi 5ce99b0261 fix: publish 0.2.5 from npm registry 2026-07-20 22:29:18 +09:00
Simon Shi e1cfff3ecf fix: release 0.2.4 with Node 24 2026-07-20 22:27:15 +09:00
Simon Shi ab34573e82 chore: bump version to 0.2.3 2026-07-20 20:56:14 +08:00
Simon ShiandGitHub 1e2a7be504 Merge pull request #8 from simonsmh/agent/auto-login-from-env
feat: auto-login from Qoder API key
2026-07-20 20:55:31 +08:00
Simon Shi 43448f0cc0 feat: default to maximum context size 2026-07-20 20:55:09 +08:00
Simon Shi a98b9573f4 feat: auto-login from Qoder API key 2026-07-20 18:22:35 +08:00
Simon Shi 049b164279 fix: resolve biome lint errors in test files
Replace all explicit any types with proper type annotations and fix
formatting issues to pass CI lint checks.
2026-06-27 20:27:29 +08:00
Simon Shi c83fa0b8f3 test: add unit tests and remove dead code
- Add vitest with 98 tests across 6 test files covering:
  - cosy.ts: URL builders, mode detection, model name mapping
  - thinking-parser.ts: ThinkingTagParser with all tag variants and chunked streaming
  - transform.ts: getContentText, transformTools, transformMessagesForQoder
  - pat.ts: isPatRefresh, encodePatRefresh/decodePatRefresh roundtrip
  - qoder-encoding.ts: custom encoding correctness and edge cases
  - models.ts: static model definitions integrity checks

- Remove dead code:
  - QODER_CN_DIRECT_BASE_URL (unused export in cosy.ts)
  - THINKING_START_TAG / THINKING_END_TAG (unused constants in thinking-parser.ts)

- Add test/test:watch scripts to package.json
2026-06-27 20:03:05 +08:00
Simon Shi 2d6e1c660b chore: bump dependencies for security fixes 2026-06-26 14:50:39 +08:00
温习江湖andGitHub 2b2f427628 Support Qoder CN (#4)
* feat(qoder-cn): add region endpoints and model catalog

* feat(qoder-cn): add separate provider auth and streaming

* docs: document Qoder CN provider
2026-06-26 14:42:36 +08:00
Simon ShiandGitHub d09feb9aec Merge pull request #2 from simonsmh/dependabot/npm_and_yarn/npm_and_yarn-53cbaf2a5b
build(deps-dev): bump esbuild from 0.25.12 to 0.28.1 in the npm_and_yarn group across 1 directory
2026-06-22 11:54:52 +08:00
dependabot[bot]andGitHub 00be927ed5 build(deps-dev): bump esbuild
Bumps the npm_and_yarn group with 1 update in the / directory: [esbuild](https://github.com/evanw/esbuild).


Updates `esbuild` from 0.25.12 to 0.28.1
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG-2025.md)
- [Commits](https://github.com/evanw/esbuild/compare/v0.25.12...v0.28.1)

---
updated-dependencies:
- dependency-name: esbuild
  dependency-version: 0.28.1
  dependency-type: direct:development
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-06-16 05:40:33 +00:00
Simon Shi 26be3e0e17 refactor: optimize model cache updates by moving to session_start hook & bump to 0.2.1 2026-06-16 13:39:24 +08:00
Simon Shi 8fb093bac0 release: v0.2.0 2026-06-16 13:39:20 +08:00
Simon Shi bcaa66091e fix: route PAT login through pi LoginDialog callbacks
The custom ctx.ui.custom login menu stole focus from pi's built-in
LoginDialog, so onPrompt never received keystrokes and PAT login
silently failed with 'No API key found'. Drive login via the provided
onPrompt/onAuth/onProgress callbacks instead, and drop login-ui.ts and
the now-unused pi-tui dependency. Also clears remaining lint warnings
by removing any-casts in models/oauth/stream/transform.
2026-06-16 13:39:16 +08:00
Simon Shi 842bec6eb2 feat: proper PAT support via job-token exchange
Qoder PATs (pt-...) cannot authenticate directly; they must be exchanged
for a short-lived job token (jt-...), mirroring the official qodercli flow.

- pat.ts: exchangeJobToken + credentialsFromPat (exchange + identity)
- oauth: fix QODER_PERSONAL_ACCESS_TOKEN env path; re-exchange PAT on refresh
- login: add 'Use API Key (PAT)' option to /login menu and terminal fallback
- README: correct PAT docs (exchange required, two entry points)
2026-06-16 13:39:13 +08:00
Simon Shi 0a4a0ddd97 release: v0.1.2 2026-06-16 13:39:09 +08:00
Simon Shi da9677e68e fix: add repository metadata required for npm provenance 2026-06-16 13:39:06 +08:00
Simon Shi fdbc00fdcc release: v0.1.1 2026-06-16 13:39:03 +08:00
Simon Shi bf03109d76 ci: add build CI and Trusted Publishing release workflows 2026-06-16 13:38:59 +08:00
Simon Shi 032cf51904 refactor: drop redundant credentials cache and unused deps
- stream: passively rebuild stale/missing models cache on request
- oauth: read identity from pi's auth.json instead of self-managed cache
- deps: remove unused js-tiktoken; move esbuild to devDependencies
2026-06-16 13:38:55 +08:00
Simon Shi c9413961d2 fix: compute max contextWindow dynamically from context_config 2026-06-16 13:38:52 +08:00
Simon Shi dd8c313984 feat: init pi-provider-qoder plugin with oauth, signature and WAF bypass 2026-06-16 13:38:48 +08:00