@eddyskywalker/dsh-chatgpt-subscription 0.10.1 → 0.10.6
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 +109 -0
- package/lib/client.js.map +1 -1
- package/lib/index.js +1185 -357
- 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 +43 -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,12 +18737,15 @@ 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;
|
|
18746
|
+
state.inputTokens = numberOr$3(usage.input_tokens, state.inputTokens);
|
|
18747
|
+
state.cacheReadTokens = numberOr$3(usage.cache_read_input_tokens, state.cacheReadTokens);
|
|
18748
|
+
state.cacheWriteTokens = numberOr$3(usage.cache_creation_input_tokens, state.cacheWriteTokens);
|
|
18657
18749
|
state.outputTokens = numberOr$3(usage.output_tokens, state.outputTokens);
|
|
18658
18750
|
}
|
|
18659
18751
|
return out;
|
|
@@ -18662,7 +18754,7 @@ function processMinimaxStreamLine(line, state) {
|
|
|
18662
18754
|
state.done = true;
|
|
18663
18755
|
return closeMinimaxStream(state);
|
|
18664
18756
|
}
|
|
18665
|
-
if (type === "error") throw new LlmError$1("MiniMax Code(编程订阅) stream error: " + (asString$8((isRecord$
|
|
18757
|
+
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
18758
|
return out;
|
|
18667
18759
|
}
|
|
18668
18760
|
//#endregion
|
|
@@ -18902,7 +18994,7 @@ function authStateJsonPath(region, buildEnv = MINIMAX_CODE_BUILD_ENV) {
|
|
|
18902
18994
|
function pluginCredentialPath() {
|
|
18903
18995
|
return path.join(dshHomeDir(), "storages", "minimax-code-credentials.json");
|
|
18904
18996
|
}
|
|
18905
|
-
function isRecord$
|
|
18997
|
+
function isRecord$14(value) {
|
|
18906
18998
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18907
18999
|
}
|
|
18908
19000
|
function asString$7(value) {
|
|
@@ -18924,7 +19016,7 @@ function asFiniteNumber(value) {
|
|
|
18924
19016
|
* exists to prevent.
|
|
18925
19017
|
*/
|
|
18926
19018
|
function parseMinimaxCodeCredentials(value, fallback) {
|
|
18927
|
-
if (!isRecord$
|
|
19019
|
+
if (!isRecord$14(value)) throw new Error("MiniMax Code credential payload is invalid");
|
|
18928
19020
|
const accessToken = asString$7(value.accessToken);
|
|
18929
19021
|
if (accessToken === void 0) throw new Error("MiniMax Code credential is missing its access token");
|
|
18930
19022
|
const refreshToken = asString$7(value.refreshToken);
|
|
@@ -18942,13 +19034,13 @@ function parseMinimaxCodeCredentials(value, fallback) {
|
|
|
18942
19034
|
generation: asFiniteNumber(value.generation) ?? 0,
|
|
18943
19035
|
loginEpoch: asString$7(value.loginEpoch) ?? "",
|
|
18944
19036
|
buildEnv: fallback.buildEnv ?? "prod",
|
|
18945
|
-
region: isRegion(value.region) ? value.region : fallback.region,
|
|
19037
|
+
region: isRegion$1(value.region) ? value.region : fallback.region,
|
|
18946
19038
|
recordKey: fallback.recordKey ?? null,
|
|
18947
19039
|
source: fallback.source ?? "file"
|
|
18948
19040
|
};
|
|
18949
19041
|
}
|
|
18950
19042
|
/** Whether one value is a region this line understands. */
|
|
18951
|
-
function isRegion(value) {
|
|
19043
|
+
function isRegion$1(value) {
|
|
18952
19044
|
return value === "cn" || value === "global";
|
|
18953
19045
|
}
|
|
18954
19046
|
/** Whether a credential is valid for long enough to use as-is. */
|
|
@@ -19010,10 +19102,10 @@ async function readNativeDocument(region) {
|
|
|
19010
19102
|
} catch {
|
|
19011
19103
|
return null;
|
|
19012
19104
|
}
|
|
19013
|
-
if (!isRecord$
|
|
19105
|
+
if (!isRecord$14(parsed) || !isRecord$14(parsed.records)) return null;
|
|
19014
19106
|
const records = parsed.records;
|
|
19015
19107
|
for (const [recordKey, entry] of Object.entries(records)) {
|
|
19016
|
-
if (!isRecord$
|
|
19108
|
+
if (!isRecord$14(entry)) continue;
|
|
19017
19109
|
if (asString$7(entry.clientId) !== "mcode-public") continue;
|
|
19018
19110
|
if (asString$7(entry.accessToken) === void 0) continue;
|
|
19019
19111
|
return {
|
|
@@ -19041,7 +19133,7 @@ async function syncAuthState(region, options) {
|
|
|
19041
19133
|
} catch {
|
|
19042
19134
|
return;
|
|
19043
19135
|
}
|
|
19044
|
-
if (!isRecord$
|
|
19136
|
+
if (!isRecord$14(parsed)) return;
|
|
19045
19137
|
const next = {
|
|
19046
19138
|
...parsed,
|
|
19047
19139
|
generation: options.generation,
|
|
@@ -19235,10 +19327,22 @@ function parseMinimaxCodeModelSettings(value) {
|
|
|
19235
19327
|
enabled: record.enabled !== false,
|
|
19236
19328
|
enabledModelIds,
|
|
19237
19329
|
contextWindowOverrides,
|
|
19238
|
-
defaultReasoningEffort: isReasoningEffort$1(record.defaultReasoningEffort) ? record.defaultReasoningEffort : null
|
|
19330
|
+
defaultReasoningEffort: isReasoningEffort$1(record.defaultReasoningEffort) ? record.defaultReasoningEffort : null,
|
|
19331
|
+
checkin: parseCheckinSettings(record.checkin)
|
|
19239
19332
|
};
|
|
19240
19333
|
}
|
|
19241
19334
|
/**
|
|
19335
|
+
* Normalize the check-in half of the settings document.
|
|
19336
|
+
*
|
|
19337
|
+
* Absent means enabled, matching the sibling lines' scheduler default: a user
|
|
19338
|
+
* who never opened the card gets the same behaviour a fresh workbuddy install
|
|
19339
|
+
* has, and only an explicit `false` parks the scheduler.
|
|
19340
|
+
*/
|
|
19341
|
+
function parseCheckinSettings(value) {
|
|
19342
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return { enabled: true };
|
|
19343
|
+
return { enabled: value.enabled !== false };
|
|
19344
|
+
}
|
|
19345
|
+
/**
|
|
19242
19346
|
* Apply one patch to one settings document.
|
|
19243
19347
|
*
|
|
19244
19348
|
* The merge lives outside both stores because the register-backed store has to
|
|
@@ -19251,7 +19355,8 @@ function mergeMinimaxCodeSettings(current, patch) {
|
|
|
19251
19355
|
enabled: patch.enabled !== void 0 ? patch.enabled : current.enabled !== false,
|
|
19252
19356
|
enabledModelIds: patch.enabledModelIds ?? current.enabledModelIds,
|
|
19253
19357
|
contextWindowOverrides: patch.contextWindowOverrides !== void 0 ? mergeContextWindowOverrides(current.contextWindowOverrides, patch.contextWindowOverrides) : current.contextWindowOverrides,
|
|
19254
|
-
defaultReasoningEffort: patch.defaultReasoningEffort !== void 0 ? patch.defaultReasoningEffort : current.defaultReasoningEffort
|
|
19358
|
+
defaultReasoningEffort: patch.defaultReasoningEffort !== void 0 ? patch.defaultReasoningEffort : current.defaultReasoningEffort,
|
|
19359
|
+
checkin: patch.checkin !== void 0 ? { enabled: patch.checkin.enabled !== false } : current.checkin ?? { enabled: true }
|
|
19255
19360
|
};
|
|
19256
19361
|
}
|
|
19257
19362
|
/**
|
|
@@ -19311,10 +19416,11 @@ var MinimaxCodeModelSettingsStore = class {
|
|
|
19311
19416
|
function registerMinimaxCodePreferenceStore(settings, fallbackStore = new MinimaxCodeModelSettingsStore()) {
|
|
19312
19417
|
if (!hasRegister(settings)) {
|
|
19313
19418
|
let snapshot = defaultMinimaxCodeSettings();
|
|
19314
|
-
fallbackStore.read().then((stored) => {
|
|
19419
|
+
const warmed = fallbackStore.read().then((stored) => {
|
|
19315
19420
|
snapshot = stored;
|
|
19316
19421
|
}).catch(() => void 0);
|
|
19317
19422
|
return {
|
|
19423
|
+
ready: () => warmed,
|
|
19318
19424
|
status: () => snapshot,
|
|
19319
19425
|
update: async (patch) => {
|
|
19320
19426
|
snapshot = await fallbackStore.updateSettings(patch);
|
|
@@ -19326,16 +19432,19 @@ function registerMinimaxCodePreferenceStore(settings, fallbackStore = new Minima
|
|
|
19326
19432
|
enabled: z.boolean().default(true),
|
|
19327
19433
|
enabledModelIds: z.array(z.string()).default([...DEFAULT_ENABLED_MODEL_IDS$2]),
|
|
19328
19434
|
contextWindowOverrides: z.dict(z.number()).default({}),
|
|
19329
|
-
defaultReasoningEffort: z.union([...MINIMAX_CODE_REASONING_EFFORTS.map((effort) => z.const(effort)), z.const(null)]).default(null)
|
|
19435
|
+
defaultReasoningEffort: z.union([...MINIMAX_CODE_REASONING_EFFORTS.map((effort) => z.const(effort)), z.const(null)]).default(null),
|
|
19436
|
+
checkin: z.object({ enabled: z.boolean().default(true) }).default({ enabled: true })
|
|
19330
19437
|
}));
|
|
19331
19438
|
return {
|
|
19439
|
+
ready: async () => void 0,
|
|
19332
19440
|
status: () => {
|
|
19333
19441
|
const value = scope.get();
|
|
19334
19442
|
return {
|
|
19335
19443
|
enabled: value.enabled !== false,
|
|
19336
19444
|
enabledModelIds: value.enabledModelIds,
|
|
19337
19445
|
contextWindowOverrides: value.contextWindowOverrides,
|
|
19338
|
-
defaultReasoningEffort: value.defaultReasoningEffort
|
|
19446
|
+
defaultReasoningEffort: value.defaultReasoningEffort,
|
|
19447
|
+
checkin: { enabled: value.checkin?.enabled !== false }
|
|
19339
19448
|
};
|
|
19340
19449
|
},
|
|
19341
19450
|
update: async (patch) => {
|
|
@@ -19344,7 +19453,8 @@ function registerMinimaxCodePreferenceStore(settings, fallbackStore = new Minima
|
|
|
19344
19453
|
enabled: value.enabled !== false,
|
|
19345
19454
|
enabledModelIds: value.enabledModelIds,
|
|
19346
19455
|
contextWindowOverrides: value.contextWindowOverrides,
|
|
19347
|
-
defaultReasoningEffort: value.defaultReasoningEffort
|
|
19456
|
+
defaultReasoningEffort: value.defaultReasoningEffort,
|
|
19457
|
+
checkin: { enabled: value.checkin?.enabled !== false }
|
|
19348
19458
|
}, patch);
|
|
19349
19459
|
await scope.update(normalized);
|
|
19350
19460
|
fallbackStore.updateSettings(patch).catch(() => void 0);
|
|
@@ -20595,7 +20705,7 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
20595
20705
|
const body = assertRequestBodyFits(buildMinimaxRequest({
|
|
20596
20706
|
...requestOptions,
|
|
20597
20707
|
maxTokens: clampOutputToContext(requestedMax, contextWindow, estimatedInputTokens(requestOptions))
|
|
20598
|
-
}, images));
|
|
20708
|
+
}, images, { cacheControl: true }));
|
|
20599
20709
|
let credentials;
|
|
20600
20710
|
let accountId;
|
|
20601
20711
|
try {
|
|
@@ -20707,7 +20817,7 @@ var MinimaxCodeAdapter = class extends LlmAdapter {
|
|
|
20707
20817
|
function minimaxCodePoolPath() {
|
|
20708
20818
|
return path.join(dshHomeDir(), "storages", "minimax-code-pool.json");
|
|
20709
20819
|
}
|
|
20710
|
-
function isRecord$
|
|
20820
|
+
function isRecord$13(value) {
|
|
20711
20821
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20712
20822
|
}
|
|
20713
20823
|
function optionalString$2(record, key) {
|
|
@@ -20742,7 +20852,7 @@ function claimDisplayFacts(accessToken) {
|
|
|
20742
20852
|
} catch {
|
|
20743
20853
|
return {};
|
|
20744
20854
|
}
|
|
20745
|
-
if (!isRecord$
|
|
20855
|
+
if (!isRecord$13(claims)) return {};
|
|
20746
20856
|
const str = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
20747
20857
|
return {
|
|
20748
20858
|
email: str(claims.email) ?? (str(claims.preferred_username)?.includes("@") === true ? str(claims.preferred_username) : void 0),
|
|
@@ -20822,14 +20932,14 @@ function minimaxCodePoolIdentity(credentials) {
|
|
|
20822
20932
|
* instead of the app's).
|
|
20823
20933
|
*/
|
|
20824
20934
|
function parseMinimaxCodePoolData(value) {
|
|
20825
|
-
if (!isRecord$
|
|
20935
|
+
if (!isRecord$13(value)) throw new Error("MiniMax Code pool payload is invalid");
|
|
20826
20936
|
const record = value;
|
|
20827
20937
|
const accounts = [];
|
|
20828
20938
|
for (const item of Array.isArray(record.accounts) ? record.accounts : []) {
|
|
20829
|
-
if (!isRecord$
|
|
20939
|
+
if (!isRecord$13(item)) continue;
|
|
20830
20940
|
if (typeof item.id !== "string") continue;
|
|
20831
|
-
const rawCredentials = isRecord$
|
|
20832
|
-
const region = isRegion$
|
|
20941
|
+
const rawCredentials = isRecord$13(item.credentials) ? item.credentials : {};
|
|
20942
|
+
const region = isRegion$2(item.region) ? item.region : isRegion$2(rawCredentials.region) ? rawCredentials.region : "cn";
|
|
20833
20943
|
let credentials;
|
|
20834
20944
|
try {
|
|
20835
20945
|
credentials = parseMinimaxCodeCredentials(item.credentials, {
|
|
@@ -21227,6 +21337,7 @@ async function getMinimaxCodeWebStatus(store, options = {}, settingsSource) {
|
|
|
21227
21337
|
const pool = await minimaxCodePoolStatus(options.accountPool);
|
|
21228
21338
|
const quota = getCachedQuota$4();
|
|
21229
21339
|
const quotaUnavailable = quota === null ? getQuotaUnavailable() : null;
|
|
21340
|
+
const checkin = options.checkin === void 0 ? null : await options.checkin.summary().catch(() => null);
|
|
21230
21341
|
return {
|
|
21231
21342
|
...pool,
|
|
21232
21343
|
serving,
|
|
@@ -21246,7 +21357,8 @@ async function getMinimaxCodeWebStatus(store, options = {}, settingsSource) {
|
|
|
21246
21357
|
defaultReasoningEffort: settings.defaultReasoningEffort,
|
|
21247
21358
|
ownedByPlugin: credentials !== null && source === "file",
|
|
21248
21359
|
...quota === null ? {} : { quota },
|
|
21249
|
-
...quotaUnavailable === null ? {} : { quotaUnavailable }
|
|
21360
|
+
...quotaUnavailable === null ? {} : { quotaUnavailable },
|
|
21361
|
+
checkin
|
|
21250
21362
|
};
|
|
21251
21363
|
}
|
|
21252
21364
|
function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore(), options = {}, modelSettings = new MinimaxCodeModelSettingsStore(), preferences) {
|
|
@@ -21268,6 +21380,20 @@ function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore()
|
|
|
21268
21380
|
force
|
|
21269
21381
|
}).catch(() => null);
|
|
21270
21382
|
};
|
|
21383
|
+
/**
|
|
21384
|
+
* The in-flight usage read, so the card can be told one is running.
|
|
21385
|
+
*
|
|
21386
|
+
* This line previously fired the background read with a bare `void`, which
|
|
21387
|
+
* discarded the only fact the card needed: nothing. On a cold start there is no
|
|
21388
|
+
* snapshot yet, so the answer carried `quota: undefined` and the refresh that
|
|
21389
|
+
* would fill it was already running but invisible. The card then showed "no
|
|
21390
|
+
* usage data" until its next 60 s poll — which, on a page opened right after a
|
|
21391
|
+
* restart, is most of a minute of a quota box the user just signed in to fill.
|
|
21392
|
+
* Every sibling line reports the flag and the client schedules a short
|
|
21393
|
+
* follow-up (see QuotaRefresh and client/common/quota-follow-up.ts); this one
|
|
21394
|
+
* had neither half.
|
|
21395
|
+
*/
|
|
21396
|
+
const quotaRefresh = new QuotaRefresh();
|
|
21271
21397
|
const handler = async (request, response) => {
|
|
21272
21398
|
const path = subPathOf(request.url ?? "/");
|
|
21273
21399
|
const method = request.method ?? "GET";
|
|
@@ -21275,19 +21401,26 @@ function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore()
|
|
|
21275
21401
|
if (path === "accounts") return accountsHandler(request, response);
|
|
21276
21402
|
if (path === "" || path === "status") {
|
|
21277
21403
|
if (method !== "GET") return sendMethodNotAllowed$2(response);
|
|
21278
|
-
if (options.fetchFn !== void 0) refreshQuota(false);
|
|
21404
|
+
if (options.fetchFn !== void 0) if (getCachedQuota$4() === null) await quotaRefresh.run(() => refreshQuota(false));
|
|
21405
|
+
else quotaRefresh.start(() => refreshQuota(false));
|
|
21279
21406
|
return sendJson$2(response, 200, {
|
|
21280
21407
|
ok: true,
|
|
21281
|
-
value:
|
|
21408
|
+
value: {
|
|
21409
|
+
...await getMinimaxCodeWebStatus(store, options, settings),
|
|
21410
|
+
quotaRefreshing: quotaRefresh.refreshing
|
|
21411
|
+
}
|
|
21282
21412
|
});
|
|
21283
21413
|
}
|
|
21284
21414
|
if (path === "quota") {
|
|
21285
21415
|
if (method !== "GET" && method !== "POST") return sendMethodNotAllowed$2(response);
|
|
21286
21416
|
if (method === "POST" && !isSameOriginMutation(request)) return sendCrossOrigin(response);
|
|
21287
|
-
await refreshQuota(method === "POST");
|
|
21417
|
+
await quotaRefresh.run(() => refreshQuota(method === "POST"));
|
|
21288
21418
|
return sendJson$2(response, 200, {
|
|
21289
21419
|
ok: true,
|
|
21290
|
-
value:
|
|
21420
|
+
value: {
|
|
21421
|
+
...await getMinimaxCodeWebStatus(store, options, settings),
|
|
21422
|
+
quotaRefreshing: quotaRefresh.refreshing
|
|
21423
|
+
}
|
|
21291
21424
|
});
|
|
21292
21425
|
}
|
|
21293
21426
|
if (path === "models" || path === "settings") {
|
|
@@ -21311,6 +21444,10 @@ function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore()
|
|
|
21311
21444
|
const effort = body.defaultReasoningEffort;
|
|
21312
21445
|
if (effort === null || isMinimaxCodeReasoningEffort(effort)) patch.defaultReasoningEffort = effort;
|
|
21313
21446
|
}
|
|
21447
|
+
if (typeof body.checkin === "object" && body.checkin !== null) {
|
|
21448
|
+
const raw = body.checkin;
|
|
21449
|
+
if (typeof raw.enabled === "boolean") patch.checkin = { enabled: raw.enabled };
|
|
21450
|
+
}
|
|
21314
21451
|
await settings.update(patch);
|
|
21315
21452
|
if (patch.enabled !== void 0 || patch.enabledModelIds !== void 0) ctx.emit?.("llm/adapters-updated");
|
|
21316
21453
|
return sendJson$2(response, 200, {
|
|
@@ -21318,11 +21455,25 @@ function registerMinimaxCodeRoutes(ctx, store = new MinimaxCodeCredentialStore()
|
|
|
21318
21455
|
value: await getMinimaxCodeWebStatus(store, options, settings)
|
|
21319
21456
|
});
|
|
21320
21457
|
}
|
|
21458
|
+
if (path === "checkin/now") {
|
|
21459
|
+
if (method !== "POST") return sendMethodNotAllowed$2(response);
|
|
21460
|
+
if (!isSameOriginMutation(request)) return sendCrossOrigin(response);
|
|
21461
|
+
const service = options.checkin;
|
|
21462
|
+
if (service === void 0) return sendJson$2(response, 400, {
|
|
21463
|
+
ok: false,
|
|
21464
|
+
error: "Check-in is not installed."
|
|
21465
|
+
});
|
|
21466
|
+
await service.tick(true);
|
|
21467
|
+
return sendJson$2(response, 200, {
|
|
21468
|
+
ok: true,
|
|
21469
|
+
value: await getMinimaxCodeWebStatus(store, options, settings)
|
|
21470
|
+
});
|
|
21471
|
+
}
|
|
21321
21472
|
if (path === "login/start") {
|
|
21322
21473
|
if (method !== "POST") return sendMethodNotAllowed$2(response);
|
|
21323
21474
|
if (!isSameOriginMutation(request)) return sendCrossOrigin(response);
|
|
21324
21475
|
const body = await readRequestJson$2(request);
|
|
21325
|
-
const requested = isRegion$
|
|
21476
|
+
const requested = isRegion$2(body.region) ? body.region : void 0;
|
|
21326
21477
|
const login = await beginWebLogin$1({
|
|
21327
21478
|
fetchFn,
|
|
21328
21479
|
...requested === void 0 ? {} : { region: requested }
|
|
@@ -22384,7 +22535,7 @@ function defaultContextWindowFor$1(id, catalog = FALLBACK_MODELS$1) {
|
|
|
22384
22535
|
}
|
|
22385
22536
|
//#endregion
|
|
22386
22537
|
//#region src/host/workbuddy/identity.ts
|
|
22387
|
-
function isRecord$
|
|
22538
|
+
function isRecord$12(value) {
|
|
22388
22539
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22389
22540
|
}
|
|
22390
22541
|
/** A trimmed, non-empty string from an untrusted record. */
|
|
@@ -22414,7 +22565,7 @@ function decodeAccessTokenClaims(accessToken) {
|
|
|
22414
22565
|
const base64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
22415
22566
|
const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
|
|
22416
22567
|
const parsed = JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
|
|
22417
|
-
return isRecord$
|
|
22568
|
+
return isRecord$12(parsed) ? parsed : null;
|
|
22418
22569
|
} catch {
|
|
22419
22570
|
return null;
|
|
22420
22571
|
}
|
|
@@ -22505,7 +22656,7 @@ const DEFAULT_CHECKIN_SETTINGS = { enabled: true };
|
|
|
22505
22656
|
* startHour/endHour; those keys are inert now and dropped on the next write.
|
|
22506
22657
|
*/
|
|
22507
22658
|
function normalizeCheckinSettings(value) {
|
|
22508
|
-
if (!isRecord$
|
|
22659
|
+
if (!isRecord$11(value)) return { ...DEFAULT_CHECKIN_SETTINGS };
|
|
22509
22660
|
return { enabled: value.enabled !== false };
|
|
22510
22661
|
}
|
|
22511
22662
|
/**
|
|
@@ -22606,10 +22757,10 @@ function modelSettingsPath$5() {
|
|
|
22606
22757
|
function managedCredentialsPath() {
|
|
22607
22758
|
return path.join(dshHomeDir$2(), "storages", "workbuddy-accounts.json");
|
|
22608
22759
|
}
|
|
22609
|
-
function isRecord$
|
|
22760
|
+
function isRecord$11(value) {
|
|
22610
22761
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22611
22762
|
}
|
|
22612
|
-
function readString(record, key) {
|
|
22763
|
+
function readString$1(record, key) {
|
|
22613
22764
|
const value = record[key];
|
|
22614
22765
|
if (typeof value !== "string") return void 0;
|
|
22615
22766
|
const trimmed = value.trim();
|
|
@@ -22624,27 +22775,27 @@ function readString(record, key) {
|
|
|
22624
22775
|
* can move on to the next candidate.
|
|
22625
22776
|
*/
|
|
22626
22777
|
function parseCredentialFile(value, sourceFile, sourceMtimeMs = 0) {
|
|
22627
|
-
if (!isRecord$
|
|
22628
|
-
const auth = isRecord$
|
|
22778
|
+
if (!isRecord$11(value)) throw new Error("WorkBuddy credential file is not an object");
|
|
22779
|
+
const auth = isRecord$11(value.auth) ? value.auth : void 0;
|
|
22629
22780
|
if (auth === void 0) throw new Error("WorkBuddy credential file has no auth block");
|
|
22630
|
-
const accessToken = readString(auth, "accessToken");
|
|
22781
|
+
const accessToken = readString$1(auth, "accessToken");
|
|
22631
22782
|
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";
|
|
22783
|
+
const account = isRecord$11(value.account) ? value.account : {};
|
|
22784
|
+
const domain = readString$1(auth, "domain") ?? "www.codebuddy.cn";
|
|
22634
22785
|
const expiresAtRaw = auth.expiresAt;
|
|
22635
22786
|
const expiresAt = typeof expiresAtRaw === "number" && Number.isFinite(expiresAtRaw) ? expiresAtRaw : 0;
|
|
22636
22787
|
return withResolvedIdentity({
|
|
22637
22788
|
accessToken,
|
|
22638
|
-
refreshToken: readString(auth, "refreshToken") ?? "",
|
|
22789
|
+
refreshToken: readString$1(auth, "refreshToken") ?? "",
|
|
22639
22790
|
expiresAt,
|
|
22640
22791
|
region: regionForDomain(domain),
|
|
22641
22792
|
domain,
|
|
22642
22793
|
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"),
|
|
22794
|
+
uid: readString$1(account, "uid"),
|
|
22795
|
+
nickname: readString$1(account, "nickname"),
|
|
22796
|
+
uin: readString$1(account, "uin"),
|
|
22797
|
+
accountType: readString$1(account, "type"),
|
|
22798
|
+
enterpriseId: readString$1(account, "enterpriseId"),
|
|
22648
22799
|
sourceFile,
|
|
22649
22800
|
sourceMtimeMs,
|
|
22650
22801
|
source: "desktop"
|
|
@@ -22700,25 +22851,25 @@ function workBuddyAccountIdAliases(credentials) {
|
|
|
22700
22851
|
}
|
|
22701
22852
|
/** Strict parser for credentials owned by the plugin's encrypted pool. */
|
|
22702
22853
|
function parseManagedCredentials(value) {
|
|
22703
|
-
if (!isRecord$
|
|
22854
|
+
if (!isRecord$11(value) || value.version !== 1 || !Array.isArray(value.accounts)) throw new Error("WorkBuddy managed credential pool is invalid");
|
|
22704
22855
|
return value.accounts.map((item) => {
|
|
22705
|
-
if (!isRecord$
|
|
22706
|
-
const accessToken = readString(item, "accessToken");
|
|
22856
|
+
if (!isRecord$11(item)) throw new Error("WorkBuddy managed account is invalid");
|
|
22857
|
+
const accessToken = readString$1(item, "accessToken");
|
|
22707
22858
|
if (accessToken === void 0) throw new Error("WorkBuddy managed account has no access token");
|
|
22708
|
-
const domain = readString(item, "domain") ?? "www.codebuddy.cn";
|
|
22859
|
+
const domain = readString$1(item, "domain") ?? "www.codebuddy.cn";
|
|
22709
22860
|
const expiresAt = typeof item.expiresAt === "number" && Number.isFinite(item.expiresAt) ? item.expiresAt : 0;
|
|
22710
22861
|
return withResolvedIdentity({
|
|
22711
22862
|
accessToken,
|
|
22712
|
-
refreshToken: readString(item, "refreshToken") ?? "",
|
|
22863
|
+
refreshToken: readString$1(item, "refreshToken") ?? "",
|
|
22713
22864
|
expiresAt,
|
|
22714
22865
|
region: regionForDomain(domain),
|
|
22715
22866
|
domain,
|
|
22716
22867
|
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"),
|
|
22868
|
+
uid: readString$1(item, "uid"),
|
|
22869
|
+
nickname: readString$1(item, "nickname"),
|
|
22870
|
+
uin: readString$1(item, "uin"),
|
|
22871
|
+
accountType: readString$1(item, "accountType"),
|
|
22872
|
+
enterpriseId: readString$1(item, "enterpriseId"),
|
|
22722
22873
|
sourceFile: "",
|
|
22723
22874
|
sourceMtimeMs: 0,
|
|
22724
22875
|
source: "managed"
|
|
@@ -23000,7 +23151,7 @@ var FileCredentialStore$4 = class {
|
|
|
23000
23151
|
try {
|
|
23001
23152
|
const raw = await fsPromises.readFile(credentials.sourceFile, "utf8");
|
|
23002
23153
|
const parsed = JSON.parse(raw);
|
|
23003
|
-
if (!isRecord$
|
|
23154
|
+
if (!isRecord$11(parsed) || !isRecord$11(parsed.auth)) return;
|
|
23004
23155
|
parsed.auth.accessToken = credentials.accessToken;
|
|
23005
23156
|
if (credentials.refreshToken !== "") parsed.auth.refreshToken = credentials.refreshToken;
|
|
23006
23157
|
parsed.auth.expiresAt = credentials.expiresAt;
|
|
@@ -23033,9 +23184,9 @@ var FileModelSettingsStore$4 = class {
|
|
|
23033
23184
|
try {
|
|
23034
23185
|
const content = await fsPromises.readFile(this.filePath, "utf8");
|
|
23035
23186
|
const parsed = JSON.parse(content);
|
|
23036
|
-
if (isRecord$
|
|
23187
|
+
if (isRecord$11(parsed)) {
|
|
23037
23188
|
const enabledModelIds = Array.isArray(parsed.enabledModelIds) ? parsed.enabledModelIds.filter((id) => typeof id === "string") : [...DEFAULT_ENABLED_MODEL_IDS$1];
|
|
23038
|
-
const contextWindowOverrides = isRecord$
|
|
23189
|
+
const contextWindowOverrides = isRecord$11(parsed.contextWindowOverrides) ? Object.fromEntries(Object.entries(parsed.contextWindowOverrides).filter((entry) => typeof entry[1] === "number")) : {};
|
|
23039
23190
|
const defaultReasoningEffort = isReasoningEffort(parsed.defaultReasoningEffort) ? parsed.defaultReasoningEffort : null;
|
|
23040
23191
|
return {
|
|
23041
23192
|
enabled: parsed.enabled !== false,
|
|
@@ -23088,11 +23239,11 @@ var FileModelSettingsStore$4 = class {
|
|
|
23088
23239
|
function timeoutSignal$1(signal, ms) {
|
|
23089
23240
|
return signal ? AbortSignal.any([signal, AbortSignal.timeout(ms)]) : AbortSignal.timeout(ms);
|
|
23090
23241
|
}
|
|
23091
|
-
function isRecord$
|
|
23242
|
+
function isRecord$10(value) {
|
|
23092
23243
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23093
23244
|
}
|
|
23094
23245
|
function asRecord$4(value) {
|
|
23095
|
-
return isRecord$
|
|
23246
|
+
return isRecord$10(value) ? value : void 0;
|
|
23096
23247
|
}
|
|
23097
23248
|
function asString$5(value) {
|
|
23098
23249
|
if (typeof value === "string" && value.trim() !== "") return value;
|
|
@@ -23206,7 +23357,7 @@ function accountFromCredentials$1(credentials) {
|
|
|
23206
23357
|
* keeps the credential it has and lets the token's own claims fill in what
|
|
23207
23358
|
* they can.
|
|
23208
23359
|
*/
|
|
23209
|
-
async function fetchAccountIdentity(credentials, options = {}) {
|
|
23360
|
+
async function fetchAccountIdentity$1(credentials, options = {}) {
|
|
23210
23361
|
const fetchFn = options.fetchFn ?? fetch;
|
|
23211
23362
|
try {
|
|
23212
23363
|
const response = await fetchFn(`${credentials.backend}${ACCOUNT_PATH}`, {
|
|
@@ -23565,7 +23716,7 @@ function resetWebLogin() {
|
|
|
23565
23716
|
controller = null;
|
|
23566
23717
|
flow = { status: "idle" };
|
|
23567
23718
|
}
|
|
23568
|
-
function isRecord$
|
|
23719
|
+
function isRecord$9(value) {
|
|
23569
23720
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23570
23721
|
}
|
|
23571
23722
|
function stringOf(record, key) {
|
|
@@ -23613,11 +23764,11 @@ async function requestLoginState(region, fetchFn = fetch, signal) {
|
|
|
23613
23764
|
let root;
|
|
23614
23765
|
try {
|
|
23615
23766
|
const parsed = JSON.parse(text);
|
|
23616
|
-
root = isRecord$
|
|
23767
|
+
root = isRecord$9(parsed) ? parsed : void 0;
|
|
23617
23768
|
} catch {
|
|
23618
23769
|
root = void 0;
|
|
23619
23770
|
}
|
|
23620
|
-
if (!response.ok || root?.code !== 0 || !isRecord$
|
|
23771
|
+
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
23772
|
const state = stringOf(root.data, "state");
|
|
23622
23773
|
const authUrl = stringOf(root.data, "authUrl");
|
|
23623
23774
|
if (!state || !authUrl) throw new Error(`${PROVIDER_NAME$1} 登录响应缺少 state 或 authUrl`);
|
|
@@ -23630,13 +23781,13 @@ async function requestLoginState(region, fetchFn = fetch, signal) {
|
|
|
23630
23781
|
}
|
|
23631
23782
|
/** Parse the successful token-poll shape while accepting the two observed wrappers. */
|
|
23632
23783
|
function parseLoginCredential(payload, attempt) {
|
|
23633
|
-
if (!isRecord$
|
|
23784
|
+
if (!isRecord$9(payload)) throw new Error(`${PROVIDER_NAME$1} 登录轮询响应无效`);
|
|
23634
23785
|
const code = numberOf(payload, "code");
|
|
23635
23786
|
if (code === 11217) return null;
|
|
23636
23787
|
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$
|
|
23788
|
+
const data = isRecord$9(payload.data) ? payload.data : payload;
|
|
23789
|
+
const auth = isRecord$9(data.auth) ? data.auth : data;
|
|
23790
|
+
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
23791
|
const accessToken = stringOf(auth, "accessToken") ?? stringOf(auth, "access_token") ?? stringOf(data, "token");
|
|
23641
23792
|
if (!accessToken) throw new Error(`${PROVIDER_NAME$1} 登录成功响应缺少 access token`);
|
|
23642
23793
|
const domain = stringOf(auth, "domain") ?? attempt.domain;
|
|
@@ -23685,7 +23836,7 @@ async function pollLogin(attempt, fetchFn = fetch, signal) {
|
|
|
23685
23836
|
*/
|
|
23686
23837
|
async function resolveLoginIdentity(credentials, resolve, fetchFn, signal) {
|
|
23687
23838
|
const resolved = withResolvedIdentity(credentials);
|
|
23688
|
-
const identity = await (resolve ?? ((current) => fetchAccountIdentity(current, {
|
|
23839
|
+
const identity = await (resolve ?? ((current) => fetchAccountIdentity$1(current, {
|
|
23689
23840
|
fetchFn,
|
|
23690
23841
|
...signal === void 0 ? {} : { signal }
|
|
23691
23842
|
})))(resolved).catch(() => null);
|
|
@@ -24353,7 +24504,7 @@ function registerWorkBuddyRoutes(ctx, store, modelSettings, preferences, options
|
|
|
24353
24504
|
* 3. **Reasoning rides `delta.reasoning_content`,** not OpenAI's
|
|
24354
24505
|
* `reasoning_summary`, and is emitted as its own DSH reasoning block.
|
|
24355
24506
|
*/
|
|
24356
|
-
function isRecord$
|
|
24507
|
+
function isRecord$8(value) {
|
|
24357
24508
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24358
24509
|
}
|
|
24359
24510
|
function asString$4(value) {
|
|
@@ -24389,17 +24540,17 @@ const SUPPORTED_IMAGE_MEDIA_TYPES$1 = /* @__PURE__ */ new Set([
|
|
|
24389
24540
|
]);
|
|
24390
24541
|
function attachmentOf$1(block) {
|
|
24391
24542
|
const attachment = block.attachment;
|
|
24392
|
-
if (!isRecord$
|
|
24543
|
+
if (!isRecord$8(attachment)) return void 0;
|
|
24393
24544
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
24394
24545
|
}
|
|
24395
24546
|
function attachmentLabel$1(block) {
|
|
24396
|
-
const attachment = isRecord$
|
|
24547
|
+
const attachment = isRecord$8(block.attachment) ? block.attachment : void 0;
|
|
24397
24548
|
return asString$4(attachment?.name) || asString$4(attachment?.attachmentId);
|
|
24398
24549
|
}
|
|
24399
24550
|
function collectImageRefs$1(content, refs) {
|
|
24400
24551
|
if (!Array.isArray(content)) return;
|
|
24401
24552
|
for (const block of content) {
|
|
24402
|
-
if (!isRecord$
|
|
24553
|
+
if (!isRecord$8(block)) continue;
|
|
24403
24554
|
if (block.type === "image") {
|
|
24404
24555
|
const attachment = attachmentOf$1(block);
|
|
24405
24556
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -24420,7 +24571,7 @@ function requestImageBytes$1(block) {
|
|
|
24420
24571
|
function collectRequestImageBytes$1(content, lengths) {
|
|
24421
24572
|
if (!Array.isArray(content)) return;
|
|
24422
24573
|
for (const block of content) {
|
|
24423
|
-
if (!isRecord$
|
|
24574
|
+
if (!isRecord$8(block) || block.type !== "image") continue;
|
|
24424
24575
|
const bytes = requestImageBytes$1(block);
|
|
24425
24576
|
if (bytes !== void 0) lengths.push(bytes);
|
|
24426
24577
|
}
|
|
@@ -24447,7 +24598,7 @@ function offloadOldestRequestImages$1(options) {
|
|
|
24447
24598
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
24448
24599
|
let replaced = false;
|
|
24449
24600
|
const content = message.content.map((block) => {
|
|
24450
|
-
if (remaining.count === 0 || !isRecord$
|
|
24601
|
+
if (remaining.count === 0 || !isRecord$8(block) || block.type !== "image") return block;
|
|
24451
24602
|
if (requestImageBytes$1(block) === void 0) return block;
|
|
24452
24603
|
remaining.count -= 1;
|
|
24453
24604
|
replaced = true;
|
|
@@ -24501,7 +24652,7 @@ function unavailableImageText$1(block) {
|
|
|
24501
24652
|
}
|
|
24502
24653
|
function imageBlockToInline$1(block, images) {
|
|
24503
24654
|
let data = asString$4(block.data) || asString$4(block.base64);
|
|
24504
|
-
const source = isRecord$
|
|
24655
|
+
const source = isRecord$8(block.source) ? block.source : void 0;
|
|
24505
24656
|
if (!data && source) data = asString$4(source.data) || asString$4(source.base64);
|
|
24506
24657
|
let mediaType = asString$4(block.mimeType) || asString$4(block.mediaType) || (source ? asString$4(source.mimeType) || asString$4(source.mediaType) : void 0) || "image/png";
|
|
24507
24658
|
if (data?.startsWith("data:")) {
|
|
@@ -24527,7 +24678,7 @@ function textOf$1(content) {
|
|
|
24527
24678
|
if (!Array.isArray(content)) return "";
|
|
24528
24679
|
const parts = [];
|
|
24529
24680
|
for (const block of content) {
|
|
24530
|
-
if (!isRecord$
|
|
24681
|
+
if (!isRecord$8(block)) continue;
|
|
24531
24682
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText$1(block.text));
|
|
24532
24683
|
else if (block.type === "tool-result") parts.push(textOf$1(block.content));
|
|
24533
24684
|
}
|
|
@@ -24536,7 +24687,7 @@ function textOf$1(content) {
|
|
|
24536
24687
|
function toolResultText$1(blocks) {
|
|
24537
24688
|
if (!Array.isArray(blocks)) return "";
|
|
24538
24689
|
return blocks.map((block) => {
|
|
24539
|
-
if (!isRecord$
|
|
24690
|
+
if (!isRecord$8(block)) return "";
|
|
24540
24691
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText$1(block.text);
|
|
24541
24692
|
if (block.type === "tool-result") return toolResultText$1(block.content);
|
|
24542
24693
|
if (block.type === "image") return `[image: ${attachmentLabel$1(block) ?? "attached image"}]`;
|
|
@@ -24548,7 +24699,7 @@ function toolResultImageBlocks(blocks, images) {
|
|
|
24548
24699
|
if (!Array.isArray(blocks)) return [];
|
|
24549
24700
|
const out = [];
|
|
24550
24701
|
for (const block of blocks) {
|
|
24551
|
-
if (!isRecord$
|
|
24702
|
+
if (!isRecord$8(block)) continue;
|
|
24552
24703
|
if (block.type === "image") {
|
|
24553
24704
|
const inline = imageBlockToInline$1(block, images);
|
|
24554
24705
|
if (inline && SUPPORTED_IMAGE_MEDIA_TYPES$1.has(inline.mediaType)) out.push({
|
|
@@ -24593,7 +24744,7 @@ function leadingSystemText$1(options) {
|
|
|
24593
24744
|
}
|
|
24594
24745
|
/** Drop the JSON-Schema keywords provider gateways reject or ignore. */
|
|
24595
24746
|
function stripMetaSchema(schema) {
|
|
24596
|
-
if (!isRecord$
|
|
24747
|
+
if (!isRecord$8(schema)) return {
|
|
24597
24748
|
type: "object",
|
|
24598
24749
|
properties: {}
|
|
24599
24750
|
};
|
|
@@ -24606,7 +24757,7 @@ function openAIUserContent(message, images) {
|
|
|
24606
24757
|
const parts = [];
|
|
24607
24758
|
let hasImage = false;
|
|
24608
24759
|
for (const block of message.content) {
|
|
24609
|
-
if (!isRecord$
|
|
24760
|
+
if (!isRecord$8(block)) continue;
|
|
24610
24761
|
if (block.type === "text" && typeof block.text === "string") {
|
|
24611
24762
|
const text = sanitizeText$1(block.text);
|
|
24612
24763
|
if (text !== "") parts.push({
|
|
@@ -24634,7 +24785,7 @@ function openAIAssistantContent(message) {
|
|
|
24634
24785
|
const textParts = [];
|
|
24635
24786
|
const toolCalls = [];
|
|
24636
24787
|
for (const block of message.content) {
|
|
24637
|
-
if (!isRecord$
|
|
24788
|
+
if (!isRecord$8(block)) continue;
|
|
24638
24789
|
if (block.type === "text" && typeof block.text === "string") textParts.push(sanitizeText$1(block.text));
|
|
24639
24790
|
else if (block.type === "tool-call" && typeof block.name === "string") toolCalls.push({
|
|
24640
24791
|
id: typeof block.id === "string" && block.id !== "" ? block.id : `call_${toolCalls.length}`,
|
|
@@ -24670,7 +24821,7 @@ function buildChatRequest(options, images = NO_RESOLVED_IMAGES$1) {
|
|
|
24670
24821
|
while (index < conversation.length && isToolResultMessage$1(conversation[index])) {
|
|
24671
24822
|
const current = conversation[index];
|
|
24672
24823
|
const block = current.content[0];
|
|
24673
|
-
const callId = isRecord$
|
|
24824
|
+
const callId = isRecord$8(block) && typeof block.toolCallId === "string" ? block.toolCallId : "";
|
|
24674
24825
|
messages.push({
|
|
24675
24826
|
role: "tool",
|
|
24676
24827
|
tool_call_id: callId,
|
|
@@ -24810,24 +24961,24 @@ function processStreamLine$1(line, state) {
|
|
|
24810
24961
|
}
|
|
24811
24962
|
if (payload === "") return [];
|
|
24812
24963
|
const chunk = safeJsonParse$1(payload);
|
|
24813
|
-
if (!isRecord$
|
|
24964
|
+
if (!isRecord$8(chunk)) return [];
|
|
24814
24965
|
const out = [];
|
|
24815
|
-
const errorPayload = isRecord$
|
|
24966
|
+
const errorPayload = isRecord$8(chunk.error) ? chunk.error : void 0;
|
|
24816
24967
|
if (errorPayload !== void 0) throw new LlmError$1(`WorkBuddy stream error: ${asString$4(errorPayload.message) ?? "unknown error"}`, "PROVIDER_ERROR");
|
|
24817
|
-
const usage = isRecord$
|
|
24968
|
+
const usage = isRecord$8(chunk.usage) ? chunk.usage : void 0;
|
|
24818
24969
|
if (usage) {
|
|
24819
24970
|
state.sawUsage = true;
|
|
24820
24971
|
const prompt = numberOr$1(usage.prompt_tokens, 0);
|
|
24821
|
-
const details = isRecord$
|
|
24972
|
+
const details = isRecord$8(usage.prompt_tokens_details) ? usage.prompt_tokens_details : void 0;
|
|
24822
24973
|
const cached = details ? numberOr$1(details.cached_tokens, 0) : 0;
|
|
24823
24974
|
state.inputTokens = Math.max(0, prompt - cached);
|
|
24824
24975
|
state.cacheReadTokens = cached;
|
|
24825
24976
|
state.outputTokens = numberOr$1(usage.completion_tokens, state.outputTokens);
|
|
24826
|
-
if (isRecord$
|
|
24977
|
+
if (isRecord$8(usage.completion_tokens_details)) state.reasoningTokens = numberOr$1(usage.completion_tokens_details.reasoning_tokens, state.reasoningTokens);
|
|
24827
24978
|
}
|
|
24828
24979
|
const choices = Array.isArray(chunk.choices) ? chunk.choices : [];
|
|
24829
|
-
const choice = isRecord$
|
|
24830
|
-
const delta = choice && isRecord$
|
|
24980
|
+
const choice = isRecord$8(choices[0]) ? choices[0] : void 0;
|
|
24981
|
+
const delta = choice && isRecord$8(choice.delta) ? choice.delta : void 0;
|
|
24831
24982
|
if (delta) {
|
|
24832
24983
|
const reasoning = asString$4(delta.reasoning_content) ?? asString$4(delta.reasoning);
|
|
24833
24984
|
if (reasoning !== void 0 && reasoning !== "") {
|
|
@@ -24855,7 +25006,7 @@ function processStreamLine$1(line, state) {
|
|
|
24855
25006
|
}
|
|
24856
25007
|
const toolDeltas = Array.isArray(delta.tool_calls) ? delta.tool_calls : [];
|
|
24857
25008
|
for (const entry of toolDeltas) {
|
|
24858
|
-
if (!isRecord$
|
|
25009
|
+
if (!isRecord$8(entry)) continue;
|
|
24859
25010
|
out.push(...applyToolDelta(entry, state));
|
|
24860
25011
|
}
|
|
24861
25012
|
}
|
|
@@ -24869,7 +25020,7 @@ function processStreamLine$1(line, state) {
|
|
|
24869
25020
|
}
|
|
24870
25021
|
function applyToolDelta(entry, state) {
|
|
24871
25022
|
const wireIndex = typeof entry.index === "number" ? entry.index : 0;
|
|
24872
|
-
const fn = isRecord$
|
|
25023
|
+
const fn = isRecord$8(entry.function) ? entry.function : {};
|
|
24873
25024
|
const out = [];
|
|
24874
25025
|
let call = state.toolCalls.get(wireIndex);
|
|
24875
25026
|
if (call === void 0) {
|
|
@@ -26590,7 +26741,7 @@ function defaultClaudeSettings() {
|
|
|
26590
26741
|
selectedAccountId: null
|
|
26591
26742
|
};
|
|
26592
26743
|
}
|
|
26593
|
-
function isRecord$
|
|
26744
|
+
function isRecord$7(value) {
|
|
26594
26745
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26595
26746
|
}
|
|
26596
26747
|
/**
|
|
@@ -26694,7 +26845,7 @@ function normalizeScopes$1(value) {
|
|
|
26694
26845
|
throw new Error("Claude credential scopes are invalid");
|
|
26695
26846
|
}
|
|
26696
26847
|
function parseAccountInfo(value) {
|
|
26697
|
-
if (!isRecord$
|
|
26848
|
+
if (!isRecord$7(value)) return void 0;
|
|
26698
26849
|
const account = {};
|
|
26699
26850
|
const uuid = optionalString(value, "uuid");
|
|
26700
26851
|
if (uuid !== void 0) account.uuid = uuid;
|
|
@@ -26714,7 +26865,7 @@ function parseAccountInfo(value) {
|
|
|
26714
26865
|
* no `user:inference` scope is refused here (see {@link isSubscriptionCredential}).
|
|
26715
26866
|
*/
|
|
26716
26867
|
function parseClaudeCredentials(value) {
|
|
26717
|
-
if (!isRecord$
|
|
26868
|
+
if (!isRecord$7(value)) throw new Error("Claude credential payload is invalid");
|
|
26718
26869
|
const accessToken = nonEmptyString$3(value.accessToken);
|
|
26719
26870
|
if (accessToken === void 0) throw new Error("Claude credential is missing its access token");
|
|
26720
26871
|
const refreshToken = nonEmptyString$3(value.refreshToken);
|
|
@@ -26737,7 +26888,7 @@ function parseClaudeCredentials(value) {
|
|
|
26737
26888
|
return credentials;
|
|
26738
26889
|
}
|
|
26739
26890
|
function parseAccountRecord(value) {
|
|
26740
|
-
if (!isRecord$
|
|
26891
|
+
if (!isRecord$7(value)) return null;
|
|
26741
26892
|
let credentials;
|
|
26742
26893
|
try {
|
|
26743
26894
|
credentials = parseClaudeCredentials(value.credentials);
|
|
@@ -26767,7 +26918,7 @@ function parseAccountRecord(value) {
|
|
|
26767
26918
|
* first read.
|
|
26768
26919
|
*/
|
|
26769
26920
|
function parseClaudeCredentialDocument(value) {
|
|
26770
|
-
if (!isRecord$
|
|
26921
|
+
if (!isRecord$7(value)) throw new Error("Claude credential file payload is invalid");
|
|
26771
26922
|
if (!Array.isArray(value.accounts)) {
|
|
26772
26923
|
if (value.accessToken !== void 0 || value.refreshToken !== void 0) {
|
|
26773
26924
|
const credentials = parseClaudeCredentials(value);
|
|
@@ -26814,11 +26965,11 @@ function parseClaudeCredentialDocument(value) {
|
|
|
26814
26965
|
* schemastery strips undeclared keys instead of failing on them.
|
|
26815
26966
|
*/
|
|
26816
26967
|
function parseClaudeModelSettings(value) {
|
|
26817
|
-
const record = isRecord$
|
|
26968
|
+
const record = isRecord$7(value) ? value : {};
|
|
26818
26969
|
const defaults = defaultClaudeSettings();
|
|
26819
26970
|
const enabledModelIds = Array.isArray(record.enabledModelIds) ? record.enabledModelIds.filter((id) => typeof id === "string" && id.trim() !== "") : defaults.enabledModelIds;
|
|
26820
26971
|
const contextWindowOverrides = {};
|
|
26821
|
-
if (isRecord$
|
|
26972
|
+
if (isRecord$7(record.contextWindowOverrides)) {
|
|
26822
26973
|
for (const [model, window] of Object.entries(record.contextWindowOverrides)) if (typeof window === "number" && Number.isFinite(window) && window > 0) contextWindowOverrides[model] = window;
|
|
26823
26974
|
}
|
|
26824
26975
|
const defaultReasoningEffort = nonEmptyString$3(record.defaultReasoningEffort) ?? null;
|
|
@@ -27237,11 +27388,11 @@ function registerClaudePreferenceStore(settings, fallbackStore = new FileModelSe
|
|
|
27237
27388
|
* them can pass. That distinction is exported as a first-class value rather
|
|
27238
27389
|
* than left for the caller to re-derive from headers.
|
|
27239
27390
|
*/
|
|
27240
|
-
function isRecord$
|
|
27391
|
+
function isRecord$6(value) {
|
|
27241
27392
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27242
27393
|
}
|
|
27243
27394
|
function asRecord$3(value) {
|
|
27244
|
-
return isRecord$
|
|
27395
|
+
return isRecord$6(value) ? value : void 0;
|
|
27245
27396
|
}
|
|
27246
27397
|
/** A non-blank string, or undefined. Numeric values are NOT coerced here. */
|
|
27247
27398
|
function asString$3(value) {
|
|
@@ -28200,7 +28351,7 @@ function classifyFailure(status, bodyText, headers = {}) {
|
|
|
28200
28351
|
* land the breakpoint on a block the merge then moves back, which leaves a
|
|
28201
28352
|
* marker in the request that caches nothing the next turn can reuse.
|
|
28202
28353
|
*/
|
|
28203
|
-
function isRecord$
|
|
28354
|
+
function isRecord$5(value) {
|
|
28204
28355
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28205
28356
|
}
|
|
28206
28357
|
function asString$2(value) {
|
|
@@ -28619,17 +28770,17 @@ const SUPPORTED_IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
|
28619
28770
|
]);
|
|
28620
28771
|
function attachmentOf(block) {
|
|
28621
28772
|
const attachment = block.attachment;
|
|
28622
|
-
if (!isRecord$
|
|
28773
|
+
if (!isRecord$5(attachment)) return void 0;
|
|
28623
28774
|
return typeof attachment.attachmentId === "string" ? attachment : void 0;
|
|
28624
28775
|
}
|
|
28625
28776
|
function attachmentLabel(block) {
|
|
28626
|
-
const attachment = isRecord$
|
|
28777
|
+
const attachment = isRecord$5(block.attachment) ? block.attachment : void 0;
|
|
28627
28778
|
return asString$2(attachment?.name) || asString$2(attachment?.attachmentId);
|
|
28628
28779
|
}
|
|
28629
28780
|
function collectImageRefs(content, refs) {
|
|
28630
28781
|
if (!Array.isArray(content)) return;
|
|
28631
28782
|
for (const block of content) {
|
|
28632
|
-
if (!isRecord$
|
|
28783
|
+
if (!isRecord$5(block)) continue;
|
|
28633
28784
|
if (block.type === "image") {
|
|
28634
28785
|
const attachment = attachmentOf(block);
|
|
28635
28786
|
if (attachment) refs.set(attachment.attachmentId, attachment);
|
|
@@ -28650,7 +28801,7 @@ function requestImageBytes(block) {
|
|
|
28650
28801
|
function collectRequestImageBytes(content, lengths) {
|
|
28651
28802
|
if (!Array.isArray(content)) return;
|
|
28652
28803
|
for (const block of content) {
|
|
28653
|
-
if (!isRecord$
|
|
28804
|
+
if (!isRecord$5(block) || block.type !== "image") continue;
|
|
28654
28805
|
const bytes = requestImageBytes(block);
|
|
28655
28806
|
if (bytes !== void 0) lengths.push(bytes);
|
|
28656
28807
|
}
|
|
@@ -28679,7 +28830,7 @@ function offloadOldestRequestImages(options) {
|
|
|
28679
28830
|
if (remaining.count === 0 || !Array.isArray(message.content)) return message;
|
|
28680
28831
|
let replaced = false;
|
|
28681
28832
|
const content = message.content.map((block) => {
|
|
28682
|
-
if (remaining.count === 0 || !isRecord$
|
|
28833
|
+
if (remaining.count === 0 || !isRecord$5(block) || block.type !== "image") return block;
|
|
28683
28834
|
if (requestImageBytes(block) === void 0) return block;
|
|
28684
28835
|
remaining.count -= 1;
|
|
28685
28836
|
replaced = true;
|
|
@@ -28737,7 +28888,7 @@ async function resolveRequestImages(options, attachments, signal) {
|
|
|
28737
28888
|
*/
|
|
28738
28889
|
function imageBlockToInline(block, images) {
|
|
28739
28890
|
let data = asString$2(block.data) || asString$2(block.base64);
|
|
28740
|
-
const source = isRecord$
|
|
28891
|
+
const source = isRecord$5(block.source) ? block.source : void 0;
|
|
28741
28892
|
if (!data && source) data = asString$2(source.data) || asString$2(source.base64);
|
|
28742
28893
|
let mediaType = asString$2(block.mimeType) || asString$2(block.mediaType) || (source ? asString$2(source.mimeType) || asString$2(source.mediaType) : void 0) || "image/png";
|
|
28743
28894
|
if (data?.startsWith("data:")) {
|
|
@@ -28791,7 +28942,7 @@ function textOf(content) {
|
|
|
28791
28942
|
if (!Array.isArray(content)) return "";
|
|
28792
28943
|
const parts = [];
|
|
28793
28944
|
for (const block of content) {
|
|
28794
|
-
if (!isRecord$
|
|
28945
|
+
if (!isRecord$5(block)) continue;
|
|
28795
28946
|
if (block.type === "text" && typeof block.text === "string") parts.push(sanitizeText(block.text));
|
|
28796
28947
|
else if (block.type === "tool-result") parts.push(textOf(block.content));
|
|
28797
28948
|
}
|
|
@@ -28835,15 +28986,15 @@ function replayBlockFor(message, index) {
|
|
|
28835
28986
|
const source = message.source;
|
|
28836
28987
|
if (source === void 0 || source.kind !== "model") return void 0;
|
|
28837
28988
|
const state = source.replayState;
|
|
28838
|
-
if (!isRecord$
|
|
28989
|
+
if (!isRecord$5(state)) return void 0;
|
|
28839
28990
|
if (Array.isArray(state.blocks)) {
|
|
28840
28991
|
const entry = state.blocks[index];
|
|
28841
|
-
return isRecord$
|
|
28992
|
+
return isRecord$5(entry) ? entry : void 0;
|
|
28842
28993
|
}
|
|
28843
|
-
const response = isRecord$
|
|
28994
|
+
const response = isRecord$5(state.response) ? state.response : void 0;
|
|
28844
28995
|
const blocks = response !== void 0 && Array.isArray(response.blocks) ? response.blocks : void 0;
|
|
28845
28996
|
const entry = blocks === void 0 ? void 0 : blocks[index];
|
|
28846
|
-
return isRecord$
|
|
28997
|
+
return isRecord$5(entry) ? entry : void 0;
|
|
28847
28998
|
}
|
|
28848
28999
|
/**
|
|
28849
29000
|
* Concatenated system-prompt text, or undefined when the caller stated none.
|
|
@@ -28957,7 +29108,7 @@ function markClaudeCacheBreakpoints(body) {
|
|
|
28957
29108
|
}
|
|
28958
29109
|
/** One tool definition in the wire shape. */
|
|
28959
29110
|
function wireTool(tool, names) {
|
|
28960
|
-
const schema = isRecord$
|
|
29111
|
+
const schema = isRecord$5(tool.parameters) ? { ...tool.parameters } : {
|
|
28961
29112
|
type: "object",
|
|
28962
29113
|
properties: {}
|
|
28963
29114
|
};
|
|
@@ -28979,7 +29130,7 @@ function claudeUserContent(message, images) {
|
|
|
28979
29130
|
return blocks;
|
|
28980
29131
|
}
|
|
28981
29132
|
for (const block of message.content) {
|
|
28982
|
-
if (!isRecord$
|
|
29133
|
+
if (!isRecord$5(block)) continue;
|
|
28983
29134
|
if (block.type === "text" && typeof block.text === "string") {
|
|
28984
29135
|
const text = sanitizeText(block.text);
|
|
28985
29136
|
if (text !== "") blocks.push({
|
|
@@ -28999,7 +29150,7 @@ function claudeUserContent(message, images) {
|
|
|
28999
29150
|
/** Whether one message is the flattened 0.1.7 tool result (see isToolResultMessage). */
|
|
29000
29151
|
function isFlattenedToolMessage(message) {
|
|
29001
29152
|
if (message.role !== "tool") return false;
|
|
29002
|
-
return !message.content.some((block) => isRecord$
|
|
29153
|
+
return !message.content.some((block) => isRecord$5(block) && block.type === "tool-result");
|
|
29003
29154
|
}
|
|
29004
29155
|
/**
|
|
29005
29156
|
* One tool_result block.
|
|
@@ -29025,7 +29176,7 @@ function toolResultBlockFor(toolUseId, resultBlocks, isError, images) {
|
|
|
29025
29176
|
function toolResultText(blocks) {
|
|
29026
29177
|
if (!Array.isArray(blocks)) return "";
|
|
29027
29178
|
return blocks.map((block) => {
|
|
29028
|
-
if (!isRecord$
|
|
29179
|
+
if (!isRecord$5(block)) return "";
|
|
29029
29180
|
if (block.type === "text" && typeof block.text === "string") return sanitizeText(block.text);
|
|
29030
29181
|
if (block.type === "tool-result") return toolResultText(block.content);
|
|
29031
29182
|
if (block.type === "image") {
|
|
@@ -29045,7 +29196,7 @@ function toolResultContent(blocks, images) {
|
|
|
29045
29196
|
const out = [];
|
|
29046
29197
|
let hasImage = false;
|
|
29047
29198
|
for (const block of blocks) {
|
|
29048
|
-
if (!isRecord$
|
|
29199
|
+
if (!isRecord$5(block)) continue;
|
|
29049
29200
|
if (block.type === "text" && typeof block.text === "string") {
|
|
29050
29201
|
out.push({
|
|
29051
29202
|
type: "text",
|
|
@@ -29079,7 +29230,7 @@ function claudeAssistantContent(message, names) {
|
|
|
29079
29230
|
if (!Array.isArray(message.content)) return blocks;
|
|
29080
29231
|
for (let index = 0; index < message.content.length; index++) {
|
|
29081
29232
|
const block = message.content[index];
|
|
29082
|
-
if (!isRecord$
|
|
29233
|
+
if (!isRecord$5(block)) continue;
|
|
29083
29234
|
if (block.type === "text" && typeof block.text === "string") {
|
|
29084
29235
|
const text = sanitizeText(block.text);
|
|
29085
29236
|
if (text !== "") blocks.push({
|
|
@@ -29094,7 +29245,7 @@ function claudeAssistantContent(message, names) {
|
|
|
29094
29245
|
type: "tool_use",
|
|
29095
29246
|
id: typeof block.id === "string" && block.id !== "" ? block.id : "toolu_" + blocks.length,
|
|
29096
29247
|
name: claudeWireToolName(block.name, names),
|
|
29097
|
-
input: isRecord$
|
|
29248
|
+
input: isRecord$5(parsed) ? parsed : {}
|
|
29098
29249
|
});
|
|
29099
29250
|
continue;
|
|
29100
29251
|
}
|
|
@@ -29118,7 +29269,7 @@ function toolCallArguments(raw) {
|
|
|
29118
29269
|
function isToolResultMessage(message) {
|
|
29119
29270
|
if (message.source?.kind === "tool") return true;
|
|
29120
29271
|
if (!Array.isArray(message.content)) return false;
|
|
29121
|
-
if (message.content.some((block) => isRecord$
|
|
29272
|
+
if (message.content.some((block) => isRecord$5(block) && block.type === "tool-result")) return true;
|
|
29122
29273
|
return message.role === "tool";
|
|
29123
29274
|
}
|
|
29124
29275
|
/**
|
|
@@ -29471,13 +29622,13 @@ function processStreamLine(line, state) {
|
|
|
29471
29622
|
const payload = trimmed.slice(5).trim();
|
|
29472
29623
|
if (payload === "" || payload === "[DONE]") return [];
|
|
29473
29624
|
const event = safeJsonParse(payload);
|
|
29474
|
-
if (!isRecord$
|
|
29625
|
+
if (!isRecord$5(event)) return [];
|
|
29475
29626
|
const type = asString$2(event.type);
|
|
29476
29627
|
const out = [];
|
|
29477
29628
|
if (type === "message_start") {
|
|
29478
29629
|
state.sawMessageStart = true;
|
|
29479
|
-
const message = isRecord$
|
|
29480
|
-
const usage = message !== void 0 && isRecord$
|
|
29630
|
+
const message = isRecord$5(event.message) ? event.message : void 0;
|
|
29631
|
+
const usage = message !== void 0 && isRecord$5(message.usage) ? message.usage : void 0;
|
|
29481
29632
|
if (usage !== void 0) applyUsage(state, usage, false);
|
|
29482
29633
|
const stop = message === void 0 ? void 0 : asString$2(message.stop_reason);
|
|
29483
29634
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
@@ -29485,13 +29636,13 @@ function processStreamLine(line, state) {
|
|
|
29485
29636
|
}
|
|
29486
29637
|
if (type === "content_block_start") {
|
|
29487
29638
|
const contentIndex = numberOr(event.index, -1);
|
|
29488
|
-
const block = isRecord$
|
|
29639
|
+
const block = isRecord$5(event.content_block) ? event.content_block : {};
|
|
29489
29640
|
const blockType = asString$2(block.type);
|
|
29490
29641
|
if (blockType === "tool_use") {
|
|
29491
29642
|
const index = state.blocks.length;
|
|
29492
29643
|
const id = asString$2(block.id) ?? "toolu_" + String(index);
|
|
29493
29644
|
const name = claudeOriginalToolName(asString$2(block.name) ?? "", state.toolNames);
|
|
29494
|
-
const seedInput = isRecord$
|
|
29645
|
+
const seedInput = isRecord$5(block.input) && Object.keys(block.input).length > 0 ? JSON.stringify(block.input) : "";
|
|
29495
29646
|
const pending = {
|
|
29496
29647
|
index,
|
|
29497
29648
|
id,
|
|
@@ -29542,7 +29693,7 @@ function processStreamLine(line, state) {
|
|
|
29542
29693
|
}
|
|
29543
29694
|
if (type === "content_block_delta") {
|
|
29544
29695
|
const contentIndex = numberOr(event.index, -1);
|
|
29545
|
-
const delta = isRecord$
|
|
29696
|
+
const delta = isRecord$5(event.delta) ? event.delta : {};
|
|
29546
29697
|
const deltaType = asString$2(delta.type);
|
|
29547
29698
|
if (deltaType === "input_json_delta") {
|
|
29548
29699
|
const pending = state.toolCalls.get(contentIndex);
|
|
@@ -29591,10 +29742,10 @@ function processStreamLine(line, state) {
|
|
|
29591
29742
|
return closeTextBlock(state, contentIndex);
|
|
29592
29743
|
}
|
|
29593
29744
|
if (type === "message_delta") {
|
|
29594
|
-
const delta = isRecord$
|
|
29745
|
+
const delta = isRecord$5(event.delta) ? event.delta : void 0;
|
|
29595
29746
|
const stop = delta === void 0 ? void 0 : asString$2(delta.stop_reason);
|
|
29596
29747
|
if (stop !== void 0 && stop !== "") state.finishReason = stop;
|
|
29597
|
-
const usage = isRecord$
|
|
29748
|
+
const usage = isRecord$5(event.usage) ? event.usage : void 0;
|
|
29598
29749
|
if (usage !== void 0) applyUsage(state, usage, true);
|
|
29599
29750
|
return out;
|
|
29600
29751
|
}
|
|
@@ -29603,7 +29754,7 @@ function processStreamLine(line, state) {
|
|
|
29603
29754
|
return closeStream(state);
|
|
29604
29755
|
}
|
|
29605
29756
|
if (type === "error") {
|
|
29606
|
-
const error = isRecord$
|
|
29757
|
+
const error = isRecord$5(event.error) ? event.error : {};
|
|
29607
29758
|
const message = asString$2(error.message) ?? "unknown error";
|
|
29608
29759
|
const kind = asString$2(error.type);
|
|
29609
29760
|
throw new LlmError$1("Claude stream error" + (kind === void 0 ? "" : " (" + kind + ")") + ": " + message, "PROVIDER_ERROR");
|
|
@@ -31454,7 +31605,7 @@ const CLAUDE_CODE_CREDENTIAL_SOURCE = "claude-code";
|
|
|
31454
31605
|
* the import has to be repeated afterwards.
|
|
31455
31606
|
*/
|
|
31456
31607
|
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$
|
|
31608
|
+
function isRecord$4(value) {
|
|
31458
31609
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31459
31610
|
}
|
|
31460
31611
|
/** A trimmed, non-empty string, or nothing. */
|
|
@@ -31617,9 +31768,9 @@ function finiteEpochMs(value) {
|
|
|
31617
31768
|
* mcpOAuth holds cannot reach the result.
|
|
31618
31769
|
*/
|
|
31619
31770
|
function parseAdoptedClaudeCredential(value, sourcePath) {
|
|
31620
|
-
if (!isRecord$
|
|
31771
|
+
if (!isRecord$4(value)) return void 0;
|
|
31621
31772
|
const oauth = value[CLAUDE_CODE_CREDENTIAL_KEY];
|
|
31622
|
-
if (!isRecord$
|
|
31773
|
+
if (!isRecord$4(oauth)) return void 0;
|
|
31623
31774
|
const accessToken = nonEmptyString$1(oauth.accessToken);
|
|
31624
31775
|
if (accessToken === void 0) return void 0;
|
|
31625
31776
|
const refreshToken = nonEmptyString$1(oauth.refreshToken);
|
|
@@ -31672,8 +31823,8 @@ async function readClaudeCodeCredentials(paths = claudeCodeCredentialPaths()) {
|
|
|
31672
31823
|
* discard an account the user added here.
|
|
31673
31824
|
*/
|
|
31674
31825
|
function isAdoptedClaudeCredential(value) {
|
|
31675
|
-
if (!isRecord$
|
|
31676
|
-
return value.adopted === true && value.source === "claude-code" && isRecord$
|
|
31826
|
+
if (!isRecord$4(value)) return false;
|
|
31827
|
+
return value.adopted === true && value.source === "claude-code" && isRecord$4(value.credentials);
|
|
31677
31828
|
}
|
|
31678
31829
|
/**
|
|
31679
31830
|
* Whether an adopted credential's access token is already unusable.
|
|
@@ -31840,7 +31991,7 @@ const ADOPTED_NEVER_REFRESHED_MESSAGE = "The sign-in imported from Claude Code i
|
|
|
31840
31991
|
function claudePoolPath() {
|
|
31841
31992
|
return path.join(dshHomeDir(), "storages", "claude-pool.json");
|
|
31842
31993
|
}
|
|
31843
|
-
function isRecord$
|
|
31994
|
+
function isRecord$3(value) {
|
|
31844
31995
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31845
31996
|
}
|
|
31846
31997
|
/** A trimmed, non-empty string, or nothing. */
|
|
@@ -31876,7 +32027,7 @@ function claudeAliasFor(credentials, position) {
|
|
|
31876
32027
|
* missing token, or an expiry that is not a finite number.
|
|
31877
32028
|
*/
|
|
31878
32029
|
function parseClaudePoolCredentials(value) {
|
|
31879
|
-
if (!isRecord$
|
|
32030
|
+
if (!isRecord$3(value)) return null;
|
|
31880
32031
|
const accessToken = nonEmptyString(value.accessToken);
|
|
31881
32032
|
const refreshToken = nonEmptyString(value.refreshToken);
|
|
31882
32033
|
if (accessToken === void 0 || refreshToken === void 0) return null;
|
|
@@ -31900,7 +32051,7 @@ function parseClaudePoolCredentials(value) {
|
|
|
31900
32051
|
}
|
|
31901
32052
|
const subscriptionType = nonEmptyString(value.subscriptionType);
|
|
31902
32053
|
if (subscriptionType !== void 0) credentials.subscriptionType = subscriptionType;
|
|
31903
|
-
if (isRecord$
|
|
32054
|
+
if (isRecord$3(value.account)) {
|
|
31904
32055
|
const uuid = nonEmptyString(value.account.uuid);
|
|
31905
32056
|
const emailAddress = nonEmptyString(value.account.email_address);
|
|
31906
32057
|
const emailCamel = nonEmptyString(value.account.emailAddress);
|
|
@@ -31990,10 +32141,10 @@ function claudeAuthRejectedReason(credentials) {
|
|
|
31990
32141
|
}
|
|
31991
32142
|
/** Validate and normalize one whole pool document. */
|
|
31992
32143
|
function parseClaudePoolData(value) {
|
|
31993
|
-
if (!isRecord$
|
|
32144
|
+
if (!isRecord$3(value)) throw new Error("Claude pool payload is invalid");
|
|
31994
32145
|
const accounts = [];
|
|
31995
32146
|
for (const item of Array.isArray(value.accounts) ? value.accounts : []) {
|
|
31996
|
-
if (!isRecord$
|
|
32147
|
+
if (!isRecord$3(item)) continue;
|
|
31997
32148
|
if (typeof item.id !== "string") continue;
|
|
31998
32149
|
const credentials = parseClaudePoolCredentials(item.credentials);
|
|
31999
32150
|
if (credentials === null) continue;
|
|
@@ -33344,23 +33495,23 @@ const CHECKIN_PATH = "/billing/meter/daily-checkin";
|
|
|
33344
33495
|
* interval keeps a long-lived process signing in on later days without a
|
|
33345
33496
|
* restart. Idle ticks cost no requests — the day state short-circuits them.
|
|
33346
33497
|
*/
|
|
33347
|
-
const CHECKIN_TICK_MS = 600 * 1e3;
|
|
33348
|
-
const CHECKIN_TIMEOUT_MS = 2e4;
|
|
33498
|
+
const CHECKIN_TICK_MS$1 = 600 * 1e3;
|
|
33499
|
+
const CHECKIN_TIMEOUT_MS$1 = 2e4;
|
|
33349
33500
|
/** State document the scheduler keeps beside the other plugin stores. */
|
|
33350
|
-
function checkinStatePath() {
|
|
33501
|
+
function checkinStatePath$1() {
|
|
33351
33502
|
return path.join(dshHomeDir(), "storages", "workbuddy-checkin.json");
|
|
33352
33503
|
}
|
|
33353
33504
|
/** Local calendar day an instant belongs to; state entries are keyed by it. */
|
|
33354
|
-
function localDateString(nowMs) {
|
|
33505
|
+
function localDateString$1(nowMs) {
|
|
33355
33506
|
const date = new Date(nowMs);
|
|
33356
33507
|
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
|
33357
33508
|
const day = `${date.getDate()}`.padStart(2, "0");
|
|
33358
33509
|
return `${date.getFullYear()}-${month}-${day}`;
|
|
33359
33510
|
}
|
|
33360
|
-
function isRecord(value) {
|
|
33511
|
+
function isRecord$2(value) {
|
|
33361
33512
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33362
33513
|
}
|
|
33363
|
-
function asCount(value) {
|
|
33514
|
+
function asCount$1(value) {
|
|
33364
33515
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
33365
33516
|
}
|
|
33366
33517
|
/**
|
|
@@ -33383,7 +33534,7 @@ function readBool(data, ...keys) {
|
|
|
33383
33534
|
function readCount(data, ...keys) {
|
|
33384
33535
|
for (const key of keys) {
|
|
33385
33536
|
const value = data[key];
|
|
33386
|
-
const direct = asCount(value);
|
|
33537
|
+
const direct = asCount$1(value);
|
|
33387
33538
|
if (direct !== void 0) return direct;
|
|
33388
33539
|
if (typeof value === "string" && value.trim() !== "") {
|
|
33389
33540
|
const parsed = Number(value);
|
|
@@ -33409,20 +33560,20 @@ function isUnauthorized(result) {
|
|
|
33409
33560
|
return result.code === 401;
|
|
33410
33561
|
}
|
|
33411
33562
|
/** 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;
|
|
33563
|
+
function parseStateEntry$1(value) {
|
|
33564
|
+
if (!isRecord$2(value) || typeof value.date !== "string") return null;
|
|
33414
33565
|
const entry = {
|
|
33415
33566
|
date: value.date,
|
|
33416
33567
|
done: value.done === true,
|
|
33417
33568
|
attempts: typeof value.attempts === "number" && Number.isFinite(value.attempts) ? value.attempts : 0
|
|
33418
33569
|
};
|
|
33419
33570
|
if (value.inactive === true) entry.inactive = true;
|
|
33420
|
-
const inactiveAt = asCount(value.inactiveAt);
|
|
33571
|
+
const inactiveAt = asCount$1(value.inactiveAt);
|
|
33421
33572
|
if (inactiveAt !== void 0) entry.inactiveAt = inactiveAt;
|
|
33422
33573
|
if (typeof value.lastError === "string") entry.lastError = value.lastError;
|
|
33423
|
-
const streakDays = asCount(value.streakDays);
|
|
33574
|
+
const streakDays = asCount$1(value.streakDays);
|
|
33424
33575
|
if (streakDays !== void 0) entry.streakDays = streakDays;
|
|
33425
|
-
const totalCredits = asCount(value.totalCredits);
|
|
33576
|
+
const totalCredits = asCount$1(value.totalCredits);
|
|
33426
33577
|
if (totalCredits !== void 0) entry.totalCredits = totalCredits;
|
|
33427
33578
|
return entry;
|
|
33428
33579
|
}
|
|
@@ -33450,7 +33601,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33450
33601
|
this.store = store;
|
|
33451
33602
|
this.options = options;
|
|
33452
33603
|
this.fetchFn = options.fetchFn ?? fetch;
|
|
33453
|
-
this.statePath = options.statePath ?? checkinStatePath();
|
|
33604
|
+
this.statePath = options.statePath ?? checkinStatePath$1();
|
|
33454
33605
|
this.now = options.now ?? (() => Date.now());
|
|
33455
33606
|
this.logger = options.logger;
|
|
33456
33607
|
}
|
|
@@ -33496,7 +33647,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33496
33647
|
if (!manual && !settings.enabled) return;
|
|
33497
33648
|
await this.load();
|
|
33498
33649
|
const nowMs = this.now();
|
|
33499
|
-
const today = localDateString(nowMs);
|
|
33650
|
+
const today = localDateString$1(nowMs);
|
|
33500
33651
|
let accounts;
|
|
33501
33652
|
try {
|
|
33502
33653
|
accounts = await this.store.list();
|
|
@@ -33538,7 +33689,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33538
33689
|
fresh = await this.forceRefresh(credentials, fresh);
|
|
33539
33690
|
status = await this.post(`${fresh.backend}${CHECKIN_STATUS_PATH}`, workBuddyHeaders(fresh));
|
|
33540
33691
|
}
|
|
33541
|
-
const statusData = isRecord(status?.data) ? status.data : {};
|
|
33692
|
+
const statusData = isRecord$2(status?.data) ? status.data : {};
|
|
33542
33693
|
if (readBool(statusData, "today_checked_in", "todayCheckedIn") === true) {
|
|
33543
33694
|
this.markSignedIn(entry, statusData);
|
|
33544
33695
|
this.logger?.info(`[workbuddy-checkin] ${id} already signed in today`);
|
|
@@ -33558,7 +33709,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33558
33709
|
fresh = await this.forceRefresh(credentials, fresh);
|
|
33559
33710
|
result = await this.post(`${fresh.backend}${CHECKIN_PATH}`, workBuddyHeaders(fresh));
|
|
33560
33711
|
}
|
|
33561
|
-
const payload = isRecord(result?.data) ? result.data : {};
|
|
33712
|
+
const payload = isRecord$2(result?.data) ? result.data : {};
|
|
33562
33713
|
if (result !== null && result.code === 0) {
|
|
33563
33714
|
this.markSignedIn(entry, payload);
|
|
33564
33715
|
this.logger?.info(`[workbuddy-checkin] ${id} signed in; total credits ${entry.totalCredits ?? "?"}`);
|
|
@@ -33620,7 +33771,7 @@ var WorkBuddyCheckinService = class {
|
|
|
33620
33771
|
await this.load();
|
|
33621
33772
|
const settings = this.options.settings();
|
|
33622
33773
|
const accounts = (await this.store.list().catch(() => [])).filter((credentials) => !isIntlDomain(credentials.domain));
|
|
33623
|
-
const today = localDateString(this.now());
|
|
33774
|
+
const today = localDateString$1(this.now());
|
|
33624
33775
|
let doneToday = 0;
|
|
33625
33776
|
let skippedToday = 0;
|
|
33626
33777
|
let failedToday = 0;
|
|
@@ -33645,11 +33796,11 @@ var WorkBuddyCheckinService = class {
|
|
|
33645
33796
|
this.loaded = true;
|
|
33646
33797
|
try {
|
|
33647
33798
|
const parsed = JSON.parse(await fsPromises.readFile(this.statePath, "utf8"));
|
|
33648
|
-
if (isRecord(parsed)) {
|
|
33649
|
-
const lastRunAt = asCount(parsed.lastRunAt);
|
|
33799
|
+
if (isRecord$2(parsed)) {
|
|
33800
|
+
const lastRunAt = asCount$1(parsed.lastRunAt);
|
|
33650
33801
|
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);
|
|
33802
|
+
if (isRecord$2(parsed.accounts)) for (const [id, value] of Object.entries(parsed.accounts)) {
|
|
33803
|
+
const entry = parseStateEntry$1(value);
|
|
33653
33804
|
if (entry !== null) this.state[id] = entry;
|
|
33654
33805
|
}
|
|
33655
33806
|
}
|
|
@@ -33673,13 +33824,13 @@ var WorkBuddyCheckinService = class {
|
|
|
33673
33824
|
method: "POST",
|
|
33674
33825
|
headers,
|
|
33675
33826
|
body: "{}",
|
|
33676
|
-
signal: AbortSignal.timeout(CHECKIN_TIMEOUT_MS)
|
|
33827
|
+
signal: AbortSignal.timeout(CHECKIN_TIMEOUT_MS$1)
|
|
33677
33828
|
});
|
|
33678
33829
|
const text = await response.text().catch(() => "");
|
|
33679
33830
|
let parsed = null;
|
|
33680
33831
|
try {
|
|
33681
33832
|
const value = JSON.parse(text);
|
|
33682
|
-
parsed = isRecord(value) ? value : null;
|
|
33833
|
+
parsed = isRecord$2(value) ? value : null;
|
|
33683
33834
|
} catch {
|
|
33684
33835
|
parsed = null;
|
|
33685
33836
|
}
|
|
@@ -33692,6 +33843,660 @@ var WorkBuddyCheckinService = class {
|
|
|
33692
33843
|
}
|
|
33693
33844
|
};
|
|
33694
33845
|
//#endregion
|
|
33846
|
+
//#region src/host/minimax-code/checkin-gateway.ts
|
|
33847
|
+
/**
|
|
33848
|
+
* Wire half of the MiniMax Code daily check-in.
|
|
33849
|
+
*
|
|
33850
|
+
* Everything in this file is measured against, or ported from, the official
|
|
33851
|
+
* client's own open source (`MiniMax-AI/minimax-code`, MIT):
|
|
33852
|
+
* `packages/tui/src/checkin/http-gateway.ts` does the two check-in calls and
|
|
33853
|
+
* `packages/tui/src/runtime/public-gateway.ts` builds the request. The wire
|
|
33854
|
+
* shape was additionally verified live against the CN deployment with this
|
|
33855
|
+
* machine's own credential (see the 0.2.0-rc.1-era probe notes in the
|
|
33856
|
+
* changelog): `GET signin/status` and `POST signin/claim` answer exactly the
|
|
33857
|
+
* shapes validated below, and a duplicate claim answers
|
|
33858
|
+
* `claim_result: 2` (AlreadyClaimed) rather than an error.
|
|
33859
|
+
*
|
|
33860
|
+
* The `yy` / `x-timestamp` / `x-signature` headers are the same first-party
|
|
33861
|
+
* attribution literals this package's `types.ts` product-token note discusses.
|
|
33862
|
+
* The official source's own comment calls them wire-protocol constants that
|
|
33863
|
+
* are "not credentials or a security boundary" — authorization is the Bearer
|
|
33864
|
+
* token. Unlike the quota read (where they are optional and stay off by
|
|
33865
|
+
* default), the check-in gateway refuses requests without them, so this
|
|
33866
|
+
* feature cannot exist without sending them; that trade is recorded in the
|
|
33867
|
+
* changelog and was made explicitly, not by default. The User-Agent stays the
|
|
33868
|
+
* plugin's own honest one — it is NOT part of the signed surface.
|
|
33869
|
+
*/
|
|
33870
|
+
/** Activity status surface; answers whether today is claimable or claimed. */
|
|
33871
|
+
const SIGNIN_STATUS_PATH = "/minimax-cloud/api/v1/signin/status";
|
|
33872
|
+
/** Check-in surface; credits are granted by posting here once a day. */
|
|
33873
|
+
const SIGNIN_CLAIM_PATH = "/minimax-cloud/api/v1/signin/claim";
|
|
33874
|
+
/** Account identity surface; resolves the realUserID the query string needs. */
|
|
33875
|
+
const USER_INFO_PATH = "/v1/api/user/info";
|
|
33876
|
+
/**
|
|
33877
|
+
* Salt the first-party clients mix into `x-signature`.
|
|
33878
|
+
*
|
|
33879
|
+
* Inline in the official client's public bundle and in its open-source CLI
|
|
33880
|
+
* (`public-gateway.ts`); the comment there calls it a wire-protocol constant,
|
|
33881
|
+
* since changing it needs a coordinated server-side rollout.
|
|
33882
|
+
*/
|
|
33883
|
+
const SIGNATURE_SALT = "I*7Cf%WZ#S&%1RlZJ&C2";
|
|
33884
|
+
function md5(value) {
|
|
33885
|
+
return createHash("md5").update(value).digest("hex");
|
|
33886
|
+
}
|
|
33887
|
+
/** Origin the official client uses for this surface, per region. */
|
|
33888
|
+
function checkinGatewayOrigin(region) {
|
|
33889
|
+
return region === "cn" ? "https://agent.minimaxi.com" : "https://agent.minimax.io";
|
|
33890
|
+
}
|
|
33891
|
+
const DAY_STATUSES = /* @__PURE__ */ new Set([
|
|
33892
|
+
1,
|
|
33893
|
+
2,
|
|
33894
|
+
3,
|
|
33895
|
+
4
|
|
33896
|
+
]);
|
|
33897
|
+
const CLAIM_RESULTS = /* @__PURE__ */ new Set([1, 2]);
|
|
33898
|
+
const PANEL_SCENES = /* @__PURE__ */ new Set([
|
|
33899
|
+
0,
|
|
33900
|
+
1,
|
|
33901
|
+
2,
|
|
33902
|
+
3,
|
|
33903
|
+
4
|
|
33904
|
+
]);
|
|
33905
|
+
/**
|
|
33906
|
+
* Validate one panel response. Ported from the official
|
|
33907
|
+
* `validateSigninPanel`: exactly seven days, day numbers 1..7 without
|
|
33908
|
+
* repeats, at most one claimable and at most one "today". A panel that fails
|
|
33909
|
+
* this is a wire surprise, and treating it as "nothing to do" would silently
|
|
33910
|
+
* skip the day, so validation throws.
|
|
33911
|
+
*/
|
|
33912
|
+
function validateSigninPanel(value) {
|
|
33913
|
+
const panel = value;
|
|
33914
|
+
const days = panel?.days;
|
|
33915
|
+
const dayNumbers = /* @__PURE__ */ new Set();
|
|
33916
|
+
let claimableDays = 0;
|
|
33917
|
+
let todayDays = 0;
|
|
33918
|
+
const validDays = Array.isArray(days) && days.length === 7 && days.every((day) => {
|
|
33919
|
+
if (day === null || typeof day !== "object") return false;
|
|
33920
|
+
const item = day;
|
|
33921
|
+
const dayNo = item.day_no;
|
|
33922
|
+
if (typeof dayNo !== "number" || !Number.isInteger(dayNo) || dayNo < 1 || dayNo > 7 || dayNumbers.has(dayNo)) return false;
|
|
33923
|
+
if (typeof item.points !== "number" || !Number.isFinite(item.points) || item.points < 0) return false;
|
|
33924
|
+
if (item.bonus_points !== void 0 && (typeof item.bonus_points !== "number" || !Number.isFinite(item.bonus_points) || item.bonus_points < 0)) return false;
|
|
33925
|
+
if (typeof item.is_today !== "boolean" || !DAY_STATUSES.has(item.status)) return false;
|
|
33926
|
+
dayNumbers.add(dayNo);
|
|
33927
|
+
if (item.status === 2) claimableDays += 1;
|
|
33928
|
+
if (item.is_today === true) todayDays += 1;
|
|
33929
|
+
return true;
|
|
33930
|
+
});
|
|
33931
|
+
if (panel === null || typeof panel !== "object" || !PANEL_SCENES.has(panel.scene) || !validDays || claimableDays > 1 || todayDays > 1) throw new Error("Invalid sign-in panel");
|
|
33932
|
+
return panel;
|
|
33933
|
+
}
|
|
33934
|
+
/** Validate one claim response. Ported from the official `validateClaimSigninData`. */
|
|
33935
|
+
function validateClaimSigninData(value) {
|
|
33936
|
+
const data = value;
|
|
33937
|
+
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");
|
|
33938
|
+
return {
|
|
33939
|
+
...data,
|
|
33940
|
+
panel: validateSigninPanel(data.panel)
|
|
33941
|
+
};
|
|
33942
|
+
}
|
|
33943
|
+
/**
|
|
33944
|
+
* The consecutive-claimed count ending today, from one panel.
|
|
33945
|
+
*
|
|
33946
|
+
* Ported from the official `getCurrentSigninStreak`: when today is claimed it
|
|
33947
|
+
* counts; when today is still claimable the streak up to yesterday is what a
|
|
33948
|
+
* claim would extend, so that is what the card shows.
|
|
33949
|
+
*/
|
|
33950
|
+
function currentSigninStreak(days) {
|
|
33951
|
+
const sorted = [...days].sort((left, right) => left.day_no - right.day_no);
|
|
33952
|
+
const todayIndex = sorted.findIndex((day) => day.is_today);
|
|
33953
|
+
if (todayIndex < 0) return 0;
|
|
33954
|
+
const todayStatus = sorted[todayIndex]?.status;
|
|
33955
|
+
let index = todayStatus === 3 ? todayIndex : todayStatus === 2 ? todayIndex - 1 : -1;
|
|
33956
|
+
if (index < 0) return 0;
|
|
33957
|
+
let streak = 0;
|
|
33958
|
+
for (; index >= 0; index -= 1) {
|
|
33959
|
+
if (sorted[index]?.status !== 3) break;
|
|
33960
|
+
streak += 1;
|
|
33961
|
+
}
|
|
33962
|
+
return streak;
|
|
33963
|
+
}
|
|
33964
|
+
function isRecord$1(value) {
|
|
33965
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33966
|
+
}
|
|
33967
|
+
function readString(record, ...keys) {
|
|
33968
|
+
if (record === void 0) return void 0;
|
|
33969
|
+
for (const key of keys) {
|
|
33970
|
+
const value = record[key];
|
|
33971
|
+
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
33972
|
+
}
|
|
33973
|
+
}
|
|
33974
|
+
/**
|
|
33975
|
+
* One signed request, built the way the official CLI builds it
|
|
33976
|
+
* (`createPublicGatewayRequest`).
|
|
33977
|
+
*
|
|
33978
|
+
* The query constants (`device_platform=web`, `is_desktop=1`, `client=mcode`,
|
|
33979
|
+
* `browser_name=mcode`, `device_id=0`) are the gateway's protocol vocabulary
|
|
33980
|
+
* for this surface, copied verbatim; `desktop_version` reports THIS plugin's
|
|
33981
|
+
* version, because it is the version field of the client making the request
|
|
33982
|
+
* and inventing the official app's number would be the one genuinely false
|
|
33983
|
+
* statement available here. `yy` hashes the millisecond clock while
|
|
33984
|
+
* `x-timestamp` / `x-signature` use whole seconds — both spellings are in
|
|
33985
|
+
* the official source and the mismatch is deliberate, not a typo to fix.
|
|
33986
|
+
*/
|
|
33987
|
+
function createCheckinRequest(input) {
|
|
33988
|
+
const url = new URL(input.origin + input.path);
|
|
33989
|
+
url.search = new URLSearchParams({
|
|
33990
|
+
device_platform: "web",
|
|
33991
|
+
biz_id: "3",
|
|
33992
|
+
app_id: "3001",
|
|
33993
|
+
version_code: "22201",
|
|
33994
|
+
is_desktop: "1",
|
|
33995
|
+
desktop_version: input.appVersion,
|
|
33996
|
+
unix: String(input.nowMs),
|
|
33997
|
+
timezone_offset: String((/* @__PURE__ */ new Date()).getTimezoneOffset() * -60),
|
|
33998
|
+
sys_language: input.language,
|
|
33999
|
+
lang: input.language,
|
|
34000
|
+
device_id: "0",
|
|
34001
|
+
os_name: process.platform,
|
|
34002
|
+
browser_name: "mcode",
|
|
34003
|
+
user_id: input.realUserID,
|
|
34004
|
+
client: "mcode"
|
|
34005
|
+
}).toString();
|
|
34006
|
+
const second = Math.floor(input.nowMs / 1e3);
|
|
34007
|
+
const pathWithSearch = `${url.pathname}${url.search}`;
|
|
34008
|
+
const signatureBody = input.body ?? "";
|
|
34009
|
+
const yyBody = input.body ?? "{}";
|
|
34010
|
+
return {
|
|
34011
|
+
url,
|
|
34012
|
+
headers: {
|
|
34013
|
+
accept: "application/json",
|
|
34014
|
+
"content-type": "application/json",
|
|
34015
|
+
"user-agent": USER_AGENT,
|
|
34016
|
+
authorization: `Bearer ${input.accessToken}`,
|
|
34017
|
+
yy: md5(`${encodeURIComponent(pathWithSearch)}_${yyBody}${md5(String(input.nowMs))}ooui`),
|
|
34018
|
+
"x-timestamp": String(second),
|
|
34019
|
+
"x-signature": md5(`${second}${SIGNATURE_SALT}${signatureBody}`)
|
|
34020
|
+
}
|
|
34021
|
+
};
|
|
34022
|
+
}
|
|
34023
|
+
/**
|
|
34024
|
+
* The identity call uses the matrix account surface's own query vocabulary
|
|
34025
|
+
* (`device_platform=mcode`, no `is_desktop`/`desktop_version`) — the two
|
|
34026
|
+
* surfaces spell the same device differently in the official client, and the
|
|
34027
|
+
* difference is load-bearing: mixing them is what an "invalid access token"
|
|
34028
|
+
* answer means when the token itself is fine.
|
|
34029
|
+
*/
|
|
34030
|
+
function createIdentityRequest(input) {
|
|
34031
|
+
const url = new URL(input.origin + USER_INFO_PATH);
|
|
34032
|
+
url.search = new URLSearchParams({
|
|
34033
|
+
device_platform: "mcode",
|
|
34034
|
+
biz_id: "3",
|
|
34035
|
+
app_id: "3001",
|
|
34036
|
+
version_code: "22201",
|
|
34037
|
+
unix: String(input.nowMs),
|
|
34038
|
+
timezone_offset: String((/* @__PURE__ */ new Date()).getTimezoneOffset() * -60),
|
|
34039
|
+
sys_language: input.language,
|
|
34040
|
+
lang: input.language,
|
|
34041
|
+
device_id: "0",
|
|
34042
|
+
os_name: process.platform,
|
|
34043
|
+
browser_name: "mcode",
|
|
34044
|
+
user_id: "0",
|
|
34045
|
+
client: "mcode"
|
|
34046
|
+
}).toString();
|
|
34047
|
+
const second = Math.floor(input.nowMs / 1e3);
|
|
34048
|
+
const pathWithSearch = `${url.pathname}${url.search}`;
|
|
34049
|
+
return {
|
|
34050
|
+
url,
|
|
34051
|
+
headers: {
|
|
34052
|
+
accept: "application/json",
|
|
34053
|
+
"content-type": "application/json",
|
|
34054
|
+
"user-agent": USER_AGENT,
|
|
34055
|
+
authorization: `Bearer ${input.accessToken}`,
|
|
34056
|
+
yy: md5(`${encodeURIComponent(pathWithSearch)}_{}${md5(String(input.nowMs))}ooui`),
|
|
34057
|
+
"x-timestamp": String(second),
|
|
34058
|
+
"x-signature": md5(`${second}${SIGNATURE_SALT}`)
|
|
34059
|
+
}
|
|
34060
|
+
};
|
|
34061
|
+
}
|
|
34062
|
+
var MinimaxCodeCheckinHttpError = class extends Error {
|
|
34063
|
+
status;
|
|
34064
|
+
constructor(message, status) {
|
|
34065
|
+
super(message);
|
|
34066
|
+
this.status = status;
|
|
34067
|
+
this.name = "MinimaxCodeCheckinHttpError";
|
|
34068
|
+
}
|
|
34069
|
+
};
|
|
34070
|
+
function languageFor(region) {
|
|
34071
|
+
return region === "cn" ? "zh" : "en";
|
|
34072
|
+
}
|
|
34073
|
+
/**
|
|
34074
|
+
* Resolve the account's realUserID (and display fields) through the identity
|
|
34075
|
+
* surface. The check-in query string needs realUserID and the OAuth document
|
|
34076
|
+
* does not carry it, so it is resolved once per scheduler pass and cached in
|
|
34077
|
+
* the check-in state afterwards.
|
|
34078
|
+
*/
|
|
34079
|
+
async function fetchAccountIdentity(accessToken, region, options = {}) {
|
|
34080
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
34081
|
+
const nowMs = (options.nowMs ?? Date.now)();
|
|
34082
|
+
const request = createIdentityRequest({
|
|
34083
|
+
origin: checkinGatewayOrigin(region),
|
|
34084
|
+
accessToken,
|
|
34085
|
+
language: languageFor(region),
|
|
34086
|
+
nowMs
|
|
34087
|
+
});
|
|
34088
|
+
const response = await fetchFn(request.url, {
|
|
34089
|
+
method: "GET",
|
|
34090
|
+
headers: request.headers,
|
|
34091
|
+
signal: options.signal ?? AbortSignal.timeout(3e4)
|
|
34092
|
+
});
|
|
34093
|
+
if (response.status === 401 || response.status === 403) throw new MinimaxCodeCheckinHttpError(`identity request rejected with HTTP ${response.status}`, response.status);
|
|
34094
|
+
const parsed = await response.json().catch(() => null);
|
|
34095
|
+
if (!response.ok || !isRecord$1(parsed)) throw new MinimaxCodeCheckinHttpError(`identity request failed with HTTP ${response.status}`, response.status);
|
|
34096
|
+
const data = isRecord$1(parsed.data) ? parsed.data : void 0;
|
|
34097
|
+
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);
|
|
34098
|
+
const realUserID = readString(userInfo, "realUserID", "real_user_id");
|
|
34099
|
+
if (realUserID === void 0) throw new MinimaxCodeCheckinHttpError("identity response carried no realUserID", response.status);
|
|
34100
|
+
return {
|
|
34101
|
+
realUserID,
|
|
34102
|
+
...readString(userInfo, "userName", "name", "user_name") !== void 0 ? { userName: readString(userInfo, "userName", "name", "user_name") } : {},
|
|
34103
|
+
...readString(userInfo, "subUserName", "sub_user_name") !== void 0 ? { subUserName: readString(userInfo, "subUserName", "sub_user_name") } : {},
|
|
34104
|
+
...readString(userInfo, "userEmail", "email", "userMail", "user_email") !== void 0 ? { userEmail: readString(userInfo, "userEmail", "email", "userMail", "user_email") } : {}
|
|
34105
|
+
};
|
|
34106
|
+
}
|
|
34107
|
+
/** One status or claim call against the check-in surface. */
|
|
34108
|
+
async function checkinCall(path, method, accessToken, realUserID, region, options) {
|
|
34109
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
34110
|
+
const nowMs = (options.nowMs ?? Date.now)();
|
|
34111
|
+
const body = method === "POST" ? "{}" : void 0;
|
|
34112
|
+
const request = createCheckinRequest({
|
|
34113
|
+
origin: checkinGatewayOrigin(region),
|
|
34114
|
+
path,
|
|
34115
|
+
accessToken,
|
|
34116
|
+
realUserID,
|
|
34117
|
+
appVersion: options.appVersion ?? "0.0.0",
|
|
34118
|
+
language: languageFor(region),
|
|
34119
|
+
nowMs,
|
|
34120
|
+
...body === void 0 ? {} : { body }
|
|
34121
|
+
});
|
|
34122
|
+
const response = await fetchFn(request.url, {
|
|
34123
|
+
method,
|
|
34124
|
+
headers: request.headers,
|
|
34125
|
+
...body === void 0 ? {} : { body },
|
|
34126
|
+
signal: options.signal ?? AbortSignal.timeout(3e4)
|
|
34127
|
+
});
|
|
34128
|
+
const text = await response.text().catch(() => "");
|
|
34129
|
+
let parsed = null;
|
|
34130
|
+
try {
|
|
34131
|
+
const value = JSON.parse(text);
|
|
34132
|
+
parsed = isRecord$1(value) ? value : null;
|
|
34133
|
+
} catch {
|
|
34134
|
+
parsed = null;
|
|
34135
|
+
}
|
|
34136
|
+
if (!response.ok) throw new MinimaxCodeCheckinHttpError(`daily check-in request failed with HTTP ${response.status}${parsed === null ? "" : `: ${text.slice(0, 200)}`}`, response.status);
|
|
34137
|
+
const baseResp = isRecord$1(parsed?.base_resp) ? parsed.base_resp : void 0;
|
|
34138
|
+
const statusCode = typeof baseResp?.status_code === "number" ? baseResp.status_code : void 0;
|
|
34139
|
+
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);
|
|
34140
|
+
if (parsed === null || parsed.data === null || parsed.data === void 0) throw new MinimaxCodeCheckinHttpError("daily check-in response data is missing", response.status);
|
|
34141
|
+
return parsed.data;
|
|
34142
|
+
}
|
|
34143
|
+
/** Read the seven-day panel; throws on transport, HTTP, or shape failures. */
|
|
34144
|
+
async function fetchSigninPanel(accessToken, realUserID, region, options = {}) {
|
|
34145
|
+
return validateSigninPanel(await checkinCall(SIGNIN_STATUS_PATH, "GET", accessToken, realUserID, region, options));
|
|
34146
|
+
}
|
|
34147
|
+
/** Claim today's credit; the response carries the fresh panel. */
|
|
34148
|
+
async function claimSignin(accessToken, realUserID, region, options = {}) {
|
|
34149
|
+
return validateClaimSigninData(await checkinCall(SIGNIN_CLAIM_PATH, "POST", accessToken, realUserID, region, options));
|
|
34150
|
+
}
|
|
34151
|
+
//#endregion
|
|
34152
|
+
//#region src/host/minimax-code/checkin.ts
|
|
34153
|
+
/**
|
|
34154
|
+
* Daily check-in scheduler for the MiniMax Code line.
|
|
34155
|
+
*
|
|
34156
|
+
* Modeled on the sibling WorkBuddy scheduler and kept semantically identical
|
|
34157
|
+
* where the two services face the same problem; the wire half lives in
|
|
34158
|
+
* ./checkin-gateway.ts (official-client recipe, verified live).
|
|
34159
|
+
*
|
|
34160
|
+
* - **Both regions.** The official client's public gateway has an origin per
|
|
34161
|
+
* region, so an account signs in against its own region's origin. There is
|
|
34162
|
+
* no CN-only carve-out like WorkBuddy's: the CLI ships the same surface
|
|
34163
|
+
* worldwide.
|
|
34164
|
+
* - **Idempotent.** The panel is read first; an account whose today is already
|
|
34165
|
+
* claimed (by anyone) is only recorded. A duplicate claim answers
|
|
34166
|
+
* `claim_result: 2` (AlreadyClaimed), which is a success, never a retry.
|
|
34167
|
+
* - **Patient with the day.** A today that is neither claimable nor claimed
|
|
34168
|
+
* (upcoming/disabled) is parked and re-checked on an hourly cadence rather
|
|
34169
|
+
* than abandoned: the activity flips on its own schedule, and the host
|
|
34170
|
+
* usually boots before it does.
|
|
34171
|
+
* - **Bounded.** A failing account is retried at most {@link CHECKIN_ATTEMPT_CAP}
|
|
34172
|
+
* times a day, so a broken account cannot turn the ten-minute tick into a
|
|
34173
|
+
* request loop. A manual run ignores the cap and the toggle, like the
|
|
34174
|
+
* workbuddy card's "check in now", and is queued behind an in-flight run.
|
|
34175
|
+
*
|
|
34176
|
+
* Credentials stay host-side: the only write beyond the state file is the
|
|
34177
|
+
* account pool's own refresh write-back, reused here unchanged through
|
|
34178
|
+
* `getFreshCredential` / `renewCredential`.
|
|
34179
|
+
*/
|
|
34180
|
+
/**
|
|
34181
|
+
* Scheduler cadence. The first tick at host startup is the daily run; the
|
|
34182
|
+
* interval keeps a long-lived process signing in on later days without a
|
|
34183
|
+
* restart. Idle ticks cost no requests — the day state short-circuits them.
|
|
34184
|
+
*/
|
|
34185
|
+
const CHECKIN_TICK_MS = 600 * 1e3;
|
|
34186
|
+
/** State document the scheduler keeps beside the other plugin stores. */
|
|
34187
|
+
function checkinStatePath() {
|
|
34188
|
+
return path.join(dshHomeDir(), "storages", "minimax-code-checkin.json");
|
|
34189
|
+
}
|
|
34190
|
+
/** Local calendar day an instant belongs to; state entries are keyed by it. */
|
|
34191
|
+
function localDateString(nowMs) {
|
|
34192
|
+
const date = new Date(nowMs);
|
|
34193
|
+
const month = `${date.getMonth() + 1}`.padStart(2, "0");
|
|
34194
|
+
const day = `${date.getDate()}`.padStart(2, "0");
|
|
34195
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
34196
|
+
}
|
|
34197
|
+
function isRecord(value) {
|
|
34198
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34199
|
+
}
|
|
34200
|
+
function asCount(value) {
|
|
34201
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
34202
|
+
}
|
|
34203
|
+
function isRegion(value) {
|
|
34204
|
+
return value === "cn" || value === "global";
|
|
34205
|
+
}
|
|
34206
|
+
function parseStateEntry(value) {
|
|
34207
|
+
if (!isRecord(value) || typeof value.date !== "string") return null;
|
|
34208
|
+
const entry = {
|
|
34209
|
+
date: value.date,
|
|
34210
|
+
done: value.done === true,
|
|
34211
|
+
attempts: typeof value.attempts === "number" && Number.isFinite(value.attempts) ? value.attempts : 0
|
|
34212
|
+
};
|
|
34213
|
+
if (value.inactive === true) entry.inactive = true;
|
|
34214
|
+
const inactiveAt = asCount(value.inactiveAt);
|
|
34215
|
+
if (inactiveAt !== void 0) entry.inactiveAt = inactiveAt;
|
|
34216
|
+
if (typeof value.lastError === "string") entry.lastError = value.lastError;
|
|
34217
|
+
const streakDays = asCount(value.streakDays);
|
|
34218
|
+
if (streakDays !== void 0) entry.streakDays = streakDays;
|
|
34219
|
+
const claimedPoints = asCount(value.claimedPoints);
|
|
34220
|
+
if (claimedPoints !== void 0) entry.claimedPoints = claimedPoints;
|
|
34221
|
+
return entry;
|
|
34222
|
+
}
|
|
34223
|
+
/**
|
|
34224
|
+
* The check-in scheduler. One instance per plugin load; the host owns the
|
|
34225
|
+
* interval and clears it from the same `ctx.effect` that created it.
|
|
34226
|
+
*/
|
|
34227
|
+
var MinimaxCodeCheckinService = class {
|
|
34228
|
+
pool;
|
|
34229
|
+
options;
|
|
34230
|
+
fetchFn;
|
|
34231
|
+
statePath;
|
|
34232
|
+
now;
|
|
34233
|
+
logger;
|
|
34234
|
+
appVersion;
|
|
34235
|
+
state = {};
|
|
34236
|
+
identities = {};
|
|
34237
|
+
loaded = false;
|
|
34238
|
+
/** Passes waiting to run, in order; `true` marks a manual pass. */
|
|
34239
|
+
queue = [];
|
|
34240
|
+
/** The drain loop currently working the queue, if any. */
|
|
34241
|
+
draining = null;
|
|
34242
|
+
lastRunAt = null;
|
|
34243
|
+
/** Memoized preference warmup, so it is awaited once however many passes run. */
|
|
34244
|
+
readyWait = null;
|
|
34245
|
+
constructor(pool, options) {
|
|
34246
|
+
this.pool = pool;
|
|
34247
|
+
this.options = options;
|
|
34248
|
+
this.fetchFn = options.fetchFn ?? fetch;
|
|
34249
|
+
this.statePath = options.statePath ?? checkinStatePath();
|
|
34250
|
+
this.now = options.now ?? (() => Date.now());
|
|
34251
|
+
this.logger = options.logger;
|
|
34252
|
+
this.appVersion = options.appVersion;
|
|
34253
|
+
}
|
|
34254
|
+
/**
|
|
34255
|
+
* One scheduler pass. Automatic passes honour the toggle and the retry cap;
|
|
34256
|
+
* a manual pass (`manual: true`, the card's "check in now") ignores both
|
|
34257
|
+
* but still respects an account already signed in today.
|
|
34258
|
+
*
|
|
34259
|
+
* A manual pass that lands while a run is already in flight is *queued*, not
|
|
34260
|
+
* absorbed: joining the running pass would silently discard the one thing the
|
|
34261
|
+
* button promises, that the retry cap and the toggle are bypassed now.
|
|
34262
|
+
*/
|
|
34263
|
+
async tick(manual = false) {
|
|
34264
|
+
if (!manual && (this.queue.length > 0 || this.draining !== null)) return this.draining ?? Promise.resolve();
|
|
34265
|
+
this.queue.push(manual);
|
|
34266
|
+
return this.drain();
|
|
34267
|
+
}
|
|
34268
|
+
drain() {
|
|
34269
|
+
if (this.draining !== null) return this.draining;
|
|
34270
|
+
if (this.queue.length === 0) return Promise.resolve();
|
|
34271
|
+
const loop = this.runQueue();
|
|
34272
|
+
this.draining = loop;
|
|
34273
|
+
return loop;
|
|
34274
|
+
}
|
|
34275
|
+
async runQueue() {
|
|
34276
|
+
for (;;) {
|
|
34277
|
+
const manual = this.queue.shift();
|
|
34278
|
+
if (manual === void 0) {
|
|
34279
|
+
this.draining = null;
|
|
34280
|
+
return;
|
|
34281
|
+
}
|
|
34282
|
+
try {
|
|
34283
|
+
await this.run(manual);
|
|
34284
|
+
} catch (error) {
|
|
34285
|
+
this.logger?.warn(`[minimax-code-checkin] pass failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
34286
|
+
}
|
|
34287
|
+
}
|
|
34288
|
+
}
|
|
34289
|
+
async run(manual) {
|
|
34290
|
+
await this.ready();
|
|
34291
|
+
const settings = this.options.settings();
|
|
34292
|
+
if (!manual && !settings.enabled) return;
|
|
34293
|
+
await this.load();
|
|
34294
|
+
const nowMs = this.now();
|
|
34295
|
+
const today = localDateString(nowMs);
|
|
34296
|
+
let accounts;
|
|
34297
|
+
try {
|
|
34298
|
+
accounts = await this.pool.listAccounts();
|
|
34299
|
+
} catch (error) {
|
|
34300
|
+
this.logger?.warn(`[minimax-code-checkin] account scan failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
34301
|
+
return;
|
|
34302
|
+
}
|
|
34303
|
+
for (const account of accounts) {
|
|
34304
|
+
const existing = this.state[account.id];
|
|
34305
|
+
const sameDay = existing?.date === today;
|
|
34306
|
+
if (sameDay && existing.done) continue;
|
|
34307
|
+
if (!manual && sameDay && existing.attempts >= 3) continue;
|
|
34308
|
+
if (!manual && sameDay && existing.inactive === true && nowMs - (existing.inactiveAt ?? 0) < 36e5) continue;
|
|
34309
|
+
await this.checkinOne(account, today, nowMs);
|
|
34310
|
+
}
|
|
34311
|
+
this.lastRunAt = nowMs;
|
|
34312
|
+
await this.save();
|
|
34313
|
+
}
|
|
34314
|
+
/** Wait for the preference store's warmup read, once. */
|
|
34315
|
+
async ready() {
|
|
34316
|
+
if (this.readyWait === null) this.readyWait = Promise.resolve(this.options.ready?.()).catch(() => void 0);
|
|
34317
|
+
await this.readyWait;
|
|
34318
|
+
}
|
|
34319
|
+
/**
|
|
34320
|
+
* Resolve the account's realUserID, cached across days.
|
|
34321
|
+
*
|
|
34322
|
+
* The OAuth document does not carry it and the check-in query string needs
|
|
34323
|
+
* it, so it is fetched from the identity surface once and kept in the state
|
|
34324
|
+
* document. The region is cached alongside because the identity call's
|
|
34325
|
+
* origin depends on it.
|
|
34326
|
+
*/
|
|
34327
|
+
async identityFor(account, accessToken, region) {
|
|
34328
|
+
const cached = this.identities[account.id];
|
|
34329
|
+
if (cached !== void 0 && cached.region === region) return cached;
|
|
34330
|
+
const next = {
|
|
34331
|
+
realUserID: (await fetchAccountIdentity(accessToken, region, {
|
|
34332
|
+
fetchFn: this.fetchFn,
|
|
34333
|
+
...this.appVersion === void 0 ? {} : { appVersion: this.appVersion }
|
|
34334
|
+
})).realUserID,
|
|
34335
|
+
region
|
|
34336
|
+
};
|
|
34337
|
+
this.identities[account.id] = next;
|
|
34338
|
+
return next;
|
|
34339
|
+
}
|
|
34340
|
+
/** Check one account in, recording the outcome in its today's entry. */
|
|
34341
|
+
async checkinOne(account, today, nowMs) {
|
|
34342
|
+
const existing = this.state[account.id];
|
|
34343
|
+
const entry = existing?.date === today ? existing : {
|
|
34344
|
+
date: today,
|
|
34345
|
+
done: false,
|
|
34346
|
+
attempts: 0
|
|
34347
|
+
};
|
|
34348
|
+
this.state[account.id] = entry;
|
|
34349
|
+
const region = isRegion(account.region) ? account.region : "cn";
|
|
34350
|
+
try {
|
|
34351
|
+
const credentials = await this.pool.getFreshCredential(account.id, this.fetchFn);
|
|
34352
|
+
try {
|
|
34353
|
+
await this.attemptOnce(account, entry, credentials, region, nowMs);
|
|
34354
|
+
} catch (error) {
|
|
34355
|
+
if (!(error instanceof MinimaxCodeCheckinHttpError) || error.status !== 401 && error.status !== 403) throw error;
|
|
34356
|
+
delete this.identities[account.id];
|
|
34357
|
+
const renewed = await this.pool.renewCredential(account.id, this.fetchFn);
|
|
34358
|
+
await this.attemptOnce(account, entry, renewed, region, nowMs);
|
|
34359
|
+
}
|
|
34360
|
+
} catch (error) {
|
|
34361
|
+
entry.attempts += 1;
|
|
34362
|
+
entry.lastError = error instanceof Error ? error.message : String(error);
|
|
34363
|
+
this.logger?.warn(`[minimax-code-checkin] ${account.id} attempt ${entry.attempts}/3 failed: ${entry.lastError}`);
|
|
34364
|
+
}
|
|
34365
|
+
}
|
|
34366
|
+
/**
|
|
34367
|
+
* One full try for one account: identity, panel, and — when today is
|
|
34368
|
+
* claimable — the claim. Settles the entry on every outcome; throws for the
|
|
34369
|
+
* caller's renew-and-retry or attempt bookkeeping.
|
|
34370
|
+
*/
|
|
34371
|
+
async attemptOnce(account, entry, credentials, region, nowMs) {
|
|
34372
|
+
const identity = await this.identityFor(account, credentials.accessToken, region);
|
|
34373
|
+
const panel = await this.panel(credentials, identity, region);
|
|
34374
|
+
if (this.recordPanelOutcome(entry, panel, account.id, nowMs)) return;
|
|
34375
|
+
const claim = await this.claim(credentials, identity, region);
|
|
34376
|
+
this.markSignedIn(entry, claim.panel);
|
|
34377
|
+
if (claim.claim_result === 1) entry.claimedPoints = claim.points;
|
|
34378
|
+
this.logger?.info(`[minimax-code-checkin] ${account.id} signed in; +${claim.points} credits${claim.claim_result === 2 ? " (already claimed upstream)" : ""}`);
|
|
34379
|
+
}
|
|
34380
|
+
/** The status call, against the current credential. */
|
|
34381
|
+
async panel(credentials, identity, region) {
|
|
34382
|
+
return fetchSigninPanel(credentials.accessToken, identity.realUserID, region, {
|
|
34383
|
+
fetchFn: this.fetchFn,
|
|
34384
|
+
...this.appVersion === void 0 ? {} : { appVersion: this.appVersion }
|
|
34385
|
+
});
|
|
34386
|
+
}
|
|
34387
|
+
/** The claim call, against the current credential. */
|
|
34388
|
+
async claim(credentials, identity, region) {
|
|
34389
|
+
return claimSignin(credentials.accessToken, identity.realUserID, region, {
|
|
34390
|
+
fetchFn: this.fetchFn,
|
|
34391
|
+
...this.appVersion === void 0 ? {} : { appVersion: this.appVersion }
|
|
34392
|
+
});
|
|
34393
|
+
}
|
|
34394
|
+
/**
|
|
34395
|
+
* Fold one panel into the day's entry.
|
|
34396
|
+
*
|
|
34397
|
+
* Returns true when the entry is settled for the day (claimed already, or
|
|
34398
|
+
* parked inactive): the caller then skips the claim. Today claimable is the
|
|
34399
|
+
* one answer that returns false.
|
|
34400
|
+
*/
|
|
34401
|
+
recordPanelOutcome(entry, panel, accountId, nowMs) {
|
|
34402
|
+
const today = panel.days.find((day) => day.is_today);
|
|
34403
|
+
if (today?.status === 3) {
|
|
34404
|
+
this.markSignedIn(entry, panel);
|
|
34405
|
+
this.logger?.info(`[minimax-code-checkin] ${accountId} already signed in today`);
|
|
34406
|
+
return true;
|
|
34407
|
+
}
|
|
34408
|
+
if (today?.status !== 2) {
|
|
34409
|
+
entry.inactive = true;
|
|
34410
|
+
entry.inactiveAt = nowMs;
|
|
34411
|
+
delete entry.lastError;
|
|
34412
|
+
this.logger?.info(`[minimax-code-checkin] ${accountId} has no claimable day today; will re-check later`);
|
|
34413
|
+
return true;
|
|
34414
|
+
}
|
|
34415
|
+
entry.inactive = false;
|
|
34416
|
+
delete entry.inactiveAt;
|
|
34417
|
+
return false;
|
|
34418
|
+
}
|
|
34419
|
+
/** Record a confirmed sign-in, clearing the transient failure bookkeeping. */
|
|
34420
|
+
markSignedIn(entry, panel) {
|
|
34421
|
+
entry.done = true;
|
|
34422
|
+
entry.inactive = false;
|
|
34423
|
+
delete entry.inactiveAt;
|
|
34424
|
+
delete entry.lastError;
|
|
34425
|
+
entry.streakDays = currentSigninStreak(panel.days);
|
|
34426
|
+
}
|
|
34427
|
+
/**
|
|
34428
|
+
* The aggregate the settings card renders. Reads only local state and the
|
|
34429
|
+
* account list; it never spends a network request.
|
|
34430
|
+
*/
|
|
34431
|
+
async summary() {
|
|
34432
|
+
await this.ready();
|
|
34433
|
+
await this.load();
|
|
34434
|
+
const settings = this.options.settings();
|
|
34435
|
+
const accounts = await this.pool.listAccounts().catch(() => []);
|
|
34436
|
+
const today = localDateString(this.now());
|
|
34437
|
+
let doneToday = 0;
|
|
34438
|
+
let skippedToday = 0;
|
|
34439
|
+
let failedToday = 0;
|
|
34440
|
+
let streakDays;
|
|
34441
|
+
let claimedPoints;
|
|
34442
|
+
for (const account of accounts) {
|
|
34443
|
+
const entry = this.state[account.id];
|
|
34444
|
+
if (entry?.date !== today) continue;
|
|
34445
|
+
if (entry.done) {
|
|
34446
|
+
doneToday += 1;
|
|
34447
|
+
if (entry.streakDays !== void 0) streakDays = Math.max(streakDays ?? 0, entry.streakDays);
|
|
34448
|
+
if (entry.claimedPoints !== void 0) claimedPoints = (claimedPoints ?? 0) + entry.claimedPoints;
|
|
34449
|
+
} else if (entry.inactive === true) skippedToday += 1;
|
|
34450
|
+
else if (entry.attempts >= 3) failedToday += 1;
|
|
34451
|
+
}
|
|
34452
|
+
return {
|
|
34453
|
+
enabled: settings.enabled,
|
|
34454
|
+
totalAccounts: accounts.length,
|
|
34455
|
+
doneToday,
|
|
34456
|
+
skippedToday,
|
|
34457
|
+
failedToday,
|
|
34458
|
+
lastRunAt: this.lastRunAt,
|
|
34459
|
+
...streakDays === void 0 ? {} : { streakDays },
|
|
34460
|
+
...claimedPoints === void 0 ? {} : { claimedPoints }
|
|
34461
|
+
};
|
|
34462
|
+
}
|
|
34463
|
+
async load() {
|
|
34464
|
+
if (this.loaded) return;
|
|
34465
|
+
this.loaded = true;
|
|
34466
|
+
try {
|
|
34467
|
+
const parsed = JSON.parse(await fsPromises.readFile(this.statePath, "utf8"));
|
|
34468
|
+
if (isRecord(parsed)) {
|
|
34469
|
+
const lastRunAt = asCount(parsed.lastRunAt);
|
|
34470
|
+
if (lastRunAt !== void 0) this.lastRunAt = lastRunAt;
|
|
34471
|
+
if (isRecord(parsed.accounts)) for (const [id, value] of Object.entries(parsed.accounts)) {
|
|
34472
|
+
const entry = parseStateEntry(value);
|
|
34473
|
+
if (entry !== null) this.state[id] = entry;
|
|
34474
|
+
}
|
|
34475
|
+
if (isRecord(parsed.identities)) {
|
|
34476
|
+
for (const [id, value] of Object.entries(parsed.identities)) if (isRecord(value) && typeof value.realUserID === "string" && isRegion(value.region)) this.identities[id] = {
|
|
34477
|
+
realUserID: value.realUserID,
|
|
34478
|
+
region: value.region
|
|
34479
|
+
};
|
|
34480
|
+
}
|
|
34481
|
+
}
|
|
34482
|
+
} catch {}
|
|
34483
|
+
}
|
|
34484
|
+
async save() {
|
|
34485
|
+
try {
|
|
34486
|
+
await fsPromises.mkdir(path.dirname(this.statePath), { recursive: true });
|
|
34487
|
+
const tmp = `${this.statePath}.tmp.${process.pid}`;
|
|
34488
|
+
const document = {
|
|
34489
|
+
version: 1,
|
|
34490
|
+
lastRunAt: this.lastRunAt,
|
|
34491
|
+
accounts: this.state,
|
|
34492
|
+
identities: this.identities
|
|
34493
|
+
};
|
|
34494
|
+
await fsPromises.writeFile(tmp, JSON.stringify(document, null, 2), "utf8");
|
|
34495
|
+
await fsPromises.rename(tmp, this.statePath);
|
|
34496
|
+
} catch {}
|
|
34497
|
+
}
|
|
34498
|
+
};
|
|
34499
|
+
//#endregion
|
|
33695
34500
|
//#region src/host/subagent-model-authorization.ts
|
|
33696
34501
|
/** DSH settings namespace owned by the Subagent settings card. */
|
|
33697
34502
|
const SUBAGENT_MODEL_SELECTION_NAMESPACE = "subagent-model-selection";
|
|
@@ -35700,11 +36505,33 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
35700
36505
|
const minimaxCodeRouteWatch = typeof ctx.on === "function" ? ctx.on("llm/adapters-updated", () => {
|
|
35701
36506
|
claimMinimaxCodeRoute();
|
|
35702
36507
|
}) : void 0;
|
|
36508
|
+
let minimaxCodeAppVersion;
|
|
36509
|
+
try {
|
|
36510
|
+
const manifest = createRequire(import.meta.url)("../package.json");
|
|
36511
|
+
if (typeof manifest.version === "string") minimaxCodeAppVersion = manifest.version;
|
|
36512
|
+
} catch {
|
|
36513
|
+
minimaxCodeAppVersion = void 0;
|
|
36514
|
+
}
|
|
36515
|
+
const minimaxCodeCheckin = new MinimaxCodeCheckinService(minimaxCodeAccountPool, {
|
|
36516
|
+
fetchFn: proxyFetch,
|
|
36517
|
+
settings: () => minimaxCodePreferences.status().checkin ?? { enabled: true },
|
|
36518
|
+
ready: () => minimaxCodePreferences.ready(),
|
|
36519
|
+
...minimaxCodeAppVersion === void 0 ? {} : { appVersion: minimaxCodeAppVersion },
|
|
36520
|
+
logger: ctx.logger
|
|
36521
|
+
});
|
|
36522
|
+
const minimaxCodeCheckinTick = () => {
|
|
36523
|
+
minimaxCodeCheckin.tick().catch((error) => {
|
|
36524
|
+
ctx.logger.warn(`[dsh-chatgpt-subscription] MiniMax Code check-in tick failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
36525
|
+
});
|
|
36526
|
+
};
|
|
36527
|
+
const minimaxCodeCheckinTimer = setInterval(minimaxCodeCheckinTick, CHECKIN_TICK_MS);
|
|
36528
|
+
minimaxCodeCheckinTick();
|
|
35703
36529
|
const disposeMinimaxCodeRoutes = registerMinimaxCodeRoutes(ctx, minimaxCodeStore, {
|
|
35704
36530
|
fetchFn: proxyFetch,
|
|
35705
36531
|
serving: () => minimaxCodeRegistration !== void 0,
|
|
35706
36532
|
conflict: () => minimaxCodeConflict,
|
|
35707
|
-
accountPool: minimaxCodeAccountPool
|
|
36533
|
+
accountPool: minimaxCodeAccountPool,
|
|
36534
|
+
checkin: minimaxCodeCheckin
|
|
35708
36535
|
}, minimaxCodeModelSettings, minimaxCodePreferences);
|
|
35709
36536
|
const workBuddyAdapter = new WorkBuddyAdapter(workBuddyStore, workBuddyModelSettings, workBuddyPreferences, {
|
|
35710
36537
|
fetchFn: proxyFetch,
|
|
@@ -35739,7 +36566,7 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
35739
36566
|
ctx.logger.warn(`[dsh-chatgpt-subscription] WorkBuddy check-in tick failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
35740
36567
|
});
|
|
35741
36568
|
};
|
|
35742
|
-
const checkinTimer = setInterval(checkinTick, CHECKIN_TICK_MS);
|
|
36569
|
+
const checkinTimer = setInterval(checkinTick, CHECKIN_TICK_MS$1);
|
|
35743
36570
|
checkinTick();
|
|
35744
36571
|
const disposeWorkBuddyRoutes = registerWorkBuddyRoutes(ctx, workBuddyStore, workBuddyModelSettings, workBuddyPreferences, {
|
|
35745
36572
|
fetchFn: proxyFetch,
|
|
@@ -35862,6 +36689,7 @@ function apply(ctx, pluginConfig = {}) {
|
|
|
35862
36689
|
releaseHandle(minimaxCodeRouteWatch);
|
|
35863
36690
|
minimaxCodeRegistration?.();
|
|
35864
36691
|
minimaxCodeRegistration = void 0;
|
|
36692
|
+
clearInterval(minimaxCodeCheckinTimer);
|
|
35865
36693
|
clearInterval(checkinTimer);
|
|
35866
36694
|
disposeWorkBuddyRoutes();
|
|
35867
36695
|
releaseHandle(workBuddyRouteWatch);
|
|
@@ -35888,4 +36716,4 @@ function localWebServerBaseUrl(host, port) {
|
|
|
35888
36716
|
return `http://${host === "0.0.0.0" ? "127.0.0.1" : host}:${port}`;
|
|
35889
36717
|
}
|
|
35890
36718
|
//#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 };
|
|
36719
|
+
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 };
|