@rebon/cli-win32-x64 1.3.0 → 1.5.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/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +239 -144
- package/THIRD_PARTY_NOTICES.txt +1232 -1232
- package/bin/rebon.js +22 -22
- package/lib/windows-managed.js +390 -390
- package/package.json +9 -2
- package/payload/compose-runtime/package.json +17 -17
- package/payload/compose-runtime/payload/compose/shims/dsh-anonymous-user-id.js +10 -10
- package/payload/compose-runtime/payload/compose/shims/dsh-credentials.js +13 -13
- package/payload/compose-runtime/payload/compose/shims/dsh-launch-environment.js +21 -21
- package/payload/compose-runtime/payload/compose/shims/dsh-llm.js +313 -313
- package/payload/compose-runtime/payload/compose/shims/dsh-settings.js +43 -43
- package/payload/compose-runtime/payload/compose/shims/dsh-tools.js +20 -20
- package/payload/compose-runtime/payload/compose/shims/dsh-web.js +10 -10
- package/payload/compose-runtime/payload/compose/shims/llm-adapter.js +32 -32
- package/payload/compose-runtime/payload/compose/shims/zod-lite.js +49 -49
- package/payload/compose-runtime/payload/vendor/cordis/LICENSE +21 -21
- package/payload/compose-runtime/payload/vendor/cordis/index.js +1530 -1530
- package/payload/compose-runtime/payload/vendor/cosmokit/LICENSE +21 -21
- package/payload/compose-runtime/payload/vendor/cosmokit/index.mjs +357 -357
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-agent +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-agent-loop +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-llm-core +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-llm-deepseek +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-logger-console +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-scope +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-session +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-system-prompt +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-timeout +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-timer +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tool-todo +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tool-web +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-tools-schema +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-turndown +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-turndown-plugin-gfm +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/LICENSE-web-search-exa +21 -21
- package/payload/compose-runtime/payload/vendor/dsh/agent-loop.js +1193 -1193
- package/payload/compose-runtime/payload/vendor/dsh/agent.js +714 -714
- package/payload/compose-runtime/payload/vendor/dsh/llm-core.js +269 -269
- package/payload/compose-runtime/payload/vendor/dsh/llm-deepseek.js +672 -672
- package/payload/compose-runtime/payload/vendor/dsh/logger-console.js +83 -83
- package/payload/compose-runtime/payload/vendor/dsh/scope.js +287 -287
- package/payload/compose-runtime/payload/vendor/dsh/session.js +1668 -1668
- package/payload/compose-runtime/payload/vendor/dsh/system-prompt.js +309 -309
- package/payload/compose-runtime/payload/vendor/dsh/timeout.js +100 -100
- package/payload/compose-runtime/payload/vendor/dsh/timer.js +128 -128
- package/payload/compose-runtime/payload/vendor/dsh/tool-todo.js +143 -143
- package/payload/compose-runtime/payload/vendor/dsh/tool-web.js +1527 -1527
- package/payload/compose-runtime/payload/vendor/dsh/tools-schema.js +849 -849
- package/payload/compose-runtime/payload/vendor/dsh/web-search-exa.js +122 -122
- package/payload/compose-runtime/payload/vendor/eventsource-parser/LICENSE +21 -21
- package/payload/compose-runtime/payload/vendor/eventsource-parser/index.js +177 -177
- package/payload/compose-runtime/payload/vendor/eventsource-parser/stream.js +48 -48
- package/payload/compose-runtime/payload/vendor/schemastery/LICENSE +21 -21
- package/payload/compose-runtime/payload/vendor/schemastery/index.mjs +656 -656
- package/payload/compose-runtime/payload-manifests.json +48 -48
- package/payload/compose-runtime/src/bridge.mjs +193 -195
- package/payload/compose-runtime/src/credentials-runtime.mjs +50 -50
- package/payload/compose-runtime/src/eventsource-stream.mjs +48 -48
- package/payload/compose-runtime/src/index.mjs +7 -7
- package/payload/compose-runtime/src/llm-runtime.mjs +326 -326
- package/payload/compose-runtime/src/loader.mjs +78 -78
- package/payload/compose-runtime/src/loop-assembly.mjs +237 -237
- package/payload/compose-runtime/src/payload.mjs +49 -49
- package/payload/compose-runtime/src/plugin.mjs +59 -59
- package/payload/compose-runtime/src/realm.mjs +223 -223
- package/payload/compose-runtime/src/registry.mjs +191 -191
- package/payload/compose-runtime/src/resolve.mjs +115 -115
- package/payload/compose-runtime/src/systemprompt-runtime.mjs +67 -67
- package/payload/compose-runtime/src/tools-runtime.mjs +239 -239
- package/payload/compose-runtime/src/web-runtime.mjs +209 -209
- package/payload/plugin-host/package.json +11 -11
- package/payload/plugin-host/src/bridge.mjs +64 -64
- package/payload/plugin-host/src/cli.mjs +147 -147
- package/payload/plugin-host/src/framing.mjs +113 -113
- package/payload/plugin-host/src/host.mjs +691 -691
- package/payload/plugin-host/src/json.mjs +208 -208
- package/payload/plugin-host/src/lifecycle.mjs +114 -114
- package/payload/plugin-host/src/loader.mjs +183 -183
- package/payload/plugin-host/src/methods.mjs +377 -377
- package/payload/plugin-host/src/ownership.mjs +57 -57
- package/payload/plugin-host/src/protocol.mjs +129 -129
- package/payload/plugin-host/src/sdk.mjs +7 -7
- package/payload/rebon-boa-helper.exe +0 -0
- package/payload/rebon-browser-mcp.exe +0 -0
- package/payload/rebon-computer-use.exe +0 -0
- package/payload/rebon-lsp-mcp.exe +0 -0
- package/payload/rebon.exe +2 -2
- package/payload/sandbox-win.exe +0 -0
- package/scripts/postinstall.js +112 -112
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
// packages/util/timeout/src/index.ts
|
|
2
|
-
var TimeoutReason = class extends Error {
|
|
3
|
-
/**
|
|
4
|
-
* @param code Capability-owned timeout code (e.g. `BASH_TIMEOUT`).
|
|
5
|
-
* @param timeoutMs The deadline that elapsed, in milliseconds.
|
|
6
|
-
*/
|
|
7
|
-
constructor(code, timeoutMs) {
|
|
8
|
-
super(`${code} after ${timeoutMs}ms`);
|
|
9
|
-
this.code = code;
|
|
10
|
-
this.timeoutMs = timeoutMs;
|
|
11
|
-
}
|
|
12
|
-
code;
|
|
13
|
-
timeoutMs;
|
|
14
|
-
name = "TimeoutReason";
|
|
15
|
-
};
|
|
16
|
-
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
17
|
-
function assertTimerDelay(timeoutMs, name) {
|
|
18
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_DELAY_MS) {
|
|
19
|
-
throw new Error(`${name} must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function clampTimeout(requested, def, max, name = "timeoutMs") {
|
|
23
|
-
if (requested !== void 0 && (!Number.isFinite(requested) || requested <= 0)) {
|
|
24
|
-
throw new Error(`${name} must be a positive finite number`);
|
|
25
|
-
}
|
|
26
|
-
return Math.min(requested ?? def, max);
|
|
27
|
-
}
|
|
28
|
-
function deadline(upstream, timeoutMs, code) {
|
|
29
|
-
if (timeoutMs <= 0) {
|
|
30
|
-
return { signal: upstream ?? new AbortController().signal, [Symbol.dispose]() {
|
|
31
|
-
} };
|
|
32
|
-
}
|
|
33
|
-
assertTimerDelay(timeoutMs, "deadline timeoutMs");
|
|
34
|
-
const timer = new AbortController();
|
|
35
|
-
const id = setTimeout(() => {
|
|
36
|
-
timer.abort(new TimeoutReason(code, timeoutMs));
|
|
37
|
-
}, timeoutMs);
|
|
38
|
-
return {
|
|
39
|
-
// AbortSignal.any adopts the reason of whichever source aborts FIRST, so a
|
|
40
|
-
// race resolves to a single cause: timeoutOf() reads TimeoutReason only
|
|
41
|
-
// when the timeout won, and upstream-wins leaves an ordinary abort reason.
|
|
42
|
-
signal: upstream !== void 0 ? AbortSignal.any([upstream, timer.signal]) : timer.signal,
|
|
43
|
-
[Symbol.dispose]() {
|
|
44
|
-
clearTimeout(id);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function idleWatchdog(upstream, timeoutMs, code) {
|
|
49
|
-
assertTimerDelay(timeoutMs, "idleWatchdog timeoutMs");
|
|
50
|
-
const timeout = new AbortController();
|
|
51
|
-
const signal = upstream === void 0 ? timeout.signal : AbortSignal.any([upstream, timeout.signal]);
|
|
52
|
-
let timer;
|
|
53
|
-
let outstanding = false;
|
|
54
|
-
let disposed = false;
|
|
55
|
-
const arm = () => {
|
|
56
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
57
|
-
timer = setTimeout(() => {
|
|
58
|
-
timeout.abort(new TimeoutReason(code, timeoutMs));
|
|
59
|
-
}, timeoutMs);
|
|
60
|
-
};
|
|
61
|
-
return {
|
|
62
|
-
signal,
|
|
63
|
-
async next(iterator) {
|
|
64
|
-
if (disposed) throw new Error("idleWatchdog is disposed");
|
|
65
|
-
if (outstanding) throw new Error("idleWatchdog next is already outstanding");
|
|
66
|
-
outstanding = true;
|
|
67
|
-
arm();
|
|
68
|
-
try {
|
|
69
|
-
return await iterator.next();
|
|
70
|
-
} finally {
|
|
71
|
-
clearTimeout(timer);
|
|
72
|
-
timer = void 0;
|
|
73
|
-
outstanding = false;
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
pulse() {
|
|
77
|
-
if (disposed || !outstanding) return;
|
|
78
|
-
arm();
|
|
79
|
-
},
|
|
80
|
-
[Symbol.dispose]() {
|
|
81
|
-
if (disposed) return;
|
|
82
|
-
disposed = true;
|
|
83
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
84
|
-
timer = void 0;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function timeoutOf(x, code) {
|
|
89
|
-
const reason = x.reason;
|
|
90
|
-
if (!(reason instanceof TimeoutReason)) return void 0;
|
|
91
|
-
return code === void 0 || reason.code === code ? reason : void 0;
|
|
92
|
-
}
|
|
93
|
-
export {
|
|
94
|
-
MAX_TIMER_DELAY_MS,
|
|
95
|
-
TimeoutReason,
|
|
96
|
-
clampTimeout,
|
|
97
|
-
deadline,
|
|
98
|
-
idleWatchdog,
|
|
99
|
-
timeoutOf
|
|
100
|
-
};
|
|
1
|
+
// packages/util/timeout/src/index.ts
|
|
2
|
+
var TimeoutReason = class extends Error {
|
|
3
|
+
/**
|
|
4
|
+
* @param code Capability-owned timeout code (e.g. `BASH_TIMEOUT`).
|
|
5
|
+
* @param timeoutMs The deadline that elapsed, in milliseconds.
|
|
6
|
+
*/
|
|
7
|
+
constructor(code, timeoutMs) {
|
|
8
|
+
super(`${code} after ${timeoutMs}ms`);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.timeoutMs = timeoutMs;
|
|
11
|
+
}
|
|
12
|
+
code;
|
|
13
|
+
timeoutMs;
|
|
14
|
+
name = "TimeoutReason";
|
|
15
|
+
};
|
|
16
|
+
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
17
|
+
function assertTimerDelay(timeoutMs, name) {
|
|
18
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMER_DELAY_MS) {
|
|
19
|
+
throw new Error(`${name} must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function clampTimeout(requested, def, max, name = "timeoutMs") {
|
|
23
|
+
if (requested !== void 0 && (!Number.isFinite(requested) || requested <= 0)) {
|
|
24
|
+
throw new Error(`${name} must be a positive finite number`);
|
|
25
|
+
}
|
|
26
|
+
return Math.min(requested ?? def, max);
|
|
27
|
+
}
|
|
28
|
+
function deadline(upstream, timeoutMs, code) {
|
|
29
|
+
if (timeoutMs <= 0) {
|
|
30
|
+
return { signal: upstream ?? new AbortController().signal, [Symbol.dispose]() {
|
|
31
|
+
} };
|
|
32
|
+
}
|
|
33
|
+
assertTimerDelay(timeoutMs, "deadline timeoutMs");
|
|
34
|
+
const timer = new AbortController();
|
|
35
|
+
const id = setTimeout(() => {
|
|
36
|
+
timer.abort(new TimeoutReason(code, timeoutMs));
|
|
37
|
+
}, timeoutMs);
|
|
38
|
+
return {
|
|
39
|
+
// AbortSignal.any adopts the reason of whichever source aborts FIRST, so a
|
|
40
|
+
// race resolves to a single cause: timeoutOf() reads TimeoutReason only
|
|
41
|
+
// when the timeout won, and upstream-wins leaves an ordinary abort reason.
|
|
42
|
+
signal: upstream !== void 0 ? AbortSignal.any([upstream, timer.signal]) : timer.signal,
|
|
43
|
+
[Symbol.dispose]() {
|
|
44
|
+
clearTimeout(id);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function idleWatchdog(upstream, timeoutMs, code) {
|
|
49
|
+
assertTimerDelay(timeoutMs, "idleWatchdog timeoutMs");
|
|
50
|
+
const timeout = new AbortController();
|
|
51
|
+
const signal = upstream === void 0 ? timeout.signal : AbortSignal.any([upstream, timeout.signal]);
|
|
52
|
+
let timer;
|
|
53
|
+
let outstanding = false;
|
|
54
|
+
let disposed = false;
|
|
55
|
+
const arm = () => {
|
|
56
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
57
|
+
timer = setTimeout(() => {
|
|
58
|
+
timeout.abort(new TimeoutReason(code, timeoutMs));
|
|
59
|
+
}, timeoutMs);
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
signal,
|
|
63
|
+
async next(iterator) {
|
|
64
|
+
if (disposed) throw new Error("idleWatchdog is disposed");
|
|
65
|
+
if (outstanding) throw new Error("idleWatchdog next is already outstanding");
|
|
66
|
+
outstanding = true;
|
|
67
|
+
arm();
|
|
68
|
+
try {
|
|
69
|
+
return await iterator.next();
|
|
70
|
+
} finally {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
timer = void 0;
|
|
73
|
+
outstanding = false;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
pulse() {
|
|
77
|
+
if (disposed || !outstanding) return;
|
|
78
|
+
arm();
|
|
79
|
+
},
|
|
80
|
+
[Symbol.dispose]() {
|
|
81
|
+
if (disposed) return;
|
|
82
|
+
disposed = true;
|
|
83
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
84
|
+
timer = void 0;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function timeoutOf(x, code) {
|
|
89
|
+
const reason = x.reason;
|
|
90
|
+
if (!(reason instanceof TimeoutReason)) return void 0;
|
|
91
|
+
return code === void 0 || reason.code === code ? reason : void 0;
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
MAX_TIMER_DELAY_MS,
|
|
95
|
+
TimeoutReason,
|
|
96
|
+
clampTimeout,
|
|
97
|
+
deadline,
|
|
98
|
+
idleWatchdog,
|
|
99
|
+
timeoutOf
|
|
100
|
+
};
|
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
// dsh-vendor/timer/src/index.ts
|
|
2
|
-
import { Service } from "@deepseek-ai/cordis";
|
|
3
|
-
var TimerService = class extends Service {
|
|
4
|
-
constructor(ctx) {
|
|
5
|
-
super(ctx, "timer");
|
|
6
|
-
ctx.mixin("timer", ["timeout", "interval", "throttle", "debounce", "setTimeout", "setInterval"]);
|
|
7
|
-
}
|
|
8
|
-
/** @deprecated use `ctx.timeout()` instead */
|
|
9
|
-
setTimeout(callback, delay) {
|
|
10
|
-
return this.timeout(callback, delay);
|
|
11
|
-
}
|
|
12
|
-
/** @deprecated use `ctx.interval()` instead */
|
|
13
|
-
setInterval(callback, delay) {
|
|
14
|
-
return this.interval(callback, delay);
|
|
15
|
-
}
|
|
16
|
-
timeout(...args) {
|
|
17
|
-
const callback = typeof args[0] === "function" ? args.shift() : void 0;
|
|
18
|
-
const delay = args[0];
|
|
19
|
-
if (callback) {
|
|
20
|
-
const dispose = this.ctx.effect(() => {
|
|
21
|
-
const timer = setTimeout(() => {
|
|
22
|
-
dispose();
|
|
23
|
-
callback();
|
|
24
|
-
}, delay);
|
|
25
|
-
return () => clearTimeout(timer);
|
|
26
|
-
}, "ctx.timeout()");
|
|
27
|
-
return dispose;
|
|
28
|
-
} else {
|
|
29
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
30
|
-
const dispose = this.ctx.effect(() => {
|
|
31
|
-
const timer = setTimeout(resolve, delay);
|
|
32
|
-
return () => {
|
|
33
|
-
clearTimeout(timer);
|
|
34
|
-
reject(new Error("Context has been disposed"));
|
|
35
|
-
};
|
|
36
|
-
}, "ctx.timeout()");
|
|
37
|
-
return promise.finally(dispose);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
interval(...args) {
|
|
41
|
-
const callback = typeof args[0] === "function" ? args.shift() : void 0;
|
|
42
|
-
const delay = args[0];
|
|
43
|
-
if (callback) {
|
|
44
|
-
return this.ctx.effect(() => {
|
|
45
|
-
const timer = setInterval(callback, delay);
|
|
46
|
-
return () => clearInterval(timer);
|
|
47
|
-
}, "ctx.interval()");
|
|
48
|
-
} else {
|
|
49
|
-
let done;
|
|
50
|
-
let nextTask;
|
|
51
|
-
const dispose = this.ctx.effect(() => {
|
|
52
|
-
const timer = setInterval(() => {
|
|
53
|
-
nextTask?.resolve({ done: false, value: void 0 });
|
|
54
|
-
}, delay);
|
|
55
|
-
return () => {
|
|
56
|
-
clearInterval(timer);
|
|
57
|
-
if (done) return;
|
|
58
|
-
done = { kind: "throw", reason: new Error("Context has been disposed") };
|
|
59
|
-
nextTask?.reject(done.reason);
|
|
60
|
-
};
|
|
61
|
-
}, "ctx.interval()");
|
|
62
|
-
return {
|
|
63
|
-
next: () => {
|
|
64
|
-
if (!done) return (nextTask = Promise.withResolvers()).promise;
|
|
65
|
-
if (done.kind === "return") return Promise.resolve({ done: true, value: done.value });
|
|
66
|
-
return Promise.reject(done.reason);
|
|
67
|
-
},
|
|
68
|
-
return: (value) => {
|
|
69
|
-
if (!done) done = { kind: "return", value };
|
|
70
|
-
nextTask?.resolve({ done: true, value });
|
|
71
|
-
dispose();
|
|
72
|
-
return Promise.resolve({ done: true, value });
|
|
73
|
-
},
|
|
74
|
-
throw: (reason) => {
|
|
75
|
-
if (!done) done = { kind: "throw", reason };
|
|
76
|
-
nextTask?.reject(reason);
|
|
77
|
-
dispose();
|
|
78
|
-
return Promise.resolve({ done: true, value: void 0 });
|
|
79
|
-
},
|
|
80
|
-
[Symbol.asyncIterator]() {
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
_schedule(label, trigger, isDisposed = false) {
|
|
87
|
-
let timer;
|
|
88
|
-
const dispose = this.ctx.effect(() => () => {
|
|
89
|
-
isDisposed = true;
|
|
90
|
-
clearTimeout(timer);
|
|
91
|
-
}, label);
|
|
92
|
-
const wrapper = (...args) => {
|
|
93
|
-
clearTimeout(timer);
|
|
94
|
-
timer = trigger(args, isDisposed);
|
|
95
|
-
};
|
|
96
|
-
wrapper.dispose = dispose;
|
|
97
|
-
return wrapper;
|
|
98
|
-
}
|
|
99
|
-
/** Return a throttled function whose timer is disposed with the current fiber. */
|
|
100
|
-
throttle(callback, delay, noTrailing) {
|
|
101
|
-
let lastCall = -Infinity;
|
|
102
|
-
const execute = (...args) => {
|
|
103
|
-
lastCall = Date.now();
|
|
104
|
-
callback(...args);
|
|
105
|
-
};
|
|
106
|
-
return this._schedule("ctx.throttle()", (args, isDisposed) => {
|
|
107
|
-
const now = Date.now();
|
|
108
|
-
const remaining = delay - now + lastCall;
|
|
109
|
-
if (remaining <= 0) {
|
|
110
|
-
execute(...args);
|
|
111
|
-
} else if (!isDisposed) {
|
|
112
|
-
return setTimeout(execute, remaining, ...args);
|
|
113
|
-
}
|
|
114
|
-
}, noTrailing);
|
|
115
|
-
}
|
|
116
|
-
/** Return a debounced function whose timer is disposed with the current fiber. */
|
|
117
|
-
debounce(callback, delay) {
|
|
118
|
-
return this._schedule("ctx.debounce()", (args, isDisposed) => {
|
|
119
|
-
if (isDisposed) return;
|
|
120
|
-
return setTimeout(callback, delay, ...args);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var index_default = TimerService;
|
|
125
|
-
export {
|
|
126
|
-
TimerService,
|
|
127
|
-
index_default as default
|
|
128
|
-
};
|
|
1
|
+
// dsh-vendor/timer/src/index.ts
|
|
2
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
3
|
+
var TimerService = class extends Service {
|
|
4
|
+
constructor(ctx) {
|
|
5
|
+
super(ctx, "timer");
|
|
6
|
+
ctx.mixin("timer", ["timeout", "interval", "throttle", "debounce", "setTimeout", "setInterval"]);
|
|
7
|
+
}
|
|
8
|
+
/** @deprecated use `ctx.timeout()` instead */
|
|
9
|
+
setTimeout(callback, delay) {
|
|
10
|
+
return this.timeout(callback, delay);
|
|
11
|
+
}
|
|
12
|
+
/** @deprecated use `ctx.interval()` instead */
|
|
13
|
+
setInterval(callback, delay) {
|
|
14
|
+
return this.interval(callback, delay);
|
|
15
|
+
}
|
|
16
|
+
timeout(...args) {
|
|
17
|
+
const callback = typeof args[0] === "function" ? args.shift() : void 0;
|
|
18
|
+
const delay = args[0];
|
|
19
|
+
if (callback) {
|
|
20
|
+
const dispose = this.ctx.effect(() => {
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
dispose();
|
|
23
|
+
callback();
|
|
24
|
+
}, delay);
|
|
25
|
+
return () => clearTimeout(timer);
|
|
26
|
+
}, "ctx.timeout()");
|
|
27
|
+
return dispose;
|
|
28
|
+
} else {
|
|
29
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
30
|
+
const dispose = this.ctx.effect(() => {
|
|
31
|
+
const timer = setTimeout(resolve, delay);
|
|
32
|
+
return () => {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
reject(new Error("Context has been disposed"));
|
|
35
|
+
};
|
|
36
|
+
}, "ctx.timeout()");
|
|
37
|
+
return promise.finally(dispose);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
interval(...args) {
|
|
41
|
+
const callback = typeof args[0] === "function" ? args.shift() : void 0;
|
|
42
|
+
const delay = args[0];
|
|
43
|
+
if (callback) {
|
|
44
|
+
return this.ctx.effect(() => {
|
|
45
|
+
const timer = setInterval(callback, delay);
|
|
46
|
+
return () => clearInterval(timer);
|
|
47
|
+
}, "ctx.interval()");
|
|
48
|
+
} else {
|
|
49
|
+
let done;
|
|
50
|
+
let nextTask;
|
|
51
|
+
const dispose = this.ctx.effect(() => {
|
|
52
|
+
const timer = setInterval(() => {
|
|
53
|
+
nextTask?.resolve({ done: false, value: void 0 });
|
|
54
|
+
}, delay);
|
|
55
|
+
return () => {
|
|
56
|
+
clearInterval(timer);
|
|
57
|
+
if (done) return;
|
|
58
|
+
done = { kind: "throw", reason: new Error("Context has been disposed") };
|
|
59
|
+
nextTask?.reject(done.reason);
|
|
60
|
+
};
|
|
61
|
+
}, "ctx.interval()");
|
|
62
|
+
return {
|
|
63
|
+
next: () => {
|
|
64
|
+
if (!done) return (nextTask = Promise.withResolvers()).promise;
|
|
65
|
+
if (done.kind === "return") return Promise.resolve({ done: true, value: done.value });
|
|
66
|
+
return Promise.reject(done.reason);
|
|
67
|
+
},
|
|
68
|
+
return: (value) => {
|
|
69
|
+
if (!done) done = { kind: "return", value };
|
|
70
|
+
nextTask?.resolve({ done: true, value });
|
|
71
|
+
dispose();
|
|
72
|
+
return Promise.resolve({ done: true, value });
|
|
73
|
+
},
|
|
74
|
+
throw: (reason) => {
|
|
75
|
+
if (!done) done = { kind: "throw", reason };
|
|
76
|
+
nextTask?.reject(reason);
|
|
77
|
+
dispose();
|
|
78
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
79
|
+
},
|
|
80
|
+
[Symbol.asyncIterator]() {
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
_schedule(label, trigger, isDisposed = false) {
|
|
87
|
+
let timer;
|
|
88
|
+
const dispose = this.ctx.effect(() => () => {
|
|
89
|
+
isDisposed = true;
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}, label);
|
|
92
|
+
const wrapper = (...args) => {
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
timer = trigger(args, isDisposed);
|
|
95
|
+
};
|
|
96
|
+
wrapper.dispose = dispose;
|
|
97
|
+
return wrapper;
|
|
98
|
+
}
|
|
99
|
+
/** Return a throttled function whose timer is disposed with the current fiber. */
|
|
100
|
+
throttle(callback, delay, noTrailing) {
|
|
101
|
+
let lastCall = -Infinity;
|
|
102
|
+
const execute = (...args) => {
|
|
103
|
+
lastCall = Date.now();
|
|
104
|
+
callback(...args);
|
|
105
|
+
};
|
|
106
|
+
return this._schedule("ctx.throttle()", (args, isDisposed) => {
|
|
107
|
+
const now = Date.now();
|
|
108
|
+
const remaining = delay - now + lastCall;
|
|
109
|
+
if (remaining <= 0) {
|
|
110
|
+
execute(...args);
|
|
111
|
+
} else if (!isDisposed) {
|
|
112
|
+
return setTimeout(execute, remaining, ...args);
|
|
113
|
+
}
|
|
114
|
+
}, noTrailing);
|
|
115
|
+
}
|
|
116
|
+
/** Return a debounced function whose timer is disposed with the current fiber. */
|
|
117
|
+
debounce(callback, delay) {
|
|
118
|
+
return this._schedule("ctx.debounce()", (args, isDisposed) => {
|
|
119
|
+
if (isDisposed) return;
|
|
120
|
+
return setTimeout(callback, delay, ...args);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var index_default = TimerService;
|
|
125
|
+
export {
|
|
126
|
+
TimerService,
|
|
127
|
+
index_default as default
|
|
128
|
+
};
|