@autopilot-agent/adapters 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +417 -208
- package/dist/index.mjs +368 -168
- package/dist/node/desktop-status-protocol.d.ts +62 -0
- package/dist/node/file-utils.d.ts +3 -0
- package/dist/node/node-errors.d.ts +2 -0
- package/dist/node/runtime-owner.d.ts +1 -0
- package/dist/node/settings/node-user-settings-service.d.ts +11 -1
- package/dist/node/thread-runner.d.ts +4 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -34,9 +34,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
));
|
|
35
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
36
|
|
|
37
|
-
// node_modules/boolbase/index.js
|
|
37
|
+
// ../../node_modules/boolbase/index.js
|
|
38
38
|
var require_boolbase = __commonJS({
|
|
39
|
-
"node_modules/boolbase/index.js"(exports2, module2) {
|
|
39
|
+
"../../node_modules/boolbase/index.js"(exports2, module2) {
|
|
40
40
|
module2.exports = {
|
|
41
41
|
trueFunc: function trueFunc() {
|
|
42
42
|
return true;
|
|
@@ -48,9 +48,9 @@ var require_boolbase = __commonJS({
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
// node_modules/css-what/lib/commonjs/types.js
|
|
51
|
+
// ../../node_modules/css-what/lib/commonjs/types.js
|
|
52
52
|
var require_types = __commonJS({
|
|
53
|
-
"node_modules/css-what/lib/commonjs/types.js"(exports2) {
|
|
53
|
+
"../../node_modules/css-what/lib/commonjs/types.js"(exports2) {
|
|
54
54
|
"use strict";
|
|
55
55
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
56
56
|
exports2.AttributeAction = exports2.IgnoreCaseMode = exports2.SelectorType = void 0;
|
|
@@ -88,9 +88,9 @@ var require_types = __commonJS({
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
// node_modules/css-what/lib/commonjs/parse.js
|
|
91
|
+
// ../../node_modules/css-what/lib/commonjs/parse.js
|
|
92
92
|
var require_parse = __commonJS({
|
|
93
|
-
"node_modules/css-what/lib/commonjs/parse.js"(exports2) {
|
|
93
|
+
"../../node_modules/css-what/lib/commonjs/parse.js"(exports2) {
|
|
94
94
|
"use strict";
|
|
95
95
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
96
96
|
exports2.parse = exports2.isTraversal = void 0;
|
|
@@ -443,9 +443,9 @@ var require_parse = __commonJS({
|
|
|
443
443
|
}
|
|
444
444
|
});
|
|
445
445
|
|
|
446
|
-
// node_modules/css-what/lib/commonjs/stringify.js
|
|
446
|
+
// ../../node_modules/css-what/lib/commonjs/stringify.js
|
|
447
447
|
var require_stringify = __commonJS({
|
|
448
|
-
"node_modules/css-what/lib/commonjs/stringify.js"(exports2) {
|
|
448
|
+
"../../node_modules/css-what/lib/commonjs/stringify.js"(exports2) {
|
|
449
449
|
"use strict";
|
|
450
450
|
var __spreadArray = exports2 && exports2.__spreadArray || function(to, from, pack) {
|
|
451
451
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
@@ -567,9 +567,9 @@ var require_stringify = __commonJS({
|
|
|
567
567
|
}
|
|
568
568
|
});
|
|
569
569
|
|
|
570
|
-
// node_modules/css-what/lib/commonjs/index.js
|
|
570
|
+
// ../../node_modules/css-what/lib/commonjs/index.js
|
|
571
571
|
var require_commonjs = __commonJS({
|
|
572
|
-
"node_modules/css-what/lib/commonjs/index.js"(exports2) {
|
|
572
|
+
"../../node_modules/css-what/lib/commonjs/index.js"(exports2) {
|
|
573
573
|
"use strict";
|
|
574
574
|
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
575
575
|
if (k2 === void 0) k2 = k;
|
|
@@ -2139,6 +2139,10 @@ __export(index_exports, {
|
|
|
2139
2139
|
DEFAULT_COMPACT_TARGET_RATIO: () => DEFAULT_COMPACT_TARGET_RATIO,
|
|
2140
2140
|
DEFAULT_COMPACT_TRIGGER_RATIO: () => DEFAULT_COMPACT_TRIGGER_RATIO,
|
|
2141
2141
|
DEFAULT_CONTEXT_WINDOW_TOKENS: () => DEFAULT_CONTEXT_WINDOW_TOKENS,
|
|
2142
|
+
DESKTOP_STATUS_FRAME_BYTES: () => DESKTOP_STATUS_FRAME_BYTES,
|
|
2143
|
+
DESKTOP_STATUS_QUEUE_BYTES: () => DESKTOP_STATUS_QUEUE_BYTES,
|
|
2144
|
+
DESKTOP_STATUS_VERSION: () => DESKTOP_STATUS_VERSION,
|
|
2145
|
+
DesktopStatusLines: () => DesktopStatusLines,
|
|
2142
2146
|
LOCAL_HUMAN_PRINCIPAL_ID: () => LOCAL_HUMAN_PRINCIPAL_ID,
|
|
2143
2147
|
NODE_CHAT_KNOWLEDGE_SPACE_ID: () => NODE_CHAT_KNOWLEDGE_SPACE_ID,
|
|
2144
2148
|
NODE_STATE_SCHEMA_VERSION: () => NODE_STATE_SCHEMA_VERSION,
|
|
@@ -2201,6 +2205,10 @@ __export(index_exports, {
|
|
|
2201
2205
|
getNodeStatePaths: () => getNodeStatePaths,
|
|
2202
2206
|
getNodeStateSchemaDiagnostic: () => getNodeStateSchemaDiagnostic,
|
|
2203
2207
|
initializeNodeStateRoot: () => initializeNodeStateRoot,
|
|
2208
|
+
isDesktopSessionStatus: () => isDesktopSessionStatus,
|
|
2209
|
+
isDesktopStatusFrame: () => isDesktopStatusFrame,
|
|
2210
|
+
isDesktopStatusId: () => isDesktopStatusId,
|
|
2211
|
+
isDesktopStatusReply: () => isDesktopStatusReply,
|
|
2204
2212
|
isSafeSettingsFile: () => isSafeSettingsFile,
|
|
2205
2213
|
loadMcpConfigFromWorkspace: () => loadMcpConfigFromWorkspace,
|
|
2206
2214
|
resolveNodeChatStatePaths: () => resolveNodeChatStatePaths,
|
|
@@ -2210,7 +2218,8 @@ __export(index_exports, {
|
|
|
2210
2218
|
resolveNodeTrustRoot: () => resolveNodeTrustRoot,
|
|
2211
2219
|
resolveNodeUserSettingsPath: () => resolveNodeUserSettingsPath,
|
|
2212
2220
|
retrieveNodeMemories: () => retrieveNodeMemories,
|
|
2213
|
-
serializePosixCommand: () => serializePosixCommand
|
|
2221
|
+
serializePosixCommand: () => serializePosixCommand,
|
|
2222
|
+
withNodeRuntimeOwner: () => withNodeRuntimeOwner
|
|
2214
2223
|
});
|
|
2215
2224
|
module.exports = __toCommonJS(index_exports);
|
|
2216
2225
|
|
|
@@ -5500,12 +5509,12 @@ function parseSkillFrontmatter(frontmatter) {
|
|
|
5500
5509
|
return void 0;
|
|
5501
5510
|
}
|
|
5502
5511
|
}
|
|
5503
|
-
function readSkillString(
|
|
5504
|
-
const value =
|
|
5512
|
+
function readSkillString(fields2, key2) {
|
|
5513
|
+
const value = fields2[key2];
|
|
5505
5514
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
5506
5515
|
}
|
|
5507
|
-
function readSkillBoolean(
|
|
5508
|
-
const value =
|
|
5516
|
+
function readSkillBoolean(fields2, key2) {
|
|
5517
|
+
const value = fields2[key2];
|
|
5509
5518
|
if (typeof value === "boolean") return value;
|
|
5510
5519
|
if (typeof value !== "string") return void 0;
|
|
5511
5520
|
const normalized = value.trim().toLocaleLowerCase();
|
|
@@ -5513,8 +5522,8 @@ function readSkillBoolean(fields, key2) {
|
|
|
5513
5522
|
if (["false", "no", "off", "0"].includes(normalized)) return false;
|
|
5514
5523
|
return void 0;
|
|
5515
5524
|
}
|
|
5516
|
-
function readSkillTools(
|
|
5517
|
-
const value =
|
|
5525
|
+
function readSkillTools(fields2) {
|
|
5526
|
+
const value = fields2["allowed-tools"];
|
|
5518
5527
|
if (Array.isArray(value) && value.every(function isToolName(item) {
|
|
5519
5528
|
return typeof item === "string" && item.trim();
|
|
5520
5529
|
})) {
|
|
@@ -5528,9 +5537,9 @@ function readSkillTools(fields) {
|
|
|
5528
5537
|
return item.trim();
|
|
5529
5538
|
}).filter(Boolean);
|
|
5530
5539
|
}
|
|
5531
|
-
function readSkillDescription(
|
|
5532
|
-
const explicit = readSkillString(
|
|
5533
|
-
const whenToUse = readSkillString(
|
|
5540
|
+
function readSkillDescription(fields2, markdown) {
|
|
5541
|
+
const explicit = readSkillString(fields2, "description");
|
|
5542
|
+
const whenToUse = readSkillString(fields2, "when_to_use") ?? readSkillString(fields2, "when-to-use");
|
|
5534
5543
|
const description = explicit ?? markdown.trim().split(/\r?\n\s*\r?\n/u).find(function firstParagraph(paragraph) {
|
|
5535
5544
|
return paragraph.trim();
|
|
5536
5545
|
})?.trim();
|
|
@@ -5552,18 +5561,18 @@ function parseSkill(filePath, source, root) {
|
|
|
5552
5561
|
const content = import_node_fs3.default.readFileSync(filePath, "utf8");
|
|
5553
5562
|
const match = /^---\r?\n([\s\S]{0,4096}?)\r?\n---\r?\n/.exec(content);
|
|
5554
5563
|
if (!match) return void 0;
|
|
5555
|
-
const
|
|
5556
|
-
if (!
|
|
5564
|
+
const fields2 = parseSkillFrontmatter(match[1]);
|
|
5565
|
+
if (!fields2) return void 0;
|
|
5557
5566
|
const name = import_node_path3.default.basename(import_node_path3.default.dirname(filePath));
|
|
5558
|
-
const description = readSkillDescription(
|
|
5567
|
+
const description = readSkillDescription(fields2, content.slice(match[0].length));
|
|
5559
5568
|
if (!/^[a-z0-9-]{1,64}$/.test(name) || !description) return void 0;
|
|
5560
|
-
const declaredName = readSkillString(
|
|
5569
|
+
const declaredName = readSkillString(fields2, "name");
|
|
5561
5570
|
const displayName = declaredName && declaredName.length <= 64 ? declaredName : name;
|
|
5562
|
-
const modelInvocable = !(readSkillBoolean(
|
|
5563
|
-
const userInvocable = readSkillBoolean(
|
|
5564
|
-
const argumentHint = readSkillString(
|
|
5565
|
-
const whenToUse = readSkillString(
|
|
5566
|
-
const allowedTools = readSkillTools(
|
|
5571
|
+
const modelInvocable = !(readSkillBoolean(fields2, "disable-model-invocation") ?? false);
|
|
5572
|
+
const userInvocable = readSkillBoolean(fields2, "user-invocable") ?? true;
|
|
5573
|
+
const argumentHint = readSkillString(fields2, "argument-hint") ?? readSkillString(fields2, "dash-hint");
|
|
5574
|
+
const whenToUse = readSkillString(fields2, "when_to_use") ?? readSkillString(fields2, "when-to-use");
|
|
5575
|
+
const allowedTools = readSkillTools(fields2);
|
|
5567
5576
|
const canonical = import_node_fs3.default.realpathSync.native(filePath);
|
|
5568
5577
|
const contentHash = import_node_crypto2.default.createHash("sha256").update(content).digest("hex");
|
|
5569
5578
|
const skillId = `${source}:${import_node_crypto2.default.createHash("sha256").update(canonical).digest("hex").slice(0, 16)}:${contentHash.slice(0, 16)}`;
|
|
@@ -8021,7 +8030,7 @@ var Parser = class {
|
|
|
8021
8030
|
}
|
|
8022
8031
|
};
|
|
8023
8032
|
|
|
8024
|
-
// ../../node_modules/
|
|
8033
|
+
// ../../node_modules/domelementtype/lib/esm/index.js
|
|
8025
8034
|
var esm_exports = {};
|
|
8026
8035
|
__export(esm_exports, {
|
|
8027
8036
|
CDATA: () => CDATA,
|
|
@@ -8037,16 +8046,16 @@ __export(esm_exports, {
|
|
|
8037
8046
|
isTag: () => isTag
|
|
8038
8047
|
});
|
|
8039
8048
|
var ElementType;
|
|
8040
|
-
(function(
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8049
|
+
(function(ElementType2) {
|
|
8050
|
+
ElementType2["Root"] = "root";
|
|
8051
|
+
ElementType2["Text"] = "text";
|
|
8052
|
+
ElementType2["Directive"] = "directive";
|
|
8053
|
+
ElementType2["Comment"] = "comment";
|
|
8054
|
+
ElementType2["Script"] = "script";
|
|
8055
|
+
ElementType2["Style"] = "style";
|
|
8056
|
+
ElementType2["Tag"] = "tag";
|
|
8057
|
+
ElementType2["CDATA"] = "cdata";
|
|
8058
|
+
ElementType2["Doctype"] = "doctype";
|
|
8050
8059
|
})(ElementType || (ElementType = {}));
|
|
8051
8060
|
function isTag(elem) {
|
|
8052
8061
|
return elem.type === ElementType.Tag || elem.type === ElementType.Script || elem.type === ElementType.Style;
|
|
@@ -11019,8 +11028,8 @@ var Comment3 = class _Comment extends CharacterData {
|
|
|
11019
11028
|
};
|
|
11020
11029
|
|
|
11021
11030
|
// node_modules/domutils/lib/esm/index.js
|
|
11022
|
-
var
|
|
11023
|
-
__export(
|
|
11031
|
+
var esm_exports4 = {};
|
|
11032
|
+
__export(esm_exports4, {
|
|
11024
11033
|
DocumentPosition: () => DocumentPosition2,
|
|
11025
11034
|
append: () => append3,
|
|
11026
11035
|
appendChild: () => appendChild2,
|
|
@@ -11051,7 +11060,7 @@ __export(esm_exports5, {
|
|
|
11051
11060
|
isCDATA: () => isCDATA2,
|
|
11052
11061
|
isComment: () => isComment2,
|
|
11053
11062
|
isDocument: () => isDocument2,
|
|
11054
|
-
isTag: () =>
|
|
11063
|
+
isTag: () => isTag3,
|
|
11055
11064
|
isText: () => isText2,
|
|
11056
11065
|
nextElementSibling: () => nextElementSibling3,
|
|
11057
11066
|
prepend: () => prepend2,
|
|
@@ -11065,47 +11074,21 @@ __export(esm_exports5, {
|
|
|
11065
11074
|
uniqueSort: () => uniqueSort2
|
|
11066
11075
|
});
|
|
11067
11076
|
|
|
11068
|
-
// node_modules/domelementtype/lib/esm/index.js
|
|
11069
|
-
var ElementType2;
|
|
11070
|
-
(function(ElementType3) {
|
|
11071
|
-
ElementType3["Root"] = "root";
|
|
11072
|
-
ElementType3["Text"] = "text";
|
|
11073
|
-
ElementType3["Directive"] = "directive";
|
|
11074
|
-
ElementType3["Comment"] = "comment";
|
|
11075
|
-
ElementType3["Script"] = "script";
|
|
11076
|
-
ElementType3["Style"] = "style";
|
|
11077
|
-
ElementType3["Tag"] = "tag";
|
|
11078
|
-
ElementType3["CDATA"] = "cdata";
|
|
11079
|
-
ElementType3["Doctype"] = "doctype";
|
|
11080
|
-
})(ElementType2 || (ElementType2 = {}));
|
|
11081
|
-
function isTag3(elem) {
|
|
11082
|
-
return elem.type === ElementType2.Tag || elem.type === ElementType2.Script || elem.type === ElementType2.Style;
|
|
11083
|
-
}
|
|
11084
|
-
var Root2 = ElementType2.Root;
|
|
11085
|
-
var Text3 = ElementType2.Text;
|
|
11086
|
-
var Directive2 = ElementType2.Directive;
|
|
11087
|
-
var Comment4 = ElementType2.Comment;
|
|
11088
|
-
var Script2 = ElementType2.Script;
|
|
11089
|
-
var Style2 = ElementType2.Style;
|
|
11090
|
-
var Tag2 = ElementType2.Tag;
|
|
11091
|
-
var CDATA3 = ElementType2.CDATA;
|
|
11092
|
-
var Doctype2 = ElementType2.Doctype;
|
|
11093
|
-
|
|
11094
11077
|
// node_modules/domhandler/lib/esm/node.js
|
|
11095
|
-
function
|
|
11096
|
-
return
|
|
11078
|
+
function isTag3(node) {
|
|
11079
|
+
return isTag(node);
|
|
11097
11080
|
}
|
|
11098
11081
|
function isCDATA2(node) {
|
|
11099
|
-
return node.type ===
|
|
11082
|
+
return node.type === ElementType.CDATA;
|
|
11100
11083
|
}
|
|
11101
11084
|
function isText2(node) {
|
|
11102
|
-
return node.type ===
|
|
11085
|
+
return node.type === ElementType.Text;
|
|
11103
11086
|
}
|
|
11104
11087
|
function isComment2(node) {
|
|
11105
|
-
return node.type ===
|
|
11088
|
+
return node.type === ElementType.Comment;
|
|
11106
11089
|
}
|
|
11107
11090
|
function isDocument2(node) {
|
|
11108
|
-
return node.type ===
|
|
11091
|
+
return node.type === ElementType.Root;
|
|
11109
11092
|
}
|
|
11110
11093
|
function hasChildren2(node) {
|
|
11111
11094
|
return Object.prototype.hasOwnProperty.call(node, "children");
|
|
@@ -11792,21 +11775,21 @@ function render2(node, options = {}) {
|
|
|
11792
11775
|
var esm_default2 = render2;
|
|
11793
11776
|
function renderNode2(node, options) {
|
|
11794
11777
|
switch (node.type) {
|
|
11795
|
-
case
|
|
11778
|
+
case Root:
|
|
11796
11779
|
return render2(node.children, options);
|
|
11797
11780
|
// @ts-expect-error We don't use `Doctype` yet
|
|
11798
|
-
case
|
|
11799
|
-
case
|
|
11781
|
+
case Doctype:
|
|
11782
|
+
case Directive:
|
|
11800
11783
|
return renderDirective2(node);
|
|
11801
|
-
case
|
|
11784
|
+
case Comment:
|
|
11802
11785
|
return renderComment2(node);
|
|
11803
|
-
case
|
|
11786
|
+
case CDATA:
|
|
11804
11787
|
return renderCdata2(node);
|
|
11805
|
-
case
|
|
11806
|
-
case
|
|
11807
|
-
case
|
|
11788
|
+
case Script:
|
|
11789
|
+
case Style:
|
|
11790
|
+
case Tag:
|
|
11808
11791
|
return renderTag2(node, options);
|
|
11809
|
-
case
|
|
11792
|
+
case Text:
|
|
11810
11793
|
return renderText2(node, options);
|
|
11811
11794
|
}
|
|
11812
11795
|
}
|
|
@@ -11887,7 +11870,7 @@ function getInnerHTML2(node, options) {
|
|
|
11887
11870
|
function getText2(node) {
|
|
11888
11871
|
if (Array.isArray(node))
|
|
11889
11872
|
return node.map(getText2).join("");
|
|
11890
|
-
if (
|
|
11873
|
+
if (isTag3(node))
|
|
11891
11874
|
return node.name === "br" ? "\n" : getText2(node.children);
|
|
11892
11875
|
if (isCDATA2(node))
|
|
11893
11876
|
return getText2(node.children);
|
|
@@ -11908,7 +11891,7 @@ function textContent2(node) {
|
|
|
11908
11891
|
function innerText2(node) {
|
|
11909
11892
|
if (Array.isArray(node))
|
|
11910
11893
|
return node.map(innerText2).join("");
|
|
11911
|
-
if (hasChildren2(node) && (node.type ===
|
|
11894
|
+
if (hasChildren2(node) && (node.type === ElementType.Tag || isCDATA2(node))) {
|
|
11912
11895
|
return innerText2(node.children);
|
|
11913
11896
|
}
|
|
11914
11897
|
if (isText2(node))
|
|
@@ -11951,13 +11934,13 @@ function getName2(elem) {
|
|
|
11951
11934
|
}
|
|
11952
11935
|
function nextElementSibling3(elem) {
|
|
11953
11936
|
let { next } = elem;
|
|
11954
|
-
while (next !== null && !
|
|
11937
|
+
while (next !== null && !isTag3(next))
|
|
11955
11938
|
({ next } = next);
|
|
11956
11939
|
return next;
|
|
11957
11940
|
}
|
|
11958
11941
|
function prevElementSibling2(elem) {
|
|
11959
11942
|
let { prev } = elem;
|
|
11960
|
-
while (prev !== null && !
|
|
11943
|
+
while (prev !== null && !isTag3(prev))
|
|
11961
11944
|
({ prev } = prev);
|
|
11962
11945
|
return prev;
|
|
11963
11946
|
}
|
|
@@ -12089,7 +12072,7 @@ function findOne2(test, nodes, recurse = true) {
|
|
|
12089
12072
|
const searchedNodes = Array.isArray(nodes) ? nodes : [nodes];
|
|
12090
12073
|
for (let i = 0; i < searchedNodes.length; i++) {
|
|
12091
12074
|
const node = searchedNodes[i];
|
|
12092
|
-
if (
|
|
12075
|
+
if (isTag3(node) && test(node)) {
|
|
12093
12076
|
return node;
|
|
12094
12077
|
}
|
|
12095
12078
|
if (recurse && hasChildren2(node) && node.children.length > 0) {
|
|
@@ -12101,7 +12084,7 @@ function findOne2(test, nodes, recurse = true) {
|
|
|
12101
12084
|
return null;
|
|
12102
12085
|
}
|
|
12103
12086
|
function existsOne2(test, nodes) {
|
|
12104
|
-
return (Array.isArray(nodes) ? nodes : [nodes]).some((node) =>
|
|
12087
|
+
return (Array.isArray(nodes) ? nodes : [nodes]).some((node) => isTag3(node) && test(node) || hasChildren2(node) && existsOne2(test, node.children));
|
|
12105
12088
|
}
|
|
12106
12089
|
function findAll2(test, nodes) {
|
|
12107
12090
|
const result = [];
|
|
@@ -12117,7 +12100,7 @@ function findAll2(test, nodes) {
|
|
|
12117
12100
|
continue;
|
|
12118
12101
|
}
|
|
12119
12102
|
const elem = nodeStack[0][indexStack[0]++];
|
|
12120
|
-
if (
|
|
12103
|
+
if (isTag3(elem) && test(elem))
|
|
12121
12104
|
result.push(elem);
|
|
12122
12105
|
if (hasChildren2(elem) && elem.children.length > 0) {
|
|
12123
12106
|
indexStack.unshift(0);
|
|
@@ -12130,11 +12113,11 @@ function findAll2(test, nodes) {
|
|
|
12130
12113
|
var Checks2 = {
|
|
12131
12114
|
tag_name(name) {
|
|
12132
12115
|
if (typeof name === "function") {
|
|
12133
|
-
return (elem) =>
|
|
12116
|
+
return (elem) => isTag3(elem) && name(elem.name);
|
|
12134
12117
|
} else if (name === "*") {
|
|
12135
|
-
return
|
|
12118
|
+
return isTag3;
|
|
12136
12119
|
}
|
|
12137
|
-
return (elem) =>
|
|
12120
|
+
return (elem) => isTag3(elem) && elem.name === name;
|
|
12138
12121
|
},
|
|
12139
12122
|
tag_type(type2) {
|
|
12140
12123
|
if (typeof type2 === "function") {
|
|
@@ -12151,9 +12134,9 @@ var Checks2 = {
|
|
|
12151
12134
|
};
|
|
12152
12135
|
function getAttribCheck2(attrib, value) {
|
|
12153
12136
|
if (typeof value === "function") {
|
|
12154
|
-
return (elem) =>
|
|
12137
|
+
return (elem) => isTag3(elem) && value(elem.attribs[attrib]);
|
|
12155
12138
|
}
|
|
12156
|
-
return (elem) =>
|
|
12139
|
+
return (elem) => isTag3(elem) && elem.attribs[attrib] === value;
|
|
12157
12140
|
}
|
|
12158
12141
|
function combineFuncs2(a, b) {
|
|
12159
12142
|
return (elem) => a(elem) || b(elem);
|
|
@@ -12640,7 +12623,7 @@ var attributeRules = {
|
|
|
12640
12623
|
// node_modules/css-select/lib/esm/pseudo-selectors/index.js
|
|
12641
12624
|
var import_css_what2 = __toESM(require_commonjs(), 1);
|
|
12642
12625
|
|
|
12643
|
-
// node_modules/nth-check/lib/esm/parse.js
|
|
12626
|
+
// ../../node_modules/nth-check/lib/esm/parse.js
|
|
12644
12627
|
var whitespace = /* @__PURE__ */ new Set([9, 10, 12, 13, 32]);
|
|
12645
12628
|
var ZERO = "0".charCodeAt(0);
|
|
12646
12629
|
var NINE = "9".charCodeAt(0);
|
|
@@ -12697,7 +12680,7 @@ function parse(formula) {
|
|
|
12697
12680
|
}
|
|
12698
12681
|
}
|
|
12699
12682
|
|
|
12700
|
-
// node_modules/nth-check/lib/esm/compile.js
|
|
12683
|
+
// ../../node_modules/nth-check/lib/esm/compile.js
|
|
12701
12684
|
var import_boolbase2 = __toESM(require_boolbase(), 1);
|
|
12702
12685
|
function compile(parsed) {
|
|
12703
12686
|
const a = parsed[0];
|
|
@@ -12715,7 +12698,7 @@ function compile(parsed) {
|
|
|
12715
12698
|
return a > 1 ? (index) => index >= b && index % absA === bMod : (index) => index <= b && index % absA === bMod;
|
|
12716
12699
|
}
|
|
12717
12700
|
|
|
12718
|
-
// node_modules/nth-check/lib/esm/index.js
|
|
12701
|
+
// ../../node_modules/nth-check/lib/esm/index.js
|
|
12719
12702
|
function nthCheck(formula) {
|
|
12720
12703
|
return compile(parse(formula));
|
|
12721
12704
|
}
|
|
@@ -13276,13 +13259,13 @@ function reduceRules(a, b) {
|
|
|
13276
13259
|
// node_modules/css-select/lib/esm/index.js
|
|
13277
13260
|
var defaultEquals = (a, b) => a === b;
|
|
13278
13261
|
var defaultOptions = {
|
|
13279
|
-
adapter:
|
|
13262
|
+
adapter: esm_exports4,
|
|
13280
13263
|
equals: defaultEquals
|
|
13281
13264
|
};
|
|
13282
13265
|
function convertOptionFormats(options) {
|
|
13283
13266
|
var _a4, _b, _c, _d;
|
|
13284
13267
|
const opts = options !== null && options !== void 0 ? options : defaultOptions;
|
|
13285
|
-
(_a4 = opts.adapter) !== null && _a4 !== void 0 ? _a4 : opts.adapter =
|
|
13268
|
+
(_a4 = opts.adapter) !== null && _a4 !== void 0 ? _a4 : opts.adapter = esm_exports4;
|
|
13286
13269
|
(_b = opts.equals) !== null && _b !== void 0 ? _b : opts.equals = (_d = (_c = opts.adapter) === null || _c === void 0 ? void 0 : _c.equals) !== null && _d !== void 0 ? _d : defaultEquals;
|
|
13287
13270
|
return opts;
|
|
13288
13271
|
}
|
|
@@ -13329,9 +13312,9 @@ function is2(elem, query2, options) {
|
|
|
13329
13312
|
|
|
13330
13313
|
// node_modules/linkedom/esm/shared/matches.js
|
|
13331
13314
|
var { isArray } = Array;
|
|
13332
|
-
var
|
|
13315
|
+
var isTag4 = ({ nodeType }) => nodeType === ELEMENT_NODE;
|
|
13333
13316
|
var existsOne3 = (test, elements) => elements.some(
|
|
13334
|
-
(element) =>
|
|
13317
|
+
(element) => isTag4(element) && (test(element) || existsOne3(test, getChildren3(element)))
|
|
13335
13318
|
);
|
|
13336
13319
|
var getAttributeValue3 = (element, name) => name === "class" ? element.classList.value : element.getAttribute(name);
|
|
13337
13320
|
var getChildren3 = ({ childNodes }) => childNodes;
|
|
@@ -13347,7 +13330,7 @@ var getSiblings3 = (element) => {
|
|
|
13347
13330
|
var getText3 = (node) => {
|
|
13348
13331
|
if (isArray(node))
|
|
13349
13332
|
return node.map(getText3).join("");
|
|
13350
|
-
if (
|
|
13333
|
+
if (isTag4(node))
|
|
13351
13334
|
return getText3(getChildren3(node));
|
|
13352
13335
|
if (node.nodeType === TEXT_NODE)
|
|
13353
13336
|
return node.data;
|
|
@@ -13374,7 +13357,7 @@ var removeSubsets3 = (nodes) => {
|
|
|
13374
13357
|
var findAll3 = (test, nodes) => {
|
|
13375
13358
|
const matches3 = [];
|
|
13376
13359
|
for (const node of nodes) {
|
|
13377
|
-
if (
|
|
13360
|
+
if (isTag4(node)) {
|
|
13378
13361
|
if (test(node))
|
|
13379
13362
|
matches3.push(node);
|
|
13380
13363
|
matches3.push(...findAll3(test, getChildren3(node)));
|
|
@@ -13389,7 +13372,7 @@ var findOne3 = (test, nodes) => {
|
|
|
13389
13372
|
return null;
|
|
13390
13373
|
};
|
|
13391
13374
|
var adapter = {
|
|
13392
|
-
isTag:
|
|
13375
|
+
isTag: isTag4,
|
|
13393
13376
|
existsOne: existsOne3,
|
|
13394
13377
|
getAttributeValue: getAttributeValue3,
|
|
13395
13378
|
getChildren: getChildren3,
|
|
@@ -13422,7 +13405,7 @@ var matches = (element, selectors) => is2(
|
|
|
13422
13405
|
);
|
|
13423
13406
|
|
|
13424
13407
|
// node_modules/linkedom/esm/interface/text.js
|
|
13425
|
-
var
|
|
13408
|
+
var Text4 = class _Text extends CharacterData {
|
|
13426
13409
|
constructor(ownerDocument, data = "") {
|
|
13427
13410
|
super(ownerDocument, "#text", TEXT_NODE, data);
|
|
13428
13411
|
}
|
|
@@ -13461,7 +13444,7 @@ var insert = (parentNode, child, nodes) => {
|
|
|
13461
13444
|
const { ownerDocument } = parentNode;
|
|
13462
13445
|
for (const node of nodes)
|
|
13463
13446
|
parentNode.insertBefore(
|
|
13464
|
-
isNode(node) ? node : new
|
|
13447
|
+
isNode(node) ? node : new Text4(ownerDocument, node),
|
|
13465
13448
|
child
|
|
13466
13449
|
);
|
|
13467
13450
|
};
|
|
@@ -14272,7 +14255,7 @@ var Element3 = class extends ParentNode {
|
|
|
14272
14255
|
set textContent(text) {
|
|
14273
14256
|
this.replaceChildren();
|
|
14274
14257
|
if (text != null && text !== "")
|
|
14275
|
-
this.appendChild(new
|
|
14258
|
+
this.appendChild(new Text4(this.ownerDocument, text));
|
|
14276
14259
|
}
|
|
14277
14260
|
get innerHTML() {
|
|
14278
14261
|
return getInnerHtml(this);
|
|
@@ -14646,11 +14629,11 @@ function CharacterData2() {
|
|
|
14646
14629
|
}
|
|
14647
14630
|
setPrototypeOf(CharacterData2, CharacterData);
|
|
14648
14631
|
CharacterData2.prototype = CharacterData.prototype;
|
|
14649
|
-
function
|
|
14632
|
+
function Comment5() {
|
|
14650
14633
|
illegalConstructor();
|
|
14651
14634
|
}
|
|
14652
|
-
setPrototypeOf(
|
|
14653
|
-
|
|
14635
|
+
setPrototypeOf(Comment5, Comment3);
|
|
14636
|
+
Comment5.prototype = Comment3.prototype;
|
|
14654
14637
|
function DocumentFragment2() {
|
|
14655
14638
|
illegalConstructor();
|
|
14656
14639
|
}
|
|
@@ -14676,11 +14659,11 @@ function ShadowRoot2() {
|
|
|
14676
14659
|
}
|
|
14677
14660
|
setPrototypeOf(ShadowRoot2, ShadowRoot);
|
|
14678
14661
|
ShadowRoot2.prototype = ShadowRoot.prototype;
|
|
14679
|
-
function
|
|
14662
|
+
function Text5() {
|
|
14680
14663
|
illegalConstructor();
|
|
14681
14664
|
}
|
|
14682
|
-
setPrototypeOf(
|
|
14683
|
-
|
|
14665
|
+
setPrototypeOf(Text5, Text4);
|
|
14666
|
+
Text5.prototype = Text4.prototype;
|
|
14684
14667
|
function SVGElement2() {
|
|
14685
14668
|
illegalConstructor();
|
|
14686
14669
|
}
|
|
@@ -14690,13 +14673,13 @@ var Facades = {
|
|
|
14690
14673
|
Attr: Attr2,
|
|
14691
14674
|
CDATASection: CDATASection2,
|
|
14692
14675
|
CharacterData: CharacterData2,
|
|
14693
|
-
Comment:
|
|
14676
|
+
Comment: Comment5,
|
|
14694
14677
|
DocumentFragment: DocumentFragment2,
|
|
14695
14678
|
DocumentType: DocumentType2,
|
|
14696
14679
|
Element: Element4,
|
|
14697
14680
|
Node: Node3,
|
|
14698
14681
|
ShadowRoot: ShadowRoot2,
|
|
14699
|
-
Text:
|
|
14682
|
+
Text: Text5,
|
|
14700
14683
|
SVGElement: SVGElement2
|
|
14701
14684
|
};
|
|
14702
14685
|
|
|
@@ -16712,7 +16695,7 @@ var Document3 = class extends NonElementParentNode {
|
|
|
16712
16695
|
return range;
|
|
16713
16696
|
}
|
|
16714
16697
|
createTextNode(textContent3) {
|
|
16715
|
-
return new
|
|
16698
|
+
return new Text4(this, textContent3);
|
|
16716
16699
|
}
|
|
16717
16700
|
createTreeWalker(root, whatToShow = -1) {
|
|
16718
16701
|
return new TreeWalker(root, whatToShow);
|
|
@@ -17061,13 +17044,13 @@ async function validatePublicWebUrl(rawUrl, options = {}) {
|
|
|
17061
17044
|
if (value.length > 2e3) throw new Error("URL_TOO_LONG");
|
|
17062
17045
|
url = new URL(value);
|
|
17063
17046
|
} catch {
|
|
17064
|
-
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u65E0\u6548");
|
|
17047
|
+
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u65E0\u6548", void 0, "url_not_allowed");
|
|
17065
17048
|
}
|
|
17066
17049
|
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || !url.hostname) {
|
|
17067
|
-
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE");
|
|
17050
|
+
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE", void 0, "url_not_allowed");
|
|
17068
17051
|
}
|
|
17069
17052
|
const hostname = normalizeHostname(url.hostname).toLowerCase();
|
|
17070
|
-
if (isBlockedHostname(hostname)) throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE");
|
|
17053
|
+
if (isBlockedHostname(hostname)) throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE", void 0, "url_not_allowed");
|
|
17071
17054
|
let addresses;
|
|
17072
17055
|
const literalFamily = (0, import_node_net.isIP)(hostname);
|
|
17073
17056
|
if (literalFamily === 4 || literalFamily === 6) {
|
|
@@ -17077,14 +17060,14 @@ async function validatePublicWebUrl(rawUrl, options = {}) {
|
|
|
17077
17060
|
addresses = await (options.resolveDns ?? resolveWebFetchDns)(hostname, options.signal);
|
|
17078
17061
|
} catch (error) {
|
|
17079
17062
|
if (options.signal?.aborted || error instanceof Error && error.name === "AbortError") throw createAbortError();
|
|
17080
|
-
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25");
|
|
17063
|
+
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25", void 0, "dns_failed");
|
|
17081
17064
|
}
|
|
17082
17065
|
}
|
|
17083
|
-
if (addresses.length === 0) throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25");
|
|
17066
|
+
if (addresses.length === 0) throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u89E3\u6790\u5931\u8D25", void 0, "dns_failed");
|
|
17084
17067
|
const unique = /* @__PURE__ */ new Map();
|
|
17085
17068
|
for (const record of addresses) {
|
|
17086
17069
|
if (!isPublicWebAddress(record.address, record.family)) {
|
|
17087
|
-
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE");
|
|
17070
|
+
throw new import_core6.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u5730\u5740\u4E0D\u5141\u8BB8\u8BBF\u95EE", void 0, "non_public_address");
|
|
17088
17071
|
}
|
|
17089
17072
|
unique.set(`${record.family}:${record.address}`, { address: record.address, family: record.family });
|
|
17090
17073
|
}
|
|
@@ -17293,7 +17276,7 @@ function createSafeWebFetchCapability(options = {}) {
|
|
|
17293
17276
|
/** 读取明确 URL;跨域目标和剩余跳数只交给 Core,在审批后续接。 */
|
|
17294
17277
|
async fetch(input) {
|
|
17295
17278
|
if (input.redirectsRemaining !== void 0 && (!Number.isInteger(input.redirectsRemaining) || input.redirectsRemaining < 0 || input.redirectsRemaining > MAX_REDIRECTS)) {
|
|
17296
|
-
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u9884\u7B97\u65E0\u6548");
|
|
17279
|
+
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u9884\u7B97\u65E0\u6548", void 0, "redirect_rejected");
|
|
17297
17280
|
}
|
|
17298
17281
|
const original = await validatePublicWebUrl(input.url, { resolveDns, signal: input.signal });
|
|
17299
17282
|
let current = original;
|
|
@@ -17306,19 +17289,19 @@ function createSafeWebFetchCapability(options = {}) {
|
|
|
17306
17289
|
const location = readHeader(response.headers, "location");
|
|
17307
17290
|
if (!location || redirectCount >= redirectLimit) {
|
|
17308
17291
|
response.abort();
|
|
17309
|
-
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u65E0\u6548\u6216\u8D85\u8FC7\u4E0A\u9650");
|
|
17292
|
+
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u65E0\u6548\u6216\u8D85\u8FC7\u4E0A\u9650", void 0, "redirect_rejected");
|
|
17310
17293
|
}
|
|
17311
17294
|
let redirectUrl;
|
|
17312
17295
|
try {
|
|
17313
17296
|
redirectUrl = new URL(location, current.url);
|
|
17314
17297
|
} catch {
|
|
17315
17298
|
response.abort();
|
|
17316
|
-
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548");
|
|
17299
|
+
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548", void 0, "redirect_rejected");
|
|
17317
17300
|
}
|
|
17318
17301
|
if (redirectUrl.hostname.toLowerCase() !== current.url.hostname.toLowerCase()) {
|
|
17319
17302
|
response.abort();
|
|
17320
17303
|
if (!["http:", "https:"].includes(redirectUrl.protocol) || redirectUrl.username || redirectUrl.password) {
|
|
17321
|
-
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548");
|
|
17304
|
+
throw new import_core7.WebFetchCapabilityError("WEB_URL_BLOCKED", "\u7F51\u9875\u91CD\u5B9A\u5411\u5730\u5740\u65E0\u6548", void 0, "redirect_rejected");
|
|
17322
17305
|
}
|
|
17323
17306
|
throw new import_core7.WebFetchCapabilityError("WEB_REDIRECT_REQUIRES_APPROVAL", "\u7F51\u9875\u91CD\u5B9A\u5411\u9700\u8981\u65B0\u7684\u57DF\u540D\u5BA1\u6279", {
|
|
17324
17307
|
url: redirectUrl.toString(),
|
|
@@ -17420,7 +17403,7 @@ function hostExecutionCapabilityReport() {
|
|
|
17420
17403
|
installed: false,
|
|
17421
17404
|
provisioned: false,
|
|
17422
17405
|
diagnostics: [
|
|
17423
|
-
"Windows \u5BBF\u4E3B\u6267\u884C\u6A21\u5F0F\uFF1A\u8FDB\u7A0B\u6C99\u7BB1\u5DF2\u505C\u7528\uFF0C\
|
|
17406
|
+
"Windows \u5BBF\u4E3B\u6267\u884C\u6A21\u5F0F\uFF1A\u8FDB\u7A0B\u6C99\u7BB1\u5DF2\u505C\u7528\uFF0C\u8C03\u7528\u6309\u6743\u9650\u6A21\u5F0F\u4E0E\u98CE\u9669\u5206\u6D41\uFF0C\u5728\u5BBF\u4E3B\u4EE5\u5F53\u524D\u7528\u6237\u6743\u9650\u76F4\u63A5\u6267\u884C"
|
|
17424
17407
|
]
|
|
17425
17408
|
};
|
|
17426
17409
|
}
|
|
@@ -17578,15 +17561,31 @@ async function acquireProcessLock(filePath, requireExitedOwner = false) {
|
|
|
17578
17561
|
}
|
|
17579
17562
|
}
|
|
17580
17563
|
}
|
|
17581
|
-
function
|
|
17564
|
+
async function removeOwnedProcessLock(lockPath, ownerId) {
|
|
17565
|
+
const startedAt = Date.now();
|
|
17566
|
+
while (true) {
|
|
17567
|
+
try {
|
|
17568
|
+
const metadata = JSON.parse(await import_promises2.default.readFile(lockPath, "utf8"));
|
|
17569
|
+
if (metadata.ownerId !== ownerId) return;
|
|
17570
|
+
await import_promises2.default.unlink(lockPath);
|
|
17571
|
+
return;
|
|
17572
|
+
} catch (error) {
|
|
17573
|
+
const code = error.code;
|
|
17574
|
+
if (code === "ENOENT") return;
|
|
17575
|
+
if ((code === "EPERM" || code === "EACCES" || code === "EBUSY") && Date.now() - startedAt < PROCESS_LOCK_TIMEOUT_MS) {
|
|
17576
|
+
await waitForProcessLock();
|
|
17577
|
+
continue;
|
|
17578
|
+
}
|
|
17579
|
+
rememberFileFailure(error, { phase: "cleanup", cleanupFailed: true });
|
|
17580
|
+
throw error;
|
|
17581
|
+
}
|
|
17582
|
+
}
|
|
17583
|
+
}
|
|
17584
|
+
async function releaseProcessLock(handle) {
|
|
17582
17585
|
try {
|
|
17583
17586
|
import_node_fs5.default.closeSync(handle.descriptor);
|
|
17584
17587
|
} finally {
|
|
17585
|
-
|
|
17586
|
-
const metadata = JSON.parse(import_node_fs5.default.readFileSync(handle.lockPath, "utf8"));
|
|
17587
|
-
if (metadata.ownerId === handle.ownerId) import_node_fs5.default.unlinkSync(handle.lockPath);
|
|
17588
|
-
} catch {
|
|
17589
|
-
}
|
|
17588
|
+
await removeOwnedProcessLock(handle.lockPath, handle.ownerId);
|
|
17590
17589
|
}
|
|
17591
17590
|
}
|
|
17592
17591
|
async function withFileLock(filePath, operation, options) {
|
|
@@ -17611,7 +17610,7 @@ async function withFileLock(filePath, operation, options) {
|
|
|
17611
17610
|
try {
|
|
17612
17611
|
return await operation();
|
|
17613
17612
|
} finally {
|
|
17614
|
-
releaseProcessLock(handle);
|
|
17613
|
+
await releaseProcessLock(handle);
|
|
17615
17614
|
}
|
|
17616
17615
|
} finally {
|
|
17617
17616
|
release();
|
|
@@ -17651,11 +17650,7 @@ async function releaseAsyncProcessLock(handle) {
|
|
|
17651
17650
|
try {
|
|
17652
17651
|
await handle.descriptor.close();
|
|
17653
17652
|
} finally {
|
|
17654
|
-
|
|
17655
|
-
const metadata = JSON.parse(await import_promises2.default.readFile(handle.lockPath, "utf8"));
|
|
17656
|
-
if (metadata.ownerId === handle.ownerId) await import_promises2.default.unlink(handle.lockPath);
|
|
17657
|
-
} catch {
|
|
17658
|
-
}
|
|
17653
|
+
await removeOwnedProcessLock(handle.lockPath, handle.ownerId);
|
|
17659
17654
|
}
|
|
17660
17655
|
}
|
|
17661
17656
|
async function withAsyncFileLock(filePath, operation) {
|
|
@@ -17708,6 +17703,39 @@ function atomicReplace(filePath, content) {
|
|
|
17708
17703
|
}
|
|
17709
17704
|
}
|
|
17710
17705
|
}
|
|
17706
|
+
async function replaceSessionFile(filePath, content) {
|
|
17707
|
+
if (process.platform !== "win32") return atomicReplace(filePath, content);
|
|
17708
|
+
ensureParentDirectory(filePath);
|
|
17709
|
+
const temporaryPath = `${filePath}.${process.pid}.${(0, import_node_crypto3.randomUUID)()}.tmp`;
|
|
17710
|
+
const delays = [20, 40, 80, 160];
|
|
17711
|
+
let attempts = 0;
|
|
17712
|
+
const started = performance.now();
|
|
17713
|
+
try {
|
|
17714
|
+
await import_promises2.default.writeFile(temporaryPath, content, { encoding: "utf8", flag: "wx" });
|
|
17715
|
+
for (; ; ) {
|
|
17716
|
+
attempts++;
|
|
17717
|
+
try {
|
|
17718
|
+
await import_promises2.default.rename(temporaryPath, filePath);
|
|
17719
|
+
return;
|
|
17720
|
+
} catch (error) {
|
|
17721
|
+
const delay = delays[attempts - 1];
|
|
17722
|
+
if (!delay || !["EBUSY", "EPERM", "EACCES"].includes(error.code ?? "")) throw error;
|
|
17723
|
+
await new Promise(function backoff(resolve) {
|
|
17724
|
+
setTimeout(resolve, delay);
|
|
17725
|
+
});
|
|
17726
|
+
}
|
|
17727
|
+
}
|
|
17728
|
+
} catch (error) {
|
|
17729
|
+
let cleanupFailed = false;
|
|
17730
|
+
try {
|
|
17731
|
+
await import_promises2.default.rm(temporaryPath, { force: true });
|
|
17732
|
+
} catch {
|
|
17733
|
+
cleanupFailed = true;
|
|
17734
|
+
}
|
|
17735
|
+
rememberFileFailure(error, { phase: attempts ? "rename" : "temporary_write", attempts, elapsedMs: Math.round(performance.now() - started), cleanupFailed });
|
|
17736
|
+
throw error;
|
|
17737
|
+
}
|
|
17738
|
+
}
|
|
17711
17739
|
function safeFilePath(directory, key2, extension) {
|
|
17712
17740
|
if (!key2 || key2.includes("/") || key2.includes("\\") || key2 === "." || key2 === "..") {
|
|
17713
17741
|
throw new Error("\u6301\u4E45\u5316 ID \u4E0D\u80FD\u5305\u542B\u8DEF\u5F84\u5206\u9694\u7B26");
|
|
@@ -18023,6 +18051,8 @@ function normalizeNodeSession(value, id) {
|
|
|
18023
18051
|
const session = value;
|
|
18024
18052
|
if (session.id !== id || !Number.isFinite(session.createdAt) || !Number.isFinite(session.updatedAt)) throw new NodeStateError("STATE_SESSION_CORRUPTED");
|
|
18025
18053
|
const source = session.creationSource;
|
|
18054
|
+
const managed = session.managedExecution;
|
|
18055
|
+
if (managed !== void 0 && (!managed || managed.threadPolicy !== "disabled" || typeof managed.hostId !== "string" || !/^[\w-]{1,128}$/.test(managed.hostId) || typeof managed.requestId !== "string" || !/^[\w-]{1,128}$/.test(managed.requestId) || session.productMode !== "work" || session.persistenceMode !== "durable")) throw new NodeStateError("STATE_SESSION_CORRUPTED");
|
|
18026
18056
|
if (source !== void 0) {
|
|
18027
18057
|
const actor = source?.actor;
|
|
18028
18058
|
if (!session.collaborationCreationId || !source || typeof source.requestId !== "string" || !source.requestId || !actor || actor.kind !== "human" && actor.kind !== "thread" || actor.kind === "human" && (typeof actor.principalId !== "string" || !actor.principalId) || actor.kind === "thread" && (typeof actor.threadId !== "string" || !actor.threadId || typeof actor.turnId !== "string" || !actor.turnId)) throw new NodeStateError("STATE_SESSION_CORRUPTED");
|
|
@@ -18036,6 +18066,7 @@ function normalizeNodeSession(value, id) {
|
|
|
18036
18066
|
return { ...session, productMode: mode };
|
|
18037
18067
|
}
|
|
18038
18068
|
function assertNodeSessionIdentity(previous, next) {
|
|
18069
|
+
if (JSON.stringify(previous.managedExecution) !== JSON.stringify(next.managedExecution)) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
|
|
18039
18070
|
if (JSON.stringify(previous.collaborationAllowedTools) !== JSON.stringify(next.collaborationAllowedTools)) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
|
|
18040
18071
|
if (JSON.stringify(previous.creationSource) !== JSON.stringify(next.creationSource)) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
|
|
18041
18072
|
if (previous.collaborationCreationId !== next.collaborationCreationId) throw createNodeIdentityError("SESSION_MODE_MISMATCH");
|
|
@@ -19740,7 +19771,7 @@ var import_node_fs20 = __toESM(require("node:fs"));
|
|
|
19740
19771
|
var import_node_fs19 = __toESM(require("node:fs"));
|
|
19741
19772
|
var DIRECTORY_FIELDS = /* @__PURE__ */ new Set(["id", "title", "productMode", "projectId", "chatRetrievalMode", "createdAt", "updatedAt", "status", "activeTurnId"]);
|
|
19742
19773
|
async function readSessionDirectoryRecord(filePath, id) {
|
|
19743
|
-
const
|
|
19774
|
+
const fields2 = {};
|
|
19744
19775
|
const stack = [];
|
|
19745
19776
|
let root = false;
|
|
19746
19777
|
let finished = false;
|
|
@@ -19770,7 +19801,7 @@ async function readSessionDirectoryRecord(filePath, id) {
|
|
|
19770
19801
|
const frame = stack[stack.length - 1];
|
|
19771
19802
|
frame.key = stack.length === 1 ? JSON.parse(text) : void 0;
|
|
19772
19803
|
frame.expect = "colon";
|
|
19773
|
-
} else if (target)
|
|
19804
|
+
} else if (target) fields2[target] = JSON.parse(text);
|
|
19774
19805
|
token = void 0;
|
|
19775
19806
|
text = "";
|
|
19776
19807
|
target = void 0;
|
|
@@ -19854,8 +19885,8 @@ async function readSessionDirectoryRecord(filePath, id) {
|
|
|
19854
19885
|
}
|
|
19855
19886
|
}
|
|
19856
19887
|
if (!finished || token || stack.length) invalid();
|
|
19857
|
-
if (
|
|
19858
|
-
return normalizeNodeSession(
|
|
19888
|
+
if (fields2.title !== void 0 && typeof fields2.title !== "string") invalid();
|
|
19889
|
+
return normalizeNodeSession(fields2, id);
|
|
19859
19890
|
}
|
|
19860
19891
|
|
|
19861
19892
|
// src/node/stores/node-session-store.ts
|
|
@@ -19984,7 +20015,7 @@ function createNodeSessionStore(options) {
|
|
|
19984
20015
|
phase = "identity";
|
|
19985
20016
|
const previous = read(session.id);
|
|
19986
20017
|
if (previous) assertNodeSessionIdentity(previous, next);
|
|
19987
|
-
|
|
20018
|
+
return replaceSessionFile(filePath(session.id), JSON.stringify(next, null, 2));
|
|
19988
20019
|
});
|
|
19989
20020
|
} catch (error) {
|
|
19990
20021
|
throw toNodeBoundaryError(error, "STATE_STORAGE_UNAVAILABLE", { operation: "session_save", target: "session", phase, ...getFileOperationDiagnostic(error) });
|
|
@@ -20839,9 +20870,15 @@ function createNodeRuntimePorts(options) {
|
|
|
20839
20870
|
};
|
|
20840
20871
|
}
|
|
20841
20872
|
|
|
20873
|
+
// src/node/runtime-owner.ts
|
|
20874
|
+
var import_node_path22 = require("node:path");
|
|
20875
|
+
function withNodeRuntimeOwner(stateRoot, operation) {
|
|
20876
|
+
return withFileLock((0, import_node_path22.join)(stateRoot, "managed-runtime-owner"), operation, { requireExitedOwner: true });
|
|
20877
|
+
}
|
|
20878
|
+
|
|
20842
20879
|
// src/node/stores/node-chat-attachment-store.ts
|
|
20843
20880
|
var import_node_fs28 = __toESM(require("node:fs"));
|
|
20844
|
-
var
|
|
20881
|
+
var import_node_path23 = __toESM(require("node:path"));
|
|
20845
20882
|
var import_node_crypto12 = require("node:crypto");
|
|
20846
20883
|
var CHAT_ATTACHMENT_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
20847
20884
|
var MAX_BYTES = 20 * 1024 * 1024;
|
|
@@ -20881,12 +20918,12 @@ function createNodeChatAttachmentStore(options) {
|
|
|
20881
20918
|
const { paths, sessionStore } = options;
|
|
20882
20919
|
const now = options.now ?? Date.now;
|
|
20883
20920
|
const root = paths.attachmentsRoot;
|
|
20884
|
-
const dataRoot =
|
|
20885
|
-
const retiredRoot =
|
|
20886
|
-
const deletingRoot =
|
|
20887
|
-
const lock =
|
|
20921
|
+
const dataRoot = import_node_path23.default.join(root, "sessions");
|
|
20922
|
+
const retiredRoot = import_node_path23.default.join(root, "retired");
|
|
20923
|
+
const deletingRoot = import_node_path23.default.join(root, "deleting");
|
|
20924
|
+
const lock = import_node_path23.default.join(root, "lifecycle");
|
|
20888
20925
|
function ensure() {
|
|
20889
|
-
assertSafeNodePath(
|
|
20926
|
+
assertSafeNodePath(import_node_path23.default.dirname(paths.root), paths.root);
|
|
20890
20927
|
for (const directory of [root, dataRoot, retiredRoot, deletingRoot]) ensureChatDirectory(paths.root, directory);
|
|
20891
20928
|
assertSafeNodePath(root, `${lock}.lock`);
|
|
20892
20929
|
}
|
|
@@ -20908,7 +20945,7 @@ function createNodeChatAttachmentStore(options) {
|
|
|
20908
20945
|
}
|
|
20909
20946
|
function isSessionDeleting(sessionId) {
|
|
20910
20947
|
try {
|
|
20911
|
-
const target =
|
|
20948
|
+
const target = import_node_path23.default.join(deletingRoot, `${sessionKey(sessionId)}.json`);
|
|
20912
20949
|
assertSafeNodePath(root, target);
|
|
20913
20950
|
return import_node_fs28.default.existsSync(target);
|
|
20914
20951
|
} catch (error) {
|
|
@@ -20927,13 +20964,13 @@ function createNodeChatAttachmentStore(options) {
|
|
|
20927
20964
|
if (session?.productMode !== "chat" || !["none", "web"].includes(session.chatRetrievalMode ?? "")) throw new NodeChatError("CHAT_UPLOAD_MODE_MISMATCH");
|
|
20928
20965
|
}
|
|
20929
20966
|
function records(sessionId) {
|
|
20930
|
-
const directory =
|
|
20967
|
+
const directory = import_node_path23.default.join(dataRoot, sessionKey(sessionId));
|
|
20931
20968
|
assertSafeNodePath(root, directory);
|
|
20932
20969
|
if (!import_node_fs28.default.existsSync(directory)) return [];
|
|
20933
20970
|
const result = [];
|
|
20934
20971
|
for (const ref of import_node_fs28.default.readdirSync(directory)) {
|
|
20935
20972
|
if (!opaque.test(ref)) unavailable();
|
|
20936
|
-
const target =
|
|
20973
|
+
const target = import_node_path23.default.join(directory, ref, "metadata.json");
|
|
20937
20974
|
assertSafeNodePath(root, target);
|
|
20938
20975
|
if (!import_node_fs28.default.statSync(target).isFile() || import_node_fs28.default.statSync(target).size > 16384) unavailable();
|
|
20939
20976
|
const record = JSON.parse(import_node_fs28.default.readFileSync(target, "utf8"));
|
|
@@ -20947,7 +20984,7 @@ function createNodeChatAttachmentStore(options) {
|
|
|
20947
20984
|
return { ref: record.ref, sessionId: record.sessionId, kind: record.kind, expiresAt: record.expiresAt };
|
|
20948
20985
|
}
|
|
20949
20986
|
function active(record) {
|
|
20950
|
-
return record.expiresAt > now() && !isSessionDeleting(record.sessionId) && !import_node_fs28.default.existsSync(
|
|
20987
|
+
return record.expiresAt > now() && !isSessionDeleting(record.sessionId) && !import_node_fs28.default.existsSync(import_node_path23.default.join(retiredRoot, `${record.ref}.json`));
|
|
20951
20988
|
}
|
|
20952
20989
|
function sanitizeSession(session) {
|
|
20953
20990
|
try {
|
|
@@ -20986,17 +21023,17 @@ function createNodeChatAttachmentStore(options) {
|
|
|
20986
21023
|
return !opaque.test(ref);
|
|
20987
21024
|
}
|
|
20988
21025
|
)) unavailable();
|
|
20989
|
-
const directory =
|
|
21026
|
+
const directory = import_node_path23.default.join(dataRoot, item.sessionId, item.ref);
|
|
20990
21027
|
assertSafeNodePath(root, directory);
|
|
20991
21028
|
import_node_fs28.default.rmSync(directory, { recursive: true, force: true });
|
|
20992
21029
|
await removePresentationRefs(item.sessionId, item.refs);
|
|
20993
|
-
import_node_fs28.default.rmSync(
|
|
21030
|
+
import_node_fs28.default.rmSync(import_node_path23.default.join(retiredRoot, `${item.ref}.json`), { force: true });
|
|
20994
21031
|
}
|
|
20995
21032
|
async function retire(record) {
|
|
20996
21033
|
const item = { sessionId: record.sessionId, ref: record.ref, refs: [record.ref, ...record.pages.map(function pageRef(page) {
|
|
20997
21034
|
return page.ref;
|
|
20998
21035
|
})] };
|
|
20999
|
-
atomicReplace(
|
|
21036
|
+
atomicReplace(import_node_path23.default.join(retiredRoot, `${record.ref}.json`), JSON.stringify(item));
|
|
21000
21037
|
await finishRetirement(item);
|
|
21001
21038
|
}
|
|
21002
21039
|
async function put(input) {
|
|
@@ -21029,13 +21066,13 @@ function createNodeChatAttachmentStore(options) {
|
|
|
21029
21066
|
const createdAt = now();
|
|
21030
21067
|
if (!Number.isSafeInteger(createdAt) || createdAt < 0) unavailable();
|
|
21031
21068
|
const ref = (0, import_node_crypto12.randomUUID)();
|
|
21032
|
-
const parent =
|
|
21069
|
+
const parent = import_node_path23.default.join(dataRoot, sessionKey(input.sessionId));
|
|
21033
21070
|
ensureChatDirectory(root, parent);
|
|
21034
|
-
const staging =
|
|
21071
|
+
const staging = import_node_path23.default.join(root, `staging-${ref}`);
|
|
21035
21072
|
const record = { ref, sessionId: input.sessionId, kind, mimeType, byteLength: bytes.length, sha256: digest(bytes), createdAt, expiresAt: createdAt + CHAT_ATTACHMENT_TTL_MS, status: "active", displayName: input.displayName.split(/[\\/]/).at(-1).replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 120) || "\u9644\u4EF6", pages: [] };
|
|
21036
21073
|
try {
|
|
21037
21074
|
ensureChatDirectory(root, staging);
|
|
21038
|
-
import_node_fs28.default.writeFileSync(
|
|
21075
|
+
import_node_fs28.default.writeFileSync(import_node_path23.default.join(staging, "content"), bytes, { flag: "wx", mode: 384 });
|
|
21039
21076
|
let pageBytes = 0;
|
|
21040
21077
|
for (const inputPage of parsed?.pages ?? []) {
|
|
21041
21078
|
const page = Buffer.from(inputPage);
|
|
@@ -21043,13 +21080,13 @@ function createNodeChatAttachmentStore(options) {
|
|
|
21043
21080
|
pageBytes += page.length;
|
|
21044
21081
|
if (!type2.startsWith("image/") || !page.length || page.length > IMAGE_BYTES || pageBytes > MAX_BYTES) unavailable();
|
|
21045
21082
|
const pageRef = (0, import_node_crypto12.randomUUID)();
|
|
21046
|
-
import_node_fs28.default.writeFileSync(
|
|
21083
|
+
import_node_fs28.default.writeFileSync(import_node_path23.default.join(staging, pageRef), page, { flag: "wx", mode: 384 });
|
|
21047
21084
|
record.pages.push({ ref: pageRef, mimeType: type2, byteLength: page.length, sha256: digest(page) });
|
|
21048
21085
|
}
|
|
21049
|
-
if (parsed) import_node_fs28.default.writeFileSync(
|
|
21050
|
-
import_node_fs28.default.writeFileSync(
|
|
21086
|
+
if (parsed) import_node_fs28.default.writeFileSync(import_node_path23.default.join(staging, "parsed.json"), JSON.stringify({ text: parsed.text.slice(0, 16e3) }), { flag: "wx", mode: 384 });
|
|
21087
|
+
import_node_fs28.default.writeFileSync(import_node_path23.default.join(staging, "metadata.json"), JSON.stringify(record), { flag: "wx", mode: 384 });
|
|
21051
21088
|
checkSignal(input.signal);
|
|
21052
|
-
import_node_fs28.default.renameSync(staging,
|
|
21089
|
+
import_node_fs28.default.renameSync(staging, import_node_path23.default.join(parent, ref));
|
|
21053
21090
|
const { pages: _pages, ...view } = record;
|
|
21054
21091
|
return view;
|
|
21055
21092
|
} finally {
|
|
@@ -21095,7 +21132,7 @@ function createNodeChatAttachmentStore(options) {
|
|
|
21095
21132
|
return locked(async function readParsed() {
|
|
21096
21133
|
const { record, page } = await find3(sessionId, ref);
|
|
21097
21134
|
if (page || record.kind !== "document") unavailable();
|
|
21098
|
-
const target =
|
|
21135
|
+
const target = import_node_path23.default.join(dataRoot, sessionId, ref, "parsed.json");
|
|
21099
21136
|
assertSafeNodePath(root, target);
|
|
21100
21137
|
if (import_node_fs28.default.statSync(target).size > 1e5) unavailable();
|
|
21101
21138
|
const parsed = JSON.parse(import_node_fs28.default.readFileSync(target, "utf8"));
|
|
@@ -21108,7 +21145,7 @@ function createNodeChatAttachmentStore(options) {
|
|
|
21108
21145
|
async function readBytes(sessionId, ref, signal) {
|
|
21109
21146
|
return locked(async function readContent() {
|
|
21110
21147
|
const { record, page } = await find3(sessionId, ref);
|
|
21111
|
-
const target =
|
|
21148
|
+
const target = import_node_path23.default.join(dataRoot, sessionId, record.ref, page?.ref ?? "content");
|
|
21112
21149
|
assertSafeNodePath(root, target);
|
|
21113
21150
|
const metadata = page ?? record;
|
|
21114
21151
|
if (import_node_fs28.default.statSync(target).size !== metadata.byteLength || metadata.byteLength > MAX_BYTES) unavailable();
|
|
@@ -21119,10 +21156,10 @@ function createNodeChatAttachmentStore(options) {
|
|
|
21119
21156
|
}
|
|
21120
21157
|
async function deleteBySession(sessionId) {
|
|
21121
21158
|
await locked(async function deleteSessionAttachments() {
|
|
21122
|
-
atomicReplace(
|
|
21159
|
+
atomicReplace(import_node_path23.default.join(deletingRoot, `${sessionKey(sessionId)}.json`), JSON.stringify({ sessionId }));
|
|
21123
21160
|
for (const record of records(sessionId)) await retire(record);
|
|
21124
21161
|
await removePresentationRefs(sessionId);
|
|
21125
|
-
import_node_fs28.default.rmSync(
|
|
21162
|
+
import_node_fs28.default.rmSync(import_node_path23.default.join(dataRoot, sessionId), { recursive: true, force: true });
|
|
21126
21163
|
}, void 0, "CHAT_ATTACHMENT_CLEANUP_FAILED");
|
|
21127
21164
|
}
|
|
21128
21165
|
async function cleanupExpired(input = {}) {
|
|
@@ -21131,13 +21168,13 @@ function createNodeChatAttachmentStore(options) {
|
|
|
21131
21168
|
return locked(async function cleanupBatch() {
|
|
21132
21169
|
for (const file of import_node_fs28.default.readdirSync(root)) {
|
|
21133
21170
|
if (!/^staging-[0-9a-f-]{36}$/.test(file)) continue;
|
|
21134
|
-
const target =
|
|
21171
|
+
const target = import_node_path23.default.join(root, file);
|
|
21135
21172
|
assertSafeNodePath(root, target);
|
|
21136
21173
|
import_node_fs28.default.rmSync(target, { recursive: true, force: true });
|
|
21137
21174
|
}
|
|
21138
21175
|
for (const file of import_node_fs28.default.readdirSync(retiredRoot)) {
|
|
21139
21176
|
if (!file.endsWith(".json")) continue;
|
|
21140
|
-
const target =
|
|
21177
|
+
const target = import_node_path23.default.join(retiredRoot, file);
|
|
21141
21178
|
assertSafeNodePath(root, target);
|
|
21142
21179
|
checkSignal(input.signal);
|
|
21143
21180
|
const item = JSON.parse(import_node_fs28.default.readFileSync(target, "utf8"));
|
|
@@ -21550,7 +21587,13 @@ function assertRevision(original, revision) {
|
|
|
21550
21587
|
}
|
|
21551
21588
|
function readEnvironmentKey(environment, key2) {
|
|
21552
21589
|
if (!key2) return void 0;
|
|
21553
|
-
return parseApiKey(environment[key2]);
|
|
21590
|
+
return parseApiKey(environment[key2] ?? (key2.startsWith("USER_SETTINGS_") ? environment[key2.slice("USER_SETTINGS_".length)] : void 0));
|
|
21591
|
+
}
|
|
21592
|
+
function readMainCredential(environment, ref, env) {
|
|
21593
|
+
const configured = readEnvironmentKey(environment, ref.key);
|
|
21594
|
+
if (configured || ref.key.startsWith("USER_SETTINGS_")) return configured;
|
|
21595
|
+
const envKey = `${ref.provider.toUpperCase().replace(/[^A-Z0-9_]/gu, "_")}_${ref.key.toUpperCase()}`;
|
|
21596
|
+
return parseApiKey(env[envKey]);
|
|
21554
21597
|
}
|
|
21555
21598
|
function collectMainCredentialCandidates(raw, environment) {
|
|
21556
21599
|
const candidates = [];
|
|
@@ -21598,30 +21641,108 @@ function removeLegacyPrimaryRoutes(raw, environment) {
|
|
|
21598
21641
|
for (const key2 of removedKeys) if (!hasCredentialReference(raw, key2)) delete environment[key2];
|
|
21599
21642
|
}
|
|
21600
21643
|
function normalizeMainInput(input) {
|
|
21644
|
+
const apiProtocol = input.apiProtocol ?? "anthropic-messages";
|
|
21601
21645
|
const baseUrl = (0, import_core19.normalizeProviderBaseUrl)(input.baseUrl);
|
|
21602
21646
|
const model = parseSettingString(input.model);
|
|
21603
21647
|
const apiKey = parseApiKey(input.apiKey);
|
|
21604
21648
|
const availableModels = input.availableModels?.map(function parseModel(value) {
|
|
21605
21649
|
return parseSettingString(value);
|
|
21606
21650
|
});
|
|
21607
|
-
if (!baseUrl || !model || input.apiKey !== void 0 && input.apiKey !== "" && !apiKey || availableModels && (availableModels.length === 0 || availableModels.some(function missing(value) {
|
|
21651
|
+
if (!["anthropic-messages", "openai-chat-completions", "openai-responses"].includes(apiProtocol) || input.compatibilityPreset !== void 0 && (apiProtocol === "anthropic-messages" || !["openai", "deepseek", "generic"].includes(input.compatibilityPreset)) || !baseUrl || !model || input.apiKey !== void 0 && input.apiKey !== "" && !apiKey || availableModels && (availableModels.length === 0 || availableModels.some(function missing(value) {
|
|
21608
21652
|
return !value;
|
|
21609
|
-
}) || new Set(availableModels).size !== availableModels.length) || input.effort !== void 0 && !["auto", "low", "medium", "high", "max"].includes(input.effort) || input.maxOutputTokens !== void 0 && (!Number.isInteger(input.maxOutputTokens) || input.maxOutputTokens < 1 || input.maxOutputTokens > 1e6) || input.compactWindow !== void 0 && (!Number.isInteger(input.compactWindow) || input.compactWindow < 1 || input.compactWindow > 1e7) || input.timeoutMs !== void 0 && (!Number.isInteger(input.timeoutMs) || input.timeoutMs < 1e3 || input.timeoutMs > 6e5) || input.alwaysThinkingEnabled !== void 0 && typeof input.alwaysThinkingEnabled !== "boolean") throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
|
|
21653
|
+
}) || new Set(availableModels).size !== availableModels.length) || input.effort !== void 0 && !["auto", "none", "low", "medium", "high", "xhigh", "max"].includes(input.effort) || input.maxOutputTokens !== void 0 && (!Number.isInteger(input.maxOutputTokens) || input.maxOutputTokens < 1 || input.maxOutputTokens > 1e6) || input.compactWindow !== void 0 && (!Number.isInteger(input.compactWindow) || input.compactWindow < 1 || input.compactWindow > 1e7) || input.timeoutMs !== void 0 && (!Number.isInteger(input.timeoutMs) || input.timeoutMs < 1e3 || input.timeoutMs > 6e5) || input.alwaysThinkingEnabled !== void 0 && typeof input.alwaysThinkingEnabled !== "boolean") throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
|
|
21610
21654
|
for (const value of [input.opusModel, input.sonnetModel, input.haikuModel, input.subagentModel]) {
|
|
21611
21655
|
if (value !== void 0 && !parseSettingString(value)) throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
|
|
21612
21656
|
}
|
|
21613
|
-
return { ...input, baseUrl, model, ...apiKey ? { apiKey } : {}, ...availableModels ? { availableModels } : {} };
|
|
21657
|
+
return { ...input, apiProtocol, baseUrl, model, ...apiKey ? { apiKey } : {}, ...availableModels ? { availableModels } : {} };
|
|
21658
|
+
}
|
|
21659
|
+
function createMainRoute(raw, input) {
|
|
21660
|
+
const previous = (0, import_core19.resolveAutopilotSettings)([{ scope: "user", value: raw }]);
|
|
21661
|
+
const selected = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
|
|
21662
|
+
const apiProtocol = input.apiProtocol ?? "anthropic-messages";
|
|
21663
|
+
const sameConnection = selected?.apiProtocol === apiProtocol && selected.baseUrl === input.baseUrl;
|
|
21664
|
+
const matches3 = sameConnection && selected.compatibilityPreset === input.compatibilityPreset;
|
|
21665
|
+
let id = selected?.id ?? "web-main";
|
|
21666
|
+
for (let suffix = 2; !selected && previous.providerRoutes[id]; suffix += 1) id = `web-main-${suffix}`;
|
|
21667
|
+
const ids = [.../* @__PURE__ */ new Set([...input.availableModels ?? (matches3 ? selected.models.map(function modelId(model) {
|
|
21668
|
+
return model.id;
|
|
21669
|
+
}) : []), input.model])];
|
|
21670
|
+
return {
|
|
21671
|
+
id,
|
|
21672
|
+
apiProtocol,
|
|
21673
|
+
baseUrl: input.baseUrl,
|
|
21674
|
+
credentialRef: sameConnection ? selected.credentialRef : { provider: id, key: `USER_SETTINGS_WEB_MAIN_${revisionOf(`${id}/${apiProtocol}/${input.baseUrl}`).slice(0, 16).toUpperCase()}` },
|
|
21675
|
+
...selected?.displayName ? { displayName: selected.displayName } : {},
|
|
21676
|
+
...input.compatibilityPreset ? { compatibilityPreset: input.compatibilityPreset } : {},
|
|
21677
|
+
...matches3 && selected.protocolProfile ? { protocolProfile: selected.protocolProfile } : {},
|
|
21678
|
+
models: ids.map(function modelEntry(modelId) {
|
|
21679
|
+
return matches3 ? selected.models.find(function matchesId(model) {
|
|
21680
|
+
return model.id === modelId;
|
|
21681
|
+
}) ?? { id: modelId } : { id: modelId };
|
|
21682
|
+
})
|
|
21683
|
+
};
|
|
21684
|
+
}
|
|
21685
|
+
function resolveMainCapabilities(route, model) {
|
|
21686
|
+
try {
|
|
21687
|
+
const capability = (0, import_core19.resolveRouteModelCapability)(route, model);
|
|
21688
|
+
return { supportedReasoningEfforts: capability.supportedReasoningEfforts ?? [], supportsToolCalls: capability.supportsToolCalls !== false };
|
|
21689
|
+
} catch {
|
|
21690
|
+
throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
|
|
21691
|
+
}
|
|
21614
21692
|
}
|
|
21615
|
-
function
|
|
21693
|
+
function applyRoutedMainCategory(raw, input, env) {
|
|
21694
|
+
const route = createMainRoute(raw, input);
|
|
21695
|
+
const capabilities = resolveMainCapabilities(route, input.model);
|
|
21696
|
+
if (!capabilities.supportsToolCalls) throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID", { scope: "user", code: "MODEL_NOT_SUPPORTED", field: "model" });
|
|
21697
|
+
if (input.effort && input.effort !== "auto" && !capabilities.supportedReasoningEfforts.includes(input.effort)) {
|
|
21698
|
+
throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID", { scope: "user", code: "SETTINGS_EFFORT_INVALID", field: "effortLevel" });
|
|
21699
|
+
}
|
|
21700
|
+
const environment = { ...isRecord4(raw.env) ? raw.env : {} };
|
|
21701
|
+
const previous = (0, import_core19.resolveAutopilotSettings)([{ scope: "user", value: raw }]);
|
|
21702
|
+
const selected = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
|
|
21703
|
+
const sameConnection = selected?.apiProtocol === route.apiProtocol && selected.baseUrl === route.baseUrl;
|
|
21704
|
+
if (!input.apiKey && !sameConnection) throw new NodeUserSettingsError("SETTINGS_KEY_REQUIRED");
|
|
21705
|
+
const key2 = input.apiKey ?? readMainCredential(environment, route.credentialRef, env);
|
|
21706
|
+
if (!key2) throw new NodeUserSettingsError("SETTINGS_KEY_REQUIRED");
|
|
21707
|
+
if (input.apiKey) environment[route.credentialRef.key] = input.apiKey;
|
|
21708
|
+
delete environment.ANTHROPIC_MODEL;
|
|
21709
|
+
delete environment.CLAUDE_CODE_EFFORT_LEVEL;
|
|
21710
|
+
raw.env = environment;
|
|
21711
|
+
raw.providerRoutes = { ...isRecord4(raw.providerRoutes) ? raw.providerRoutes : {}, [route.id]: route };
|
|
21712
|
+
raw.model = `${route.id}/${input.model}`;
|
|
21713
|
+
if (input.effort && input.effort !== "auto") raw.effortLevel = input.effort;
|
|
21714
|
+
else delete raw.effortLevel;
|
|
21715
|
+
}
|
|
21716
|
+
function applyMainCategory(raw, input, env) {
|
|
21616
21717
|
const normalized = normalizeMainInput(input);
|
|
21718
|
+
const previous = (0, import_core19.resolveAutopilotSettings)([{ scope: "user", value: raw }]);
|
|
21719
|
+
const previousRoute = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
|
|
21720
|
+
if (normalized.apiProtocol !== "anthropic-messages" || input.apiProtocol !== void 0 && previousRoute) {
|
|
21721
|
+
applyRoutedMainCategory(raw, normalized, env);
|
|
21722
|
+
if (normalized.maxOutputTokens === void 0) delete raw.maxOutputTokens;
|
|
21723
|
+
else raw.maxOutputTokens = normalized.maxOutputTokens;
|
|
21724
|
+
const environment2 = raw.env;
|
|
21725
|
+
const optional2 = {
|
|
21726
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: normalized.opusModel,
|
|
21727
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: normalized.sonnetModel,
|
|
21728
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: normalized.haikuModel,
|
|
21729
|
+
CLAUDE_CODE_AUTO_COMPACT_WINDOW: normalized.compactWindow?.toString(),
|
|
21730
|
+
API_TIMEOUT_MS: normalized.timeoutMs?.toString(),
|
|
21731
|
+
CLAUDE_CODE_SUBAGENT_MODEL: normalized.subagentModel
|
|
21732
|
+
};
|
|
21733
|
+
for (const [key2, value] of Object.entries(optional2)) {
|
|
21734
|
+
if (value === void 0) delete environment2[key2];
|
|
21735
|
+
else environment2[key2] = value;
|
|
21736
|
+
}
|
|
21737
|
+
if (normalized.apiProtocol === "anthropic-messages" && normalized.alwaysThinkingEnabled !== void 0) raw.alwaysThinkingEnabled = normalized.alwaysThinkingEnabled;
|
|
21738
|
+
return;
|
|
21739
|
+
}
|
|
21617
21740
|
const environment = { ...isRecord4(raw.env) ? raw.env : {} };
|
|
21618
21741
|
const candidates = collectMainCredentialCandidates(raw, environment);
|
|
21619
21742
|
const distinct = [...new Set(candidates.map(function value(candidate) {
|
|
21620
21743
|
return candidate.value;
|
|
21621
21744
|
}))];
|
|
21622
21745
|
if (!normalized.apiKey && distinct.length > 1) throw new NodeUserSettingsError("SETTINGS_MIGRATION_CONFLICT");
|
|
21623
|
-
const previous = (0, import_core19.resolveAutopilotSettings)([{ scope: "user", value: raw }]);
|
|
21624
|
-
const previousRoute = previous.modelRef && previous.providerRoutes[previous.modelRef.provider];
|
|
21625
21746
|
const previousBaseUrl = (0, import_core19.normalizeProviderBaseUrl)(previousRoute?.baseUrl ?? previous.firstParty.baseUrl);
|
|
21626
21747
|
const officialDeepSeekMigration = previousBaseUrl === "https://api.deepseek.com" && normalized.baseUrl === "https://api.deepseek.com/anthropic";
|
|
21627
21748
|
if (!normalized.apiKey && previousBaseUrl !== normalized.baseUrl && !officialDeepSeekMigration) throw new NodeUserSettingsError("SETTINGS_KEY_REQUIRED");
|
|
@@ -21648,6 +21769,7 @@ function applyMainCategory(raw, input) {
|
|
|
21648
21769
|
}
|
|
21649
21770
|
raw.env = environment;
|
|
21650
21771
|
delete raw.model;
|
|
21772
|
+
delete raw.effortLevel;
|
|
21651
21773
|
raw.availableModels = normalized.availableModels ?? [...new Set([normalized.model, normalized.opusModel, normalized.sonnetModel, normalized.haikuModel, normalized.subagentModel].filter(function present(value) {
|
|
21652
21774
|
return Boolean(value);
|
|
21653
21775
|
}))];
|
|
@@ -21656,7 +21778,7 @@ function applyMainCategory(raw, input) {
|
|
|
21656
21778
|
if (normalized.alwaysThinkingEnabled === void 0) delete raw.alwaysThinkingEnabled;
|
|
21657
21779
|
else raw.alwaysThinkingEnabled = normalized.alwaysThinkingEnabled;
|
|
21658
21780
|
}
|
|
21659
|
-
function applyWebSearch(raw, input) {
|
|
21781
|
+
function applyWebSearch(raw, input, env) {
|
|
21660
21782
|
if (typeof input.enabled !== "boolean" || typeof input.useMainKey !== "boolean") throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
|
|
21661
21783
|
if (!input.enabled) {
|
|
21662
21784
|
raw.webSearch = false;
|
|
@@ -21666,15 +21788,19 @@ function applyWebSearch(raw, input) {
|
|
|
21666
21788
|
const baseUrl = (0, import_core19.normalizeProviderBaseUrl)(input.baseUrl);
|
|
21667
21789
|
const model = parseSettingString(input.model);
|
|
21668
21790
|
const environment = { ...isRecord4(raw.env) ? raw.env : {} };
|
|
21669
|
-
const
|
|
21670
|
-
const
|
|
21791
|
+
const settings = (0, import_core19.resolveAutopilotSettings)([{ scope: "user", value: raw }]);
|
|
21792
|
+
const mainRoute = settings.modelRef && settings.providerRoutes[settings.modelRef.provider];
|
|
21793
|
+
const mainBaseUrl = mainRoute?.baseUrl ?? (0, import_core19.normalizeProviderBaseUrl)(environment.ANTHROPIC_BASE_URL);
|
|
21794
|
+
const mainRef = mainRoute?.credentialRef ?? { provider: "deepseek", key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" };
|
|
21795
|
+
const mainKey = mainRoute ? readMainCredential(environment, mainRef, env) : readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY");
|
|
21796
|
+
const canReuseMainKey = (!mainRoute || mainRoute.apiProtocol === "anthropic-messages") && mainBaseUrl === "https://api.deepseek.com/anthropic" && Boolean(mainKey);
|
|
21671
21797
|
if (input.useMainKey) {
|
|
21672
21798
|
if (!canReuseMainKey) throw new NodeUserSettingsError("SETTINGS_INPUT_INVALID");
|
|
21673
21799
|
raw.webSearch = {
|
|
21674
21800
|
provider: "deepseek",
|
|
21675
21801
|
baseUrl: "https://api.deepseek.com/anthropic",
|
|
21676
21802
|
model: "deepseek-flash",
|
|
21677
|
-
credentialRef:
|
|
21803
|
+
credentialRef: mainRef
|
|
21678
21804
|
};
|
|
21679
21805
|
return;
|
|
21680
21806
|
}
|
|
@@ -21719,6 +21845,7 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21719
21845
|
const homeDirectory = options.homeDirectory;
|
|
21720
21846
|
const settingsPath = resolveNodeUserSettingsPath(homeDirectory);
|
|
21721
21847
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
21848
|
+
const env = options.env ?? process.env;
|
|
21722
21849
|
async function save(update2, revision) {
|
|
21723
21850
|
return withFileLock(settingsPath, function writeSettings() {
|
|
21724
21851
|
ensureUserConfigDirectory({ ...homeDirectory ? { homeDirectory } : {} });
|
|
@@ -21734,6 +21861,11 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21734
21861
|
});
|
|
21735
21862
|
}
|
|
21736
21863
|
return {
|
|
21864
|
+
/** 预览草稿模型在当前 route 覆盖下的能力,不读取或返回 API Key。 */
|
|
21865
|
+
getMainModelCapabilities(input) {
|
|
21866
|
+
const normalized = normalizeMainInput(input);
|
|
21867
|
+
return resolveMainCapabilities(createMainRoute(readUserSettings(settingsPath).raw, normalized), normalized.model);
|
|
21868
|
+
},
|
|
21737
21869
|
/** 用户主动刷新时调用 DeepSeek 官方目录;无凭据、失败或异常响应均使用维护目录。 */
|
|
21738
21870
|
async refreshMainModelCatalog() {
|
|
21739
21871
|
const maintained = ["deepseek-v4-pro[1m]", "deepseek-v4-flash"];
|
|
@@ -21765,10 +21897,11 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21765
21897
|
const resolved = (0, import_core19.resolveAutopilotSettings)([{ scope: "user", value: raw }]);
|
|
21766
21898
|
const { blocking, permissions } = splitDiagnostics(resolved.diagnostics);
|
|
21767
21899
|
if (blocking.length > 0) throw new NodeUserSettingsError("SETTINGS_INVALID", safeDiagnostic(blocking[0]));
|
|
21768
|
-
const
|
|
21900
|
+
const mainRoute = resolved.modelRef && resolved.providerRoutes[resolved.modelRef.provider];
|
|
21901
|
+
const mainBaseUrl = mainRoute?.baseUrl ?? resolved.firstParty.baseUrl ?? "https://api.deepseek.com/anthropic";
|
|
21769
21902
|
const mainModel = resolved.modelRef?.modelId ?? "deepseek-v4-flash";
|
|
21770
|
-
const mainKey = readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY");
|
|
21771
|
-
const search = resolved.webSearch ?? (!resolved.webSearchDisabled && mainKey && mainBaseUrl === "https://api.deepseek.com/anthropic" ? { provider: "deepseek", baseUrl: "https://api.deepseek.com/anthropic", model: "deepseek-flash", credentialRef: { key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" } } : void 0);
|
|
21903
|
+
const mainKey = mainRoute ? readMainCredential(environment, mainRoute.credentialRef, env) : readEnvironmentKey(environment, "ANTHROPIC_AUTH_TOKEN") ?? readEnvironmentKey(environment, "ANTHROPIC_API_KEY");
|
|
21904
|
+
const search = resolved.webSearch ?? (!resolved.webSearchDisabled && !mainRoute && mainKey && mainBaseUrl === "https://api.deepseek.com/anthropic" ? { provider: "deepseek", baseUrl: "https://api.deepseek.com/anthropic", model: "deepseek-flash", credentialRef: { key: "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" } } : void 0);
|
|
21772
21905
|
const searchKeyName = search?.credentialRef.key;
|
|
21773
21906
|
const searchKey = readEnvironmentKey(environment, searchKeyName) ?? (searchKeyName === "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN" ? mainKey : void 0);
|
|
21774
21907
|
const rag = {};
|
|
@@ -21786,16 +21919,20 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21786
21919
|
return {
|
|
21787
21920
|
revision: revisionOf(current.original),
|
|
21788
21921
|
main: {
|
|
21789
|
-
provider: mainBaseUrl === "https://api.deepseek.com/anthropic" ? "deepseek" : "custom",
|
|
21922
|
+
provider: mainBaseUrl === "https://api.deepseek.com/anthropic" || mainRoute?.compatibilityPreset === "deepseek" ? "deepseek" : "custom",
|
|
21923
|
+
apiProtocol: mainRoute?.apiProtocol ?? "anthropic-messages",
|
|
21924
|
+
...mainRoute?.compatibilityPreset ? { compatibilityPreset: mainRoute.compatibilityPreset } : {},
|
|
21790
21925
|
baseUrl: mainBaseUrl,
|
|
21791
21926
|
model: mainModel,
|
|
21792
21927
|
configured: Boolean(mainKey),
|
|
21793
|
-
availableModels:
|
|
21928
|
+
availableModels: mainRoute ? mainRoute.models.map(function modelId(model) {
|
|
21929
|
+
return model.id;
|
|
21930
|
+
}) : resolved.availableModels.length > 0 ? [...resolved.availableModels] : ["deepseek-v4-flash", "deepseek-v4-pro[1m]"],
|
|
21794
21931
|
opusModel: typeof environment.ANTHROPIC_DEFAULT_OPUS_MODEL === "string" ? environment.ANTHROPIC_DEFAULT_OPUS_MODEL : void 0,
|
|
21795
21932
|
sonnetModel: typeof environment.ANTHROPIC_DEFAULT_SONNET_MODEL === "string" ? environment.ANTHROPIC_DEFAULT_SONNET_MODEL : void 0,
|
|
21796
21933
|
haikuModel: typeof environment.ANTHROPIC_DEFAULT_HAIKU_MODEL === "string" ? environment.ANTHROPIC_DEFAULT_HAIKU_MODEL : void 0,
|
|
21797
21934
|
subagentModel: resolved.firstParty.subagentModelId,
|
|
21798
|
-
effort:
|
|
21935
|
+
effort: resolved.reasoningProfile?.effort ?? "auto",
|
|
21799
21936
|
maxOutputTokens: resolved.firstParty.maxOutputTokens,
|
|
21800
21937
|
compactWindow: resolved.firstParty.compactWindow,
|
|
21801
21938
|
timeoutMs: resolved.firstParty.timeoutMs,
|
|
@@ -21803,7 +21940,7 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21803
21940
|
},
|
|
21804
21941
|
search: {
|
|
21805
21942
|
enabled: Boolean(search),
|
|
21806
|
-
useMainKey: searchKeyName === "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN",
|
|
21943
|
+
useMainKey: mainRoute ? mainRoute.apiProtocol === "anthropic-messages" && mainRoute.baseUrl === "https://api.deepseek.com/anthropic" && searchKeyName === mainRoute.credentialRef.key : searchKeyName === "USER_SETTINGS_ANTHROPIC_AUTH_TOKEN",
|
|
21807
21944
|
provider: search?.provider ?? "deepseek",
|
|
21808
21945
|
baseUrl: search?.baseUrl ?? "https://api.deepseek.com",
|
|
21809
21946
|
model: search?.model ?? "deepseek-v4-flash",
|
|
@@ -21821,7 +21958,7 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21821
21958
|
/** 保存主模型分类并执行旧 route/哈希凭据迁移。 */
|
|
21822
21959
|
saveMain(input, revision) {
|
|
21823
21960
|
return save(function updateMain(raw) {
|
|
21824
|
-
applyMainCategory(raw, input);
|
|
21961
|
+
applyMainCategory(raw, input, env);
|
|
21825
21962
|
}, revision);
|
|
21826
21963
|
},
|
|
21827
21964
|
/** 原子保存设置中心的主模型分类,包含已经独立化的 Search 连接。 */
|
|
@@ -21830,8 +21967,8 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21830
21967
|
return key2 !== "main" && key2 !== "search";
|
|
21831
21968
|
})) return Promise.reject(new NodeUserSettingsError("SETTINGS_INPUT_INVALID"));
|
|
21832
21969
|
return save(function updateMainAndSearch(raw) {
|
|
21833
|
-
applyMainCategory(raw, input.main);
|
|
21834
|
-
applyWebSearch(raw, input.search);
|
|
21970
|
+
applyMainCategory(raw, input.main, env);
|
|
21971
|
+
applyWebSearch(raw, input.search, env);
|
|
21835
21972
|
}, revision);
|
|
21836
21973
|
},
|
|
21837
21974
|
/** 增量保存 RAG 分类;未提交角色保持不变。 */
|
|
@@ -21849,15 +21986,15 @@ function createNodeUserSettingsService(options = {}) {
|
|
|
21849
21986
|
// src/node/capabilities/memory-retriever.ts
|
|
21850
21987
|
var import_node_crypto14 = __toESM(require("node:crypto"));
|
|
21851
21988
|
var import_node_fs31 = __toESM(require("node:fs"));
|
|
21852
|
-
var
|
|
21989
|
+
var import_node_path24 = __toESM(require("node:path"));
|
|
21853
21990
|
function getNodeMemoryWorkspaceId(workspaceRoot) {
|
|
21854
21991
|
return import_node_crypto14.default.createHash("sha256").update(import_node_fs31.default.realpathSync.native(workspaceRoot).toLowerCase()).digest("hex").slice(0, 24);
|
|
21855
21992
|
}
|
|
21856
21993
|
function getNodeMemoryDirectory(stateRoot, workspaceRoot) {
|
|
21857
|
-
return
|
|
21994
|
+
return import_node_path24.default.join(import_node_path24.default.resolve(stateRoot), "memory", getNodeMemoryWorkspaceId(workspaceRoot));
|
|
21858
21995
|
}
|
|
21859
21996
|
function getLegacyWebMemoryDirectory(workspaceRoot, cwd = process.cwd()) {
|
|
21860
|
-
return
|
|
21997
|
+
return import_node_path24.default.join(import_node_path24.default.resolve(cwd), ".local", "agent", "workspaces", getNodeMemoryWorkspaceId(workspaceRoot), "memory");
|
|
21861
21998
|
}
|
|
21862
21999
|
function retrieveNodeMemories(_stateRoot, _workspaceRoot, _query, _maxItems = 5) {
|
|
21863
22000
|
return [];
|
|
@@ -21865,10 +22002,10 @@ function retrieveNodeMemories(_stateRoot, _workspaceRoot, _query, _maxItems = 5)
|
|
|
21865
22002
|
|
|
21866
22003
|
// src/node/trust-policy.ts
|
|
21867
22004
|
var import_node_fs32 = __toESM(require("node:fs"));
|
|
21868
|
-
var
|
|
22005
|
+
var import_node_path25 = __toESM(require("node:path"));
|
|
21869
22006
|
function createNodeTrustStore(options) {
|
|
21870
22007
|
const trustRoot = resolveNodeTrustRoot({ stateRoot: options.stateRoot, trustRoot: options.trustRoot });
|
|
21871
|
-
const trustFile =
|
|
22008
|
+
const trustFile = import_node_path25.default.join(trustRoot, "trust.json");
|
|
21872
22009
|
const now = options.now ?? (() => Date.now());
|
|
21873
22010
|
function ensureDir() {
|
|
21874
22011
|
import_node_fs32.default.mkdirSync(trustRoot, { recursive: true });
|
|
@@ -21979,10 +22116,10 @@ function createNodeTrustPolicy(options) {
|
|
|
21979
22116
|
|
|
21980
22117
|
// src/node/workspace-registry.ts
|
|
21981
22118
|
var import_node_fs33 = __toESM(require("node:fs"));
|
|
21982
|
-
var
|
|
22119
|
+
var import_node_path26 = __toESM(require("node:path"));
|
|
21983
22120
|
function createNodeWorkspaceRegistry(options = {}) {
|
|
21984
22121
|
const globalStateRoot = resolveNodeGlobalStateRoot({ globalStateRoot: options.globalStateRoot, cwd: options.cwd });
|
|
21985
|
-
const registryPath =
|
|
22122
|
+
const registryPath = import_node_path26.default.join(globalStateRoot, "workspace-registry.json");
|
|
21986
22123
|
const now = options.now ?? (() => Date.now());
|
|
21987
22124
|
function load2() {
|
|
21988
22125
|
if (!import_node_fs33.default.existsSync(registryPath)) return [];
|
|
@@ -22010,7 +22147,7 @@ function createNodeWorkspaceRegistry(options = {}) {
|
|
|
22010
22147
|
const next = {
|
|
22011
22148
|
workspaceId,
|
|
22012
22149
|
workspaceRoot: canonicalRoot,
|
|
22013
|
-
displayName:
|
|
22150
|
+
displayName: import_node_path26.default.basename(canonicalRoot) || canonicalRoot,
|
|
22014
22151
|
lastOpenedAt: now()
|
|
22015
22152
|
};
|
|
22016
22153
|
const entries2 = load2().filter(function removeExisting(entry) {
|
|
@@ -22417,6 +22554,11 @@ function createNodeThreadRunner(options) {
|
|
|
22417
22554
|
stop,
|
|
22418
22555
|
kick,
|
|
22419
22556
|
registerExecution,
|
|
22557
|
+
listExecutions: function listExecutions() {
|
|
22558
|
+
return [...active.values()].map(function identity(record) {
|
|
22559
|
+
return { threadId: record.threadId, turnId: record.turnId };
|
|
22560
|
+
});
|
|
22561
|
+
},
|
|
22420
22562
|
isRunning: function isRunning() {
|
|
22421
22563
|
return running;
|
|
22422
22564
|
},
|
|
@@ -22426,14 +22568,72 @@ function createNodeThreadRunner(options) {
|
|
|
22426
22568
|
};
|
|
22427
22569
|
}
|
|
22428
22570
|
|
|
22571
|
+
// src/node/desktop-status-protocol.ts
|
|
22572
|
+
var DESKTOP_STATUS_VERSION = 1;
|
|
22573
|
+
var DESKTOP_STATUS_FRAME_BYTES = 64 * 1024;
|
|
22574
|
+
var DESKTOP_STATUS_QUEUE_BYTES = 256 * 1024;
|
|
22575
|
+
function isDesktopStatusId(value) {
|
|
22576
|
+
return typeof value === "string" && /^[a-zA-Z0-9:_-]{1,160}$/.test(value);
|
|
22577
|
+
}
|
|
22578
|
+
function fields(value, required, optional = []) {
|
|
22579
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && required.every(function present(key2) {
|
|
22580
|
+
return Object.prototype.hasOwnProperty.call(value, key2);
|
|
22581
|
+
}) && Object.keys(value).every(function allowed(key2) {
|
|
22582
|
+
return required.includes(key2) || optional.includes(key2);
|
|
22583
|
+
});
|
|
22584
|
+
}
|
|
22585
|
+
function optionalEnum(value, values) {
|
|
22586
|
+
return value === void 0 || typeof value === "string" && values.includes(value);
|
|
22587
|
+
}
|
|
22588
|
+
function isDesktopSessionStatus(value) {
|
|
22589
|
+
if (!fields(value, ["sessionId", "selected", "relation", "freshness", "status", "lastSeq"], ["turnId", "execution", "waiting", "result", "interaction", "continuation", "recoverable"])) return false;
|
|
22590
|
+
return isDesktopStatusId(value.sessionId) && (value.turnId === void 0 || isDesktopStatusId(value.turnId)) && typeof value.selected === "boolean" && ["opened", "locallyDriven", "relatedObserved"].includes(value.relation) && ["fresh", "unknown"].includes(value.freshness) && ["idle", "running", "waiting_approval", "waiting_user_input", "completed", "failed", "interrupted"].includes(value.status) && Number.isSafeInteger(value.lastSeq) && value.lastSeq >= 0 && optionalEnum(value.execution, ["active", "inactive", "unconfirmed", "lost"]) && optionalEnum(value.waiting, ["approval", "user_input", "threads"]) && optionalEnum(value.result, ["completed", "failed", "interrupted", "limit_reached"]) && optionalEnum(value.interaction, ["pending", "decided", "expired", "unconfirmed"]) && optionalEnum(value.continuation, ["pending", "applied", "rejected", "claimed", "executing", "completed", "failed"]) && (value.recoverable === void 0 || typeof value.recoverable === "boolean");
|
|
22591
|
+
}
|
|
22592
|
+
function workspace(value) {
|
|
22593
|
+
return fields(value, ["workspaceId", "stateRootId", "projectId", "displayName"]) && isDesktopStatusId(value.workspaceId) && isDesktopStatusId(value.stateRootId) && isDesktopStatusId(value.projectId) && typeof value.displayName === "string" && value.displayName.length <= 80 && !/[\x00-\x1f\x7f/\\]/.test(value.displayName);
|
|
22594
|
+
}
|
|
22595
|
+
function isDesktopStatusFrame(value) {
|
|
22596
|
+
if (!value || typeof value !== "object") return false;
|
|
22597
|
+
const v = value;
|
|
22598
|
+
const common2 = ["protocolVersion", "desktopInstanceId", "paneId", "generation", "apInstanceId", "seq", "type"];
|
|
22599
|
+
if (v.protocolVersion !== 1 || !isDesktopStatusId(v.desktopInstanceId) || !isDesktopStatusId(v.paneId) || !isDesktopStatusId(v.apInstanceId) || !Number.isSafeInteger(v.generation) || v.generation < 1 || !Number.isSafeInteger(v.seq) || v.seq < 1) return false;
|
|
22600
|
+
if (v.type === "hello") return fields(v, [...common2, "token", "cliVersion"]) && typeof v.token === "string" && /^[0-9a-f]{64}$/.test(v.token) && typeof v.cliVersion === "string" && /^\d+\.\d+\.\d+[-\w.]*$/.test(v.cliVersion);
|
|
22601
|
+
if (v.type === "heartbeat" || v.type === "ap_exiting") return fields(v, common2);
|
|
22602
|
+
return v.type === "snapshot" && fields(v, [...common2, "snapshotId", "part", "final", "lifecycle", "sessions"], ["workspace"]) && isDesktopStatusId(v.snapshotId) && Number.isSafeInteger(v.part) && v.part >= 0 && typeof v.final === "boolean" && ["starting", "ready"].includes(v.lifecycle) && (v.workspace === void 0 || workspace(v.workspace)) && (v.lifecycle !== "ready" || v.workspace !== void 0) && Array.isArray(v.sessions) && v.sessions.length <= 128 && v.sessions.every(isDesktopSessionStatus) && (v.lifecycle !== "starting" || v.sessions.length === 0 && v.workspace === void 0);
|
|
22603
|
+
}
|
|
22604
|
+
function isDesktopStatusReply(value) {
|
|
22605
|
+
return fields(value, ["type", "seq"]) && ["accepted", "ack", "resync_required"].includes(value.type) && Number.isSafeInteger(value.seq) && value.seq >= 0;
|
|
22606
|
+
}
|
|
22607
|
+
var DesktopStatusLines = class {
|
|
22608
|
+
constructor() {
|
|
22609
|
+
this.pending = Buffer.alloc(0);
|
|
22610
|
+
}
|
|
22611
|
+
push(chunk) {
|
|
22612
|
+
const values = [];
|
|
22613
|
+
let offset = 0;
|
|
22614
|
+
while (offset < chunk.length) {
|
|
22615
|
+
const newline = chunk.indexOf(10, offset);
|
|
22616
|
+
const end = newline < 0 ? chunk.length : newline;
|
|
22617
|
+
if (this.pending.length + end - offset > DESKTOP_STATUS_FRAME_BYTES) throw new Error("STATUS_FRAME_INVALID");
|
|
22618
|
+
this.pending = Buffer.concat([this.pending, chunk.subarray(offset, end)]);
|
|
22619
|
+
if (newline < 0) break;
|
|
22620
|
+
const line = new TextDecoder("utf-8", { fatal: true }).decode(this.pending);
|
|
22621
|
+
this.pending = Buffer.alloc(0);
|
|
22622
|
+
values.push(JSON.parse(line));
|
|
22623
|
+
offset = newline + 1;
|
|
22624
|
+
}
|
|
22625
|
+
return values;
|
|
22626
|
+
}
|
|
22627
|
+
};
|
|
22628
|
+
|
|
22429
22629
|
// src/node/thread-handoff.ts
|
|
22430
22630
|
var import_node_crypto16 = require("node:crypto");
|
|
22431
22631
|
var import_node_fs34 = __toESM(require("node:fs"));
|
|
22432
|
-
var
|
|
22632
|
+
var import_node_path27 = __toESM(require("node:path"));
|
|
22433
22633
|
var HANDOFF_DIRECTORY = ".autopilot";
|
|
22434
22634
|
function assertWithinRoot(root, candidate) {
|
|
22435
|
-
const relative =
|
|
22436
|
-
if (!relative || relative.startsWith(`..${
|
|
22635
|
+
const relative = import_node_path27.default.relative(root, candidate);
|
|
22636
|
+
if (!relative || relative.startsWith(`..${import_node_path27.default.sep}`) || relative === ".." || import_node_path27.default.isAbsolute(relative)) {
|
|
22437
22637
|
throw new Error("THREAD_HANDOFF_WRITE_FAILED");
|
|
22438
22638
|
}
|
|
22439
22639
|
}
|
|
@@ -22441,13 +22641,13 @@ function sha2562(content) {
|
|
|
22441
22641
|
return (0, import_node_crypto16.createHash)("sha256").update(content, "utf8").digest("hex");
|
|
22442
22642
|
}
|
|
22443
22643
|
function createNodeThreadHandoffWriter(options) {
|
|
22444
|
-
const workspaceRoot =
|
|
22644
|
+
const workspaceRoot = import_node_path27.default.resolve(options.workspaceRoot);
|
|
22445
22645
|
function resolveTarget(handoffId) {
|
|
22446
22646
|
if (!/^[0-9a-f]{16,64}$/.test(handoffId)) throw new Error("THREAD_HANDOFF_WRITE_FAILED");
|
|
22447
22647
|
const realRoot = import_node_fs34.default.realpathSync(workspaceRoot);
|
|
22448
|
-
const directory =
|
|
22648
|
+
const directory = import_node_path27.default.resolve(realRoot, HANDOFF_DIRECTORY);
|
|
22449
22649
|
assertWithinRoot(realRoot, directory);
|
|
22450
|
-
const filePath =
|
|
22650
|
+
const filePath = import_node_path27.default.join(directory, `thread-passdown-${handoffId}.md`);
|
|
22451
22651
|
assertWithinRoot(realRoot, filePath);
|
|
22452
22652
|
return { directory, filePath };
|
|
22453
22653
|
}
|
|
@@ -22491,6 +22691,10 @@ function createNodeStateRootId(stateRoot) {
|
|
|
22491
22691
|
DEFAULT_COMPACT_TARGET_RATIO,
|
|
22492
22692
|
DEFAULT_COMPACT_TRIGGER_RATIO,
|
|
22493
22693
|
DEFAULT_CONTEXT_WINDOW_TOKENS,
|
|
22694
|
+
DESKTOP_STATUS_FRAME_BYTES,
|
|
22695
|
+
DESKTOP_STATUS_QUEUE_BYTES,
|
|
22696
|
+
DESKTOP_STATUS_VERSION,
|
|
22697
|
+
DesktopStatusLines,
|
|
22494
22698
|
LOCAL_HUMAN_PRINCIPAL_ID,
|
|
22495
22699
|
NODE_CHAT_KNOWLEDGE_SPACE_ID,
|
|
22496
22700
|
NODE_STATE_SCHEMA_VERSION,
|
|
@@ -22553,6 +22757,10 @@ function createNodeStateRootId(stateRoot) {
|
|
|
22553
22757
|
getNodeStatePaths,
|
|
22554
22758
|
getNodeStateSchemaDiagnostic,
|
|
22555
22759
|
initializeNodeStateRoot,
|
|
22760
|
+
isDesktopSessionStatus,
|
|
22761
|
+
isDesktopStatusFrame,
|
|
22762
|
+
isDesktopStatusId,
|
|
22763
|
+
isDesktopStatusReply,
|
|
22556
22764
|
isSafeSettingsFile,
|
|
22557
22765
|
loadMcpConfigFromWorkspace,
|
|
22558
22766
|
resolveNodeChatStatePaths,
|
|
@@ -22562,5 +22770,6 @@ function createNodeStateRootId(stateRoot) {
|
|
|
22562
22770
|
resolveNodeTrustRoot,
|
|
22563
22771
|
resolveNodeUserSettingsPath,
|
|
22564
22772
|
retrieveNodeMemories,
|
|
22565
|
-
serializePosixCommand
|
|
22773
|
+
serializePosixCommand,
|
|
22774
|
+
withNodeRuntimeOwner
|
|
22566
22775
|
});
|