dsh-grok-subscription 1.0.0 → 1.0.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/README.md +13 -5
- package/lib/client.js +2 -2
- package/lib/index.js +99 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ dsh plugin --profile web add BaronCyrus/dsh-grok-subscription
|
|
|
25
25
|
# 或本地路径
|
|
26
26
|
# dsh plugin --profile web add /absolute/path/to/dsh-grok-subscription
|
|
27
27
|
# 或 npm(发布后)
|
|
28
|
-
# dsh plugin --profile web add dsh-grok-subscription@1.0.
|
|
28
|
+
# dsh plugin --profile web add dsh-grok-subscription@1.0.1
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
然后重启 `dsh web`,打开 **Settings → Grok 订阅**。也可以在设置页点击“CLI 登录”或“设备码登录”;设备码流程会在启动 DSH 的终端中显示提示。登录完成后点击“从 Grok CLI 拉取”可立即同步;Chat 模型列表会随之刷新。
|
|
@@ -46,19 +46,23 @@ npm test
|
|
|
46
46
|
npm run build
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
## v1.0.1
|
|
50
|
+
|
|
51
|
+
修复 grok-build 路由「发第二条消息没有回复」:`/v1/responses` 只在 `response.output_item.added` 与 `function_call_arguments.done` 上给函数名,参数增量事件不带 `name`,于是工具调用块带着 `name: undefined` 发给宿主。DSH 会拒绝任何无法无损 JSON 序列化的流片段,并以「Assistant stream chunk must be losslessly JSON-serializable」结束整轮,界面上完全没有回复——走 grok-build 的工具调用轮次都会这样,纯文本回复则正常。现:按 call id 记住工具名;采用 `arguments.done` / `response.completed` 的权威参数;从终止快照恢复只出现在 `completed` 里的调用;用量合计保持有限值、错误状态仅在其为数字时附带;出口再统一剔除 `undefined` / 非有限值兜底。附 8 个基于真实抓包帧的回归测试。
|
|
52
|
+
|
|
49
53
|
## v1.0.0
|
|
50
54
|
|
|
51
55
|
首个稳定版,已发布 npm:`dsh-grok-subscription@1.0.0`。内置模型选择器现可通过 `model.reasoning`(efforts + defaultEffort)展示 Grok Build 的 reasoning effort 子菜单(low/medium/high/xhigh),与 Codex 一致。修复 duck `listModels`/`resolveModel` 此前省略该元数据的问题。
|
|
52
56
|
|
|
53
57
|
## v0.1.13
|
|
54
58
|
|
|
55
|
-
Chat 输入区模型选择旁增加 Codex 风格的每周剩余额度徽章(如 `16%`);悬停/点击显示「每周额度 剩余 N% · 重置于 M/D HH:mm」。仅在当前会话 provider 为 `grok-build` 且用量 `ok` 时显示。Settings 中 Pull
|
|
59
|
+
Chat 输入区模型选择旁增加 Codex 风格的每周剩余额度徽章(如 `16%`);悬停/点击显示「每周额度 剩余 N% · 重置于 M/D HH:mm」。仅在当前会话 provider 为 `grok-build` 且用量 `ok` 时显示。Settings 中 Pull/登录成功后会派发刷新事件更新徽章。已发布 npm:`dsh-grok-subscription@0.1.13`。升级后请用新 token URL 硬刷新。
|
|
56
60
|
|
|
57
61
|
## v0.1.12
|
|
58
62
|
|
|
59
63
|
升级后请用 `dsh web` 新打印的带 token URL 打开,并硬刷新(Ctrl+Shift+R),避免旧 `/plugins` client 缓存。
|
|
60
64
|
|
|
61
|
-
修复 0.1.11 实机:Settings → Plugins 仍卡在「Reading plugins…」,Pull 等到客户端 45s 超时。根因是 `status` / `currentToken` 仍可能无超时地 `await credentials.resolve` 与裸 `import('@deepseek-ai/dsh-credentials')`,楔住连接桥后 Plugins 清单也跟着挂。现:`credentialRefOf` 用 timed `optionalImport`;resolve 硬超时(默认 1.5s);`status` 先内存 / auth.json,再可选 credentials;宿主 RPC 每端点 8s 硬超时;`llm/adapters-updated` 一律延后;`inject` 保持 `['llm','web']`;客户端缺 connection 软跳过,RPC 客户端超时降至 12s
|
|
65
|
+
修复 0.1.11 实机:Settings → Plugins 仍卡在「Reading plugins…」,Pull 等到客户端 45s 超时。根因是 `status` / `currentToken` 仍可能无超时地 `await credentials.resolve` 与裸 `import('@deepseek-ai/dsh-credentials')`,楔住连接桥后 Plugins 清单也跟着挂。现:`credentialRefOf` 用 timed `optionalImport`;resolve 硬超时(默认 1.5s);`status` 先内存 / auth.json,再可选 credentials;宿主 RPC 每端点 8s 硬超时;`llm/adapters-updated` 一律延后;`inject` 保持 `['llm','web']`;客户端缺 connection 软跳过,RPC 客户端超时降至 12s。已发布 npm:`dsh-grok-subscription@0.1.12`。
|
|
62
66
|
|
|
63
67
|
## v0.1.10
|
|
64
68
|
|
|
@@ -123,19 +127,23 @@ dsh plugin --profile web add BaronCyrus/dsh-grok-subscription
|
|
|
123
127
|
|
|
124
128
|
Reinstall after upgrades, restart `dsh web`, then open **Settings → Grok Subscription**.
|
|
125
129
|
|
|
130
|
+
### v1.0.1
|
|
131
|
+
|
|
132
|
+
Fixes "no reply after sending a second message" on the grok-build route: `/v1/responses` sends the function name only on `response.output_item.added` and `function_call_arguments.done`, never on the arguments delta, so tool-call chunks carried `name: undefined`. DSH rejects any stream chunk that is not losslessly JSON-serializable and ends the whole turn with "Assistant stream chunk must be losslessly JSON-serializable", leaving no reply in the UI; every tool-calling turn over grok-build failed this way while text-only replies looked fine. Now tool names are remembered by call id, arguments are adopted from `arguments.done` / `response.completed`, calls that appear only in the terminal snapshot are recovered, usage totals stay finite, an error status is attached only when numeric, and outgoing chunks are pruned of `undefined` / non-finite values. Adds 8 regression tests built from real captured frames.
|
|
133
|
+
|
|
126
134
|
### v1.0.0
|
|
127
135
|
|
|
128
136
|
First stable release, published to npm as `dsh-grok-subscription@1.0.0`. Stock model picker now shows Grok Build reasoning effort (low/medium/high/xhigh) via `model.reasoning` metadata (`efforts` + `defaultEffort`), matching Codex. Fixes duck `listModels`/`resolveModel` omitting that shape.
|
|
129
137
|
|
|
130
138
|
### v0.1.13
|
|
131
139
|
|
|
132
|
-
Chat 输入区模型选择旁增加 Codex 风格的每周剩余额度徽章(如 `16%`);悬停/点击显示「每周额度 剩余 N% · 重置于 M/D HH:mm」。仅在当前会话 provider 为 `grok-build` 且用量 `ok` 时显示。Settings 中 Pull
|
|
140
|
+
Chat 输入区模型选择旁增加 Codex 风格的每周剩余额度徽章(如 `16%`);悬停/点击显示「每周额度 剩余 N% · 重置于 M/D HH:mm」。仅在当前会话 provider 为 `grok-build` 且用量 `ok` 时显示。Settings 中 Pull/登录成功后会派发刷新事件更新徽章。已发布 npm:`dsh-grok-subscription@0.1.13`。升级后请用新 token URL 硬刷新。
|
|
133
141
|
|
|
134
142
|
## v0.1.12
|
|
135
143
|
|
|
136
144
|
After upgrading, open the fresh token URL from `dsh web` and hard-refresh (Ctrl+Shift+R) so the old immutable `/plugins` client is not reused.
|
|
137
145
|
|
|
138
|
-
修复 0.1.11 实机:Settings → Plugins 仍卡在「Reading plugins…」,Pull 等到客户端 45s 超时。根因是 `status` / `currentToken` 仍可能无超时地 `await credentials.resolve` 与裸 `import('@deepseek-ai/dsh-credentials')`,楔住连接桥后 Plugins 清单也跟着挂。现:`credentialRefOf` 用 timed `optionalImport`;resolve 硬超时(默认 1.5s);`status` 先内存 / auth.json,再可选 credentials;宿主 RPC 每端点 8s 硬超时;`llm/adapters-updated` 一律延后;`inject` 保持 `['llm','web']`;客户端缺 connection 软跳过,RPC 客户端超时降至 12s
|
|
146
|
+
修复 0.1.11 实机:Settings → Plugins 仍卡在「Reading plugins…」,Pull 等到客户端 45s 超时。根因是 `status` / `currentToken` 仍可能无超时地 `await credentials.resolve` 与裸 `import('@deepseek-ai/dsh-credentials')`,楔住连接桥后 Plugins 清单也跟着挂。现:`credentialRefOf` 用 timed `optionalImport`;resolve 硬超时(默认 1.5s);`status` 先内存 / auth.json,再可选 credentials;宿主 RPC 每端点 8s 硬超时;`llm/adapters-updated` 一律延后;`inject` 保持 `['llm','web']`;客户端缺 connection 软跳过,RPC 客户端超时降至 12s。已发布 npm:`dsh-grok-subscription@0.1.12`。
|
|
139
147
|
|
|
140
148
|
## v0.1.10
|
|
141
149
|
|
package/lib/client.js
CHANGED
|
@@ -34,7 +34,7 @@ var import_react2 = require("react");
|
|
|
34
34
|
var zh = {
|
|
35
35
|
nav: "Grok \u8BA2\u9605",
|
|
36
36
|
title: "Grok \u8BA2\u9605",
|
|
37
|
-
subtitle: "\u7528 SuperGrok / X Premium\uFF08Grok Build\uFF09\u4F1A\u8BDD\uFF0C\u800C\u4E0D\u662F XAI_API_KEY\u3002\xB7 1.0.
|
|
37
|
+
subtitle: "\u7528 SuperGrok / X Premium\uFF08Grok Build\uFF09\u4F1A\u8BDD\uFF0C\u800C\u4E0D\u662F XAI_API_KEY\u3002\xB7 1.0.1",
|
|
38
38
|
signedIn: "\u5DF2\u767B\u5F55",
|
|
39
39
|
signedOut: "\u672A\u767B\u5F55",
|
|
40
40
|
account: "\u8D26\u6237",
|
|
@@ -81,7 +81,7 @@ var zh = {
|
|
|
81
81
|
var en = {
|
|
82
82
|
nav: "Grok Subscription",
|
|
83
83
|
title: "Grok Subscription",
|
|
84
|
-
subtitle: "Use a SuperGrok / X Premium (Grok Build) session, not XAI_API_KEY. \xB7 1.0.
|
|
84
|
+
subtitle: "Use a SuperGrok / X Premium (Grok Build) session, not XAI_API_KEY. \xB7 1.0.1",
|
|
85
85
|
signedIn: "Signed in",
|
|
86
86
|
signedOut: "Signed out",
|
|
87
87
|
account: "Account",
|
package/lib/index.js
CHANGED
|
@@ -788,7 +788,31 @@ function mapFinish(reason) {
|
|
|
788
788
|
if (reason === "length" || reason === "max_tokens") return { kind: "max-tokens" };
|
|
789
789
|
return { kind: "stop" };
|
|
790
790
|
}
|
|
791
|
-
|
|
791
|
+
function finiteOr(value, fallback) {
|
|
792
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
793
|
+
}
|
|
794
|
+
function jsonSafeChunk(value) {
|
|
795
|
+
if (value === null) return null;
|
|
796
|
+
const type = typeof value;
|
|
797
|
+
if (type === "string" || type === "boolean") return value;
|
|
798
|
+
if (type === "number") return Number.isFinite(value) && !Object.is(value, -0) ? value : void 0;
|
|
799
|
+
if (type !== "object") return void 0;
|
|
800
|
+
if (Array.isArray(value)) {
|
|
801
|
+
const list = [];
|
|
802
|
+
for (const item of value) {
|
|
803
|
+
const safe = jsonSafeChunk(item);
|
|
804
|
+
if (safe !== void 0) list.push(safe);
|
|
805
|
+
}
|
|
806
|
+
return list;
|
|
807
|
+
}
|
|
808
|
+
const out = {};
|
|
809
|
+
for (const [key, item] of Object.entries(value)) {
|
|
810
|
+
const safe = jsonSafeChunk(item);
|
|
811
|
+
if (safe !== void 0) out[key] = safe;
|
|
812
|
+
}
|
|
813
|
+
return out;
|
|
814
|
+
}
|
|
815
|
+
async function* streamResponsesUnsafe(options, token) {
|
|
792
816
|
const headers = {
|
|
793
817
|
Accept: "text/event-stream",
|
|
794
818
|
"Content-Type": "application/json",
|
|
@@ -839,8 +863,24 @@ async function* streamResponses(options, token) {
|
|
|
839
863
|
let reasoningContent = "";
|
|
840
864
|
let nextIndex = 0;
|
|
841
865
|
const toolBlocks = /* @__PURE__ */ new Map();
|
|
866
|
+
const toolNames = /* @__PURE__ */ new Map();
|
|
842
867
|
let usage;
|
|
843
868
|
let finish = { kind: "stop" };
|
|
869
|
+
const toolIdOf = (payload) => {
|
|
870
|
+
const id = payload?.item_id ?? payload?.call_id ?? payload?.id;
|
|
871
|
+
return typeof id === "string" && id ? id : void 0;
|
|
872
|
+
};
|
|
873
|
+
const learnToolName = (id, name2) => {
|
|
874
|
+
if (typeof id !== "string" || !id || typeof name2 !== "string" || !name2) return;
|
|
875
|
+
toolNames.set(id, name2);
|
|
876
|
+
const tool = toolBlocks.get(id);
|
|
877
|
+
if (tool) tool.name = name2;
|
|
878
|
+
};
|
|
879
|
+
const adoptToolArguments = (id, value) => {
|
|
880
|
+
if (typeof id !== "string" || typeof value !== "string" || !value) return;
|
|
881
|
+
const tool = toolBlocks.get(id);
|
|
882
|
+
if (tool && value.length > tool.arguments.length) tool.arguments = value;
|
|
883
|
+
};
|
|
844
884
|
const flushSse = function* (raw) {
|
|
845
885
|
const lines = raw.split("\n");
|
|
846
886
|
let event = "message";
|
|
@@ -880,12 +920,33 @@ async function* streamResponses(options, token) {
|
|
|
880
920
|
yield { type: "reasoning-delta", index: reasoningIndex, text: String(delta) };
|
|
881
921
|
return;
|
|
882
922
|
}
|
|
923
|
+
if (type === "response.output_item.added" || type === "response.output_item.done") {
|
|
924
|
+
const item = payload.item;
|
|
925
|
+
if (item?.type === "function_call") {
|
|
926
|
+
learnToolName(item.id, item.name);
|
|
927
|
+
learnToolName(item.call_id, item.name);
|
|
928
|
+
adoptToolArguments(item.id, item.arguments);
|
|
929
|
+
}
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
if (type === "response.function_call_arguments.done") {
|
|
933
|
+
const id = toolIdOf(payload);
|
|
934
|
+
learnToolName(id, payload.name);
|
|
935
|
+
adoptToolArguments(id, payload.arguments);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
883
938
|
if (type === "response.function_call_arguments.delta") {
|
|
884
|
-
const id = payload
|
|
939
|
+
const id = toolIdOf(payload);
|
|
885
940
|
if (!id) return;
|
|
886
941
|
let tool = toolBlocks.get(id);
|
|
887
942
|
if (!tool) {
|
|
888
|
-
tool = {
|
|
943
|
+
tool = {
|
|
944
|
+
index: nextIndex++,
|
|
945
|
+
id,
|
|
946
|
+
// Never leave this undefined: an unserializable chunk aborts the turn.
|
|
947
|
+
name: toolNames.get(id) ?? "tool",
|
|
948
|
+
arguments: ""
|
|
949
|
+
};
|
|
889
950
|
toolBlocks.set(id, tool);
|
|
890
951
|
yield { type: "block-start", index: tool.index, blockType: "tool-call" };
|
|
891
952
|
}
|
|
@@ -895,20 +956,38 @@ async function* streamResponses(options, token) {
|
|
|
895
956
|
return;
|
|
896
957
|
}
|
|
897
958
|
if (type === "response.completed") {
|
|
959
|
+
for (const item of payload.response?.output ?? []) {
|
|
960
|
+
if (item?.type !== "function_call") continue;
|
|
961
|
+
learnToolName(item.id, item.name);
|
|
962
|
+
learnToolName(item.call_id, item.name);
|
|
963
|
+
const id = typeof item.id === "string" && item.id ? item.id : void 0;
|
|
964
|
+
if (id && !toolBlocks.has(id)) {
|
|
965
|
+
const tool = { index: nextIndex++, id, name: toolNames.get(id) ?? "tool", arguments: "" };
|
|
966
|
+
toolBlocks.set(id, tool);
|
|
967
|
+
yield { type: "block-start", index: tool.index, blockType: "tool-call" };
|
|
968
|
+
}
|
|
969
|
+
adoptToolArguments(id, item.arguments);
|
|
970
|
+
}
|
|
898
971
|
const responseUsage = payload.response?.usage ?? payload.usage;
|
|
899
972
|
if (responseUsage) {
|
|
900
973
|
usage = {
|
|
901
|
-
inputTokens: responseUsage.input_tokens ?? responseUsage.prompt_tokens
|
|
902
|
-
outputTokens: responseUsage.output_tokens ?? responseUsage.completion_tokens
|
|
903
|
-
totalTokens: responseUsage.total_tokens
|
|
974
|
+
inputTokens: finiteOr(responseUsage.input_tokens ?? responseUsage.prompt_tokens, 0),
|
|
975
|
+
outputTokens: finiteOr(responseUsage.output_tokens ?? responseUsage.completion_tokens, 0)
|
|
904
976
|
};
|
|
977
|
+
usage.totalTokens = finiteOr(responseUsage.total_tokens, usage.inputTokens + usage.outputTokens);
|
|
905
978
|
}
|
|
906
979
|
finish = mapFinish(payload.response?.status === "incomplete" ? "length" : "stop");
|
|
907
980
|
if (toolBlocks.size) finish = { kind: "tool-calls" };
|
|
908
981
|
}
|
|
909
982
|
if (type === "response.failed" || type === "error") {
|
|
910
|
-
const
|
|
911
|
-
|
|
983
|
+
const raw2 = payload.error?.message ?? payload.message;
|
|
984
|
+
const failure = {
|
|
985
|
+
message: typeof raw2 === "string" && raw2 ? raw2 : "Grok Build stream failed",
|
|
986
|
+
code: "PROVIDER"
|
|
987
|
+
};
|
|
988
|
+
const status = finiteOr(payload.error?.status, void 0);
|
|
989
|
+
if (status !== void 0) failure.status = status;
|
|
990
|
+
finish = { kind: "error", failure };
|
|
912
991
|
}
|
|
913
992
|
};
|
|
914
993
|
for await (const chunk of response.body) {
|
|
@@ -937,6 +1016,12 @@ async function* streamResponses(options, token) {
|
|
|
937
1016
|
if (usage) yield { type: "usage", usage };
|
|
938
1017
|
yield { type: "finish", reason: finish };
|
|
939
1018
|
}
|
|
1019
|
+
async function* streamResponses(options, token) {
|
|
1020
|
+
for await (const chunk of streamResponsesUnsafe(options, token)) {
|
|
1021
|
+
const safe = jsonSafeChunk(chunk);
|
|
1022
|
+
if (safe) yield safe;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
940
1025
|
function visiblePiModels(session) {
|
|
941
1026
|
if (session.publicAccount()?.signedIn !== true) return [];
|
|
942
1027
|
return toPiModels(session.models()).map((model) => model.provider === PROVIDER_ID ? model : { ...model, provider: PROVIDER_ID });
|
|
@@ -992,17 +1077,13 @@ function createDuckAdapter(session) {
|
|
|
992
1077
|
yield* streamResponses(options, token);
|
|
993
1078
|
} catch (error) {
|
|
994
1079
|
const aborted = options.signal?.aborted === true;
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
kind: aborted ? "aborted" : "error",
|
|
999
|
-
failure: {
|
|
1000
|
-
message: error instanceof Error ? error.message : "Grok Build request failed",
|
|
1001
|
-
code: aborted ? "ABORTED" : "PROVIDER",
|
|
1002
|
-
status: error?.status
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1080
|
+
const failure = {
|
|
1081
|
+
message: error instanceof Error ? error.message : "Grok Build request failed",
|
|
1082
|
+
code: aborted ? "ABORTED" : "PROVIDER"
|
|
1005
1083
|
};
|
|
1084
|
+
const status = finiteOr(error?.status, void 0);
|
|
1085
|
+
if (status !== void 0) failure.status = status;
|
|
1086
|
+
yield { type: "finish", reason: { kind: aborted ? "aborted" : "error", failure } };
|
|
1006
1087
|
}
|
|
1007
1088
|
}
|
|
1008
1089
|
};
|