@ai-workbench/connect 0.7.29 → 0.7.31
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/NOTICE.md +2 -6
- package/README.md +8 -22
- package/client/index.cjs +14 -8
- package/helper/claude-callback.cjs +2 -13
- package/helper/remote-login.cjs +4 -11
- package/lib/api.d.ts +11 -0
- package/lib/browser-login.d.ts +10 -0
- package/lib/browser-login.js +70 -0
- package/lib/components.d.ts +1 -3
- package/lib/components.js +37 -15
- package/lib/connect.js +5 -1
- package/lib/defaults.d.ts +0 -10
- package/lib/defaults.js +1 -2
- package/lib/index.d.ts +0 -9
- package/lib/index.js +4 -13
- package/lib/integration.d.ts +1 -3
- package/lib/integration.js +8 -26
- package/lib/login.d.ts +2 -2
- package/lib/login.js +11 -9
- package/lib/needs.js +1 -1
- package/lib/ports.d.ts +1 -0
- package/lib/profile-settings.d.ts +2 -6
- package/lib/profile-settings.js +4 -8
- package/lib/remote-login.d.ts +1 -1
- package/lib/remote-login.js +2 -2
- package/lib/startup.js +19 -1
- package/package.json +3 -6
- package/helper/device-panel.cjs +0 -4
- package/helper/device-panel.css +0 -1
- package/helper/device-panel.html +0 -1
- package/helper/device-preload.cjs +0 -5
- package/helper/device-window.cjs +0 -60
- package/helper/main.cjs +0 -19
- package/helper/window.cjs +0 -46
- package/lib/archive.d.ts +0 -1
- package/lib/archive.js +0 -63
- package/lib/cache.d.ts +0 -21
- package/lib/cache.js +0 -156
- package/lib/component-download.d.ts +0 -34
- package/lib/component-download.js +0 -86
- package/lib/component-source.d.ts +0 -31
- package/lib/component-source.js +0 -18
- package/lib/electron.d.ts +0 -8
- package/lib/electron.js +0 -83
- package/lib/physical-fs.d.ts +0 -3
- package/lib/physical-fs.js +0 -7
- package/node_modules/pend/LICENSE +0 -23
- package/node_modules/pend/README.md +0 -41
- package/node_modules/pend/index.js +0 -55
- package/node_modules/pend/package.json +0 -18
- package/node_modules/pend/test.js +0 -137
- package/node_modules/yauzl/LICENSE +0 -21
- package/node_modules/yauzl/README.md +0 -1015
- package/node_modules/yauzl/crc32.js +0 -45
- package/node_modules/yauzl/fd-slicer.js +0 -188
- package/node_modules/yauzl/index.js +0 -1096
- package/node_modules/yauzl/package.json +0 -40
package/lib/cache.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { open, lstat, readFile, writeFile, readdir, readlink, realpath, rename, rm, mkdir } from "./physical-fs.js";
|
|
3
|
-
import { join, isAbsolute, relative } from 'node:path';
|
|
4
|
-
import { dependency, fail, ok, need } from "./needs.js";
|
|
5
|
-
import { ComponentDownloadError, componentCertificateMessage, isComponentCertificateFailure } from "./component-download.js";
|
|
6
|
-
import { privateDirectory } from "./private-files.js";
|
|
7
|
-
import { unpackZip } from "./archive.js";
|
|
8
|
-
async function treeHash(root) {
|
|
9
|
-
const hash = createHash('sha256');
|
|
10
|
-
const walk = async (dir) => {
|
|
11
|
-
for (const name of (await readdir(dir)).sort()) {
|
|
12
|
-
const p = join(dir, name), s = await lstat(p), rel = relative(root, p);
|
|
13
|
-
hash.update(rel + '\0' + (s.mode & 0o777) + '\0');
|
|
14
|
-
if (s.isDirectory())
|
|
15
|
-
await walk(p);
|
|
16
|
-
else if (s.isSymbolicLink()) {
|
|
17
|
-
const dest = await realpath(p);
|
|
18
|
-
if (!dest.startsWith(root + '/'))
|
|
19
|
-
throw new Error('CACHE_LINK_ESCAPE');
|
|
20
|
-
hash.update(await readlink(p));
|
|
21
|
-
}
|
|
22
|
-
else if (s.isFile())
|
|
23
|
-
hash.update(await readFile(p));
|
|
24
|
-
else
|
|
25
|
-
throw new Error('CACHE_TYPE_INVALID');
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
await walk(root);
|
|
29
|
-
return hash.digest('hex');
|
|
30
|
-
}
|
|
31
|
-
function valid(s) {
|
|
32
|
-
try {
|
|
33
|
-
return new URL(s.source).protocol === 'https:' && !new URL(s.source).username && !new URL(s.source).password && isAbsolute(s.cacheDir) && /^[a-f0-9]{64}$/.test(s.sha256) && Number.isSafeInteger(s.maxDownloadBytes) && s.maxDownloadBytes > 0 && Number.isSafeInteger(s.maxExtractedBytes) && s.maxExtractedBytes > 0 && !isAbsolute(s.executable) && !s.executable.split('/').includes('..') && s.executable !== '';
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export async function ensureHelper(s, io) {
|
|
40
|
-
if (!s || !valid(s))
|
|
41
|
-
return fail('SETTINGS_REQUIRED');
|
|
42
|
-
if (!io?.download)
|
|
43
|
-
return dependency('组件官方地址的直接HTTPS下载通道');
|
|
44
|
-
const final = join(s.cacheDir, s.sha256), payload = join(final, 'runtime'), executable = join(payload, s.executable);
|
|
45
|
-
let temp, receivedBytes = 0, totalBytes = null;
|
|
46
|
-
const emit = (phase, errorCode) => io.onProgress?.({ phase, receivedBytes, totalBytes, ...errorCode ? { errorCode } : {} });
|
|
47
|
-
const cancelled = () => { if (io.signal?.aborted)
|
|
48
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_CANCELLED'); };
|
|
49
|
-
try {
|
|
50
|
-
cancelled();
|
|
51
|
-
await privateDirectory(s.cacheDir);
|
|
52
|
-
let existing = false;
|
|
53
|
-
try {
|
|
54
|
-
const st = await lstat(final);
|
|
55
|
-
if (st.isSymbolicLink() || !st.isDirectory())
|
|
56
|
-
throw new ComponentDownloadError('COMPONENT_CACHE_INVALID');
|
|
57
|
-
existing = true;
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
if (e.code !== 'ENOENT')
|
|
61
|
-
throw e;
|
|
62
|
-
}
|
|
63
|
-
if (existing) {
|
|
64
|
-
const receipt = JSON.parse(await readFile(join(final, 'receipt.json'), 'utf8'));
|
|
65
|
-
if (receipt.sha256 !== s.sha256 || receipt.treeHash !== await treeHash(payload))
|
|
66
|
-
throw new ComponentDownloadError('COMPONENT_CACHE_INVALID');
|
|
67
|
-
const file = await lstat(executable);
|
|
68
|
-
if (!file.isFile() || (file.mode & 0o100) === 0)
|
|
69
|
-
throw new ComponentDownloadError('COMPONENT_CACHE_INVALID');
|
|
70
|
-
cancelled();
|
|
71
|
-
emit('ready');
|
|
72
|
-
return ok(executable);
|
|
73
|
-
}
|
|
74
|
-
temp = join(s.cacheDir, 'download-' + randomUUID());
|
|
75
|
-
await mkdir(temp, { mode: 0o700 });
|
|
76
|
-
const archive = join(temp, 'electron.zip');
|
|
77
|
-
emit('downloading');
|
|
78
|
-
const response = await io.download(s.source);
|
|
79
|
-
cancelled();
|
|
80
|
-
if (!response.ok || !response.body)
|
|
81
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_RESPONSE');
|
|
82
|
-
const length = response.headers.get('content-length');
|
|
83
|
-
if (length !== null) {
|
|
84
|
-
const n = Number(length);
|
|
85
|
-
if (!/^\d+$/.test(length) || !Number.isSafeInteger(n) || n < 0)
|
|
86
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_LENGTH_INVALID');
|
|
87
|
-
totalBytes = n;
|
|
88
|
-
if (n > s.maxDownloadBytes) {
|
|
89
|
-
await response.body.cancel();
|
|
90
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_SIZE');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
emit('downloading');
|
|
94
|
-
const file = await open(archive, 'wx', 0o600), hash = createHash('sha256');
|
|
95
|
-
let total = 0;
|
|
96
|
-
try {
|
|
97
|
-
for await (const chunk of response.body) {
|
|
98
|
-
cancelled();
|
|
99
|
-
total += chunk.byteLength;
|
|
100
|
-
receivedBytes = total;
|
|
101
|
-
if (total > s.maxDownloadBytes)
|
|
102
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_SIZE');
|
|
103
|
-
hash.update(chunk);
|
|
104
|
-
await file.write(chunk);
|
|
105
|
-
emit('downloading');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
await file.close();
|
|
110
|
-
}
|
|
111
|
-
cancelled();
|
|
112
|
-
emit('verifying');
|
|
113
|
-
if (hash.digest('hex') !== s.sha256)
|
|
114
|
-
throw new ComponentDownloadError('COMPONENT_SHA256_MISMATCH');
|
|
115
|
-
const runtime = join(temp, 'runtime');
|
|
116
|
-
await privateDirectory(runtime);
|
|
117
|
-
emit('unpacking');
|
|
118
|
-
cancelled();
|
|
119
|
-
if (io.unpack)
|
|
120
|
-
await io.unpack(archive, runtime, s.maxExtractedBytes);
|
|
121
|
-
else
|
|
122
|
-
await unpackZip(archive, runtime, s.maxExtractedBytes, io.signal);
|
|
123
|
-
cancelled();
|
|
124
|
-
let unpacked = 0;
|
|
125
|
-
const measure = async (dir) => { for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
126
|
-
const p = join(dir, entry.name);
|
|
127
|
-
if (entry.isDirectory())
|
|
128
|
-
await measure(p);
|
|
129
|
-
else if (entry.isFile())
|
|
130
|
-
unpacked += (await lstat(p)).size;
|
|
131
|
-
if (unpacked > s.maxExtractedBytes)
|
|
132
|
-
throw new Error('EXTRACTED_SIZE_EXCEEDED');
|
|
133
|
-
} };
|
|
134
|
-
await measure(runtime);
|
|
135
|
-
const exe = join(runtime, s.executable), st = await lstat(exe);
|
|
136
|
-
if (!st.isFile() || (st.mode & 0o100) === 0)
|
|
137
|
-
throw new ComponentDownloadError('COMPONENT_EXECUTABLE_INVALID');
|
|
138
|
-
await writeFile(join(temp, 'receipt.json'), JSON.stringify({ sha256: s.sha256, treeHash: await treeHash(runtime) }), { mode: 0o600 });
|
|
139
|
-
await rm(archive);
|
|
140
|
-
cancelled();
|
|
141
|
-
await rename(temp, final);
|
|
142
|
-
temp = undefined;
|
|
143
|
-
cancelled();
|
|
144
|
-
emit('ready');
|
|
145
|
-
return ok(executable);
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
const code = io.signal?.aborted ? 'COMPONENT_DOWNLOAD_CANCELLED' : error instanceof ComponentDownloadError ? error.message : 'COMPONENT_CACHE_IO';
|
|
149
|
-
emit(code === 'COMPONENT_DOWNLOAD_CANCELLED' ? 'cancelled' : 'failed', code);
|
|
150
|
-
return { ok: false, error: { ...need('LOGIN_FAILED'), ...(isComponentCertificateFailure(code) ? { message: componentCertificateMessage, action: { id: 'open-login', label: '换网络或联系网管', available: false } } : {}), requires: '登录组件从官方地址下载并通过完整校验;未重试或换源', officialReason: code } };
|
|
151
|
-
}
|
|
152
|
-
finally {
|
|
153
|
-
if (temp)
|
|
154
|
-
await rm(temp, { recursive: true, force: true });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type ComponentPhase = 'idle' | 'downloading' | 'verifying' | 'unpacking' | 'ready' | 'failed' | 'cancelled';
|
|
2
|
-
export interface ComponentProgress {
|
|
3
|
-
phase: ComponentPhase;
|
|
4
|
-
receivedBytes: number;
|
|
5
|
-
totalBytes: number | null;
|
|
6
|
-
errorCode?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface ComponentDownloadState extends ComponentProgress {
|
|
9
|
-
instanceId: string;
|
|
10
|
-
revision: number;
|
|
11
|
-
attemptId: string | null;
|
|
12
|
-
lastProgressAt?: number;
|
|
13
|
-
sourceLabel?: string;
|
|
14
|
-
sourceId?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function createComponentProgress(now?: () => number): {
|
|
17
|
-
getState: () => ComponentDownloadState;
|
|
18
|
-
onState(fn: () => void): () => void;
|
|
19
|
-
cancel(attemptId: string): boolean;
|
|
20
|
-
begin(source?: {
|
|
21
|
-
id: string;
|
|
22
|
-
label: string;
|
|
23
|
-
}, cancel?: () => void): {
|
|
24
|
-
attemptId: `${string}-${string}-${string}-${string}-${string}`;
|
|
25
|
-
update: (progress: ComponentProgress) => void;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export type ComponentProgressStore = ReturnType<typeof createComponentProgress>;
|
|
29
|
-
export declare class ComponentDownloadError extends Error {
|
|
30
|
-
constructor(code: string);
|
|
31
|
-
}
|
|
32
|
-
export declare const componentCertificateMessage = "\u8FDE\u63A5\u88AB\u622A\u83B7\uFF0C\u53EF\u80FD\u8FDE\u4E0D\u4E0A\u4E3B\u673A\u3002";
|
|
33
|
-
export declare const isComponentCertificateFailure: (reason: string) => boolean;
|
|
34
|
-
export declare function downloadComponent(source: string, signal: AbortSignal, maxRedirects: number): Promise<Response>;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import https from 'node:https';
|
|
2
|
-
import { Readable } from 'node:stream';
|
|
3
|
-
import { randomUUID } from 'node:crypto';
|
|
4
|
-
export function createComponentProgress(now = Date.now) {
|
|
5
|
-
let state = { instanceId: randomUUID(), revision: 0, attemptId: null, phase: 'idle', receivedBytes: 0, totalBytes: null };
|
|
6
|
-
const listeners = new Set();
|
|
7
|
-
let cancelDownload;
|
|
8
|
-
return { getState: () => structuredClone(state), onState(fn) { listeners.add(fn); return () => { listeners.delete(fn); }; }, cancel(attemptId) { if (state.attemptId !== attemptId || !['downloading', 'verifying', 'unpacking'].includes(state.phase) || !cancelDownload)
|
|
9
|
-
return false; const cancel = cancelDownload; cancelDownload = undefined; cancel(); return true; }, begin(source, cancel) { cancelDownload = cancel; const attemptId = randomUUID(); const update = (progress) => { if (state.attemptId !== attemptId)
|
|
10
|
-
return; if (['ready', 'failed', 'cancelled'].includes(progress.phase))
|
|
11
|
-
cancelDownload = undefined; state = { ...progress, lastProgressAt: progress.receivedBytes > state.receivedBytes ? now() : state.lastProgressAt, ...(source ? { sourceLabel: source.label, sourceId: source.id } : {}), instanceId: state.instanceId, revision: state.revision + 1, attemptId }; for (const fn of listeners)
|
|
12
|
-
fn(); }; state = { ...state, attemptId, receivedBytes: 0, lastProgressAt: now() }; update({ phase: 'downloading', receivedBytes: 0, totalBytes: null }); return { attemptId, update }; } };
|
|
13
|
-
}
|
|
14
|
-
export class ComponentDownloadError extends Error {
|
|
15
|
-
constructor(code) { super(code); this.name = 'ComponentDownloadError'; }
|
|
16
|
-
}
|
|
17
|
-
// 只按Node明确证书code分类;不解析可能含私密URL的message,不由此推断截获。
|
|
18
|
-
// Node24.13.1 X509表除OUT_OF_MEM(非证书原因)外的验证码,另含Node主机名校验码。
|
|
19
|
-
const certificateCodes = new Set(['UNABLE_TO_GET_ISSUER_CERT', 'UNABLE_TO_GET_CRL', 'UNABLE_TO_DECRYPT_CERT_SIGNATURE', 'UNABLE_TO_DECRYPT_CRL_SIGNATURE', 'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY', 'CERT_SIGNATURE_FAILURE', 'CRL_SIGNATURE_FAILURE', 'CERT_NOT_YET_VALID', 'CERT_HAS_EXPIRED', 'CRL_NOT_YET_VALID', 'CRL_HAS_EXPIRED', 'ERROR_IN_CERT_NOT_BEFORE_FIELD', 'ERROR_IN_CERT_NOT_AFTER_FIELD', 'ERROR_IN_CRL_LAST_UPDATE_FIELD', 'ERROR_IN_CRL_NEXT_UPDATE_FIELD', 'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'CERT_CHAIN_TOO_LONG', 'CERT_REVOKED', 'INVALID_CA', 'PATH_LENGTH_EXCEEDED', 'INVALID_PURPOSE', 'CERT_UNTRUSTED', 'CERT_REJECTED', 'HOSTNAME_MISMATCH', 'ERR_TLS_CERT_ALTNAME_INVALID']);
|
|
20
|
-
const tlsPrefix = 'COMPONENT_DOWNLOAD_TLS_';
|
|
21
|
-
export const componentCertificateMessage = '连接被截获,可能连不上主机。';
|
|
22
|
-
export const isComponentCertificateFailure = (reason) => reason.startsWith(tlsPrefix) && certificateCodes.has(reason.slice(tlsPrefix.length));
|
|
23
|
-
function downloadError(error, signal, fallback) {
|
|
24
|
-
const code = typeof error === 'object' && error !== null ? error.code : undefined;
|
|
25
|
-
return new ComponentDownloadError(signal.aborted ? 'COMPONENT_DOWNLOAD_CANCELLED' : typeof code === 'string' && certificateCodes.has(code) ? tlsPrefix + code : fallback);
|
|
26
|
-
}
|
|
27
|
-
const sourceUrl = (source) => { let u; try {
|
|
28
|
-
u = new URL(source);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
throw new ComponentDownloadError('COMPONENT_SOURCE_INVALID');
|
|
32
|
-
} if (u.protocol !== 'https:' || u.username || u.password)
|
|
33
|
-
throw new ComponentDownloadError('COMPONENT_SOURCE_INVALID'); return u; };
|
|
34
|
-
// 仅固定组件供给。不接收OAuth URL、ProxyLease、认证头或cookie;不读取系统/N代理。
|
|
35
|
-
export async function downloadComponent(source, signal, maxRedirects) {
|
|
36
|
-
if (!Number.isSafeInteger(maxRedirects) || maxRedirects < 0)
|
|
37
|
-
throw new ComponentDownloadError('COMPONENT_REDIRECT_LIMIT_INVALID');
|
|
38
|
-
let url = sourceUrl(source);
|
|
39
|
-
for (let redirects = 0;; redirects++) {
|
|
40
|
-
if (signal.aborted)
|
|
41
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_CANCELLED');
|
|
42
|
-
const response = await new Promise((yes, no) => {
|
|
43
|
-
const req = https.request(url, { signal, headers: { Accept: 'application/octet-stream' } }, yes);
|
|
44
|
-
req.once('error', error => no(downloadError(error, signal, 'COMPONENT_DOWNLOAD_NETWORK')));
|
|
45
|
-
req.end();
|
|
46
|
-
});
|
|
47
|
-
const status = response.statusCode ?? 0;
|
|
48
|
-
if ([301, 302, 303, 307, 308].includes(status)) {
|
|
49
|
-
const location = response.headers.location;
|
|
50
|
-
response.destroy();
|
|
51
|
-
if (redirects >= maxRedirects)
|
|
52
|
-
throw new ComponentDownloadError('COMPONENT_REDIRECT_LIMIT');
|
|
53
|
-
if (!location)
|
|
54
|
-
throw new ComponentDownloadError('COMPONENT_REDIRECT_INVALID');
|
|
55
|
-
try {
|
|
56
|
-
url = sourceUrl(new URL(location, url).href);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
throw new ComponentDownloadError('COMPONENT_REDIRECT_INVALID');
|
|
60
|
-
}
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if (status !== 200) {
|
|
64
|
-
response.destroy();
|
|
65
|
-
throw new ComponentDownloadError('COMPONENT_DOWNLOAD_HTTP_' + status);
|
|
66
|
-
}
|
|
67
|
-
const headers = new Headers();
|
|
68
|
-
for (const name of ['content-length', 'content-type']) {
|
|
69
|
-
const v = response.headers[name];
|
|
70
|
-
if (typeof v === 'string')
|
|
71
|
-
headers.set(name, v);
|
|
72
|
-
}
|
|
73
|
-
const reader = Readable.toWeb(response).getReader();
|
|
74
|
-
const body = new ReadableStream({ async pull(controller) { try {
|
|
75
|
-
const part = await reader.read();
|
|
76
|
-
if (part.done)
|
|
77
|
-
controller.close();
|
|
78
|
-
else
|
|
79
|
-
controller.enqueue(part.value);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
controller.error(downloadError(error, signal, 'COMPONENT_DOWNLOAD_BODY'));
|
|
83
|
-
} }, cancel: reason => reader.cancel(reason) });
|
|
84
|
-
return new Response(body, { status, headers });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export declare const COMPONENT_SOURCES: Readonly<{
|
|
2
|
-
npmmirror: {
|
|
3
|
-
label: string;
|
|
4
|
-
source: string;
|
|
5
|
-
};
|
|
6
|
-
}>;
|
|
7
|
-
export declare const DEFAULT_SOURCE_REASON = "\u767B\u5F55\u7EC4\u4EF6\u56FA\u5B9A\u4ECE npmmirror \u4E0B\u8F7D\u3002";
|
|
8
|
-
export declare function createComponentSources(options: {
|
|
9
|
-
sha256?: string;
|
|
10
|
-
}): {
|
|
11
|
-
ready: Promise<void>;
|
|
12
|
-
getState: () => {
|
|
13
|
-
instanceId: `${string}-${string}-${string}-${string}-${string}`;
|
|
14
|
-
revision: number;
|
|
15
|
-
phase: string;
|
|
16
|
-
selectedId: string;
|
|
17
|
-
selectedLabel: string;
|
|
18
|
-
reason: string;
|
|
19
|
-
version: string;
|
|
20
|
-
sha256: string | null;
|
|
21
|
-
};
|
|
22
|
-
onState(_fn: () => void): () => void;
|
|
23
|
-
resolve(): Promise<{
|
|
24
|
-
source: string;
|
|
25
|
-
id: string;
|
|
26
|
-
label: string;
|
|
27
|
-
reason: string;
|
|
28
|
-
}>;
|
|
29
|
-
dispose(): Promise<void>;
|
|
30
|
-
};
|
|
31
|
-
export type ComponentSources = ReturnType<typeof createComponentSources>;
|
package/lib/component-source.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { ELECTRON_PIN } from "./defaults.js";
|
|
3
|
-
import { ComponentDownloadError } from "./component-download.js";
|
|
4
|
-
export const COMPONENT_SOURCES = Object.freeze({
|
|
5
|
-
npmmirror: { label: 'npmmirror', source: 'https://npmmirror.com/mirrors/electron/44.0.0/electron-v44.0.0-darwin-arm64.zip' },
|
|
6
|
-
});
|
|
7
|
-
export const DEFAULT_SOURCE_REASON = '登录组件固定从 npmmirror 下载。';
|
|
8
|
-
export function createComponentSources(options) {
|
|
9
|
-
let disposed = false;
|
|
10
|
-
const state = { instanceId: randomUUID(), revision: 0, phase: 'ready', selectedId: 'npmmirror', selectedLabel: COMPONENT_SOURCES.npmmirror.label, reason: DEFAULT_SOURCE_REASON, version: '44.0.0', sha256: options.sha256 ?? null };
|
|
11
|
-
return { ready: Promise.resolve(), getState: () => structuredClone(state), onState(_fn) { return () => { }; }, async resolve() {
|
|
12
|
-
if (disposed)
|
|
13
|
-
throw new ComponentDownloadError('COMPONENT_SOURCE_DISPOSED');
|
|
14
|
-
if (options.sha256 !== ELECTRON_PIN.sha256)
|
|
15
|
-
throw new ComponentDownloadError('COMPONENT_PIN_MISMATCH');
|
|
16
|
-
return { source: COMPONENT_SOURCES.npmmirror.source, id: state.selectedId, label: state.selectedLabel, reason: state.reason };
|
|
17
|
-
}, async dispose() { disposed = true; } };
|
|
18
|
-
}
|
package/lib/electron.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { LoginBoot, LoginWindow } from './login.ts';
|
|
2
|
-
export interface ElectronLaunch {
|
|
3
|
-
executable: string;
|
|
4
|
-
entry: string;
|
|
5
|
-
cacheDir: string;
|
|
6
|
-
ipcMaxBytes: number;
|
|
7
|
-
}
|
|
8
|
-
export declare function launchElectron(settings: ElectronLaunch, boot: LoginBoot, onCode: (code: string) => Promise<void>, signal: AbortSignal): Promise<LoginWindow>;
|
package/lib/electron.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
3
|
-
import { join, isAbsolute } from 'node:path';
|
|
4
|
-
import { StringDecoder } from 'node:string_decoder';
|
|
5
|
-
import { privateDirectory } from "./private-files.js";
|
|
6
|
-
export async function launchElectron(settings, boot, onCode, signal) {
|
|
7
|
-
if (signal.aborted || !isAbsolute(settings.executable) || !isAbsolute(settings.entry) || !Number.isSafeInteger(settings.ipcMaxBytes) || settings.ipcMaxBytes < 1)
|
|
8
|
-
throw new Error('HELPER_SETTINGS_REQUIRED');
|
|
9
|
-
await privateDirectory(settings.cacheDir);
|
|
10
|
-
if (signal.aborted)
|
|
11
|
-
throw new Error('HELPER_CANCELLED');
|
|
12
|
-
const userDataDir = await mkdtemp(join(settings.cacheDir, 'session-'));
|
|
13
|
-
if (signal.aborted) {
|
|
14
|
-
await rm(userDataDir, { recursive: true });
|
|
15
|
-
throw new Error('HELPER_CANCELLED');
|
|
16
|
-
}
|
|
17
|
-
const child = spawn(settings.executable, [settings.entry], { shell: false, stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env, ELECTRON_RUN_AS_NODE: undefined, ELECTRON_ENABLE_LOGGING: undefined } });
|
|
18
|
-
let resolveReady = () => { }, rejectReady = () => { };
|
|
19
|
-
const ready = new Promise((yes, no) => { resolveReady = yes; rejectReady = no; });
|
|
20
|
-
let failed = false, line = '', size = 0;
|
|
21
|
-
const decoder = new StringDecoder('utf8');
|
|
22
|
-
const abort = () => { failed = true; child.kill('SIGTERM'); };
|
|
23
|
-
const close = () => { if (child.exitCode === null && child.signalCode === null && !child.stdin.destroyed) {
|
|
24
|
-
child.stdin.end(JSON.stringify({ type: 'close' }) + '\n');
|
|
25
|
-
} return closed; };
|
|
26
|
-
child.stdout.on('data', (chunk) => {
|
|
27
|
-
size += chunk.length;
|
|
28
|
-
if (size > settings.ipcMaxBytes) {
|
|
29
|
-
abort();
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
line += decoder.write(chunk);
|
|
33
|
-
const lines = line.split('\n');
|
|
34
|
-
line = lines.pop();
|
|
35
|
-
for (const value of lines) {
|
|
36
|
-
try {
|
|
37
|
-
const e = JSON.parse(value);
|
|
38
|
-
if (e.type === 'ready')
|
|
39
|
-
resolveReady();
|
|
40
|
-
else if (e.type === 'claude-code' && boot.provider === 'claude' && typeof e.code === 'string')
|
|
41
|
-
void onCode(e.code).catch(abort);
|
|
42
|
-
else if (e.type === 'closed') { /* process exit owns cleanup acknowledgement */ }
|
|
43
|
-
else
|
|
44
|
-
abort();
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
abort();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
// Chromium diagnostics are deliberately not forwarded to logs; failures use fixed public codes.
|
|
52
|
-
child.stderr.resume();
|
|
53
|
-
child.stdin.on('error', abort);
|
|
54
|
-
child.once('error', () => { failed = true; });
|
|
55
|
-
const closed = new Promise((yes, no) => child.once('close', async (code) => {
|
|
56
|
-
signal.removeEventListener('abort', abort);
|
|
57
|
-
rejectReady(new Error('HELPER_CLOSED'));
|
|
58
|
-
try {
|
|
59
|
-
await rm(userDataDir, { recursive: true });
|
|
60
|
-
if (failed || code !== 0)
|
|
61
|
-
no(new Error('HELPER_FAILED'));
|
|
62
|
-
else
|
|
63
|
-
yes();
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
no(new Error('HELPER_CLEANUP_FAILED'));
|
|
67
|
-
}
|
|
68
|
-
}));
|
|
69
|
-
// The child may fail before the caller receives its handle.
|
|
70
|
-
void closed.catch(() => { });
|
|
71
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
72
|
-
child.stdin.write(JSON.stringify({ ...boot, userDataDir }) + '\n');
|
|
73
|
-
if (signal.aborted)
|
|
74
|
-
abort();
|
|
75
|
-
try {
|
|
76
|
-
await ready;
|
|
77
|
-
return { closed, close };
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
await closed.catch(() => { });
|
|
81
|
-
throw new Error('HELPER_FAILED');
|
|
82
|
-
}
|
|
83
|
-
}
|
package/lib/physical-fs.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import * as nodeFs from 'node:fs';
|
|
2
|
-
export declare const createWriteStream: typeof nodeFs.createWriteStream;
|
|
3
|
-
export declare const open: typeof nodeFs.promises.open, lstat: typeof nodeFs.promises.lstat, readFile: typeof nodeFs.promises.readFile, writeFile: typeof nodeFs.promises.writeFile, readdir: typeof nodeFs.promises.readdir, readlink: typeof nodeFs.promises.readlink, realpath: typeof nodeFs.promises.realpath, rename: typeof nodeFs.promises.rename, rm: typeof nodeFs.promises.rm, mkdir: typeof nodeFs.promises.mkdir, symlink: typeof nodeFs.promises.symlink;
|
package/lib/physical-fs.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as nodeFs from 'node:fs';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
// 组件归档内的.asar是待校验的物理文件,不能消费Electron的虚拟目录视图。
|
|
4
|
-
// 仅缓存/解压边界使用;不设置全局process.noAsar,不影响宿主模块加载。
|
|
5
|
-
const physical = process.versions.electron ? createRequire(import.meta.url)('original-fs') : nodeFs;
|
|
6
|
-
export const { createWriteStream } = physical;
|
|
7
|
-
export const { open, lstat, readFile, writeFile, readdir, readlink, realpath, rename, rm, mkdir, symlink } = physical.promises;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
The MIT License (Expat)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014 Andrew Kelley
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person
|
|
6
|
-
obtaining a copy of this software and associated documentation files
|
|
7
|
-
(the "Software"), to deal in the Software without restriction,
|
|
8
|
-
including without limitation the rights to use, copy, modify, merge,
|
|
9
|
-
publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
-
and to permit persons to whom the Software is furnished to do so,
|
|
11
|
-
subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
included in all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
20
|
-
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
21
|
-
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
22
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
SOFTWARE.
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Pend
|
|
2
|
-
|
|
3
|
-
Dead-simple optimistic async helper.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
var Pend = require('pend');
|
|
9
|
-
var pend = new Pend();
|
|
10
|
-
pend.max = 10; // defaults to Infinity
|
|
11
|
-
setTimeout(pend.hold(), 1000); // pend.wait will have to wait for this hold to finish
|
|
12
|
-
pend.go(function(cb) {
|
|
13
|
-
console.log("this function is immediately executed");
|
|
14
|
-
setTimeout(function() {
|
|
15
|
-
console.log("calling cb 1");
|
|
16
|
-
cb();
|
|
17
|
-
}, 500);
|
|
18
|
-
});
|
|
19
|
-
pend.go(function(cb) {
|
|
20
|
-
console.log("this function is also immediately executed");
|
|
21
|
-
setTimeout(function() {
|
|
22
|
-
console.log("calling cb 2");
|
|
23
|
-
cb();
|
|
24
|
-
}, 1000);
|
|
25
|
-
});
|
|
26
|
-
pend.wait(function(err) {
|
|
27
|
-
console.log("this is excuted when the first 2 have returned.");
|
|
28
|
-
console.log("err is a possible error in the standard callback style.");
|
|
29
|
-
});
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Output:
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
this function is immediately executed
|
|
36
|
-
this function is also immediately executed
|
|
37
|
-
calling cb 1
|
|
38
|
-
calling cb 2
|
|
39
|
-
this is excuted when the first 2 have returned.
|
|
40
|
-
err is a possible error in the standard callback style.
|
|
41
|
-
```
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module.exports = Pend;
|
|
2
|
-
|
|
3
|
-
function Pend() {
|
|
4
|
-
this.pending = 0;
|
|
5
|
-
this.max = Infinity;
|
|
6
|
-
this.listeners = [];
|
|
7
|
-
this.waiting = [];
|
|
8
|
-
this.error = null;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
Pend.prototype.go = function(fn) {
|
|
12
|
-
if (this.pending < this.max) {
|
|
13
|
-
pendGo(this, fn);
|
|
14
|
-
} else {
|
|
15
|
-
this.waiting.push(fn);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
Pend.prototype.wait = function(cb) {
|
|
20
|
-
if (this.pending === 0) {
|
|
21
|
-
cb(this.error);
|
|
22
|
-
} else {
|
|
23
|
-
this.listeners.push(cb);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
Pend.prototype.hold = function() {
|
|
28
|
-
return pendHold(this);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
function pendHold(self) {
|
|
32
|
-
self.pending += 1;
|
|
33
|
-
var called = false;
|
|
34
|
-
return onCb;
|
|
35
|
-
function onCb(err) {
|
|
36
|
-
if (called) throw new Error("callback called twice");
|
|
37
|
-
called = true;
|
|
38
|
-
self.error = self.error || err;
|
|
39
|
-
self.pending -= 1;
|
|
40
|
-
if (self.waiting.length > 0 && self.pending < self.max) {
|
|
41
|
-
pendGo(self, self.waiting.shift());
|
|
42
|
-
} else if (self.pending === 0) {
|
|
43
|
-
var listeners = self.listeners;
|
|
44
|
-
self.listeners = [];
|
|
45
|
-
listeners.forEach(cbListener);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function cbListener(listener) {
|
|
49
|
-
listener(self.error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function pendGo(self, fn) {
|
|
54
|
-
fn(pendHold(self));
|
|
55
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pend",
|
|
3
|
-
"version": "1.2.0",
|
|
4
|
-
"description": "dead-simple optimistic async helper",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "node test.js"
|
|
8
|
-
},
|
|
9
|
-
"author": "Andrew Kelley <superjoe30@gmail.com>",
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git://github.com/andrewrk/node-pend.git"
|
|
14
|
-
},
|
|
15
|
-
"bugs": {
|
|
16
|
-
"url": "https://github.com/andrewrk/node-pend/issues"
|
|
17
|
-
}
|
|
18
|
-
}
|