dsh-grok-provider 1.0.2 → 1.0.3

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/CHANGELOG.md CHANGED
@@ -1,11 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3 - 2026-08-31
4
+
5
+ - Recover one pre-stream 401/403 by asking the official Grok CLI to refresh its shared session, reloading the validated credential, and retrying the request exactly once. Concurrent rejections from the same credential revision share one bounded refresh; a persistent rejection remains `AUTH`.
6
+ - Never replay a request after a successful response begins. Abort a response after two continuous minutes without any wire bytes; each received byte chunk refreshes this idle deadline. If the source disconnects, idles out, or reaches clean EOF after only bounded text/reasoning chunks, preserve that partial output, close its visible blocks, and append a bilingual interruption notice asking the user to send “continue.” Any observed tool call, unknown chunk, malformed protocol, user abort, or empty partial response keeps the established fail-closed behavior.
7
+ - Distinguish a clean premature SSE EOF from malformed events so only the former is eligible for partial-output preservation. Focused regressions cover one-shot recovery, persistent auth failure, concurrent single-flight refresh, post-start no-retry, idle timeout, transport interruption, clean EOF, status-bearing stream rejection, and partial tool-call rejection. The exact Node `24.19.0` suite passes with 274 tests, 272 pass, 0 fail, and 2 platform skips.
8
+ - Complete one redacted real-account success-path request with exact `grok-4.6` at Low Effort through the production adapter. It produced 2 block starts, 14 reasoning deltas, 2 block ends, 1 text delta, 1 usage chunk, and 1 finish. No response text, prompt output, URL, identity, credential, or raw event was retained; this does not simulate a future 401 or network stall.
9
+ - Code PR #37 merged as `9958f487abf8ebd062eecb4368689e4d049b1d35`; main CI run `33377849906` passed on macOS 14 and Windows 2022. Artifact digests and publication evidence remain pending until the release-evidence commit is merged and one tarball is frozen from that exact commit.
10
+
3
11
  ## 1.0.2 - 2026-08-30
4
12
 
5
13
  - Suppress contentless Harness reasoning blocks for upstream reasoning lifecycles that fully close without any visible summary or raw delta. The decoder now starts a visible block only when the first non-empty reasoning delta arrives; non-empty reasoning items remain separate blocks with their existing ordering.
6
14
  - Preserve the strict protocol boundary while changing the projection: ordinary empty items retain their existing ID/type, sequence, output-index, status, summary/content, size, optional encrypted-content, and closure checks; Search-backed same-ID reuse additionally retains exact own-data key/accessor validation. Invalid reuse, ordering violations, and incomplete responses with an open reused lifecycle continue to fail closed.
7
15
  - Preserve output-index order when a later visible block must wait for an earlier unresolved reasoning item. The shared delayed-chunk queue now fails closed above 65,536 chunks or 32 MiB of dynamic UTF-8 payload, preventing an unresolved item from amplifying memory across otherwise individually bounded blocks. Response text, tool calls, usage, finish reasons, visible non-empty replay, Search replay suppression, authentication, models, images, fixed endpoints, citation/URL handling, and Harness permissions remain unchanged. A hidden ordinary empty item has no replay-alignment slot, so validated encrypted content from that item is not persisted; existing empty `Think` rows stored in old conversations are not rewritten.
8
- - Package the bilingual README with durable `1.0.2` wording and an exact `dsh-grok-provider@1.0.2` installation command. The exact Node `24.19.0` local suite passes with 265 tests, 263 pass, 0 fail, and 2 platform skips; production audit reports zero vulnerabilities and the isolated-cache dry-run pack lists 74 files. Code PR #34, branch push/PR CI, merge commit `47d688cc47bc9643f3477ee9333cfdf7788045cd`, and main CI run `33318245251` passed on macOS 14 and Windows 2022. A fixed final release commit and CI, frozen artifact, isolated installation, publication, and supply-chain readback remain pending and are recorded only after they actually exist.
16
+ - Package the bilingual README with durable `1.0.2` wording and an exact `dsh-grok-provider@1.0.2` installation command. The exact Node `24.19.0` local suite passes with 265 tests, 263 pass, 0 fail, and 2 platform skips; production audit reports zero vulnerabilities and the isolated-cache dry-run pack lists 74 files. Final release commit `be200f9352afe93b27dd2856d89c01674f0cd637` passed dual-platform final CI run `33318426571`; annotated tag object `b7efd3aabb99c73e1747d2d87890cdf9b284c438` peels to that commit. Trusted Publisher run `33319150964` attempt 1 published the explicitly authorized unique 74-file artifact: 255,282 bytes packed, 789,962 bytes unpacked, SHA-1 `3feddb7048fe4c796037804518999b12ae491802`, SHA-256 `010a21770cb3e4e42b7195984df1f5bf8dc5027066198cf99b7d713ac045f605`, and SRI `sha512-TcvvPUXBJZEA728pVnUrXSZebGfIoB5ATG5041wA1OFzOE+hFTO98C5Fxl99WuFW2y7V89gkusYIKCpGlLNQIg==`. The frozen candidate, GitHub Release asset, and npm Registry tarball are byte-identical; npm reports `latest=1.0.2`, the locked Node `24.19.0` / npm `11.5.1` Host/client smoke and production audit passed, package metadata exposes 1 Registry signature and 2 attestations, `npm audit signatures` verified 11 signed packages and 2 attested packages, and SLSA provenance exactly binds `release.yml`, `refs/tags/v1.0.2`, the release commit, and publish run. Real-device Windows external-browser launch remains unverified.
9
17
 
10
18
  ## 1.0.1 - 2026-08-30
11
19
 
package/README.en.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  Use an already authenticated official Grok Build account from DeepSeek Harness, with dynamic model discovery, streaming reasoning, image input, optional Web/X Search, tool calls, and an account quota/model capability dashboard.
6
6
 
7
- > Unofficial community project; not affiliated with xAI or DeepSeek Harness. This README describes the `dsh-grok-provider@1.0.2` artifact; version `0.1.8` was published and then withdrawn and cannot be reused.
7
+ > Unofficial community project; not affiliated with xAI or DeepSeek Harness. This README describes the `dsh-grok-provider@1.0.3` artifact; version `0.1.8` was published and then withdrawn and cannot be reused.
8
8
 
9
- `1.0.2` fixes a presentation defect: an upstream Search stream may contain fully closed reasoning lifecycles with no visible text. The Provider continues to validate those lifecycles strictly but no longer projects them as empty Harness `Think` rows; reasoning with real summary/raw deltas remains visible as separate blocks.
9
+ `1.0.3` addresses two real-session interruption paths. A 401/403 received before streaming begins triggers one bounded refresh through the official Grok CLI and at most one retry. Once streaming starts, the request is never replayed. If a connection then ends after only safe text/reasoning output, the Provider preserves those chunks and asks the user to send “continue”; tool calls, unknown events, and malformed protocol still fail closed.
10
10
 
