@linxin666/dsh-client-ui-browser-view 0.4.15 → 0.4.17
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.i18n.yaml +2 -2
- package/README.md +9 -5
- package/README.zh.md +9 -5
- package/lib/client.js +126 -31
- package/lib/client.js.map +1 -1
- package/lib/index.js +316 -71
- package/lib/types/client/BrowserViewSettingsCard.d.ts +2 -0
- package/lib/types/client/locales.d.ts +4 -0
- package/lib/types/core/cdp.d.ts +29 -5
- package/lib/types/core/tabs.d.ts +24 -0
- package/lib/types/host/config.d.ts +3 -0
- package/lib/types/host/service.d.ts +86 -2
- package/package.json +16 -16
package/lib/index.js
CHANGED
|
@@ -46,14 +46,14 @@ var CdpError = class extends Error {
|
|
|
46
46
|
*/
|
|
47
47
|
var CdpClient = class CdpClient {
|
|
48
48
|
socket;
|
|
49
|
-
|
|
49
|
+
commandTimeoutMs;
|
|
50
50
|
pending = /* @__PURE__ */ new Map();
|
|
51
51
|
listeners = /* @__PURE__ */ new Map();
|
|
52
52
|
nextId = 1;
|
|
53
53
|
closedReason;
|
|
54
|
-
constructor(socket,
|
|
54
|
+
constructor(socket, commandTimeoutMs) {
|
|
55
55
|
this.socket = socket;
|
|
56
|
-
this.
|
|
56
|
+
this.commandTimeoutMs = commandTimeoutMs;
|
|
57
57
|
socket.on("message", (data) => {
|
|
58
58
|
this.handleMessage(data);
|
|
59
59
|
});
|
|
@@ -67,13 +67,13 @@ var CdpClient = class CdpClient {
|
|
|
67
67
|
/**
|
|
68
68
|
* Open a client against an already-discovered DevTools endpoint.
|
|
69
69
|
* @param url - `webSocketDebuggerUrl` from `/json/version`.
|
|
70
|
-
* @param options - command
|
|
70
|
+
* @param options - handshake and per-command deadlines, independently.
|
|
71
71
|
* @returns a connected client.
|
|
72
72
|
* @throws CdpError when the socket cannot be established in time.
|
|
73
73
|
*/
|
|
74
74
|
static async connect(url, options = {}) {
|
|
75
|
-
const
|
|
76
|
-
const socket = new WebSocket$1(url, { handshakeTimeout:
|
|
75
|
+
const commandTimeoutMs = options.commandTimeoutMs ?? 3e4;
|
|
76
|
+
const socket = new WebSocket$1(url, { handshakeTimeout: options.handshakeTimeoutMs ?? 3e4 });
|
|
77
77
|
await new Promise((resolve, reject) => {
|
|
78
78
|
const cleanup = () => {
|
|
79
79
|
socket.off("open", onOpen);
|
|
@@ -90,7 +90,11 @@ var CdpClient = class CdpClient {
|
|
|
90
90
|
socket.once("open", onOpen);
|
|
91
91
|
socket.once("error", onError);
|
|
92
92
|
});
|
|
93
|
-
return new CdpClient(socket,
|
|
93
|
+
return new CdpClient(socket, commandTimeoutMs);
|
|
94
|
+
}
|
|
95
|
+
/** Whether the socket is gone and every later command will be refused. */
|
|
96
|
+
get closed() {
|
|
97
|
+
return this.closedReason !== void 0;
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
100
|
* Address one protocol command.
|
|
@@ -111,8 +115,8 @@ var CdpClient = class CdpClient {
|
|
|
111
115
|
return new Promise((resolve, reject) => {
|
|
112
116
|
const timer = setTimeout(() => {
|
|
113
117
|
this.pending.delete(id);
|
|
114
|
-
reject(new CdpError(method, -1, `timed out after ${this.
|
|
115
|
-
}, this.
|
|
118
|
+
reject(new CdpError(method, -1, `timed out after ${this.commandTimeoutMs} ms`));
|
|
119
|
+
}, this.commandTimeoutMs);
|
|
116
120
|
this.pending.set(id, {
|
|
117
121
|
method,
|
|
118
122
|
timer,
|
|
@@ -711,6 +715,33 @@ var TabManager = class {
|
|
|
711
715
|
if (record === void 0) throw new Error(`unknown tab "${tabId}"; call browser_tabs to see the open tabs`);
|
|
712
716
|
return this.view(record);
|
|
713
717
|
}
|
|
718
|
+
/**
|
|
719
|
+
* Record that a tool call just worked on this tab.
|
|
720
|
+
*
|
|
721
|
+
* Only the host's own tool paths call this. A panel that keeps watching a
|
|
722
|
+
* page is not activity: a page nobody drives must still age out, or a viewer
|
|
723
|
+
* left open on one tab keeps the cleanup from ever running.
|
|
724
|
+
* @param tabId - the tab the call used; an id that closed meanwhile is ignored.
|
|
725
|
+
*/
|
|
726
|
+
touch(tabId) {
|
|
727
|
+
const record = this.tabs.get(tabId);
|
|
728
|
+
if (record === void 0) return;
|
|
729
|
+
record.lastActiveAt = this.now();
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Tabs DSH opened itself that no tool call has touched within `maxAgeMs`.
|
|
733
|
+
*
|
|
734
|
+
* Adopted real-browser pages are never candidates: they belong to the person
|
|
735
|
+
* using that browser, and the real-browser contract closes them only when a
|
|
736
|
+
* caller names the tab explicitly.
|
|
737
|
+
* @param maxAgeMs - idle window in milliseconds; zero or less selects nothing.
|
|
738
|
+
* @returns ids in creation order.
|
|
739
|
+
*/
|
|
740
|
+
idleCandidates(maxAgeMs) {
|
|
741
|
+
if (!(maxAgeMs > 0)) return [];
|
|
742
|
+
const nowMs = this.now();
|
|
743
|
+
return [...this.tabs.values()].filter((record) => record.origin === "created" && nowMs - record.lastActiveAt >= maxAgeMs).map((record) => record.id);
|
|
744
|
+
}
|
|
714
745
|
/** Internal record access for the layers that need the CDP session. */
|
|
715
746
|
sessionOf(tabId) {
|
|
716
747
|
const record = this.tabs.get(tabId);
|
|
@@ -796,6 +827,7 @@ var TabManager = class {
|
|
|
796
827
|
loaderId: void 0,
|
|
797
828
|
ownerSessionId: void 0,
|
|
798
829
|
origin,
|
|
830
|
+
lastActiveAt: this.now(),
|
|
799
831
|
console: [],
|
|
800
832
|
network: [],
|
|
801
833
|
pendingRequests: /* @__PURE__ */ new Map(),
|
|
@@ -2096,14 +2128,23 @@ async function openIsolatedSession(options) {
|
|
|
2096
2128
|
}
|
|
2097
2129
|
};
|
|
2098
2130
|
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Handshake deadline for an external browser. Its debugger port is already
|
|
2133
|
+
* listening, so an endpoint that does not complete the upgrade within this
|
|
2134
|
+
* window is wedged; the per-command budget is a separate setting and is left at
|
|
2135
|
+
* `CDP_COMMAND_TIMEOUT_MS`, exactly as in the isolated mode.
|
|
2136
|
+
*/
|
|
2137
|
+
const REAL_BROWSER_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
2138
|
+
/** One day in milliseconds: the unit the idle-close window is configured in. */
|
|
2139
|
+
const DAY_MS = 1440 * 60 * 1e3;
|
|
2099
2140
|
/** Connect to an existing real browser without owning its process or tabs. */
|
|
2100
|
-
async function openExternalSession(options) {
|
|
2141
|
+
async function openExternalSession(options, seams = {}) {
|
|
2101
2142
|
const endpoint = parseCdpEndpoint(options.cdpEndpoint ?? "");
|
|
2143
|
+
const connect = seams.connect ?? CdpClient.connect;
|
|
2102
2144
|
let cdp;
|
|
2103
2145
|
let tabs;
|
|
2104
2146
|
try {
|
|
2105
|
-
|
|
2106
|
-
cdp = await CdpClient.connect(version.webSocketDebuggerUrl, { timeoutMs: 5e3 });
|
|
2147
|
+
cdp = await connect((await fetchCdpVersion(endpoint)).webSocketDebuggerUrl, { handshakeTimeoutMs: REAL_BROWSER_HANDSHAKE_TIMEOUT_MS });
|
|
2107
2148
|
tabs = new TabManager({
|
|
2108
2149
|
transport: cdp,
|
|
2109
2150
|
jpegQuality: options.jpegQuality,
|
|
@@ -2144,6 +2185,9 @@ var BrowserViewService = class {
|
|
|
2144
2185
|
openSession;
|
|
2145
2186
|
resolveConfig;
|
|
2146
2187
|
authenticatedUrl;
|
|
2188
|
+
idleCloseDays;
|
|
2189
|
+
sweepIntervalMs;
|
|
2190
|
+
idleTimer;
|
|
2147
2191
|
sinks = /* @__PURE__ */ new Set();
|
|
2148
2192
|
bindings = /* @__PURE__ */ new Map();
|
|
2149
2193
|
/**
|
|
@@ -2184,6 +2228,16 @@ var BrowserViewService = class {
|
|
|
2184
2228
|
this.openSession = options.openSession ?? openConfiguredSession;
|
|
2185
2229
|
this.resolveConfig = options.resolveConfig ?? (() => ({ mode: "isolated" }));
|
|
2186
2230
|
this.authenticatedUrl = options.authenticatedUrl;
|
|
2231
|
+
this.idleCloseDays = options.idleCloseDays ?? (() => 0);
|
|
2232
|
+
this.sweepIntervalMs = options.sweepIntervalMs ?? 6e5;
|
|
2233
|
+
if (this.sweepIntervalMs > 0) {
|
|
2234
|
+
const timer = setInterval(() => {
|
|
2235
|
+
this.sweepIdle().catch(() => void 0);
|
|
2236
|
+
}, this.sweepIntervalMs);
|
|
2237
|
+
const unref = timer.unref;
|
|
2238
|
+
if (typeof unref === "function") unref.call(timer);
|
|
2239
|
+
this.idleTimer = timer;
|
|
2240
|
+
}
|
|
2187
2241
|
}
|
|
2188
2242
|
/** Whether a browser is currently running. */
|
|
2189
2243
|
get running() {
|
|
@@ -2308,7 +2362,7 @@ var BrowserViewService = class {
|
|
|
2308
2362
|
*/
|
|
2309
2363
|
async closeOwnTabs(sessionId, tabId) {
|
|
2310
2364
|
if (sessionId === void 0) throw new Error("browser_close needs the calling session: with no session there is no tab this call may close");
|
|
2311
|
-
if (this.session === void 0) {
|
|
2365
|
+
if (this.session === void 0 || this.session.transport.closed) {
|
|
2312
2366
|
if (tabId === void 0 || tabId === "" || this.resolveConfig().mode !== "cdp") return [];
|
|
2313
2367
|
await this.requireSession();
|
|
2314
2368
|
}
|
|
@@ -2331,6 +2385,31 @@ var BrowserViewService = class {
|
|
|
2331
2385
|
return closed;
|
|
2332
2386
|
}
|
|
2333
2387
|
/**
|
|
2388
|
+
* Close the tabs no browser tool has touched for the configured idle window.
|
|
2389
|
+
*
|
|
2390
|
+
* Scope is what the real-browser contract allows: only tabs DSH created are
|
|
2391
|
+
* candidates, and a page adopted from the person's own browser is never closed
|
|
2392
|
+
* by a timer — that contract keeps adopted pages closable only through an
|
|
2393
|
+
* explicit `tab_id`. The window is read per sweep, so a settings edit applies
|
|
2394
|
+
* to the next one, and a host with no browser running closes nothing and
|
|
2395
|
+
* starts none: cleanup must never cost a process.
|
|
2396
|
+
* @returns ids of the tabs actually closed, in close order.
|
|
2397
|
+
*/
|
|
2398
|
+
async sweepIdle() {
|
|
2399
|
+
if (this.disposed) return [];
|
|
2400
|
+
const days = this.idleCloseDays();
|
|
2401
|
+
if (!(days > 0)) return [];
|
|
2402
|
+
const session = this.session;
|
|
2403
|
+
if (session === void 0 || session.transport.closed) return [];
|
|
2404
|
+
const closed = [];
|
|
2405
|
+
for (const tabId of session.tabs.idleCandidates(days * DAY_MS)) {
|
|
2406
|
+
if (!session.tabs.has(tabId)) continue;
|
|
2407
|
+
await this.closeTab(tabId).catch(() => void 0);
|
|
2408
|
+
if (!session.tabs.has(tabId)) closed.push(tabId);
|
|
2409
|
+
}
|
|
2410
|
+
return closed;
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2334
2413
|
* Resolve the tab a tool call from `sessionId` should act on.
|
|
2335
2414
|
*
|
|
2336
2415
|
* The order is a safety property, not a preference. An agent that lands on
|
|
@@ -2352,6 +2431,18 @@ var BrowserViewService = class {
|
|
|
2352
2431
|
*/
|
|
2353
2432
|
async tabFor(sessionId, tabId) {
|
|
2354
2433
|
const tabs = await this.requireTabs();
|
|
2434
|
+
const tab = await this.resolveTabFor(tabs, sessionId, tabId);
|
|
2435
|
+
tabs.touch(tab.id);
|
|
2436
|
+
return tab;
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Apply {@link tabFor}'s resolution order against an already open manager.
|
|
2440
|
+
* @param tabs - the live tab manager.
|
|
2441
|
+
* @param sessionId - calling agent session, when the host provides one.
|
|
2442
|
+
* @param tabId - explicit tab from the tool arguments.
|
|
2443
|
+
* @returns the tab the call should act on.
|
|
2444
|
+
*/
|
|
2445
|
+
async resolveTabFor(tabs, sessionId, tabId) {
|
|
2355
2446
|
if (tabId !== void 0 && tabId !== "") {
|
|
2356
2447
|
const found = tabs.list().find((tab) => tab.id === tabId);
|
|
2357
2448
|
if (found === void 0) throw new Error(`unknown tab "${tabId}"; call browser_tabs to see the open tabs`);
|
|
@@ -2653,7 +2744,7 @@ var BrowserViewService = class {
|
|
|
2653
2744
|
}
|
|
2654
2745
|
/** Open tabs, for `browser_tabs`. */
|
|
2655
2746
|
async listTabs() {
|
|
2656
|
-
if (this.session === void 0) {
|
|
2747
|
+
if (this.session === void 0 || this.session.transport.closed) {
|
|
2657
2748
|
if (this.resolveConfig().mode !== "cdp") return {
|
|
2658
2749
|
tabs: [],
|
|
2659
2750
|
activeTabId: null
|
|
@@ -2682,13 +2773,8 @@ var BrowserViewService = class {
|
|
|
2682
2773
|
async reconfigure() {
|
|
2683
2774
|
if (this.disposed) return;
|
|
2684
2775
|
this.generation += 1;
|
|
2685
|
-
const session = this.session;
|
|
2686
|
-
this.session = void 0;
|
|
2687
2776
|
this.opening = void 0;
|
|
2688
|
-
this.
|
|
2689
|
-
this.authTopUpSpent.clear();
|
|
2690
|
-
this.displayedTabId = null;
|
|
2691
|
-
this.selectionPinned = false;
|
|
2777
|
+
const session = this.forgetSession();
|
|
2692
2778
|
this.lastError = void 0;
|
|
2693
2779
|
if (session !== void 0) await session.dispose();
|
|
2694
2780
|
this.broadcast({
|
|
@@ -2706,6 +2792,10 @@ var BrowserViewService = class {
|
|
|
2706
2792
|
async dispose() {
|
|
2707
2793
|
if (this.disposed) return;
|
|
2708
2794
|
this.disposed = true;
|
|
2795
|
+
if (this.idleTimer !== void 0) {
|
|
2796
|
+
clearInterval(this.idleTimer);
|
|
2797
|
+
this.idleTimer = void 0;
|
|
2798
|
+
}
|
|
2709
2799
|
this.generation += 1;
|
|
2710
2800
|
this.opening = void 0;
|
|
2711
2801
|
const sinks = [...this.sinks];
|
|
@@ -2713,11 +2803,7 @@ var BrowserViewService = class {
|
|
|
2713
2803
|
for (const sink of sinks) try {
|
|
2714
2804
|
sink.close();
|
|
2715
2805
|
} catch {}
|
|
2716
|
-
const session = this.
|
|
2717
|
-
this.session = void 0;
|
|
2718
|
-
this.bindings.clear();
|
|
2719
|
-
this.displayedTabId = null;
|
|
2720
|
-
this.selectionPinned = false;
|
|
2806
|
+
const session = this.forgetSession();
|
|
2721
2807
|
if (session !== void 0) await session.dispose();
|
|
2722
2808
|
}
|
|
2723
2809
|
/** The action helpers' collaborator view: one transport, one tab manager. */
|
|
@@ -2737,11 +2823,37 @@ var BrowserViewService = class {
|
|
|
2737
2823
|
async requireTabs() {
|
|
2738
2824
|
return (await this.requireSession()).tabs;
|
|
2739
2825
|
}
|
|
2740
|
-
/**
|
|
2826
|
+
/**
|
|
2827
|
+
* Forget everything bound to the current session without disposing it: the
|
|
2828
|
+
* per-session tab bindings, the watched tab, the pinned selection and the
|
|
2829
|
+
* spent auth tickets all describe a browser that is going away.
|
|
2830
|
+
* @returns the session that was dropped, if any.
|
|
2831
|
+
*/
|
|
2832
|
+
forgetSession() {
|
|
2833
|
+
const session = this.session;
|
|
2834
|
+
this.session = void 0;
|
|
2835
|
+
this.bindings.clear();
|
|
2836
|
+
this.authTopUpSpent.clear();
|
|
2837
|
+
this.displayedTabId = null;
|
|
2838
|
+
this.selectionPinned = false;
|
|
2839
|
+
return session;
|
|
2840
|
+
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Resolve the live session, starting the browser on first use.
|
|
2843
|
+
*
|
|
2844
|
+
* A session whose transport has closed is dead even though its record still
|
|
2845
|
+
* exists: the external browser restarted, crashed, or dropped the socket, and
|
|
2846
|
+
* every command would reject with that one stale reason for the rest of the
|
|
2847
|
+
* host's life. The next call therefore drops it exactly the way a settings
|
|
2848
|
+
* change does and opens a replacement, so the caller recovers instead of
|
|
2849
|
+
* needing a reconfigure or a restart. The replacement goes through `opening`,
|
|
2850
|
+
* so concurrent callers share one session instead of opening two.
|
|
2851
|
+
*/
|
|
2741
2852
|
async requireSession() {
|
|
2742
2853
|
if (this.disposed) throw new Error("the browser view service is disposed");
|
|
2743
|
-
|
|
2744
|
-
if (
|
|
2854
|
+
const current = this.session;
|
|
2855
|
+
if (current !== void 0 && !current.transport.closed) return current;
|
|
2856
|
+
if (this.opening === void 0) this.opening = this.replaceSession(current);
|
|
2745
2857
|
const opening = this.opening;
|
|
2746
2858
|
try {
|
|
2747
2859
|
return await opening;
|
|
@@ -2749,6 +2861,29 @@ var BrowserViewService = class {
|
|
|
2749
2861
|
if (this.opening === opening) this.opening = void 0;
|
|
2750
2862
|
}
|
|
2751
2863
|
}
|
|
2864
|
+
/**
|
|
2865
|
+
* Drop a closed session and open its replacement.
|
|
2866
|
+
*
|
|
2867
|
+
* The cleanup is the settings-change cleanup: an external browser is only
|
|
2868
|
+
* detached, never closed, and its tabs stay open. A teardown that throws is
|
|
2869
|
+
* swallowed because the dead session has nothing left to deliver — its
|
|
2870
|
+
* failure must not be the reason no replacement starts.
|
|
2871
|
+
* @param stale - the dead session, or undefined for an ordinary first start.
|
|
2872
|
+
* @returns the live session.
|
|
2873
|
+
*/
|
|
2874
|
+
async replaceSession(stale) {
|
|
2875
|
+
if (stale === void 0) return await this.startSession();
|
|
2876
|
+
if (this.session === stale) this.forgetSession();
|
|
2877
|
+
await stale.dispose().catch(() => void 0);
|
|
2878
|
+
this.broadcast({
|
|
2879
|
+
v: 1,
|
|
2880
|
+
kind: "state",
|
|
2881
|
+
state: this.state()
|
|
2882
|
+
});
|
|
2883
|
+
const session = await this.startSession();
|
|
2884
|
+
if (this.sinks.size > 0) this.startStreaming().catch(() => void 0);
|
|
2885
|
+
return session;
|
|
2886
|
+
}
|
|
2752
2887
|
/** Start the browser once, recording failures for the panel. */
|
|
2753
2888
|
async startSession() {
|
|
2754
2889
|
const generation = this.generation;
|
|
@@ -2800,7 +2935,7 @@ var BrowserViewService = class {
|
|
|
2800
2935
|
}
|
|
2801
2936
|
/** Start the screencast for the tab the panel watches. */
|
|
2802
2937
|
async startStreaming() {
|
|
2803
|
-
const session = this.session ?? (this.resolveConfig().mode === "cdp" && this.sinks.size > 0 ? await this.requireSession() : void 0);
|
|
2938
|
+
const session = (this.session !== void 0 && !this.session.transport.closed ? this.session : void 0) ?? (this.resolveConfig().mode === "cdp" && this.sinks.size > 0 ? await this.requireSession() : void 0);
|
|
2804
2939
|
if (session === void 0 || this.sinks.size === 0) return;
|
|
2805
2940
|
const tabId = this.displayedOrDefault();
|
|
2806
2941
|
if (tabId === null) return;
|
|
@@ -3079,7 +3214,7 @@ function writeJson(res, status, body) {
|
|
|
3079
3214
|
res.end(text);
|
|
3080
3215
|
}
|
|
3081
3216
|
//#endregion
|
|
3082
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.
|
|
3217
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
|
|
3083
3218
|
/** The one Remote failure class shared by owners, the Gateway, and consumers. */
|
|
3084
3219
|
/**
|
|
3085
3220
|
* One Remote call failure: a real Error carrying its stable code and typed
|
|
@@ -3261,7 +3396,7 @@ function validateName(subject, value) {
|
|
|
3261
3396
|
if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
|
|
3262
3397
|
}
|
|
3263
3398
|
//#endregion
|
|
3264
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.
|
|
3399
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
|
|
3265
3400
|
/**
|
|
3266
3401
|
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
3267
3402
|
* that may still be streaming or from an already parsed object. Nothing is
|
|
@@ -4967,23 +5102,15 @@ defineMethod("transform", [
|
|
|
4967
5102
|
"preserve"
|
|
4968
5103
|
], ({ inner }, isInner) => inner.toString(isInner));
|
|
4969
5104
|
//#endregion
|
|
4970
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.
|
|
5105
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
|
|
4971
5106
|
/** Largest delay Node schedules without clamping it to one millisecond. */
|
|
4972
5107
|
const MAX_TIMER_DELAY_MS = 2147483647;
|
|
4973
5108
|
//#endregion
|
|
4974
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-
|
|
4975
|
-
/**
|
|
4976
|
-
* Detach and deep-freeze a message whose identity already exists.
|
|
4977
|
-
* @param message - complete message, including its stable identity.
|
|
4978
|
-
* @returns an immutable snapshot that preserves the identity.
|
|
4979
|
-
*/
|
|
4980
|
-
function freezeMessage(message) {
|
|
4981
|
-
return deepFreeze(structuredClone(message));
|
|
4982
|
-
}
|
|
5109
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-error/lib/index.js
|
|
4983
5110
|
/**
|
|
4984
5111
|
* Harness error base with a stable machine-routable code and chained cause.
|
|
4985
5112
|
* Package errors extend it so tool results and replay can retain failure class.
|
|
4986
|
-
* @module @deepseek-ai/dsh-
|
|
5113
|
+
* @module @deepseek-ai/dsh-error
|
|
4987
5114
|
*/
|
|
4988
5115
|
/**
|
|
4989
5116
|
* Base class for all harness errors. Carries a `code` (stable, programmatic —
|
|
@@ -5000,6 +5127,83 @@ var HarnessError = class extends Error {
|
|
|
5000
5127
|
this.name = new.target.name;
|
|
5001
5128
|
}
|
|
5002
5129
|
};
|
|
5130
|
+
//#endregion
|
|
5131
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-error@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_/node_modules/@deepseek-ai/dsh-llm/lib/index.js
|
|
5132
|
+
/**
|
|
5133
|
+
* Detach and deep-freeze a message whose identity already exists.
|
|
5134
|
+
* @param message - complete message, including its stable identity.
|
|
5135
|
+
* @returns an immutable snapshot that preserves the identity.
|
|
5136
|
+
*/
|
|
5137
|
+
function freezeMessage(message) {
|
|
5138
|
+
return deepFreeze(structuredClone(message));
|
|
5139
|
+
}
|
|
5140
|
+
/**
|
|
5141
|
+
* LLM failure codes and helpers over the shared Harness error base. The base
|
|
5142
|
+
* class lives in `@deepseek-ai/dsh-error` and is re-exported here, so both
|
|
5143
|
+
* import paths name the same class.
|
|
5144
|
+
* @module @deepseek-ai/dsh-llm/error
|
|
5145
|
+
*/
|
|
5146
|
+
/**
|
|
5147
|
+
* Every failure code the built-in providers and the LLM runtime raise. An entry
|
|
5148
|
+
* marked `retryChoice` is offered as a choice for a provider retry policy's
|
|
5149
|
+
* `retryableCodes`; being a choice does not make a code retried by default.
|
|
5150
|
+
*/
|
|
5151
|
+
const LLM_FAILURE_CODES = {
|
|
5152
|
+
ABORTED: {},
|
|
5153
|
+
ACCOUNT_QUOTA: {},
|
|
5154
|
+
ACCOUNT_SIGN_IN_REQUIRED: {},
|
|
5155
|
+
ACCOUNT_TOKEN_INVALID: {},
|
|
5156
|
+
AUTH: {},
|
|
5157
|
+
CLIENT_UPGRADE_REQUIRED: {},
|
|
5158
|
+
CONTEXT_WINDOW_EXCEEDED: {},
|
|
5159
|
+
DISCOVERY_FAILED: {},
|
|
5160
|
+
DISCOVERY_UNSUPPORTED: {},
|
|
5161
|
+
DUPLICATE_ADAPTER: {},
|
|
5162
|
+
DUPLICATE_DIRECTORY: {},
|
|
5163
|
+
DUPLICATE_DISCOVERY: {},
|
|
5164
|
+
EMPTY_RESPONSE: { retryChoice: true },
|
|
5165
|
+
FILES_API: {},
|
|
5166
|
+
IMAGE_OFFLOAD_REQUIRED: {},
|
|
5167
|
+
INVALID_ADAPTER: {},
|
|
5168
|
+
INVALID_CATALOG: {},
|
|
5169
|
+
INVALID_CONFIG: {},
|
|
5170
|
+
INVALID_CREDENTIAL: {},
|
|
5171
|
+
INVALID_DIRECTORY: {},
|
|
5172
|
+
INVALID_DISCOVERY: {},
|
|
5173
|
+
INVALID_MODEL_CONTEXT: {},
|
|
5174
|
+
INVALID_MODEL_INFO: {},
|
|
5175
|
+
INVALID_MODEL_MAX_TOKENS: {},
|
|
5176
|
+
INVALID_MODEL_REASONING: {},
|
|
5177
|
+
INVALID_PREPARED_CALL: {},
|
|
5178
|
+
INVALID_REPLAY_STATE: {},
|
|
5179
|
+
INVALID_REQUEST: {},
|
|
5180
|
+
INVALID_RESPONSE: {},
|
|
5181
|
+
MALFORMED_RESPONSE: { retryChoice: true },
|
|
5182
|
+
MISSING_CREDENTIAL: {},
|
|
5183
|
+
MODEL_SWITCH_COMPACTION_FAILED: {},
|
|
5184
|
+
MODEL_UNSUPPORTED: {},
|
|
5185
|
+
NO_ADAPTER: {},
|
|
5186
|
+
NO_CREDENTIAL_STORE: {},
|
|
5187
|
+
NO_DISCOVERY: {},
|
|
5188
|
+
PI_AI_ERROR: {},
|
|
5189
|
+
QUOTA: { retryChoice: true },
|
|
5190
|
+
RATE_LIMIT: { retryChoice: true },
|
|
5191
|
+
REGISTRATION_DISPOSED: {},
|
|
5192
|
+
REQUEST_EXTENSION: {},
|
|
5193
|
+
REQUEST_HEADERS: {},
|
|
5194
|
+
SERVER: { retryChoice: true },
|
|
5195
|
+
STREAM_CLOSED: { retryChoice: true },
|
|
5196
|
+
TIMEOUT: { retryChoice: true },
|
|
5197
|
+
TRANSPORT: { retryChoice: true },
|
|
5198
|
+
UNKNOWN: {},
|
|
5199
|
+
UNKNOWN_MODEL: {},
|
|
5200
|
+
UNSTORABLE_PROVIDER_ID: {},
|
|
5201
|
+
UNSUPPORTED_CONTENT: {},
|
|
5202
|
+
UNSUPPORTED_OPTION: {},
|
|
5203
|
+
UNSUPPORTED_REASONING_EFFORT: {}
|
|
5204
|
+
};
|
|
5205
|
+
/** The {@link LLM_FAILURE_CODES} entries marked as retry-policy choices, in definition order. */
|
|
5206
|
+
const RETRY_CODE_CHOICES = Object.freeze(Object.keys(LLM_FAILURE_CODES).filter((code) => "retryChoice" in LLM_FAILURE_CODES[code]));
|
|
5003
5207
|
/**
|
|
5004
5208
|
* Canonical provider-neutral code for a response that completed normally but
|
|
5005
5209
|
* carried no content blocks at all. Providers occasionally emit a degenerate
|
|
@@ -5033,14 +5237,14 @@ const DEFAULT_RETRYABLE_CODES = Object.freeze([
|
|
|
5033
5237
|
"TRANSPORT"
|
|
5034
5238
|
]);
|
|
5035
5239
|
const backoffSchema = Schema.object({
|
|
5036
|
-
initialDelayMs: Schema.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_INITIAL_DELAY_MS),
|
|
5037
|
-
maxDelayMs: Schema.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_MAX_DELAY_MS),
|
|
5240
|
+
initialDelayMs: Schema.number().min(Number.MIN_VALUE).max(MAX_TIMER_DELAY_MS).default(DEFAULT_INITIAL_DELAY_MS),
|
|
5241
|
+
maxDelayMs: Schema.number().min(Number.MIN_VALUE).max(MAX_TIMER_DELAY_MS).default(DEFAULT_MAX_DELAY_MS),
|
|
5038
5242
|
jitterRatio: Schema.number().min(0).max(1).default(DEFAULT_JITTER_RATIO)
|
|
5039
5243
|
});
|
|
5040
5244
|
const normalPolicySchema = Schema.object({
|
|
5041
5245
|
mode: Schema.const("normal").required(),
|
|
5042
5246
|
maxRetries: Schema.number().step(1).min(0).max(Number.MAX_SAFE_INTEGER).default(DEFAULT_MAX_RETRIES),
|
|
5043
|
-
retryableCodes: Schema.array(Schema.string()).default([...DEFAULT_RETRYABLE_CODES]),
|
|
5247
|
+
retryableCodes: Schema.array(Schema.union([...RETRY_CODE_CHOICES.map((code) => Schema.const(code)), Schema.string().min(1)])).min(1).default([...DEFAULT_RETRYABLE_CODES]),
|
|
5044
5248
|
backoff: backoffSchema
|
|
5045
5249
|
});
|
|
5046
5250
|
const alwaysPolicySchema = Schema.object({
|
|
@@ -5318,27 +5522,47 @@ function withoutDeveloperMessages(messages) {
|
|
|
5318
5522
|
const retained = messages.filter((message) => message.role !== "developer");
|
|
5319
5523
|
return retained.length === messages.length ? messages : retained;
|
|
5320
5524
|
}
|
|
5321
|
-
function toolDeclarations(
|
|
5525
|
+
function toolDeclarations(history) {
|
|
5322
5526
|
const declarations = new Map(history.tools.map((tool) => [tool.name, tool]));
|
|
5323
5527
|
for (const update of history.updates) for (const tool of update.additions) if (!declarations.has(tool.name)) declarations.set(tool.name, {
|
|
5324
5528
|
...tool,
|
|
5325
5529
|
deferLoading: true
|
|
5326
5530
|
});
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5531
|
+
return declarations;
|
|
5532
|
+
}
|
|
5533
|
+
/** Rebuild declarations on removals or additions to an empty set, where the request prefix changes. */
|
|
5534
|
+
function rebaseAdditionOnlyHistory(history, messages) {
|
|
5535
|
+
const available = new Map(history.tools.map((tool) => [tool.name, tool]));
|
|
5536
|
+
let baseline = history.tools;
|
|
5537
|
+
let retainedFrom = 0;
|
|
5538
|
+
for (const [index, update] of history.updates.entries()) {
|
|
5539
|
+
const additions = new Map(update.additions.map((tool) => [tool.name, tool]));
|
|
5540
|
+
let reset = available.size === 0 && additions.size > 0;
|
|
5541
|
+
for (const block of messages.get(update.messageId)) if (block.type === "tool-addition") {
|
|
5542
|
+
const { deferLoading: _loading, ...tool } = additions.get(block.toolName);
|
|
5543
|
+
available.set(tool.name, tool);
|
|
5544
|
+
} else if (block.type === "tool-removal") {
|
|
5545
|
+
reset = true;
|
|
5546
|
+
available.delete(block.toolName);
|
|
5547
|
+
}
|
|
5548
|
+
if (reset) {
|
|
5549
|
+
baseline = [...available.values()];
|
|
5550
|
+
retainedFrom = index + 1;
|
|
5551
|
+
}
|
|
5552
|
+
}
|
|
5553
|
+
return retainedFrom === 0 ? history : {
|
|
5554
|
+
tools: baseline,
|
|
5555
|
+
updates: history.updates.slice(retainedFrom)
|
|
5556
|
+
};
|
|
5337
5557
|
}
|
|
5338
5558
|
/**
|
|
5339
5559
|
* Construct provider declarations from session-folded history without changing logged active tools.
|
|
5340
5560
|
* Unsupported routes and incomplete history use current declarations without developer updates.
|
|
5341
|
-
* Explicitly deferred
|
|
5561
|
+
* Explicitly deferred declarations require an addition to activate them.
|
|
5562
|
+
* A rebuild makes previously activated declarations immediate; unactivated declarations stay deferred.
|
|
5563
|
+
* Addition-only routes rebuild when a tool is removed or tools are added to an empty set;
|
|
5564
|
+
* deferred declarations count as existing tools.
|
|
5565
|
+
* Later additions remain deferred and superseded tool blocks are omitted without dropping other content.
|
|
5342
5566
|
* @param messages - complete request inputs, or the prefix selected for an auxiliary call.
|
|
5343
5567
|
* @param tools - currently active tool schemas.
|
|
5344
5568
|
* @param toolUpdate - the resolved route's update mode.
|
|
@@ -5358,14 +5582,16 @@ function projectToolUpdates(messages, tools, toolUpdate, history) {
|
|
|
5358
5582
|
messages: withoutDeveloperMessages(messages),
|
|
5359
5583
|
tools
|
|
5360
5584
|
};
|
|
5361
|
-
const
|
|
5362
|
-
if (history.updates.some((update) => !
|
|
5585
|
+
const updates = new Map(messages.flatMap((message) => message.role === "developer" ? [[message.id, message.content]] : []));
|
|
5586
|
+
if (history.updates.some((update) => !updates.has(update.messageId))) return {
|
|
5363
5587
|
messages: withoutDeveloperMessages(messages),
|
|
5364
5588
|
tools
|
|
5365
5589
|
};
|
|
5366
|
-
const
|
|
5590
|
+
const projectedHistory = toolUpdate === "addition-only" ? rebaseAdditionOnlyHistory(history, updates) : history;
|
|
5591
|
+
const declarations = toolDeclarations(projectedHistory);
|
|
5367
5592
|
const updateIds = new Set(history.updates.map((update) => update.messageId));
|
|
5368
|
-
const
|
|
5593
|
+
const retainedUpdateIds = new Set(projectedHistory.updates.map((update) => update.messageId));
|
|
5594
|
+
const offered = new Set(projectedHistory.tools.filter((tool) => !tool.deferLoading).map((tool) => tool.name));
|
|
5369
5595
|
const projectedMessages = [];
|
|
5370
5596
|
for (const message of messages) {
|
|
5371
5597
|
if (message.role !== "developer") {
|
|
@@ -5376,6 +5602,7 @@ function projectToolUpdates(messages, tools, toolUpdate, history) {
|
|
|
5376
5602
|
const content = message.content.filter((block) => {
|
|
5377
5603
|
switch (block.type) {
|
|
5378
5604
|
case "tool-addition":
|
|
5605
|
+
if (!retainedUpdateIds.has(message.id)) return false;
|
|
5379
5606
|
if (!declarations.has(block.toolName) || offered.has(block.toolName)) return false;
|
|
5380
5607
|
offered.add(block.toolName);
|
|
5381
5608
|
return true;
|
|
@@ -5454,13 +5681,16 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
|
|
|
5454
5681
|
/**
|
|
5455
5682
|
* Typed error for LLM-related failures. Extends {@link HarnessError}, so the
|
|
5456
5683
|
* `code` string (e.g. `AUTH`, `RATE_LIMIT`, `NO_ADAPTER`) is shared taxonomy.
|
|
5684
|
+
* The constructor takes only a {@link BuiltinLlmFailureCode}; a failure from
|
|
5685
|
+
* another provider, whose code may be any string, is re-raised through
|
|
5686
|
+
* {@link LlmError.fromFailure}.
|
|
5457
5687
|
*/
|
|
5458
|
-
var LlmError = class extends HarnessError {
|
|
5688
|
+
var LlmError = class LlmError extends HarnessError {
|
|
5459
5689
|
/** Serializable facts retained beside this live Error. */
|
|
5460
5690
|
failure;
|
|
5461
5691
|
/**
|
|
5462
5692
|
* @param message - non-empty human-readable failure summary.
|
|
5463
|
-
* @param code -
|
|
5693
|
+
* @param code - built-in stable provider-neutral machine code.
|
|
5464
5694
|
* @param options - optional cause and validated serializable provider facts.
|
|
5465
5695
|
*/
|
|
5466
5696
|
constructor(message, code, options) {
|
|
@@ -5480,6 +5710,18 @@ var LlmError = class extends HarnessError {
|
|
|
5480
5710
|
...options?.offloadImages === void 0 ? {} : { offloadImages: options.offloadImages }
|
|
5481
5711
|
});
|
|
5482
5712
|
}
|
|
5713
|
+
/**
|
|
5714
|
+
* Raise an observed failure again with its own code, which any provider may have chosen.
|
|
5715
|
+
* @param failure - the serializable failure, typically from a stream's terminal chunk.
|
|
5716
|
+
* @param options - optional cause.
|
|
5717
|
+
* @returns an error carrying the failure's message, code, and provider facts.
|
|
5718
|
+
*/
|
|
5719
|
+
static fromFailure(failure, options) {
|
|
5720
|
+
return new LlmError(failure.message, failure.code, {
|
|
5721
|
+
...failure,
|
|
5722
|
+
...options
|
|
5723
|
+
});
|
|
5724
|
+
}
|
|
5483
5725
|
};
|
|
5484
5726
|
(() => {
|
|
5485
5727
|
let _classSuper = TypertRemoteService;
|
|
@@ -6155,7 +6397,7 @@ function detachDirectoryEntry(entry) {
|
|
|
6155
6397
|
};
|
|
6156
6398
|
}
|
|
6157
6399
|
//#endregion
|
|
6158
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.
|
|
6400
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-agent@0.2._d54d331d737d4347e4d7b0f13cb396ba/node_modules/@deepseek-ai/dsh-tools/lib/shared-DGx6D7zk.js
|
|
6159
6401
|
/** The selected provider is missing or unloaded; another provider must not take its calls. */
|
|
6160
6402
|
var ToolExecutorUnavailableError = class extends HarnessError {
|
|
6161
6403
|
constructor() {
|
|
@@ -6692,7 +6934,7 @@ var ToolActivationError = class extends HarnessError {
|
|
|
6692
6934
|
}
|
|
6693
6935
|
};
|
|
6694
6936
|
//#endregion
|
|
6695
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.
|
|
6937
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-scope/lib/index.js
|
|
6696
6938
|
/**
|
|
6697
6939
|
* Shared insertion-ordered storage and effect ownership for scope-aware registries.
|
|
6698
6940
|
*
|
|
@@ -6945,7 +7187,7 @@ function scopeOf(ctx) {
|
|
|
6945
7187
|
return ctx[kScope];
|
|
6946
7188
|
}
|
|
6947
7189
|
//#endregion
|
|
6948
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.
|
|
7190
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.2_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-agent@0.2._d54d331d737d4347e4d7b0f13cb396ba/node_modules/@deepseek-ai/dsh-tools/lib/index.js
|
|
6949
7191
|
/** Unified JSON-value schema DSL, inference, compilation, and tool definition helpers. @module dsh-tools/schema */
|
|
6950
7192
|
const ANNOTATION_KEYS = [
|
|
6951
7193
|
"description",
|
|
@@ -7581,12 +7823,12 @@ var GuardLayer = class {
|
|
|
7581
7823
|
/**
|
|
7582
7824
|
* Check global and inherited guards after pre-execute policy and approval resolve.
|
|
7583
7825
|
* @param exec - invocation whose guards are checked before dispatch.
|
|
7584
|
-
* @returns the first denial
|
|
7826
|
+
* @returns the first denial with its optional structured identity, or undefined when no guard denies.
|
|
7585
7827
|
*/
|
|
7586
7828
|
checkGuards(exec) {
|
|
7587
7829
|
for (const layer of [this.guards.global, ...this.guards.chainLayers(exec.agent)]) for (const guard of layer.guards.values()) {
|
|
7588
|
-
const
|
|
7589
|
-
if (
|
|
7830
|
+
const denial = guard(exec);
|
|
7831
|
+
if (denial !== void 0) return typeof denial === "string" ? { reason: denial } : denial;
|
|
7590
7832
|
}
|
|
7591
7833
|
}
|
|
7592
7834
|
});
|
|
@@ -8297,13 +8539,15 @@ title: ${value.title}
|
|
|
8297
8539
|
/** Settings schema exported through the host loader entry. */
|
|
8298
8540
|
const Config = Schema.object({
|
|
8299
8541
|
realBrowserEnabled: Schema.boolean().default(false).volatile().description("Connect the browser tools to a real Chrome/Edge over CDP instead of launching an isolated temporary browser. Off by default."),
|
|
8300
|
-
cdpEndpoint: Schema.string().default("http://127.0.0.1:9222").volatile().description("Loopback CDP endpoint only. Chrome 136+ ignores remote debugging on its default data directory; use a browser profile explicitly started with remote debugging and a non-default --user-data-dir.")
|
|
8542
|
+
cdpEndpoint: Schema.string().default("http://127.0.0.1:9222").volatile().description("Loopback CDP endpoint only. Chrome 136+ ignores remote debugging on its default data directory; use a browser profile explicitly started with remote debugging and a non-default --user-data-dir."),
|
|
8543
|
+
idleCloseDays: Schema.number().min(0).default(3).volatile().description("Close tabs DSH opened itself once no browser tool has touched them for this many days. Adopted real-browser tabs are never closed; 0 disables the sweep.")
|
|
8301
8544
|
});
|
|
8302
8545
|
/** Read the current values, including edits committed without a plugin remount. */
|
|
8303
8546
|
function effectiveConfig(config) {
|
|
8304
8547
|
return {
|
|
8305
8548
|
realBrowserEnabled: config?.realBrowserEnabled?.get() ?? false,
|
|
8306
|
-
cdpEndpoint: config?.cdpEndpoint?.get() ?? "http://127.0.0.1:9222"
|
|
8549
|
+
cdpEndpoint: config?.cdpEndpoint?.get() ?? "http://127.0.0.1:9222",
|
|
8550
|
+
idleCloseDays: config?.idleCloseDays?.get() ?? 3
|
|
8307
8551
|
};
|
|
8308
8552
|
}
|
|
8309
8553
|
//#endregion
|
|
@@ -8325,6 +8569,7 @@ function apply(ctx, config) {
|
|
|
8325
8569
|
cdpEndpoint: value.cdpEndpoint
|
|
8326
8570
|
} : { mode: "isolated" };
|
|
8327
8571
|
},
|
|
8572
|
+
idleCloseDays: () => effectiveConfig(config).idleCloseDays,
|
|
8328
8573
|
authenticatedUrl: (url) => {
|
|
8329
8574
|
const connection = ctx.get("connection");
|
|
8330
8575
|
if (connection === void 0 || typeof connection.authenticatedUrl !== "function") return void 0;
|