@zhushanwen/zcode-subagent-cli 0.8.0 → 0.8.2
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/dist/{chunk-REEFBX67.js → chunk-Z6IPBSKG.js} +550 -48
- package/dist/index.cjs +550 -48
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -1
- package/dist/main.cjs +550 -48
- package/dist/main.js +1 -1
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -424,41 +424,97 @@ function resolveAccountModelRef(wanted, wantedProvider, sources) {
|
|
|
424
424
|
`\u672A\u77E5 account provider "${wantedProvider}"\uFF08\u5185\u5EFA\u76EE\u5F55\u65E0\u6B64\u89C4\u5219\uFF09\u3002\u6062\u590D\u6307\u5F15\uFF1A\u6539\u7528\u76EE\u5F55\u5185 account:* \u89C4\u5219\uFF08\u5982 account:zai-individual-coding-plan / account:bigmodel-individual-coding-plan\uFF09\u3002`
|
|
425
425
|
);
|
|
426
426
|
}
|
|
427
|
-
|
|
428
|
-
return wanted;
|
|
427
|
+
return `${wantedProvider}/${normalizeAccountModel(accountRule, wanted, wantedProvider)}`;
|
|
429
428
|
}
|
|
430
429
|
function findAccountProviderRule(catalog, wantedProvider) {
|
|
431
430
|
const catalogRules = isRecord(catalog) && isRecord(catalog["config"]) && isRecord(catalog["config"]["providerConfigRules"]) ? catalog["config"]["providerConfigRules"]["providerRules"] : void 0;
|
|
432
431
|
const accountRule = Array.isArray(catalogRules) ? catalogRules.find((r) => isRecord(r) && r["providerId"] === wantedProvider) : void 0;
|
|
433
432
|
return isRecord(accountRule) ? accountRule : void 0;
|
|
434
433
|
}
|
|
435
|
-
function
|
|
434
|
+
function normalizeAccountModel(accountRule, wanted, wantedProvider) {
|
|
436
435
|
const accountConfig = isRecord(accountRule["config"]) ? accountRule["config"] : {};
|
|
437
436
|
const modelIds = accountConfig["builtinModelIds"] ?? accountConfig["personalModelIds"];
|
|
438
437
|
const short = modelShort(wanted);
|
|
439
|
-
if (Array.isArray(modelIds)
|
|
438
|
+
if (!Array.isArray(modelIds) || modelIds.length === 0) return short;
|
|
439
|
+
const matched = modelIds.find((m) => typeof m === "string" && m.toLowerCase() === short.toLowerCase());
|
|
440
|
+
if (matched === void 0) {
|
|
440
441
|
throw new ZcodePrepareError(
|
|
441
442
|
"model_not_available",
|
|
442
|
-
`\u672A\u77E5\u6A21\u578B "${short}"\uFF08account provider ${wantedProvider} \u4E0B\u53EF\u7528: ${modelIds.join(", ")}\uFF09\u3002`
|
|
443
|
+
`\u672A\u77E5\u6A21\u578B "${short}"\uFF08account provider ${wantedProvider} \u4E0B\u53EF\u7528: ${modelIds.filter((m) => typeof m === "string").join(", ")}\uFF09\u3002`
|
|
443
444
|
);
|
|
444
445
|
}
|
|
446
|
+
return matched;
|
|
447
|
+
}
|
|
448
|
+
var PI_TO_ZCODE_PROVIDER_MAP = {
|
|
449
|
+
"zai-coding-cn": "account:bigmodel-individual-coding-plan"
|
|
450
|
+
};
|
|
451
|
+
function translatePiModelRefToZcode(requested, sources) {
|
|
452
|
+
if (!requested.includes("/")) return requested;
|
|
453
|
+
const piProvider = providerOf(requested);
|
|
454
|
+
const target = PI_TO_ZCODE_PROVIDER_MAP[piProvider];
|
|
455
|
+
if (target === void 0) return requested;
|
|
456
|
+
const catalogPath = locateZcodeBuiltinCatalog(sources);
|
|
457
|
+
if (catalogPath === void 0) {
|
|
458
|
+
throw new ZcodePrepareError(
|
|
459
|
+
"model_not_available",
|
|
460
|
+
`\u6A21\u578B\u901A\u9053\u7FFB\u8BD1\u5931\u8D25\uFF1Api \u4FA7 "${piProvider}" \u5728 zcode \u4FA7\u5BF9\u5E94 ${target}\uFF0C\u4F46\u5185\u5EFA\u76EE\u5F55\u5B9A\u4F4D\u5931\u8D25\uFF08ZCODE_BUILTIN_PROVIDER_CONFIG_FILE \u4E0E runtime/provider \u626B\u63CF\u5747\u672A\u547D\u4E2D\uFF09\u3002\u6062\u590D\u6307\u5F15\uFF1A\u786E\u8BA4 ZCode \u5DF2\u5B89\u88C5\u540E\u91CD\u8BD5\u3002`
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
let catalog;
|
|
464
|
+
try {
|
|
465
|
+
catalog = JSON.parse(fs.readFileSync(catalogPath, "utf8"));
|
|
466
|
+
} catch (err) {
|
|
467
|
+
throw new ZcodePrepareError(
|
|
468
|
+
"model_not_available",
|
|
469
|
+
`\u6A21\u578B\u901A\u9053\u7FFB\u8BD1\u5931\u8D25\uFF1A\u5185\u5EFA\u76EE\u5F55\u4E0D\u53EF\u8BFB\uFF08${err instanceof Error ? err.message : String(err)}\uFF09\u3002`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
const accountRule = findAccountProviderRule(catalog, target);
|
|
473
|
+
if (accountRule === void 0) {
|
|
474
|
+
throw new ZcodePrepareError(
|
|
475
|
+
"model_not_available",
|
|
476
|
+
`pi \u4FA7 "${piProvider}" \u7684 zcode \u5BF9\u5E94\u901A\u9053 ${target} \u4E0D\u53EF\u7528\uFF08\u5185\u5EFA\u76EE\u5F55\u65E0\u6B64\u89C4\u5219\uFF09\u3002\u6062\u590D\u6307\u5F15\uFF1A\u5728 ZCode \u684C\u9762\u7AEF\u5B8C\u6210\u8BE5 plan \u7684\u8D26\u53F7\u767B\u5F55/\u914D\u7F6E\u540E\u91CD\u8BD5\u3002`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
const accountConfig = isRecord(accountRule["config"]) ? accountRule["config"] : {};
|
|
480
|
+
const modelIds = accountConfig["builtinModelIds"] ?? accountConfig["personalModelIds"];
|
|
481
|
+
if (!Array.isArray(modelIds) || modelIds.length === 0) {
|
|
482
|
+
return `${target}/${modelShort(requested)}`;
|
|
483
|
+
}
|
|
484
|
+
const wanted = modelShort(requested).toLowerCase();
|
|
485
|
+
const matched = modelIds.find((m) => typeof m === "string" && m.toLowerCase() === wanted);
|
|
486
|
+
if (matched === void 0) {
|
|
487
|
+
throw new ZcodePrepareError(
|
|
488
|
+
"model_not_available",
|
|
489
|
+
`\u6A21\u578B "${modelShort(requested)}" \u5728 ${target} \u4E0B\u65E0\u7B49\u4EF7\u6A21\u578B\uFF08\u53EF\u7528: ${modelIds.filter((m) => typeof m === "string").join(", ")}\uFF09\u3002\u6062\u590D\u6307\u5F15\uFF1A\u6539\u7528\u4E0A\u8FF0\u6A21\u578B\u4E4B\u4E00\uFF0C\u6216\u7701\u7565 model \u53C2\u6570\u8D70\u5F15\u64CE\u7F3A\u7701\u3002`
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
return `${target}/${matched}`;
|
|
493
|
+
}
|
|
494
|
+
function translateToAccountModelRef(wanted, sources) {
|
|
495
|
+
const translated = translatePiModelRefToZcode(wanted, sources);
|
|
496
|
+
const translatedProvider = translated.includes("/") ? providerOf(translated) : void 0;
|
|
497
|
+
if (translatedProvider !== void 0 && translatedProvider.startsWith("account:")) {
|
|
498
|
+
return resolveAccountModelRef(translated, translatedProvider, sources);
|
|
499
|
+
}
|
|
500
|
+
return void 0;
|
|
445
501
|
}
|
|
446
502
|
function resolveZcodeModelRef(requested, sources) {
|
|
447
503
|
const { conf, sourceDesc } = readPersonalProviderView(sources);
|
|
448
504
|
const withKey = [...conf.providers.entries()].filter(([, e]) => hasApiKey(e));
|
|
449
505
|
const wanted = requested?.trim() || void 0;
|
|
506
|
+
if (wanted !== void 0) {
|
|
507
|
+
const accountRef = translateToAccountModelRef(wanted, sources);
|
|
508
|
+
if (accountRef !== void 0) return accountRef;
|
|
509
|
+
}
|
|
450
510
|
if (withKey.length === 0) {
|
|
451
511
|
const hint = wanted ? `model="${wanted}" \u4E0D\u80FD\u6821\u9A8C` : "\u7F3A\u7701\u6A21\u578B\u89E3\u6790\u4E0D\u80FD\u6821\u9A8C";
|
|
452
512
|
throw new ZcodePrepareError(
|
|
453
513
|
"engine_credential_missing",
|
|
454
|
-
`zcode \u5F15\u64CE\u627E\u4E0D\u5230\u4EFB\u4F55\u5E26 apiKey \u7684\u4E2A\u4EBA provider\uFF08${hint}\uFF09\u3002\u5DF2\u8BFB\u6E90\uFF1A${sourceDesc}\u3002\u6062\u590D\u6307\u5F15\uFF1A\u5728 ZCode \u684C\u9762\u7AEF\u914D\u7F6E\u81F3\u5C11\u4E00\u4E2A\u4E2A\u4EBA provider\uFF08provider_config.json \u5185\u5B58\u5728 config.access.apiKey \u975E\u7A7A\u6761\u76EE\uFF09\u540E\u91CD\u8BD5\uFF1Bplan \u5957\u9910\u65CF\
|
|
514
|
+
`zcode \u5F15\u64CE\u627E\u4E0D\u5230\u4EFB\u4F55\u5E26 apiKey \u7684\u4E2A\u4EBA provider\uFF08${hint}\uFF09\u3002\u5DF2\u8BFB\u6E90\uFF1A${sourceDesc}\u3002\u6062\u590D\u6307\u5F15\uFF1A\u5728 ZCode \u684C\u9762\u7AEF\u914D\u7F6E\u81F3\u5C11\u4E00\u4E2A\u4E2A\u4EBA provider\uFF08provider_config.json \u5185\u5B58\u5728 config.access.apiKey \u975E\u7A7A\u6761\u76EE\uFF09\u540E\u91CD\u8BD5\uFF1Bplan \u5957\u9910\u65CF\u4E2D account: \u524D\u7F00\u7ECF\u8D26\u53F7 entitlement \u76F4\u901A\u53EF\u7528\uFF08builtin: \u524D\u7F00\u4E0D\u88C5\u8F7D\uFF0C\u4E0D\u53EF\u4F5C\u4E3A\u5F15\u64CE\u6A21\u578B\uFF09\u3002` + TAIJI_SYNC_GUIDANCE
|
|
455
515
|
);
|
|
456
516
|
}
|
|
457
517
|
if (wanted === void 0) return "";
|
|
458
|
-
const wantedProvider = wanted.includes("/") ? providerOf(wanted) : void 0;
|
|
459
|
-
if (wantedProvider !== void 0 && wantedProvider.startsWith("account:")) {
|
|
460
|
-
return resolveAccountModelRef(wanted, wantedProvider, sources);
|
|
461
|
-
}
|
|
462
518
|
const provider = wanted.includes("/") ? providerOf(wanted) : defaultProviderForShortName(conf, withKey);
|
|
463
519
|
const short = modelShort(wanted);
|
|
464
520
|
const entry = conf.providers.get(provider);
|
|
@@ -487,16 +543,58 @@ function resolveZcodeModelRef(requested, sources) {
|
|
|
487
543
|
function listZcodeModels(sources) {
|
|
488
544
|
const { conf } = readPersonalProviderView(sources);
|
|
489
545
|
const out = [];
|
|
546
|
+
const seen = /* @__PURE__ */ new Set();
|
|
490
547
|
for (const [pid, entry] of conf.providers) {
|
|
491
548
|
if (!hasApiKey(entry)) continue;
|
|
492
549
|
const providerName = entry.providerName !== void 0 && entry.providerName.trim() !== "" ? entry.providerName.trim() : void 0;
|
|
493
550
|
for (const model of entry.models ?? []) {
|
|
551
|
+
if (seen.has(`${pid}/${model}`)) continue;
|
|
552
|
+
seen.add(`${pid}/${model}`);
|
|
494
553
|
out.push({
|
|
495
554
|
id: `${pid}/${model}`,
|
|
496
555
|
...providerName !== void 0 ? { name: `${providerName} \xB7 ${model}` } : {}
|
|
497
556
|
});
|
|
498
557
|
}
|
|
499
558
|
}
|
|
559
|
+
for (const entry of listAccountFamilyModels(sources)) {
|
|
560
|
+
if (seen.has(entry.id)) continue;
|
|
561
|
+
seen.add(entry.id);
|
|
562
|
+
out.push(entry);
|
|
563
|
+
}
|
|
564
|
+
return out;
|
|
565
|
+
}
|
|
566
|
+
function readCatalogProviderRules(catalog) {
|
|
567
|
+
const rules = isRecord(catalog) && isRecord(catalog["config"]) && isRecord(catalog["config"]["providerConfigRules"]) ? catalog["config"]["providerConfigRules"]["providerRules"] : void 0;
|
|
568
|
+
return Array.isArray(rules) ? rules : [];
|
|
569
|
+
}
|
|
570
|
+
function pushAccountFamilyRuleModels(rule, out) {
|
|
571
|
+
if (!isRecord(rule)) return;
|
|
572
|
+
const providerId = rule["providerId"];
|
|
573
|
+
if (typeof providerId !== "string" || !providerId.startsWith("account:")) return;
|
|
574
|
+
const cfg = isRecord(rule["config"]) ? rule["config"] : {};
|
|
575
|
+
const models = Array.isArray(cfg["builtinModelIds"]) ? cfg["builtinModelIds"] : cfg["personalModelIds"];
|
|
576
|
+
const providerName = typeof rule["providerName"] === "string" && rule["providerName"].trim() !== "" ? rule["providerName"].trim() : void 0;
|
|
577
|
+
for (const model of Array.isArray(models) ? models : []) {
|
|
578
|
+
if (typeof model !== "string" || model.trim() === "") continue;
|
|
579
|
+
out.push({
|
|
580
|
+
id: `${providerId}/${model}`,
|
|
581
|
+
...providerName !== void 0 ? { name: `${providerName} \xB7 ${model}` } : {}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function listAccountFamilyModels(sources) {
|
|
586
|
+
const catalogPath = locateZcodeBuiltinCatalog(sources);
|
|
587
|
+
if (catalogPath === void 0) return [];
|
|
588
|
+
let catalog;
|
|
589
|
+
try {
|
|
590
|
+
catalog = JSON.parse(fs.readFileSync(catalogPath, "utf8"));
|
|
591
|
+
} catch {
|
|
592
|
+
return [];
|
|
593
|
+
}
|
|
594
|
+
const out = [];
|
|
595
|
+
for (const rule of readCatalogProviderRules(catalog)) {
|
|
596
|
+
pushAccountFamilyRuleModels(rule, out);
|
|
597
|
+
}
|
|
500
598
|
return out;
|
|
501
599
|
}
|
|
502
600
|
|
|
@@ -507,6 +605,406 @@ var path3 = __toESM(require("path"), 1);
|
|
|
507
605
|
// src/error-message.ts
|
|
508
606
|
var import_subagent_engine_sdk5 = require("@zhushanwen/subagent-engine-sdk");
|
|
509
607
|
|
|
608
|
+
// src/appserver-launcher-patches.ts
|
|
609
|
+
var CLI_PATCH_SECTION = `
|
|
610
|
+
// [2026-10-13 account \u76F4\u901A\u2461] CLI bundle \u6E90\u7801\u5185\u5B58\u8865\u4E01\uFF1A\u5916\u90E8 spawn \u7684\u8D26\u53F7\u6761\u76EE\u6784\u5EFA
|
|
611
|
+
// \u786C\u7F16\u7801 entitled:!1\uFF08YXe\uFF09\uFF0C\u6570\u636E\u9762\u6CE8\u5165\uFF08\u76EE\u5F55 entitled \u5B57\u6BB5\uFF09\u88AB\u5176\u65E0\u89C6\u2014\u2014\u6309\u7528\u6237\u88C1\u51B3
|
|
612
|
+
// \u6539 zcode \u6E90\u7801\u7ED5\u8FC7\uFF1A\u62E6\u622A CLI bundle \u6E90\u7801\u8BFB\u53D6\uFF0C\u5185\u5B58\u66FF\u6362\u8BE5\u5B57\u9762\u91CF\u4E3A !0\uFF08ZCode.app
|
|
613
|
+
// \u78C1\u76D8\u6587\u4EF6\u96F6\u89E6\u78B0\uFF1B\u951A\u4E32\u542B ]]:[] \u5C3E\u7F00\u552F\u4E00\u547D\u4E2D YXe \u6784\u9020\uFF0C\u53E6\u4E00\u5904\u540C\u540D\u6761\u4EF6\u903B\u8F91\u4E0D\u53D7\u5F71\u54CD\uFF09\u3002
|
|
614
|
+
// \u951A\u4E0D\u547D\u4E2D\uFF08\u4E0A\u6E38\u6DF7\u6DC6\u5F62\u6001\u53D8\u5316\uFF09\u2192 \u539F\u6587\u900F\u51FA\uFF1A\u4EC5 account \u5BB6\u65CF\u7EE7\u7EED\u88AB\u62D2\uFF0C\u4E2A\u4EBA provider
|
|
615
|
+
// \u4E0D\u53D7\u5F71\u54CD\u3002
|
|
616
|
+
// \u8865\u4E01\u6BB5\u5185\u8054\u626B\u63CF\u5668\uFF082026-10 review\xB7MF-1-5\uFF09\uFF1A\u8DF3\u8FC7\u5B57\u7B26\u4E32/\u6A21\u677F\u5B57\u9762\u91CF/\u6CE8\u91CA\uFF0C\u8BA9\u62EC\u53F7
|
|
617
|
+
// \u914D\u5E73\u4E0E\u53C2\u6570\u5207\u5206\u53EA\u5728\u4EE3\u7801\u9762\u4E0A\u8FDB\u884C\u2014\u2014bundle \u5185\u8054\u4E32\u91CC\u7684 ')' \u66FE\u628A\u8C03\u7528\u70B9\u53C2\u6570\u914D\u5E73\u5E26\u504F\u3002
|
|
618
|
+
// \u8FD4\u56DE -1 = \u8BE5\u4F4D\u7F6E\u4E0D\u662F\u5B57\u9762\u91CF/\u6CE8\u91CA\u8D77\u70B9\uFF08\u6B63\u5E38\u4EE3\u7801\u5B57\u7B26\uFF09\u3002
|
|
619
|
+
function __skipLiteralOrComment(src, i) {
|
|
620
|
+
const ch = src[i];
|
|
621
|
+
if (ch === '"' || ch === "'") {
|
|
622
|
+
i++;
|
|
623
|
+
while (i < src.length) {
|
|
624
|
+
if (src.charCodeAt(i) === 92) { i += 2; continue; }
|
|
625
|
+
if (src[i] === ch) return i + 1;
|
|
626
|
+
i++;
|
|
627
|
+
}
|
|
628
|
+
return i;
|
|
629
|
+
}
|
|
630
|
+
if (ch === '\`') {
|
|
631
|
+
i++;
|
|
632
|
+
while (i < src.length) {
|
|
633
|
+
if (src.charCodeAt(i) === 92) { i += 2; continue; }
|
|
634
|
+
const c = src[i];
|
|
635
|
+
if (c === '\`') return i + 1;
|
|
636
|
+
if (c === '$' && src[i + 1] === '{') {
|
|
637
|
+
let depth = 1;
|
|
638
|
+
i += 2;
|
|
639
|
+
while (i < src.length && depth > 0) {
|
|
640
|
+
const cc = src[i];
|
|
641
|
+
if (cc === '"' || cc === "'" || cc === '\`') { i = __skipLiteralOrComment(src, i); continue; }
|
|
642
|
+
if (cc === '/' && src[i + 1] === '/') { const nl = src.indexOf('\\n', i + 2); i = nl < 0 ? src.length : nl + 1; continue; }
|
|
643
|
+
if (cc === '/' && src[i + 1] === '*') { const end = src.indexOf('*/', i + 2); i = end < 0 ? src.length : end + 2; continue; }
|
|
644
|
+
if (cc === '{') depth++;
|
|
645
|
+
else if (cc === '}') depth--;
|
|
646
|
+
i++;
|
|
647
|
+
}
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
i++;
|
|
651
|
+
}
|
|
652
|
+
return i;
|
|
653
|
+
}
|
|
654
|
+
if (ch === '/' && src[i + 1] === '/') {
|
|
655
|
+
const nl = src.indexOf('\\n', i + 2);
|
|
656
|
+
return nl < 0 ? src.length : nl + 1;
|
|
657
|
+
}
|
|
658
|
+
if (ch === '/' && src[i + 1] === '*') {
|
|
659
|
+
const end = src.indexOf('*/', i + 2);
|
|
660
|
+
return end < 0 ? src.length : end + 2;
|
|
661
|
+
}
|
|
662
|
+
return -1;
|
|
663
|
+
}
|
|
664
|
+
// \u4E0E openIdx \u5904 '(' \u914D\u5BF9\u7684\u95ED\u62EC\u53F7\uFF08\u8DF3\u8FC7\u5B57\u9762\u91CF/\u6CE8\u91CA\uFF09\uFF1B-1 = \u4E0D\u914D\u5E73\u3002
|
|
665
|
+
function __matchingParen(src, openIdx) {
|
|
666
|
+
let depth = 0;
|
|
667
|
+
for (let i = openIdx; i < src.length; i++) {
|
|
668
|
+
const skip = __skipLiteralOrComment(src, i);
|
|
669
|
+
if (skip >= 0) { i = skip - 1; continue; }
|
|
670
|
+
const c = src[i];
|
|
671
|
+
if (c === '(') depth++;
|
|
672
|
+
else if (c === ')') { depth--; if (depth === 0) return i; }
|
|
673
|
+
}
|
|
674
|
+
return -1;
|
|
675
|
+
}
|
|
676
|
+
// [start,end) \u5185\u6309\u9876\u5C42\u9017\u53F7\u5207\u5206\uFF08\u62EC\u53F7/\u65B9\u62EC\u53F7/\u5BF9\u8C61\u5B57\u9762\u91CF\u4E0E\u5B57\u9762\u91CF\u5185\u7684\u9017\u53F7\u4E0D\u8BA1\uFF09\uFF1B
|
|
677
|
+
// \u8FD4\u56DE\u7EDD\u5BF9\u504F\u79FB\u6BB5\u5217\u8868\u3002
|
|
678
|
+
function __splitTopLevel(src, start, end) {
|
|
679
|
+
const parts = [];
|
|
680
|
+
let depth = 0;
|
|
681
|
+
let segStart = start;
|
|
682
|
+
for (let i = start; i < end; i++) {
|
|
683
|
+
const skip = __skipLiteralOrComment(src, i);
|
|
684
|
+
if (skip >= 0) { i = Math.min(skip, end) - 1; continue; }
|
|
685
|
+
const c = src[i];
|
|
686
|
+
if (c === '(' || c === '[' || c === '{') depth++;
|
|
687
|
+
else if (c === ')' || c === ']' || c === '}') depth--;
|
|
688
|
+
else if (c === ',' && depth === 0) { parts.push({ start: segStart, end: i }); segStart = i + 1; }
|
|
689
|
+
}
|
|
690
|
+
parts.push({ start: segStart, end: end });
|
|
691
|
+
return parts;
|
|
692
|
+
}
|
|
693
|
+
const __cliPatchCache = new Map();
|
|
694
|
+
// \u5E94\u7528\u6001\u6807\u5FD7\u53D1\u5E03\uFF082026-10 review\uFF09\uFF1A\u5B89\u88C5\u95E8\u66FE\u4EE5\u8865\u4E01\u4EA7\u7269\u5B50\u4E32\u5224\u5B9A header-port\u2014\u2014\u771F\u5B9E
|
|
695
|
+
// 3.15.3 bundle \u672C\u5C31\u542B 8 \u5904 'providerRuntimeHeadersPort:'\uFF082 \u5904 ',providerRuntimeHeadersPort:'\uFF09
|
|
696
|
+
// \u2192 \u5B50\u4E32\u5224\u5B9A\u6052\u771F\u3001\u5BF9\u951A\u70B9\u6F02\u79FB\u96F6\u68C0\u6D4B\u529B\u3002\u6539\u7531\u8865\u4E01\u51FD\u6570\u672C\u8EAB\u53D1\u5E03 {entitled,standalone,
|
|
697
|
+
// headerPort}\uFF08\u7F13\u5B58\u547D\u4E2D\u4ECD\u53EF\u8BFB\uFF09\uFF0C\u95E8\u53EA\u8BFB\u6807\u5FD7\uFF08\u4E09\u5904\u5224\u5B9A\u5404\u81EA\u5177\u540D\uFF0C\u6F02\u79FB\u4E0D\u9759\u9ED8\uFF09\u3002
|
|
698
|
+
const __cliPatchStatus = new Map();
|
|
699
|
+
function patchedCliSource(path) {
|
|
700
|
+
if (__cliPatchCache.has(path)) return __cliPatchCache.get(path);
|
|
701
|
+
let result = null;
|
|
702
|
+
let entitledApplied = false;
|
|
703
|
+
let standaloneApplied = false;
|
|
704
|
+
let portInjected = false;
|
|
705
|
+
try {
|
|
706
|
+
const readOrig = fs.__origReadFileSync || fs.readFileSync;
|
|
707
|
+
let src = readOrig(path, 'utf8');
|
|
708
|
+
// \u2460 \u7248\u672C\u9C81\u68D2\u951A\uFF082026-10-13 \u4FEE\u8BA2\uFF09\uFF1Aminified \u6807\u8BC6\u7B26\uFF08Uk/I3 \u7B49\uFF09\u968F zcode \u91CD\u65B0\u6253\u5305
|
|
709
|
+
// \u6F02\u79FB\uFF0C\u5C5E\u6027\u540D\uFF08zcodeBuiltinProviders / zhipu-account / entitled\uFF09\u662F\u6570\u636E/\u5951\u7EA6
|
|
710
|
+
// \u771F\u540D\u4E0D\u88AB\u6DF7\u6DC6\u2014\u2014\u4EE5\u5C5E\u6027\u540D\u5B9A\u4F4D + 600 \u5B57\u7B26\u7A97\u53E3\u5185\u628A\u8D26\u53F7\u6761\u76EE\u6784\u5EFA\u7684 entitled:!1
|
|
711
|
+
// \u7FFB\u8F6C\u4E3A !0\u3002\u7A97\u53E3\u96F6\u547D\u4E2D = \u4E0A\u6E38\u5F62\u6001\u6F02\u79FB \u2192 \u539F\u6587\u900F\u51FA + stderr warn\uFF08\u6F02\u79FB\u53EF\u89C1\uFF0C
|
|
712
|
+
// \u8FDB app-server stderr \u65E5\u5FD7\uFF09\u3002
|
|
713
|
+
const anchorIdx = src.indexOf('zcodeBuiltinProviders.entries()');
|
|
714
|
+
if (anchorIdx >= 0) {
|
|
715
|
+
const window = src.slice(anchorIdx, Math.min(src.length, anchorIdx + 600));
|
|
716
|
+
if (window.indexOf('zhipu-account') >= 0 && window.indexOf('entitled:!1') >= 0) {
|
|
717
|
+
src = src.slice(0, anchorIdx)
|
|
718
|
+
+ window.split('entitled:!1').join('entitled:!0')
|
|
719
|
+
+ src.slice(anchorIdx + 600);
|
|
720
|
+
entitledApplied = true;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
if (!entitledApplied) {
|
|
724
|
+
process.stderr.write('[zcode-launcher] account bypass: CLI bundle anchor not found (zcode upstream shape drifted?) - account family stays gated\\n');
|
|
725
|
+
}
|
|
726
|
+
// \u2461 [2026-10-16 standalone account] \u534F\u8BAE\u8DEF\u5F84\u7684 provider registry \u6052\u4EE5 host-account
|
|
727
|
+
// \u6A21\u5F0F\u521B\u5EFA\uFF08\u6E90\u7801\uFF1Acreate:r(()=>xCt(z),"create") \u4E0D\u4F20 standalone\uFF09\u2014\u2014\u8BE5\u6A21\u5F0F\u4E0B
|
|
728
|
+
// account \u65CF\u8BF7\u6C42\u5FC5\u987B\u7531\u5BBF\u4E3B\u5E94\u7B54 providerRuntimeHeaders\uFF1Btaiji \u7684 headless spawn \u65E0
|
|
729
|
+
// \u5BBF\u4E3B\u53C2\u4E0E\u8BE5\u534F\u8BAE\uFF0C\u5E94\u7B54\u5E27\u7578\u5F62 \u2192 zod invalid_union(headersApplied)\uFF082026-10-16 \u771F\u673A
|
|
730
|
+
// \u4E8B\u6545\u6839\u56E0\uFF1B\u5BBF\u4E3B\u65E5\u5FD7\u96F6\u8E2A\u8FF9 = \u8BF7\u6C42\u4ECE\u672A\u5230\u8FBE\u4EFB\u4F55 host \u5B9E\u73B0\uFF09\u3002\u672C\u8865\u4E01\u7ED9\u8BE5\u8C03\u7528\u6CE8\u5165
|
|
731
|
+
// {standalone:{}}\uFF1Astandalone \u6A21\u5F0F\u81EA\u5EFA\u672C\u5730\u8D26\u53F7\u6E90\uFF08entitled \u7531\u51ED\u636E\u5B58\u5728\u6027\u8BA1\u7B97\uFF0C
|
|
732
|
+
// \u8BFB credentials.json\uFF09\u5E76\u6CE8\u5165\u672C\u5730 providerRuntimeHeaders \u7AEF\u53E3\u2014\u2014\u8D26\u53F7\u65CF\u5168\u94FE\u672C\u5730
|
|
733
|
+
// \u5B8C\u6210\u3001\u96F6\u5BBF\u4E3B\u4F9D\u8D56\u3002\u951A\u70B9\u4E24\u5904\u7A33\u5B9A\u4E32\uFF08\u975E minified\uFF09\uFF1A\u6A21\u5757\u5BFC\u51FA\u6620\u5C04
|
|
734
|
+
// startProcessProviderRegistryRuntime:()=> \u53D6\u51FD\u6570\u540D + \u8C03\u7528\u70B9 create:r(()=><fn>(\u3002
|
|
735
|
+
const exportAnchor = 'startProcessProviderRegistryRuntime:()=>';
|
|
736
|
+
const exportIdx = src.indexOf(exportAnchor);
|
|
737
|
+
if (exportIdx >= 0) {
|
|
738
|
+
// \u540D\u79F0\u5C3E\u90E8\u987B\u662F\u5206\u9694\u7B26\uFF08\u771F\u5B9E\u5F62\u6001 = \u5BFC\u51FA\u6620\u5C04\u5BF9\u8C61 ',' / '}'\uFF09\uFF1A'{0,10}' \u4E0A\u9650\u4F1A\u9759\u9ED8
|
|
739
|
+
// \u622A\u65AD\u66F4\u957F\u7684 minified \u540D \u2192 \u53D6\u5230\u9519\u8BEF\u51FD\u6570\u540D\uFF1B\u8981\u6C42\u5206\u9694\u7B26\u540E\u622A\u65AD\u4E0D\u6210\u7ACB\uFF08\u6F02\u79FB\u53EF\u89C1\uFF09\u3002
|
|
740
|
+
const nameMatch = /^([A-Za-z_$][A-Za-z0-9_$]*)(?=[,}:])/.exec(src.slice(exportIdx + exportAnchor.length));
|
|
741
|
+
const fnName = nameMatch ? nameMatch[1] : null;
|
|
742
|
+
if (fnName) {
|
|
743
|
+
// \u951A\u70B9 A\uFF08\u9996\u9009\uFF0C\u6297\u6F02\u79FB\u6700\u5F3A\uFF09\uFF1A\u51FD\u6570\u5B9A\u4E49\u9ED8\u8BA4\u53C2\u6570\u6CD5\u2014\u2014
|
|
744
|
+
// 'function <fnName>(e,t={}){' \u2192 'function <fnName>(e,t={standalone:{}}){'\u3002
|
|
745
|
+
// \u8BED\u4E49\uFF1A\u8C03\u7528\u65B9\u7701\u7565\u7B2C\u4E8C\u53C2\uFF08\u534F\u8BAE\u8DEF\u5F84 xCt(z)\uFF09\u2192 t = {standalone:{}}\uFF1B\u663E\u5F0F\u4F20
|
|
746
|
+
// {}\uFF08skipUserConfig \u8DEF\u5F84\uFF09\u6216 {standalone:{...}}\uFF08TUI \u8DEF\u5F84\uFF09\u4E0D\u53D7\u5F71\u54CD\u3002
|
|
747
|
+
const defAnchor = 'function ' + fnName + '(';
|
|
748
|
+
// \u7ED3\u6784\u6821\u9A8C\uFF082026-10 review\xB7MF-1-5\uFF09\uFF1A\u66FE\u53D6\u9996\u4E2A\u6587\u672C\u547D\u4E2D\u2014\u2014\u771F\u5B9E bundle \u6709\u6570\u767E\u4E2A
|
|
749
|
+
// \u91CD\u540D function \u5B9A\u4E49\uFF08\u540C\u540D\u4E0D\u4EE3\u8868\u552F\u4E00\uFF09\uFF0C\u9519\u6539\u4E00\u5904\u4ECD\u662F\u8BED\u6CD5\u5408\u6CD5 bundle\uFF0C\u81EA\u68C0\u65E0\u6CD5
|
|
750
|
+
// \u53D1\u73B0\u4E14\u95E8\u4F1A\u62A5 armed\u3002\u5B9A\u4E49\u5FC5\u987B**\u552F\u4E00**\u4E14\u4F4D\u4E8E\u5BFC\u51FA\u6620\u5C04\u4E4B\u524D\uFF1B\u7B2C\u4E8C\u5904\u51FA\u73B0\u6216\u5B9A\u4E49
|
|
751
|
+
// \u843D\u5728\u5BFC\u51FA\u6620\u5C04\u4E4B\u540E = \u65E0\u6CD5\u786E\u5B9A\u5BFC\u51FA\u5BF9\u8C61\u6307\u5411\u7684\u5B9E\u73B0 \u2192 \u653E\u5F03\u672C\u951A\uFF08\u56DE\u9000\u8C03\u7528\u70B9\u951A /
|
|
752
|
+
// not armed\uFF09\uFF0C\u5B81\u53EF\u6F0F\u8865\u4E5F\u4E0D\u9ED8\u9ED8\u6539\u9519\u4F4D\u7F6E\u3002
|
|
753
|
+
let defCount = 0;
|
|
754
|
+
let defIdx = -1;
|
|
755
|
+
for (let scan = src.indexOf(defAnchor); scan >= 0; scan = src.indexOf(defAnchor, scan + 1)) {
|
|
756
|
+
defCount++;
|
|
757
|
+
if (scan < exportIdx) defIdx = scan;
|
|
758
|
+
}
|
|
759
|
+
if (defCount !== 1) defIdx = -1;
|
|
760
|
+
if (defIdx >= 0) {
|
|
761
|
+
const paramsEnd = __matchingParen(src, defIdx + defAnchor.length - 1);
|
|
762
|
+
if (paramsEnd > defIdx) {
|
|
763
|
+
// \u5FC5\u987B\u6070\u597D\u4E24\u4E2A\u9876\u5C42\u53C2\u6570\u4E14\u7B2C\u4E8C\u4E2A\u4EE5 '={}' \u6536\u5C3E\uFF1A\u66FE\u53EA\u8981\u6C42 '={}' \u552F\u4E00\u2014\u2014
|
|
764
|
+
// function f(e={},t) \u4F1A\u628A standalone \u6CE8\u5165\u7B2C\u4E00\u4E2A\u53C2\u6570\uFF08\u8BED\u6CD5\u5408\u6CD5\u3001\u8BED\u4E49\u9519\u8BEF\uFF09\uFF0C
|
|
765
|
+
// function f(e,t={},o={}) \u4E5F\u4E0D\u786E\u5B9A\u6CE8\u5165\u70B9\uFF08\u65E2\u6709\u56DE\u9000\u7528\u4F8B\uFF09\u3002
|
|
766
|
+
const params = __splitTopLevel(src, defIdx + defAnchor.length, paramsEnd);
|
|
767
|
+
if (params.length === 2) {
|
|
768
|
+
const second = params[1];
|
|
769
|
+
let secondEnd = second.end;
|
|
770
|
+
while (secondEnd > second.start && src.charCodeAt(secondEnd - 1) <= 32) secondEnd--;
|
|
771
|
+
// \u51FD\u6570\u4F53\u7A97\u53E3\u4EE4\u724C\uFF08\u53EF\u9009\u4FDD\u9669\uFF09\uFF1A\u771F\u5B9E\u6CE8\u518C\u6E90\u5B9E\u88C5\u5F15\u7528 .standalone /
|
|
772
|
+
// credentialStore\u2014\u2014\u540C\u540D\u4F46\u65E0\u5173\u7684\u5B9A\u4E49\uFF08\u6216\u5B57\u7B26\u4E32\u5185\u4F2A\u547D\u4E2D\uFF09\u4E0D\u5F97\u88AB\u6539\u5199\u3002
|
|
773
|
+
const bodyWindow = src.slice(paramsEnd + 1, paramsEnd + 500);
|
|
774
|
+
if (secondEnd - second.start > 3 && src.slice(secondEnd - 3, secondEnd) === '={}'
|
|
775
|
+
&& (bodyWindow.indexOf('standalone') >= 0 || bodyWindow.indexOf('credentialStore') >= 0)) {
|
|
776
|
+
const at = secondEnd - 3;
|
|
777
|
+
src = src.slice(0, at) + '={standalone:{}}' + src.slice(secondEnd);
|
|
778
|
+
standaloneApplied = true;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
// \u951A\u70B9 B\uFF08\u56DE\u9000\uFF09\uFF1A\u8C03\u7528\u70B9\u6CE8\u5165 create:r(()=><fn>( \u2192 (<arg>,{standalone:{}})
|
|
784
|
+
if (!standaloneApplied) {
|
|
785
|
+
const callAnchor = 'create:r(()=>' + fnName + '(';
|
|
786
|
+
const callIdx = src.indexOf(callAnchor);
|
|
787
|
+
if (callIdx >= 0) {
|
|
788
|
+
const argStart = callIdx + callAnchor.length;
|
|
789
|
+
// \u62EC\u53F7\u914D\u5E73\u627E\u4E0E fnName( \u914D\u5BF9\u7684\u95ED\u62EC\u53F7\uFF08\u626B\u63CF\u5668\u8DF3\u8FC7\u5B57\u9762\u91CF/\u6A21\u677F/\u6CE8\u91CA\u2014\u2014\u5B9E\u53C2
|
|
790
|
+
// \u542B\u5185\u8054\u4E32\u6216\u5185\u5C42\u8C03\u7528\u65F6\u9996\u4E2A ')' \u843D\u5728\u9519\u8BEF\u5C42\u7EA7 = \u6CE8\u5165\u9519\u4F4D\u7684\u5047\u6210\u529F\uFF09
|
|
791
|
+
const closeIdx = __matchingParen(src, argStart - 1);
|
|
792
|
+
if (closeIdx > argStart) {
|
|
793
|
+
src = src.slice(0, closeIdx) + ',{standalone:{}}' + src.slice(closeIdx);
|
|
794
|
+
standaloneApplied = true;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (!standaloneApplied) {
|
|
801
|
+
process.stderr.write('[zcode-launcher] standalone account: CLI bundle anchor not found (zcode upstream shape drifted?) - account family stays host-dependent\\n');
|
|
802
|
+
}
|
|
803
|
+
// \u2462 [2026-10-16 standalone account\xB7\u7AEF\u53E3\u6CE8\u5165] \u534F\u8BAE\u8DEF\u5F84\u7684 app \u521B\u5EFA\uFF08
|
|
804
|
+
// createZCodeApp:r((ut={})=>INn({...q0c(...)}) \u552F\u4E00\u547D\u4E2D\uFF09\u672A\u4F20
|
|
805
|
+
// providerRuntimeHeadersPort\u2014\u2014app \u56E0\u6B64\u56DE\u843D host \u8BF7\u6C42\u7AEF\u53E3\uFF08mai\uFF09\uFF0C\u800C taiji \u94FE\u4E0A\u65E0
|
|
806
|
+
// \u5BBF\u4E3B\u4EFB\u5E94\u7B54 \u2192 zod invalid_union(headersApplied)\uFF08\u2461\u53EA\u4FEE\u4E86 registry \u4FA7\uFF1Aprovider
|
|
807
|
+
// \u5DF2\u80FD\u8FDB\u6CE8\u518C\u8868\uFF0C\u4F46\u8BA4\u8BC1\u5934\u4ECD\u8D70 host \u8BF7\u6C42\uFF09\u3002\u672C\u6B65\u628A registry runtime \u5BF9\u8C61\u4E0A\u7684
|
|
808
|
+
// providerRuntimeHeadersPort\uFF08standalone \u6A21\u5F0F = \u672C\u5730\u7AEF\u53E3\uFF09\u6CE8\u5165\u8BE5 app \u521B\u5EFA\u9009\u9879\uFF1A
|
|
809
|
+
// \u8D26\u53F7\u65CF\u8BA4\u8BC1\u5934\u7531\u672C\u8FDB\u7A0B\u672C\u5730\u89E3\u6790\uFF08\u51ED\u636E = credentials.json \u4E2D ZCode \u81EA\u6709\u9879\uFF09\u3002
|
|
810
|
+
const appAnchor = 'createZCodeApp:r(';
|
|
811
|
+
const appIdx = src.indexOf(appAnchor);
|
|
812
|
+
if (appIdx >= 0) {
|
|
813
|
+
const closeAnchor = '}),"createZCodeApp")';
|
|
814
|
+
const closeIdx = src.indexOf(closeAnchor, appIdx);
|
|
815
|
+
// \u641C\u7D22\u7A97\u4EE5\u6536\u53E3\u951A\u4E3A\u754C\uFF08\u66FE\u7528 appIdx+1600 \u56FA\u5B9A\u7A97\u2014\u2014\u7A97\u53E3\u8D8A\u8FC7\u6536\u53E3\u4F1A\u6355\u83B7\u9009\u9879\u5BF9\u8C61\u5916
|
|
816
|
+
// \u7684\u65E0\u5173\u540C\u540D\u5F62\u6001\uFF0C\u6CE8\u5165\u9519\u8BEF\u53D8\u91CF\u540D \u2192 \u52A0\u8F7D\u671F ReferenceError \u4E14\u8865\u4E01\u5C42\u65E0 warn\uFF09
|
|
817
|
+
const regMatch = closeIdx > appIdx
|
|
818
|
+
? /([A-Za-z_$][A-Za-z0-9_$]*).runtime.registryService/.exec(src.slice(appIdx, closeIdx))
|
|
819
|
+
: null;
|
|
820
|
+
if (closeIdx > appIdx && regMatch) {
|
|
821
|
+
// \u6761\u4EF6 spread\uFF082026-10 review\xB7S-4\uFF09\uFF1A\u4E0A\u6E38 kEt \u4EE5 \`n.providerRuntimeHeadersPort ??
|
|
822
|
+
// mai(e,t)\` \u628A\u5BBF\u4E3B\u8BF7\u6C42\u7AEF\u53E3\u663E\u5F0F\u4EA4\u7ED9 createZCodeApp\uFF08...q0c($0c(ut,n),...) \u5DF2\u542B\u8BE5\u503C\uFF09\uFF1B
|
|
823
|
+
// \u65E0\u6761\u4EF6\u5C3E\u63D2 <reg>.providerRuntimeHeadersPort \u5728 standalone \u672A\u6B66\u88C5\u5F62\u6001\uFF08\u503C\u4E3A
|
|
824
|
+
// undefined\uFF09\u4F1A shadow \u6389\u5BBF\u4E3B\u7AEF\u53E3\u3001\u62B9\u9664 host \u56DE\u843D\u3002\u6539\u4E3A\u4EC5\u5728\u672C\u5730\u7AEF\u53E3\u5B58\u5728\u65F6\u8986\u76D6\uFF1A
|
|
825
|
+
// standalone \u5F62\u6001\u5B57\u8282\u7B49\u4EF7\uFF0Chost \u5F62\u6001\u4FDD\u7559\u8C03\u7528\u65B9\u503C\u3002
|
|
826
|
+
const reg = regMatch[1];
|
|
827
|
+
src = src.slice(0, closeIdx)
|
|
828
|
+
+ ',...(' + reg + '.providerRuntimeHeadersPort?{providerRuntimeHeadersPort:' + reg + '.providerRuntimeHeadersPort}:{})'
|
|
829
|
+
+ src.slice(closeIdx);
|
|
830
|
+
portInjected = true;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (!portInjected) {
|
|
834
|
+
process.stderr.write('[zcode-launcher] standalone account: header-port injection anchor not found (zcode upstream shape drifted?) - account auth stays host-dependent\\n');
|
|
835
|
+
}
|
|
836
|
+
// \u4EA4\u4ED8\u6761\u4EF6\u542B portInjected\uFF082026-10 review \u4FEE\u6B63\uFF09\uFF1A\u66FE\u53EA\u8BA4 entitled/standalone\u2014\u2014
|
|
837
|
+
// \u7AEF\u53E3\u951A\u5355\u72EC\u547D\u4E2D\u65F6\u8865\u4E01\u4EA7\u7269\u88AB\u9759\u9ED8\u4E22\u5F03\uFF08\u2462 \u5F62\u540C\u865A\u8BBE\uFF0C\u65E0\u4EFB\u4F55\u4FE1\u53F7\uFF09\u3002
|
|
838
|
+
if (entitledApplied || standaloneApplied || portInjected) {
|
|
839
|
+
// \u7F13\u5B58\u524D\u8BED\u6CD5\u81EA\u68C0\uFF08\u5EC9\u4EF7\u4FDD\u9669\uFF09\uFF1A\u951A\u6F02\u79FB\u5F62\u6001\u4E0B\u63D2\u9519\u4F4D\u7F6E\u4F1A\u4EA7\u51FA\u8BED\u6CD5\u975E\u6CD5 bundle\uFF0C
|
|
840
|
+
// app-server \u542F\u52A8\u5373\u88F8 SyntaxError \u4E14\u96BE\u5F52\u56E0\u8865\u4E01\u5C42\u2014\u2014\u7F13\u5B58\u524D try \u7F16\u8BD1\u4E00\u6B21\uFF0C
|
|
841
|
+
// \u5931\u8D25\u56DE\u9000\u539F\u6587 + stderr warn\uFF08\u8D70\u65E2\u6709\u300C\u539F\u6587\u900F\u51FA\u300D\u964D\u7EA7\u8BED\u4E49\uFF09\u3002BOM/shebang \u5265\u79BB
|
|
842
|
+
// \u4E0E .js \u6269\u5C55\u5904\u7406\u5668\u540C\u6B3E\uFF08\u5426\u5219\u5408\u6CD5 CJS \u88AB\u8BEF\u5224\u975E\u6CD5\uFF09\u3002
|
|
843
|
+
let check = src;
|
|
844
|
+
if (check.charCodeAt(0) === 0xfeff) check = check.slice(1);
|
|
845
|
+
if (check.startsWith('#!')) check = check.slice(check.indexOf('\\n') + 1);
|
|
846
|
+
try {
|
|
847
|
+
new Function(check);
|
|
848
|
+
result = src;
|
|
849
|
+
} catch (syntaxErr) {
|
|
850
|
+
process.stderr.write('[zcode-launcher] cli-source patch produced invalid JS (' + ((syntaxErr && syntaxErr.message) || 'unknown') + ') - falling back to unpatched source\\n');
|
|
851
|
+
result = null;
|
|
852
|
+
}
|
|
853
|
+
} else {
|
|
854
|
+
result = null;
|
|
855
|
+
}
|
|
856
|
+
} catch { result = null; }
|
|
857
|
+
__cliPatchCache.set(path, result);
|
|
858
|
+
// \u6807\u5FD7\u53EA\u63CF\u8FF0\u300C\u5DF2\u4EA4\u4ED8\u4EA7\u7269\u300D\uFF1A\u8BED\u6CD5\u81EA\u68C0\u5931\u8D25/\u5F02\u5E38\u56DE\u9000\uFF08result=null\uFF09\u65F6\u5168\u90E8 false\u2014\u2014
|
|
859
|
+
// \u95E8\u4E0D\u5F97\u628A\u672A\u751F\u6548\u7684\u8865\u4E01\u62A5\u6210 armed\u3002
|
|
860
|
+
__cliPatchStatus.set(path, {
|
|
861
|
+
entitled: result !== null && entitledApplied,
|
|
862
|
+
standalone: result !== null && standaloneApplied,
|
|
863
|
+
headerPort: result !== null && portInjected,
|
|
864
|
+
});
|
|
865
|
+
return result;
|
|
866
|
+
}`;
|
|
867
|
+
var ACCOUNT_METADATA_SECTION = `
|
|
868
|
+
// [2026-10-16 standalone account metadata] standalone \u8D26\u53F7\u6E90\u8981\u6C42
|
|
869
|
+
// account-provider:<planProviderId>:identity / :auth-source \u4E24\u6761**\u5143\u6570\u636E**\u952E\u624D\u627F\u8BA4
|
|
870
|
+
// account provider\uFF08\u7F3A identity \u76F4\u63A5\u4E22\u5F03\u8BE5 provider \u2192 \u6D3E\u53D1\u62A5\u300CProvider Registry \u4E2D
|
|
871
|
+
// \u4E0D\u5B58\u5728 Model\u300D\uFF09\u3002\u4E24\u952E\u975E\u79D8\u5BC6\uFF08\u8EAB\u4EFD ID / \u8BA4\u8BC1\u6765\u6E90\uFF09\uFF0C\u771F\u51ED\u636E\u4ECD\u662F ZCode \u81EA\u6709\u9879
|
|
872
|
+
// \uFF08oauth token \u6216 plan api-key\uFF0C\u5747\u5728 credentials.json\uFF0C\u7531 ZCode \u767B\u5F55/\u914D\u7F6E\u5199\u5165\uFF09\u3002
|
|
873
|
+
// \u672C\u6B65\u5E42\u7B49\u4F9B\u7ED9\uFF1A\u7F3A\u65F6\u8FFD\u52A0 + **\u5B64\u513F\u503C\u77EB\u6B63**\uFF082026-10 review\xB7MF-1-1\uFF09\u2014\u2014\u6D3E\u751F\u503C\u6BCF\u6B21
|
|
874
|
+
// spawn \u91CD\u7B97\uFF0C\u65E2\u6709\u975E\u7A7A\u503C\u4ECD\u662F\u6743\u5A01\uFF08\u4E0D\u65E0\u5DEE\u522B\u8986\u5199\uFF09\uFF0C\u4EC5\u5F53\u5176\u80CC\u540E\u51ED\u636E\u5DF2\u4E0D\u5B58\u5728\u65F6\u624D
|
|
875
|
+
// \u6539\u5199\uFF08oauth \u64A4\u9500 / plan key \u8F6E\u6362 / \u8D26\u53F7\u5207\u6362\uFF09\uFF1B\u5426\u5219\u65E7\u8EAB\u4EFD/\u65E7\u6765\u6E90\u4F1A\u6C38\u4E45\u95E8\u63A7\u8BE5
|
|
876
|
+
// provider \u4E14\u6C38\u4E0D\u6536\u655B\u3002\u4EFB\u4F55\u5931\u8D25\u53EA warn \u4E0D\u963B\u65AD spawn\uFF08\u7F3A\u952E\u7684\u62A5\u9519\u8DEF\u5F84\u4E0E\u6062\u590D\u6307\u5F15\u7531
|
|
877
|
+
// \u5F15\u64CE\u4FA7\u65E2\u6709\u6587\u6848\u627F\u8F7D\uFF09\u3002catches\uFF1A\u6587\u4EF6\u7F3A\u5931/\u574F JSON/\u76EE\u5F55\u4E0D\u53EF\u5199\u3002
|
|
878
|
+
// \u5E76\u53D1\u8FB9\u754C\uFF08ADR-0143 \u767B\u8BB0\uFF09\uFF1A\u5BF9\u4E0E GUI \u5171\u4EAB\u7684\u51ED\u636E\u5E93\u505A\u65E0\u9501 read-modify-write \u5168\u91CF
|
|
879
|
+
// \u5199\u56DE\uFF0C\u4E0E GUI token \u5237\u65B0\u5E76\u53D1\u5B58\u5728\u6BEB\u79D2\u7EA7\u4E22\u66F4\u65B0\u7A97\u53E3\u2014\u2014\u540E\u679C\u81EA\u6108\uFF08GUI \u4FA7\u91CD\u8BD5\u5237\u65B0 /
|
|
880
|
+
// \u672C\u4FA7\u7F3A\u952E\u4E0B\u6B21 spawn \u5E42\u7B49\u8865\u9F50\uFF09\uFF0C\u4E8B\u5B9E\u9A71\u52A8\u539F\u5219\u4E0B\u4E0D\u52A0\u9501\u3001\u4E0D\u505A\u65F6\u95F4\u8865\u507F\u3002
|
|
881
|
+
// \u8C03\u7528\u5951\u7EA6\uFF082026-10 review\xB7S-3\uFF09\uFF1A\u4EC5\u5728\u5B89\u88C5\u95E8\u786E\u8BA4 standalone \u4E0E header-port \u4E24\u951A
|
|
882
|
+
// \u5747\u5DF2\u6B66\u88C5\u65F6\u8C03\u7528\u2014\u2014\u8FD9\u4E9B\u5143\u6570\u636E\u952E\u53EA\u88AB standalone \u8D26\u53F7\u6E90\u6D88\u8D39\uFF0C\u4E14\u8D26\u53F7\u94FE\u8981\u6210\u7ACB\u8FD8\u8981\u6C42
|
|
883
|
+
// \u8BA4\u8BC1\u5934\u8D70\u672C\u5730\u7AEF\u53E3\uFF1B\u4EFB\u4E00\u951A\u6F02\u79FB\uFF08\u7248\u672C\u4E0D\u652F\u6301\uFF09\u65F6\u5199\u5165\u7528\u6237\u5171\u4EAB credentials.json \u65E0
|
|
884
|
+
// \u4EFB\u4F55\u8FD0\u884C\u65F6\u6536\u76CA\uFF0C\u53EA\u589E\u98CE\u9669\u3002
|
|
885
|
+
function ensureAccountMetadata() {
|
|
886
|
+
try {
|
|
887
|
+
const credPath = path.join(os.homedir(), '.zcode', 'v2', 'credentials.json');
|
|
888
|
+
const readOrig = fs.__origReadFileSync || fs.readFileSync;
|
|
889
|
+
if (!fs.existsSync(credPath)) return;
|
|
890
|
+
const creds = JSON.parse(readOrig.call(fs, credPath, 'utf8'));
|
|
891
|
+
if (!creds || typeof creds !== 'object' || Array.isArray(creds)) return;
|
|
892
|
+
if (!CATALOG_PATH) return;
|
|
893
|
+
let planIds = [];
|
|
894
|
+
try {
|
|
895
|
+
const cat = JSON.parse(readOrig.call(fs, CATALOG_PATH, 'utf8'));
|
|
896
|
+
const pcr = (cat && cat.config && cat.config.providerConfigRules) || {};
|
|
897
|
+
const rules = Array.isArray(pcr.providerRules) ? pcr.providerRules : [];
|
|
898
|
+
planIds = rules
|
|
899
|
+
// \u8FC7\u6EE4\u9762\u523B\u610F\u5BBD\u4E8E 3.15.3 standalone \u5FEB\u7167\u7684\u6D88\u8D39\u5224\u636E\uFF08\u6E90\u7801 NNn\uFF1Atype=zhipu-account
|
|
900
|
+
// && mode=individual-coding-plan && accountType \u975E\u7A7A && builtinModelIds \u975E\u7A7A\uFF1B
|
|
901
|
+
// \u771F\u5B9E\u76EE\u5F55 10 \u6761\u547D\u4E2D\u3001\u4EC5 2 \u6761\u88AB individual \u5FEB\u7167\u6D88\u8D39\uFF09\uFF1A\u591A\u5199\u7684\u952E\u662F\u975E\u79D8\u5BC6\u5143\u6570\u636E\u3001
|
|
902
|
+
// \u7F3A\u65F6\u8FFD\u52A0\u6210\u672C\u2248\u96F6\uFF1B\u800C mode \u503C\u57DF\uFF08individual/team/start/off-peak/
|
|
903
|
+
// highspeed\uFF09\u8DE8 CLI \u7248\u672C\u4ECD\u5728\u6F14\u5316\uFF0C\u6309\u5F53\u524D\u7248\u672C\u6536\u7A84\u4F1A\u8BA9\u522B\u7684\u7248\u672C/\u672A\u6765\u6D88\u8D39\u9762
|
|
904
|
+
// \u9759\u9ED8\u7F3A\u952E\u3002\u5BBD\u5EA6\u662F\u6709\u610F\u7684\uFF0C\u4E0D\u6309 3.15.3 \u6536\u7A84\uFF082026-10 review\xB7S-5 \u6838\u5B9E\u540E\u4FDD\u7559\uFF09\u3002
|
|
905
|
+
.filter(function (r) { return r && r.config && r.config.access && r.config.access.type === 'zhipu-account'; })
|
|
906
|
+
.map(function (r) { return String(r.providerId || ''); })
|
|
907
|
+
.filter(Boolean);
|
|
908
|
+
} catch (e) {
|
|
909
|
+
// \u76EE\u5F55\u635F\u574F/\u4E0D\u53EF\u8BFB = identity/auth-source \u65E0\u6CD5\u4F9B\u7ED9\u7684\u771F\u56E0\uFF0C\u4E0D\u80FD\u9759\u9ED8\u8FD4\u56DE\uFF08\u5426\u5219
|
|
910
|
+
// standalone \u6D3E\u53D1\u62A5\u300CProvider Registry \u4E2D\u4E0D\u5B58\u5728 Model\u300D\u65F6\u6392\u969C\u65E0\u5165\u53E3\uFF09
|
|
911
|
+
process.stderr.write('[zcode-launcher] account metadata: builtin catalog unreadable (' + ((e && e.message) || String(e)) + ') - skipping account provider metadata\\n');
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
const added = [];
|
|
915
|
+
const reconciled = [];
|
|
916
|
+
for (const pid of planIds) {
|
|
917
|
+
const idKey = 'account-provider:' + pid + ':identity';
|
|
918
|
+
const srcKey = 'account-provider:' + pid + ':auth-source';
|
|
919
|
+
// host \u6001 plan api-key \u952E\u540D\u6A21\u677F\uFF1Aaccount-provider:coding-plan:<pid>:account:<identity>:api-key
|
|
920
|
+
const apiKeyPrefix = 'account-provider:coding-plan:' + pid + ':account:';
|
|
921
|
+
const apiKeySuffix = ':api-key';
|
|
922
|
+
const hasPlanApiKey = (id) => {
|
|
923
|
+
if (!id) return false;
|
|
924
|
+
return Boolean(creds[apiKeyPrefix + encodeURIComponent(id) + apiKeySuffix]);
|
|
925
|
+
};
|
|
926
|
+
let identity = typeof creds[idKey] === 'string' ? creds[idKey] : '';
|
|
927
|
+
const authSource = typeof creds[srcKey] === 'string' ? creds[srcKey] : '';
|
|
928
|
+
// \u6D3E\u751F\u8EAB\u4EFD\u6BCF\u6B21 spawn \u91CD\u7B97\uFF08\u4E0D\u8BFB\u65E2\u6709\u952E\uFF09\uFF1A\u5F53\u524D host \u6001\u952E\u540D\u9996\u547D\u4E2D\uFF08\u4FDD\u6301\u65E2\u6709\u4F18\u5148\u7EA7\uFF09\u3002
|
|
929
|
+
let derivedIdentity = '';
|
|
930
|
+
for (const k of Object.keys(creds)) {
|
|
931
|
+
if (k.indexOf(apiKeyPrefix) === 0 && k.slice(-apiKeySuffix.length) === apiKeySuffix) {
|
|
932
|
+
const mid = k.slice(apiKeyPrefix.length, k.length - apiKeySuffix.length);
|
|
933
|
+
if (mid) { try { derivedIdentity = decodeURIComponent(mid); } catch (e2) { derivedIdentity = mid; } break; }
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
// oauth \u5BB6\u65CF\u51ED\u636E\u5B58\u5728\u6027\uFF1A\u626B oauth:<family>:access_token\uFF0Cprovider id \u4EE5
|
|
937
|
+
// account:<family> \u5F00\u5934\u5373\u7ED1\u5B9A\u8BE5\u5BB6\u65CF\uFF08\u96F6\u5BB6\u65CF\u540D\u5199\u6B7B\uFF09\u3002
|
|
938
|
+
let oauthBacked = false;
|
|
939
|
+
const oauthPrefix = 'oauth:';
|
|
940
|
+
const oauthSuffix = ':access_token';
|
|
941
|
+
for (const k of Object.keys(creds)) {
|
|
942
|
+
if (k.indexOf(oauthPrefix) !== 0 || k.slice(-oauthSuffix.length) !== oauthSuffix) continue;
|
|
943
|
+
const fam = k.slice(oauthPrefix.length, k.length - oauthSuffix.length);
|
|
944
|
+
if (!fam) continue;
|
|
945
|
+
const token = creds[k];
|
|
946
|
+
if (typeof token !== 'string' || token === '') continue;
|
|
947
|
+
if (pid.indexOf('account:' + fam) === 0) { oauthBacked = true; break; }
|
|
948
|
+
}
|
|
949
|
+
// \u2460 \u8EAB\u4EFD\u5B64\u513F\u77EB\u6B63\uFF1A\u65E2\u6709\u975E\u7A7A\u8EAB\u4EFD\u662F\u6743\u5A01\u5199\u5165\uFF0C\u4F46\u53EA\u5728\u300C\u8BA4\u8BC1\u5F62\u6001\u8981\u6C42\u8EAB\u4EFD\u5BF9\u5E94 plan
|
|
950
|
+
// api-key\u300D\u65F6\u5224\u5B9A\u5B64\u513F\u2014\u2014oauth \u5F62\u6001\u4E0B\u8EAB\u4EFD\u4E0D\u53C2\u4E0E\u51ED\u636E\u67E5\u627E\uFF08CLI \u767B\u5F55\u5199\u5165\u7684\u8EAB\u4EFD
|
|
951
|
+
// \u53EF\u80FD\u6C38\u65E0 api-key\uFF09\uFF0C\u4E0D\u5F97\u7528\u6B8B\u7559\u952E\u540D\u8986\u5199\u3002\u5B64\u513F = \u65E0\u5BF9\u5E94 api-key \u4E14\u5F53\u524D\u53EF\u6D3E\u751F
|
|
952
|
+
// \u2192 \u6539\u6210\u5F53\u524D\u8EAB\u4EFD\uFF08\u5426\u5219 manual \u67E5\u65E7\u8EAB\u4EFD\u51ED\u636E\u6052\u5931\u8D25\u3001\u6C38\u4E0D\u6536\u655B\uFF09\u3002\u65E5\u5FD7\u5728\u843D\u5E93
|
|
953
|
+
// \u70B9\u53D1\uFF08\u65E0\u53EF\u7528 auth-source \u65F6 continue\uFF0C\u4E0D\u5F97\u7559\u4E0B\u201C\u5DF2\u77EB\u6B63\u201D\u800C\u672A\u5199\u76D8\u7684\u5047\u65E5\u5FD7\uFF09\u3002
|
|
954
|
+
let identityCorrectedFrom = '';
|
|
955
|
+
if (identity && !hasPlanApiKey(identity) && (authSource === 'manual' || !oauthBacked)
|
|
956
|
+
&& derivedIdentity && derivedIdentity !== identity) {
|
|
957
|
+
identityCorrectedFrom = identity;
|
|
958
|
+
identity = derivedIdentity;
|
|
959
|
+
}
|
|
960
|
+
if (!identity) identity = derivedIdentity;
|
|
961
|
+
if (!identity) continue;
|
|
962
|
+
// \u2461 auth-source \u6D3E\u751F + \u5B64\u513F\u77EB\u6B63\uFF1Aoauth \u9700\u5339\u914D\u5BB6\u65CF\u7684 access_token\uFF1Bmanual \u9700\u8BE5
|
|
963
|
+
// \u8EAB\u4EFD\u540D\u4E0B\u7684 plan api-key\u3002\u65E2\u6709\u503C\u4E0E\u5F53\u524D\u4E8B\u5B9E\u4E00\u81F4\u65F6\u539F\u6837\u4FDD\u7559\uFF08GUI/\u767B\u5F55\u5199\u5165\u7684
|
|
964
|
+
// manual \u5728 oauth \u540C\u65F6\u5B58\u5728\u65F6\u4ECD\u662F\u6743\u5A01\u2014\u2014\u66FE\u65E0\u5DEE\u522B\u8986\u5199\u5DEE\u5F02\u503C\uFF09\u3002
|
|
965
|
+
const derivedAuthSource = oauthBacked ? 'oauth' : (hasPlanApiKey(identity) ? 'manual' : '');
|
|
966
|
+
let nextAuthSource = authSource || derivedAuthSource;
|
|
967
|
+
if (authSource === 'oauth' && !oauthBacked) nextAuthSource = derivedAuthSource;
|
|
968
|
+
else if (authSource === 'manual' && !hasPlanApiKey(identity)) nextAuthSource = derivedAuthSource;
|
|
969
|
+
if (!nextAuthSource) continue;
|
|
970
|
+
// \u843D\u5E93\u5224\u5B9A\uFF1A\u7F3A\u5931\u6001\uFF08\u7A7A\u4E32/\u975E\u4E32\uFF09\u8BB0 provisioned\uFF0C\u975E\u7A7A\u65E7\u503C\u88AB\u77EB\u6B63\u8BB0 reconciled\u3002
|
|
971
|
+
if (creds[idKey] !== identity) {
|
|
972
|
+
if (identityCorrectedFrom) {
|
|
973
|
+
reconciled.push(idKey + ' (' + identityCorrectedFrom + ' -> ' + identity + ')');
|
|
974
|
+
} else if (typeof creds[idKey] !== 'string' || creds[idKey] === '') {
|
|
975
|
+
added.push(idKey);
|
|
976
|
+
}
|
|
977
|
+
creds[idKey] = identity;
|
|
978
|
+
}
|
|
979
|
+
if (creds[srcKey] !== nextAuthSource) {
|
|
980
|
+
if (typeof creds[srcKey] === 'string' && creds[srcKey] !== '') {
|
|
981
|
+
reconciled.push(srcKey + ' (' + creds[srcKey] + ' -> ' + nextAuthSource + ')');
|
|
982
|
+
} else added.push(srcKey);
|
|
983
|
+
creds[srcKey] = nextAuthSource;
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
if (added.length === 0 && reconciled.length === 0) return;
|
|
987
|
+
const tmp = credPath + '.taiji-tmp-' + process.pid;
|
|
988
|
+
// rename \u6362 inode\u2014\u2014tmp \u4E0D\u5E26 mode \u843D\u76D8\u4F1A\u628A GUI \u4FA7\u6536\u7D27\u8FC7\u7684\u6587\u4EF6\u6743\u9650\u9759\u9ED8\u653E\u5BBD\u4E3A
|
|
989
|
+
// \u7F3A\u7701 umask \u503C\uFF0C\u5199\u524D\u8BFB\u65E2\u6709 mode \u968F\u5199\u4F20\u9012\uFF08stat \u5931\u8D25\u56DE\u9000 0600\uFF09\uFF1B\u5199/rename
|
|
990
|
+
// \u5931\u8D25\u6E05\u7406 tmp\uFF0C\u4E0D\u5728\u7528\u6237\u51ED\u636E\u76EE\u5F55\u7559\u6B8B\u7247\u3002
|
|
991
|
+
let writeMode = 0o600;
|
|
992
|
+
try { writeMode = fs.statSync(credPath).mode & 0o777; } catch { /* \u7F3A\u7701 0600 */ }
|
|
993
|
+
try {
|
|
994
|
+
fs.writeFileSync(tmp, JSON.stringify(creds, null, 2), { mode: writeMode });
|
|
995
|
+
fs.renameSync(tmp, credPath);
|
|
996
|
+
} catch (err) {
|
|
997
|
+
try { fs.unlinkSync(tmp); } catch { /* tmp \u672A\u751F\u6210\u6216\u5DF2 rename */ }
|
|
998
|
+
throw err;
|
|
999
|
+
}
|
|
1000
|
+
if (added.length > 0) process.stderr.write('[zcode-launcher] account metadata provisioned: ' + added.join(', ') + '\\n');
|
|
1001
|
+
if (reconciled.length > 0) process.stderr.write('[zcode-launcher] account metadata reconciled: ' + reconciled.join(', ') + '\\n');
|
|
1002
|
+
} catch (err) {
|
|
1003
|
+
process.stderr.write('[zcode-launcher] account metadata provisioning failed (non-blocking): ' + ((err && err.message) || String(err)) + '\\n');
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
`;
|
|
1007
|
+
|
|
510
1008
|
// src/appserver-launcher.ts
|
|
511
1009
|
var ZCODE_APPSERVER_LAUNCHER_NAME = "appserver-launcher.cjs";
|
|
512
1010
|
var APPSERVER_LAUNCHER_SOURCE = `'use strict';
|
|
@@ -733,40 +1231,7 @@ function catalogPatchText(path) {
|
|
|
733
1231
|
return result;
|
|
734
1232
|
}
|
|
735
1233
|
|
|
736
|
-
|
|
737
|
-
// \u786C\u7F16\u7801 entitled:!1\uFF08YXe\uFF09\uFF0C\u6570\u636E\u9762\u6CE8\u5165\uFF08\u76EE\u5F55 entitled \u5B57\u6BB5\uFF09\u88AB\u5176\u65E0\u89C6\u2014\u2014\u6309\u7528\u6237\u88C1\u51B3
|
|
738
|
-
// \u6539 zcode \u6E90\u7801\u7ED5\u8FC7\uFF1A\u62E6\u622A CLI bundle \u6E90\u7801\u8BFB\u53D6\uFF0C\u5185\u5B58\u66FF\u6362\u8BE5\u5B57\u9762\u91CF\u4E3A !0\uFF08ZCode.app
|
|
739
|
-
// \u78C1\u76D8\u6587\u4EF6\u96F6\u89E6\u78B0\uFF1B\u951A\u4E32\u542B ]]:[] \u5C3E\u7F00\u552F\u4E00\u547D\u4E2D YXe \u6784\u9020\uFF0C\u53E6\u4E00\u5904\u540C\u540D\u6761\u4EF6\u903B\u8F91\u4E0D\u53D7\u5F71\u54CD\uFF09\u3002
|
|
740
|
-
// \u951A\u4E0D\u547D\u4E2D\uFF08\u4E0A\u6E38\u6DF7\u6DC6\u5F62\u6001\u53D8\u5316\uFF09\u2192 \u539F\u6587\u900F\u51FA\uFF1A\u4EC5 account \u5BB6\u65CF\u7EE7\u7EED\u88AB\u62D2\uFF0C\u4E2A\u4EBA provider
|
|
741
|
-
// \u4E0D\u53D7\u5F71\u54CD\u3002
|
|
742
|
-
const __cliPatchCache = new Map();
|
|
743
|
-
function patchedCliSource(path) {
|
|
744
|
-
if (__cliPatchCache.has(path)) return __cliPatchCache.get(path);
|
|
745
|
-
let result = null;
|
|
746
|
-
try {
|
|
747
|
-
const readOrig = fs.__origReadFileSync || fs.readFileSync;
|
|
748
|
-
const src = readOrig(path, 'utf8');
|
|
749
|
-
// \u7248\u672C\u9C81\u68D2\u951A\uFF082026-10-13 \u4FEE\u8BA2\uFF09\uFF1Aminified \u6807\u8BC6\u7B26\uFF08Uk/I3 \u7B49\uFF09\u968F zcode \u91CD\u65B0\u6253\u5305
|
|
750
|
-
// \u6F02\u79FB\uFF0C\u5C5E\u6027\u540D\uFF08zcodeBuiltinProviders / zhipu-account / entitled\uFF09\u662F\u6570\u636E/\u5951\u7EA6
|
|
751
|
-
// \u771F\u540D\u4E0D\u88AB\u6DF7\u6DC6\u2014\u2014\u4EE5\u5C5E\u6027\u540D\u5B9A\u4F4D + 600 \u5B57\u7B26\u7A97\u53E3\u5185\u628A\u8D26\u53F7\u6761\u76EE\u6784\u5EFA\u7684 entitled:!1
|
|
752
|
-
// \u7FFB\u8F6C\u4E3A !0\u3002\u7A97\u53E3\u96F6\u547D\u4E2D = \u4E0A\u6E38\u5F62\u6001\u6F02\u79FB \u2192 \u539F\u6587\u900F\u51FA + stderr warn\uFF08\u6F02\u79FB\u53EF\u89C1\uFF0C
|
|
753
|
-
// \u8FDB app-server stderr \u65E5\u5FD7\uFF09\uFF0C\u4E2A\u4EBA provider \u4E0D\u53D7\u5F71\u54CD\u3002
|
|
754
|
-
const anchorIdx = src.indexOf('zcodeBuiltinProviders.entries()');
|
|
755
|
-
if (anchorIdx >= 0) {
|
|
756
|
-
const window = src.slice(anchorIdx, Math.min(src.length, anchorIdx + 600));
|
|
757
|
-
if (window.indexOf('zhipu-account') >= 0 && window.indexOf('entitled:!1') >= 0) {
|
|
758
|
-
result = src.slice(0, anchorIdx)
|
|
759
|
-
+ window.split('entitled:!1').join('entitled:!0')
|
|
760
|
-
+ src.slice(anchorIdx + 600);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
if (result === null) {
|
|
764
|
-
process.stderr.write('[zcode-launcher] account bypass: CLI bundle anchor not found (zcode upstream shape drifted?) - account family stays gated, personal providers unaffected\\n');
|
|
765
|
-
}
|
|
766
|
-
} catch { result = null; }
|
|
767
|
-
__cliPatchCache.set(path, result);
|
|
768
|
-
return result;
|
|
769
|
-
}
|
|
1234
|
+
${CLI_PATCH_SECTION}
|
|
770
1235
|
|
|
771
1236
|
// \u5185\u5EFA provider \u914D\u7F6E\u5B9A\u4F4D\uFF08\u6F02\u79FB\u9762\u2461\uFF09\uFF1A3.12.x \u8D77\u914D\u7F6E\u6587\u4EF6\u632A\u4F4D + CLI \u4F9D\u8D56\u5BBF\u4E3B\u6CE8\u5165
|
|
772
1237
|
// ZCODE_BUILTIN_PROVIDER_CONFIG_FILE \u76F4\u63A5\u5B9A\u4F4D\uFF1BZCode \u684C\u9762 spawn \u94FE\u81EA\u5E26\u8BE5\u952E\uFF0C
|
|
@@ -840,15 +1305,32 @@ if (!process.env.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE) {
|
|
|
840
1305
|
}
|
|
841
1306
|
}
|
|
842
1307
|
|
|
1308
|
+
${ACCOUNT_METADATA_SECTION}
|
|
1309
|
+
|
|
843
1310
|
// \u5B89\u88C5\u95E8\uFF1A\u4EFB\u4E00 patch \u6E90\u53EF\u7528\u5373\u5B89\u88C5\u62E6\u622A\u5C42\uFF1B\u51B3\u7B56\u4E24\u6001\u90FD\u51FA\u58F0\uFF08\u88C5\u4E86\u54EA\u4E9B patch / \u4E3A\u4F55
|
|
844
1311
|
// \u8DF3\u8FC7\uFF09\u2014\u2014\u8865\u4E01\u5C42\u7684\u5931\u6548\u5F62\u6001\u662F\u9759\u9ED8\u7684\uFF08account \u76F4\u901A\u5931\u6548 = plan \u5BB6\u65CF\u62A5\u300C\u4E0D\u5B58\u5728
|
|
845
1312
|
// Model\u300D\u800C\u65E0\u4EFB\u4F55\u65E5\u5FD7\uFF09\uFF0C\u8DF3\u8FC7\u540C\u6837\u5FC5\u987B\u7559\u75D5\u3002
|
|
846
1313
|
const text = injectedConfigText();
|
|
847
1314
|
const catalogPatch = CATALOG_PATH !== null ? catalogPatchText(CATALOG_PATH) : null;
|
|
848
|
-
|
|
1315
|
+
const cliPatchProbe = CLI_PATH ? patchedCliSource(CLI_PATH) : null;
|
|
1316
|
+
// \u4E09\u5904\u6539\u5199\u7684\u5E94\u7528\u6001\u7531 patchedCliSource \u53D1\u5E03\uFF08__cliPatchStatus\uFF09\u2014\u2014\u66FE\u4EE5\u4EA7\u7269\u5B50\u4E32\u5224\u5B9A\uFF1A
|
|
1317
|
+
// header-port \u5728\u672A\u6253\u8865\u4E01\u7684 3.15.3 bundle \u4E0A\u6052\u771F\uFF088 \u5904\u65E2\u6709\u540C\u540D\u5C5E\u6027\uFF09\u2192 \u95E8\u5BF9\u951A\u70B9
|
|
1318
|
+
// \u6F02\u79FB\u96F6\u68C0\u6D4B\u529B\uFF1Bstandalone \u540C\u7406\u7531\u6807\u5FD7\u9A71\u52A8\uFF08\u4E09\u5904\u5224\u5B9A\u5404\u81EA\u5177\u540D\uFF09\u3002cli-source-bypass
|
|
1319
|
+
// \u7684\u62EC\u53F7\u540E\u7F00\u628A\u4E09\u951A\u9010\u4E00\u5217\u51FA\uFF082026-10 review\xB7S-2\uFF09\uFF1Aentitled \u6807\u5FD7\u66FE\u53D1\u5E03\u4F46\u65E0\u6D88\u8D39\u65B9\uFF0C
|
|
1320
|
+
// \u8BE5\u951A\u5355\u72EC\u6F02\u79FB\u65F6\u516D\u9879\u77E9\u9635\u4F1A\u5168\u90E8 armed\u2014\u2014\u9010\u951A\u53EF\u89C1\u624D\u80FD\u5B9A\u4F4D\u6F02\u79FB\uFF08\u516D\u9879\u53E3\u5F84\u4E0D\u53D8\uFF09\u3002
|
|
1321
|
+
const cliPatchStatus = CLI_PATH ? __cliPatchStatus.get(CLI_PATH) : null;
|
|
1322
|
+
const anchorFlags = cliPatchStatus
|
|
1323
|
+
? '(entitled=' + (cliPatchStatus.entitled ? 'on' : 'off')
|
|
1324
|
+
+ ',standalone=' + (cliPatchStatus.standalone ? 'on' : 'off')
|
|
1325
|
+
+ ',port=' + (cliPatchStatus.headerPort ? 'on' : 'off') + ')'
|
|
1326
|
+
: '';
|
|
1327
|
+
if (text !== null || catalogPatch !== null || cliPatchProbe !== null) {
|
|
849
1328
|
process.stderr.write('[zcode-launcher] \u8865\u4E01\u5C42\u5DF2\u5B89\u88C5: cli-config-inject=' + (text !== null ? 'on' : 'off')
|
|
850
1329
|
+ ', catalog-entitled=' + (catalogPatch !== null ? 'on' : 'off')
|
|
851
|
-
+ ', provider-merge=' + (PI_SYNCED_PATH ? 'armed' : 'off')
|
|
1330
|
+
+ ', provider-merge=' + (PI_SYNCED_PATH ? 'armed' : 'off')
|
|
1331
|
+
+ ', cli-source-bypass=' + (cliPatchProbe !== null ? 'armed' : 'off') + anchorFlags
|
|
1332
|
+
+ ', standalone-account=' + (cliPatchStatus && cliPatchStatus.standalone ? 'armed' : 'off')
|
|
1333
|
+
+ ', header-port=' + (cliPatchStatus && cliPatchStatus.headerPort ? 'armed' : 'off') + '\\n');
|
|
852
1334
|
// encoding \u5F52\u4E00\uFF08Node \u522B\u540D\u9762\uFF09\uFF1A'utf8'/'utf-8'/\u5927\u5C0F\u5199\u53D8\u4F53\u7EDF\u4E00\u6309 string \u8FD4\u56DE\u2014\u2014
|
|
853
1335
|
// \u771F\u5B9E bundle \u7684 config \u8BFB\u53D6\u6070\u7528 'utf-8' \u5F62\u6001\uFF0C\u4EC5\u5339\u914D 'utf8' \u4F1A\u9519\u56DE Buffer
|
|
854
1336
|
// \uFF08\u5F53\u4E0B\u6E38\u4E0D\u53EA JSON.parse \u800C\u505A\u5B57\u7B26\u4E32\u8FD0\u7B97\u65F6\u5373 TypeError\uFF09
|
|
@@ -862,6 +1344,11 @@ if (text !== null || catalogPatch !== null) {
|
|
|
862
1344
|
return Buffer.from(value);
|
|
863
1345
|
};
|
|
864
1346
|
fs.__origReadFileSync = fs.readFileSync;
|
|
1347
|
+
// standalone \u8D26\u53F7\u5143\u6570\u636E\u952E\u4F9B\u7ED9\uFF08ADR-0143\uFF09\uFF1A\u4EC5\u5F53 standalone \u4E0E header-port \u4E24\u951A
|
|
1348
|
+
// \u5747\u5DF2\u6B66\u88C5\u65F6\u6267\u884C\uFF082026-10 review\xB7S-3\uFF09\u2014\u2014\u53EA\u6B66\u88C5 standalone \u65F6\u8BA4\u8BC1\u5934\u4ECD\u56DE\u843D\u5BBF\u4E3B
|
|
1349
|
+
// \u8BF7\u6C42\u7AEF\u53E3\uFF08\u65E0\u5BBF\u4E3B\u4EFB\u5E94\u7B54 = \u8D26\u53F7\u94FE\u4ECD\u4E0D\u53EF\u7528\uFF09\uFF0C\u6B64\u65F6\u5199\u7528\u6237\u5171\u4EAB credentials.json
|
|
1350
|
+
// \u65E0\u8FD0\u884C\u65F6\u6536\u76CA\u3001\u53EA\u589E\u98CE\u9669\uFF1B\u6B64\u5904\u8BFB\u6E90\u4ECD\u662F\u539F\u751F fs\uFF08readFileSync \u62E6\u622A\u5C1A\u672A\u5B89\u88C5\uFF09\u3002
|
|
1351
|
+
if (cliPatchStatus && cliPatchStatus.standalone && cliPatchStatus.headerPort) ensureAccountMetadata();
|
|
865
1352
|
fs.readFileSync = function (p, ...rest) {
|
|
866
1353
|
if (typeof p === 'string' && p === CONFIG_PATH) {
|
|
867
1354
|
const cur = injectedConfigText();
|
|
@@ -2860,6 +3347,17 @@ var ZcodeEngine = class {
|
|
|
2860
3347
|
listModels() {
|
|
2861
3348
|
return listZcodeModels(this.deps.sources);
|
|
2862
3349
|
}
|
|
3350
|
+
/**
|
|
3351
|
+
* [engine-ref-translation D1] 派发期模型 ref 翻译(EnginePort 可选成员实装):
|
|
3352
|
+
* pi 词汇 ref → zcode 原生 ref(zai-coding-cn/* → account:bigmodel-individual-*
|
|
3353
|
+
* 大小写归一,2026-10-16 用户裁决(证据驱动修正目标家族)),其余透传。编排层在 record stamp 前调用——
|
|
3354
|
+
* record/上报面呈现实际发给引擎的 ref;翻译失败抛错 = 显式失败(不静默回落)。
|
|
3355
|
+
* 幂等:翻译产物(account:/个人 id)再入恒等,引擎内 resolveZcodeModelRef 的
|
|
3356
|
+
* 同名翻译分支零冲突。
|
|
3357
|
+
*/
|
|
3358
|
+
translateModelRef(modelRef) {
|
|
3359
|
+
return translatePiModelRefToZcode(modelRef, this.deps.sources);
|
|
3360
|
+
}
|
|
2863
3361
|
/** 模型 reasoning 值域缓存(目录 modelRules 值域;per-modelRef 记忆化——
|
|
2864
3362
|
* 目录文件在引擎进程生命周期内视为静态,重复 run 不重读)。 */
|
|
2865
3363
|
reasoningMemo = /* @__PURE__ */ new Map();
|
|
@@ -2969,13 +3467,17 @@ var ZcodeEngine = class {
|
|
|
2969
3467
|
* COMMON_THOUGHT_LEVELS 之外的档位出声一行提示(措辞是「若不支持将被忽略/回落」的
|
|
2970
3468
|
* 或然警告,非无效断言);是否真不支持由目标模型决定,core 不做权威校验(引擎层
|
|
2971
3469
|
* 不掌握各模型值域)。
|
|
3470
|
+
*
|
|
3471
|
+
* [2026-10-14 措辞同步] thoughtLevel 下发值已改为「按目录值域解析后的档位」
|
|
3472
|
+
* (reasoning 唯一生效通道,见 buildAppServerCreateParams 头注):有值域时
|
|
3473
|
+
* off/minimal 归一最小档、非命中档取非最小档末值;无值域时维持恒等透传。
|
|
2972
3474
|
*/
|
|
2973
3475
|
warnThoughtLevelUncommon(task, ctx) {
|
|
2974
3476
|
const thoughtLevel = task.thinkingLevel?.trim();
|
|
2975
3477
|
if (thoughtLevel === void 0 || thoughtLevel === "") return;
|
|
2976
3478
|
if (COMMON_THOUGHT_LEVELS.includes(thoughtLevel)) return;
|
|
2977
3479
|
logger4.warn(
|
|
2978
|
-
`[zcode-engine] thinkingLevel=${thoughtLevel} \
|
|
3480
|
+
`[zcode-engine] thinkingLevel=${thoughtLevel}\uFF08\u975E\u5E38\u89C1\u6863\u4F4D\uFF09\u2192 \u6309\u6A21\u578B reasoning \u503C\u57DF\u89E3\u6790\u540E\u4E0B\u53D1 thoughtLevel\uFF08\u65E0\u503C\u57DF\u65F6\u6052\u7B49\u900F\u4F20\uFF1Boff/minimal \u5F52\u4E00\u6700\u5C0F\u6863\uFF0C\u975E\u547D\u4E2D\u6863\u53D6\u975E\u6700\u5C0F\u6863\u672B\u503C\uFF1B\u82E5\u76EE\u6807\u6A21\u578B\u4E0D\u652F\u6301\u5C06\u88AB\u5FFD\u7565/\u56DE\u843D\u5230\u6A21\u578B\u7F3A\u7701\u63A8\u7406\u6863\u4F4D\uFF0C\u5E38\u89C1\u6863\u4F4D\uFF1A${COMMON_THOUGHT_LEVELS.join("/")}\uFF09`,
|
|
2979
3481
|
{ taskId: ctx.taskId }
|
|
2980
3482
|
);
|
|
2981
3483
|
}
|
|
@@ -3165,7 +3667,7 @@ Answer again. Output ONLY the JSON value conforming to the schema above \u2014 n
|
|
|
3165
3667
|
}
|
|
3166
3668
|
function buildAppServerCreateParams(task, modelRef, cwd, reasoningLevel) {
|
|
3167
3669
|
const denyTools = (task.denyTools ?? []).filter((t) => typeof t === "string" && t.trim() !== "");
|
|
3168
|
-
const thoughtLevel = task.thinkingLevel?.trim();
|
|
3670
|
+
const thoughtLevel = reasoningLevel !== void 0 && reasoningLevel !== "" ? reasoningLevel : task.thinkingLevel?.trim();
|
|
3169
3671
|
const model = modelRef !== void 0 && modelRef !== "" ? {
|
|
3170
3672
|
...splitZcodeModelRef(modelRef),
|
|
3171
3673
|
...reasoningLevel !== void 0 && reasoningLevel !== "" ? { options: { reasoningLevel } } : {}
|