11
- This README is included in the `1.0.2` npm tarball, and the exact installation command below is pinned to `1.0.2`. Publication state, integrity digests, signatures, attestations, and provenance must come from actual npm Registry and GitHub Release readback rather than being predicted before artifact freeze.
11
+ This README is included in the `1.0.3` npm tarball, and the exact installation command below is pinned to `1.0.3`. The previous version with completed supply-chain readback is `1.0.2`.
12
12
 
13
13
  ## What it provides
14
14
 
@@ -19,7 +19,7 @@ This README is included in the `1.0.2` npm tarball, and the exact installation c
19
19
  | Models | Discovers every model visible to the account at runtime; no static model allowlist |
20
20
  | Conversations | Streaming Responses text, reasoning, encrypted reasoning replay, usage, and finish reasons |
21
21
  | Images | Only exact `grok-4.6` accepts bounded JPEG/PNG images from Harness attachments; `grok-4.5` and all other models remain text-only |
22
- | Search | Exact `grok-4.6` provides default-off Web/X Search; `1.0.1` resolves same-name function/server-tool conflicts and `1.0.2` hides contentless `Think` projections for strictly empty reasoning |
22
+ | Search | Exact `grok-4.6` provides default-off Web/X Search; `1.0.3` adds pre-stream authentication recovery and safe partial-output preservation without replaying a started stream |
23
23
  | Tools | Returns function calls to the Harness permission layer; the provider never executes tools, and local `web_search` / `x_search` remain when the corresponding Search setting is off |
24
24
  | Account dashboard | Login status, weekly/monthly quota, reset time, dynamic model capabilities and reasoning efforts |
25
25
  | Surfaces | Bilingual Web settings and a closed `/grok` TUI command set |
@@ -44,10 +44,10 @@ When the network is reachable and OIDC discovery succeeds, the official CLI open
44
44
 
45
45
  ### 2. Install the provider
46
46
 
47
- Install the exact version described here after confirming that it is available from the npm Registry:
47
+ Install the exact version:
48
48
 
49
49
  ```sh
50
- dsh plugin --profile web add dsh-grok-provider@1.0.2
50
+ dsh plugin --profile web add dsh-grok-provider@1.0.3
51
51
  dsh web
52
52
  ```
53
53
 
@@ -135,9 +135,9 @@ Uninstalling the provider does not remove the official Grok CLI or directly modi
135
135
  ## Sources and discovery
136
136
 
