dsh-connect-doubao 0.2.0 → 0.3.0
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 +85 -0
- package/README.md +108 -6
- package/lib/cli-doctor.js +14 -2
- package/lib/cli-probe.js +1 -1
- package/lib/client.js +168 -29
- package/lib/{doubao-quota-XUFfDd1i.js → doubao-quota-Qj46Oa4D.js} +260 -43
- package/lib/doubao-status-NgMAwtxK.js +1463 -0
- package/lib/index.js +269 -21
- package/package.json +2 -1
- package/lib/doubao-status-C3wgMqnL.js +0 -773
|
@@ -105,11 +105,92 @@ const DEFAULT_REASONING_LEVEL_ID = "high";
|
|
|
105
105
|
function findReasoningLevel(id) {
|
|
106
106
|
return DOUBAO_REASONING_LEVELS.find((level) => level.id === id) ?? DOUBAO_REASONING_LEVELS.find((level) => level.id === "high");
|
|
107
107
|
}
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
/**
|
|
109
|
+
* `need_deep_think` / `ext.use_deep_think` — the 深度思考 switch.
|
|
110
|
+
*
|
|
111
|
+
* CDP-captured 2026-10-23, the same conversation sent with the switch OFF and ON:
|
|
112
|
+
*
|
|
113
|
+
* off → option.need_deep_think: 0 ext.use_deep_think: "0"
|
|
114
|
+
* on → option.need_deep_think: 3 ext.use_deep_think: "3"
|
|
115
|
+
*
|
|
116
|
+
* `3` is what the switch sends — NOT `10000 + reasoning_effort`. That shape
|
|
117
|
+
* (10005 at 高) was this plugin's own invention, and sending it produced no
|
|
118
|
+
* thinking at all: every frame still carried `block_type: 10000` and the reply
|
|
119
|
+
* agent was `pc_general_nocot_agent` (no-CoT).
|
|
120
|
+
*
|
|
121
|
+
* The two axes are independent: effort still travels as `reasoning_effort`
|
|
122
|
+
* 3/4/5, while this flag only says whether the model may think before answering.
|
|
123
|
+
*/
|
|
124
|
+
const DEEP_THINK_OFF = 0;
|
|
125
|
+
const DEEP_THINK_ON = 3;
|
|
126
|
+
/** `need_deep_think` value for the switch state. */
|
|
127
|
+
function needDeepThinkValue(deepThink) {
|
|
128
|
+
return deepThink ? 3 : 0;
|
|
111
129
|
}
|
|
112
130
|
/**
|
|
131
|
+
* Doubao's skill table, transcribed verbatim from the client bundle
|
|
132
|
+
* (`{FreeChat:0, SkillWrite:2, SkillImageGen:3, …}`), not inferred.
|
|
133
|
+
*
|
|
134
|
+
* `skill_id` is the decimal string of `skill_type`; the two are ALWAYS the same
|
|
135
|
+
* number, which is why a plain turn carries `{"skill_id":"0","skill_type":0}`.
|
|
136
|
+
* On the wire it is a JSON STRING inside `ext.input_skill`.
|
|
137
|
+
*
|
|
138
|
+
* There is no separate HTTP endpoint for text-to-image in the client — the only
|
|
139
|
+
* generation URL is `/creativity/canvas/exec`, which is the image EDITOR
|
|
140
|
+
* (cutout / outpaint / layer split). So a skill turn must go through
|
|
141
|
+
* `/chat/completion`, and it does: verified 2026-11-02, `skill_type: 3` returns
|
|
142
|
+
* real `rc_gen_image/*.jpeg` artefacts from Seedream 5.0.
|
|
143
|
+
*/
|
|
144
|
+
const DOUBAO_SKILLS = {
|
|
145
|
+
freeChat: 0,
|
|
146
|
+
write: 2,
|
|
147
|
+
imageGen: 3,
|
|
148
|
+
search: 4,
|
|
149
|
+
translate: 5,
|
|
150
|
+
read: 6,
|
|
151
|
+
webpage: 7,
|
|
152
|
+
deepSearch: 8,
|
|
153
|
+
musicGen: 9,
|
|
154
|
+
edu: 11,
|
|
155
|
+
codeInterpreter: 13,
|
|
156
|
+
codeAssistant: 16,
|
|
157
|
+
videoGeneration: 17,
|
|
158
|
+
aiPPT: 18
|
|
159
|
+
};
|
|
160
|
+
/** The `ext.input_skill` JSON string for a skill; undefined means plain chat. */
|
|
161
|
+
function inputSkillOf(skill) {
|
|
162
|
+
if (skill === void 0 || skill === "freeChat") return void 0;
|
|
163
|
+
const type = DOUBAO_SKILLS[skill];
|
|
164
|
+
return JSON.stringify({
|
|
165
|
+
skill_id: String(type),
|
|
166
|
+
skill_type: type,
|
|
167
|
+
variables: {}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* `block_type` of a creation (image-generation) block.
|
|
172
|
+
*
|
|
173
|
+
* Shape, from a captured stream:
|
|
174
|
+
* content.creation_block.creations[] = {
|
|
175
|
+
* type: 1, // 1 = image
|
|
176
|
+
* id: "<task id>",
|
|
177
|
+
* image: { key, status, image_ori{url,width,height}, image_preview{…}, image_thumb{…} }
|
|
178
|
+
* }
|
|
179
|
+
*/
|
|
180
|
+
const CREATION_BLOCK_TYPE = 2074;
|
|
181
|
+
/**
|
|
182
|
+
* DSH-side alias for "generate an image".
|
|
183
|
+
*
|
|
184
|
+
* NOT a Doubao `model_item_key` — Doubao has no model by this name. Selecting it
|
|
185
|
+
* makes the shim send an ordinary chat turn with `input_skill: imageGen`, and
|
|
186
|
+
* Doubao answers with Seedream. Keeping it in the catalog is what puts 生图 in
|
|
187
|
+
* DSH's model picker without inventing a second UI.
|
|
188
|
+
*/
|
|
189
|
+
const DOUBAO_IMAGE_MODEL_ID = "image-gen";
|
|
190
|
+
const DOUBAO_IMAGE_MODEL_NAME = "豆包 生图(Seedream 5.0)";
|
|
191
|
+
/** The chat model a skill turn rides on: the app's own default. */
|
|
192
|
+
const SKILL_CARRIER_MODEL_ID = "0";
|
|
193
|
+
/**
|
|
113
194
|
* The two entries DSH may offer.
|
|
114
195
|
*
|
|
115
196
|
* WHY ONLY TWO. Doubao groups models by MODE, and the model list is per-mode:
|
|
@@ -132,16 +213,24 @@ function needDeepThinkOf(level) {
|
|
|
132
213
|
* unconfigured install reproduces the app rather than something that merely
|
|
133
214
|
* happens to work.
|
|
134
215
|
*/
|
|
135
|
-
const DOUBAO_MODELS = [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
216
|
+
const DOUBAO_MODELS = [
|
|
217
|
+
{
|
|
218
|
+
id: "0",
|
|
219
|
+
name: "豆包 快速",
|
|
220
|
+
reasoning: true
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "3",
|
|
224
|
+
name: "豆包 2.1 Turbo",
|
|
225
|
+
badge: "专家",
|
|
226
|
+
reasoning: true
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: DOUBAO_IMAGE_MODEL_ID,
|
|
230
|
+
name: DOUBAO_IMAGE_MODEL_NAME,
|
|
231
|
+
reasoning: true
|
|
232
|
+
}
|
|
233
|
+
];
|
|
145
234
|
/**
|
|
146
235
|
* Entries that exist in the desktop app but are deliberately NOT offered here.
|
|
147
236
|
*
|
|
@@ -191,8 +280,15 @@ const DOUBAO_DEFAULT_MODEL_ID = "0";
|
|
|
191
280
|
function findDoubaoModel(id) {
|
|
192
281
|
return DOUBAO_MODELS.find((model) => model.id === id) ?? DOUBAO_MODELS.find((model) => model.id === "0");
|
|
193
282
|
}
|
|
194
|
-
|
|
195
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Publish the catalog as pi-ai model descriptors.
|
|
285
|
+
*
|
|
286
|
+
* `models` defaults to the static list but is normally the DISCOVERED one — the
|
|
287
|
+
* caller passes whatever the client cache currently reports, so a model Doubao
|
|
288
|
+
* ships appears without a plugin release.
|
|
289
|
+
*/
|
|
290
|
+
function discoverDoubaoModels(models = DOUBAO_MODELS) {
|
|
291
|
+
return models.map((model) => ({
|
|
196
292
|
id: model.id,
|
|
197
293
|
name: model.badge === void 0 ? model.name : `${model.name} · ${model.badge}`,
|
|
198
294
|
contextWindow: DOUBAO_CONTEXT_WINDOW,
|
|
@@ -210,14 +306,20 @@ function discoverDoubaoModels() {
|
|
|
210
306
|
*
|
|
211
307
|
* `undefined` (never configured) serves the whole catalog: a first-run install
|
|
212
308
|
* must show its models. Ids that no longer exist are dropped.
|
|
309
|
+
*
|
|
310
|
+
* A model DISCOVERED after the user last saved is kept even when it is not in
|
|
311
|
+
* their tick list — otherwise a new Doubao release would be invisible until the
|
|
312
|
+
* user thought to reopen the card and re-save, which is exactly the staleness
|
|
313
|
+
* this path exists to remove.
|
|
213
314
|
*/
|
|
214
|
-
function enabledModelsOf(enabledIds) {
|
|
215
|
-
if (enabledIds === void 0 || enabledIds.length === 0) return [...
|
|
315
|
+
function enabledModelsOf(enabledIds, models = DOUBAO_MODELS) {
|
|
316
|
+
if (enabledIds === void 0 || enabledIds.length === 0) return [...models];
|
|
216
317
|
const wanted = new Set(enabledIds);
|
|
217
|
-
|
|
318
|
+
const known = new Set(DOUBAO_MODELS.map((model) => model.id));
|
|
319
|
+
return models.filter((model) => wanted.has(model.id) || !known.has(model.id));
|
|
218
320
|
}
|
|
219
|
-
function doubaoCatalogEntries() {
|
|
220
|
-
return
|
|
321
|
+
function doubaoCatalogEntries(models = DOUBAO_MODELS) {
|
|
322
|
+
return models.map((model) => ({
|
|
221
323
|
id: model.id,
|
|
222
324
|
name: model.name,
|
|
223
325
|
badge: model.badge ?? null,
|
|
@@ -857,6 +959,16 @@ function buildChatBody(prompt, options = {}) {
|
|
|
857
959
|
const level = findReasoningLevel(options.reasoningLevel);
|
|
858
960
|
const task = taskModeEnabled(options);
|
|
859
961
|
/**
|
|
962
|
+
* Deep-thinking toggle, for probing only.
|
|
963
|
+
*
|
|
964
|
+
* The captured ordinary turn sends `need_deep_think: 0`; the client's 深度思考
|
|
965
|
+
* switch is what turns this on, and the value it sends there has NOT been
|
|
966
|
+
* captured yet. `DSH_DOUBAO_DEEP_THINK=1` reproduces the old 10000+level shape
|
|
967
|
+
* so the resulting stream can be inspected.
|
|
968
|
+
*/
|
|
969
|
+
const deepThink = options.deepThink === true || options.deepThink === void 0 && process.env.DSH_DOUBAO_DEEP_THINK === "1";
|
|
970
|
+
const needDeepThink = needDeepThinkValue(deepThink);
|
|
971
|
+
/**
|
|
860
972
|
* 2 = 普通对话, 1 = 「工作任务」.
|
|
861
973
|
*
|
|
862
974
|
* CDP-captured from the running client on 2026-10-22. This constant was the
|
|
@@ -902,7 +1014,7 @@ function buildChatBody(prompt, options = {}) {
|
|
|
902
1014
|
answer_with_suggest: false,
|
|
903
1015
|
agent_mode: agentMode,
|
|
904
1016
|
tts_switch: false,
|
|
905
|
-
need_deep_think:
|
|
1017
|
+
need_deep_think: needDeepThink,
|
|
906
1018
|
click_clear_context: false,
|
|
907
1019
|
from_suggest: false,
|
|
908
1020
|
is_regen: false,
|
|
@@ -916,7 +1028,7 @@ function buildChatBody(prompt, options = {}) {
|
|
|
916
1028
|
scene_type: 0,
|
|
917
1029
|
unique_key: randomUUID(),
|
|
918
1030
|
start_seq: 0,
|
|
919
|
-
need_create_conversation: true,
|
|
1031
|
+
need_create_conversation: options.continueConversation !== true,
|
|
920
1032
|
conversation_init_option: { need_ack_conversation: true },
|
|
921
1033
|
conversation_init_ext: {
|
|
922
1034
|
model_item_key: model.id,
|
|
@@ -952,7 +1064,7 @@ function buildChatBody(prompt, options = {}) {
|
|
|
952
1064
|
mention_skill_list: "[]",
|
|
953
1065
|
mention_plugin_list: "[]",
|
|
954
1066
|
mention_ext: "[{}]",
|
|
955
|
-
conversation_mode: "",
|
|
1067
|
+
conversation_mode: deepThink ? "1" : "",
|
|
956
1068
|
mode_id: modeId,
|
|
957
1069
|
model_item_key: model.id,
|
|
958
1070
|
agent_mode: String(agentMode),
|
|
@@ -984,13 +1096,17 @@ function buildChatBody(prompt, options = {}) {
|
|
|
984
1096
|
user_context: [],
|
|
985
1097
|
ext: {
|
|
986
1098
|
agent_mode: String(agentMode),
|
|
987
|
-
use_deep_think:
|
|
1099
|
+
use_deep_think: String(needDeepThink),
|
|
988
1100
|
sub_conv_firstmet_type: "1",
|
|
989
1101
|
general_task_param: JSON.stringify(taskParam),
|
|
990
1102
|
collection_id: "",
|
|
991
1103
|
is_finish: "1",
|
|
992
1104
|
conversation_init_option: JSON.stringify({ need_ack_conversation: true }),
|
|
993
|
-
commerce_credit_config_enable: "0"
|
|
1105
|
+
commerce_credit_config_enable: "0",
|
|
1106
|
+
...(() => {
|
|
1107
|
+
const encoded = inputSkillOf(options.skill);
|
|
1108
|
+
return encoded === void 0 ? {} : { input_skill: encoded };
|
|
1109
|
+
})()
|
|
994
1110
|
}
|
|
995
1111
|
};
|
|
996
1112
|
}
|
|
@@ -1032,20 +1148,70 @@ function parseFrames(buffer) {
|
|
|
1032
1148
|
};
|
|
1033
1149
|
}
|
|
1034
1150
|
/**
|
|
1035
|
-
* Collect
|
|
1151
|
+
* Collect answer text and thinking text, separated by block ownership.
|
|
1036
1152
|
*
|
|
1037
|
-
*
|
|
1038
|
-
*
|
|
1039
|
-
*
|
|
1153
|
+
* A deep-think reply carries a `block_type: 10040` container (the visible
|
|
1154
|
+
* 「正在思考 / 已完成思考」 shell) and then streams the reasoning as ordinary
|
|
1155
|
+
* `block_type: 10000` blocks whose `parent_id` is that container's id. The shell
|
|
1156
|
+
* and its children both point at `Deep_Think.png`, but `parent_id` is the
|
|
1157
|
+
* reliable discriminator, so it is what this uses.
|
|
1158
|
+
*
|
|
1159
|
+
* Treating every `text` as answer text — what the previous revision did — mixes
|
|
1160
|
+
* the model's private reasoning into the reply the user sees.
|
|
1040
1161
|
*/
|
|
1041
|
-
function
|
|
1162
|
+
function collectBlocks(node, into, thinkingIds) {
|
|
1042
1163
|
if (Array.isArray(node)) {
|
|
1043
|
-
for (const item of node)
|
|
1164
|
+
for (const item of node) collectBlocks(item, into, thinkingIds);
|
|
1044
1165
|
return;
|
|
1045
1166
|
}
|
|
1046
1167
|
if (node === null || typeof node !== "object") return;
|
|
1047
|
-
|
|
1048
|
-
|
|
1168
|
+
const record = node;
|
|
1169
|
+
const blockType = record.block_type;
|
|
1170
|
+
if (typeof blockType === "number") {
|
|
1171
|
+
const blockId = typeof record.block_id === "string" ? record.block_id : void 0;
|
|
1172
|
+
if (blockType === THINKING_BLOCK_TYPE && blockId !== void 0) thinkingIds.add(blockId);
|
|
1173
|
+
if (blockType === 2074 && into.images !== void 0) {
|
|
1174
|
+
const creations = record.content?.creation_block?.creations;
|
|
1175
|
+
if (Array.isArray(creations)) for (const raw of creations) {
|
|
1176
|
+
const image = toDoubaoImage(raw);
|
|
1177
|
+
if (image !== void 0) into.images.push(image);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
const text = record.content?.text_block?.text;
|
|
1181
|
+
if (typeof text === "string" && text !== "") {
|
|
1182
|
+
const parentId = typeof record.parent_id === "string" ? record.parent_id : "";
|
|
1183
|
+
if (blockType === THINKING_BLOCK_TYPE || parentId !== "" && thinkingIds.has(parentId)) into.thinking.push(text);
|
|
1184
|
+
else into.answer.push(text);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
for (const value of Object.values(record)) collectBlocks(value, into, thinkingIds);
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Turn one `creations[]` entry into an image, or undefined when it carries no
|
|
1191
|
+
* usable URL yet (the placeholder stage).
|
|
1192
|
+
*
|
|
1193
|
+
* URL preference is original → preview → thumb: `image_ori` is the full-
|
|
1194
|
+
* resolution artefact, the others are watermarked/derivative variants the app
|
|
1195
|
+
* uses for lists and thumbnails.
|
|
1196
|
+
*/
|
|
1197
|
+
function toDoubaoImage(raw) {
|
|
1198
|
+
if (raw === null || typeof raw !== "object") return void 0;
|
|
1199
|
+
const creation = raw;
|
|
1200
|
+
const image = creation.image;
|
|
1201
|
+
if (image === void 0) return void 0;
|
|
1202
|
+
const pick = (key) => {
|
|
1203
|
+
const value = image[key];
|
|
1204
|
+
return typeof value === "object" && value !== null ? value : void 0;
|
|
1205
|
+
};
|
|
1206
|
+
const best = pick("image_ori") ?? pick("image_preview") ?? pick("image_thumb");
|
|
1207
|
+
if (best === void 0 || typeof best.url !== "string" || best.url === "") return void 0;
|
|
1208
|
+
const taskId = typeof creation.id === "string" ? creation.id : typeof creation.id === "number" ? String(creation.id) : void 0;
|
|
1209
|
+
const out = { url: best.url };
|
|
1210
|
+
if (taskId !== void 0) out.taskId = taskId;
|
|
1211
|
+
if (typeof image.key === "string") out.key = image.key;
|
|
1212
|
+
if (typeof best.width === "number") out.width = best.width;
|
|
1213
|
+
if (typeof best.height === "number") out.height = best.height;
|
|
1214
|
+
return out;
|
|
1049
1215
|
}
|
|
1050
1216
|
/** Read the model identifier the server actually used for a reply. */
|
|
1051
1217
|
function extractModel(payload) {
|
|
@@ -1212,6 +1378,12 @@ async function consumeStream(response, callbacks, options = {}) {
|
|
|
1212
1378
|
const texts = [];
|
|
1213
1379
|
/** Text carried by STREAM_MSG_NOTIFY instead of by chunk deltas. */
|
|
1214
1380
|
const notifyTexts = [];
|
|
1381
|
+
/** Generated images, in arrival order (may repeat a task while it streams). */
|
|
1382
|
+
const images = [];
|
|
1383
|
+
/** Private reasoning (deep-think turns), kept out of the answer. */
|
|
1384
|
+
const reasoningParts = [];
|
|
1385
|
+
/** block_ids of the `block_type: 10040` thinking containers seen so far. */
|
|
1386
|
+
const thinkingBlockIds = /* @__PURE__ */ new Set();
|
|
1215
1387
|
let conversationId;
|
|
1216
1388
|
let messageId;
|
|
1217
1389
|
let model;
|
|
@@ -1275,9 +1447,18 @@ async function consumeStream(response, callbacks, options = {}) {
|
|
|
1275
1447
|
if (typeof reason === "string" && /agent_err_real_answer/.test(reason)) taskAgentError = reason;
|
|
1276
1448
|
}
|
|
1277
1449
|
if (name === "STREAM_MSG_NOTIFY") {
|
|
1278
|
-
const acc = {
|
|
1279
|
-
|
|
1280
|
-
|
|
1450
|
+
const acc = {
|
|
1451
|
+
answer: [],
|
|
1452
|
+
thinking: [],
|
|
1453
|
+
images
|
|
1454
|
+
};
|
|
1455
|
+
collectBlocks(record.content?.content_block, acc, thinkingBlockIds);
|
|
1456
|
+
for (const piece of acc.thinking) {
|
|
1457
|
+
if (!piece) continue;
|
|
1458
|
+
reasoningParts.push(piece);
|
|
1459
|
+
if (callbacks?.onThinking) callbacks.onThinking(piece);
|
|
1460
|
+
}
|
|
1461
|
+
for (const piece of acc.answer) {
|
|
1281
1462
|
if (!piece) continue;
|
|
1282
1463
|
notifyTexts.push(piece);
|
|
1283
1464
|
if (callbacks?.onText) callbacks.onText(piece);
|
|
@@ -1288,9 +1469,18 @@ async function consumeStream(response, callbacks, options = {}) {
|
|
|
1288
1469
|
if (name === "STREAM_CHUNK" || name === "CHUNK_DELTA") {
|
|
1289
1470
|
model = model ?? extractModel(payload);
|
|
1290
1471
|
thinking = thinking || extractThinking(payload);
|
|
1291
|
-
const acc = {
|
|
1292
|
-
|
|
1293
|
-
|
|
1472
|
+
const acc = {
|
|
1473
|
+
answer: [],
|
|
1474
|
+
thinking: [],
|
|
1475
|
+
images
|
|
1476
|
+
};
|
|
1477
|
+
collectBlocks(payload, acc, thinkingBlockIds);
|
|
1478
|
+
for (const piece of acc.thinking) {
|
|
1479
|
+
if (!piece) continue;
|
|
1480
|
+
reasoningParts.push(piece);
|
|
1481
|
+
if (callbacks?.onThinking) callbacks.onThinking(piece);
|
|
1482
|
+
}
|
|
1483
|
+
for (const text of acc.answer) {
|
|
1294
1484
|
if (!text) continue;
|
|
1295
1485
|
if (callbacks?.onText) callbacks.onText(text);
|
|
1296
1486
|
texts.push(text);
|
|
@@ -1313,10 +1503,10 @@ async function consumeStream(response, callbacks, options = {}) {
|
|
|
1313
1503
|
reader.releaseLock();
|
|
1314
1504
|
}
|
|
1315
1505
|
const chunkText = texts.join("");
|
|
1316
|
-
const
|
|
1317
|
-
const text = stripPromptEcho(chunkText.startsWith(notifyText) ? chunkText : notifyText + chunkText);
|
|
1506
|
+
const text = stripPromptEcho(assembleReplyText(notifyTexts.join(""), chunkText));
|
|
1318
1507
|
if (taskAgentError !== void 0) throw new DoubaoUpstreamError(`Doubao accepted the task but its executing runtime was unreachable (${taskAgentError}). The 「工作任务」 runtime is attached by the desktop client; without it the agent has nowhere to run.`, CODE_TASK_RUNTIME_UNAVAILABLE);
|
|
1319
|
-
|
|
1508
|
+
const uniqueImages = [...new Map(images.map((image) => [image.url, image])).values()];
|
|
1509
|
+
if (!text && uniqueImages.length === 0) {
|
|
1320
1510
|
const seen = [...events];
|
|
1321
1511
|
throw new DoubaoUpstreamError(`Doubao returned an empty completion${lastEventId ? ` (last event id ${lastEventId})` : ""}${seen.length > 0 ? `; events seen: ${seen.join(", ")}` : "; no events at all"}.`);
|
|
1322
1512
|
}
|
|
@@ -1325,11 +1515,30 @@ async function consumeStream(response, callbacks, options = {}) {
|
|
|
1325
1515
|
...model !== void 0 ? { model } : {},
|
|
1326
1516
|
...conversationId !== void 0 ? { conversationId } : {},
|
|
1327
1517
|
...messageId !== void 0 ? { messageId } : {},
|
|
1518
|
+
...reasoningParts.length > 0 ? { reasoningText: reasoningParts.join("") } : {},
|
|
1328
1519
|
...intentionAgent !== void 0 ? { intentionAgent } : {},
|
|
1520
|
+
images: uniqueImages,
|
|
1329
1521
|
thinking
|
|
1330
1522
|
};
|
|
1331
1523
|
}
|
|
1332
1524
|
/**
|
|
1525
|
+
* Join the two halves of a reply.
|
|
1526
|
+
*
|
|
1527
|
+
* The opening of every answer arrives in STREAM_MSG_NOTIFY and the remainder as
|
|
1528
|
+
* patch deltas in STREAM_CHUNK. Reading only the chunks swallowed the first
|
|
1529
|
+
* character of EVERY reply — 「1+1等于2。」 came back as 「+1等于2。」, 「我是豆包」
|
|
1530
|
+
* as 「是豆包」 — and nothing failed loudly, which is exactly why it survived.
|
|
1531
|
+
*
|
|
1532
|
+
* A cumulative chunk stream (one that re-sends what was already delivered)
|
|
1533
|
+
* already starts with the notification text; that case is detected rather than
|
|
1534
|
+
* concatenated twice. Exported so the rule can be tested without a live stream.
|
|
1535
|
+
*/
|
|
1536
|
+
function assembleReplyText(notifyText, chunkText) {
|
|
1537
|
+
if (notifyText === "") return chunkText;
|
|
1538
|
+
if (chunkText === "") return notifyText;
|
|
1539
|
+
return chunkText.startsWith(notifyText) ? chunkText : notifyText + chunkText;
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1333
1542
|
* Remove the echoed user prompt from the front of the assembled text.
|
|
1334
1543
|
*
|
|
1335
1544
|
* Doubao's first chunk replays the inbound message; keeping it would make every
|
|
@@ -1350,6 +1559,14 @@ const CODE_SESSION_DEAD = 710012001;
|
|
|
1350
1559
|
/** The server's business code for a risk-control slider challenge. */
|
|
1351
1560
|
const CODE_RATE_LIMITED = 710022004;
|
|
1352
1561
|
/**
|
|
1562
|
+
* `block_type` of the deep-think container.
|
|
1563
|
+
*
|
|
1564
|
+
* A 深度思考 turn opens one `10040` block (the 「正在思考 / 已完成思考」 shell) and
|
|
1565
|
+
* then streams the reasoning as `10000` blocks whose `parent_id` is its id.
|
|
1566
|
+
* Captured 2026-10-23.
|
|
1567
|
+
*/
|
|
1568
|
+
const THINKING_BLOCK_TYPE = 10040;
|
|
1569
|
+
/**
|
|
1353
1570
|
* The server's business code when a 「工作任务」 was accepted but its executing
|
|
1354
1571
|
* runtime could not be reached (`expose_reason: agent_err_real_answer`).
|
|
1355
1572
|
*
|
|
@@ -1573,4 +1790,4 @@ function formatDuration(ms) {
|
|
|
1573
1790
|
return parts.join(" ") || "0s";
|
|
1574
1791
|
}
|
|
1575
1792
|
//#endregion
|
|
1576
|
-
export {
|
|
1793
|
+
export { DOUBAO_PROVIDER as $, probeAccount as A, invalidateCredentialCache as B, chat as C, extractModel as D, describeDoubaoFailure as E, REQUIRED_COOKIE_NAMES as F, DEEP_THINK_ON as G, CHAT_AGENT_MODE as H, decodeCookiePlaintext as I, DOUBAO_DEFAULT_MODEL_ID as J, DEFAULT_REASONING_LEVEL_ID as K, decryptCookieValue as L, taskModeEnabled as M, taskWorkspaceOf as N, invalidateRenewals as O, CREDENTIAL_TTL_MS as P, DOUBAO_MODELS as Q, describeProfileLocation as R, buildQueryUrl as S, collectBlocks as T, CREATION_BLOCK_TYPE as U, loadDoubaoCredentials as V, DEEP_THINK_OFF as W, DOUBAO_IMAGE_MODEL_NAME as X, DOUBAO_IMAGE_MODEL_ID as Y, DOUBAO_MAX_TOKENS as Z, applyRenewals as _, invalidateQuotaCache as a, TASK_AGENT_MODE as at, buildGeneralTaskParam as b, ACCOUNT_ENDPOINT as c, TASK_SANDBOX_AUTH_ALLOW_ALL as ct, DEFAULT_BOT_ID as d, enabledModelsOf as dt, DOUBAO_PROVIDER_DISPLAY_NAME as et, DOUBAO_ERROR_HINTS as f, findDoubaoModel as ft, RUNTIME_VERSION as g, QUOTA_ENDPOINT as h, needDeepThinkValue as ht, formatDuration as i, SKILL_CARRIER_MODEL_ID as it, streamChat as j, parseFrames as k, CHAT_ENDPOINT as l, discoverDoubaoModels as lt, DoubaoUpstreamError as m, inputSkillOf as mt, fetchQuota as n, DOUBAO_SKILLS as nt, millisUntilReset as o, TASK_RUNTIME_CLOUD_VM as ot, DOUBAO_VERSION as p, findReasoningLevel as pt, DOUBAO_CONTEXT_WINDOW as q, findWindow as r, DOUBAO_UNAVAILABLE_MODELS as rt, normalizeWindow as s, TASK_RUNTIME_LOCAL_PC as st, QUOTA_TTL_MS as t, DOUBAO_REASONING_LEVELS as tt, CLIENT_PARAMS as u, doubaoCatalogEntries as ut, assembleReplyText as v, classifyDoubaoFailure as w, buildHeaders as x, buildChatBody as y, findDoubaoUserDataDir as z };
|