@@ -34616,6 +34616,7 @@ ${captureLines}` : capture.stack;
3461634616var index_exports = {};
3461734617__export(index_exports, {
3461834618 applyAndroidIdentityDefaults: () => applyAndroidIdentityDefaults,
34619+ ensureDeviceMidInConfig: () => ensureDeviceMidInConfig,
3461934620 main: () => main,
3462034621 parseServeArgs: () => parseServeArgs
3462134622});
@@ -34705,7 +34706,8 @@ function loadConfig(path) {
3470534706 sourceTitleEnv: process.env[ENV.SOURCE_TITLE],
3470634707 sourceTitleYaml: parsed?.identity?.sourceTitle,
3470734708 refererEnv: process.env[ENV.REFERER_ORIGIN],
34708- refererYaml: parsed?.identity?.refererOrigin
34709+ refererYaml: parsed?.identity?.refererOrigin,
34710+ deviceMidYaml: parsed?.identity?.deviceMid
3470934711 });
3471034712 const clientIdentity = resolveClientIdentity(parsed?.clientIdentity);
3471134713 const responses = resolveResponsesConfig(parsed?.responses);
@@ -34859,7 +34861,8 @@ function resolveIdentity(inp) {
3485934861 const appVersion = ASCII_PRINTABLE.test(rawVersion) ? rawVersion : DEFAULTS.APP_VERSION;
3486034862 const sourceTitle = (inp.sourceTitleEnv ?? inp.sourceTitleYaml ?? DEFAULTS.SOURCE_TITLE).trim() || DEFAULTS.SOURCE_TITLE;
3486134863 const refererOrigin = (inp.refererEnv ?? inp.refererYaml ?? DEFAULTS.REFERER_ORIGIN).trim() || DEFAULTS.REFERER_ORIGIN;
34862- return { appVersion, sourceTitle, refererOrigin };
34864+ const deviceMid = typeof inp.deviceMidYaml === "string" ? inp.deviceMidYaml.trim() : "";
34865+ return { appVersion, sourceTitle, refererOrigin, ...deviceMid ? { deviceMid } : {} };
3486334866}
3486434867function validate(config) {
3486534868 if (config.server.port < 1 || config.server.port > 65535) {
@@ -34946,6 +34949,11 @@ identity:
3494634949 sourceTitle: "cli"
3494734950 # HTTP-Referer URL. Default "https://zcode.z.ai".
3494834951 refererOrigin: "https://zcode.z.ai"
34952+ # Device identity (X-Device-Mid) \u2014 random UUIDv4, generated ONCE and reused
34953+ # forever (mirrors ZCode's telemetry deviceMid; no hardware values involved).
34954+ # Auto-generated into this file at first \`auth login\` or config creation.
34955+ # Leave empty on Android \u2014 the app injects ZCODE_IDENTITY_DEVICE_MID instead.
34956+ deviceMid: ""
3494934957
3495034958# Local client-session inference for cache-affinity experiments.
3495134959# "observe" (default) logs inferred sessions in debug mode but does not change
@@ -36525,7 +36533,7 @@ function buildIdentityHeaders(id) {
3652536533 const releaseChannel = normalizePrintableHeaderValue(process.env.ZCODE_IDENTITY_RELEASE_CHANNEL);
3652636534 const clientLanguage = resolveClientLanguage();
3652736535 const clientTimezone = resolveClientTimezone();
36528- const deviceMid = normalizePrintableHeaderValue(process.env.ZCODE_IDENTITY_DEVICE_MID);
36536+ const deviceMid = normalizePrintableHeaderValue(process.env.ZCODE_IDENTITY_DEVICE_MID) ?? normalizePrintableHeaderValue(id.deviceMid) ;
3652936537 const headers = {
3653036538 "HTTP-Referer": id.refererOrigin,
3653136539 "User-Agent": `ZCode/${n ?? "unknown"}`,
@@ -41992,6 +42000,7 @@ var import_node_child_process = require("node:child_process");
4199242000var import_node_fs4 = require("node:fs");
4199342001var import_node_path2 = require("node:path");
4199442002var import_node_os3 = require("node:os");
42003+ var import_node_crypto3 = require("node:crypto");
4199542004
4199642005// src/runtime/node-fetch-compat.ts
4199742006var applied = false;
@@ -42075,6 +42084,7 @@ async function serve(configPath, debug) {
4207542084 const path = configPath ?? process.env.ZCODE_PROXY_CONFIG ?? "config.yaml";
4207642085 if (!(0, import_node_fs4.existsSync)(path)) {
4207742086 (0, import_node_fs4.writeFileSync)(path, EXAMPLE_CONFIG_YAML, "utf-8");
42087+ ensureDeviceMidInConfig(path);
4207842088 console.log(`Created ${path} from bundled template.`);
4207942089 console.log(`Edit auth.apiKey, or run: zcode-proxy auth login <zai|bigmodel>
4208042090`);
@@ -42267,6 +42277,7 @@ async function authLogin(args) {
4226742277 console.error("Usage: zcode-proxy auth login <zai|bigmodel> [--import]");
4226842278 process.exit(1);
4226942279 }
42280+ ensureConfigWithDeviceMid();
4227042281 console.log(`Logging in: ${provider}${importMode ? " (import)" : " (OAuth)"}
4227142282`);
4227242283 let cred;
@@ -42286,6 +42297,40 @@ Logged in as ${provider}.`);
4228642297 if (cred.userId) console.log(` User ID: ${cred.userId}`);
4228742298 console.log(` Stored: ${getStorePath()}`);
4228842299}
42300+ function ensureConfigWithDeviceMid() {
42301+ const path = process.env.ZCODE_PROXY_CONFIG ?? "config.yaml";
42302+ if (!(0, import_node_fs4.existsSync)(path)) {
42303+ (0, import_node_fs4.writeFileSync)(path, EXAMPLE_CONFIG_YAML, "utf-8");
42304+ console.log(`Created ${path} from bundled template.`);
42305+ }
42306+ return ensureDeviceMidInConfig(path);
42307+ }
42308+ function ensureDeviceMidInConfig(path) {
42309+ const deviceMidLine = /^(\s*)deviceMid:\s*(.*)$/m;
42310+ const identityBlockLine = /^identity:\s*$/m;
42311+ const raw = (0, import_node_fs4.readFileSync)(path, "utf-8");
42312+ const existing = deviceMidLine.exec(raw);
42313+ if (existing) {
42314+ const value = existing[2].trim().replace(/^"|"$/g, "");
42315+ if (value.length > 0) return value;
42316+ }
42317+ const mid = (0, import_node_crypto3.randomUUID)();
42318+ let updated;
42319+ if (existing) {
42320+ updated = raw.replace(deviceMidLine, `${existing[1]}deviceMid: "${mid}"`);
42321+ } else if (identityBlockLine.test(raw)) {
42322+ updated = raw.replace(identityBlockLine, `identity:
42323+ deviceMid: "${mid}"`);
42324+ } else {
42325+ const block = `identity:
42326+ deviceMid: "${mid}"
42327+ `;
42328+ updated = raw.endsWith("\n") || raw.length === 0 ? raw + block : raw + "\n" + block;
42329+ }
42330+ (0, import_node_fs4.writeFileSync)(path, updated, "utf-8");
42331+ console.log(`Device identity generated: ${mid.slice(0, 8)}\u2026 (stored in ${path})`);
42332+ return mid;
42333+ }
4228942334function authLogout() {
4229042335 if (!(0, import_node_fs4.existsSync)(getStorePath())) {
4229142336 console.log("Not logged in.");
@@ -42371,6 +42416,7 @@ function openBrowser(url) {
4237142416// Annotate the CommonJS export names for ESM import in node:
42372424170 && (module.exports = {
4237342418 applyAndroidIdentityDefaults,
42419+ ensureDeviceMidInConfig,
4237442420 main,
4237542421 parseServeArgs
4237642422});
0 commit comments