137
137
  - Exact npm version described by this README: [dsh-grok-provider@1.0.2](https://www.npmjs.com/package/dsh-grok-provider/v/1.0.2)
138
- - Previous GitHub release with completed readback: [v1.0.1](https://github.com/yoshino-xiao7/dsh-grok-provider/releases/tag/v1.0.1)
139
- - Release evidence: release commit `3c25a53571531e35ac888df16df4fe6c01849e85`, annotated tag object `ab79b1bb1e408a0112166cadc26761a327819c3f` peeling to that commit, final CI run [`33312946205`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33312946205), and Trusted Publisher run [`33313699790` attempt 1](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33313699790/attempts/1). The repository owner explicitly authorized the unique 73-file artifact, which is 240,904 bytes packed and 748,888 bytes unpacked; SHA-1 is `9e6449160947104e8dbb71b7201c53e81b073f83`, SHA-256 is `e3e15646d38de23c32c71ed759f9c10be9b2d790d4b10b4b8dfe59a44fbfef9f`, and SRI is `sha512-Bm1qjJQ9i7CWT0oWah7QKDVBP8dR2YQtvEEZGE/BOSwZCo8sZbrW2v2QSfUfLsOLHcQXFZZ0jlDCAztr1m/q+A==`. Frozen-candidate, GitHub Release, and npm Registry copies are byte-identical; a locked Registry install under Node `24.19.0` / npm `11.5.1` passed Host `name`/`apply` and client `id`/factory smoke checks with zero production vulnerabilities. `npm audit signatures` confirmed verified Registry signatures for 11 packages and verified attestations for 2 packages; this package's public metadata exposes 1 Registry signature and 2 attestations, while SLSA provenance exactly binds `release.yml`, `refs/tags/v1.0.1`, the release commit, and publish run.
140
- - npm page documentation correction: the `1.0.1` tarball retained an older installation example; the README embedded in the `1.0.2` artifact uses the exact `@1.0.2` command. Published `1.0.1` bytes are not replaced.
138
+ - Current GitHub release with completed readback: [v1.0.2](https://github.com/yoshino-xiao7/dsh-grok-provider/releases/tag/v1.0.2)
139
+ - Release evidence: release commit `be200f9352afe93b27dd2856d89c01674f0cd637`, annotated tag object `b7efd3aabb99c73e1747d2d87890cdf9b284c438` peeling to that commit, final CI run [`33318426571`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33318426571), and Trusted Publisher run [`33319150964` attempt 1](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33319150964/attempts/1). The repository owner explicitly authorized the unique 74-file artifact, which is 255,282 bytes packed and 789,962 bytes unpacked; SHA-1 is `3feddb7048fe4c796037804518999b12ae491802`, SHA-256 is `010a21770cb3e4e42b7195984df1f5bf8dc5027066198cf99b7d713ac045f605`, and SRI is `sha512-TcvvPUXBJZEA728pVnUrXSZebGfIoB5ATG5041wA1OFzOE+hFTO98C5Fxl99WuFW2y7V89gkusYIKCpGlLNQIg==`. The frozen candidate, GitHub Release asset, and npm Registry tarball are byte-identical, and npm confirms that `dsh-grok-provider@1.0.2` is installable and `latest=1.0.2`. A locked Registry install under Node `24.19.0` / npm `11.5.1` passed Host registration/`apply`/injection and client registration/factory/`apply`/injection smoke checks with zero production vulnerabilities. `npm audit signatures` confirmed verified Registry signatures for 11 packages and verified attestations for 2 packages; this package's public metadata exposes 1 Registry signature and 2 attestations, while SLSA provenance exactly binds `release.yml`, `refs/tags/v1.0.2`, the release commit, and publish run.
140
+ - npm page documentation correction: the `1.0.1` tarball retained an older installation example; the README in the published `1.0.2` tarball uses the exact `@1.0.2` command. Published `1.0.1` bytes are not replaced.
141
141
  - GitHub community discovery: the repository carries the DeepSeek Harness-recommended `dsh-plugin` and `dsh` topics
142
142
  - YukiRyou managed source: [deepseek-yukiryou-plugin-catalog](https://github.com/yoshino-xiao7/deepseek-yukiryou-plugin-catalog), still pinned to the real-device-accepted `dsh-grok-provider@0.1.0` and marking only `darwin-arm64`
143
143
 
@@ -150,7 +150,7 @@ Directory inclusion is not an endorsement by xAI or DeepSeek Harness. [Listing P
150
150
  - An ordinary strictly empty reasoning item retains the existing ID/type, sequence, output-index, status, empty summary/content, size, optional encrypted-content, and closure checks. A same-ID Search-backed reuse additionally retains exact own-data key and accessor rejection. This release does not expand the accepted protocol domain.
151
151
  - The Provider delays creating a Harness reasoning block until the first non-empty summary/raw delta, then emits the existing delta and block-end sequence. A lifecycle that remains empty produces no visible reasoning chunk.
152
152
  - Multiple non-empty reasoning items remain separate in output-index order. Text, tool calls, usage, finish reasons, visible non-empty reasoning replay, Search replay suppression, and fail-closed behavior are unchanged. A hidden ordinary empty item occupies no visible block/replay alignment slot, so its validated bounded encrypted content is not persisted.
153
- - The exact Node `24.19.0` local gate reports 265 tests, 263 pass, 0 fail, and 2 platform skips; production audit reports zero vulnerabilities and the isolated-cache dry-run pack lists 74 files. Branch head `52359e691dfd1bbdb849362c9d1a461e4e693b83` push/PR CI, code PR [#34](https://github.com/yoshino-xiao7/dsh-grok-provider/pull/34), merge commit `47d688cc47bc9643f3477ee9333cfdf7788045cd`, and main CI run [`33318245251`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33318245251) pass on macOS 14 and Windows 2022. This still does not establish a final release commit, frozen artifact, publication, or supply-chain readback.
153
+ - The exact Node `24.19.0` local gate reports 265 tests, 263 pass, 0 fail, and 2 platform skips; production audit reports zero vulnerabilities. Final release commit `be200f9352afe93b27dd2856d89c01674f0cd637` for the 74-file artifact and final CI run [`33318426571`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33318426571) pass on macOS 14 and Windows 2022. Unique-artifact authorization, isolated installation, Registry, signature, attestation, and provenance readback are complete.
154
154
  - The repair affects new responses after upgrading; empty `Think` rows already persisted in older conversations are not rewritten.
155
155
  - Search settings, models, authentication, images, fixed endpoints, citation/URL handling, and the Harness tool-permission boundary are unchanged. This is not real-device Windows browser-login acceptance.
156
156
 
@@ -171,7 +171,7 @@ Directory inclusion is not an endorsement by xAI or DeepSeek Harness. [Listing P
171
171
  - Two-layer redacted real-account verification passed against the final source: raw Web/X probes each completed one 64-event response, observed the requested Search kind, and reached `completed`; the production adapter completed 5 Responses calls, with direct Web/X both ending in `stop` and a Harness-shaped local `x_search` call/result continuation ending `tool-calls`, `tool-calls`, then `stop`, with one local call in each of the first two turns. That continuation did not place a Harness `x_search` function definition beside an xAI `{ type: "x_search" }` server descriptor in the same wire request; `1.0.1` later isolated that combination as an HTTP 400 conflict. No results, URLs, prompts, identity, or credentials were retained; this is not publication, OAuth, or real-device Windows evidence.
172
172
  - The manifest and lockfile are synchronized at `1.0.0`; the Node 24 suite reports 245 tests, 243 pass, 0 fail, and 2 platform skips. Production audit reports zero vulnerabilities, and the deterministic build/bundle comparison, 72-entry dry-run pack, secret scan, and diff check pass. Code PR #28, main CI run [`33308371009`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33308371009), the final release commit, dual-platform final CI, unique artifact, exact authorization, and Registry/signature/attestation/provenance readback are complete.
173
173
 
174
- | Item | `1.0.2` artifact boundary |
174
+ | Item | Published `1.0.2` compatibility boundary |
175
175
  | --- | --- |
176
176
  | DeepSeek Harness | Exact support for `0.1.1-rc.2` |
177
177
  | Node.js | `>=24.19.0` |
@@ -292,6 +292,7 @@ Read the [contributing guide](CONTRIBUTING.md) before filing an issue or PR. Cha
292
292
  - [x] Publish `0.1.11`: repair High Effort + Web Search reasoning-lifecycle compatibility; the unique artifact, final dual-platform CI, exact authorization, Registry, signatures, attestations, and provenance readback are complete
293
293
  - [x] Publish `1.0.0`: repair multiple strictly empty reasoning-ID reuses and completed Web Search `open_page` actions; the unique artifact, final dual-platform CI, exact authorization, Registry, signatures, attestations, and provenance readback are complete
294
294
  - [x] Publish `1.0.1`: repair HTTP 400 conflicts between server Search and same-name Harness function definitions while preserving true transport-error classification; the unique artifact, final dual-platform CI, exact authorization, Registry, signatures, attestations, and provenance readback are complete
295
+ - [x] Publish `1.0.2`: hide contentless `Think` projections for strictly empty reasoning while preserving protocol validation and output-index order; the unique artifact, final dual-platform CI, exact authorization, Registry, signatures, attestations, and provenance readback are complete
295
296
  - [ ] A subsequent slice: opt-in image generation (inline results only, committed through Harness attachments)
296
297
  - [ ] Complete independent Windows x64 acceptance and publish a later stable fix if needed
297
298
 
package/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  让 DeepSeek Harness 使用你已登录的官方 Grok Build 账号:动态模型发现、流式推理、图片输入、可选 Web/X Search、工具调用,以及账号额度与模型能力面板。
6
6
 
7
- > 非官方社区项目,与 xAI 或 DeepSeek Harness 官方无隶属关系。本说明对应 `dsh-grok-provider@1.0.2` 制品;`0.1.8` 曾发布后撤回且版本号不可复用。
7
+ > 非官方社区项目,与 xAI 或 DeepSeek Harness 官方无隶属关系。本说明对应 `dsh-grok-provider@1.0.3` 制品;`0.1.8` 曾发布后撤回且版本号不可复用。
8
8
 
9
- `1.0.2` 修复一个显示层问题:上游 Search 流可能产生完整闭合、但没有任何可见文本的 reasoning lifecycle。Provider 仍会严格验证这些 lifecycle,但不再把它们投影成空的 Harness `Think` 行;真正包含 summary/raw delta 的 reasoning 仍按独立块显示。
9
+ `1.0.3` 修复两类真实运行中断:流开始前遇到 401/403 时,通过官方 Grok CLI 进行一次有界会话刷新并仅重试一次;流已开始后绝不重放。若连接中断前只收到安全的文本/reasoning,Provider 会保留已收到内容并提示用户发送“继续”;一旦出现工具调用、未知事件或协议异常,仍严格失败关闭。
10
10
 
11
- 本 README 随 `1.0.2` 一起进入 npm tarball,下面的精确安装命令也固定为 `1.0.2`。发布状态、完整性摘要、签名、attestations 与 provenance 应以该版本的 npm Registry 和 GitHub Release 实际回读为准,不在制品冻结前预写。
11
+ 本 README 随 `1.0.3` 一起进入 npm tarball,下面的精确安装命令也固定为 `1.0.3`。上一份已完成供应链回读的版本为 `1.0.2`。
12
12
 
13
13
  ## 它解决什么问题
14
14
 
@@ -19,7 +19,7 @@
19
19
  | 模型 | 运行时读取账号可见的全部 Grok Build 模型,不维护静态模型白名单 |
20
20
  | 对话 | Responses 流式文本、reasoning、加密 reasoning replay、usage 与 finish reason |
21
21
  | 图片 | 仅精确 `grok-4.6` 接收 Harness attachment 中有界的 JPEG/PNG 图片;`grok-4.5` 与其他模型保持 text-only |
22
- | 搜索 | 精确 `grok-4.6` 提供默认关闭的 Web/X Search;`1.0.1` 解决同名 function/server-tool 冲突,`1.0.2` 隐藏严格空 reasoning 的无内容 `Think` 投影 |
22
+ | 搜索 | 精确 `grok-4.6` 提供默认关闭的 Web/X Search;`1.0.3` 增加流前认证恢复与安全的部分输出保留,不自动重放已开始的流 |
23
23
  | 工具 | 将 function call 交回 Harness 权限层;Provider 本身不执行工具,关闭对应 Search 开关时保留本地 `web_search` / `x_search` |
24
24
  | 账户面板 | 登录状态、每周/月额度、重置时间、动态模型能力与 reasoning 档位 |
25
25
  | 界面 | Web 设置页中英文切换;TUI 提供闭合的 `/grok` 命令 |
@@ -44,10 +44,10 @@ grok models
44
44
 
45
45
  ### 2. 安装 Provider
46
46
 
47
- 安装本说明对应的精确版本;执行前可在 npm Registry 核对该版本是否已可用:
47
+ 安装精确版本:
48
48
 
49
49
  ```sh
50
- dsh plugin --profile web add dsh-grok-provider@1.0.2
50
+ dsh plugin --profile web add dsh-grok-provider@1.0.3
51
51
  dsh web
52
52
  ```
53
53
 
@@ -135,9 +135,9 @@ dsh web
135
135
  ## 项目来源与发现
136
136
 
137
137
  - 本说明对应的 npm 精确版本:[dsh-grok-provider@1.0.2](https://www.npmjs.com/package/dsh-grok-provider/v/1.0.2)
138
- - 上一版已完成回读的 GitHub Release:[v1.0.1](https://github.com/yoshino-xiao7/dsh-grok-provider/releases/tag/v1.0.1)
139
- - 发布证据:release commit `3c25a53571531e35ac888df16df4fe6c01849e85`,annotated tag object `ab79b1bb1e408a0112166cadc26761a327819c3f` peel 至该提交,final CI run [`33312946205`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33312946205),Trusted Publisher run [`33313699790` attempt 1](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33313699790/attempts/1)。仓库所有者明确授权的唯一 tarball 含 73 个文件、240,904 bytes,unpacked size 748,888 bytes;SHA-1 为 `9e6449160947104e8dbb71b7201c53e81b073f83`,SHA-256 为 `e3e15646d38de23c32c71ed759f9c10be9b2d790d4b10b4b8dfe59a44fbfef9f`,SRI 为 `sha512-Bm1qjJQ9i7CWT0oWah7QKDVBP8dR2YQtvEEZGE/BOSwZCo8sZbrW2v2QSfUfLsOLHcQXFZZ0jlDCAztr1m/q+A==`。冻结候选、GitHub Release 与 npm Registry 制品逐字节一致;Node `24.19.0` / npm `11.5.1` 的 Registry 锁定隔离安装通过 Host `name`/`apply` 与 client `id`/factory smoke,生产依赖审计为 0 漏洞。`npm audit signatures` 确认安装图中 11 个包具有已验证 Registry 签名、2 个包具有已验证 attestations;本包公开 metadata 包含 1 个 Registry signature、2 个 attestations,SLSA provenance 精确绑定 `release.yml`、`refs/tags/v1.0.1`、release commit 与 publish run。
140
- - npm 页面文档修正:`1.0.1` tarball 内曾保留旧安装示例;`1.0.2` 制品内的本 README 已改用精确 `@1.0.2` 命令。已发布的 `1.0.1` 字节不会被覆盖。
138
+ - 当前已完成回读的 GitHub Release:[v1.0.2](https://github.com/yoshino-xiao7/dsh-grok-provider/releases/tag/v1.0.2)
139
+ - 发布证据:release commit `be200f9352afe93b27dd2856d89c01674f0cd637`,annotated tag object `b7efd3aabb99c73e1747d2d87890cdf9b284c438` peel 至该提交,final CI run [`33318426571`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33318426571),Trusted Publisher run [`33319150964` attempt 1](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33319150964/attempts/1)。仓库所有者明确授权的唯一 tarball 含 74 个文件、255,282 bytes,unpacked size 789,962 bytes;SHA-1 为 `3feddb7048fe4c796037804518999b12ae491802`,SHA-256 为 `010a21770cb3e4e42b7195984df1f5bf8dc5027066198cf99b7d713ac045f605`,SRI 为 `sha512-TcvvPUXBJZEA728pVnUrXSZebGfIoB5ATG5041wA1OFzOE+hFTO98C5Fxl99WuFW2y7V89gkusYIKCpGlLNQIg==`。冻结候选、GitHub Release asset 与 npm Registry tarball 逐字节一致,npm 确认 `dsh-grok-provider@1.0.2` 可安装且 `latest=1.0.2`;Node `24.19.0` / npm `11.5.1` 的 Registry 锁定隔离安装通过 Host 注册/`apply`/注入与 client 注册/factory/`apply`/注入 smoke,生产依赖审计为 0 漏洞。`npm audit signatures` 确认安装图中 11 个包具有已验证 Registry 签名、2 个包具有已验证 attestations;本包公开 metadata 包含 1 个 Registry signature、2 个 attestations,SLSA provenance 精确绑定 `release.yml`、`refs/tags/v1.0.2`、release commit 与 publish run。
140
+ - npm 页面文档修正:`1.0.1` tarball 内曾保留旧安装示例;已发布的 `1.0.2` tarball 内,本 README 使用精确 `@1.0.2` 命令。已发布的 `1.0.1` 字节不会被覆盖。
141
141
  - GitHub 社区发现:仓库已添加 DeepSeek Harness 官方推荐的 `dsh-plugin` 与 `dsh` Topics
142
142
  - YukiRyou 受管来源:[deepseek-yukiryou-plugin-catalog](https://github.com/yoshino-xiao7/deepseek-yukiryou-plugin-catalog),当前仍锁定已完成真机验收的 `dsh-grok-provider@0.1.0`,且只标记 `darwin-arm64`
143
143
 
@@ -150,7 +150,7 @@ dsh web
150
150
  - 普通严格空 reasoning item 继续执行既有 ID/type、sequence、output index、状态、summary/content 空性、大小、可选 encrypted content 与闭合校验;Search-backed 同 ID 复用项继续额外执行精确 own-data 键集与 accessor 拒绝。本版没有扩大协议接受域。
151
151
  - Provider 延迟创建 Harness reasoning block,只有收到首个非空 summary/raw delta 才发送 `block-start`,随后按原顺序发送 delta 和 `block-end`。完整生命周期最终为空时产生零个可见 reasoning chunk。
152
152
  - 多个非空 reasoning item 继续按 output index 保持独立块;正文、工具调用、usage、finish reason、可见非空 reasoning replay、Search 后 replay 抑制和失败关闭行为不变。被隐藏的普通空 item 不占可见 block/replay 对齐槽,其有界 encrypted content 通过校验后不持久化。
153
- - 精确 Node `24.19.0` 本地门禁为 265 tests、263 pass、0 fail、2 platform skips;生产依赖审计 0 漏洞,隔离 cache 的 dry-run pack 为 74 文件。代码分支 head `52359e691dfd1bbdb849362c9d1a461e4e693b83` 的 push/PR CI、代码 PR [#34](https://github.com/yoshino-xiao7/dsh-grok-provider/pull/34)、merge commit `47d688cc47bc9643f3477ee9333cfdf7788045cd` 及 main CI run [`33318245251`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33318245251) 已在 macOS 14 / Windows 2022 全绿;这仍不代表最终 release commit、冻结制品、发布或供应链回读已经完成。
153
+ - 精确 Node `24.19.0` 本地门禁为 265 tests、263 pass、0 fail、2 platform skips;生产依赖审计 0 漏洞,74 文件制品的 final release commit `be200f9352afe93b27dd2856d89c01674f0cd637` 与 final CI run [`33318426571`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33318426571) 已在 macOS 14 / Windows 2022 全绿。唯一授权制品、隔离安装、Registry、签名、attestations 与 provenance 回读均已完成。
154
154
  - 修复只影响升级后的新回复;旧会话中已经持久化的空 `Think` 行不会被回写删除。
155
155
  - 本版不改变 Search 开关、模型、认证、图片、固定 endpoint、citation/URL 或 Harness 工具权限边界,也不构成 Windows 真机浏览器登录验收。
156
156
 
@@ -171,7 +171,7 @@ dsh web
171
171
  - 最终源码完成两层脱敏真实账号复验:原始 Web/X 协议探针各 1 次请求、各 64 events,分别观察到对应 Search 且终态 `completed`;生产 adapter 共完成 5 次 Responses,direct Web/X 均为 `stop`,Harness 形状的本地 `x_search` call/result 续跑三轮依次为 `tool-calls`、`tool-calls`、`stop`,前两轮各 1 次本地调用。该续跑没有在同一 wire request 中同时放入 Harness `x_search` function definition 与 xAI `{ type: "x_search" }` server descriptor;`1.0.1` 后续才隔离出这一 HTTP 400 冲突。未保存结果、URL、prompt、身份或凭据;这些不是发布、OAuth 或 Windows 真机证据。
172
172
  - manifest/lock 已同步为 `1.0.0`;Node 24 全量测试为 245 项、243 pass、0 fail、2 项平台跳过,生产依赖审计为 0 漏洞,确定性 build/bundle、72 项 dry-run pack、秘密模式扫描与 diff 检查均通过。代码 PR #28、main CI run [`33308371009`](https://github.com/yoshino-xiao7/dsh-grok-provider/actions/runs/33308371009)、最终 release commit、双平台 final CI、唯一制品、精确授权及 Registry/signature/attestation/provenance 回读均已完成。
173
173
 
174
- | 项目 | `1.0.2` 制品边界 |
174
+ | 项目 | `1.0.2` 已发布兼容边界 |
175
175
  | --- | --- |
176
176
  | DeepSeek Harness | 精确支持 `0.1.1-rc.2` |
177
177
  | Node.js | `>=24.19.0` |
@@ -292,6 +292,7 @@ npm run pack:check
292
292
  - [x] 发布 `0.1.11`:修复 High Effort + Web Search reasoning 生命周期兼容;唯一制品、双平台 final CI、精确授权、Registry、签名、attestations 与 provenance 回读均已完成
293
293
  - [x] 发布 `1.0.0`:修复多次严格空 reasoning ID 复用和完成态 Web Search `open_page` action;唯一制品、双平台 final CI、精确授权、Registry、签名、attestations 与 provenance 回读均已完成
294
294
  - [x] 发布 `1.0.1`:修复 server Search 与 Harness 同名 function definition 的 HTTP 400 冲突,并保留真实 transport error 分类;唯一制品、双平台 final CI、精确授权、Registry、签名、attestations 与 provenance 回读均已完成
295
+ - [x] 发布 `1.0.2`:隐藏严格空 reasoning 的无内容 `Think` 投影,同时保持协议校验与 output-index 顺序;唯一制品、双平台 final CI、精确授权、Registry、签名、attestations 与 provenance 回读均已完成
295
296
  - [ ] 再后续独立切片:默认关闭的图片生成(只收内联结果,提交 Harness attachment)
296
297
  - [ ] 完成 Windows x64 独立真机验收并按需发布后续稳定修复版
297
298
 
package/SECURITY.md CHANGED
@@ -4,12 +4,16 @@
4
4
 
5
5
  ## 支持范围
6
6
 
7
- 本安全策略对应 `dsh-grok-provider@1.0.2` 制品。它只改变已通过严格校验的 reasoning lifecycle 向 Harness 可见 block 的投影:完整闭合且始终没有非空 summary/raw delta 的 item 不产生可见 block;首个非空 delta 到来时才开始 block。协议接受域、固定 origin、凭据、Search、模型、图片、工具和 URL 边界均不放宽。`0.1.8` 曾发布后撤回且版本号不可复用;网络可达 Windows 真机外部浏览器弹出仍未验收。
7
+ 本安全策略对应 `dsh-grok-provider@1.0.3` 制品。它只在 200/SSE 开始前为 401/403 增加一次官方 CLI 会话刷新与同请求重试;同一凭据版本的并发拒绝共享一次刷新。流开始后绝不自动重放。只有已投影且有界的 text/reasoning 可在无工具调用、未知 chunk、协议异常或用户取消时被保留并附加中断提示;其他情况继续失败关闭。协议接受域、固定 origin、refresh-token 隔离、Search、模型、图片、工具和 URL 边界均不放宽。`0.1.8` 曾发布后撤回且版本号不可复用;网络可达 Windows 真机外部浏览器弹出仍未验收。
8
+
9
+ `1.0.3` 不把 HTTP 401/403 解释为 API Key 模式,也不自行刷新 OAuth grant:固定且有界的官方 `grok models` 子进程拥有刷新行为,插件随后重新读取并严格校验共享凭据。第二次拒绝仍为 `AUTH`。SSE source 的无状态 transport failure 和干净过早 EOF 与畸形事件分开;只有前两者能进入安全部分输出保留,status-bearing transport error、工具调用和所有 `INVALID_RESPONSE` 均不得被吞掉。部分内容不生成 replay metadata,提示不包含上游错误正文。
8
10
 
9
11
  `1.0.0` 把 reasoning ID 复用收窄为 Search-backed 且严格空的完整生命周期:可见 summary/content 及 summary/raw lifecycle 必须为空,允许有界 opaque `encrypted_content`;每次复用都必须到达自己的 `response.output_item.done`,仅当 `response.incomplete` 到来时仍有复用段未闭合才失败关闭,所有复用段闭合后的 `max_output_tokens` 终态仍有效。非空、跨类型、未知 terminal 字段或 accessor 字段继续拒绝。完成态 Web Search `open_page` 只允许精确且有界的 `type + url`,streamed/final action 的类型与 URL 必须一致,校验后 URL 被丢弃且不会被访问、预览、下载或回放。脱敏真实账号复验未保存结果、URL、prompt、身份或凭据;供应链回读也不构成 OAuth、完整桌面会话或 Windows 真机浏览器验收。
10
12
 
11
13
  `1.0.1` 已完成同名 function/server-tool 冲突、receipt 和 transport 错误归因修复及其独立供应链回读。`1.0.2` 不改变这些 request 或错误规则:普通空 reasoning 在决定“不可见”前继续执行既有 ID/type、sequence、output-index、状态、summary/content 空性、大小、可选 encrypted-content 与 terminal 闭合校验;Search-backed 同 ID 复用继续额外执行精确 own-data 键集与 accessor 拒绝。非空复用、乱序和未闭合复用项继续归类为 `INVALID_RESPONSE`。隐藏的普通空项不占 replay 对齐槽,其有界 encrypted content 校验后不持久化;server Search 仍不投影为本地工具。
12
14
 
15
+ `1.0.2` 的发布回读已关闭:最终 release commit `be200f9352afe93b27dd2856d89c01674f0cd637`,annotated tag object `b7efd3aabb99c73e1747d2d87890cdf9b284c438`,macOS 14 / Windows 2022 final CI run `33318426571`,Trusted Publisher run `33319150964` attempt 1。仓库所有者明确授权的唯一 74 文件制品为 255,282 bytes packed / 789,962 bytes unpacked,SHA-1 `3feddb7048fe4c796037804518999b12ae491802`、SHA-256 `010a21770cb3e4e42b7195984df1f5bf8dc5027066198cf99b7d713ac045f605`、SRI `sha512-TcvvPUXBJZEA728pVnUrXSZebGfIoB5ATG5041wA1OFzOE+hFTO98C5Fxl99WuFW2y7V89gkusYIKCpGlLNQIg==`;冻结候选、GitHub Release asset 与 npm Registry tarball 逐字节一致,npm `latest=1.0.2`。锁定隔离安装、本包 1 个 Registry signature / 2 个 package attestations、安装图 11 个 signed / 2 个 attested packages,以及精确绑定 `release.yml` / `refs/tags/v1.0.2` / release commit / publish run 的 SLSA provenance 均已验证。候选源码的真实账号验收只保留 Web `5/1/0/1/1` 与 X `3/1/0/1/1` 的 Search/non-empty-reasoning/empty-reasoning/non-empty-text/finish 计数;不保存内容、URL、身份、凭据或原始响应。上述证据均不构成 OAuth、完整桌面会话或网络可达 Windows 真机外部浏览器弹出验收。
16
+
13
17
  `0.1.11` 沿用已发布版本的图片边界:只为精确 `grok-4.6` 提供有界图片输入;`grok-4.5` 与所有其他模型保持 text-only。普通 user/system 历史中的私有 reasoning 会被省略并保留相邻可见 text/image;只有有效的同 Provider assistant 历史可进入加密 reasoning replay,一层 tool-result 仍只接受公开 text/image。图片只能来自 Harness attachment service 的已验证 JPEG/PNG 投影,以 `detail:"high"` 发送,并受单图字节、像素、边长、数量、总字节与最终 JSON 上限约束;URL、路径、file ID 和调用方预制 data URL 都会被拒绝。
14
18
 
15
19
  `0.1.7` 的闭合运行时诊断、CLI 安装恢复、OIDC timeout 脱敏结算和 `IconThinkOutline16` 兼容层在本版保持不变。官方 CLI 仍负责生成登录 URL 与打开外部浏览器;插件不修复系统 DNS、代理、防火墙、VPN 或 CLI 行为。
@@ -42,8 +46,8 @@
42
46
 
43
47
  ---
44
48
 
45
- Release security note: the `1.0.2` artifact changes visible reasoning projection and its aligned replay envelope. A reasoning lifecycle that remains strictly empty produces no Harness block, while the first non-empty summary/raw delta begins the same visible block lifecycle used previously. Ordinary empty items retain their existing validation, and Search-backed same-ID reuse retains exact own-data/accessor checks. A hidden ordinary empty item's validated encrypted content is not persisted because no visible replay-alignment slot exists. No authentication, model, image, fixed-origin, URL, permission, or protocol-acceptance boundary is expanded. Publication and supply-chain evidence must come from actual version-specific readback rather than this pre-frozen policy text.
49
+ Release security note: the published `1.0.2` artifact changes visible reasoning projection and its aligned replay envelope. A reasoning lifecycle that remains strictly empty produces no Harness block, while the first non-empty summary/raw delta begins the same visible block lifecycle used previously. Ordinary empty items retain their existing validation, and Search-backed same-ID reuse retains exact own-data/accessor checks. A hidden ordinary empty item's validated encrypted content is not persisted because no visible replay-alignment slot exists. No authentication, model, image, fixed-origin, URL, permission, or protocol-acceptance boundary is expanded. Version-specific publication and supply-chain facts above come from completed Registry, GitHub Release, signature, attestation, and provenance readback.
46
50
 
47
51
  The `1.0.2` artifact retains the `1.0.1` function/server-tool collision and transport-error rules. An ordinary strictly empty lifecycle keeps the existing ID/type, sequence, output-index, status, empty summary/content, size, optional encrypted-content, and closure checks; a Search-backed same-ID reuse additionally keeps exact own-data key/accessor validation. Invalid reused content, ordering violations, and an open reused lifecycle at an incomplete terminal still fail closed; an ordinary non-reused partial item retains the existing max-token behavior. Visible non-empty replay and Search replay suppression remain unchanged, while a hidden ordinary empty item has no replay slot. Existing stored conversations are not rewritten, and this change does not establish real-device Windows browser login.
48
52
 
49
- English summary: GitHub Private vulnerability reporting is enabled and preferred. This policy describes the `1.0.2` artifact, which suppresses the visible block for a reasoning lifecycle that remains strictly empty. The first non-empty summary/raw delta starts the existing block lifecycle in output-index order. Ordinary empty items retain their existing validation; Search-backed same-ID reuse retains exact key/accessor rejection; invalid, out-of-order, or incomplete responses with an open reused lifecycle still fail closed. Hidden ordinary empty items have no replay slot, while visible non-empty replay and Search suppression remain unchanged. Ordinary non-reused partial items retain the existing max-token behavior. The verified `1.0.1` release remains historical supply-chain evidence, while `1.0.2` publication facts are recorded only after they exist. Version `0.1.8` was published and withdrawn and cannot be reused. Fixed-origin, credential, settings, Search, model, image, URL, permission, and platform boundaries remain unchanged. Network-reachable external-browser launch is still unverified on a physical Windows device. Search results and citations remain untrusted remote data. Never send credentials, identity data, prompts, tool arguments, cookies, image bytes, Search contents, or unreviewed diagnostics.
53
+ English summary: GitHub Private vulnerability reporting is enabled and preferred. This policy describes the published `1.0.2` artifact, which suppresses the visible block for a reasoning lifecycle that remains strictly empty. The first non-empty summary/raw delta starts the existing block lifecycle in output-index order. Ordinary empty items retain their existing validation; Search-backed same-ID reuse retains exact key/accessor rejection; invalid, out-of-order, or incomplete responses with an open reused lifecycle still fail closed. Hidden ordinary empty items have no replay slot, while visible non-empty replay and Search suppression remain unchanged. Ordinary non-reused partial items retain the existing max-token behavior. The final release commit, tag object, CI and Trusted Publisher runs, byte-identical frozen/Release/Registry tarballs, Registry metadata, signatures, attestations, isolated installation, and SLSA provenance have all been read back for `1.0.2`; these supply-chain facts do not prove OAuth, complete live desktop sessions, or real-device Windows browser launch. Version `0.1.8` was published and withdrawn and cannot be reused. Fixed-origin, credential, settings, Search, model, image, URL, permission, and platform boundaries remain unchanged. Network-reachable external-browser launch is still unverified on a physical Windows device. Search results and citations remain untrusted remote data. Never send credentials, identity data, prompts, tool arguments, cookies, image bytes, Search contents, or unreviewed diagnostics.
@@ -34,104 +34,132 @@ export function createCredentialSource({ contract, load, now, refresh }) {
34
34
  throw new TypeError("Invalid credential source dependencies")
35
35
  }
36
36
  let activeRefresh
37
+ let refreshRevision = 0
37
38
 
38
39
  const refreshOnce = async () => {
39
40
  if (activeRefresh === undefined) {
40
- activeRefresh = Promise.resolve().then(refresh).finally(() => {
41
- activeRefresh = undefined
42
- })
41
+ activeRefresh = Promise.resolve()
42
+ .then(refresh)
43
+ .then((result) => {
44
+ refreshRevision += 1
45
+ return result
46
+ })
47
+ .finally(() => {
48
+ activeRefresh = undefined
49
+ })
43
50
  }
44
51
  return activeRefresh
45
52
  }
46
53
 
47
- return Object.freeze({
48
- async withAccessToken(operation) {
49
- if (typeof operation !== "function") {
50
- throw new TypeError("Access-token operation must be a function")
51
- }
54
+ const withAccessToken = async (operation, recoveryAllowed) => {
55
+ if (typeof operation !== "function") {
56
+ throw new TypeError("Access-token operation must be a function")
57
+ }
52
58
 
53
- let raw
54
- let rawText
55
- let parsed
56
- let accessToken
57
- let metadata
58
- let refreshAttempted = false
59
-
60
- try {
61
- while (accessToken === undefined) {
62
- try {
63
- raw = await load()
64
- if (utf8ByteLength(raw) > 64 * 1024) {
65
- throw new CredentialFileTooLargeError()
66
- }
67
- rawText = decodeUtf8(raw)
68
- parsed = JSON.parse(rawText)
59
+ let raw
60
+ let rawText
61
+ let parsed
62
+ let accessToken
63
+ let metadata
64
+ let refreshAttempted = false
65
+ let recoveryAttempted = false
66
+
67
+ try {
68
+ while (accessToken === undefined) {
69
+ try {
70
+ raw = await load()
71
+ if (utf8ByteLength(raw) > 64 * 1024) {
72
+ throw new CredentialFileTooLargeError()
73
+ }
74
+ rawText = decodeUtf8(raw)
75
+ parsed = JSON.parse(rawText)
69
76
 
70
- if (!isPlainObject(parsed)) throw new UnsupportedCredentialError()
77
+ if (!isPlainObject(parsed)) throw new UnsupportedCredentialError()
71
78
 
72
- const entries = Object.entries(parsed)
73
- if (entries.length !== 1 || entries[0][0] !== contract.scope) {
74
- throw new UnsupportedCredentialError()
75
- }
79
+ const entries = Object.entries(parsed)
80
+ if (entries.length !== 1 || entries[0][0] !== contract.scope) {
81
+ throw new UnsupportedCredentialError()
82
+ }
76
83
 
77
- const record = entries[0][1]
78
- if (
79
- !isPlainObject(record) ||
80
- record.auth_mode !== contract.authMode ||
81
- record.oidc_issuer !== contract.issuer ||
82
- record.oidc_client_id !== contract.clientId ||
83
- typeof record.key !== "string" ||
84
- record.key.length === 0 ||
85
- !isDateTime(record.expires_at)
86
- ) {
84
+ const record = entries[0][1]
85
+ if (
86
+ !isPlainObject(record) ||
87
+ record.auth_mode !== contract.authMode ||
88
+ record.oidc_issuer !== contract.issuer ||
89
+ record.oidc_client_id !== contract.clientId ||
90
+ typeof record.key !== "string" ||
91
+ record.key.length === 0 ||
92
+ !isDateTime(record.expires_at)
93
+ ) {
94
+ throw new UnsupportedCredentialError()
95
+ }
96
+ const currentTime = now()
97
+ if (!(currentTime instanceof Date) || !Number.isFinite(currentTime.getTime())) {
98
+ throw new TypeError("Invalid credential source clock")
99
+ }
100
+ if (!isFutureDateTime(record.expires_at, currentTime)) throw new CredentialRefreshRequiredError()
101
+
102
+ accessToken = record.key
103
+ metadata = Object.freeze({
104
+ ...(isHeaderValue(record.user_id) ? { userId: record.user_id } : {}),
105
+ })
106
+ } catch (error) {
107
+ if (
108
+ error instanceof CredentialRefreshRequiredError &&
109
+ refresh !== undefined &&
110
+ !refreshAttempted
111
+ ) {
112
+ refreshAttempted = true
113
+ try {
114
+ await refreshOnce()
115
+ } catch {
87
116
  throw new UnsupportedCredentialError()
88
117
  }
89
- const currentTime = now()
90
- if (!(currentTime instanceof Date) || !Number.isFinite(currentTime.getTime())) {
91
- throw new TypeError("Invalid credential source clock")
92
- }
93
- if (!isFutureDateTime(record.expires_at, currentTime)) throw new CredentialRefreshRequiredError()
94
-
95
- accessToken = record.key
96
- metadata = Object.freeze({
97
- ...(isHeaderValue(record.user_id) ? { userId: record.user_id } : {}),
98
- })
99
- } catch (error) {
100
- if (
101
- error instanceof CredentialRefreshRequiredError &&
102
- refresh !== undefined &&
103
- !refreshAttempted
104
- ) {
105
- refreshAttempted = true
106
- try {
107
- await refreshOnce()
108
- } catch {
109
- throw new UnsupportedCredentialError()
110
- }
111
- raw = undefined
112
- rawText = undefined
113
- parsed = undefined
114
- continue
118
+ raw = undefined
119
+ rawText = undefined
120
+ parsed = undefined
121
+ continue
122
+ }
123
+ if (
124
+ error instanceof UnsupportedCredentialError ||
125
+ error instanceof CredentialFileTooLargeError ||
126
+ error instanceof TypeError
127
+ ) {
128
+ throw error
129
+ }
130
+ throw new UnsupportedCredentialError()
131
+ }
132
+ }
133
+
134
+ const loadedRevision = refreshRevision
135
+ const recover = recoveryAllowed
136
+ ? async (recoveryOperation) => {
137
+ if (typeof recoveryOperation !== "function" || recoveryAttempted) {
138
+ throw new TypeError("Invalid access-token recovery operation")
115
139
  }
116
- if (
117
- error instanceof UnsupportedCredentialError ||
118
- error instanceof CredentialFileTooLargeError ||
119
- error instanceof TypeError
120
- ) {
121
- throw error
140
+ recoveryAttempted = true
141
+ if (refresh === undefined) throw new UnsupportedCredentialError()
142
+ try {
143
+ if (loadedRevision === refreshRevision) await refreshOnce()
144
+ } catch {
145
+ throw new UnsupportedCredentialError()
122
146
  }
123
- throw new UnsupportedCredentialError()
147
+ return withAccessToken(recoveryOperation, false)
124
148
  }
125
- }
149
+ : undefined
150
+ return await operation(accessToken, metadata, recover)
151
+ } finally {
152
+ metadata = undefined
153
+ accessToken = undefined
154
+ parsed = undefined
155
+ rawText = undefined
156
+ raw = undefined
157
+ }
158
+ }
126
159
 
127
- return await operation(accessToken, metadata)
128
- } finally {
129
- metadata = undefined
130
- accessToken = undefined
131
- parsed = undefined
132
- rawText = undefined
133
- raw = undefined
134
- }
160
+ return Object.freeze({
161
+ withAccessToken(operation) {
162
+ return withAccessToken(operation, true)
135
163
  },
136
164
  })
137
165
  }
@@ -1,4 +1,5 @@
1
1
  import { parseModelCatalogResponse } from "./model-catalog.mjs"
2
+ import { preserveSafePartialResponse } from "./partial-response-recovery.mjs"
2
3
  import { createResponsesCallProtocol } from "./responses-call.mjs"
3
4
 
4
5
  export class GrokAdapterError extends Error {
@@ -131,10 +132,11 @@ async function* streamWithGeneration(generation, preparedRoute, requestPlan, map
131
132
  try {
132
133
  requireProvider(requestPlan.provider)
133
134
  const route = preparedRoute ?? await resolveRoute(generation, requestPlan)
134
- for await (const chunk of requestPlan.stream({
135
+ const stream = requestPlan.stream({
135
136
  route,
136
137
  transport: generation.transport,
137
- })) yield chunk
138
+ })
139
+ for await (const chunk of preserveSafePartialResponse(stream)) yield chunk
138
140
  } catch (error) {
139
141
  throw mapError(error, requestPlan.signal)
140
142
  }
@@ -3,7 +3,7 @@ const MAX_JSON_RESPONSE_BYTES = 256 * 1024
3
3
  const MAX_REQUEST_BYTES = 16 * 1024 * 1024
4
4
  const DEFAULT_MODEL_TIMEOUT_MS = 30 * 1000
5
5
  const DEFAULT_BILLING_TIMEOUT_MS = 15 * 1000
6
- const DEFAULT_RESPONSE_TIMEOUT_MS = 10 * 60 * 1000
6
+ const DEFAULT_RESPONSE_TIMEOUT_MS = 2 * 60 * 1000
7
7
  const MAX_TIMER_DELAY_MS = 2_147_483_647
8
8
 
9
9
  export class GrokTransportError extends Error {
@@ -42,10 +42,10 @@ export function createGrokTransport({
42
42
  async getBilling({ signal } = {}) {
43
43
  const deadline = createDeadline(signal, billingTimeoutMs)
44
44
  try {
45
- return await credentialSource.withAccessToken(async (accessToken, metadata) => {
46
- if (!isPlainObject(metadata) || !isHeaderValue(metadata.userId)) throw new GrokTransportError()
45
+ return await withAuthRecovery(credentialSource, async (accessToken, metadata) => {
47
46
  let response
48
47
  try {
48
+ if (!isPlainObject(metadata) || !isHeaderValue(metadata.userId)) throw new GrokTransportError()
49
49
  const headers = buildHeaders({ accessToken, attributionHeaders, clientIdentifier, clientVersion })
50
50
  headers.set("x-userid", metadata.userId)
51
51
  response = await fetch(`${BASE_URL}/v1/billing?format=credits`, {
@@ -75,7 +75,7 @@ export function createGrokTransport({
75
75
  async listModels({ signal } = {}) {
76
76
  const deadline = createDeadline(signal, modelTimeoutMs)
77
77
  try {
78
- return await credentialSource.withAccessToken(async (accessToken) => {
78
+ return await withAuthRecovery(credentialSource, async (accessToken) => {
79
79
  let response
80
80
  try {
81
81
  response = await fetch(`${BASE_URL}/v1/models`, {
@@ -124,7 +124,7 @@ export function createGrokTransport({
124
124
  let source
125
125
  const deadline = createDeadline(signal, responseTimeoutMs)
126
126
  try {
127
- response = await credentialSource.withAccessToken(async (accessToken) => {
127
+ response = await withAuthRecovery(credentialSource, async (accessToken) => {
128
128
  const headers = buildHeaders({
129
129
  accessToken,
130
130
  attributionHeaders,
@@ -145,6 +145,7 @@ export function createGrokTransport({
145
145
  source = response.body
146
146
  for await (const chunk of source) {
147
147
  if (!(chunk instanceof Uint8Array)) throw new GrokTransportError(response.status)
148
+ deadline.reset()
148
149
  yield chunk
149
150
  }
150
151
  } catch (error) {
@@ -161,6 +162,34 @@ export function createGrokTransport({
161
162
  })
162
163
  }
163
164
 
165
+ async function withAuthRecovery(credentialSource, operation) {
166
+ return credentialSource.withAccessToken(async (accessToken, metadata, recover) => {
167
+ let response = await operation(accessToken, metadata)
168
+ if (!isAuthRejection(response)) return response
169
+ const status = response.status
170
+ await discardResponse(response)
171
+ response = undefined
172
+ if (typeof recover !== "function") throw new GrokTransportError(status)
173
+ return recover(operation)
174
+ })
175
+ }
176
+
177
+ function isAuthRejection(response) {
178
+ return response !== null &&
179
+ typeof response === "object" &&
180
+ (response.status === 401 || response.status === 403)
181
+ }
182
+
183
+ async function discardResponse(response) {
184
+ try {
185
+ if (response.body && typeof response.body.cancel === "function") {
186
+ await response.body.cancel()
187
+ }
188
+ } catch {
189
+ // A rejected response must not prevent the bounded credential recovery attempt.
190
+ }
191
+ }
192
+
164
193
  function createDeadline(callerSignal, timeoutMs) {
165
194
  if (callerSignal !== undefined && (
166
195
  callerSignal === null ||
@@ -173,9 +202,15 @@ function createDeadline(callerSignal, timeoutMs) {
173
202
  const abortFromCaller = () => controller.abort(callerSignal.reason)
174
203
  if (callerSignal?.aborted) abortFromCaller()
175
204
  else callerSignal?.addEventListener("abort", abortFromCaller, { once: true })
176
- const timer = setTimeout(() => controller.abort(new DOMException("Timed out", "TimeoutError")), timeoutMs)
205
+ let timer
206
+ const reset = () => {
207
+ clearTimeout(timer)
208
+ timer = setTimeout(() => controller.abort(new DOMException("Timed out", "TimeoutError")), timeoutMs)
209
+ }
210
+ reset()
177
211
  return {
178
212
  signal: controller.signal,
213
+ reset,
179
214
  dispose() {
180
215
  clearTimeout(timer)
181
216
  callerSignal?.removeEventListener("abort", abortFromCaller)