@eddyskywalker/dsh-chatgpt-subscription 0.10.1 → 0.10.5
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 +13 -0
- package/lib/client.js +103 -0
- package/lib/client.js.map +1 -1
- package/lib/index.js +1157 -353
- package/lib/types/client/minimax-code/MinimaxCodeSection.d.ts.map +1 -1
- package/lib/types/client/minimax-code/locales.d.ts +38 -2
- package/lib/types/client/minimax-code/locales.d.ts.map +1 -1
- package/lib/types/host/minimax-code/adapter.d.ts.map +1 -1
- package/lib/types/host/minimax-code/checkin-gateway.d.ts +109 -0
- package/lib/types/host/minimax-code/checkin-gateway.d.ts.map +1 -0
- package/lib/types/host/minimax-code/checkin.d.ts +150 -0
- package/lib/types/host/minimax-code/checkin.d.ts.map +1 -0
- package/lib/types/host/minimax-code/mapper.d.ts +52 -23
- package/lib/types/host/minimax-code/mapper.d.ts.map +1 -1
- package/lib/types/host/minimax-code/routes.d.ts +3 -0
- package/lib/types/host/minimax-code/routes.d.ts.map +1 -1
- package/lib/types/host/minimax-code/token-store.d.ts +15 -0
- package/lib/types/host/minimax-code/token-store.d.ts.map +1 -1
- package/lib/types/host/minimax-code/types.d.ts +25 -9
- package/lib/types/host/minimax-code/types.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/minimax-code-contracts.d.ts +36 -0
- package/lib/types/shared/minimax-code-contracts.d.ts.map +1 -1
- package/package.json +31 -31
- package/lib/types/host/claude/__probe-assert.d.ts +0 -2
- package/lib/types/host/claude/__probe-assert.d.ts.map +0 -1
- package/lib/types/shared/__probe-claude-import.d.ts +0 -2
- package/lib/types/shared/__probe-claude-import.d.ts.map +0 -1
package/lib/index.js
CHANGED
|
@@ -2547,13 +2547,13 @@ function createCodexFetchProvider(options = {}) {
|
|
|
2547
2547
|
//#region src/host/common/llm-compat.ts
|
|
2548
2548
|
/** This package's kind in the harness message-source map. */
|
|
2549
2549
|
const PLUGIN_MESSAGE_SOURCE_KIND = "dsh-chatgpt-subscription";
|
|
2550
|
-
function isRecord$
|
|
2550
|
+
function isRecord$23(value) {
|
|
2551
2551
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2552
2552
|
}
|
|
2553
2553
|
/** Read a message body's blocks, keeping every entry that carries a block tag. */
|
|
2554
2554
|
function readBlocks(raw) {
|
|
2555
2555
|
if (!Array.isArray(raw)) return [];
|
|
2556
|
-
return raw.filter((block) => isRecord$
|
|
2556
|
+
return raw.filter((block) => isRecord$23(block) && typeof block.type === "string");
|
|
2557
2557
|
}
|
|
2558
2558
|
/**
|
|
2559
2559
|
* Normalize one harness message list into {@link Message}.
|
|
@@ -2568,10 +2568,10 @@ function readBlocks(raw) {
|
|
|
2568
2568
|
function normalizeMessages(messages) {
|
|
2569
2569
|
const normalized = [];
|
|
2570
2570
|
for (const raw of messages ?? []) {
|
|
2571
|
-
if (!isRecord$
|
|
2571
|
+
if (!isRecord$23(raw)) continue;
|
|
2572
2572
|
const content = readBlocks(raw.content);
|
|
2573
2573
|
if (raw.role === "tool") {
|
|
2574
|
-
const source = isRecord$
|
|
2574
|
+
const source = isRecord$23(raw.source) ? raw.source : void 0;
|
|
2575
2575
|
const callId = String(raw.toolCallId ?? source?.callId ?? "");
|
|
2576
2576
|
normalized.push({
|
|
2577
2577
|
id: raw.id,
|
|
@@ -2593,7 +2593,7 @@ function normalizeMessages(messages) {
|
|
|
2593
2593
|
id: raw.id,
|
|
2594
2594
|
role: typeof raw.role === "string" ? raw.role : "user",
|
|
2595
2595
|
content,
|
|
2596
|
-
...isRecord$
|
|
2596
|
+
...isRecord$23(raw.source) ? { source: raw.source } : {}
|
|
2597
2597
|
});
|
|
2598
2598
|
}
|
|
2599
2599
|
return normalized;
|
|
@@ -6026,7 +6026,7 @@ function field(value, name) {
|
|
|
6026
6026
|
const candidate = value[name];
|
|
6027
6027
|
return typeof candidate === "string" && candidate !== "" ? candidate : null;
|
|
6028
6028
|
}
|
|
6029
|
-
function isRecord$
|
|
6029
|
+
function isRecord$22(value) {
|
|
6030
6030
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6031
6031
|
}
|
|
6032
6032
|
function readPreferencesUpdate(value, current) {
|
|
@@ -6060,7 +6060,7 @@ function readPreferencesUpdate(value, current) {
|
|
|
6060
6060
|
patch.searchProvider = value.searchProvider;
|
|
6061
6061
|
}
|
|
6062
6062
|
if ("contextWindowOverrides" in value) {
|
|
6063
|
-
if (!isRecord$
|
|
6063
|
+
if (!isRecord$22(value.contextWindowOverrides)) throw new PreferenceError("contextWindowOverrides must be an object.");
|
|
6064
6064
|
const overrides = {};
|
|
6065
6065
|
for (const [model, contextWindow] of Object.entries(value.contextWindowOverrides)) {
|
|
6066
6066
|
if (!isCodexModelId(model)) throw new PreferenceError("Unknown Codex model for a context window override.");
|
|
@@ -6864,7 +6864,7 @@ const schemaFields = /* @__PURE__ */ new Set([
|
|
|
6864
6864
|
"required",
|
|
6865
6865
|
"propertyOrdering"
|
|
6866
6866
|
]);
|
|
6867
|
-
function isRecord$
|
|
6867
|
+
function isRecord$21(value) {
|
|
6868
6868
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6869
6869
|
}
|
|
6870
6870
|
function mergeSchemas(left, right) {
|
|
@@ -6872,7 +6872,7 @@ function mergeSchemas(left, right) {
|
|
|
6872
6872
|
...left,
|
|
6873
6873
|
...right
|
|
6874
6874
|
};
|
|
6875
|
-
if (isRecord$
|
|
6875
|
+
if (isRecord$21(left.properties) && isRecord$21(right.properties)) merged.properties = {
|
|
6876
6876
|
...left.properties,
|
|
6877
6877
|
...right.properties
|
|
6878
6878
|
};
|
|
@@ -6880,7 +6880,7 @@ function mergeSchemas(left, right) {
|
|
|
6880
6880
|
return merged;
|
|
6881
6881
|
}
|
|
6882
6882
|
function toAntigravityToolSchema(schema) {
|
|
6883
|
-
if (!isRecord$
|
|
6883
|
+
if (!isRecord$21(schema)) return schema;
|
|
6884
6884
|
const root = schema;
|
|
6885
6885
|
function resolveReference(reference) {
|
|
6886
6886
|
let target = root;
|
|
@@ -6888,13 +6888,13 @@ function toAntigravityToolSchema(schema) {
|
|
|
6888
6888
|
const path = reference === "#" ? [] : reference.slice(2).split("/");
|
|
6889
6889
|
for (const segment of path) {
|
|
6890
6890
|
const key = segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
6891
|
-
target = isRecord$
|
|
6891
|
+
target = isRecord$21(target) && Object.hasOwn(target, key) ? target[key] : void 0;
|
|
6892
6892
|
}
|
|
6893
|
-
if (!isRecord$
|
|
6893
|
+
if (!isRecord$21(target)) throw new LlmError(`Antigravity tool schema reference was not found: ${reference}`, "PROVIDER_ERROR");
|
|
6894
6894
|
return target;
|
|
6895
6895
|
}
|
|
6896
6896
|
function convert(node, references) {
|
|
6897
|
-
if (!isRecord$
|
|
6897
|
+
if (!isRecord$21(node)) return {};
|
|
6898
6898
|
let inherited = {};
|
|
6899
6899
|
if (typeof node.$ref === "string") {
|
|
6900
6900
|
if (references.has(node.$ref)) throw new LlmError(`Antigravity tool schema contains a recursive reference: ${node.$ref}`, "PROVIDER_ERROR");
|
|
@@ -6903,8 +6903,8 @@ function toAntigravityToolSchema(schema) {
|
|
|
6903
6903
|
if (Array.isArray(node.allOf)) for (const branch of node.allOf) inherited = mergeSchemas(inherited, convert(branch, references));
|
|
6904
6904
|
const out = {};
|
|
6905
6905
|
for (const [key, value] of Object.entries(node)) if (schemaFields.has(key)) out[key] = value;
|
|
6906
|
-
if (isRecord$
|
|
6907
|
-
if (isRecord$
|
|
6906
|
+
if (isRecord$21(node.properties)) out.properties = Object.fromEntries(Object.entries(node.properties).map(([name, child]) => [name, convert(child, references)]));
|
|
6907
|
+
if (isRecord$21(node.items)) out.items = convert(node.items, references);
|
|
6908
6908
|
const alternatives = Array.isArray(node.anyOf) ? node.anyOf : node.oneOf;
|
|
6909
6909
|
if (Array.isArray(alternatives)) out.anyOf = alternatives.map((child) => convert(child, references));
|
|
6910
6910
|
if (Array.isArray(node.type)) {
|
|
@@ -6932,7 +6932,7 @@ let toolCallCounter = 0;
|
|
|
6932
6932
|
function sanitizeText$5(text) {
|
|
6933
6933
|
return text.replace(/\0/g, "");
|
|
6934
6934
|
}
|
|
6935
|
-
function isRecord$
|
|
6935
|
+
function isRecord$20(value) {
|
|
6936
6936
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6937
6937
|
}
|
|
6938
6938
|
function asString$13(value) {
|
|
@@ -6952,25 +6952,25 @@ function toolCallIdNeeded(modelId, runtimeModel) {
|
|
|
6952
6952
|
return modelId.startsWith("claude-") || modelId.startsWith("gpt-oss-") || runtimeModel.startsWith("claude-") || runtimeModel.startsWith("gpt-oss-");
|
|
6953
6953
|
}
|
|
6954
6954
|
function parseArguments(raw) {
|
|
6955
|
-
if (isRecord$
|
|
6955
|
+
if (isRecord$20(raw)) return raw;
|
|
6956
6956
|
if (raw === void 0 || raw === null || raw === "") return {};
|
|
6957
6957
|
const parsed = typeof raw === "string" ? safeJsonParse$5(raw) : raw;
|
|
6958
|
-
return isRecord$
|
|
6958
|
+
return isRecord$20(parsed) ? parsed : {};
|
|
6959
6959
|
}
|
|
6960
6960
|
const NO_RESOLVED_IMAGES$5 = /* @__PURE__ */ new Map();
|
|
6961
6961
|
function attachmentOf$5(block) {
|
|
6962
6962
|
const attachment = block.attachment;
|
|
6963
|
-
if (!isRecord$
|
|
6963
|
+
if (!isRecord$20(attachment)) return void 0;
|
|
6964
6964
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
6965
6965
|
}
|
|
6966
6966
|
function attachmentLabel$5(block) {
|
|
6967
|
-
const attachment = isRecord$
|
|
6967
|
+
const attachment = isRecord$20(block.attachment) ? block.attachment : void 0;
|
|
6968
6968
|
return asString$13(attachment?.name) || asString$13(attachment?.attachmentId);
|
|
6969
6969
|
}
|
|
6970
6970
|
function collectImageRefs$4(content, refs) {
|
|
6971
6971
|
if (!Array.isArray(content)) return;
|
|
6972
6972
|
for (const block of content) {
|
|
6973
|
-
if (!isRecord$
|
|
6973
|
+
if (!isRecord$20(block)) continue;
|
|
6974
6974
|
if (block.type === "image") {
|
|
6975
6975
|
const attachment = attachmentOf$5(block);
|
|
6976
6976
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -7014,7 +7014,7 @@ function requestImageBytes$4(block) {
|
|
|
7014
7014
|
function collectRequestImageBytes$4(content, lengths) {
|
|
7015
7015
|
if (!Array.isArray(content)) return;
|
|
7016
7016
|
for (const block of content) {
|
|
7017
|
-
if (!isRecord$
|
|
7017
|
+
if (!isRecord$20(block) || block.type !== "image") continue;
|
|
7018
7018
|
const bytes = requestImageBytes$4(block);
|
|
7019
7019
|
if (bytes !== void 0) lengths.push(bytes);
|
|
7020
7020
|
}
|
|
@@ -7049,7 +7049,7 @@ function offloadOldestRequestImages$4(options) {
|
|
|
7049
7049
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
7050
7050
|
let replaced = false;
|
|
7051
7051
|
const content = message.content.map((block) => {
|
|
7052
|
-
if (remaining.count === 0 || !isRecord$
|
|
7052
|
+
if (remaining.count === 0 || !isRecord$20(block) || block.type !== "image") return block;
|
|
7053
7053
|
if (requestImageBytes$4(block) === void 0) return block;
|
|
7054
7054
|
remaining.count -= 1;
|
|
7055
7055
|
replaced = true;
|
|
@@ -7113,7 +7113,7 @@ function unavailableImageText$5(block) {
|
|
|
7113
7113
|
}
|
|
7114
7114
|
function imageBlockToPart(block, images) {
|
|
7115
7115
|
let data = asString$13(block.data) || asString$13(block.base64);
|
|
7116
|
-
const source = isRecord$
|
|
7116
|
+
const source = isRecord$20(block.source) ? block.source : void 0;
|
|
7117
7117
|
if (!data && source) data = asString$13(source.data) || asString$13(source.base64);
|
|
7118
7118
|
let mimeType = asString$13(block.mimeType) || asString$13(block.mediaType) || (source ? asString$13(source.mimeType) || asString$13(source.mediaType) : void 0) || "image/png";
|
|
7119
7119
|
if (data?.startsWith("data:")) {
|
|
@@ -7138,8 +7138,8 @@ function contentToUserParts(content, images) {
|
|
|
7138
7138
|
if (typeof content === "string") return [{ text: sanitizeText$5(content) }];
|
|
7139
7139
|
if (!Array.isArray(content)) return [];
|
|
7140
7140
|
const parts = [];
|
|
7141
|
-
for (const block of content) if (isRecord$
|
|
7142
|
-
else if (isRecord$
|
|
7141
|
+
for (const block of content) if (isRecord$20(block) && block.type === "text" && typeof block.text === "string") parts.push({ text: sanitizeText$5(block.text) });
|
|
7142
|
+
else if (isRecord$20(block) && block.type === "image") {
|
|
7143
7143
|
const img = imageBlockToPart(block, images);
|
|
7144
7144
|
parts.push(img ?? { text: unavailableImageText$5(block) });
|
|
7145
7145
|
}
|
|
@@ -7154,7 +7154,7 @@ function toolResultImageParts(blocks, images) {
|
|
|
7154
7154
|
if (!Array.isArray(blocks)) return [];
|
|
7155
7155
|
const parts = [];
|
|
7156
7156
|
for (const block of blocks) {
|
|
7157
|
-
if (!isRecord$
|
|
7157
|
+
if (!isRecord$20(block)) continue;
|
|
7158
7158
|
if (block.type === "image") {
|
|
7159
7159
|
parts.push(imageBlockToPart(block, images) ?? { text: unavailableImageText$5(block) });
|
|
7160
7160
|
continue;
|
|
@@ -7166,7 +7166,7 @@ function toolResultImageParts(blocks, images) {
|
|
|
7166
7166
|
function toolResultText$5(blocks) {
|
|
7167
7167
|
if (!Array.isArray(blocks)) return "";
|
|
7168
7168
|
return blocks.map((block) => {
|
|
7169
|
-
if (!isRecord$
|
|
7169
|
+
if (!isRecord$20(block)) return "";
|
|
7170
7170
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText$5(block.text);
|
|
7171
7171
|
if (block.type === "tool-result") return toolResultText$5(block.content);
|
|
7172
7172
|
if (block.type === "image") {
|
|
@@ -7180,9 +7180,9 @@ function replayBlockFor$1(message, index) {
|
|
|
7180
7180
|
const source = message.source;
|
|
7181
7181
|
if (!source || source.kind !== "model" || source.provider !== "antigravity") return void 0;
|
|
7182
7182
|
const state = source.replayState;
|
|
7183
|
-
if (!isRecord$
|
|
7183
|
+
if (!isRecord$20(state)) return void 0;
|
|
7184
7184
|
if (Array.isArray(state.blocks)) return state.blocks[index];
|
|
7185
|
-
const resp = isRecord$
|
|
7185
|
+
const resp = isRecord$20(state.response) ? state.response : void 0;
|
|
7186
7186
|
if (resp) {
|
|
7187
7187
|
if (Array.isArray(resp.outputItems)) return resp.outputItems[index];
|
|
7188
7188
|
if (Array.isArray(resp.blocks)) return resp.blocks[index];
|
|
@@ -7205,9 +7205,9 @@ function assistantParts(message, model, runtimeModel, toolCalls) {
|
|
|
7205
7205
|
if (!Array.isArray(message.content)) return parts;
|
|
7206
7206
|
for (let index = 0; index < message.content.length; index++) {
|
|
7207
7207
|
const block = message.content[index];
|
|
7208
|
-
if (!isRecord$
|
|
7208
|
+
if (!isRecord$20(block)) continue;
|
|
7209
7209
|
const replay = replayBlockFor$1(message, index);
|
|
7210
|
-
const originalParts = Array.isArray(replay?.parts) ? replay.parts.filter(isRecord$
|
|
7210
|
+
const originalParts = Array.isArray(replay?.parts) ? replay.parts.filter(isRecord$20) : [];
|
|
7211
7211
|
if ((block.type === "text" || block.type === "reasoning") && originalParts.length > 0 && originalParts.every((part) => !part.functionCall) && originalParts.map((part) => asString$13(part.text) || "").join("") === sanitizeText$5(String(block.text || ""))) {
|
|
7212
7212
|
parts.push(...originalParts.map(replayPart));
|
|
7213
7213
|
continue;
|
|
@@ -7228,8 +7228,8 @@ function assistantParts(message, model, runtimeModel, toolCalls) {
|
|
|
7228
7228
|
} else if (block.type === "tool-call") {
|
|
7229
7229
|
const toolId = String(block.id || "");
|
|
7230
7230
|
const toolName = String(block.name || "");
|
|
7231
|
-
const originalCall = originalParts.find((part) => isRecord$
|
|
7232
|
-
const wireId = asString$13((isRecord$
|
|
7231
|
+
const originalCall = originalParts.find((part) => isRecord$20(part.functionCall));
|
|
7232
|
+
const wireId = asString$13((isRecord$20(originalCall?.functionCall) ? originalCall.functionCall : void 0)?.id) || (toolCallIdNeeded(model.id, runtimeModel) ? sanitizeToolCallId(toolId, toolName) : originalCall ? void 0 : toolId || void 0);
|
|
7233
7233
|
toolCalls.set(toolId, {
|
|
7234
7234
|
name: toolName,
|
|
7235
7235
|
id: wireId
|
|
@@ -7281,7 +7281,7 @@ function convertMessages(options, model, runtimeModel, images = NO_RESOLVED_IMAG
|
|
|
7281
7281
|
continue;
|
|
7282
7282
|
}
|
|
7283
7283
|
const content = Array.isArray(message.content) ? message.content : [];
|
|
7284
|
-
const userParts = contentToUserParts(content.filter((b) => !isRecord$
|
|
7284
|
+
const userParts = contentToUserParts(content.filter((b) => !isRecord$20(b) || b.type !== "tool-result"), images);
|
|
7285
7285
|
if (role === "system") {
|
|
7286
7286
|
if (userParts.length) contents.push({
|
|
7287
7287
|
role: GEMINI_ROLE.user,
|
|
@@ -7293,7 +7293,7 @@ function convertMessages(options, model, runtimeModel, images = NO_RESOLVED_IMAG
|
|
|
7293
7293
|
role: GEMINI_ROLE.user,
|
|
7294
7294
|
parts: userParts
|
|
7295
7295
|
});
|
|
7296
|
-
for (const b of content) if (isRecord$
|
|
7296
|
+
for (const b of content) if (isRecord$20(b) && b.type === "tool-result") pushToolResult(contents, b, toolCalls, model, runtimeModel, images);
|
|
7297
7297
|
}
|
|
7298
7298
|
return contents;
|
|
7299
7299
|
}
|
|
@@ -7416,7 +7416,7 @@ const USAGE_FIELDS = [
|
|
|
7416
7416
|
"totalTokenCount"
|
|
7417
7417
|
];
|
|
7418
7418
|
function collectUsage(value, state) {
|
|
7419
|
-
if (!isRecord$
|
|
7419
|
+
if (!isRecord$20(value)) return;
|
|
7420
7420
|
for (const key of USAGE_FIELDS) {
|
|
7421
7421
|
const count = value[key];
|
|
7422
7422
|
if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) continue;
|
|
@@ -7446,15 +7446,15 @@ function processStreamLine$2(line, state) {
|
|
|
7446
7446
|
}
|
|
7447
7447
|
if (!json) return [];
|
|
7448
7448
|
const chunk = safeJsonParse$5(json);
|
|
7449
|
-
if (!isRecord$
|
|
7450
|
-
const responseData = isRecord$
|
|
7449
|
+
if (!isRecord$20(chunk)) return [];
|
|
7450
|
+
const responseData = isRecord$20(chunk.response) ? chunk.response : chunk;
|
|
7451
7451
|
const candidates = Array.isArray(responseData.candidates) ? responseData.candidates : [];
|
|
7452
|
-
const candidate = isRecord$
|
|
7453
|
-
const content = isRecord$
|
|
7452
|
+
const candidate = isRecord$20(candidates[0]) ? candidates[0] : void 0;
|
|
7453
|
+
const content = isRecord$20(candidate?.content) ? candidate.content : void 0;
|
|
7454
7454
|
const parts = Array.isArray(content?.parts) ? content.parts : [];
|
|
7455
7455
|
const out = [];
|
|
7456
7456
|
for (const part of parts) {
|
|
7457
|
-
if (!isRecord$
|
|
7457
|
+
if (!isRecord$20(part)) continue;
|
|
7458
7458
|
if (typeof part.text === "string" && part.text !== "") {
|
|
7459
7459
|
const isThinking = Boolean(part.thought);
|
|
7460
7460
|
const blockType = isThinking ? "reasoning" : "text";
|
|
@@ -7486,7 +7486,7 @@ function processStreamLine$2(line, state) {
|
|
|
7486
7486
|
index: state.currentBlock.index,
|
|
7487
7487
|
text: delta
|
|
7488
7488
|
});
|
|
7489
|
-
} else if (!isRecord$
|
|
7489
|
+
} else if (!isRecord$20(part.functionCall) && thoughtSignature(part)) {
|
|
7490
7490
|
if (state.replayBlocks.length === 0) {
|
|
7491
7491
|
const type = part.thought ? "reasoning" : "text";
|
|
7492
7492
|
state.blocks.push({
|
|
@@ -7510,12 +7510,12 @@ function processStreamLine$2(line, state) {
|
|
|
7510
7510
|
}
|
|
7511
7511
|
state.replayBlocks[state.replayBlocks.length - 1].parts.push(replayPart(part));
|
|
7512
7512
|
}
|
|
7513
|
-
if (isRecord$
|
|
7513
|
+
if (isRecord$20(part.functionCall)) {
|
|
7514
7514
|
out.push(...closeCurrentBlock(state));
|
|
7515
7515
|
const fc = part.functionCall;
|
|
7516
7516
|
const toolName = asString$13(fc.name) || "";
|
|
7517
7517
|
const toolId = asString$13(fc.id) || sanitizeToolCallId("", toolName);
|
|
7518
|
-
const argsText = JSON.stringify(isRecord$
|
|
7518
|
+
const argsText = JSON.stringify(isRecord$20(fc.args) ? fc.args : {});
|
|
7519
7519
|
const index = state.blocks.length;
|
|
7520
7520
|
const block = {
|
|
7521
7521
|
type: "tool-call",
|
|
@@ -9656,11 +9656,11 @@ function commandCodeHeaders(apiKey, extra = {}) {
|
|
|
9656
9656
|
function timeoutSignal$3(signal, ms) {
|
|
9657
9657
|
return signal ? AbortSignal.any([signal, AbortSignal.timeout(ms)]) : AbortSignal.timeout(ms);
|
|
9658
9658
|
}
|
|
9659
|
-
function isRecord$
|
|
9659
|
+
function isRecord$19(value) {
|
|
9660
9660
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9661
9661
|
}
|
|
9662
9662
|
function asRecord$9(value) {
|
|
9663
|
-
return isRecord$
|
|
9663
|
+
return isRecord$19(value) ? value : void 0;
|
|
9664
9664
|
}
|
|
9665
9665
|
function asString$12(value) {
|
|
9666
9666
|
if (typeof value === "string" && value.trim() !== "") return value;
|
|
@@ -9695,7 +9695,7 @@ function deepValue(value, keys, depth = 0) {
|
|
|
9695
9695
|
}
|
|
9696
9696
|
return;
|
|
9697
9697
|
}
|
|
9698
|
-
if (!isRecord$
|
|
9698
|
+
if (!isRecord$19(value)) return void 0;
|
|
9699
9699
|
for (const key of keys) if (value[key] !== void 0 && value[key] !== null) return value[key];
|
|
9700
9700
|
for (const nested of Object.values(value)) {
|
|
9701
9701
|
const hit = deepValue(nested, keys, depth + 1);
|
|
@@ -9709,7 +9709,7 @@ function collectRecords(value, keys, depth = 0, out = []) {
|
|
|
9709
9709
|
for (const entry of value) collectRecords(entry, keys, depth + 1, out);
|
|
9710
9710
|
return out;
|
|
9711
9711
|
}
|
|
9712
|
-
if (!isRecord$
|
|
9712
|
+
if (!isRecord$19(value)) return out;
|
|
9713
9713
|
if (keys.some((key) => value[key] !== void 0)) out.push(value);
|
|
9714
9714
|
for (const nested of Object.values(value)) collectRecords(nested, keys, depth + 1, out);
|
|
9715
9715
|
return out;
|
|
@@ -10466,7 +10466,7 @@ function buildModelOptions$2(catalog, enabledModelIds, overrides) {
|
|
|
10466
10466
|
*
|
|
10467
10467
|
* https://commandcode.ai/blog/command-code-provider-api
|
|
10468
10468
|
*/
|
|
10469
|
-
function isRecord$
|
|
10469
|
+
function isRecord$18(value) {
|
|
10470
10470
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10471
10471
|
}
|
|
10472
10472
|
function asString$11(value) {
|
|
@@ -10506,17 +10506,17 @@ const SUPPORTED_IMAGE_MEDIA_TYPES$4 = /* @__PURE__ */ new Set([
|
|
|
10506
10506
|
]);
|
|
10507
10507
|
function attachmentOf$4(block) {
|
|
10508
10508
|
const attachment = block.attachment;
|
|
10509
|
-
if (!isRecord$
|
|
10509
|
+
if (!isRecord$18(attachment)) return void 0;
|
|
10510
10510
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
10511
10511
|
}
|
|
10512
10512
|
function attachmentLabel$4(block) {
|
|
10513
|
-
const attachment = isRecord$
|
|
10513
|
+
const attachment = isRecord$18(block.attachment) ? block.attachment : void 0;
|
|
10514
10514
|
return asString$11(attachment?.name) || asString$11(attachment?.attachmentId);
|
|
10515
10515
|
}
|
|
10516
10516
|
function collectImageRefs$3(content, refs) {
|
|
10517
10517
|
if (!Array.isArray(content)) return;
|
|
10518
10518
|
for (const block of content) {
|
|
10519
|
-
if (!isRecord$
|
|
10519
|
+
if (!isRecord$18(block)) continue;
|
|
10520
10520
|
if (block.type === "image") {
|
|
10521
10521
|
const attachment = attachmentOf$4(block);
|
|
10522
10522
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -10537,7 +10537,7 @@ function requestImageBytes$3(block) {
|
|
|
10537
10537
|
function collectRequestImageBytes$3(content, lengths) {
|
|
10538
10538
|
if (!Array.isArray(content)) return;
|
|
10539
10539
|
for (const block of content) {
|
|
10540
|
-
if (!isRecord$
|
|
10540
|
+
if (!isRecord$18(block) || block.type !== "image") continue;
|
|
10541
10541
|
const bytes = requestImageBytes$3(block);
|
|
10542
10542
|
if (bytes !== void 0) lengths.push(bytes);
|
|
10543
10543
|
}
|
|
@@ -10564,7 +10564,7 @@ function offloadOldestRequestImages$3(options) {
|
|
|
10564
10564
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
10565
10565
|
let replaced = false;
|
|
10566
10566
|
const content = message.content.map((block) => {
|
|
10567
|
-
if (remaining.count === 0 || !isRecord$
|
|
10567
|
+
if (remaining.count === 0 || !isRecord$18(block) || block.type !== "image") return block;
|
|
10568
10568
|
if (requestImageBytes$3(block) === void 0) return block;
|
|
10569
10569
|
remaining.count -= 1;
|
|
10570
10570
|
replaced = true;
|
|
@@ -10618,7 +10618,7 @@ function unavailableImageText$4(block) {
|
|
|
10618
10618
|
}
|
|
10619
10619
|
function imageBlockToInline$3(block, images) {
|
|
10620
10620
|
let data = asString$11(block.data) || asString$11(block.base64);
|
|
10621
|
-
const source = isRecord$
|
|
10621
|
+
const source = isRecord$18(block.source) ? block.source : void 0;
|
|
10622
10622
|
if (!data && source) data = asString$11(source.data) || asString$11(source.base64);
|
|
10623
10623
|
let mediaType = asString$11(block.mimeType) || asString$11(block.mediaType) || (source ? asString$11(source.mimeType) || asString$11(source.mediaType) : void 0) || "image/png";
|
|
10624
10624
|
if (data?.startsWith("data:")) {
|
|
@@ -10644,7 +10644,7 @@ function textOf$4(content) {
|
|
|
10644
10644
|
if (!Array.isArray(content)) return "";
|
|
10645
10645
|
const parts = [];
|
|
10646
10646
|
for (const block of content) {
|
|
10647
|
-
if (!isRecord$
|
|
10647
|
+
if (!isRecord$18(block)) continue;
|
|
10648
10648
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText$4(block.text));
|
|
10649
10649
|
else if (block.type === "tool-result") parts.push(textOf$4(block.content));
|
|
10650
10650
|
}
|
|
@@ -10653,7 +10653,7 @@ function textOf$4(content) {
|
|
|
10653
10653
|
function toolResultText$4(blocks) {
|
|
10654
10654
|
if (!Array.isArray(blocks)) return "";
|
|
10655
10655
|
return blocks.map((block) => {
|
|
10656
|
-
if (!isRecord$
|
|
10656
|
+
if (!isRecord$18(block)) return "";
|
|
10657
10657
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText$4(block.text);
|
|
10658
10658
|
if (block.type === "tool-result") return toolResultText$4(block.content);
|
|
10659
10659
|
if (block.type === "image") return `[image: ${attachmentLabel$4(block) ?? "attached image"}]`;
|
|
@@ -10671,7 +10671,7 @@ function toolResultBlocks$2(blocks, images) {
|
|
|
10671
10671
|
const out = [];
|
|
10672
10672
|
let hasImage = false;
|
|
10673
10673
|
for (const block of blocks) {
|
|
10674
|
-
if (!isRecord$
|
|
10674
|
+
if (!isRecord$18(block)) continue;
|
|
10675
10675
|
if (block.type === "text" && typeof block.text === "string") {
|
|
10676
10676
|
out.push({
|
|
10677
10677
|
type: "text",
|
|
@@ -10720,7 +10720,7 @@ function toolResultImageBlocks$2(blocks, images) {
|
|
|
10720
10720
|
if (!Array.isArray(blocks)) return [];
|
|
10721
10721
|
const out = [];
|
|
10722
10722
|
for (const block of blocks) {
|
|
10723
|
-
if (!isRecord$
|
|
10723
|
+
if (!isRecord$18(block)) continue;
|
|
10724
10724
|
if (block.type === "image") {
|
|
10725
10725
|
const inline = imageBlockToInline$3(block, images);
|
|
10726
10726
|
if (inline && SUPPORTED_IMAGE_MEDIA_TYPES$4.has(inline.mediaType)) out.push({
|
|
@@ -10764,7 +10764,7 @@ function nonSystemMessages$4(options) {
|
|
|
10764
10764
|
}
|
|
10765
10765
|
/** Drop the JSON-Schema keywords provider gateways reject or ignore. */
|
|
10766
10766
|
function stripMetaSchema$2(schema) {
|
|
10767
|
-
if (!isRecord$
|
|
10767
|
+
if (!isRecord$18(schema)) return {
|
|
10768
10768
|
type: "object",
|
|
10769
10769
|
properties: {}
|
|
10770
10770
|
};
|
|
@@ -10781,7 +10781,7 @@ function openAIUserContent$2(message, images) {
|
|
|
10781
10781
|
const parts = [];
|
|
10782
10782
|
let hasImage = false;
|
|
10783
10783
|
for (const block of message.content) {
|
|
10784
|
-
if (!isRecord$
|
|
10784
|
+
if (!isRecord$18(block)) continue;
|
|
10785
10785
|
if (block.type === "text" && typeof block.text === "string") {
|
|
10786
10786
|
const text = sanitizeText$4(block.text);
|
|
10787
10787
|
if (text !== "") parts.push({
|
|
@@ -10809,7 +10809,7 @@ function openAIAssistantContent$2(message) {
|
|
|
10809
10809
|
const textParts = [];
|
|
10810
10810
|
const toolCalls = [];
|
|
10811
10811
|
for (const block of message.content) {
|
|
10812
|
-
if (!isRecord$
|
|
10812
|
+
if (!isRecord$18(block)) continue;
|
|
10813
10813
|
if (block.type === "text" && typeof block.text === "string") textParts.push(sanitizeText$4(block.text));
|
|
10814
10814
|
else if (block.type === "tool-call" && typeof block.name === "string") toolCalls.push({
|
|
10815
10815
|
id: typeof block.id === "string" && block.id !== "" ? block.id : `call_${toolCalls.length}`,
|
|
@@ -10841,7 +10841,7 @@ function buildOpenAIRequest$1(options, images = NO_RESOLVED_IMAGES$4) {
|
|
|
10841
10841
|
while (index < conversation.length && isToolResultMessage$4(conversation[index])) {
|
|
10842
10842
|
const current = conversation[index];
|
|
10843
10843
|
const block = current.content[0];
|
|
10844
|
-
const callId = isRecord$
|
|
10844
|
+
const callId = isRecord$18(block) && typeof block.toolCallId === "string" ? block.toolCallId : "";
|
|
10845
10845
|
messages.push({
|
|
10846
10846
|
role: "tool",
|
|
10847
10847
|
tool_call_id: callId,
|
|
@@ -10902,7 +10902,7 @@ function anthropicUserContent$2(message, images) {
|
|
|
10902
10902
|
if (!Array.isArray(message.content)) return [];
|
|
10903
10903
|
const blocks = [];
|
|
10904
10904
|
for (const block of message.content) {
|
|
10905
|
-
if (!isRecord$
|
|
10905
|
+
if (!isRecord$18(block)) continue;
|
|
10906
10906
|
if (block.type === "text" && typeof block.text === "string") {
|
|
10907
10907
|
const text = sanitizeText$4(block.text);
|
|
10908
10908
|
if (text !== "") blocks.push({
|
|
@@ -10939,7 +10939,7 @@ function anthropicUserContent$2(message, images) {
|
|
|
10939
10939
|
function anthropicAssistantContent$2(message) {
|
|
10940
10940
|
const blocks = [];
|
|
10941
10941
|
for (const block of message.content) {
|
|
10942
|
-
if (!isRecord$
|
|
10942
|
+
if (!isRecord$18(block)) continue;
|
|
10943
10943
|
if (block.type === "text" && typeof block.text === "string") {
|
|
10944
10944
|
const text = sanitizeText$4(block.text);
|
|
10945
10945
|
if (text !== "") blocks.push({
|
|
@@ -10952,7 +10952,7 @@ function anthropicAssistantContent$2(message) {
|
|
|
10952
10952
|
type: "tool_use",
|
|
10953
10953
|
id: typeof block.id === "string" && block.id !== "" ? block.id : `toolu_${blocks.length}`,
|
|
10954
10954
|
name: block.name,
|
|
10955
|
-
input: isRecord$
|
|
10955
|
+
input: isRecord$18(parsed) ? parsed : {}
|
|
10956
10956
|
});
|
|
10957
10957
|
}
|
|
10958
10958
|
}
|
|
@@ -11116,22 +11116,22 @@ function processOpenAIStreamLine$1(line, state) {
|
|
|
11116
11116
|
}
|
|
11117
11117
|
if (payload === "") return [];
|
|
11118
11118
|
const chunk = safeJsonParse$4(payload);
|
|
11119
|
-
if (!isRecord$
|
|
11119
|
+
if (!isRecord$18(chunk)) return [];
|
|
11120
11120
|
const out = [];
|
|
11121
|
-
const usage = isRecord$
|
|
11121
|
+
const usage = isRecord$18(chunk.usage) ? chunk.usage : void 0;
|
|
11122
11122
|
if (usage) {
|
|
11123
11123
|
state.sawUsage = true;
|
|
11124
11124
|
const prompt = numberOr$5(usage.prompt_tokens, 0);
|
|
11125
|
-
const details = isRecord$
|
|
11125
|
+
const details = isRecord$18(usage.prompt_tokens_details) ? usage.prompt_tokens_details : void 0;
|
|
11126
11126
|
const cached = details ? numberOr$5(details.cached_tokens, 0) : 0;
|
|
11127
11127
|
state.inputTokens = Math.max(0, prompt - cached);
|
|
11128
11128
|
state.cacheReadTokens = cached;
|
|
11129
11129
|
state.outputTokens = numberOr$5(usage.completion_tokens, state.outputTokens);
|
|
11130
|
-
if (isRecord$
|
|
11130
|
+
if (isRecord$18(usage.completion_tokens_details)) state.reasoningTokens = numberOr$5(usage.completion_tokens_details.reasoning_tokens, state.reasoningTokens);
|
|
11131
11131
|
}
|
|
11132
11132
|
const choices = Array.isArray(chunk.choices) ? chunk.choices : [];
|
|
11133
|
-
const choice = isRecord$
|
|
11134
|
-
const delta = isRecord$
|
|
11133
|
+
const choice = isRecord$18(choices[0]) ? choices[0] : void 0;
|
|
11134
|
+
const delta = isRecord$18(choice?.delta) ? choice.delta : void 0;
|
|
11135
11135
|
if (delta) {
|
|
11136
11136
|
const reasoning = asString$11(delta.reasoning_content) ?? asString$11(delta.reasoning);
|
|
11137
11137
|
if (reasoning !== void 0 && reasoning !== "") {
|
|
@@ -11159,7 +11159,7 @@ function processOpenAIStreamLine$1(line, state) {
|
|
|
11159
11159
|
}
|
|
11160
11160
|
const toolDeltas = Array.isArray(delta.tool_calls) ? delta.tool_calls : [];
|
|
11161
11161
|
for (const entry of toolDeltas) {
|
|
11162
|
-
if (!isRecord$
|
|
11162
|
+
if (!isRecord$18(entry)) continue;
|
|
11163
11163
|
out.push(...applyOpenAIToolDelta$1(entry, state));
|
|
11164
11164
|
}
|
|
11165
11165
|
}
|
|
@@ -11173,7 +11173,7 @@ function processOpenAIStreamLine$1(line, state) {
|
|
|
11173
11173
|
}
|
|
11174
11174
|
function applyOpenAIToolDelta$1(entry, state) {
|
|
11175
11175
|
const wireIndex = typeof entry.index === "number" ? entry.index : 0;
|
|
11176
|
-
const fn = isRecord$
|
|
11176
|
+
const fn = isRecord$18(entry.function) ? entry.function : {};
|
|
11177
11177
|
const out = [];
|
|
11178
11178
|
let call = state.toolCalls.get(wireIndex);
|
|
11179
11179
|
if (call === void 0) {
|
|
@@ -11231,12 +11231,12 @@ function processAnthropicStreamLine$1(line, state) {
|
|
|
11231
11231
|
const payload = trimmed.slice(5).trim();
|
|
11232
11232
|
if (payload === "" || payload === "[DONE]") return [];
|
|
11233
11233
|
const event = safeJsonParse$4(payload);
|
|
11234
|
-
if (!isRecord$
|
|
11234
|
+
if (!isRecord$18(event)) return [];
|
|
11235
11235
|
const type = asString$11(event.type);
|
|
11236
11236
|
const out = [];
|
|
11237
11237
|
if (type === "message_start") {
|
|
11238
|
-
const message = isRecord$
|
|
11239
|
-
const usage = message && isRecord$
|
|
11238
|
+
const message = isRecord$18(event.message) ? event.message : void 0;
|
|
11239
|
+
const usage = message && isRecord$18(message.usage) ? message.usage : void 0;
|
|
11240
11240
|
if (usage) {
|
|
11241
11241
|
state.sawUsage = true;
|
|
11242
11242
|
state.inputTokens = numberOr$5(usage.input_tokens, 0);
|
|
@@ -11250,7 +11250,7 @@ function processAnthropicStreamLine$1(line, state) {
|
|
|
11250
11250
|
}
|
|
11251
11251
|
if (type === "content_block_start") {
|
|
11252
11252
|
const contentIndex = numberOr$5(event.index, 0);
|
|
11253
|
-
const block = isRecord$
|
|
11253
|
+
const block = isRecord$18(event.content_block) ? event.content_block : {};
|
|
11254
11254
|
const blockType = asString$11(block.type);
|
|
11255
11255
|
out.push(...closeCurrent$3(state));
|
|
11256
11256
|
if (blockType === "tool_use") {
|
|
@@ -11300,7 +11300,7 @@ function processAnthropicStreamLine$1(line, state) {
|
|
|
11300
11300
|
}
|
|
11301
11301
|
if (type === "content_block_delta") {
|
|
11302
11302
|
const contentIndex = numberOr$5(event.index, 0);
|
|
11303
|
-
const delta = isRecord$
|
|
11303
|
+
const delta = isRecord$18(event.delta) ? event.delta : {};
|
|
11304
11304
|
const deltaType = asString$11(delta.type);
|
|
11305
11305
|
if (deltaType === "input_json_delta") {
|
|
11306
11306
|
const pending = state.toolCalls.get(contentIndex);
|
|
@@ -11373,10 +11373,10 @@ function processAnthropicStreamLine$1(line, state) {
|
|
|
11373
11373
|
return out;
|
|
11374
11374
|
}
|
|
11375
11375
|
if (type === "message_delta") {
|
|
11376
|
-
const delta = isRecord$
|
|
11376
|
+
const delta = isRecord$18(event.delta) ? event.delta : void 0;
|
|
11377
11377
|
const stop = delta ? asString$11(delta.stop_reason) : void 0;
|
|
11378
11378
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
11379
|
-
const usage = isRecord$
|
|
11379
|
+
const usage = isRecord$18(event.usage) ? event.usage : void 0;
|
|
11380
11380
|
if (usage) {
|
|
11381
11381
|
state.sawUsage = true;
|
|
11382
11382
|
state.outputTokens = numberOr$5(usage.output_tokens, state.outputTokens);
|
|
@@ -11387,7 +11387,7 @@ function processAnthropicStreamLine$1(line, state) {
|
|
|
11387
11387
|
state.done = true;
|
|
11388
11388
|
return closeStream$3(state);
|
|
11389
11389
|
}
|
|
11390
|
-
if (type === "error") throw new LlmError$1(`Command Code stream error: ${asString$11((isRecord$
|
|
11390
|
+
if (type === "error") throw new LlmError$1(`Command Code stream error: ${asString$11((isRecord$18(event.error) ? event.error : {}).message) ?? "unknown error"}`, "PROVIDER_ERROR");
|
|
11391
11391
|
return out;
|
|
11392
11392
|
}
|
|
11393
11393
|
function tokenUsage$4(state) {
|
|
@@ -13014,7 +13014,7 @@ function optionalString$4(record, key) {
|
|
|
13014
13014
|
if (typeof value !== "string") throw new Error("Kimi Code credential payload is invalid");
|
|
13015
13015
|
return value;
|
|
13016
13016
|
}
|
|
13017
|
-
function isRegion$
|
|
13017
|
+
function isRegion$4(value) {
|
|
13018
13018
|
return value === "mainland-cn" || value === "global";
|
|
13019
13019
|
}
|
|
13020
13020
|
function parseKimiCodeCredentials(value) {
|
|
@@ -13026,7 +13026,7 @@ function parseKimiCodeCredentials(value) {
|
|
|
13026
13026
|
if (typeof refreshToken !== "string" || refreshToken === "") throw new Error("Kimi Code credential is missing its refresh token");
|
|
13027
13027
|
const expiresAt = record.expiresAt;
|
|
13028
13028
|
if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt)) throw new Error("Kimi Code credential expiry is invalid");
|
|
13029
|
-
const region = isRegion$
|
|
13029
|
+
const region = isRegion$4(record.region) ? record.region : "mainland-cn";
|
|
13030
13030
|
const credentials = {
|
|
13031
13031
|
accessToken,
|
|
13032
13032
|
refreshToken,
|
|
@@ -13228,7 +13228,7 @@ async function resolveRegion(env = process.env) {
|
|
|
13228
13228
|
}
|
|
13229
13229
|
try {
|
|
13230
13230
|
const marker = (await fsPromises.readFile(regionMarkerPath(), "utf8")).trim();
|
|
13231
|
-
if (isRegion$
|
|
13231
|
+
if (isRegion$4(marker)) return marker;
|
|
13232
13232
|
} catch {}
|
|
13233
13233
|
return "mainland-cn";
|
|
13234
13234
|
}
|
|
@@ -13824,11 +13824,11 @@ const MODELS_PATH$1 = "/models";
|
|
|
13824
13824
|
const USAGES_PATH = "/usages";
|
|
13825
13825
|
/** The service reports money in fixed-point units of 1e-6 cents. */
|
|
13826
13826
|
const FIXED_POINT_CENTS = 1e6;
|
|
13827
|
-
function isRecord$
|
|
13827
|
+
function isRecord$17(value) {
|
|
13828
13828
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13829
13829
|
}
|
|
13830
13830
|
function asRecord$7(value) {
|
|
13831
|
-
return isRecord$
|
|
13831
|
+
return isRecord$17(value) ? value : void 0;
|
|
13832
13832
|
}
|
|
13833
13833
|
function asString$10(value) {
|
|
13834
13834
|
if (typeof value === "string" && value.trim() !== "") return value;
|
|
@@ -14719,7 +14719,7 @@ function videoBlockLabel(block) {
|
|
|
14719
14719
|
*
|
|
14720
14720
|
* See https://www.kimi.com/code/docs/en/kimi-code/error-reference.html
|
|
14721
14721
|
*/
|
|
14722
|
-
function isRecord$
|
|
14722
|
+
function isRecord$16(value) {
|
|
14723
14723
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14724
14724
|
}
|
|
14725
14725
|
function asString$9(value) {
|
|
@@ -14876,17 +14876,17 @@ const SUPPORTED_IMAGE_MEDIA_TYPES$3 = /* @__PURE__ */ new Set([
|
|
|
14876
14876
|
]);
|
|
14877
14877
|
function attachmentOf$3(block) {
|
|
14878
14878
|
const attachment = block.attachment;
|
|
14879
|
-
if (!isRecord$
|
|
14879
|
+
if (!isRecord$16(attachment)) return void 0;
|
|
14880
14880
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
14881
14881
|
}
|
|
14882
14882
|
function attachmentLabel$3(block) {
|
|
14883
|
-
const attachment = isRecord$
|
|
14883
|
+
const attachment = isRecord$16(block.attachment) ? block.attachment : void 0;
|
|
14884
14884
|
return asString$9(attachment?.name) || asString$9(attachment?.attachmentId);
|
|
14885
14885
|
}
|
|
14886
14886
|
function collectImageRefs$2(content, refs) {
|
|
14887
14887
|
if (!Array.isArray(content)) return;
|
|
14888
14888
|
for (const block of content) {
|
|
14889
|
-
if (!isRecord$
|
|
14889
|
+
if (!isRecord$16(block)) continue;
|
|
14890
14890
|
if (block.type === "image") {
|
|
14891
14891
|
const attachment = attachmentOf$3(block);
|
|
14892
14892
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -14907,7 +14907,7 @@ function requestImageBytes$2(block) {
|
|
|
14907
14907
|
function collectRequestImageBytes$2(content, lengths) {
|
|
14908
14908
|
if (!Array.isArray(content)) return;
|
|
14909
14909
|
for (const block of content) {
|
|
14910
|
-
if (!isRecord$
|
|
14910
|
+
if (!isRecord$16(block) || block.type !== "image") continue;
|
|
14911
14911
|
const bytes = requestImageBytes$2(block);
|
|
14912
14912
|
if (bytes !== void 0) lengths.push(bytes);
|
|
14913
14913
|
}
|
|
@@ -14934,7 +14934,7 @@ function offloadOldestRequestImages$2(options) {
|
|
|
14934
14934
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
14935
14935
|
let replaced = false;
|
|
14936
14936
|
const content = message.content.map((block) => {
|
|
14937
|
-
if (remaining.count === 0 || !isRecord$
|
|
14937
|
+
if (remaining.count === 0 || !isRecord$16(block) || block.type !== "image") return block;
|
|
14938
14938
|
if (requestImageBytes$2(block) === void 0) return block;
|
|
14939
14939
|
remaining.count -= 1;
|
|
14940
14940
|
replaced = true;
|
|
@@ -14985,14 +14985,14 @@ async function resolveRequestImages$2(options, attachments, signal) {
|
|
|
14985
14985
|
const NO_RESOLVED_VIDEOS = /* @__PURE__ */ new Map();
|
|
14986
14986
|
function videoAttachmentOf(block) {
|
|
14987
14987
|
const attachment = block.attachment;
|
|
14988
|
-
if (!isRecord$
|
|
14988
|
+
if (!isRecord$16(attachment)) return void 0;
|
|
14989
14989
|
if (typeof attachment.attachmentId !== "string") return void 0;
|
|
14990
14990
|
return attachment;
|
|
14991
14991
|
}
|
|
14992
14992
|
function collectVideoRefs(content, refs) {
|
|
14993
14993
|
if (!Array.isArray(content)) return;
|
|
14994
14994
|
for (const block of content) {
|
|
14995
|
-
if (!isRecord$
|
|
14995
|
+
if (!isRecord$16(block) || block.type !== "video") continue;
|
|
14996
14996
|
const attachment = videoAttachmentOf(block);
|
|
14997
14997
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
14998
14998
|
}
|
|
@@ -15007,7 +15007,7 @@ function requestVideoBytes(block) {
|
|
|
15007
15007
|
function collectRequestVideoBytes(content, lengths) {
|
|
15008
15008
|
if (!Array.isArray(content)) return;
|
|
15009
15009
|
for (const block of content) {
|
|
15010
|
-
if (!isRecord$
|
|
15010
|
+
if (!isRecord$16(block) || block.type !== "video") continue;
|
|
15011
15011
|
const bytes = requestVideoBytes(block);
|
|
15012
15012
|
if (bytes !== void 0) lengths.push(bytes);
|
|
15013
15013
|
}
|
|
@@ -15037,7 +15037,7 @@ function offloadOldestRequestVideos(options) {
|
|
|
15037
15037
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
15038
15038
|
let replaced = false;
|
|
15039
15039
|
const content = message.content.map((block) => {
|
|
15040
|
-
if (remaining.count === 0 || !isRecord$
|
|
15040
|
+
if (remaining.count === 0 || !isRecord$16(block) || block.type !== "video") return block;
|
|
15041
15041
|
if (requestVideoBytes(block) === void 0) return block;
|
|
15042
15042
|
remaining.count -= 1;
|
|
15043
15043
|
replaced = true;
|
|
@@ -15087,7 +15087,7 @@ async function resolveRequestVideos(options, attachments, signal) {
|
|
|
15087
15087
|
}
|
|
15088
15088
|
/** True when the request carries any video occurrence at all. */
|
|
15089
15089
|
function requestHasVideo(options) {
|
|
15090
|
-
return options.messages.some((message) => Array.isArray(message.content) && message.content.some((block) => isRecord$
|
|
15090
|
+
return options.messages.some((message) => Array.isArray(message.content) && message.content.some((block) => isRecord$16(block) && block.type === "video"));
|
|
15091
15091
|
}
|
|
15092
15092
|
/**
|
|
15093
15093
|
* Resolve one video block for the wire, or explain why it cannot be sent.
|
|
@@ -15127,7 +15127,7 @@ function unavailableImageText$3(block) {
|
|
|
15127
15127
|
}
|
|
15128
15128
|
function imageBlockToInline$2(block, images) {
|
|
15129
15129
|
let data = asString$9(block.data) || asString$9(block.base64);
|
|
15130
|
-
const source = isRecord$
|
|
15130
|
+
const source = isRecord$16(block.source) ? block.source : void 0;
|
|
15131
15131
|
if (!data && source) data = asString$9(source.data) || asString$9(source.base64);
|
|
15132
15132
|
let mediaType = asString$9(block.mimeType) || asString$9(block.mediaType) || (source ? asString$9(source.mimeType) || asString$9(source.mediaType) : void 0) || "image/png";
|
|
15133
15133
|
if (data?.startsWith("data:")) {
|
|
@@ -15153,7 +15153,7 @@ function textOf$3(content) {
|
|
|
15153
15153
|
if (!Array.isArray(content)) return "";
|
|
15154
15154
|
const parts = [];
|
|
15155
15155
|
for (const block of content) {
|
|
15156
|
-
if (!isRecord$
|
|
15156
|
+
if (!isRecord$16(block)) continue;
|
|
15157
15157
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText$3(block.text));
|
|
15158
15158
|
else if (block.type === "tool-result") parts.push(textOf$3(block.content));
|
|
15159
15159
|
}
|
|
@@ -15162,7 +15162,7 @@ function textOf$3(content) {
|
|
|
15162
15162
|
function toolResultText$3(blocks) {
|
|
15163
15163
|
if (!Array.isArray(blocks)) return "";
|
|
15164
15164
|
return blocks.map((block) => {
|
|
15165
|
-
if (!isRecord$
|
|
15165
|
+
if (!isRecord$16(block)) return "";
|
|
15166
15166
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText$3(block.text);
|
|
15167
15167
|
if (block.type === "tool-result") return toolResultText$3(block.content);
|
|
15168
15168
|
if (block.type === "image") return `[image: ${attachmentLabel$3(block) ?? "attached image"}]`;
|
|
@@ -15180,7 +15180,7 @@ function toolResultBlocks$1(blocks, images) {
|
|
|
15180
15180
|
const out = [];
|
|
15181
15181
|
let hasImage = false;
|
|
15182
15182
|
for (const block of blocks) {
|
|
15183
|
-
if (!isRecord$
|
|
15183
|
+
if (!isRecord$16(block)) continue;
|
|
15184
15184
|
if (block.type === "text" && typeof block.text === "string") {
|
|
15185
15185
|
out.push({
|
|
15186
15186
|
type: "text",
|
|
@@ -15229,7 +15229,7 @@ function toolResultImageBlocks$1(blocks, images) {
|
|
|
15229
15229
|
if (!Array.isArray(blocks)) return [];
|
|
15230
15230
|
const out = [];
|
|
15231
15231
|
for (const block of blocks) {
|
|
15232
|
-
if (!isRecord$
|
|
15232
|
+
if (!isRecord$16(block)) continue;
|
|
15233
15233
|
if (block.type === "image") {
|
|
15234
15234
|
const inline = imageBlockToInline$2(block, images);
|
|
15235
15235
|
if (inline && SUPPORTED_IMAGE_MEDIA_TYPES$3.has(inline.mediaType)) out.push({
|
|
@@ -15292,7 +15292,7 @@ function nonSystemMessages$3(options) {
|
|
|
15292
15292
|
}
|
|
15293
15293
|
function cloneJsonValue(value) {
|
|
15294
15294
|
if (Array.isArray(value)) return value.map(cloneJsonValue);
|
|
15295
|
-
if (isRecord$
|
|
15295
|
+
if (isRecord$16(value)) {
|
|
15296
15296
|
const res = {};
|
|
15297
15297
|
for (const [k, v] of Object.entries(value)) res[k] = cloneJsonValue(v);
|
|
15298
15298
|
return res;
|
|
@@ -15307,7 +15307,7 @@ function resolveLocalJsonPointer(root, ref) {
|
|
|
15307
15307
|
let current = root;
|
|
15308
15308
|
for (const rawPart of ref.slice(2).split("/")) {
|
|
15309
15309
|
const part = rawPart.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
15310
|
-
if (isRecord$
|
|
15310
|
+
if (isRecord$16(current)) {
|
|
15311
15311
|
if (!Object.prototype.hasOwnProperty.call(current, part)) return { found: false };
|
|
15312
15312
|
current = current[part];
|
|
15313
15313
|
} else if (Array.isArray(current)) {
|
|
@@ -15323,7 +15323,7 @@ function resolveLocalJsonPointer(root, ref) {
|
|
|
15323
15323
|
}
|
|
15324
15324
|
function derefNode(node, root, visited) {
|
|
15325
15325
|
if (Array.isArray(node)) return node.map((item) => derefNode(item, root, visited));
|
|
15326
|
-
if (isRecord$
|
|
15326
|
+
if (isRecord$16(node)) {
|
|
15327
15327
|
if (typeof node["$ref"] === "string" && (node["$ref"] === "#" || node["$ref"].startsWith("#/"))) {
|
|
15328
15328
|
const ref = node["$ref"];
|
|
15329
15329
|
if (visited.has(ref)) return node;
|
|
@@ -15332,7 +15332,7 @@ function derefNode(node, root, visited) {
|
|
|
15332
15332
|
visited.add(ref);
|
|
15333
15333
|
const inlined = derefNode(resolved.value, root, visited);
|
|
15334
15334
|
visited.delete(ref);
|
|
15335
|
-
if (isRecord$
|
|
15335
|
+
if (isRecord$16(inlined)) {
|
|
15336
15336
|
const merged = { ...inlined };
|
|
15337
15337
|
for (const [k, v] of Object.entries(node)) {
|
|
15338
15338
|
if (k === "$ref") continue;
|
|
@@ -15352,7 +15352,7 @@ function derefNode(node, root, visited) {
|
|
|
15352
15352
|
}
|
|
15353
15353
|
function hasUnresolvedDefinitionRef(node, bucketKey) {
|
|
15354
15354
|
if (Array.isArray(node)) return node.some((child) => hasUnresolvedDefinitionRef(child, bucketKey));
|
|
15355
|
-
if (isRecord$
|
|
15355
|
+
if (isRecord$16(node)) {
|
|
15356
15356
|
const ref = node["$ref"];
|
|
15357
15357
|
if (typeof ref === "string" && ref.startsWith(`#/${bucketKey}/`)) return true;
|
|
15358
15358
|
for (const [k, v] of Object.entries(node)) {
|
|
@@ -15383,19 +15383,19 @@ function inferTypeFromValues(values) {
|
|
|
15383
15383
|
if (types.size === 1) return types.values().next().value;
|
|
15384
15384
|
}
|
|
15385
15385
|
function normalizeSchemaProperties(node) {
|
|
15386
|
-
if (!isRecord$
|
|
15387
|
-
if (isRecord$
|
|
15388
|
-
for (const propSchema of Object.values(node.properties)) if (isRecord$
|
|
15386
|
+
if (!isRecord$16(node)) return;
|
|
15387
|
+
if (isRecord$16(node.properties)) {
|
|
15388
|
+
for (const propSchema of Object.values(node.properties)) if (isRecord$16(propSchema)) {
|
|
15389
15389
|
if (!propSchema.type && !propSchema.$ref) {
|
|
15390
15390
|
if (Array.isArray(propSchema.enum) && propSchema.enum.length > 0) propSchema.type = inferTypeFromValues(propSchema.enum) ?? "string";
|
|
15391
15391
|
else if (propSchema.const !== void 0) propSchema.type = inferValueType(propSchema.const) ?? "string";
|
|
15392
|
-
else if (isRecord$
|
|
15392
|
+
else if (isRecord$16(propSchema.properties)) propSchema.type = "object";
|
|
15393
15393
|
else if (propSchema.items) propSchema.type = "array";
|
|
15394
15394
|
}
|
|
15395
15395
|
normalizeSchemaProperties(propSchema);
|
|
15396
15396
|
}
|
|
15397
15397
|
}
|
|
15398
|
-
if (isRecord$
|
|
15398
|
+
if (isRecord$16(node.items)) normalizeSchemaProperties(node.items);
|
|
15399
15399
|
else if (Array.isArray(node.items)) for (const item of node.items) normalizeSchemaProperties(item);
|
|
15400
15400
|
}
|
|
15401
15401
|
/**
|
|
@@ -15403,7 +15403,7 @@ function normalizeSchemaProperties(node) {
|
|
|
15403
15403
|
* inlining definitions ($defs/definitions/$ref), and ensuring property types for enums/consts.
|
|
15404
15404
|
*/
|
|
15405
15405
|
function normalizeKimiToolSchema(schema) {
|
|
15406
|
-
if (!isRecord$
|
|
15406
|
+
if (!isRecord$16(schema)) return {
|
|
15407
15407
|
type: "object",
|
|
15408
15408
|
properties: {}
|
|
15409
15409
|
};
|
|
@@ -15423,7 +15423,7 @@ function stripMetaSchema$1(schema) {
|
|
|
15423
15423
|
function reasoningText(message) {
|
|
15424
15424
|
if (!Array.isArray(message.content)) return "";
|
|
15425
15425
|
const parts = [];
|
|
15426
|
-
for (const block of message.content) if (isRecord$
|
|
15426
|
+
for (const block of message.content) if (isRecord$16(block) && block.type === "reasoning" && typeof block.text === "string") parts.push(sanitizeText$3(block.text));
|
|
15427
15427
|
return parts.join("");
|
|
15428
15428
|
}
|
|
15429
15429
|
/**
|
|
@@ -15471,7 +15471,7 @@ function openAIUserContent$1(message, images, media = {}) {
|
|
|
15471
15471
|
const parts = [];
|
|
15472
15472
|
let hasRichPart = false;
|
|
15473
15473
|
for (const block of message.content) {
|
|
15474
|
-
if (!isRecord$
|
|
15474
|
+
if (!isRecord$16(block)) continue;
|
|
15475
15475
|
if (block.type === "text" && typeof block.text === "string") {
|
|
15476
15476
|
const text = sanitizeText$3(block.text);
|
|
15477
15477
|
if (text !== "") parts.push({
|
|
@@ -15511,7 +15511,7 @@ function openAIAssistantContent$1(message) {
|
|
|
15511
15511
|
const textParts = [];
|
|
15512
15512
|
const toolCalls = [];
|
|
15513
15513
|
for (const block of message.content) {
|
|
15514
|
-
if (!isRecord$
|
|
15514
|
+
if (!isRecord$16(block)) continue;
|
|
15515
15515
|
if (block.type === "text" && typeof block.text === "string") textParts.push(sanitizeText$3(block.text));
|
|
15516
15516
|
else if (block.type === "tool-call" && typeof block.name === "string") toolCalls.push({
|
|
15517
15517
|
id: clampToolCallId(typeof block.id === "string" && block.id !== "" ? block.id : `call_${toolCalls.length}`),
|
|
@@ -15642,7 +15642,7 @@ function buildOpenAIRequest(options, images = NO_RESOLVED_IMAGES$3, preserveThin
|
|
|
15642
15642
|
nonSystemIndex += 1;
|
|
15643
15643
|
}
|
|
15644
15644
|
const block = current.content[0];
|
|
15645
|
-
const callId = isRecord$
|
|
15645
|
+
const callId = isRecord$16(block) && typeof block.toolCallId === "string" ? block.toolCallId : "";
|
|
15646
15646
|
messages.push({
|
|
15647
15647
|
role: "tool",
|
|
15648
15648
|
tool_call_id: clampToolCallId(callId),
|
|
@@ -15728,7 +15728,7 @@ function anthropicUserContent$1(message, images) {
|
|
|
15728
15728
|
if (!Array.isArray(message.content)) return [];
|
|
15729
15729
|
const blocks = [];
|
|
15730
15730
|
for (const block of message.content) {
|
|
15731
|
-
if (!isRecord$
|
|
15731
|
+
if (!isRecord$16(block)) continue;
|
|
15732
15732
|
if (block.type === "video") {
|
|
15733
15733
|
blocks.push({
|
|
15734
15734
|
type: "text",
|
|
@@ -15772,7 +15772,7 @@ function anthropicUserContent$1(message, images) {
|
|
|
15772
15772
|
function anthropicAssistantContent$1(message) {
|
|
15773
15773
|
const blocks = [];
|
|
15774
15774
|
for (const block of message.content) {
|
|
15775
|
-
if (!isRecord$
|
|
15775
|
+
if (!isRecord$16(block)) continue;
|
|
15776
15776
|
if (block.type === "text" && typeof block.text === "string") {
|
|
15777
15777
|
const text = sanitizeText$3(block.text);
|
|
15778
15778
|
if (text !== "") blocks.push({
|
|
@@ -15785,7 +15785,7 @@ function anthropicAssistantContent$1(message) {
|
|
|
15785
15785
|
type: "tool_use",
|
|
15786
15786
|
id: clampToolCallId(typeof block.id === "string" && block.id !== "" ? block.id : `toolu_${blocks.length}`),
|
|
15787
15787
|
name: block.name,
|
|
15788
|
-
input: isRecord$
|
|
15788
|
+
input: isRecord$16(parsed) ? parsed : {}
|
|
15789
15789
|
});
|
|
15790
15790
|
}
|
|
15791
15791
|
}
|
|
@@ -15973,24 +15973,24 @@ function processOpenAIStreamLine(line, state) {
|
|
|
15973
15973
|
}
|
|
15974
15974
|
if (payload === "") return [];
|
|
15975
15975
|
const chunk = safeJsonParse$3(payload);
|
|
15976
|
-
if (!isRecord$
|
|
15976
|
+
if (!isRecord$16(chunk)) return [];
|
|
15977
15977
|
const out = [];
|
|
15978
|
-
const errorPayload = isRecord$
|
|
15978
|
+
const errorPayload = isRecord$16(chunk.error) ? chunk.error : void 0;
|
|
15979
15979
|
if (errorPayload !== void 0) throw new LlmError$1(`Kimi Code stream error: ${asString$9(errorPayload.message) ?? "unknown error"}`, "PROVIDER_ERROR");
|
|
15980
|
-
const usage = isRecord$
|
|
15980
|
+
const usage = isRecord$16(chunk.usage) ? chunk.usage : void 0;
|
|
15981
15981
|
if (usage) {
|
|
15982
15982
|
state.sawUsage = true;
|
|
15983
15983
|
const prompt = numberOr$4(usage.prompt_tokens, 0);
|
|
15984
|
-
const details = isRecord$
|
|
15984
|
+
const details = isRecord$16(usage.prompt_tokens_details) ? usage.prompt_tokens_details : void 0;
|
|
15985
15985
|
const cached = details ? numberOr$4(details.cached_tokens, 0) : 0;
|
|
15986
15986
|
state.inputTokens = Math.max(0, prompt - cached);
|
|
15987
15987
|
state.cacheReadTokens = cached;
|
|
15988
15988
|
state.outputTokens = numberOr$4(usage.completion_tokens, state.outputTokens);
|
|
15989
|
-
if (isRecord$
|
|
15989
|
+
if (isRecord$16(usage.completion_tokens_details)) state.reasoningTokens = numberOr$4(usage.completion_tokens_details.reasoning_tokens, state.reasoningTokens);
|
|
15990
15990
|
}
|
|
15991
15991
|
const choices = Array.isArray(chunk.choices) ? chunk.choices : [];
|
|
15992
|
-
const choice = isRecord$
|
|
15993
|
-
const delta = isRecord$
|
|
15992
|
+
const choice = isRecord$16(choices[0]) ? choices[0] : void 0;
|
|
15993
|
+
const delta = isRecord$16(choice?.delta) ? choice.delta : void 0;
|
|
15994
15994
|
if (delta) {
|
|
15995
15995
|
const reasoning = asString$9(delta.reasoning_content) ?? asString$9(delta.reasoning);
|
|
15996
15996
|
if (reasoning !== void 0 && reasoning !== "") {
|
|
@@ -16018,7 +16018,7 @@ function processOpenAIStreamLine(line, state) {
|
|
|
16018
16018
|
}
|
|
16019
16019
|
const toolDeltas = Array.isArray(delta.tool_calls) ? delta.tool_calls : [];
|
|
16020
16020
|
for (const entry of toolDeltas) {
|
|
16021
|
-
if (!isRecord$
|
|
16021
|
+
if (!isRecord$16(entry)) continue;
|
|
16022
16022
|
out.push(...applyOpenAIToolDelta(entry, state));
|
|
16023
16023
|
}
|
|
16024
16024
|
}
|
|
@@ -16032,7 +16032,7 @@ function processOpenAIStreamLine(line, state) {
|
|
|
16032
16032
|
}
|
|
16033
16033
|
function applyOpenAIToolDelta(entry, state) {
|
|
16034
16034
|
const wireIndex = typeof entry.index === "number" ? entry.index : 0;
|
|
16035
|
-
const fn = isRecord$
|
|
16035
|
+
const fn = isRecord$16(entry.function) ? entry.function : {};
|
|
16036
16036
|
const out = [];
|
|
16037
16037
|
let call = state.toolCalls.get(wireIndex);
|
|
16038
16038
|
if (call === void 0) {
|
|
@@ -16087,12 +16087,12 @@ function processAnthropicStreamLine(line, state) {
|
|
|
16087
16087
|
const payload = trimmed.slice(5).trim();
|
|
16088
16088
|
if (payload === "" || payload === "[DONE]") return [];
|
|
16089
16089
|
const event = safeJsonParse$3(payload);
|
|
16090
|
-
if (!isRecord$
|
|
16090
|
+
if (!isRecord$16(event)) return [];
|
|
16091
16091
|
const type = asString$9(event.type);
|
|
16092
16092
|
const out = [];
|
|
16093
16093
|
if (type === "message_start") {
|
|
16094
|
-
const message = isRecord$
|
|
16095
|
-
const usage = message && isRecord$
|
|
16094
|
+
const message = isRecord$16(event.message) ? event.message : void 0;
|
|
16095
|
+
const usage = message && isRecord$16(message.usage) ? message.usage : void 0;
|
|
16096
16096
|
if (usage) {
|
|
16097
16097
|
state.sawUsage = true;
|
|
16098
16098
|
state.inputTokens = numberOr$4(usage.input_tokens, 0);
|
|
@@ -16106,7 +16106,7 @@ function processAnthropicStreamLine(line, state) {
|
|
|
16106
16106
|
}
|
|
16107
16107
|
if (type === "content_block_start") {
|
|
16108
16108
|
const contentIndex = numberOr$4(event.index, 0);
|
|
16109
|
-
const block = isRecord$
|
|
16109
|
+
const block = isRecord$16(event.content_block) ? event.content_block : {};
|
|
16110
16110
|
const blockType = asString$9(block.type);
|
|
16111
16111
|
out.push(...closeCurrent$2(state));
|
|
16112
16112
|
if (blockType === "tool_use") {
|
|
@@ -16156,7 +16156,7 @@ function processAnthropicStreamLine(line, state) {
|
|
|
16156
16156
|
}
|
|
16157
16157
|
if (type === "content_block_delta") {
|
|
16158
16158
|
const contentIndex = numberOr$4(event.index, 0);
|
|
16159
|
-
const delta = isRecord$
|
|
16159
|
+
const delta = isRecord$16(event.delta) ? event.delta : {};
|
|
16160
16160
|
const deltaType = asString$9(delta.type);
|
|
16161
16161
|
if (deltaType === "input_json_delta") {
|
|
16162
16162
|
const pending = state.toolCalls.get(contentIndex);
|
|
@@ -16229,10 +16229,10 @@ function processAnthropicStreamLine(line, state) {
|
|
|
16229
16229
|
return out;
|
|
16230
16230
|
}
|
|
16231
16231
|
if (type === "message_delta") {
|
|
16232
|
-
const delta = isRecord$
|
|
16232
|
+
const delta = isRecord$16(event.delta) ? event.delta : void 0;
|
|
16233
16233
|
const stop = delta ? asString$9(delta.stop_reason) : void 0;
|
|
16234
16234
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
16235
|
-
const usage = isRecord$
|
|
16235
|
+
const usage = isRecord$16(event.usage) ? event.usage : void 0;
|
|
16236
16236
|
if (usage) {
|
|
16237
16237
|
state.sawUsage = true;
|
|
16238
16238
|
state.outputTokens = numberOr$4(usage.output_tokens, state.outputTokens);
|
|
@@ -16243,7 +16243,7 @@ function processAnthropicStreamLine(line, state) {
|
|
|
16243
16243
|
state.done = true;
|
|
16244
16244
|
return closeStream$2(state);
|
|
16245
16245
|
}
|
|
16246
|
-
if (type === "error") throw new LlmError$1(`Kimi Code stream error: ${asString$9((isRecord$
|
|
16246
|
+
if (type === "error") throw new LlmError$1(`Kimi Code stream error: ${asString$9((isRecord$16(event.error) ? event.error : {}).message) ?? "unknown error"}`, "PROVIDER_ERROR");
|
|
16247
16247
|
return out;
|
|
16248
16248
|
}
|
|
16249
16249
|
/**
|
|
@@ -16927,7 +16927,7 @@ var KimiCodeAccountPool = class extends AccountPoolCore {
|
|
|
16927
16927
|
function isKimiCodeEffort(value) {
|
|
16928
16928
|
return typeof value === "string" && KIMI_CODE_REASONING_EFFORTS.includes(value);
|
|
16929
16929
|
}
|
|
16930
|
-
function isRegion$
|
|
16930
|
+
function isRegion$3(value) {
|
|
16931
16931
|
return value === "mainland-cn" || value === "global";
|
|
16932
16932
|
}
|
|
16933
16933
|
const MAX_BODY_BYTES$4 = 64 * 1024;
|
|
@@ -17139,7 +17139,7 @@ function registerKimiCodeRoutes(ctx, store, modelSettings, preferences, options
|
|
|
17139
17139
|
error: "Cross-origin request rejected."
|
|
17140
17140
|
});
|
|
17141
17141
|
const body = await readRequestJson$4(request);
|
|
17142
|
-
const requested = isRegion$
|
|
17142
|
+
const requested = isRegion$3(body.region) ? body.region : void 0;
|
|
17143
17143
|
return sendJson$4(response, 200, {
|
|
17144
17144
|
ok: true,
|
|
17145
17145
|
value: await beginWebLogin(store, {
|
|
@@ -17830,10 +17830,12 @@ const REGION_HOSTS = {
|
|
|
17830
17830
|
* platform API key (or the platform OAuth the `mmx` CLI holds), and it answers
|
|
17831
17831
|
* an `mcode-public` sign-in with HTTP 200 + `base_resp.status_code: 1004`
|
|
17832
17832
|
* ("Please carry the API secret key") under every auth shape.
|
|
17833
|
-
* - `/v1/api/openplatform/coding_plan/remains`
|
|
17834
|
-
*
|
|
17833
|
+
* - `/v1/api/openplatform/coding_plan/remains` is what the OFFICIAL MiniMax Code
|
|
17834
|
+
* client uses for exactly this credential
|
|
17835
17835
|
* (`packages/tui/src/account/matrix-account-client.ts`, which reads it as the
|
|
17836
|
-
* Token Plan quota).
|
|
17836
|
+
* Token Plan quota). It is served by the API hosts — see
|
|
17837
|
+
* {@link QUOTA_HOST_CANDIDATES} for the measured origin — not by the agent hosts
|
|
17838
|
+
* this line posts Messages to.
|
|
17837
17839
|
*
|
|
17838
17840
|
* So the path below is the second one. See the note on
|
|
17839
17841
|
* {@link QUOTA_CLIENT_ATTRIBUTION} for the one caveat that comes with it.
|
|
@@ -17842,16 +17844,30 @@ const TOKEN_PLAN_REMAINS_PATH = "/v1/api/openplatform/coding_plan/remains";
|
|
|
17842
17844
|
/**
|
|
17843
17845
|
* Candidate hosts for the usage endpoint, most likely first.
|
|
17844
17846
|
*
|
|
17845
|
-
*
|
|
17846
|
-
*
|
|
17847
|
-
*
|
|
17848
|
-
*
|
|
17849
|
-
*
|
|
17850
|
-
*
|
|
17847
|
+
* MEASURED, not inferred. The path below (`/v1/api/openplatform/coding_plan/remains`)
|
|
17848
|
+
* lives on the API hosts, and this list previously carried the AGENT hosts because
|
|
17849
|
+
* the Messages endpoint they serve is the one this line already talks to. That was
|
|
17850
|
+
* the wrong surface for usage: an earlier revision measured only what a 404 "looked
|
|
17851
|
+
* like" and not where the path actually serves, so both `agent.*` origins answered
|
|
17852
|
+
* `404 page not found` for it — and, on the two of them that answer the request at
|
|
17853
|
+
* all, an HTML chat-shell page rather than JSON. Either way no usable document was
|
|
17854
|
+
* produced, every candidate was exhausted, and the card degraded to "the usage
|
|
17855
|
+
* endpoint did not answer".
|
|
17856
|
+
*
|
|
17857
|
+
* The correct hosts, probed directly with a live `mcode-public` cn credential:
|
|
17858
|
+
* `api.minimax.cn` answers HTTP 200 with `base_resp.status_code: 0` and the full
|
|
17859
|
+
* `model_remains` document. The global pairing mirrors the region split already
|
|
17860
|
+
* used above (cn vs io); `api.minimax.io` is NOT one of them — measured, it
|
|
17861
|
+
* answers this path with HTTP 401 even for a credential its cn sibling accepts, so
|
|
17862
|
+
* listing it would spend a probe to learn nothing. `api.minimaxi.com` is kept as
|
|
17863
|
+
* the measured fallback because it serves the same document.
|
|
17864
|
+
*
|
|
17865
|
+
* The winner is still remembered, which keeps any remaining uncertainty in one
|
|
17866
|
+
* place instead of spreading a guess through every request.
|
|
17851
17867
|
*/
|
|
17852
17868
|
const QUOTA_HOST_CANDIDATES = {
|
|
17853
|
-
cn: ["https://
|
|
17854
|
-
global: ["https://
|
|
17869
|
+
cn: ["https://api.minimax.cn", "https://api.minimaxi.com"],
|
|
17870
|
+
global: ["https://api.minimax.io"]
|
|
17855
17871
|
};
|
|
17856
17872
|
/** Whether the caller opted in to sending the first-party attribution headers. */
|
|
17857
17873
|
function quotaAttributionEnabled() {
|
|
@@ -17962,7 +17978,7 @@ function oauthUrl(region, path) {
|
|
|
17962
17978
|
return accountHost(region) + path;
|
|
17963
17979
|
}
|
|
17964
17980
|
/** Whether one value is a region this route understands. */
|
|
17965
|
-
function isRegion$
|
|
17981
|
+
function isRegion$2(value) {
|
|
17966
17982
|
return value === "cn" || value === "global";
|
|
17967
17983
|
}
|
|
17968
17984
|
/** Reasoning levels the whole route understands, for route-level validation. */
|
|
@@ -18025,35 +18041,32 @@ function redactToken(token) {
|
|
|
18025
18041
|
* \`effort\` level, so the field is emitted in that vocabulary and nowhere else. No
|
|
18026
18042
|
* other undocumented field is ever sent.
|
|
18027
18043
|
*
|
|
18028
|
-
*
|
|
18044
|
+
* PROMPT CACHING IS ON BY DEFAULT, AND IT IS THE REQUEST THAT TURNS IT ON
|
|
18029
18045
|
*
|
|
18030
|
-
*
|
|
18031
|
-
* counters out of `usage` (see the message_start branch) - so the route is
|
|
18032
|
-
* prepared to report cache hits it never asks for. MiniMax documents two
|
|
18033
|
-
* different mechanisms, and they are not interchangeable:
|
|
18046
|
+
* MiniMax documents two caching mechanisms, and they are not interchangeable:
|
|
18034
18047
|
*
|
|
18035
18048
|
* - an AUTOMATIC cache on its native API, which needs no marker at all; and
|
|
18036
18049
|
* - an EXPLICIT cache on its Anthropic-compatible API, where the
|
|
18037
18050
|
* `cache_control` breakpoints are what create the cache at all
|
|
18038
|
-
* (`tools` -> `system` -> `messages`,
|
|
18039
|
-
* (Anthropic API)" page of the
|
|
18040
|
-
*
|
|
18041
|
-
*
|
|
18042
|
-
*
|
|
18043
|
-
*
|
|
18044
|
-
*
|
|
18045
|
-
*
|
|
18046
|
-
*
|
|
18047
|
-
*
|
|
18048
|
-
*
|
|
18049
|
-
*
|
|
18050
|
-
*
|
|
18051
|
-
*
|
|
18052
|
-
*
|
|
18053
|
-
*
|
|
18054
|
-
*
|
|
18051
|
+
* (`tools` -> `system` -> `messages`, at most MAX_CACHE_BREAKPOINTS per
|
|
18052
|
+
* request, per the "Explicit Prompt Caching (Anthropic API)" page of the
|
|
18053
|
+
* MiniMax docs).
|
|
18054
|
+
*
|
|
18055
|
+
* This line speaks the Anthropic dialect, so the explicit mechanism is the one
|
|
18056
|
+
* that applies: a request with no breakpoint gets no `cache_read_input_tokens`
|
|
18057
|
+
* back no matter how identical its bytes are turn over turn, which is exactly
|
|
18058
|
+
* why this route showed no cache hits before the markers went in.
|
|
18059
|
+
*
|
|
18060
|
+
* The shape is the Claude line's (claude/mapper.ts, section 7), because the
|
|
18061
|
+
* wire vocabulary is the same and that shape is the one MiniMax's
|
|
18062
|
+
* explicit-caching page documents: breakpoints on the LAST system block, the
|
|
18063
|
+
* last block of the LAST user message, and the last tool. The first requires
|
|
18064
|
+
* `system` to go out as a block array rather than the plain string this line
|
|
18065
|
+
* was first measured with, so the array form is used only while caching is on -
|
|
18066
|
+
* a caller that opts out (MinimaxRequestOptions.cacheControl === false) gets
|
|
18067
|
+
* the original string body byte-for-byte.
|
|
18055
18068
|
*/
|
|
18056
|
-
function isRecord$
|
|
18069
|
+
function isRecord$15(value) {
|
|
18057
18070
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18058
18071
|
}
|
|
18059
18072
|
function asString$8(value) {
|
|
@@ -18081,7 +18094,7 @@ const SUPPORTED_IMAGE_MEDIA_TYPES$2 = /* @__PURE__ */ new Set([
|
|
|
18081
18094
|
]);
|
|
18082
18095
|
function attachmentOf$2(block) {
|
|
18083
18096
|
const attachment = block.attachment;
|
|
18084
|
-
return isRecord$
|
|
18097
|
+
return isRecord$15(attachment) ? attachment : void 0;
|
|
18085
18098
|
}
|
|
18086
18099
|
function attachmentLabel$2(block) {
|
|
18087
18100
|
const attachment = attachmentOf$2(block);
|
|
@@ -18117,7 +18130,7 @@ function textOf$2(content) {
|
|
|
18117
18130
|
if (!Array.isArray(content)) return "";
|
|
18118
18131
|
const parts = [];
|
|
18119
18132
|
for (const block of content) {
|
|
18120
|
-
if (!isRecord$
|
|
18133
|
+
if (!isRecord$15(block)) continue;
|
|
18121
18134
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText$2(block.text));
|
|
18122
18135
|
else if (block.type === "tool-result") parts.push(textOf$2(block.content));
|
|
18123
18136
|
}
|
|
@@ -18126,7 +18139,7 @@ function textOf$2(content) {
|
|
|
18126
18139
|
function toolResultText$2(blocks) {
|
|
18127
18140
|
if (!Array.isArray(blocks)) return "";
|
|
18128
18141
|
return blocks.map((block) => {
|
|
18129
|
-
if (!isRecord$
|
|
18142
|
+
if (!isRecord$15(block)) return "";
|
|
18130
18143
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText$2(block.text);
|
|
18131
18144
|
if (block.type === "tool-result") return toolResultText$2(block.content);
|
|
18132
18145
|
if (block.type === "image") return "[image: " + (attachmentLabel$2(block) ?? "attached image") + "]";
|
|
@@ -18145,7 +18158,7 @@ function toolResultBlocks(blocks, images) {
|
|
|
18145
18158
|
const out = [];
|
|
18146
18159
|
let hasImage = false;
|
|
18147
18160
|
for (const block of blocks) {
|
|
18148
|
-
if (!isRecord$
|
|
18161
|
+
if (!isRecord$15(block)) continue;
|
|
18149
18162
|
if (block.type === "text" && typeof block.text === "string") {
|
|
18150
18163
|
out.push({
|
|
18151
18164
|
type: "text",
|
|
@@ -18220,7 +18233,7 @@ function anthropicUserContent(message, images) {
|
|
|
18220
18233
|
if (!Array.isArray(message.content)) return [];
|
|
18221
18234
|
const blocks = [];
|
|
18222
18235
|
for (const block of message.content) {
|
|
18223
|
-
if (!isRecord$
|
|
18236
|
+
if (!isRecord$15(block)) continue;
|
|
18224
18237
|
if (block.type === "text" && typeof block.text === "string") {
|
|
18225
18238
|
const text = sanitizeText$2(block.text);
|
|
18226
18239
|
if (text !== "") blocks.push({
|
|
@@ -18258,7 +18271,7 @@ function anthropicUserContent(message, images) {
|
|
|
18258
18271
|
function anthropicAssistantContent(message) {
|
|
18259
18272
|
const blocks = [];
|
|
18260
18273
|
for (const block of message.content) {
|
|
18261
|
-
if (!isRecord$
|
|
18274
|
+
if (!isRecord$15(block)) continue;
|
|
18262
18275
|
if (block.type === "text" && typeof block.text === "string") {
|
|
18263
18276
|
const text = sanitizeText$2(block.text);
|
|
18264
18277
|
if (text !== "") blocks.push({
|
|
@@ -18273,7 +18286,7 @@ function anthropicAssistantContent(message) {
|
|
|
18273
18286
|
type: "tool_use",
|
|
18274
18287
|
id: asString$8(block.id) ?? "toolu_" + blocks.length,
|
|
18275
18288
|
name: block.name,
|
|
18276
|
-
input: isRecord$
|
|
18289
|
+
input: isRecord$15(parsed) ? parsed : {}
|
|
18277
18290
|
});
|
|
18278
18291
|
}
|
|
18279
18292
|
}
|
|
@@ -18351,8 +18364,78 @@ function clampOutputToContext(requested, contextWindow, estimatedInputTokens) {
|
|
|
18351
18364
|
if (available <= 0) return Math.min(requested, CONTEXT_HEADROOM_TOKENS);
|
|
18352
18365
|
return Math.min(requested, available);
|
|
18353
18366
|
}
|
|
18367
|
+
/**
|
|
18368
|
+
* Block types the wire accepts a cache_control marker on.
|
|
18369
|
+
*
|
|
18370
|
+
* A marker on any other block is a request the server rejects, so the last
|
|
18371
|
+
* block of the last user message is marked only when its type is one of these
|
|
18372
|
+
* (the same set the Claude line guards on, since the wire vocabulary is the
|
|
18373
|
+
* same).
|
|
18374
|
+
*/
|
|
18375
|
+
const CACHE_MARKABLE_BLOCK_TYPES$1 = /* @__PURE__ */ new Set([
|
|
18376
|
+
"text",
|
|
18377
|
+
"image",
|
|
18378
|
+
"tool_result"
|
|
18379
|
+
]);
|
|
18380
|
+
/**
|
|
18381
|
+
* The last block worth a cache breakpoint on the message list, if any.
|
|
18382
|
+
*
|
|
18383
|
+
* Marks the last block of the last USER message and nothing else, with two
|
|
18384
|
+
* load-bearing guards: the last message must be a user turn (a history ending
|
|
18385
|
+
* on an assistant turn - a prefill-shaped request - gets no message breakpoint
|
|
18386
|
+
* rather than a marker somewhere it was not asked for), and the block must be
|
|
18387
|
+
* one the wire accepts a marker on. An unmarkable block yields NO breakpoint
|
|
18388
|
+
* rather than one moved onto an earlier turn: an unmarked request is merely
|
|
18389
|
+
* uncached, while a marker on a block type the wire rejects fails the whole
|
|
18390
|
+
* turn.
|
|
18391
|
+
*/
|
|
18392
|
+
function lastCacheableUserBlock$1(messages) {
|
|
18393
|
+
const lastMessage = messages[messages.length - 1];
|
|
18394
|
+
if (lastMessage === void 0 || lastMessage.role !== "user") return void 0;
|
|
18395
|
+
const block = lastMessage.content[lastMessage.content.length - 1];
|
|
18396
|
+
if (block === void 0) return void 0;
|
|
18397
|
+
return CACHE_MARKABLE_BLOCK_TYPES$1.has(String(block.type)) ? block : void 0;
|
|
18398
|
+
}
|
|
18399
|
+
/**
|
|
18400
|
+
* Put the cache breakpoints on one built body, and report how many landed.
|
|
18401
|
+
*
|
|
18402
|
+
* Runs against the FINAL shape - the merged message list and the full tool
|
|
18403
|
+
* array - so the marker cannot land on a block the merge then moves.
|
|
18404
|
+
*
|
|
18405
|
+
* @param body - the built body, mutated in place: it was created by this module
|
|
18406
|
+
* and has not been handed to a caller yet.
|
|
18407
|
+
* @returns the number of breakpoints written.
|
|
18408
|
+
*/
|
|
18409
|
+
function markMinimaxCacheBreakpoints(body) {
|
|
18410
|
+
let marked = 0;
|
|
18411
|
+
const system = body.system;
|
|
18412
|
+
if (Array.isArray(system)) {
|
|
18413
|
+
const last = system[system.length - 1];
|
|
18414
|
+
if (last !== void 0) {
|
|
18415
|
+
last.cache_control = { type: "ephemeral" };
|
|
18416
|
+
marked += 1;
|
|
18417
|
+
}
|
|
18418
|
+
}
|
|
18419
|
+
const messages = body.messages;
|
|
18420
|
+
if (Array.isArray(messages)) {
|
|
18421
|
+
const target = lastCacheableUserBlock$1(messages);
|
|
18422
|
+
if (target !== void 0) {
|
|
18423
|
+
target.cache_control = { type: "ephemeral" };
|
|
18424
|
+
marked += 1;
|
|
18425
|
+
}
|
|
18426
|
+
}
|
|
18427
|
+
const tools = body.tools;
|
|
18428
|
+
if (Array.isArray(tools) && tools.length > 0) {
|
|
18429
|
+
const last = tools[tools.length - 1];
|
|
18430
|
+
if (last !== void 0) {
|
|
18431
|
+
last.cache_control = { type: "ephemeral" };
|
|
18432
|
+
marked += 1;
|
|
18433
|
+
}
|
|
18434
|
+
}
|
|
18435
|
+
return marked;
|
|
18436
|
+
}
|
|
18354
18437
|
/** Build one Anthropic Messages body for this subscription. */
|
|
18355
|
-
function buildMinimaxRequest(options, images = NO_RESOLVED_IMAGES$2) {
|
|
18438
|
+
function buildMinimaxRequest(options, images = NO_RESOLVED_IMAGES$2, request = {}) {
|
|
18356
18439
|
const entries = [];
|
|
18357
18440
|
for (const message of nonSystemMessages$2(options)) {
|
|
18358
18441
|
if (isToolResultMessage$2(message)) {
|
|
@@ -18370,12 +18453,16 @@ function buildMinimaxRequest(options, images = NO_RESOLVED_IMAGES$2) {
|
|
|
18370
18453
|
const system = leadingSystemText$2(options);
|
|
18371
18454
|
const maxTokens = options.maxTokens ?? maxOutputTokensFor$1(options.model);
|
|
18372
18455
|
const thinking = thinkingFieldFor(options.model, options.reasoningEffort === void 0 ? null : String(options.reasoningEffort));
|
|
18373
|
-
|
|
18456
|
+
const caching = request.cacheControl !== false;
|
|
18457
|
+
const body = {
|
|
18374
18458
|
model: options.model,
|
|
18375
18459
|
max_tokens: maxTokens,
|
|
18376
18460
|
stream: true,
|
|
18377
18461
|
messages: mergeAnthropicMessages(entries),
|
|
18378
|
-
...system === void 0 ? {} : { system
|
|
18462
|
+
...system === void 0 ? {} : { system: caching ? [{
|
|
18463
|
+
type: "text",
|
|
18464
|
+
text: system
|
|
18465
|
+
}] : system },
|
|
18379
18466
|
...options.temperature === void 0 || thinking !== void 0 ? {} : { temperature: options.temperature },
|
|
18380
18467
|
...options.stop && options.stop.length > 0 ? { stop_sequences: options.stop } : {},
|
|
18381
18468
|
...options.tools && options.tools.length > 0 ? { tools: options.tools.map((tool) => ({
|
|
@@ -18385,6 +18472,8 @@ function buildMinimaxRequest(options, images = NO_RESOLVED_IMAGES$2) {
|
|
|
18385
18472
|
})) } : {},
|
|
18386
18473
|
...thinking === void 0 ? {} : { thinking }
|
|
18387
18474
|
};
|
|
18475
|
+
if (caching) markMinimaxCacheBreakpoints(body);
|
|
18476
|
+
return body;
|
|
18388
18477
|
}
|
|
18389
18478
|
/**
|
|
18390
18479
|
* Reject a request the service would refuse, before sending it.
|
|
@@ -18509,12 +18598,12 @@ function processMinimaxStreamLine(line, state) {
|
|
|
18509
18598
|
const payload = trimmed.slice(5).trim();
|
|
18510
18599
|
if (payload === "" || payload === "[DONE]") return [];
|
|
18511
18600
|
const event = safeJsonParse$2(payload);
|
|
18512
|
-
if (!isRecord$
|
|
18601
|
+
if (!isRecord$15(event)) return [];
|
|
18513
18602
|
const type = asString$8(event.type);
|
|
18514
18603
|
const out = [];
|
|
18515
18604
|
if (type === "message_start") {
|
|
18516
|
-
const message = isRecord$
|
|
18517
|
-
const usage = message !== void 0 && isRecord$
|
|
18605
|
+
const message = isRecord$15(event.message) ? event.message : void 0;
|
|
18606
|
+
const usage = message !== void 0 && isRecord$15(message.usage) ? message.usage : void 0;
|
|
18518
18607
|
if (usage !== void 0) {
|
|
18519
18608
|
state.sawUsage = true;
|
|
18520
18609
|
state.inputTokens = numberOr$3(usage.input_tokens, 0);
|
|
@@ -18528,7 +18617,7 @@ function processMinimaxStreamLine(line, state) {
|
|
|
18528
18617
|
}
|
|
18529
18618
|
if (type === "content_block_start") {
|
|
18530
18619
|
const contentIndex = numberOr$3(event.index, 0);
|
|
18531
|
-
const block = isRecord$
|
|
18620
|
+
const block = isRecord$15(event.content_block) ? event.content_block : {};
|
|
18532
18621
|
const blockType = asString$8(block.type);
|
|
18533
18622
|
out.push(...closeCurrent$1(state));
|
|
18534
18623
|
if (blockType === "tool_use") {
|
|
@@ -18575,7 +18664,7 @@ function processMinimaxStreamLine(line, state) {
|
|
|
18575
18664
|
}
|
|
18576
18665
|
if (type === "content_block_delta") {
|
|
18577
18666
|
const contentIndex = numberOr$3(event.index, 0);
|
|
18578
|
-
const delta = isRecord$
|
|
18667
|
+
const delta = isRecord$15(event.delta) ? event.delta : {};
|
|
18579
18668
|
const deltaType = asString$8(delta.type);
|
|
18580
18669
|
if (deltaType === "input_json_delta") {
|
|
18581
18670
|
const pending = state.toolCalls.get(contentIndex);
|
|
@@ -18648,10 +18737,10 @@ function processMinimaxStreamLine(line, state) {
|
|
|
18648
18737
|
return out;
|
|
18649
18738
|
}
|
|
18650
18739
|
if (type === "message_delta") {
|
|
18651
|
-
const delta = isRecord$
|
|
18740
|
+
const delta = isRecord$15(event.delta) ? event.delta : void 0;
|
|
18652
18741
|
const stop = delta === void 0 ? void 0 : asString$8(delta.stop_reason);
|
|
18653
18742
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
18654
|
-
const usage = isRecord$
|
|
18743
|
+
const usage = isRecord$15(event.usage) ? event.usage : void 0;
|
|
18655
18744
|
if (usage !== void 0) {
|
|
18656
18745
|
state.sawUsage = true;
|
|
18657
18746
|
state.outputTokens = numberOr$3(usage.output_tokens, state.outputTokens);
|
|
@@ -18662,7 +18751,7 @@ function processMinimaxStreamLine(line, state) {
|
|
|
18662
18751
|
state.done = true;
|
|
18663
18752
|
return closeMinimaxStream(state);
|
|
18664
18753
|
}
|
|
18665
|
-
if (type === "error") throw new LlmError$1("MiniMax Code(编程订阅) stream error: " + (asString$8((isRecord$
|
|
18754
|
+
if (type === "error") throw new LlmError$1("MiniMax Code(编程订阅) stream error: " + (asString$8((isRecord$15(event.error) ? event.error : {}).message) ?? "unknown error"), "PROVIDER_ERROR");
|
|
18666
18755
|
return out;
|
|
18667
18756
|
}
|
|
18668
18757
|
//#endregion
|
|
@@ -18902,7 +18991,7 @@ function authStateJsonPath(region, buildEnv = MINIMAX_CODE_BUILD_ENV) {
|
|
|
18902
18991
|
function pluginCredentialPath() {
|
|
18903
18992
|
return path.join(dshHomeDir(), "storages", "minimax-code-credentials.json");
|
|
18904
18993
|
}
|
|
18905
|
-
function isRecord$
|
|
18994
|
+
function isRecord$14(value) {
|
|
18906
18995
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18907
18996
|
}
|
|
18908
18997
|
function asString$7(value) {
|
|
@@ -18924,7 +19013,7 @@ function asFiniteNumber(value) {
|
|
|
18924
19013
|
* exists to prevent.
|
|
18925
19014
|
*/
|
|
18926
19015
|
function parseMinimaxCodeCredentials(value, fallback) {
|
|
18927
|
-
if (!isRecord$
|
|
19016
|
+
if (!isRecord$14(value)) throw new Error("MiniMax Code credential payload is invalid");
|
|
18928
19017
|
const accessToken = asString$7(value.accessToken);
|
|
18929
19018
|
if (accessToken === void 0) throw new Error("MiniMax Code credential is missing its access token");
|
|
18930
19019
|
const refreshToken = asString$7(value.refreshToken);
|
|
@@ -18942,13 +19031,13 @@ function parseMinimaxCodeCredentials(value, fallback) {
|
|
|
18942
19031
|
generation: asFiniteNumber(value.generation) ?? 0,
|
|
18943
19032
|
loginEpoch: asString$7(value.loginEpoch) ?? "",
|
|
18944
19033
|
buildEnv: fallback.buildEnv ?? "prod",
|
|
18945
|
-
region: isRegion(value.region) ? value.region : fallback.region,
|
|
19034
|
+
region: isRegion$1(value.region) ? value.region : fallback.region,
|
|
18946
19035
|
recordKey: fallback.recordKey ?? null,
|
|
18947
19036
|
source: fallback.source ?? "file"
|
|
18948
19037
|
};
|
|
18949
19038
|
}
|
|
18950
19039
|
/** Whether one value is a region this line understands. */
|
|
18951
|
-
function isRegion(value) {
|
|
19040
|
+
function isRegion$1(value) {
|
|
18952
19041
|
return value === "cn" || value === "global";
|
|
18953
19042
|
}
|
|
18954
19043
|
/** Whether a credential is valid for long enough to use as-is. */
|
|
@@ -19010,10 +19099,10 @@ async function readNativeDocument(region) {
|
|
|
19010
19099
|
} catch {
|
|
19011
19100
|
return null;
|
|
19012
19101
|
}
|
|
19013
|
-
if (!isRecord$
|
|
19102
|
+
if (!isRecord$14(parsed) || !isRecord$14(parsed.records)) return null;
|
|
19014
19103
|
const records = parsed.records;
|
|
19015
19104
|
for (const [recordKey, entry] of Object.entries(records)) {
|
|
19016
|
-
if (!isRecord$
|
|
19105
|
+
if (!isRecord$14(entry)) continue;
|
|
19017
19106
|
if (asString$7(entry.clientId) !== "mcode-public") continue;
|
|
19018
19107
|
if (asString$7(entry.accessToken) === void 0) continue;
|
|
19019
19108
|
return {
|
|
@@ -19041,7 +19130,7 @@ async function syncAuthState(region, options) {
|
|
|
19041
19130
|
} catch {
|
|
19042
19131
|
return;
|
|
19043
19132
|
}
|
|
19044
|
-
if (!isRecord$
|
|
19133
|
+
if (!isRecord$14(parsed)) return;
|
|
19045
19134
|
const next = {
|
|
19046
19135
|
...parsed,
|
|
19047
19136
|
generation: options.generation,
|
|
@@ -19235,10 +19324,22 @@ function parseMinimaxCodeModelSettings(value) {
|
|
|
19235
19324
|
enabled: record.enabled !== false,
|
|
19236
19325
|
enabledModelIds,
|
|
19237
19326
|
contextWindowOverrides,
|
|
19238
|
-
defaultReasoningEffort: isReasoningEffort$1(record.defaultReasoningEffort) ? record.defaultReasoningEffort : null
|
|
19327
|
+
defaultReasoningEffort: isReasoningEffort$1(record.defaultReasoningEffort) ? record.defaultReasoningEffort : null,
|
|
19328
|
+
checkin: parseCheckinSettings(record.checkin)
|
|
19239
19329
|
};
|
|
19240
19330
|
}
|
|
19241
19331
|
/**
|
|
19332
|
+
* Normalize the check-in half of the settings document.
|
|
19333
|
+
*
|
|
19334
|
+
* Absent means enabled, matching the sibling lines' scheduler default: a user
|
|
19335
|
+
* who never opened the card gets the same behaviour a fresh workbuddy install
|
|
19336
|
+
* has, and only an explicit `false` parks the scheduler.
|
|
19337
|
+
*/
|
|
19338
|
+
function parseCheckinSettings(value) {
|
|
19339
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return { enabled: true };
|
|
19340
|
+
return { enabled: value.enabled !== false };
|
|
19341
|
+
}
|
|
19342
|
+
/**
|
|
19242
19343
|
* Apply one patch to one settings document.
|
|
19243
19344
|
*
|
|
19244
19345
|
* The merge lives outside both stores because the register-backed store has to
|
|
@@ -19251,7 +19352,8 @@ function mergeMinimaxCodeSettings(current, patch) {
|
|
|
19251
19352
|
enabled: patch.enabled !== void 0 ? patch.enabled : current.enabled !== false,
|
|
19252
19353
|
enabledModelIds: patch.enabledModelIds ?? current.enabledModelIds,
|
|
19253
19354
|
contextWindowOverrides: patch.contextWindowOverrides !== void 0 ? mergeContextWindowOverrides(current.contextWindowOverrides, patch.contextWindowOverrides) : current.contextWindowOverrides,
|
|
19254
|
-
defaultReasoningEffort: patch.defaultReasoningEffort !== void 0 ? patch.defaultReasoningEffort : current.defaultReasoningEffort
|
|
19355
|
+
defaultReasoningEffort: patch.defaultReasoningEffort !== void 0 ? patch.defaultReasoningEffort : current.defaultReasoningEffort,
|
|
19356
|
+
checkin: patch.checkin !== void 0 ? { enabled: patch.checkin.enabled !== false } : current.checkin ?? { enabled: true }
|
|
19255
19357
|
};
|
|
19256
19358
|
}
|
|
19257
19359
|
/**
|
|
@@ -19311,10 +19413,11 @@ var MinimaxCodeModelSettingsStore = class {
|
|
|
19311
19413
|
function registerMinimaxCodePreferenceStore(settings, fallbackStore = new MinimaxCodeModelSettingsStore()) {
|
|
19312
19414
|
if (!hasRegister(settings)) {
|
|
19313
19415
|
let snapshot = defaultMinimaxCodeSettings();
|
|
19314
|
-
fallbackStore.read().then((stored) => {
|
|
19416
|
+
const warmed = fallbackStore.read().then((stored) => {
|
|
19315
19417
|
snapshot = stored;
|
|
19316
19418
|
}).catch(() => void 0);
|
|
19317
19419
|
return {
|
|
19420
|
+
ready: () => warmed,
|
|
19318
19421
|
status: () => snapshot,
|
|
19319
19422
|
update: async (patch) => {
|
|
19320
19423
|
snapshot = await fallbackStore.updateSettings(patch);
|
|
@@ -19326,16 +19429,19 @@ function registerMinimaxCodePreferenceStore(settings, fallbackStore = new Minima
|
|
|
19326
19429
|
enabled: z.boolean().default(true),
|
|
19327
19430
|
enabledModelIds: z.array(z.string()).default([...DEFAULT_ENABLED_MODEL_IDS$2]),
|
|
19328
19431
|
contextWindowOverrides: z.dict(z.number()).default({}),
|
|
19329
|
-
defaultReasoningEffort: z.union([...MINIMAX_CODE_REASONING_EFFORTS.map((effort) => z.const(effort)), z.const(null)]).default(null)
|
|
19432
|
+
defaultReasoningEffort: z.union([...MINIMAX_CODE_REASONING_EFFORTS.map((effort) => z.const(effort)), z.const(null)]).default(null),
|
|
19433
|
+
checkin: z.object({ enabled: z.boolean().default(true) }).default({ enabled: true })
|
|
19330
19434
|
}));
|
|
19331
19435
|
return {
|
|
19436
|
+
ready: async () => void 0,
|
|
19332
19437
|
status: () => {
|
|
19333
19438
|
const value = scope.get();
|
|
19334
19439
|
return {
|
|
19335
19440
|
enabled: value.enabled !== false,
|
|
19336
19441
|
enabledModelIds: value.enabledModelIds,
|
|
19337
19442
|
contextWindowOverrides: value.contextWindowOverrides,
|
|
19338
|
-
defaultReasoningEffort: value.defaultReasoningEffort
|
|
19443
|
+
defaultReasoningEffort: value.defaultReasoningEffort,
|
|
19444
|
+
checkin: { enabled: value.checkin?.enabled !== false }
|
|
19339
19445
|
};
|
|
19340
19446
|
},
|
|
19341
19447
|
update: async (patch) => {
|
|
@@ -19344,7 +19450,8 @@ function registerMinimaxCodePreferenceStore(settings, fallbackStore = new Minima
|
|
|
19344
19450
|
enabled: value.enabled !== false,
|
|
19345
19451
|
enabledModelIds: value.enabledModelIds,
|
|
19346
19452
|
contextWindowOverrides: value.contextWindowOverrides,
|
|
19347
|
-
defaultReasoningEffort: value.defaultReasoningEffort
|
|
19453
|
+
defaultReasoningEffort: value.defaultReasoningEffort,
|
|
19454
|
+
checkin: { enabled: value.checkin?.enabled !== false }
|
|
19348
19455
|
}, patch);
|
|
19349
19456
|
await scope.update(normalized);
|
|
19350
19457
|
fallbackStore.updateSettings(patch).catch(() => void 0);
|
|
@@ -20595,7 +20702,7 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
20595
20702
|
const body = assertRequestBodyFits(buildMinimaxRequest({
|
|
20596
20703
|
...requestOptions,
|
|
20597
20704
|
maxTokens: clampOutputToContext(requestedMax, contextWindow, estimatedInputTokens(requestOptions))
|
|
20598
|
-
}, images));
|
|
20705
|
+
}, images, { cacheControl: true }));
|
|
20599
20706
|
let credentials;
|
|
20600
20707
|
let accountId;
|
|
20601
20708
|
try {
|
|
@@ -20707,7 +20814,7 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
20707
20814
|
function minimaxCodePoolPath() {
|
|
20708
20815
|
return path.join(dshHomeDir(), "storages", "minimax-code-pool.json");
|
|
20709
20816
|
}
|
|
20710
|
-
function isRecord$
|
|
20817
|
+
function isRecord$13(value) {
|
|
20711
20818
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20712
20819
|
}
|
|
20713
20820
|
function optionalString$2(record, key) {
|
|
@@ -20742,7 +20849,7 @@ function claimDisplayFacts(accessToken) {
|
|
|
20742
20849
|
} catch {
|
|
20743
20850
|
return {};
|
|
20744
20851
|
}
|
|
20745
|
-
if (!isRecord$
|
|
20852
|
+
if (!isRecord$13(claims)) return {};
|
|
20746
20853
|
const str = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
20747
20854
|
return {
|
|
20748
20855
|
email: str(claims.email) ?? (str(claims.preferred_username)?.includes("@") === true ? str(claims.preferred_username) : void 0),
|
|
@@ -20822,14 +20929,14 @@ function minimaxCodePoolIdentity(credentials) {
|
|
|
20822
20929
|
* instead of the app's).
|
|
20823
20930
|
*/
|
|
20824
20931
|
function parseMinimaxCodePoolData(value) {
|
|
20825
|
-
if (!isRecord$
|
|
20932
|
+
if (!isRecord$13(value)) throw new Error("MiniMax Code pool payload is invalid");
|
|
20826
20933
|
const record = value;
|
|
20827
20934
|
const accounts = [];
|
|
20828
20935
|
for (const item of Array.isArray(record.accounts) ? record.accounts : []) {
|
|
20829
|
-
if (!isRecord$
|
|
20936
|
+
if (!isRecord$13(item)) continue;
|
|
20830
20937
|
if (typeof item.id !== "string") continue;
|
|
20831
|
-
const rawCredentials = isRecord$
|
|
20832
|
-
const region = isRegion$
|
|
20938
|
+
const rawCredentials = isRecord$13(item.credentials) ? item.credentials : {};
|
|
20939
|
+
const region = isRegion$2(item.region) ? item.region : isRegion$2(rawCredentials.region) ? rawCredentials.region : "cn";
|
|
20833
20940
|
let credentials;
|
|
20834
20941
|
try {
|
|
20835
20942
|
credentials = parseMinimaxCodeCredentials(item.credentials, {
|
|
@@ -21227,6 +21334,7 @@ async function getMinimaxCodeWebStatus(store, options = {}, settingsSource) {
|
|
|
21227
21334
|
const pool = await minimaxCodePoolStatus(options.accountPool);
|
|
21228
21335
|
const quota = getCachedQuota$4();
|
|
21229
21336
|
const quotaUnavailable = quota === null ? getQuotaUnavailable() : null;
|
|
21337
|
+
const checkin = options.checkin === void 0 ? null : await options.checkin.summary().catch(() => null);
|
|
21230
21338
|
return {
|
|
21231
21339
|
...pool,
|
|
21232
21340
|
serving,
|
|
@@ -21246,7 +21354,8 @@ async function getMinimaxCodeWebStatus(store, options = {}, settingsSource) {
|
|
|
21246
21354
|
defaultReasoningEffort: settings.defaultReasoningEffort,
|
|
21247
21355
|
ownedByPlugin: credentials !== null && source === "file",
|
|
21248
21356
|
...quota === null ? {} : { quota },
|
|
21249
|
-
...quotaUnavailable === null ? {} : { quotaUnavailable }
|
|
21357
|
+
...quotaUnavailable === null ? {} : { quotaUnavailable },
|
|
21358
|
+
checkin
|
|
21250
21359
|
};
|
|
21251
21360
|
}
|
|
21252
21361
|
function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore(), options = {}, modelSettings = new MinimaxCodeModelSettingsStore(), preferences) {
|
|
@@ -21311,6 +21420,10 @@ function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore()
|
|
|
21311
21420
|
const effort = body.defaultReasoningEffort;
|
|
21312
21421
|
if (effort === null || isMinimaxCodeReasoningEffort(effort)) patch.defaultReasoningEffort = effort;
|
|
21313
21422
|
}
|
|
21423
|
+
if (typeof body.checkin === "object" && body.checkin !== null) {
|
|
21424
|
+
const raw = body.checkin;
|
|
21425
|
+
if (typeof raw.enabled === "boolean") patch.checkin = { enabled: raw.enabled };
|
|
21426
|
+
}
|
|
21314
21427
|
await settings.update(patch);
|
|
21315
21428
|
if (patch.enabled !== void 0 || patch.enabledModelIds !== void 0) ctx.emit?.("llm/adapters-updated");
|
|
21316
21429
|
return sendJson$2(response, 200, {
|
|
@@ -21318,11 +21431,25 @@ function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore()
|
|
|
21318
21431
|
value: await getMinimaxCodeWebStatus(store, options, settings)
|
|
21319
21432
|
});
|
|
21320
21433
|
}
|
|
21434
|
+
if (path === "checkin/now") {
|
|
21435
|
+
if (method !== "POST") return sendMethodNotAllowed$2(response);
|
|
21436
|
+
if (!isSameOriginMutation(request)) return sendCrossOrigin(response);
|
|
21437
|
+
const service = options.checkin;
|
|
21438
|
+
if (service === void 0) return sendJson$2(response, 400, {
|
|
21439
|
+
ok: false,
|
|
21440
|
+
error: "Check-in is not installed."
|
|
21441
|
+
});
|
|
21442
|
+
await service.tick(true);
|
|
21443
|
+
return sendJson$2(response, 200, {
|
|
21444
|
+
ok: true,
|
|
21445
|
+
value: await getMinimaxCodeWebStatus(store, options, settings)
|
|
21446
|
+
});
|
|
21447
|
+
}
|
|
21321
21448
|
if (path === "login/start") {
|
|
21322
21449
|
if (method !== "POST") return sendMethodNotAllowed$2(response);
|
|
21323
21450
|
if (!isSameOriginMutation(request)) return sendCrossOrigin(response);
|
|
21324
21451
|
const body = await readRequestJson$2(request);
|
|
21325
|
-
const requested = isRegion$
|
|
21452
|
+
const requested = isRegion$2(body.region) ? body.region : void 0;
|
|
21326
21453
|
const login = await beginWebLogin$1({
|
|
21327
21454
|
fetchFn,
|
|
21328
21455
|
...requested === void 0 ? {} : { region: requested }
|
|
@@ -22384,7 +22511,7 @@ function defaultContextWindowFor$1(id, catalog = FALLBACK_MODELS$1) {
|
|
|
22384
22511
|
}
|
|
22385
22512
|
//#endregion
|
|
22386
22513
|
//#region src/host/workbuddy/identity.ts
|
|
22387
|
-
function isRecord$
|
|
22514
|
+
function isRecord$12(value) {
|
|
22388
22515
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22389
22516
|
}
|
|
22390
22517
|
/** A trimmed, non-empty string from an untrusted record. */
|
|
@@ -22414,7 +22541,7 @@ function decodeAccessTokenClaims(accessToken) {
|
|
|
22414
22541
|
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
22415
22542
|
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
22416
22543
|
const parsed = JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
|
|
22417
|
-
return isRecord$
|
|
22544
|
+
return isRecord$12(parsed) ? parsed : null;
|
|
22418
22545
|
} catch {
|
|
22419
22546
|
return null;
|
|
22420
22547
|
}
|
|
@@ -22505,7 +22632,7 @@ const DEFAULT_CHECKIN_SETTINGS = { enabled: true };
|
|
|
22505
22632
|
* startHour/endHour; those keys are inert now and dropped on the next write.
|
|
22506
22633
|
*/
|
|
22507
22634
|
function normalizeCheckinSettings(value) {
|
|
22508
|
-
if (!isRecord$
|
|
22635
|
+
if (!isRecord$11(value)) return { ...DEFAULT_CHECKIN_SETTINGS };
|
|
22509
22636
|
return { enabled: value.enabled !== false };
|
|
22510
22637
|
}
|
|
22511
22638
|
/**
|
|
@@ -22606,10 +22733,10 @@ function modelSettingsPath$5() {
|
|
|
22606
22733
|
function managedCredentialsPath() {
|
|
22607
22734
|
return path.join(dshHomeDir$2(), "storages", "workbuddy-accounts.json");
|
|
22608
22735
|
}
|
|
22609
|
-
function isRecord$
|
|
22736
|
+
function isRecord$11(value) {
|
|
22610
22737
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22611
22738
|
}
|
|
22612
|
-
function readString(record, key) {
|
|
22739
|
+
function readString$1(record, key) {
|
|
22613
22740
|
const value = record[key];
|
|
22614
22741
|
if (typeof value !== "string") return void 0;
|
|
22615
22742
|
const trimmed = value.trim();
|
|
@@ -22624,27 +22751,27 @@ function readString(record, key) {
|
|
|
22624
22751
|
* can move on to the next candidate.
|
|
22625
22752
|
*/
|
|
22626
22753
|
function parseCredentialFile(value, sourceFile, sourceMtimeMs = 0) {
|
|
22627
|
-
if (!isRecord$
|
|
22628
|
-
const auth = isRecord$
|
|
22754
|
+
if (!isRecord$11(value)) throw new Error("WorkBuddy credential file is not an object");
|
|
22755
|
+
const auth = isRecord$11(value.auth) ? value.auth : void 0;
|
|
22629
22756
|
if (auth === void 0) throw new Error("WorkBuddy credential file has no auth block");
|
|
22630
|
-
const accessToken = readString(auth, "accessToken");
|
|
22757
|
+
const accessToken = readString$1(auth, "accessToken");
|
|
22631
22758
|
if (accessToken === void 0) throw new Error("WorkBuddy credential file has no access token");
|
|
22632
|
-
const account = isRecord$
|
|
22633
|
-
const domain = readString(auth, "domain") ?? "www.codebuddy.cn";
|
|
22759
|
+
const account = isRecord$11(value.account) ? value.account : {};
|
|
22760
|
+
const domain = readString$1(auth, "domain") ?? "www.codebuddy.cn";
|
|
22634
22761
|
const expiresAtRaw = auth.expiresAt;
|
|
22635
22762
|
const expiresAt = typeof expiresAtRaw === "number" && Number.isFinite(expiresAtRaw) ? expiresAtRaw : 0;
|
|
22636
22763
|
return withResolvedIdentity({
|
|
22637
22764
|
accessToken,
|
|
22638
|
-
refreshToken: readString(auth, "refreshToken") ?? "",
|
|
22765
|
+
refreshToken: readString$1(auth, "refreshToken") ?? "",
|
|
22639
22766
|
expiresAt,
|
|
22640
22767
|
region: regionForDomain(domain),
|
|
22641
22768
|
domain,
|
|
22642
22769
|
backend: backendForDomain(domain),
|
|
22643
|
-
uid: readString(account, "uid"),
|
|
22644
|
-
nickname: readString(account, "nickname"),
|
|
22645
|
-
uin: readString(account, "uin"),
|
|
22646
|
-
accountType: readString(account, "type"),
|
|
22647
|
-
enterpriseId: readString(account, "enterpriseId"),
|
|
22770
|
+
uid: readString$1(account, "uid"),
|
|
22771
|
+
nickname: readString$1(account, "nickname"),
|
|
22772
|
+
uin: readString$1(account, "uin"),
|
|
22773
|
+
accountType: readString$1(account, "type"),
|
|
22774
|
+
enterpriseId: readString$1(account, "enterpriseId"),
|
|
22648
22775
|
sourceFile,
|
|
22649
22776
|
sourceMtimeMs,
|
|
22650
22777
|
source: "desktop"
|
|
@@ -22700,25 +22827,25 @@ function workBuddyAccountIdAliases(credentials) {
|
|
|
22700
22827
|
}
|
|
22701
22828
|
/** Strict parser for credentials owned by the plugin's encrypted pool. */
|
|
22702
22829
|
function parseManagedCredentials(value) {
|
|
22703
|
-
if (!isRecord$
|
|
22830
|
+
if (!isRecord$11(value) || value.version !== 1 || !Array.isArray(value.accounts)) throw new Error("WorkBuddy managed credential pool is invalid");
|
|
22704
22831
|
return value.accounts.map((item) => {
|
|
22705
|
-
if (!isRecord$
|
|
22706
|
-
const accessToken = readString(item, "accessToken");
|
|
22832
|
+
if (!isRecord$11(item)) throw new Error("WorkBuddy managed account is invalid");
|
|
22833
|
+
const accessToken = readString$1(item, "accessToken");
|
|
22707
22834
|
if (accessToken === void 0) throw new Error("WorkBuddy managed account has no access token");
|
|
22708
|
-
const domain = readString(item, "domain") ?? "www.codebuddy.cn";
|
|
22835
|
+
const domain = readString$1(item, "domain") ?? "www.codebuddy.cn";
|
|
22709
22836
|
const expiresAt = typeof item.expiresAt === "number" && Number.isFinite(item.expiresAt) ? item.expiresAt : 0;
|
|
22710
22837
|
return withResolvedIdentity({
|
|
22711
22838
|
accessToken,
|
|
22712
|
-
refreshToken: readString(item, "refreshToken") ?? "",
|
|
22839
|
+
refreshToken: readString$1(item, "refreshToken") ?? "",
|
|
22713
22840
|
expiresAt,
|
|
22714
22841
|
region: regionForDomain(domain),
|
|
22715
22842
|
domain,
|
|
22716
22843
|
backend: backendForDomain(domain),
|
|
22717
|
-
uid: readString(item, "uid"),
|
|
22718
|
-
nickname: readString(item, "nickname"),
|
|
22719
|
-
uin: readString(item, "uin"),
|
|
22720
|
-
accountType: readString(item, "accountType"),
|
|
22721
|
-
enterpriseId: readString(item, "enterpriseId"),
|
|
22844
|
+
uid: readString$1(item, "uid"),
|
|
22845
|
+
nickname: readString$1(item, "nickname"),
|
|
22846
|
+
uin: readString$1(item, "uin"),
|
|
22847
|
+
accountType: readString$1(item, "accountType"),
|
|
22848
|
+
enterpriseId: readString$1(item, "enterpriseId"),
|
|
22722
22849
|
sourceFile: "",
|
|
22723
22850
|
sourceMtimeMs: 0,
|
|
22724
22851
|
source: "managed"
|
|
@@ -23000,7 +23127,7 @@ var FileCredentialStore$4 = class {
|
|
|
23000
23127
|
try {
|
|
23001
23128
|
const raw = await fsPromises.readFile(credentials.sourceFile, "utf8");
|
|
23002
23129
|
const parsed = JSON.parse(raw);
|
|
23003
|
-
if (!isRecord$
|
|
23130
|
+
if (!isRecord$11(parsed) || !isRecord$11(parsed.auth)) return;
|
|
23004
23131
|
parsed.auth.accessToken = credentials.accessToken;
|
|
23005
23132
|
if (credentials.refreshToken !== "") parsed.auth.refreshToken = credentials.refreshToken;
|
|
23006
23133
|
parsed.auth.expiresAt = credentials.expiresAt;
|
|
@@ -23033,9 +23160,9 @@ var FileModelSettingsStore$4 = class {
|
|
|
23033
23160
|
try {
|
|
23034
23161
|
const content = await fsPromises.readFile(this.filePath, "utf8");
|
|
23035
23162
|
const parsed = JSON.parse(content);
|
|
23036
|
-
if (isRecord$
|
|
23163
|
+
if (isRecord$11(parsed)) {
|
|
23037
23164
|
const enabledModelIds = Array.isArray(parsed.enabledModelIds) ? parsed.enabledModelIds.filter((id) => typeof id === "string") : [...DEFAULT_ENABLED_MODEL_IDS$1];
|
|
23038
|
-
const contextWindowOverrides = isRecord$
|
|
23165
|
+
const contextWindowOverrides = isRecord$11(parsed.contextWindowOverrides) ? Object.fromEntries(Object.entries(parsed.contextWindowOverrides).filter((entry) => typeof entry[1] === "number")) : {};
|
|
23039
23166
|
const defaultReasoningEffort = isReasoningEffort(parsed.defaultReasoningEffort) ? parsed.defaultReasoningEffort : null;
|
|
23040
23167
|
return {
|
|
23041
23168
|
enabled: parsed.enabled !== false,
|
|
@@ -23088,11 +23215,11 @@ var FileModelSettingsStore$4 = class {
|
|
|
23088
23215
|
function timeoutSignal$1(signal, ms) {
|
|
23089
23216
|
return signal ? AbortSignal.any([signal, AbortSignal.timeout(ms)]) : AbortSignal.timeout(ms);
|
|
23090
23217
|
}
|
|
23091
|
-
function isRecord$
|
|
23218
|
+
function isRecord$10(value) {
|
|
23092
23219
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23093
23220
|
}
|
|
23094
23221
|
function asRecord$4(value) {
|
|
23095
|
-
return isRecord$
|
|
23222
|
+
return isRecord$10(value) ? value : void 0;
|
|
23096
23223
|
}
|
|
23097
23224
|
function asString$5(value) {
|
|
23098
23225
|
if (typeof value === "string" && value.trim() !== "") return value;
|
|
@@ -23206,7 +23333,7 @@ function accountFromCredentials$1(credentials) {
|
|
|
23206
23333
|
* keeps the credential it has and lets the token's own claims fill in what
|
|
23207
23334
|
* they can.
|
|
23208
23335
|
*/
|
|
23209
|
-
async function fetchAccountIdentity(credentials, options = {}) {
|
|
23336
|
+
async function fetchAccountIdentity$1(credentials, options = {}) {
|
|
23210
23337
|
const fetchFn = options.fetchFn ?? fetch;
|
|
23211
23338
|
try {
|
|
23212
23339
|
const response = await fetchFn(`${credentials.backend}${ACCOUNT_PATH}`, {
|
|
@@ -23565,7 +23692,7 @@ function resetWebLogin() {
|
|
|
23565
23692
|
controller = null;
|
|
23566
23693
|
flow = { status: "idle" };
|
|
23567
23694
|
}
|
|
23568
|
-
function isRecord$
|
|
23695
|
+
function isRecord$9(value) {
|
|
23569
23696
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23570
23697
|
}
|
|
23571
23698
|
function stringOf(record, key) {
|
|
@@ -23613,11 +23740,11 @@ async function requestLoginState(region, fetchFn = fetch, signal) {
|
|
|
23613
23740
|
let root;
|
|
23614
23741
|
try {
|
|
23615
23742
|
const parsed = JSON.parse(text);
|
|
23616
|
-
root = isRecord$
|
|
23743
|
+
root = isRecord$9(parsed) ? parsed : void 0;
|
|
23617
23744
|
} catch {
|
|
23618
23745
|
root = void 0;
|
|
23619
23746
|
}
|
|
23620
|
-
if (!response.ok || root?.code !== 0 || !isRecord$
|
|
23747
|
+
if (!response.ok || root?.code !== 0 || !isRecord$9(root.data)) throw new Error(`${PROVIDER_NAME$1} 登录初始化失败(HTTP ${response.status}):${stringOf(root ?? {}, "msg") ?? text.slice(0, 160)}`);
|
|
23621
23748
|
const state = stringOf(root.data, "state");
|
|
23622
23749
|
const authUrl = stringOf(root.data, "authUrl");
|
|
23623
23750
|
if (!state || !authUrl) throw new Error(`${PROVIDER_NAME$1} 登录响应缺少 state 或 authUrl`);
|
|
@@ -23630,13 +23757,13 @@ async function requestLoginState(region, fetchFn = fetch, signal) {
|
|
|
23630
23757
|
}
|
|
23631
23758
|
/** Parse the successful token-poll shape while accepting the two observed wrappers. */
|
|
23632
23759
|
function parseLoginCredential(payload, attempt) {
|
|
23633
|
-
if (!isRecord$
|
|
23760
|
+
if (!isRecord$9(payload)) throw new Error(`${PROVIDER_NAME$1} 登录轮询响应无效`);
|
|
23634
23761
|
const code = numberOf(payload, "code");
|
|
23635
23762
|
if (code === 11217) return null;
|
|
23636
23763
|
if (code !== 0) throw new Error(`${PROVIDER_NAME$1} 登录失败:${stringOf(payload, "msg") ?? `code ${String(code)}`}`);
|
|
23637
|
-
const data = isRecord$
|
|
23638
|
-
const auth = isRecord$
|
|
23639
|
-
const account = isRecord$
|
|
23764
|
+
const data = isRecord$9(payload.data) ? payload.data : payload;
|
|
23765
|
+
const auth = isRecord$9(data.auth) ? data.auth : data;
|
|
23766
|
+
const account = isRecord$9(data.account) ? data.account : isRecord$9(auth.account) ? auth.account : isRecord$9(data.user) ? data.user : isRecord$9(auth.user) ? auth.user : {};
|
|
23640
23767
|
const accessToken = stringOf(auth, "accessToken") ?? stringOf(auth, "access_token") ?? stringOf(data, "token");
|
|
23641
23768
|
if (!accessToken) throw new Error(`${PROVIDER_NAME$1} 登录成功响应缺少 access token`);
|
|
23642
23769
|
const domain = stringOf(auth, "domain") ?? attempt.domain;
|
|
@@ -23685,7 +23812,7 @@ async function pollLogin(attempt, fetchFn = fetch, signal) {
|
|
|
23685
23812
|
*/
|
|
23686
23813
|
async function resolveLoginIdentity(credentials, resolve, fetchFn, signal) {
|
|
23687
23814
|
const resolved = withResolvedIdentity(credentials);
|
|
23688
|
-
const identity = await (resolve ?? ((current) => fetchAccountIdentity(current, {
|
|
23815
|
+
const identity = await (resolve ?? ((current) => fetchAccountIdentity$1(current, {
|
|
23689
23816
|
fetchFn,
|
|
23690
23817
|
...signal === void 0 ? {} : { signal }
|
|
23691
23818
|
})))(resolved).catch(() => null);
|
|
@@ -24353,7 +24480,7 @@ function registerWorkBuddyRoutes(ctx, store, modelSettings, preferences, options
|
|
|
24353
24480
|
* 3. **Reasoning rides `delta.reasoning_content`,** not OpenAI's
|
|
24354
24481
|
* `reasoning_summary`, and is emitted as its own DSH reasoning block.
|
|
24355
24482
|
*/
|
|
24356
|
-
function isRecord$
|
|
24483
|
+
function isRecord$8(value) {
|
|
24357
24484
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24358
24485
|
}
|
|
24359
24486
|
function asString$4(value) {
|
|
@@ -24389,17 +24516,17 @@ const SUPPORTED_IMAGE_MEDIA_TYPES$1 = /* @__PURE__ */ new Set([
|
|
|
24389
24516
|
]);
|
|
24390
24517
|
function attachmentOf$1(block) {
|
|
24391
24518
|
const attachment = block.attachment;
|
|
24392
|
-
if (!isRecord$
|
|
24519
|
+
if (!isRecord$8(attachment)) return void 0;
|
|
24393
24520
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
24394
24521
|
}
|
|
24395
24522
|
function attachmentLabel$1(block) {
|
|
24396
|
-
const attachment = isRecord$
|
|
24523
|
+
const attachment = isRecord$8(block.attachment) ? block.attachment : void 0;
|
|
24397
24524
|
return asString$4(attachment?.name) || asString$4(attachment?.attachmentId);
|
|
24398
24525
|
}
|
|
24399
24526
|
function collectImageRefs$1(content, refs) {
|
|
24400
24527
|
if (!Array.isArray(content)) return;
|
|
24401
24528
|
for (const block of content) {
|
|
24402
|
-
if (!isRecord$
|
|
24529
|
+
if (!isRecord$8(block)) continue;
|
|
24403
24530
|
if (block.type === "image") {
|
|
24404
24531
|
const attachment = attachmentOf$1(block);
|
|
24405
24532
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -24420,7 +24547,7 @@ function requestImageBytes$1(block) {
|
|
|
24420
24547
|
function collectRequestImageBytes$1(content, lengths) {
|
|
24421
24548
|
if (!Array.isArray(content)) return;
|
|
24422
24549
|
for (const block of content) {
|
|
24423
|
-
if (!isRecord$
|
|
24550
|
+
if (!isRecord$8(block) || block.type !== "image") continue;
|
|
24424
24551
|
const bytes = requestImageBytes$1(block);
|
|
24425
24552
|
if (bytes !== void 0) lengths.push(bytes);
|
|
24426
24553
|
}
|
|
@@ -24447,7 +24574,7 @@ function offloadOldestRequestImages$1(options) {
|
|
|
24447
24574
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
24448
24575
|
let replaced = false;
|
|
24449
24576
|
const content = message.content.map((block) => {
|
|
24450
|
-
if (remaining.count === 0 || !isRecord$
|
|
24577
|
+
if (remaining.count === 0 || !isRecord$8(block) || block.type !== "image") return block;
|
|
24451
24578
|
if (requestImageBytes$1(block) === void 0) return block;
|
|
24452
24579
|
remaining.count -= 1;
|
|
24453
24580
|
replaced = true;
|
|
@@ -24501,7 +24628,7 @@ function unavailableImageText$1(block) {
|
|
|
24501
24628
|
}
|
|
24502
24629
|
function imageBlockToInline$1(block, images) {
|
|
24503
24630
|
let data = asString$4(block.data) || asString$4(block.base64);
|
|
24504
|
-
const source = isRecord$
|
|
24631
|
+
const source = isRecord$8(block.source) ? block.source : void 0;
|
|
24505
24632
|
if (!data && source) data = asString$4(source.data) || asString$4(source.base64);
|
|
24506
24633
|
let mediaType = asString$4(block.mimeType) || asString$4(block.mediaType) || (source ? asString$4(source.mimeType) || asString$4(source.mediaType) : void 0) || "image/png";
|
|
24507
24634
|
if (data?.startsWith("data:")) {
|
|
@@ -24527,7 +24654,7 @@ function textOf$1(content) {
|
|
|
24527
24654
|
if (!Array.isArray(content)) return "";
|
|
24528
24655
|
const parts = [];
|
|
24529
24656
|
for (const block of content) {
|
|
24530
|
-
if (!isRecord$
|
|
24657
|
+
if (!isRecord$8(block)) continue;
|
|
24531
24658
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText$1(block.text));
|
|
24532
24659
|
else if (block.type === "tool-result") parts.push(textOf$1(block.content));
|
|
24533
24660
|
}
|
|
@@ -24536,7 +24663,7 @@ function textOf$1(content) {
|
|
|
24536
24663
|
function toolResultText$1(blocks) {
|
|
24537
24664
|
if (!Array.isArray(blocks)) return "";
|
|
24538
24665
|
return blocks.map((block) => {
|
|
24539
|
-
if (!isRecord$
|
|
24666
|
+
if (!isRecord$8(block)) return "";
|
|
24540
24667
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText$1(block.text);
|
|
24541
24668
|
if (block.type === "tool-result") return toolResultText$1(block.content);
|
|
24542
24669
|
if (block.type === "image") return `[image: ${attachmentLabel$1(block) ?? "attached image"}]`;
|
|
@@ -24548,7 +24675,7 @@ function toolResultImageBlocks(blocks, images) {
|
|
|
24548
24675
|
if (!Array.isArray(blocks)) return [];
|
|
24549
24676
|
const out = [];
|
|
24550
24677
|
for (const block of blocks) {
|
|
24551
|
-
if (!isRecord$
|
|
24678
|
+
if (!isRecord$8(block)) continue;
|
|
24552
24679
|
if (block.type === "image") {
|
|
24553
24680
|
const inline = imageBlockToInline$1(block, images);
|
|
24554
24681
|
if (inline && SUPPORTED_IMAGE_MEDIA_TYPES$1.has(inline.mediaType)) out.push({
|
|
@@ -24593,7 +24720,7 @@ function leadingSystemText$1(options) {
|
|
|
24593
24720
|
}
|
|
24594
24721
|
/** Drop the JSON-Schema keywords provider gateways reject or ignore. */
|
|
24595
24722
|
function stripMetaSchema(schema) {
|
|
24596
|
-
if (!isRecord$
|
|
24723
|
+
if (!isRecord$8(schema)) return {
|
|
24597
24724
|
type: "object",
|
|
24598
24725
|
properties: {}
|
|
24599
24726
|
};
|
|
@@ -24606,7 +24733,7 @@ function openAIUserContent(message, images) {
|
|
|
24606
24733
|
const parts = [];
|
|
24607
24734
|
let hasImage = false;
|
|
24608
24735
|
for (const block of message.content) {
|
|
24609
|
-
if (!isRecord$
|
|
24736
|
+
if (!isRecord$8(block)) continue;
|
|
24610
24737
|
if (block.type === "text" && typeof block.text === "string") {
|
|
24611
24738
|
const text = sanitizeText$1(block.text);
|
|
24612
24739
|
if (text !== "") parts.push({
|
|
@@ -24634,7 +24761,7 @@ function openAIAssistantContent(message) {
|
|
|
24634
24761
|
const textParts = [];
|
|
24635
24762
|
const toolCalls = [];
|
|
24636
24763
|
for (const block of message.content) {
|
|
24637
|
-
if (!isRecord$
|
|
24764
|
+
if (!isRecord$8(block)) continue;
|
|
24638
24765
|
if (block.type === "text" && typeof block.text === "string") textParts.push(sanitizeText$1(block.text));
|
|
24639
24766
|
else if (block.type === "tool-call" && typeof block.name === "string") toolCalls.push({
|
|
24640
24767
|
id: typeof block.id === "string" && block.id !== "" ? block.id : `call_${toolCalls.length}`,
|
|
@@ -24670,7 +24797,7 @@ function buildChatRequest(options, images = NO_RESOLVED_IMAGES$1) {
|
|
|
24670
24797
|
while (index < conversation.length && isToolResultMessage$1(conversation[index])) {
|
|
24671
24798
|
const current = conversation[index];
|
|
24672
24799
|
const block = current.content[0];
|
|
24673
|
-
const callId = isRecord$
|
|
24800
|
+
const callId = isRecord$8(block) && typeof block.toolCallId === "string" ? block.toolCallId : "";
|
|
24674
24801
|
messages.push({
|
|
24675
24802
|
role: "tool",
|
|
24676
24803
|
tool_call_id: callId,
|
|
@@ -24810,24 +24937,24 @@ function processStreamLine$1(line, state) {
|
|
|
24810
24937
|
}
|
|
24811
24938
|
if (payload === "") return [];
|
|
24812
24939
|
const chunk = safeJsonParse$1(payload);
|
|
24813
|
-
if (!isRecord$
|
|
24940
|
+
if (!isRecord$8(chunk)) return [];
|
|
24814
24941
|
const out = [];
|
|
24815
|
-
const errorPayload = isRecord$
|
|
24942
|
+
const errorPayload = isRecord$8(chunk.error) ? chunk.error : void 0;
|
|
24816
24943
|
if (errorPayload !== void 0) throw new LlmError$1(`WorkBuddy stream error: ${asString$4(errorPayload.message) ?? "unknown error"}`, "PROVIDER_ERROR");
|
|
24817
|
-
const usage = isRecord$
|
|
24944
|
+
const usage = isRecord$8(chunk.usage) ? chunk.usage : void 0;
|
|
24818
24945
|
if (usage) {
|
|
24819
24946
|
state.sawUsage = true;
|
|
24820
24947
|
const prompt = numberOr$1(usage.prompt_tokens, 0);
|
|
24821
|
-
const details = isRecord$
|
|
24948
|
+
const details = isRecord$8(usage.prompt_tokens_details) ? usage.prompt_tokens_details : void 0;
|
|
24822
24949
|
const cached = details ? numberOr$1(details.cached_tokens, 0) : 0;
|
|
24823
24950
|
state.inputTokens = Math.max(0, prompt - cached);
|
|
24824
24951
|
state.cacheReadTokens = cached;
|
|
24825
24952
|
state.outputTokens = numberOr$1(usage.completion_tokens, state.outputTokens);
|
|
24826
|
-
if (isRecord$
|
|
24953
|
+
if (isRecord$8(usage.completion_tokens_details)) state.reasoningTokens = numberOr$1(usage.completion_tokens_details.reasoning_tokens, state.reasoningTokens);
|
|
24827
24954
|
}
|
|
24828
24955
|
const choices = Array.isArray(chunk.choices) ? chunk.choices : [];
|
|
24829
|
-
const choice = isRecord$
|
|
24830
|
-
const delta = choice && isRecord$
|
|
24956
|
+
const choice = isRecord$8(choices[0]) ? choices[0] : void 0;
|
|
24957
|
+
const delta = choice && isRecord$8(choice.delta) ? choice.delta : void 0;
|
|
24831
24958
|
if (delta) {
|
|
24832
24959
|
const reasoning = asString$4(delta.reasoning_content) ?? asString$4(delta.reasoning);
|
|
24833
24960
|
if (reasoning !== void 0 && reasoning !== "") {
|
|
@@ -24855,7 +24982,7 @@ function processStreamLine$1(line, state) {
|
|
|
24855
24982
|
}
|
|
24856
24983
|
const toolDeltas = Array.isArray(delta.tool_calls) ? delta.tool_calls : [];
|
|
24857
24984
|
for (const entry of toolDeltas) {
|
|
24858
|
-
if (!isRecord$
|
|
24985
|
+
if (!isRecord$8(entry)) continue;
|
|
24859
24986
|
out.push(...applyToolDelta(entry, state));
|
|
24860
24987
|
}
|
|
24861
24988
|
}
|
|
@@ -24869,7 +24996,7 @@ function processStreamLine$1(line, state) {
|
|
|
24869
24996
|
}
|
|
24870
24997
|
function applyToolDelta(entry, state) {
|
|
24871
24998
|
const wireIndex = typeof entry.index === "number" ? entry.index : 0;
|
|
24872
|
-
const fn = isRecord$
|
|
24999
|
+
const fn = isRecord$8(entry.function) ? entry.function : {};
|
|
24873
25000
|
const out = [];
|
|
24874
25001
|
let call = state.toolCalls.get(wireIndex);
|
|
24875
25002
|
if (call === void 0) {
|
|
@@ -26590,7 +26717,7 @@ function defaultClaudeSettings() {
|
|
|
26590
26717
|
selectedAccountId: null
|
|
26591
26718
|
};
|
|
26592
26719
|
}
|
|
26593
|
-
function isRecord$
|
|
26720
|
+
function isRecord$7(value) {
|
|
26594
26721
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26595
26722
|
}
|
|
26596
26723
|
/**
|
|
@@ -26694,7 +26821,7 @@ function normalizeScopes$1(value) {
|
|
|
26694
26821
|
throw new Error("Claude credential scopes are invalid");
|
|
26695
26822
|
}
|
|
26696
26823
|
function parseAccountInfo(value) {
|
|
26697
|
-
if (!isRecord$
|
|
26824
|
+
if (!isRecord$7(value)) return void 0;
|
|
26698
26825
|
const account = {};
|
|
26699
26826
|
const uuid = optionalString(value, "uuid");
|
|
26700
26827
|
if (uuid !== void 0) account.uuid = uuid;
|
|
@@ -26714,7 +26841,7 @@ function parseAccountInfo(value) {
|
|
|
26714
26841
|
* no `user:inference` scope is refused here (see {@link isSubscriptionCredential}).
|
|
26715
26842
|
*/
|
|
26716
26843
|
function parseClaudeCredentials(value) {
|
|
26717
|
-
if (!isRecord$
|
|
26844
|
+
if (!isRecord$7(value)) throw new Error("Claude credential payload is invalid");
|
|
26718
26845
|
const accessToken = nonEmptyString$3(value.accessToken);
|
|
26719
26846
|
if (accessToken === void 0) throw new Error("Claude credential is missing its access token");
|
|
26720
26847
|
const refreshToken = nonEmptyString$3(value.refreshToken);
|
|
@@ -26737,7 +26864,7 @@ function parseClaudeCredentials(value) {
|
|
|
26737
26864
|
return credentials;
|
|
26738
26865
|
}
|
|
26739
26866
|
function parseAccountRecord(value) {
|
|
26740
|
-
if (!isRecord$
|
|
26867
|
+
if (!isRecord$7(value)) return null;
|
|
26741
26868
|
let credentials;
|
|
26742
26869
|
try {
|
|
26743
26870
|
credentials = parseClaudeCredentials(value.credentials);
|
|
@@ -26767,7 +26894,7 @@ function parseAccountRecord(value) {
|
|
|
26767
26894
|
* first read.
|
|
26768
26895
|
*/
|
|
26769
26896
|
function parseClaudeCredentialDocument(value) {
|
|
26770
|
-
if (!isRecord$
|
|
26897
|
+
if (!isRecord$7(value)) throw new Error("Claude credential file payload is invalid");
|
|
26771
26898
|
if (!Array.isArray(value.accounts)) {
|
|
26772
26899
|
if (value.accessToken !== void 0 || value.refreshToken !== void 0) {
|
|
26773
26900
|
const credentials = parseClaudeCredentials(value);
|
|
@@ -26814,11 +26941,11 @@ function parseClaudeCredentialDocument(value) {
|
|
|
26814
26941
|
* schemastery strips undeclared keys instead of failing on them.
|
|
26815
26942
|
*/
|
|
26816
26943
|
function parseClaudeModelSettings(value) {
|
|
26817
|
-
const record = isRecord$
|
|
26944
|
+
const record = isRecord$7(value) ? value : {};
|
|
26818
26945
|
const defaults = defaultClaudeSettings();
|
|
26819
26946
|
const enabledModelIds = Array.isArray(record.enabledModelIds) ? record.enabledModelIds.filter((id) => typeof id === "string" && id.trim() !== "") : defaults.enabledModelIds;
|
|
26820
26947
|
const contextWindowOverrides = {};
|
|
26821
|
-
if (isRecord$
|
|
26948
|
+
if (isRecord$7(record.contextWindowOverrides)) {
|
|
26822
26949
|
for (const [model, window] of Object.entries(record.contextWindowOverrides)) if (typeof window === "number" && Number.isFinite(window) && window > 0) contextWindowOverrides[model] = window;
|
|
26823
26950
|
}
|
|
26824
26951
|
const defaultReasoningEffort = nonEmptyString$3(record.defaultReasoningEffort) ?? null;
|
|
@@ -27237,11 +27364,11 @@ function registerClaudePreferenceStore(settings, fallbackStore = new FileModelSe
|
|
|
27237
27364
|
* them can pass. That distinction is exported as a first-class value rather
|
|
27238
27365
|
* than left for the caller to re-derive from headers.
|
|
27239
27366
|
*/
|
|
27240
|
-
function isRecord$
|
|
27367
|
+
function isRecord$6(value) {
|
|
27241
27368
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27242
27369
|
}
|
|
27243
27370
|
function asRecord$3(value) {
|
|
27244
|
-
return isRecord$
|
|
27371
|
+
return isRecord$6(value) ? value : void 0;
|
|
27245
27372
|
}
|
|
27246
27373
|
/** A non-blank string, or undefined. Numeric values are NOT coerced here. */
|
|
27247
27374
|
function asString$3(value) {
|
|
@@ -28200,7 +28327,7 @@ function classifyFailure(status, bodyText, headers = {}) {
|
|
|
28200
28327
|
* land the breakpoint on a block the merge then moves back, which leaves a
|
|
28201
28328
|
* marker in the request that caches nothing the next turn can reuse.
|
|
28202
28329
|
*/
|
|
28203
|
-
function isRecord$
|
|
28330
|
+
function isRecord$5(value) {
|
|
28204
28331
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28205
28332
|
}
|
|
28206
28333
|
function asString$2(value) {
|
|
@@ -28619,17 +28746,17 @@ const SUPPORTED_IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
28619
28746
|
]);
|
|
28620
28747
|
function attachmentOf(block) {
|
|
28621
28748
|
const attachment = block.attachment;
|
|
28622
|
-
if (!isRecord$
|
|
28749
|
+
if (!isRecord$5(attachment)) return void 0;
|
|
28623
28750
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
28624
28751
|
}
|
|
28625
28752
|
function attachmentLabel(block) {
|
|
28626
|
-
const attachment = isRecord$
|
|
28753
|
+
const attachment = isRecord$5(block.attachment) ? block.attachment : void 0;
|
|
28627
28754
|
return asString$2(attachment?.name) || asString$2(attachment?.attachmentId);
|
|
28628
28755
|
}
|
|
28629
28756
|
function collectImageRefs(content, refs) {
|
|
28630
28757
|
if (!Array.isArray(content)) return;
|
|
28631
28758
|
for (const block of content) {
|
|
28632
|
-
if (!isRecord$
|
|
28759
|
+
if (!isRecord$5(block)) continue;
|
|
28633
28760
|
if (block.type === "image") {
|
|
28634
28761
|
const attachment = attachmentOf(block);
|
|
28635
28762
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -28650,7 +28777,7 @@ function requestImageBytes(block) {
|
|
|
28650
28777
|
function collectRequestImageBytes(content, lengths) {
|
|
28651
28778
|
if (!Array.isArray(content)) return;
|
|
28652
28779
|
for (const block of content) {
|
|
28653
|
-
if (!isRecord$
|
|
28780
|
+
if (!isRecord$5(block) || block.type !== "image") continue;
|
|
28654
28781
|
const bytes = requestImageBytes(block);
|
|
28655
28782
|
if (bytes !== void 0) lengths.push(bytes);
|
|
28656
28783
|
}
|
|
@@ -28679,7 +28806,7 @@ function offloadOldestRequestImages(options) {
|
|
|
28679
28806
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
28680
28807
|
let replaced = false;
|
|
28681
28808
|
const content = message.content.map((block) => {
|
|
28682
|
-
if (remaining.count === 0 || !isRecord$
|
|
28809
|
+
if (remaining.count === 0 || !isRecord$5(block) || block.type !== "image") return block;
|
|
28683
28810
|
if (requestImageBytes(block) === void 0) return block;
|
|
28684
28811
|
remaining.count -= 1;
|
|
28685
28812
|
replaced = true;
|
|
@@ -28737,7 +28864,7 @@ async function resolveRequestImages(options, attachments, signal) {
|
|
|
28737
28864
|
*/
|
|
28738
28865
|
function imageBlockToInline(block, images) {
|
|
28739
28866
|
let data = asString$2(block.data) || asString$2(block.base64);
|
|
28740
|
-
const source = isRecord$
|
|
28867
|
+
const source = isRecord$5(block.source) ? block.source : void 0;
|
|
28741
28868
|
if (!data && source) data = asString$2(source.data) || asString$2(source.base64);
|
|
28742
28869
|
let mediaType = asString$2(block.mimeType) || asString$2(block.mediaType) || (source ? asString$2(source.mimeType) || asString$2(source.mediaType) : void 0) || "image/png";
|
|
28743
28870
|
if (data?.startsWith("data:")) {
|
|
@@ -28791,7 +28918,7 @@ function textOf(content) {
|
|
|
28791
28918
|
if (!Array.isArray(content)) return "";
|
|
28792
28919
|
const parts = [];
|
|
28793
28920
|
for (const block of content) {
|
|
28794
|
-
if (!isRecord$
|
|
28921
|
+
if (!isRecord$5(block)) continue;
|
|
28795
28922
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText(block.text));
|
|
28796
28923
|
else if (block.type === "tool-result") parts.push(textOf(block.content));
|
|
28797
28924
|
}
|
|
@@ -28835,15 +28962,15 @@ function replayBlockFor(message, index) {
|
|
|
28835
28962
|
const source = message.source;
|
|
28836
28963
|
if (source === void 0 || source.kind !== "model") return void 0;
|
|
28837
28964
|
const state = source.replayState;
|
|
28838
|
-
if (!isRecord$
|
|
28965
|
+
if (!isRecord$5(state)) return void 0;
|
|
28839
28966
|
if (Array.isArray(state.blocks)) {
|
|
28840
28967
|
const entry = state.blocks[index];
|
|
28841
|
-
return isRecord$
|
|
28968
|
+
return isRecord$5(entry) ? entry : void 0;
|
|
28842
28969
|
}
|
|
28843
|
-
const response = isRecord$
|
|
28970
|
+
const response = isRecord$5(state.response) ? state.response : void 0;
|
|
28844
28971
|
const blocks = response !== void 0 && Array.isArray(response.blocks) ? response.blocks : void 0;
|
|
28845
28972
|
const entry = blocks === void 0 ? void 0 : blocks[index];
|
|
28846
|
-
return isRecord$
|
|
28973
|
+
return isRecord$5(entry) ? entry : void 0;
|
|
28847
28974
|
}
|
|
28848
28975
|
/**
|
|
28849
28976
|
* Concatenated system-prompt text, or undefined when the caller stated none.
|
|
@@ -28957,7 +29084,7 @@ function markClaudeCacheBreakpoints(body) {
|
|
|
28957
29084
|
}
|
|
28958
29085
|
/** One tool definition in the wire shape. */
|
|
28959
29086
|
function wireTool(tool, names) {
|
|
28960
|
-
const schema = isRecord$
|
|
29087
|
+
const schema = isRecord$5(tool.parameters) ? { ...tool.parameters } : {
|
|
28961
29088
|
type: "object",
|
|
28962
29089
|
properties: {}
|
|
28963
29090
|
};
|
|
@@ -28979,7 +29106,7 @@ function claudeUserContent(message, images) {
|
|
|
28979
29106
|
return blocks;
|
|
28980
29107
|
}
|
|
28981
29108
|
for (const block of message.content) {
|
|
28982
|
-
if (!isRecord$
|
|
29109
|
+
if (!isRecord$5(block)) continue;
|
|
28983
29110
|
if (block.type === "text" && typeof block.text === "string") {
|
|
28984
29111
|
const text = sanitizeText(block.text);
|
|
28985
29112
|
if (text !== "") blocks.push({
|
|
@@ -28999,7 +29126,7 @@ function claudeUserContent(message, images) {
|
|
|
28999
29126
|
/** Whether one message is the flattened 0.1.7 tool result (see isToolResultMessage). */
|
|
29000
29127
|
function isFlattenedToolMessage(message) {
|
|
29001
29128
|
if (message.role !== "tool") return false;
|
|
29002
|
-
return !message.content.some((block) => isRecord$
|
|
29129
|
+
return !message.content.some((block) => isRecord$5(block) && block.type === "tool-result");
|
|
29003
29130
|
}
|
|
29004
29131
|
/**
|
|
29005
29132
|
* One tool_result block.
|
|
@@ -29025,7 +29152,7 @@ function toolResultBlockFor(toolUseId, resultBlocks, isError, images) {
|
|
|
29025
29152
|
function toolResultText(blocks) {
|
|
29026
29153
|
if (!Array.isArray(blocks)) return "";
|
|
29027
29154
|
return blocks.map((block) => {
|
|
29028
|
-
if (!isRecord$
|
|
29155
|
+
if (!isRecord$5(block)) return "";
|
|
29029
29156
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText(block.text);
|
|
29030
29157
|
if (block.type === "tool-result") return toolResultText(block.content);
|
|
29031
29158
|
if (block.type === "image") {
|
|
@@ -29045,7 +29172,7 @@ function toolResultContent(blocks, images) {
|
|
|
29045
29172
|
const out = [];
|
|
29046
29173
|
let hasImage = false;
|
|
29047
29174
|
for (const block of blocks) {
|
|
29048
|
-
if (!isRecord$
|
|
29175
|
+
if (!isRecord$5(block)) continue;
|
|
29049
29176
|
if (block.type === "text" && typeof block.text === "string") {
|
|
29050
29177
|
out.push({
|
|
29051
29178
|
type: "text",
|
|
@@ -29079,7 +29206,7 @@ function claudeAssistantContent(message, names) {
|
|
|
29079
29206
|
if (!Array.isArray(message.content)) return blocks;
|
|
29080
29207
|
for (let index = 0; index < message.content.length; index++) {
|
|
29081
29208
|
const block = message.content[index];
|
|
29082
|
-
if (!isRecord$
|
|
29209
|
+
if (!isRecord$5(block)) continue;
|
|
29083
29210
|
if (block.type === "text" && typeof block.text === "string") {
|
|
29084
29211
|
const text = sanitizeText(block.text);
|
|
29085
29212
|
if (text !== "") blocks.push({
|
|
@@ -29094,7 +29221,7 @@ function claudeAssistantContent(message, names) {
|
|
|
29094
29221
|
type: "tool_use",
|
|
29095
29222
|
id: typeof block.id === "string" && block.id !== "" ? block.id : "toolu_" + blocks.length,
|
|
29096
29223
|
name: claudeWireToolName(block.name, names),
|
|
29097
|
-
input: isRecord$
|
|
29224
|
+
input: isRecord$5(parsed) ? parsed : {}
|
|
29098
29225
|
});
|
|
29099
29226
|
continue;
|
|
29100
29227
|
}
|
|
@@ -29118,7 +29245,7 @@ function toolCallArguments(raw) {
|
|
|
29118
29245
|
function isToolResultMessage(message) {
|
|
29119
29246
|
if (message.source?.kind === "tool") return true;
|
|
29120
29247
|
if (!Array.isArray(message.content)) return false;
|
|
29121
|
-
if (message.content.some((block) => isRecord$
|
|
29248
|
+
if (message.content.some((block) => isRecord$5(block) && block.type === "tool-result")) return true;
|
|
29122
29249
|
return message.role === "tool";
|
|
29123
29250
|
}
|
|
29124
29251
|
/**
|
|
@@ -29471,13 +29598,13 @@ function processStreamLine(line, state) {
|
|
|
29471
29598
|
const payload = trimmed.slice(5).trim();
|
|
29472
29599
|
if (payload === "" || payload === "[DONE]") return [];
|
|
29473
29600
|
const event = safeJsonParse(payload);
|
|
29474
|
-
if (!isRecord$
|
|
29601
|
+
if (!isRecord$5(event)) return [];
|
|
29475
29602
|
const type = asString$2(event.type);
|
|
29476
29603
|
const out = [];
|
|
29477
29604
|
if (type === "message_start") {
|
|
29478
29605
|
state.sawMessageStart = true;
|
|
29479
|
-
const message = isRecord$
|
|
29480
|
-
const usage = message !== void 0 && isRecord$
|
|
29606
|
+
const message = isRecord$5(event.message) ? event.message : void 0;
|
|
29607
|
+
const usage = message !== void 0 && isRecord$5(message.usage) ? message.usage : void 0;
|
|
29481
29608
|
if (usage !== void 0) applyUsage(state, usage, false);
|
|
29482
29609
|
const stop = message === void 0 ? void 0 : asString$2(message.stop_reason);
|
|
29483
29610
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
@@ -29485,13 +29612,13 @@ function processStreamLine(line, state) {
|
|
|
29485
29612
|
}
|
|
29486
29613
|
if (type === "content_block_start") {
|
|
29487
29614
|
const contentIndex = numberOr(event.index, -1);
|
|
29488
|
-
const block = isRecord$
|
|
29615
|
+
const block = isRecord$5(event.content_block) ? event.content_block : {};
|
|
29489
29616
|
const blockType = asString$2(block.type);
|
|
29490
29617
|
if (blockType === "tool_use") {
|
|
29491
29618
|
const index = state.blocks.length;
|
|
29492
29619
|
const id = asString$2(block.id) ?? "toolu_" + String(index);
|
|
29493
29620
|
const name = claudeOriginalToolName(asString$2(block.name) ?? "", state.toolNames);
|
|
29494
|
-
const seedInput = isRecord$
|
|
29621
|
+
const seedInput = isRecord$5(block.input) && Object.keys(block.input).length > 0 ? JSON.stringify(block.input) : "";
|
|
29495
29622
|
const pending = {
|
|
29496
29623
|
index,
|
|
29497
29624
|
id,
|
|
@@ -29542,7 +29669,7 @@ function processStreamLine(line, state) {
|
|
|
29542
29669
|
}
|
|
29543
29670
|
if (type === "content_block_delta") {
|
|
29544
29671
|
const contentIndex = numberOr(event.index, -1);
|
|
29545
|
-
const delta = isRecord$
|
|
29672
|
+
const delta = isRecord$5(event.delta) ? event.delta : {};
|
|
29546
29673
|
const deltaType = asString$2(delta.type);
|
|
29547
29674
|
if (deltaType === "input_json_delta") {
|
|
29548
29675
|
const pending = state.toolCalls.get(contentIndex);
|
|
@@ -29591,10 +29718,10 @@ function processStreamLine(line, state) {
|
|
|
29591
29718
|
return closeTextBlock(state, contentIndex);
|
|
29592
29719
|
}
|
|
29593
29720
|
if (type === "message_delta") {
|
|
29594
|
-
const delta = isRecord$
|
|
29721
|
+
const delta = isRecord$5(event.delta) ? event.delta : void 0;
|
|
29595
29722
|
const stop = delta === void 0 ? void 0 : asString$2(delta.stop_reason);
|
|
29596
29723
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
29597
|
-
const usage = isRecord$
|
|
29724
|
+
const usage = isRecord$5(event.usage) ? event.usage : void 0;
|
|
29598
29725
|
if (usage !== void 0) applyUsage(state, usage, true);
|
|
29599
29726
|
return out;
|
|
29600
29727
|
}
|
|
@@ -29603,7 +29730,7 @@ function processStreamLine(line, state) {
|
|
|
29603
29730
|
return closeStream(state);
|
|
29604
29731
|
}
|
|
29605
29732
|
if (type === "error") {
|
|
29606
|
-
const error = isRecord$
|
|
29733
|
+
const error = isRecord$5(event.error) ? event.error : {};
|
|
29607
29734
|
const message = asString$2(error.message) ?? "unknown error";
|
|
29608
29735
|
const kind = asString$2(error.type);
|
|
29609
29736
|
throw new LlmError$1("Claude stream error" + (kind === void 0 ? "" : " (" + kind + ")") + ": " + message, "PROVIDER_ERROR");
|
|
@@ -31454,7 +31581,7 @@ const CLAUDE_CODE_CREDENTIAL_SOURCE = "claude-code";
|
|
|
31454
31581
|
* the import has to be repeated afterwards.
|
|
31455
31582
|
*/
|
|
31456
31583
|
const ADOPTED_CREDENTIAL_EXPIRED_HINT = "The sign-in imported from Claude Code has expired. Sign in again in Claude Code, then import it again from this settings card.";
|
|
31457
|
-
function isRecord$
|
|
31584
|
+
function isRecord$4(value) {
|
|
31458
31585
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31459
31586
|
}
|
|
31460
31587
|
/** A trimmed, non-empty string, or nothing. */
|
|
@@ -31617,9 +31744,9 @@ function finiteEpochMs(value) {
|
|
|
31617
31744
|
* mcpOAuth holds cannot reach the result.
|
|
31618
31745
|
*/
|
|
31619
31746
|
function parseAdoptedClaudeCredential(value, sourcePath) {
|
|
31620
|
-
if (!isRecord$
|
|
31747
|
+
if (!isRecord$4(value)) return void 0;
|
|
31621
31748
|
const oauth = value[CLAUDE_CODE_CREDENTIAL_KEY];
|
|
31622
|
-
if (!isRecord$
|
|
31749
|
+
if (!isRecord$4(oauth)) return void 0;
|
|
31623
31750
|
const accessToken = nonEmptyString$1(oauth.accessToken);
|
|
31624
31751
|
if (accessToken === void 0) return void 0;
|
|
31625
31752
|
const refreshToken = nonEmptyString$1(oauth.refreshToken);
|
|
@@ -31672,8 +31799,8 @@ async function readClaudeCodeCredentials(paths = claudeCodeCredentialPaths()) {
|
|
|
31672
31799
|
* discard an account the user added here.
|
|
31673
31800
|
*/
|
|
31674
31801
|
function isAdoptedClaudeCredential(value) {
|
|
31675
|
-
if (!isRecord$
|
|
31676
|
-
return value.adopted === true && value.source === "claude-code" && isRecord$
|
|
31802
|
+
if (!isRecord$4(value)) return false;
|
|
31803
|
+
return value.adopted === true && value.source === "claude-code" && isRecord$4(value.credentials);
|
|
31677
31804
|
}
|
|
31678
31805
|
/**
|
|
31679
31806
|
* Whether an adopted credential's access token is already unusable.
|
|
@@ -31840,7 +31967,7 @@ const ADOPTED_NEVER_REFRESHED_MESSAGE = "The sign-in imported from Claude Code i
|
|
|
31840
31967
|
function claudePoolPath() {
|
|
31841
31968
|
return path.join(dshHomeDir(), "storages", "claude-pool.json");
|
|
31842
31969
|
}
|
|
31843
|
-
function isRecord$
|
|
31970
|
+
function isRecord$3(value) {
|
|
31844
31971
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31845
31972
|
}
|
|
31846
31973
|
/** A trimmed, non-empty string, or nothing. */
|
|
@@ -31876,7 +32003,7 @@ function claudeAliasFor(credentials, position) {
|
|
|
31876
32003
|
* missing token, or an expiry that is not a finite number.
|
|
31877
32004
|
*/
|
|
31878
32005
|
function parseClaudePoolCredentials(value) {
|
|
31879
|
-
if (!isRecord$
|
|
32006
|
+
if (!isRecord$3(value)) return null;
|
|
31880
32007
|
const accessToken = nonEmptyString(value.accessToken);
|
|
31881
32008
|
const refreshToken = nonEmptyString(value.refreshToken);
|
|
31882
32009
|
if (accessToken === void 0 || refreshToken === void 0) return null;
|
|
@@ -31900,7 +32027,7 @@ function parseClaudePoolCredentials(value) {
|
|
|
31900
32027
|
}
|
|
31901
32028
|
const subscriptionType = nonEmptyString(value.subscriptionType);
|
|
31902
32029
|
if (subscriptionType !== void 0) credentials.subscriptionType = subscriptionType;
|
|
31903
|
-
if (isRecord$
|
|
32030
|
+
if (isRecord$3(value.account)) {
|
|
31904
32031
|
const uuid = nonEmptyString(value.account.uuid);
|
|
31905
32032
|
const emailAddress = nonEmptyString(value.account.email_address);
|
|
31906
32033
|
const emailCamel = nonEmptyString(value.account.emailAddress);
|
|
@@ -31990,10 +32117,10 @@ function claudeAuthRejectedReason(credentials) {
|
|
|
31990
32117
|
}
|
|
31991
32118
|
/** Validate and normalize one whole pool document. */
|
|
31992
32119
|
function parseClaudePoolData(value) {
|
|
31993
|
-
if (!isRecord$
|
|
32120
|
+
if (!isRecord$3(value)) throw new Error("Claude pool payload is invalid");
|
|
31994
32121
|
const accounts = [];
|
|
31995
32122
|
for (const item of Array.isArray(value.accounts) ? value.accounts : []) {
|
|
31996
|
-
if (!isRecord$
|
|
32123
|
+
if (!isRecord$3(item)) continue;
|
|
31997
32124
|
if (typeof item.id !== "string") continue;
|
|
31998
32125
|
const credentials = parseClaudePoolCredentials(item.credentials);
|
|
31999
32126
|
if (credentials === null) continue;
|
|
@@ -33344,23 +33471,23 @@ const CHECKIN_PATH = "/billing/meter/daily-checkin";
|
|
|
33344
33471
|
* interval keeps a long-lived process signing in on later days without a
|
|
33345
33472
|
* restart. Idle ticks cost no requests — the day state short-circuits them.
|
|
33346
33473
|
*/
|
|
33347
|
-
const CHECKIN_TICK_MS = 600 * 1e3;
|
|
33348
|
-
const CHECKIN_TIMEOUT_MS = 2e4;
|
|
33474
|
+
const CHECKIN_TICK_MS$1 = 600 * 1e3;
|
|
33475
|
+
const CHECKIN_TIMEOUT_MS$1 = 2e4;
|
|
33349
33476
|
/** State document the scheduler keeps beside the other plugin stores. */
|
|
33350
|
-
function checkinStatePath() {
|
|
33477
|
+
function checkinStatePath$1() {
|
|
33351
33478
|
return path.join(dshHomeDir(), "storages", "workbuddy-checkin.json");
|
|
33352
33479
|
}
|
|
33353
33480
|
/** Local calendar day an instant belongs to; state entries are keyed by it. */
|
|
33354
|
-
function localDateString(nowMs) {
|
|
33481
|
+
function localDateString$1(nowMs) {
|
|
33355
33482
|
const date = new Date(nowMs);
|
|
33356
33483
|
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
|
33357
33484
|
const day = `${date.getDate()}`.padStart(2, "0");
|
|
33358
33485
|
return `${date.getFullYear()}-${month}-${day}`;
|
|
33359
33486
|
}
|
|
33360
|
-
function isRecord(value) {
|
|
33487
|
+
function isRecord$2(value) {
|
|
33361
33488
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33362
33489
|
}
|
|
33363
|
-
function asCount(value) {
|
|
33490
|
+
function asCount$1(value) {
|
|
33364
33491
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
33365
33492
|
}
|
|
33366
33493
|
/**
|
|
@@ -33383,7 +33510,7 @@ function readBool(data, ...keys) {
|
|
|
33383
33510
|
function readCount(data, ...keys) {
|
|
33384
33511
|
for (const key of keys) {
|
|
33385
33512
|
const value = data[key];
|
|
33386
|
-
const direct = asCount(value);
|
|
33513
|
+
const direct = asCount$1(value);
|
|
33387
33514
|
if (direct !== void 0) return direct;
|
|
33388
33515
|
if (typeof value === "string" && value.trim() !== "") {
|
|
33389
33516
|
const parsed = Number(value);
|
|
@@ -33409,20 +33536,20 @@ function isUnauthorized(result) {
|
|
|
33409
33536
|
return result.code === 401;
|
|
33410
33537
|
}
|
|
33411
33538
|
/** Read one stored entry, keeping only the fields with the right shape. */
|
|
33412
|
-
function parseStateEntry(value) {
|
|
33413
|
-
if (!isRecord(value) || typeof value.date !== "string") return null;
|
|
33539
|
+
function parseStateEntry$1(value) {
|
|
33540
|
+
if (!isRecord$2(value) || typeof value.date !== "string") return null;
|
|
33414
33541
|
const entry = {
|
|
33415
33542
|
date: value.date,
|
|
33416
33543
|
done: value.done === true,
|
|
33417
33544
|
attempts: typeof value.attempts === "number" && Number.isFinite(value.attempts) ? value.attempts : 0
|
|
33418
33545
|
};
|
|
33419
33546
|
if (value.inactive === true) entry.inactive = true;
|
|
33420
|
-
const inactiveAt = asCount(value.inactiveAt);
|
|
33547
|
+
const inactiveAt = asCount$1(value.inactiveAt);
|
|
33421
33548
|
if (inactiveAt !== void 0) entry.inactiveAt = inactiveAt;
|
|
33422
33549
|
if (typeof value.lastError === "string") entry.lastError = value.lastError;
|
|
33423
|
-
const streakDays = asCount(value.streakDays);
|
|
33550
|
+
const streakDays = asCount$1(value.streakDays);
|
|
33424
33551
|
if (streakDays !== void 0) entry.streakDays = streakDays;
|
|
33425
|
-
const totalCredits = asCount(value.totalCredits);
|
|
33552
|
+
const totalCredits = asCount$1(value.totalCredits);
|
|
33426
33553
|
if (totalCredits !== void 0) entry.totalCredits = totalCredits;
|
|
33427
33554
|
return entry;
|
|
33428
33555
|
}
|
|
@@ -33450,7 +33577,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33450
33577
|
this.store = store;
|
|
33451
33578
|
this.options = options;
|
|
33452
33579
|
this.fetchFn = options.fetchFn ?? fetch;
|
|
33453
|
-
this.statePath = options.statePath ?? checkinStatePath();
|
|
33580
|
+
this.statePath = options.statePath ?? checkinStatePath$1();
|
|
33454
33581
|
this.now = options.now ?? (() => Date.now());
|
|
33455
33582
|
this.logger = options.logger;
|
|
33456
33583
|
}
|
|
@@ -33496,7 +33623,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33496
33623
|
if (!manual && !settings.enabled) return;
|
|
33497
33624
|
await this.load();
|
|
33498
33625
|
const nowMs = this.now();
|
|
33499
|
-
const today = localDateString(nowMs);
|
|
33626
|
+
const today = localDateString$1(nowMs);
|
|
33500
33627
|
let accounts;
|
|
33501
33628
|
try {
|
|
33502
33629
|
accounts = await this.store.list();
|
|
@@ -33538,7 +33665,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33538
33665
|
fresh = await this.forceRefresh(credentials, fresh);
|
|
33539
33666
|
status = await this.post(`${fresh.backend}${CHECKIN_STATUS_PATH}`, workBuddyHeaders(fresh));
|
|
33540
33667
|
}
|
|
33541
|
-
const statusData = isRecord(status?.data) ? status.data : {};
|
|
33668
|
+
const statusData = isRecord$2(status?.data) ? status.data : {};
|
|
33542
33669
|
if (readBool(statusData, "today_checked_in", "todayCheckedIn") === true) {
|
|
33543
33670
|
this.markSignedIn(entry, statusData);
|
|
33544
33671
|
this.logger?.info(`[workbuddy-checkin] ${id} already signed in today`);
|
|
@@ -33558,7 +33685,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33558
33685
|
fresh = await this.forceRefresh(credentials, fresh);
|
|
33559
33686
|
result = await this.post(`${fresh.backend}${CHECKIN_PATH}`, workBuddyHeaders(fresh));
|
|
33560
33687
|
}
|
|
33561
|
-
const payload = isRecord(result?.data) ? result.data : {};
|
|
33688
|
+
const payload = isRecord$2(result?.data) ? result.data : {};
|
|
33562
33689
|
if (result !== null && result.code === 0) {
|
|
33563
33690
|
this.markSignedIn(entry, payload);
|
|
33564
33691
|
this.logger?.info(`[workbuddy-checkin] ${id} signed in; total credits ${entry.totalCredits ?? "?"}`);
|
|
@@ -33620,7 +33747,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33620
33747
|
await this.load();
|
|
33621
33748
|
const settings = this.options.settings();
|
|
33622
33749
|
const accounts = (await this.store.list().catch(() => [])).filter((credentials) => !isIntlDomain(credentials.domain));
|
|
33623
|
-
const today = localDateString(this.now());
|
|
33750
|
+
const today = localDateString$1(this.now());
|
|
33624
33751
|
let doneToday = 0;
|
|
33625
33752
|
let skippedToday = 0;
|
|
33626
33753
|
let failedToday = 0;
|
|
@@ -33645,11 +33772,11 @@ var WorkBuddyCheckinService = class {
|
|
|
33645
33772
|
this.loaded = true;
|
|
33646
33773
|
try {
|
|
33647
33774
|
const parsed = JSON.parse(await fsPromises.readFile(this.statePath, "utf8"));
|
|
33648
|
-
if (isRecord(parsed)) {
|
|
33649
|
-
const lastRunAt = asCount(parsed.lastRunAt);
|
|
33775
|
+
if (isRecord$2(parsed)) {
|
|
33776
|
+
const lastRunAt = asCount$1(parsed.lastRunAt);
|
|
33650
33777
|
if (lastRunAt !== void 0) this.lastRunAt = lastRunAt;
|
|
33651
|
-
if (isRecord(parsed.accounts)) for (const [id, value] of Object.entries(parsed.accounts)) {
|
|
33652
|
-
const entry = parseStateEntry(value);
|
|
33778
|
+
if (isRecord$2(parsed.accounts)) for (const [id, value] of Object.entries(parsed.accounts)) {
|
|
33779
|
+
const entry = parseStateEntry$1(value);
|
|
33653
33780
|
if (entry !== null) this.state[id] = entry;
|
|
33654
33781
|
}
|
|
33655
33782
|
}
|
|
@@ -33673,13 +33800,13 @@ var WorkBuddyCheckinService = class {
|
|
|
33673
33800
|
method: "POST",
|
|
33674
33801
|
headers,
|
|
33675
33802
|
body: "{}",
|
|
33676
|
-
signal: AbortSignal.timeout(CHECKIN_TIMEOUT_MS)
|
|
33803
|
+
signal: AbortSignal.timeout(CHECKIN_TIMEOUT_MS$1)
|
|
33677
33804
|
});
|
|
33678
33805
|
const text = await response.text().catch(() => "");
|
|
33679
33806
|
let parsed = null;
|
|
33680
33807
|
try {
|
|
33681
33808
|
const value = JSON.parse(text);
|
|
33682
|
-
parsed = isRecord(value) ? value : null;
|
|
33809
|
+
parsed = isRecord$2(value) ? value : null;
|
|
33683
33810
|
} catch {
|
|
33684
33811
|
parsed = null;
|
|
33685
33812
|
}
|
|
@@ -33692,6 +33819,660 @@ var WorkBuddyCheckinService = class {
|
|
|
33692
33819
|
}
|
|
33693
33820
|
};
|
|
33694
33821
|
//#endregion
|
|
33822
|
+
//#region src/host/minimax-code/checkin-gateway.ts
|
|
33823
|
+
/**
|
|
33824
|
+
* Wire half of the MiniMax Code daily check-in.
|
|
33825
|
+
*
|
|
33826
|
+
* Everything in this file is measured against, or ported from, the official
|
|
33827
|
+
* client's own open source (`MiniMax-AI/minimax-code`, MIT):
|
|
33828
|
+
* `packages/tui/src/checkin/http-gateway.ts` does the two check-in calls and
|
|
33829
|
+
* `packages/tui/src/runtime/public-gateway.ts` builds the request. The wire
|
|
33830
|
+
* shape was additionally verified live against the CN deployment with this
|
|
33831
|
+
* machine's own credential (see the 0.2.0-rc.1-era probe notes in the
|
|
33832
|
+
* changelog): `GET signin/status` and `POST signin/claim` answer exactly the
|
|
33833
|
+
* shapes validated below, and a duplicate claim answers
|
|
33834
|
+
* `claim_result: 2` (AlreadyClaimed) rather than an error.
|
|
33835
|
+
*
|
|
33836
|
+
* The `yy` / `x-timestamp` / `x-signature` headers are the same first-party
|
|
33837
|
+
* attribution literals this package's `types.ts` product-token note discusses.
|
|
33838
|
+
* The official source's own comment calls them wire-protocol constants that
|
|
33839
|
+
* are "not credentials or a security boundary" — authorization is the Bearer
|
|
33840
|
+
* token. Unlike the quota read (where they are optional and stay off by
|
|
33841
|
+
* default), the check-in gateway refuses requests without them, so this
|
|
33842
|
+
* feature cannot exist without sending them; that trade is recorded in the
|
|
33843
|
+
* changelog and was made explicitly, not by default. The User-Agent stays the
|
|
33844
|
+
* plugin's own honest one — it is NOT part of the signed surface.
|
|
33845
|
+
*/
|
|
33846
|
+
/** Activity status surface; answers whether today is claimable or claimed. */
|
|
33847
|
+
const SIGNIN_STATUS_PATH = "/minimax-cloud/api/v1/signin/status";
|
|
33848
|
+
/** Check-in surface; credits are granted by posting here once a day. */
|
|
33849
|
+
const SIGNIN_CLAIM_PATH = "/minimax-cloud/api/v1/signin/claim";
|
|
33850
|
+
/** Account identity surface; resolves the realUserID the query string needs. */
|
|
33851
|
+
const USER_INFO_PATH = "/v1/api/user/info";
|
|
33852
|
+
/**
|
|
33853
|
+
* Salt the first-party clients mix into `x-signature`.
|
|
33854
|
+
*
|
|
33855
|
+
* Inline in the official client's public bundle and in its open-source CLI
|
|
33856
|
+
* (`public-gateway.ts`); the comment there calls it a wire-protocol constant,
|
|
33857
|
+
* since changing it needs a coordinated server-side rollout.
|
|
33858
|
+
*/
|
|
33859
|
+
const SIGNATURE_SALT = "I*7Cf%WZ#S&%1RlZJ&C2";
|
|
33860
|
+
function md5(value) {
|
|
33861
|
+
return createHash("md5").update(value).digest("hex");
|
|
33862
|
+
}
|
|
33863
|
+
/** Origin the official client uses for this surface, per region. */
|
|
33864
|
+
function checkinGatewayOrigin(region) {
|
|
33865
|
+
return region === "cn" ? "https://agent.minimaxi.com" : "https://agent.minimax.io";
|
|
33866
|
+
}
|
|
33867
|
+
const DAY_STATUSES = /* @__PURE__ */ new Set([
|
|
33868
|
+
1,
|
|
33869
|
+
2,
|
|
33870
|
+
3,
|
|
33871
|
+
4
|
|
33872
|
+
]);
|
|
33873
|
+
const CLAIM_RESULTS = /* @__PURE__ */ new Set([1, 2]);
|
|
33874
|
+
const PANEL_SCENES = /* @__PURE__ */ new Set([
|
|
33875
|
+
0,
|
|
33876
|
+
1,
|
|
33877
|
+
2,
|
|
33878
|
+
3,
|
|
33879
|
+
4
|
|
33880
|
+
]);
|
|
33881
|
+
/**
|
|
33882
|
+
* Validate one panel response. Ported from the official
|
|
33883
|
+
* `validateSigninPanel`: exactly seven days, day numbers 1..7 without
|
|
33884
|
+
* repeats, at most one claimable and at most one "today". A panel that fails
|
|
33885
|
+
* this is a wire surprise, and treating it as "nothing to do" would silently
|
|
33886
|
+
* skip the day, so validation throws.
|
|
33887
|
+
*/
|
|
33888
|
+
function validateSigninPanel(value) {
|
|
33889
|
+
const panel = value;
|
|
33890
|
+
const days = panel?.days;
|
|
33891
|
+
const dayNumbers = /* @__PURE__ */ new Set();
|
|
33892
|
+
let claimableDays = 0;
|
|
33893
|
+
let todayDays = 0;
|
|
33894
|
+
const validDays = Array.isArray(days) && days.length === 7 && days.every((day) => {
|
|
33895
|
+
if (day === null || typeof day !== "object") return false;
|
|
33896
|
+
const item = day;
|
|
33897
|
+
const dayNo = item.day_no;
|
|
33898
|
+
if (typeof dayNo !== "number" || !Number.isInteger(dayNo) || dayNo < 1 || dayNo > 7 || dayNumbers.has(dayNo)) return false;
|
|
33899
|
+
if (typeof item.points !== "number" || !Number.isFinite(item.points) || item.points < 0) return false;
|
|
33900
|
+
if (item.bonus_points !== void 0 && (typeof item.bonus_points !== "number" || !Number.isFinite(item.bonus_points) || item.bonus_points < 0)) return false;
|
|
33901
|
+
if (typeof item.is_today !== "boolean" || !DAY_STATUSES.has(item.status)) return false;
|
|
33902
|
+
dayNumbers.add(dayNo);
|
|
33903
|
+
if (item.status === 2) claimableDays += 1;
|
|
33904
|
+
if (item.is_today === true) todayDays += 1;
|
|
33905
|
+
return true;
|
|
33906
|
+
});
|
|
33907
|
+
if (panel === null || typeof panel !== "object" || !PANEL_SCENES.has(panel.scene) || !validDays || claimableDays > 1 || todayDays > 1) throw new Error("Invalid sign-in panel");
|
|
33908
|
+
return panel;
|
|
33909
|
+
}
|
|
33910
|
+
/** Validate one claim response. Ported from the official `validateClaimSigninData`. */
|
|
33911
|
+
function validateClaimSigninData(value) {
|
|
33912
|
+
const data = value;
|
|
33913
|
+
if (!(data !== null && typeof data === "object" && typeof data.claim_id === "string" && data.claim_id.length > 0 && CLAIM_RESULTS.has(data.claim_result) && Number.isInteger(data.day_no) && (data.day_no ?? 0) >= 1 && (data.day_no ?? 8) <= 7 && typeof data.points === "number" && Number.isFinite(data.points) && data.points >= 0 && typeof data.expire_at_ms === "number" && Number.isFinite(data.expire_at_ms))) throw new Error("Invalid sign-in claim response");
|
|
33914
|
+
return {
|
|
33915
|
+
...data,
|
|
33916
|
+
panel: validateSigninPanel(data.panel)
|
|
33917
|
+
};
|
|
33918
|
+
}
|
|
33919
|
+
/**
|
|
33920
|
+
* The consecutive-claimed count ending today, from one panel.
|
|
33921
|
+
*
|
|
33922
|
+
* Ported from the official `getCurrentSigninStreak`: when today is claimed it
|
|
33923
|
+
* counts; when today is still claimable the streak up to yesterday is what a
|
|
33924
|
+
* claim would extend, so that is what the card shows.
|
|
33925
|
+
*/
|
|
33926
|
+
function currentSigninStreak(days) {
|
|
33927
|
+
const sorted = [...days].sort((left, right) => left.day_no - right.day_no);
|
|
33928
|
+
const todayIndex = sorted.findIndex((day) => day.is_today);
|
|
33929
|
+
if (todayIndex < 0) return 0;
|
|
33930
|
+
const todayStatus = sorted[todayIndex]?.status;
|
|
33931
|
+
let index = todayStatus === 3 ? todayIndex : todayStatus === 2 ? todayIndex - 1 : -1;
|
|
33932
|
+
if (index < 0) return 0;
|
|
33933
|
+
let streak = 0;
|
|
33934
|
+
for (; index >= 0; index -= 1) {
|
|
33935
|
+
if (sorted[index]?.status !== 3) break;
|
|
33936
|
+
streak += 1;
|
|
33937
|
+
}
|
|
33938
|
+
return streak;
|
|
33939
|
+
}
|
|
33940
|
+
function isRecord$1(value) {
|
|
33941
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33942
|
+
}
|
|
33943
|
+
function readString(record, ...keys) {
|
|
33944
|
+
if (record === void 0) return void 0;
|
|
33945
|
+
for (const key of keys) {
|
|
33946
|
+
const value = record[key];
|
|
33947
|
+
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
33948
|
+
}
|
|
33949
|
+
}
|
|
33950
|
+
/**
|
|
33951
|
+
* One signed request, built the way the official CLI builds it
|
|
33952
|
+
* (`createPublicGatewayRequest`).
|
|
33953
|
+
*
|
|
33954
|
+
* The query constants (`device_platform=web`, `is_desktop=1`, `client=mcode`,
|
|
33955
|
+
* `browser_name=mcode`, `device_id=0`) are the gateway's protocol vocabulary
|
|
33956
|
+
* for this surface, copied verbatim; `desktop_version` reports THIS plugin's
|
|
33957
|
+
* version, because it is the version field of the client making the request
|
|
33958
|
+
* and inventing the official app's number would be the one genuinely false
|
|
33959
|
+
* statement available here. `yy` hashes the millisecond clock while
|
|
33960
|
+
* `x-timestamp` / `x-signature` use whole seconds — both spellings are in
|
|
33961
|
+
* the official source and the mismatch is deliberate, not a typo to fix.
|
|
33962
|
+
*/
|
|
33963
|
+
function createCheckinRequest(input) {
|
|
33964
|
+
const url = new URL(input.origin + input.path);
|
|
33965
|
+
url.search = new URLSearchParams({
|
|
33966
|
+
device_platform: "web",
|
|
33967
|
+
biz_id: "3",
|
|
33968
|
+
app_id: "3001",
|
|
33969
|
+
version_code: "22201",
|
|
33970
|
+
is_desktop: "1",
|
|
33971
|
+
desktop_version: input.appVersion,
|
|
33972
|
+
unix: String(input.nowMs),
|
|
33973
|
+
timezone_offset: String((/* @__PURE__ */ new Date()).getTimezoneOffset() * -60),
|
|
33974
|
+
sys_language: input.language,
|
|
33975
|
+
lang: input.language,
|
|
33976
|
+
device_id: "0",
|
|
33977
|
+
os_name: process.platform,
|
|
33978
|
+
browser_name: "mcode",
|
|
33979
|
+
user_id: input.realUserID,
|
|
33980
|
+
client: "mcode"
|
|
33981
|
+
}).toString();
|
|
33982
|
+
const second = Math.floor(input.nowMs / 1e3);
|
|
33983
|
+
const pathWithSearch = `${url.pathname}${url.search}`;
|
|
33984
|
+
const signatureBody = input.body ?? "";
|
|
33985
|
+
const yyBody = input.body ?? "{}";
|
|
33986
|
+
return {
|
|
33987
|
+
url,
|
|
33988
|
+
headers: {
|
|
33989
|
+
accept: "application/json",
|
|
33990
|
+
"content-type": "application/json",
|
|
33991
|
+
"user-agent": USER_AGENT,
|
|
33992
|
+
authorization: `Bearer ${input.accessToken}`,
|
|
33993
|
+
yy: md5(`${encodeURIComponent(pathWithSearch)}_${yyBody}${md5(String(input.nowMs))}ooui`),
|
|
33994
|
+
"x-timestamp": String(second),
|
|
33995
|
+
"x-signature": md5(`${second}${SIGNATURE_SALT}${signatureBody}`)
|
|
33996
|
+
}
|
|
33997
|
+
};
|
|
33998
|
+
}
|
|
33999
|
+
/**
|
|
34000
|
+
* The identity call uses the matrix account surface's own query vocabulary
|
|
34001
|
+
* (`device_platform=mcode`, no `is_desktop`/`desktop_version`) — the two
|
|
34002
|
+
* surfaces spell the same device differently in the official client, and the
|
|
34003
|
+
* difference is load-bearing: mixing them is what an "invalid access token"
|
|
34004
|
+
* answer means when the token itself is fine.
|
|
34005
|
+
*/
|
|
34006
|
+
function createIdentityRequest(input) {
|
|
34007
|
+
const url = new URL(input.origin + USER_INFO_PATH);
|
|
34008
|
+
url.search = new URLSearchParams({
|
|
34009
|
+
device_platform: "mcode",
|
|
34010
|
+
biz_id: "3",
|
|
34011
|
+
app_id: "3001",
|
|
34012
|
+
version_code: "22201",
|
|
34013
|
+
unix: String(input.nowMs),
|
|
34014
|
+
timezone_offset: String((/* @__PURE__ */ new Date()).getTimezoneOffset() * -60),
|
|
34015
|
+
sys_language: input.language,
|
|
34016
|
+
lang: input.language,
|
|
34017
|
+
device_id: "0",
|
|
34018
|
+
os_name: process.platform,
|
|
34019
|
+
browser_name: "mcode",
|
|
34020
|
+
user_id: "0",
|
|
34021
|
+
client: "mcode"
|
|
34022
|
+
}).toString();
|
|
34023
|
+
const second = Math.floor(input.nowMs / 1e3);
|
|
34024
|
+
const pathWithSearch = `${url.pathname}${url.search}`;
|
|
34025
|
+
return {
|
|
34026
|
+
url,
|
|
34027
|
+
headers: {
|
|
34028
|
+
accept: "application/json",
|
|
34029
|
+
"content-type": "application/json",
|
|
34030
|
+
"user-agent": USER_AGENT,
|
|
34031
|
+
authorization: `Bearer ${input.accessToken}`,
|
|
34032
|
+
yy: md5(`${encodeURIComponent(pathWithSearch)}_{}${md5(String(input.nowMs))}ooui`),
|
|
34033
|
+
"x-timestamp": String(second),
|
|
34034
|
+
"x-signature": md5(`${second}${SIGNATURE_SALT}`)
|
|
34035
|
+
}
|
|
34036
|
+
};
|
|
34037
|
+
}
|
|
34038
|
+
var MinimaxCodeCheckinHttpError = class extends Error {
|
|
34039
|
+
status;
|
|
34040
|
+
constructor(message, status) {
|
|
34041
|
+
super(message);
|
|
34042
|
+
this.status = status;
|
|
34043
|
+
this.name = "MinimaxCodeCheckinHttpError";
|
|
34044
|
+
}
|
|
34045
|
+
};
|
|
34046
|
+
function languageFor(region) {
|
|
34047
|
+
return region === "cn" ? "zh" : "en";
|
|
34048
|
+
}
|
|
34049
|
+
/**
|
|
34050
|
+
* Resolve the account's realUserID (and display fields) through the identity
|
|
34051
|
+
* surface. The check-in query string needs realUserID and the OAuth document
|
|
34052
|
+
* does not carry it, so it is resolved once per scheduler pass and cached in
|
|
34053
|
+
* the check-in state afterwards.
|
|
34054
|
+
*/
|
|
34055
|
+
async function fetchAccountIdentity(accessToken, region, options = {}) {
|
|
34056
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
34057
|
+
const nowMs = (options.nowMs ?? Date.now)();
|
|
34058
|
+
const request = createIdentityRequest({
|
|
34059
|
+
origin: checkinGatewayOrigin(region),
|
|
34060
|
+
accessToken,
|
|
34061
|
+
language: languageFor(region),
|
|
34062
|
+
nowMs
|
|
34063
|
+
});
|
|
34064
|
+
const response = await fetchFn(request.url, {
|
|
34065
|
+
method: "GET",
|
|
34066
|
+
headers: request.headers,
|
|
34067
|
+
signal: options.signal ?? AbortSignal.timeout(3e4)
|
|
34068
|
+
});
|
|
34069
|
+
if (response.status === 401 || response.status === 403) throw new MinimaxCodeCheckinHttpError(`identity request rejected with HTTP ${response.status}`, response.status);
|
|
34070
|
+
const parsed = await response.json().catch(() => null);
|
|
34071
|
+
if (!response.ok || !isRecord$1(parsed)) throw new MinimaxCodeCheckinHttpError(`identity request failed with HTTP ${response.status}`, response.status);
|
|
34072
|
+
const data = isRecord$1(parsed.data) ? parsed.data : void 0;
|
|
34073
|
+
const userInfo = (isRecord$1(data?.userInfo) ? data?.userInfo : void 0) ?? (isRecord$1(data?.user_info) ? data?.user_info : void 0) ?? (isRecord$1(parsed.userInfo) ? parsed.userInfo : void 0) ?? (isRecord$1(parsed.user_info) ? parsed.user_info : void 0);
|
|
34074
|
+
const realUserID = readString(userInfo, "realUserID", "real_user_id");
|
|
34075
|
+
if (realUserID === void 0) throw new MinimaxCodeCheckinHttpError("identity response carried no realUserID", response.status);
|
|
34076
|
+
return {
|
|
34077
|
+
realUserID,
|
|
34078
|
+
...readString(userInfo, "userName", "name", "user_name") !== void 0 ? { userName: readString(userInfo, "userName", "name", "user_name") } : {},
|
|
34079
|
+
...readString(userInfo, "subUserName", "sub_user_name") !== void 0 ? { subUserName: readString(userInfo, "subUserName", "sub_user_name") } : {},
|
|
34080
|
+
...readString(userInfo, "userEmail", "email", "userMail", "user_email") !== void 0 ? { userEmail: readString(userInfo, "userEmail", "email", "userMail", "user_email") } : {}
|
|
34081
|
+
};
|
|
34082
|
+
}
|
|
34083
|
+
/** One status or claim call against the check-in surface. */
|
|
34084
|
+
async function checkinCall(path, method, accessToken, realUserID, region, options) {
|
|
34085
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
34086
|
+
const nowMs = (options.nowMs ?? Date.now)();
|
|
34087
|
+
const body = method === "POST" ? "{}" : void 0;
|
|
34088
|
+
const request = createCheckinRequest({
|
|
34089
|
+
origin: checkinGatewayOrigin(region),
|
|
34090
|
+
path,
|
|
34091
|
+
accessToken,
|
|
34092
|
+
realUserID,
|
|
34093
|
+
appVersion: options.appVersion ?? "0.0.0",
|
|
34094
|
+
language: languageFor(region),
|
|
34095
|
+
nowMs,
|
|
34096
|
+
...body === void 0 ? {} : { body }
|
|
34097
|
+
});
|
|
34098
|
+
const response = await fetchFn(request.url, {
|
|
34099
|
+
method,
|
|
34100
|
+
headers: request.headers,
|
|
34101
|
+
...body === void 0 ? {} : { body },
|
|
34102
|
+
signal: options.signal ?? AbortSignal.timeout(3e4)
|
|
34103
|
+
});
|
|
34104
|
+
const text = await response.text().catch(() => "");
|
|
34105
|
+
let parsed = null;
|
|
34106
|
+
try {
|
|
34107
|
+
const value = JSON.parse(text);
|
|
34108
|
+
parsed = isRecord$1(value) ? value : null;
|
|
34109
|
+
} catch {
|
|
34110
|
+
parsed = null;
|
|
34111
|
+
}
|
|
34112
|
+
if (!response.ok) throw new MinimaxCodeCheckinHttpError(`daily check-in request failed with HTTP ${response.status}${parsed === null ? "" : `: ${text.slice(0, 200)}`}`, response.status);
|
|
34113
|
+
const baseResp = isRecord$1(parsed?.base_resp) ? parsed.base_resp : void 0;
|
|
34114
|
+
const statusCode = typeof baseResp?.status_code === "number" ? baseResp.status_code : void 0;
|
|
34115
|
+
if (statusCode !== void 0 && statusCode !== 0) throw new MinimaxCodeCheckinHttpError(typeof baseResp?.status_msg === "string" && baseResp.status_msg !== "" ? baseResp.status_msg : "daily check-in request rejected", response.status);
|
|
34116
|
+
if (parsed === null || parsed.data === null || parsed.data === void 0) throw new MinimaxCodeCheckinHttpError("daily check-in response data is missing", response.status);
|
|
34117
|
+
return parsed.data;
|
|
34118
|
+
}
|
|
34119
|
+
/** Read the seven-day panel; throws on transport, HTTP, or shape failures. */
|
|
34120
|
+
async function fetchSigninPanel(accessToken, realUserID, region, options = {}) {
|
|
34121
|
+
return validateSigninPanel(await checkinCall(SIGNIN_STATUS_PATH, "GET", accessToken, realUserID, region, options));
|
|
34122
|
+
}
|
|
34123
|
+
/** Claim today's credit; the response carries the fresh panel. */
|
|
34124
|
+
async function claimSignin(accessToken, realUserID, region, options = {}) {
|
|
34125
|
+
return validateClaimSigninData(await checkinCall(SIGNIN_CLAIM_PATH, "POST", accessToken, realUserID, region, options));
|
|
34126
|
+
}
|
|
34127
|
+
//#endregion
|
|
34128
|
+
//#region src/host/minimax-code/checkin.ts
|
|
34129
|
+
/**
|
|
34130
|
+
* Daily check-in scheduler for the MiniMax Code line.
|
|
34131
|
+
*
|
|
34132
|
+
* Modeled on the sibling WorkBuddy scheduler and kept semantically identical
|
|
34133
|
+
* where the two services face the same problem; the wire half lives in
|
|
34134
|
+
* ./checkin-gateway.ts (official-client recipe, verified live).
|
|
34135
|
+
*
|
|
34136
|
+
* - **Both regions.** The official client's public gateway has an origin per
|
|
34137
|
+
* region, so an account signs in against its own region's origin. There is
|
|
34138
|
+
* no CN-only carve-out like WorkBuddy's: the CLI ships the same surface
|
|
34139
|
+
* worldwide.
|
|
34140
|
+
* - **Idempotent.** The panel is read first; an account whose today is already
|
|
34141
|
+
* claimed (by anyone) is only recorded. A duplicate claim answers
|
|
34142
|
+
* `claim_result: 2` (AlreadyClaimed), which is a success, never a retry.
|
|
34143
|
+
* - **Patient with the day.** A today that is neither claimable nor claimed
|
|
34144
|
+
* (upcoming/disabled) is parked and re-checked on an hourly cadence rather
|
|
34145
|
+
* than abandoned: the activity flips on its own schedule, and the host
|
|
34146
|
+
* usually boots before it does.
|
|
34147
|
+
* - **Bounded.** A failing account is retried at most {@link CHECKIN_ATTEMPT_CAP}
|
|
34148
|
+
* times a day, so a broken account cannot turn the ten-minute tick into a
|
|
34149
|
+
* request loop. A manual run ignores the cap and the toggle, like the
|
|
34150
|
+
* workbuddy card's "check in now", and is queued behind an in-flight run.
|
|
34151
|
+
*
|
|
34152
|
+
* Credentials stay host-side: the only write beyond the state file is the
|
|
34153
|
+
* account pool's own refresh write-back, reused here unchanged through
|
|
34154
|
+
* `getFreshCredential` / `renewCredential`.
|
|
34155
|
+
*/
|
|
34156
|
+
/**
|
|
34157
|
+
* Scheduler cadence. The first tick at host startup is the daily run; the
|
|
34158
|
+
* interval keeps a long-lived process signing in on later days without a
|
|
34159
|
+
* restart. Idle ticks cost no requests — the day state short-circuits them.
|
|
34160
|
+
*/
|
|
34161
|
+
const CHECKIN_TICK_MS = 600 * 1e3;
|
|
34162
|
+
/** State document the scheduler keeps beside the other plugin stores. */
|
|
34163
|
+
function checkinStatePath() {
|
|
34164
|
+
return path.join(dshHomeDir(), "storages", "minimax-code-checkin.json");
|
|
34165
|
+
}
|
|
34166
|
+
/** Local calendar day an instant belongs to; state entries are keyed by it. */
|
|
34167
|
+
function localDateString(nowMs) {
|
|
34168
|
+
const date = new Date(nowMs);
|
|
34169
|
+
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
|
34170
|
+
const day = `${date.getDate()}`.padStart(2, "0");
|
|
34171
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
34172
|
+
}
|
|
34173
|
+
function isRecord(value) {
|
|
34174
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34175
|
+
}
|
|
34176
|
+
function asCount(value) {
|
|
34177
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
34178
|
+
}
|
|
34179
|
+
function isRegion(value) {
|
|
34180
|
+
return value === "cn" || value === "global";
|
|
34181
|
+
}
|
|
34182
|
+
function parseStateEntry(value) {
|
|
34183
|
+
if (!isRecord(value) || typeof value.date !== "string") return null;
|
|
34184
|
+
const entry = {
|
|
34185
|
+
date: value.date,
|
|
34186
|
+
done: value.done === true,
|
|
34187
|
+
attempts: typeof value.attempts === "number" && Number.isFinite(value.attempts) ? value.attempts : 0
|
|
34188
|
+
};
|
|
34189
|
+
if (value.inactive === true) entry.inactive = true;
|
|
34190
|
+
const inactiveAt = asCount(value.inactiveAt);
|
|
34191
|
+
if (inactiveAt !== void 0) entry.inactiveAt = inactiveAt;
|
|
34192
|
+
if (typeof value.lastError === "string") entry.lastError = value.lastError;
|
|
34193
|
+
const streakDays = asCount(value.streakDays);
|
|
34194
|
+
if (streakDays !== void 0) entry.streakDays = streakDays;
|
|
34195
|
+
const claimedPoints = asCount(value.claimedPoints);
|
|
34196
|
+
if (claimedPoints !== void 0) entry.claimedPoints = claimedPoints;
|
|
34197
|
+
return entry;
|
|
34198
|
+
}
|
|
34199
|
+
/**
|
|
34200
|
+
* The check-in scheduler. One instance per plugin load; the host owns the
|
|
34201
|
+
* interval and clears it from the same `ctx.effect` that created it.
|
|
34202
|
+
*/
|
|
34203
|
+
var MinimaxCodeCheckinService = class {
|
|
34204
|
+
pool;
|
|
34205
|
+
options;
|
|
34206
|
+
fetchFn;
|
|
34207
|
+
statePath;
|
|
34208
|
+
now;
|
|
34209
|
+
logger;
|
|
34210
|
+
appVersion;
|
|
34211
|
+
state = {};
|
|
34212
|
+
identities = {};
|
|
34213
|
+
loaded = false;
|
|
34214
|
+
/** Passes waiting to run, in order; `true` marks a manual pass. */
|
|
34215
|
+
queue = [];
|
|
34216
|
+
/** The drain loop currently working the queue, if any. */
|
|
34217
|
+
draining = null;
|
|
34218
|
+
lastRunAt = null;
|
|
34219
|
+
/** Memoized preference warmup, so it is awaited once however many passes run. */
|
|
34220
|
+
readyWait = null;
|
|
34221
|
+
constructor(pool, options) {
|
|
34222
|
+
this.pool = pool;
|
|
34223
|
+
this.options = options;
|
|
34224
|
+
this.fetchFn = options.fetchFn ?? fetch;
|
|
34225
|
+
this.statePath = options.statePath ?? checkinStatePath();
|
|
34226
|
+
this.now = options.now ?? (() => Date.now());
|
|
34227
|
+
this.logger = options.logger;
|
|
34228
|
+
this.appVersion = options.appVersion;
|
|
34229
|
+
}
|
|
34230
|
+
/**
|
|
34231
|
+
* One scheduler pass. Automatic passes honour the toggle and the retry cap;
|
|
34232
|
+
* a manual pass (`manual: true`, the card's "check in now") ignores both
|
|
34233
|
+
* but still respects an account already signed in today.
|
|
34234
|
+
*
|
|
34235
|
+
* A manual pass that lands while a run is already in flight is *queued*, not
|
|
34236
|
+
* absorbed: joining the running pass would silently discard the one thing the
|
|
34237
|
+
* button promises, that the retry cap and the toggle are bypassed now.
|
|
34238
|
+
*/
|
|
34239
|
+
async tick(manual = false) {
|
|
34240
|
+
if (!manual && (this.queue.length > 0 || this.draining !== null)) return this.draining ?? Promise.resolve();
|
|
34241
|
+
this.queue.push(manual);
|
|
34242
|
+
return this.drain();
|
|
34243
|
+
}
|
|
34244
|
+
drain() {
|
|
34245
|
+
if (this.draining !== null) return this.draining;
|
|
34246
|
+
if (this.queue.length === 0) return Promise.resolve();
|
|
34247
|
+
const loop = this.runQueue();
|
|
34248
|
+
this.draining = loop;
|
|
34249
|
+
return loop;
|
|
34250
|
+
}
|
|
34251
|
+
async runQueue() {
|
|
34252
|
+
for (;;) {
|
|
34253
|
+
const manual = this.queue.shift();
|
|
34254
|
+
if (manual === void 0) {
|
|
34255
|
+
this.draining = null;
|
|
34256
|
+
return;
|
|
34257
|
+
}
|
|
34258
|
+
try {
|
|
34259
|
+
await this.run(manual);
|
|
34260
|
+
} catch (error) {
|
|
34261
|
+
this.logger?.warn(`[minimax-code-checkin] pass failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
34262
|
+
}
|
|
34263
|
+
}
|
|
34264
|
+
}
|
|
34265
|
+
async run(manual) {
|
|
34266
|
+
await this.ready();
|
|
34267
|
+
const settings = this.options.settings();
|
|
34268
|
+
if (!manual && !settings.enabled) return;
|
|
34269
|
+
await this.load();
|
|
34270
|
+
const nowMs = this.now();
|
|
34271
|
+
const today = localDateString(nowMs);
|
|
34272
|
+
let accounts;
|
|
34273
|
+
try {
|
|
34274
|
+
accounts = await this.pool.listAccounts();
|
|
34275
|
+
} catch (error) {
|
|
34276
|
+
this.logger?.warn(`[minimax-code-checkin] account scan failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
34277
|
+
return;
|
|
34278
|
+
}
|
|
34279
|
+
for (const account of accounts) {
|
|
34280
|
+
const existing = this.state[account.id];
|
|
34281
|
+
const sameDay = existing?.date === today;
|
|
34282
|
+
if (sameDay && existing.done) continue;
|
|
34283
|
+
if (!manual && sameDay && existing.attempts >= 3) continue;
|
|
34284
|
+
if (!manual && sameDay && existing.inactive === true && nowMs - (existing.inactiveAt ?? 0) < 36e5) continue;
|
|
34285
|
+
await this.checkinOne(account, today, nowMs);
|
|
34286
|
+
}
|
|
34287
|
+
this.lastRunAt = nowMs;
|
|
34288
|
+
await this.save();
|
|
34289
|
+
}
|
|
34290
|
+
/** Wait for the preference store's warmup read, once. */
|
|
34291
|
+
async ready() {
|
|
34292
|
+
if (this.readyWait === null) this.readyWait = Promise.resolve(this.options.ready?.()).catch(() => void 0);
|
|
34293
|
+
await this.readyWait;
|
|
34294
|
+
}
|
|
34295
|
+
/**
|
|
34296
|
+
* Resolve the account's realUserID, cached across days.
|
|
34297
|
+
*
|
|
34298
|
+
* The OAuth document does not carry it and the check-in query string needs
|
|
34299
|
+
* it, so it is fetched from the identity surface once and kept in the state
|
|
34300
|
+
* document. The region is cached alongside because the identity call's
|
|
34301
|
+
* origin depends on it.
|
|
34302
|
+
*/
|
|
34303
|
+
async identityFor(account, accessToken, region) {
|
|
34304
|
+
const cached = this.identities[account.id];
|
|
34305
|
+
if (cached !== void 0 && cached.region === region) return cached;
|
|
34306
|
+
const next = {
|
|
34307
|
+
realUserID: (await fetchAccountIdentity(accessToken, region, {
|
|
34308
|
+
fetchFn: this.fetchFn,
|
|
34309
|
+
...this.appVersion === void 0 ? {} : { appVersion: this.appVersion }
|
|
34310
|
+
})).realUserID,
|
|
34311
|
+
region
|
|
34312
|
+
};
|
|
34313
|
+
this.identities[account.id] = next;
|
|
34314
|
+
return next;
|
|
34315
|
+
}
|
|
34316
|
+
/** Check one account in, recording the outcome in its today's entry. */
|
|
34317
|
+
async checkinOne(account, today, nowMs) {
|
|
34318
|
+
const existing = this.state[account.id];
|
|
34319
|
+
const entry = existing?.date === today ? existing : {
|
|
34320
|
+
date: today,
|
|
34321
|
+
done: false,
|
|
34322
|
+
attempts: 0
|
|
34323
|
+
};
|
|
34324
|
+
this.state[account.id] = entry;
|
|
34325
|
+
const region = isRegion(account.region) ? account.region : "cn";
|
|
34326
|
+
try {
|
|
34327
|
+
const credentials = await this.pool.getFreshCredential(account.id, this.fetchFn);
|
|
34328
|
+
try {
|
|
34329
|
+
await this.attemptOnce(account, entry, credentials, region, nowMs);
|
|
34330
|
+
} catch (error) {
|
|
34331
|
+
if (!(error instanceof MinimaxCodeCheckinHttpError) || error.status !== 401 && error.status !== 403) throw error;
|
|
34332
|
+
delete this.identities[account.id];
|
|
34333
|
+
const renewed = await this.pool.renewCredential(account.id, this.fetchFn);
|
|
34334
|
+
await this.attemptOnce(account, entry, renewed, region, nowMs);
|
|
34335
|
+
}
|
|
34336
|
+
} catch (error) {
|
|
34337
|
+
entry.attempts += 1;
|
|
34338
|
+
entry.lastError = error instanceof Error ? error.message : String(error);
|
|
34339
|
+
this.logger?.warn(`[minimax-code-checkin] ${account.id} attempt ${entry.attempts}/3 failed: ${entry.lastError}`);
|
|
34340
|
+
}
|
|
34341
|
+
}
|
|
34342
|
+
/**
|
|
34343
|
+
* One full try for one account: identity, panel, and — when today is
|
|
34344
|
+
* claimable — the claim. Settles the entry on every outcome; throws for the
|
|
34345
|
+
* caller's renew-and-retry or attempt bookkeeping.
|
|
34346
|
+
*/
|
|
34347
|
+
async attemptOnce(account, entry, credentials, region, nowMs) {
|
|
34348
|
+
const identity = await this.identityFor(account, credentials.accessToken, region);
|
|
34349
|
+
const panel = await this.panel(credentials, identity, region);
|
|
34350
|
+
if (this.recordPanelOutcome(entry, panel, account.id, nowMs)) return;
|
|
34351
|
+
const claim = await this.claim(credentials, identity, region);
|
|
34352
|
+
this.markSignedIn(entry, claim.panel);
|
|
34353
|
+
if (claim.claim_result === 1) entry.claimedPoints = claim.points;
|
|
34354
|
+
this.logger?.info(`[minimax-code-checkin] ${account.id} signed in; +${claim.points} credits${claim.claim_result === 2 ? " (already claimed upstream)" : ""}`);
|
|
34355
|
+
}
|
|
34356
|
+
/** The status call, against the current credential. */
|
|
34357
|
+
async panel(credentials, identity, region) {
|
|
34358
|
+
return fetchSigninPanel(credentials.accessToken, identity.realUserID, region, {
|
|
34359
|
+
fetchFn: this.fetchFn,
|
|
34360
|
+
...this.appVersion === void 0 ? {} : { appVersion: this.appVersion }
|
|
34361
|
+
});
|
|
34362
|
+
}
|
|
34363
|
+
/** The claim call, against the current credential. */
|
|
34364
|
+
async claim(credentials, identity, region) {
|
|
34365
|
+
return claimSignin(credentials.accessToken, identity.realUserID, region, {
|
|
34366
|
+
fetchFn: this.fetchFn,
|
|
34367
|
+
...this.appVersion === void 0 ? {} : { appVersion: this.appVersion }
|
|
34368
|
+
});
|
|
34369
|
+
}
|
|
34370
|
+
/**
|
|
34371
|
+
* Fold one panel into the day's entry.
|
|
34372
|
+
*
|
|
34373
|
+
* Returns true when the entry is settled for the day (claimed already, or
|
|
34374
|
+
* parked inactive): the caller then skips the claim. Today claimable is the
|
|
34375
|
+
* one answer that returns false.
|
|
34376
|
+
*/
|
|
34377
|
+
recordPanelOutcome(entry, panel, accountId, nowMs) {
|
|
34378
|
+
const today = panel.days.find((day) => day.is_today);
|
|
34379
|
+
if (today?.status === 3) {
|
|
34380
|
+
this.markSignedIn(entry, panel);
|
|
34381
|
+
this.logger?.info(`[minimax-code-checkin] ${accountId} already signed in today`);
|
|
34382
|
+
return true;
|
|
34383
|
+
}
|
|
34384
|
+
if (today?.status !== 2) {
|
|
34385
|
+
entry.inactive = true;
|
|
34386
|
+
entry.inactiveAt = nowMs;
|
|
34387
|
+
delete entry.lastError;
|
|
34388
|
+
this.logger?.info(`[minimax-code-checkin] ${accountId} has no claimable day today; will re-check later`);
|
|
34389
|
+
return true;
|
|
34390
|
+
}
|
|
34391
|
+
entry.inactive = false;
|
|
34392
|
+
delete entry.inactiveAt;
|
|
34393
|
+
return false;
|
|
34394
|
+
}
|
|
34395
|
+
/** Record a confirmed sign-in, clearing the transient failure bookkeeping. */
|
|
34396
|
+
markSignedIn(entry, panel) {
|
|
34397
|
+
entry.done = true;
|
|
34398
|
+
entry.inactive = false;
|
|
34399
|
+
delete entry.inactiveAt;
|
|
34400
|
+
delete entry.lastError;
|
|
34401
|
+
entry.streakDays = currentSigninStreak(panel.days);
|
|
34402
|
+
}
|
|
34403
|
+
/**
|
|
34404
|
+
* The aggregate the settings card renders. Reads only local state and the
|
|
34405
|
+
* account list; it never spends a network request.
|
|
34406
|
+
*/
|
|
34407
|
+
async summary() {
|
|
34408
|
+
await this.ready();
|
|
34409
|
+
await this.load();
|
|
34410
|
+
const settings = this.options.settings();
|
|
34411
|
+
const accounts = await this.pool.listAccounts().catch(() => []);
|
|
34412
|
+
const today = localDateString(this.now());
|
|
34413
|
+
let doneToday = 0;
|
|
34414
|
+
let skippedToday = 0;
|
|
34415
|
+
let failedToday = 0;
|
|
34416
|
+
let streakDays;
|
|
34417
|
+
let claimedPoints;
|
|
34418
|
+
for (const account of accounts) {
|
|
34419
|
+
const entry = this.state[account.id];
|
|
34420
|
+
if (entry?.date !== today) continue;
|
|
34421
|
+
if (entry.done) {
|
|
34422
|
+
doneToday += 1;
|
|
34423
|
+
if (entry.streakDays !== void 0) streakDays = Math.max(streakDays ?? 0, entry.streakDays);
|
|
34424
|
+
if (entry.claimedPoints !== void 0) claimedPoints = (claimedPoints ?? 0) + entry.claimedPoints;
|
|
34425
|
+
} else if (entry.inactive === true) skippedToday += 1;
|
|
34426
|
+
else if (entry.attempts >= 3) failedToday += 1;
|
|
34427
|
+
}
|
|
34428
|
+
return {
|
|
34429
|
+
enabled: settings.enabled,
|
|
34430
|
+
totalAccounts: accounts.length,
|
|
34431
|
+
doneToday,
|
|
34432
|
+
skippedToday,
|
|
34433
|
+
failedToday,
|
|
34434
|
+
lastRunAt: this.lastRunAt,
|
|
34435
|
+
...streakDays === void 0 ? {} : { streakDays },
|
|
34436
|
+
...claimedPoints === void 0 ? {} : { claimedPoints }
|
|
34437
|
+
};
|
|
34438
|
+
}
|
|
34439
|
+
async load() {
|
|
34440
|
+
if (this.loaded) return;
|
|
34441
|
+
this.loaded = true;
|
|
34442
|
+
try {
|
|
34443
|
+
const parsed = JSON.parse(await fsPromises.readFile(this.statePath, "utf8"));
|
|
34444
|
+
if (isRecord(parsed)) {
|
|
34445
|
+
const lastRunAt = asCount(parsed.lastRunAt);
|
|
34446
|
+
if (lastRunAt !== void 0) this.lastRunAt = lastRunAt;
|
|
34447
|
+
if (isRecord(parsed.accounts)) for (const [id, value] of Object.entries(parsed.accounts)) {
|
|
34448
|
+
const entry = parseStateEntry(value);
|
|
34449
|
+
if (entry !== null) this.state[id] = entry;
|
|
34450
|
+
}
|
|
34451
|
+
if (isRecord(parsed.identities)) {
|
|
34452
|
+
for (const [id, value] of Object.entries(parsed.identities)) if (isRecord(value) && typeof value.realUserID === "string" && isRegion(value.region)) this.identities[id] = {
|
|
34453
|
+
realUserID: value.realUserID,
|
|
34454
|
+
region: value.region
|
|
34455
|
+
};
|
|
34456
|
+
}
|
|
34457
|
+
}
|
|
34458
|
+
} catch {}
|
|
34459
|
+
}
|
|
34460
|
+
async save() {
|
|
34461
|
+
try {
|
|
34462
|
+
await fsPromises.mkdir(path.dirname(this.statePath), { recursive: true });
|
|
34463
|
+
const tmp = `${this.statePath}.tmp.${process.pid}`;
|
|
34464
|
+
const document = {
|
|
34465
|
+
version: 1,
|
|
34466
|
+
lastRunAt: this.lastRunAt,
|
|
34467
|
+
accounts: this.state,
|
|
34468
|
+
identities: this.identities
|
|
34469
|
+
};
|
|
34470
|
+
await fsPromises.writeFile(tmp, JSON.stringify(document, null, 2), "utf8");
|
|
34471
|
+
await fsPromises.rename(tmp, this.statePath);
|
|
34472
|
+
} catch {}
|
|
34473
|
+
}
|
|
34474
|
+
};
|
|
34475
|
+
//#endregion
|
|
33695
34476
|
//#region src/host/subagent-model-authorization.ts
|
|
33696
34477
|
/** DSH settings namespace owned by the Subagent settings card. */
|
|
33697
34478
|
const SUBAGENT_MODEL_SELECTION_NAMESPACE = "subagent-model-selection";
|
|
@@ -35700,11 +36481,33 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
35700
36481
|
const minimaxCodeRouteWatch = typeof ctx.on === "function" ? ctx.on("llm/adapters-updated", () => {
|
|
35701
36482
|
claimMinimaxCodeRoute();
|
|
35702
36483
|
}) : void 0;
|
|
36484
|
+
let minimaxCodeAppVersion;
|
|
36485
|
+
try {
|
|
36486
|
+
const manifest = createRequire(import.meta.url)("../package.json");
|
|
36487
|
+
if (typeof manifest.version === "string") minimaxCodeAppVersion = manifest.version;
|
|
36488
|
+
} catch {
|
|
36489
|
+
minimaxCodeAppVersion = void 0;
|
|
36490
|
+
}
|
|
36491
|
+
const minimaxCodeCheckin = new MinimaxCodeCheckinService(minimaxCodeAccountPool, {
|
|
36492
|
+
fetchFn: proxyFetch,
|
|
36493
|
+
settings: () => minimaxCodePreferences.status().checkin ?? { enabled: true },
|
|
36494
|
+
ready: () => minimaxCodePreferences.ready(),
|
|
36495
|
+
...minimaxCodeAppVersion === void 0 ? {} : { appVersion: minimaxCodeAppVersion },
|
|
36496
|
+
logger: ctx.logger
|
|
36497
|
+
});
|
|
36498
|
+
const minimaxCodeCheckinTick = () => {
|
|
36499
|
+
minimaxCodeCheckin.tick().catch((error) => {
|
|
36500
|
+
ctx.logger.warn(`[dsh-chatgpt-subscription] MiniMax Code check-in tick failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
36501
|
+
});
|
|
36502
|
+
};
|
|
36503
|
+
const minimaxCodeCheckinTimer = setInterval(minimaxCodeCheckinTick, CHECKIN_TICK_MS);
|
|
36504
|
+
minimaxCodeCheckinTick();
|
|
35703
36505
|
const disposeMinimaxCodeRoutes = registerMinimaxCodeRoutes(ctx, minimaxCodeStore, {
|
|
35704
36506
|
fetchFn: proxyFetch,
|
|
35705
36507
|
serving: () => minimaxCodeRegistration !== void 0,
|
|
35706
36508
|
conflict: () => minimaxCodeConflict,
|
|
35707
|
-
accountPool: minimaxCodeAccountPool
|
|
36509
|
+
accountPool: minimaxCodeAccountPool,
|
|
36510
|
+
checkin: minimaxCodeCheckin
|
|
35708
36511
|
}, minimaxCodeModelSettings, minimaxCodePreferences);
|
|
35709
36512
|
const workBuddyAdapter = new WorkBuddyAdapter(workBuddyStore, workBuddyModelSettings, workBuddyPreferences, {
|
|
35710
36513
|
fetchFn: proxyFetch,
|
|
@@ -35739,7 +36542,7 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
35739
36542
|
ctx.logger.warn(`[dsh-chatgpt-subscription] WorkBuddy check-in tick failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
35740
36543
|
});
|
|
35741
36544
|
};
|
|
35742
|
-
const checkinTimer = setInterval(checkinTick, CHECKIN_TICK_MS);
|
|
36545
|
+
const checkinTimer = setInterval(checkinTick, CHECKIN_TICK_MS$1);
|
|
35743
36546
|
checkinTick();
|
|
35744
36547
|
const disposeWorkBuddyRoutes = registerWorkBuddyRoutes(ctx, workBuddyStore, workBuddyModelSettings, workBuddyPreferences, {
|
|
35745
36548
|
fetchFn: proxyFetch,
|
|
@@ -35862,6 +36665,7 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
35862
36665
|
releaseHandle(minimaxCodeRouteWatch);
|
|
35863
36666
|
minimaxCodeRegistration?.();
|
|
35864
36667
|
minimaxCodeRegistration = void 0;
|
|
36668
|
+
clearInterval(minimaxCodeCheckinTimer);
|
|
35865
36669
|
clearInterval(checkinTimer);
|
|
35866
36670
|
disposeWorkBuddyRoutes();
|
|
35867
36671
|
releaseHandle(workBuddyRouteWatch);
|
|
@@ -35888,4 +36692,4 @@ function localWebServerBaseUrl(host, port) {
|
|
|
35888
36692
|
return `http://${host === "0.0.0.0" ? "127.0.0.1" : host}:${port}`;
|
|
35889
36693
|
}
|
|
35890
36694
|
//#endregion
|
|
35891
|
-
export { AccountPoolCore, AccountPoolStore, AntigravityAdapter, ADOPTED_CREDENTIAL_EXPIRED_HINT as CLAUDE_ADOPTED_CREDENTIAL_EXPIRED_HINT, API_BASE as CLAUDE_API_BASE, DEFAULT_VISIBLE_MODEL_IDS as CLAUDE_DEFAULT_VISIBLE_MODELS, FALLBACK_MODELS as CLAUDE_FALLBACK_MODELS, MESSAGES_PATH as CLAUDE_MESSAGES_PATH, CLAUDE_MODELS, CLAUDE_MODEL_IDS, PROVIDER_ID as CLAUDE_PROVIDER_ID, PROVIDER_NAME as CLAUDE_PROVIDER_NAME, QUOTA_CACHE_TTL_MS as CLAUDE_QUOTA_CACHE_TTL_MS, CLAUDE_REASONING_EFFORTS, ROUTE_PREFIX as CLAUDE_ROUTE_PREFIX, ClaudeAccountPool, ClaudeAdapter, FileCredentialStore as ClaudeCredentialStore, FileModelSettingsStore as ClaudeModelSettingsStore, CodexAccountPool, CodexChatGptAdapter, CommandCodeAccountPool, CommandCodeAdapter, FileCredentialStore$1 as CommandCodeCredentialStore, FileModelSettingsStore$1 as CommandCodeModelSettingsStore, Config, DEFAULT_SUBAGENT_INHERIT_TOOLS, FileCredentialStore$2 as FileCredentialStore, FileModelSettingsStore$2 as FileModelSettingsStore, KIMI_CODE_MODELS, KIMI_CODE_RETRY_POLICY_CONFIG, KimiCodeAccountPool, KimiCodeAdapter, FileCredentialStore$3 as KimiCodeCredentialStore, FileModelSettingsStore$3 as KimiCodeModelSettingsStore, LinuxFileTokenStore, AGENT_LLM_PREFIX as MINIMAX_CODE_AGENT_LLM_PREFIX, MESSAGES_PATH$1 as MINIMAX_CODE_MESSAGES_PATH, MINIMAX_CODE_MODELS, PROBE_MODEL as MINIMAX_CODE_PROBE_MODEL, MINIMAX_CODE_PROVIDER_ID, MINIMAX_CODE_PROVIDER_NAME, MINIMAX_CODE_REASONING_EFFORTS, REGION_HOSTS as MINIMAX_CODE_REGION_HOSTS, MINIMAX_CODE_RETRY_POLICY_CONFIG, MINIMAX_CODE_ROUTE_PREFIX, MacKeychainTokenStore, MinimaxCodeAccountPool, MinimaxCodeAdapter, MinimaxCodeCredentialStore, MinimaxCodeModelSettingsStore, OAuthService, ProxyManager, RELAY_PROBE_ENV, RELAY_PROBE_FILE_ENV, RELAY_PROBE_FILE_NAME, RELAY_PROBE_MAX_BYTES, RELAY_SOURCE_KINDS, RelayProbe, ResponsesClient, SUBAGENT_MODEL_SELECTION_NAMESPACE, SUBAGENT_POLICY_EVENT, SearchProviderSwitcher, UsageService, FALLBACK_MODELS$1 as WORKBUDDY_MODELS, WORKBUDDY_MODEL_IDS, WindowsDpapiTokenStore, WorkBuddyAdapter, WorkBuddyCheckinService, FileCredentialStore$4 as WorkBuddyCredentialStore, FileModelSettingsStore$4 as WorkBuddyModelSettingsStore, adoptedPoolAccountKey, apply, assertRequestBodyFits as assertMinimaxCodeBodyFits, assertStreamComplete as assertMinimaxCodeStreamComplete, auditChildRoutes, auditedRoutesOf, authorizedRoutesFor, beginLogin as beginClaudeLogin, beginWebLogin as beginKimiCodeLogin, beginWebLogin$1 as beginMinimaxCodeLogin, beginWebLogin$2 as beginWebLogin, buildClaudeModelOptions, buildMinimaxCodeModelOptions, buildMinimaxRequest, cancelLogin as cancelClaudeLogin, cancelWebLogin as cancelMinimaxCodeLogin, childRoutesOf, clampOutputToContext as clampMinimaxCodeOutputToContext, classifyFailure as classifyClaudeFailure, classifyKimiFailure, classifyMinimaxFailure, classifyFailure$1 as classifyWorkBuddyFailure, claudeCliVersion, claudeCodeCredentialPaths, claudeCodeCredentialPresence, codeForFailure as claudeCodeForFailure, credentialPath as claudeCredentialPath, defaultContextWindowFor as claudeDefaultContextWindow, maxOutputTokensFor as claudeMaxOutputTokens, claudeModelCanDisableThinking, modelSettingsPath as claudeModelSettingsPath, claudeModelSupportsImage, claudeModelSupportsTemperature, claudePoolPath, claudeReasoningEfforts, claudeThinkingMode, toLlmError as claudeToLlmError, clearCachedQuota, clearCachedCatalog as clearClaudeCatalog, clearCachedQuota$1 as clearClaudeQuota, clearCachedQuota$2 as clearCommandCodeQuota, clearCachedQuota$3 as clearKimiCodeQuota, clearCachedQuota$4 as clearMinimaxCodeQuota, clearCachedCatalog$1 as clearWorkBuddyCatalog, clearCachedQuota$5 as clearWorkBuddyQuota, closeMinimaxStream, codeBuddyAuthDir, codexPoolPath, commandCodeAccountKey, credentialPath$1 as commandCodeCredentialPath, modelSettingsPath$1 as commandCodeModelSettingsPath, commandCodePoolPath, contextWindowForModel, createCodexFetchProvider, createCodexImageTool, createCodexSearchProvider, createFileRelayProbeSink, createMinimaxCodeAccountsHandler, createMessage as createMinimaxCodeMessage, createPkcePair as createMinimaxCodePkcePair, createStreamState as createMinimaxCodeStreamState, createPlatformTokenStore, createSubagentAuthorization, credentialPath$2 as credentialPath, delegationDenialReason, delegationModeOf, describeCredentials as describeMinimaxCodeCredentials, detectSystemProxy, dshHomeDir, effectiveRouteOf, ensureAccessToken as ensureClaudeAccessToken, ensureAccessToken$1 as ensureKimiCodeAccessToken, ensureAccessToken$2 as ensureMinimaxCodeAccessToken, fetchAccountQuota, fetchAccountQuota$1 as fetchClaudeQuota, fetchAccountQuota$2 as fetchCommandCodeQuota, fetchAccountQuota$3 as fetchKimiCodeQuota, fetchUserInfo as fetchKimiCodeUserInfo, fetchTokenPlanQuota as fetchMinimaxCodeQuota, fetchAccountQuota$4 as fetchWorkBuddyQuota, getCachedQuota, getLoginStatus as getClaudeLoginStatus, getCachedQuota$1 as getClaudeQuota, getClaudeWebStatus, getWebLoginStatus as getCommandCodeLoginStatus, getCachedQuota$2 as getCommandCodeQuota, getCommandCodeWebStatus, getWebLoginStatus$1 as getKimiCodeLoginStatus, getCachedQuota$3 as getKimiCodeQuota, getKimiCodeWebStatus, getWebLogin as getMinimaxCodeLogin, getCachedQuota$4 as getMinimaxCodeQuota, getMinimaxCodeWebStatus, getCachedQuota$5 as getWorkBuddyQuota, getWorkBuddyWebStatus, inheritOverrideReason, inheritRouteDenialReason, inheritedRouteOf, inject, installRelayProbe, installSubagentModelAuthorization, isAdoptedClaudeCredential, isAdoptedCredentialExpired, isAdoptedPoolCredential, isClaudeReasoningEffort, isMinimaxCodeReasoningEffort, isRefreshTokenRejected as isMinimaxCodeRefreshTokenRejected, isThinkingDisabledEffort, credentialPath$3 as kimiCodeCredentialPath, kimiCodeModelDef, modelSettingsPath$2 as kimiCodeModelSettingsPath, kimiCodePoolPath, listModelIds as listMinimaxCodeModelIds, loadCatalog as loadClaudeCatalog, loadProviderModels as loadCommandCodeModels, loadProviderModels$1 as loadKimiCodeModels, loadConfigCatalog as loadWorkBuddyModels, loginAndSave, mapCodexUsage, accountFromCredentials as minimaxCodeAccountFromCredentials, accountHost as minimaxCodeAccountHost, agentBaseUrl as minimaxCodeAgentBaseUrl, authJsonPath as minimaxCodeAuthJsonPath, authStateJsonPath as minimaxCodeAuthStateJsonPath, catalogSize as minimaxCodeCatalogSize, credentialIsFresh as minimaxCodeCredentialIsFresh, effortForModel as minimaxCodeEffortForModel, minimaxHomeDir as minimaxCodeHomeDir, maxOutputTokensFor$1 as minimaxCodeMaxOutputTokens, messagesUrl as minimaxCodeMessagesUrl, minimaxCodeModelDef, minimaxCodeModelIds, minimaxCodeModelName, modelRequestHeaders as minimaxCodeModelRequestHeaders, modelSettingsPath$3 as minimaxCodeModelSettingsPath, pluginCredentialPath as minimaxCodePluginCredentialPath, minimaxCodePoolIdentity, minimaxCodePoolPath, minimaxCodePoolStatus, quotaHostCandidates as minimaxCodeQuotaHostCandidates, quotaRequestHeaders as minimaxCodeQuotaRequestHeaders, subPathOf as minimaxCodeSubPathOf, thinkingFieldFor as minimaxCodeThinkingField, tokenPlanRemainsUrl as minimaxCodeTokenPlanRemainsUrl, modelSettingsPath$4 as modelSettingsPath, normalizeDelegationToolNames, normalizeInheritToolNames, normalizeRotationStrategy, parseAllowedRoutes, parseClaudeCredentialDocument, parseClaudeCredentials, parseClaudePoolData, parseUsagePayload as parseClaudeUsagePayload, parseCodexPoolData, parseCodexUsage, parseCommandCodePoolData, parseKimiCodePoolData, parseMinimaxCodeCredentials, parseMinimaxCodePoolData, parseTokenPlanQuota as parseMinimaxCodeQuota, parseAnthropicUsage as parseMinimaxCodeUsage, parseResponsesStream, parseBilling as parseWorkBuddyBilling, parseConfigModels as parseWorkBuddyConfigModels, parseCredentialFile as parseWorkBuddyCredential, policyRoutesOf, pollWebLogin as pollMinimaxCodeLogin, probeConnection as probeClaudeConnection, processMinimaxStreamLine, readChildDescriptor, readClaudeCodeCredentials, redactToken as redactMinimaxCodeToken, refreshAntigravityToken, refreshAccessToken as refreshClaudeToken, refreshAccessToken$1 as refreshKimiCodeToken, refreshAccessToken$2 as refreshMinimaxCodeToken, refreshCredentials as refreshWorkBuddyCredentials, registerClaudePreferenceStore, registerClaudeRoutes, registerCommandCodePreferenceStore, registerCommandCodeRoutes, registerKimiCodePreferenceStore, registerKimiCodeRoutes, registerMinimaxCodePreferenceStore, registerMinimaxCodeRoutes, registerWorkBuddyPreferenceStore, registerWorkBuddyRoutes, relayProbeEnabled, relayProbeEnvFile, relayProbeEnvValue, relayProbeLogPath, requestDeviceAuthorization as requestKimiCodeDeviceAuthorization, requestDeviceAuthorization$1 as requestMinimaxCodeDeviceAuthorization, resetWebLogins as resetMinimaxCodeLogins, resolveEnabledModelIds as resolveClaudeEnabledModelIds, resolveLoginInput as resolveClaudeLoginInput, resolveClaudeModel, resolveRegion as resolveKimiCodeRegion, resolveMinimaxCodeEnabledModelIds, resolveQuotaCounts as resolveMinimaxCodeQuotaCounts, resolveWorkBuddyModel, revokeToken as revokeMinimaxCodeToken, saveApiKey as saveCommandCodeApiKey, scanCredentials as scanWorkBuddyCredentials, setClaudeCliVersion, beginWebLogin$3 as startCommandCodeLogin, subagentModelSelectionPreference, submitLoginInput as submitClaudeLoginInput, summarizeFailureBody as summarizeMinimaxCodeFailureBody, testConnection as testMinimaxCodeConnection, unauthorizedRouteReason, validateAuthorizationScope, validateDelegationToolNames, validateInheritToolNames, violationText, modelSettingsPath$5 as workBuddyModelSettingsPath, modelsForRegion as workBuddyModelsForRegion };
|
|
36695
|
+
export { AccountPoolCore, AccountPoolStore, AntigravityAdapter, ADOPTED_CREDENTIAL_EXPIRED_HINT as CLAUDE_ADOPTED_CREDENTIAL_EXPIRED_HINT, API_BASE as CLAUDE_API_BASE, DEFAULT_VISIBLE_MODEL_IDS as CLAUDE_DEFAULT_VISIBLE_MODELS, FALLBACK_MODELS as CLAUDE_FALLBACK_MODELS, MESSAGES_PATH as CLAUDE_MESSAGES_PATH, CLAUDE_MODELS, CLAUDE_MODEL_IDS, PROVIDER_ID as CLAUDE_PROVIDER_ID, PROVIDER_NAME as CLAUDE_PROVIDER_NAME, QUOTA_CACHE_TTL_MS as CLAUDE_QUOTA_CACHE_TTL_MS, CLAUDE_REASONING_EFFORTS, ROUTE_PREFIX as CLAUDE_ROUTE_PREFIX, ClaudeAccountPool, ClaudeAdapter, FileCredentialStore as ClaudeCredentialStore, FileModelSettingsStore as ClaudeModelSettingsStore, CodexAccountPool, CodexChatGptAdapter, CommandCodeAccountPool, CommandCodeAdapter, FileCredentialStore$1 as CommandCodeCredentialStore, FileModelSettingsStore$1 as CommandCodeModelSettingsStore, Config, DEFAULT_SUBAGENT_INHERIT_TOOLS, FileCredentialStore$2 as FileCredentialStore, FileModelSettingsStore$2 as FileModelSettingsStore, KIMI_CODE_MODELS, KIMI_CODE_RETRY_POLICY_CONFIG, KimiCodeAccountPool, KimiCodeAdapter, FileCredentialStore$3 as KimiCodeCredentialStore, FileModelSettingsStore$3 as KimiCodeModelSettingsStore, LinuxFileTokenStore, AGENT_LLM_PREFIX as MINIMAX_CODE_AGENT_LLM_PREFIX, MESSAGES_PATH$1 as MINIMAX_CODE_MESSAGES_PATH, MINIMAX_CODE_MODELS, PROBE_MODEL as MINIMAX_CODE_PROBE_MODEL, MINIMAX_CODE_PROVIDER_ID, MINIMAX_CODE_PROVIDER_NAME, MINIMAX_CODE_REASONING_EFFORTS, REGION_HOSTS as MINIMAX_CODE_REGION_HOSTS, MINIMAX_CODE_RETRY_POLICY_CONFIG, MINIMAX_CODE_ROUTE_PREFIX, MacKeychainTokenStore, MinimaxCodeAccountPool, MinimaxCodeAdapter, MinimaxCodeCheckinService, MinimaxCodeCredentialStore, MinimaxCodeModelSettingsStore, OAuthService, ProxyManager, RELAY_PROBE_ENV, RELAY_PROBE_FILE_ENV, RELAY_PROBE_FILE_NAME, RELAY_PROBE_MAX_BYTES, RELAY_SOURCE_KINDS, RelayProbe, ResponsesClient, SUBAGENT_MODEL_SELECTION_NAMESPACE, SUBAGENT_POLICY_EVENT, SearchProviderSwitcher, UsageService, FALLBACK_MODELS$1 as WORKBUDDY_MODELS, WORKBUDDY_MODEL_IDS, WindowsDpapiTokenStore, WorkBuddyAdapter, WorkBuddyCheckinService, FileCredentialStore$4 as WorkBuddyCredentialStore, FileModelSettingsStore$4 as WorkBuddyModelSettingsStore, adoptedPoolAccountKey, apply, assertRequestBodyFits as assertMinimaxCodeBodyFits, assertStreamComplete as assertMinimaxCodeStreamComplete, auditChildRoutes, auditedRoutesOf, authorizedRoutesFor, beginLogin as beginClaudeLogin, beginWebLogin as beginKimiCodeLogin, beginWebLogin$1 as beginMinimaxCodeLogin, beginWebLogin$2 as beginWebLogin, buildClaudeModelOptions, buildMinimaxCodeModelOptions, buildMinimaxRequest, cancelLogin as cancelClaudeLogin, cancelWebLogin as cancelMinimaxCodeLogin, childRoutesOf, clampOutputToContext as clampMinimaxCodeOutputToContext, classifyFailure as classifyClaudeFailure, classifyKimiFailure, classifyMinimaxFailure, classifyFailure$1 as classifyWorkBuddyFailure, claudeCliVersion, claudeCodeCredentialPaths, claudeCodeCredentialPresence, codeForFailure as claudeCodeForFailure, credentialPath as claudeCredentialPath, defaultContextWindowFor as claudeDefaultContextWindow, maxOutputTokensFor as claudeMaxOutputTokens, claudeModelCanDisableThinking, modelSettingsPath as claudeModelSettingsPath, claudeModelSupportsImage, claudeModelSupportsTemperature, claudePoolPath, claudeReasoningEfforts, claudeThinkingMode, toLlmError as claudeToLlmError, clearCachedQuota, clearCachedCatalog as clearClaudeCatalog, clearCachedQuota$1 as clearClaudeQuota, clearCachedQuota$2 as clearCommandCodeQuota, clearCachedQuota$3 as clearKimiCodeQuota, clearCachedQuota$4 as clearMinimaxCodeQuota, clearCachedCatalog$1 as clearWorkBuddyCatalog, clearCachedQuota$5 as clearWorkBuddyQuota, closeMinimaxStream, codeBuddyAuthDir, codexPoolPath, commandCodeAccountKey, credentialPath$1 as commandCodeCredentialPath, modelSettingsPath$1 as commandCodeModelSettingsPath, commandCodePoolPath, contextWindowForModel, createCodexFetchProvider, createCodexImageTool, createCodexSearchProvider, createFileRelayProbeSink, createMinimaxCodeAccountsHandler, createMessage as createMinimaxCodeMessage, createPkcePair as createMinimaxCodePkcePair, createStreamState as createMinimaxCodeStreamState, createPlatformTokenStore, createSubagentAuthorization, credentialPath$2 as credentialPath, delegationDenialReason, delegationModeOf, describeCredentials as describeMinimaxCodeCredentials, detectSystemProxy, dshHomeDir, effectiveRouteOf, ensureAccessToken as ensureClaudeAccessToken, ensureAccessToken$1 as ensureKimiCodeAccessToken, ensureAccessToken$2 as ensureMinimaxCodeAccessToken, fetchAccountQuota, fetchAccountQuota$1 as fetchClaudeQuota, fetchAccountQuota$2 as fetchCommandCodeQuota, fetchAccountQuota$3 as fetchKimiCodeQuota, fetchUserInfo as fetchKimiCodeUserInfo, fetchTokenPlanQuota as fetchMinimaxCodeQuota, fetchAccountQuota$4 as fetchWorkBuddyQuota, getCachedQuota, getLoginStatus as getClaudeLoginStatus, getCachedQuota$1 as getClaudeQuota, getClaudeWebStatus, getWebLoginStatus as getCommandCodeLoginStatus, getCachedQuota$2 as getCommandCodeQuota, getCommandCodeWebStatus, getWebLoginStatus$1 as getKimiCodeLoginStatus, getCachedQuota$3 as getKimiCodeQuota, getKimiCodeWebStatus, getWebLogin as getMinimaxCodeLogin, getCachedQuota$4 as getMinimaxCodeQuota, getMinimaxCodeWebStatus, getCachedQuota$5 as getWorkBuddyQuota, getWorkBuddyWebStatus, inheritOverrideReason, inheritRouteDenialReason, inheritedRouteOf, inject, installRelayProbe, installSubagentModelAuthorization, isAdoptedClaudeCredential, isAdoptedCredentialExpired, isAdoptedPoolCredential, isClaudeReasoningEffort, isMinimaxCodeReasoningEffort, isRefreshTokenRejected as isMinimaxCodeRefreshTokenRejected, isThinkingDisabledEffort, credentialPath$3 as kimiCodeCredentialPath, kimiCodeModelDef, modelSettingsPath$2 as kimiCodeModelSettingsPath, kimiCodePoolPath, listModelIds as listMinimaxCodeModelIds, loadCatalog as loadClaudeCatalog, loadProviderModels as loadCommandCodeModels, loadProviderModels$1 as loadKimiCodeModels, loadConfigCatalog as loadWorkBuddyModels, loginAndSave, mapCodexUsage, accountFromCredentials as minimaxCodeAccountFromCredentials, accountHost as minimaxCodeAccountHost, agentBaseUrl as minimaxCodeAgentBaseUrl, authJsonPath as minimaxCodeAuthJsonPath, authStateJsonPath as minimaxCodeAuthStateJsonPath, catalogSize as minimaxCodeCatalogSize, credentialIsFresh as minimaxCodeCredentialIsFresh, effortForModel as minimaxCodeEffortForModel, minimaxHomeDir as minimaxCodeHomeDir, maxOutputTokensFor$1 as minimaxCodeMaxOutputTokens, messagesUrl as minimaxCodeMessagesUrl, minimaxCodeModelDef, minimaxCodeModelIds, minimaxCodeModelName, modelRequestHeaders as minimaxCodeModelRequestHeaders, modelSettingsPath$3 as minimaxCodeModelSettingsPath, pluginCredentialPath as minimaxCodePluginCredentialPath, minimaxCodePoolIdentity, minimaxCodePoolPath, minimaxCodePoolStatus, quotaHostCandidates as minimaxCodeQuotaHostCandidates, quotaRequestHeaders as minimaxCodeQuotaRequestHeaders, subPathOf as minimaxCodeSubPathOf, thinkingFieldFor as minimaxCodeThinkingField, tokenPlanRemainsUrl as minimaxCodeTokenPlanRemainsUrl, modelSettingsPath$4 as modelSettingsPath, normalizeDelegationToolNames, normalizeInheritToolNames, normalizeRotationStrategy, parseAllowedRoutes, parseClaudeCredentialDocument, parseClaudeCredentials, parseClaudePoolData, parseUsagePayload as parseClaudeUsagePayload, parseCodexPoolData, parseCodexUsage, parseCommandCodePoolData, parseKimiCodePoolData, parseMinimaxCodeCredentials, parseMinimaxCodePoolData, parseTokenPlanQuota as parseMinimaxCodeQuota, parseAnthropicUsage as parseMinimaxCodeUsage, parseResponsesStream, parseBilling as parseWorkBuddyBilling, parseConfigModels as parseWorkBuddyConfigModels, parseCredentialFile as parseWorkBuddyCredential, policyRoutesOf, pollWebLogin as pollMinimaxCodeLogin, probeConnection as probeClaudeConnection, processMinimaxStreamLine, readChildDescriptor, readClaudeCodeCredentials, redactToken as redactMinimaxCodeToken, refreshAntigravityToken, refreshAccessToken as refreshClaudeToken, refreshAccessToken$1 as refreshKimiCodeToken, refreshAccessToken$2 as refreshMinimaxCodeToken, refreshCredentials as refreshWorkBuddyCredentials, registerClaudePreferenceStore, registerClaudeRoutes, registerCommandCodePreferenceStore, registerCommandCodeRoutes, registerKimiCodePreferenceStore, registerKimiCodeRoutes, registerMinimaxCodePreferenceStore, registerMinimaxCodeRoutes, registerWorkBuddyPreferenceStore, registerWorkBuddyRoutes, relayProbeEnabled, relayProbeEnvFile, relayProbeEnvValue, relayProbeLogPath, requestDeviceAuthorization as requestKimiCodeDeviceAuthorization, requestDeviceAuthorization$1 as requestMinimaxCodeDeviceAuthorization, resetWebLogins as resetMinimaxCodeLogins, resolveEnabledModelIds as resolveClaudeEnabledModelIds, resolveLoginInput as resolveClaudeLoginInput, resolveClaudeModel, resolveRegion as resolveKimiCodeRegion, resolveMinimaxCodeEnabledModelIds, resolveQuotaCounts as resolveMinimaxCodeQuotaCounts, resolveWorkBuddyModel, revokeToken as revokeMinimaxCodeToken, saveApiKey as saveCommandCodeApiKey, scanCredentials as scanWorkBuddyCredentials, setClaudeCliVersion, beginWebLogin$3 as startCommandCodeLogin, subagentModelSelectionPreference, submitLoginInput as submitClaudeLoginInput, summarizeFailureBody as summarizeMinimaxCodeFailureBody, testConnection as testMinimaxCodeConnection, unauthorizedRouteReason, validateAuthorizationScope, validateDelegationToolNames, validateInheritToolNames, violationText, modelSettingsPath$5 as workBuddyModelSettingsPath, modelsForRegion as workBuddyModelsForRegion };
|