@ai-workbench/connect 0.7.29 → 0.7.32
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 +12 -18
- 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/ssh.js +1 -1
- 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/index.js
CHANGED
|
@@ -5,8 +5,6 @@ import { createConnect } from "./connect.js";
|
|
|
5
5
|
import { configuredPorts } from "./integration.js";
|
|
6
6
|
import { attachProfileRuntime } from "./profile-runtime.js";
|
|
7
7
|
import { profileSettings } from "./profile-settings.js";
|
|
8
|
-
import { createComponentSources } from "./component-source.js";
|
|
9
|
-
import { createComponentProgress } from "./component-download.js";
|
|
10
8
|
import { L_DEFAULTS, NETWORK_DEFAULTS } from "./defaults.js";
|
|
11
9
|
import { registerComponents } from "./components.js";
|
|
12
10
|
export { writeNetworkConfig } from "./network.js";
|
|
@@ -28,13 +26,8 @@ export const Config = z.object({
|
|
|
28
26
|
commandOutputMaxBytes: positive().default(L_DEFAULTS.commandOutputMaxBytes).description('远程命令输出内存上限(字节),默认1048576,管理员可修改'),
|
|
29
27
|
network: z.object({ executable: z.string(), runtimeDir: z.string(), stateDir: z.string(), configFile: z.string(), helperLogFile: z.string(), nodeName: z.string(), startupObservationSeconds: z.number().min(0.001).max(2147483.647).default(NETWORK_DEFAULTS.startupObservationSeconds), shutdownObservationSeconds: z.number().min(0.001).max(2147483.647).default(NETWORK_DEFAULTS.shutdownObservationSeconds), controlResponseMaxBytes: positive().default(NETWORK_DEFAULTS.controlResponseMaxBytes), logUpload: z.boolean().default(NETWORK_DEFAULTS.logUpload), statusRefreshIntervalSeconds: z.number().min(0.001).max(2147483.647).default(NETWORK_DEFAULTS.statusRefreshIntervalSeconds), dialTimeoutSeconds: z.number().min(1e-9).default(NETWORK_DEFAULTS.dialTimeoutSeconds), headerTimeoutSeconds: z.number().min(0.001).max(2147483.647).default(NETWORK_DEFAULTS.headerTimeoutSeconds), enrollmentObservationSeconds: z.number().min(1e-9).default(NETWORK_DEFAULTS.enrollmentObservationSeconds), httpMaxHeaderBytes: positive().default(NETWORK_DEFAULTS.httpMaxHeaderBytes), controlMaxBytes: positive() }).description('远程网络连接设置:使用默认技术参数,管理员可修改;路径根据当前用户和应用配置目录生成,员工无需填写'),
|
|
30
28
|
helper: z.object({
|
|
31
|
-
componentObservationIntervalMs: z.number().step(1).min(1).max(2147483647).default(L_DEFAULTS.componentObservationIntervalMs).description('无进展观察刷新间隔毫秒,默认1000;只刷新秒数,不超时/重试/换源'),
|
|
32
|
-
componentDownloadMaxRedirects: z.number().step(1).min(0).default(L_DEFAULTS.componentDownloadMaxRedirects).description('组件直接HTTPS下载的重定向次数上限;默认3,0拒绝重定向;管理员可改,不改变网页登录网络'),
|
|
33
29
|
remoteKillGraceMs: z.number().step(1).min(0).max(2147483647).default(L_DEFAULTS.remoteKillGraceMs).description('远端本轮登录进程组结束宽限毫秒;默认1000,0立即KILL,管理员可改'),
|
|
34
|
-
|
|
35
|
-
sha256: z.string().description('darwin-arm64默认使用Electron 44.0.0对应的下载SHA256;管理员可改,必须校验'),
|
|
36
|
-
cacheDir: z.string().description('默认从当前profile自动派生ai-workbench-connect/login-component-cache;管理员可改,员工不填路径'), maxDownloadBytes: positive().default(L_DEFAULTS.maxDownloadBytes).description('下载字节上限;默认200000000,管理员可改'), maxExtractedBytes: positive().default(L_DEFAULTS.maxExtractedBytes).description('解压字节上限;默认600000000,管理员可改'),
|
|
37
|
-
executable: z.string().description('darwin-arm64默认Electron.app/Contents/MacOS/Electron;其他平台无默认,管理员可改'), loginOutputMaxBytes: positive().default(L_DEFAULTS.loginOutputMaxBytes).description('登录进程输出字节上限;默认1048576,管理员可改'), ipcMaxBytes: positive().default(L_DEFAULTS.ipcMaxBytes).description('私有IPC字节上限;默认1048576,管理员可改'),
|
|
30
|
+
loginOutputMaxBytes: positive().default(L_DEFAULTS.loginOutputMaxBytes).description('登录进程输出字节上限;默认1048576,管理员可改'),
|
|
38
31
|
}),
|
|
39
32
|
});
|
|
40
33
|
export function register(ctx, ports, _inventory, extend, autoStart = true) {
|
|
@@ -47,12 +40,10 @@ export function register(ctx, ports, _inventory, extend, autoStart = true) {
|
|
|
47
40
|
}
|
|
48
41
|
export function apply(ctx, config = {}) {
|
|
49
42
|
config = profileSettings(config, ctx.get('profileContext')?.dir);
|
|
50
|
-
const network = ctx.get('aiWorkbenchNetwork')
|
|
51
|
-
const
|
|
52
|
-
ctx.effect(() => () => sources.dispose());
|
|
53
|
-
const ports = configuredPorts(config, network, component, sources);
|
|
43
|
+
const network = ctx.get('aiWorkbenchNetwork');
|
|
44
|
+
const ports = configuredPorts(config, network);
|
|
54
45
|
register(ctx, ports, config.inventory, api => attachProfileRuntime(ctx, api, ports, config, network, true), false);
|
|
55
|
-
registerComponents(ctx, config.inventory, config.
|
|
46
|
+
registerComponents(ctx, config.inventory, config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes);
|
|
56
47
|
}
|
|
57
48
|
export { createProfileEnrollment } from "./profile-enrollment.js";
|
|
58
49
|
export { profileSettings } from "./profile-settings.js";
|
package/lib/integration.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { ComponentSources } from './component-source.ts';
|
|
2
1
|
import type { RuntimeConfig } from './profile-settings.ts';
|
|
3
2
|
import type { Ports } from './ports.ts';
|
|
4
3
|
import { type NetworkProvider } from './provider.ts';
|
|
5
|
-
|
|
6
|
-
export declare function configuredPorts(config: RuntimeConfig, provider?: NetworkProvider, component?: ComponentProgressStore, sources?: ComponentSources): Ports;
|
|
4
|
+
export declare function configuredPorts(config: RuntimeConfig, provider?: NetworkProvider): Ports;
|
package/lib/integration.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
+
import { createBrowserLogin } from "./browser-login.js";
|
|
1
2
|
import { createHostDirectories } from "./host-directories.js";
|
|
2
|
-
import { ComponentDownloadError } from "./component-download.js";
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
3
|
import { readEnrollment } from "./enrollment.js";
|
|
5
4
|
import { adaptNetwork } from "./provider.js";
|
|
6
5
|
import { createRunner, createRemoteLogin } from "./processes.js";
|
|
7
6
|
import { createSsh, sshArgs } from "./ssh.js";
|
|
8
7
|
import { remoteLoginCommand } from "./remote-login.js";
|
|
9
8
|
import { runLogin } from "./login.js";
|
|
10
|
-
import { ensureHelper } from "./cache.js";
|
|
11
|
-
import { launchElectron } from "./electron.js";
|
|
12
9
|
import { parseLoginStatus } from "./auth-status.js";
|
|
13
10
|
import { authFailure } from "./auth-diagnostics.js";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
export function configuredPorts(config, provider, component = createComponentProgress(), sources) {
|
|
11
|
+
import { fail, ok } from "./needs.js";
|
|
12
|
+
export function configuredPorts(config, provider) {
|
|
17
13
|
const ports = {};
|
|
18
14
|
const network = provider ? adaptNetwork(provider) : undefined;
|
|
19
15
|
if (config.enrollmentPackageDir && config.trustDir)
|
|
@@ -29,25 +25,11 @@ export function configuredPorts(config, provider, component = createComponentPro
|
|
|
29
25
|
ports.ssh = { verify: async () => fail('SETTINGS_REQUIRED'), status: async () => fail('SETTINGS_REQUIRED') };
|
|
30
26
|
if (network) {
|
|
31
27
|
ports.network = network;
|
|
32
|
-
ports.login = { run: async (target, provider, signal) => {
|
|
28
|
+
ports.login = { interaction: createBrowserLogin(), run: async (target, provider, signal) => {
|
|
33
29
|
const h = config.helper;
|
|
34
|
-
if (!h || !Number.isSafeInteger(h.remoteKillGraceMs) || h.remoteKillGraceMs < 0 || h.remoteKillGraceMs > 2147483647 || !
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
selection = await sources?.resolve();
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
return { ok: false, error: { ...need('SETTINGS_REQUIRED'), officialReason: e instanceof ComponentDownloadError ? e.message : 'COMPONENT_SOURCE_STATE_INVALID' } };
|
|
42
|
-
}
|
|
43
|
-
const cancellation = new AbortController(), downloadSignal = AbortSignal.any([signal, cancellation.signal]);
|
|
44
|
-
const attempt = component.begin(selection, () => cancellation.abort());
|
|
45
|
-
const result = await ensureHelper({ ...h, source: selection?.source ?? h.source }, { download: source => downloadComponent(source, downloadSignal, h.componentDownloadMaxRedirects), signal: downloadSignal, onProgress: attempt.update });
|
|
46
|
-
if (!result.ok)
|
|
47
|
-
return result;
|
|
48
|
-
if (signal.aborted)
|
|
49
|
-
return fail('LOGIN_FAILED');
|
|
50
|
-
// Component preparation may outlive another device's completed login. Recheck immediately before any destructive CLI authorization.
|
|
30
|
+
if (!h || !Number.isSafeInteger(h.remoteKillGraceMs) || h.remoteKillGraceMs < 0 || h.remoteKillGraceMs > 2147483647 || !Number.isSafeInteger(h.loginOutputMaxBytes) || h.loginOutputMaxBytes < 1)
|
|
31
|
+
return fail('SETTINGS_REQUIRED');
|
|
32
|
+
// Another device may already have completed login: check before starting the CLI.
|
|
51
33
|
if (!ports.ssh)
|
|
52
34
|
return authFailure('integration-pre-login', 'SSH_PORT_MISSING');
|
|
53
35
|
try {
|
|
@@ -67,7 +49,7 @@ export function configuredPorts(config, provider, component = createComponentPro
|
|
|
67
49
|
}
|
|
68
50
|
return runLogin(target, provider, {
|
|
69
51
|
start: (t, p, s) => createRemoteLogin('ssh', [...sshArgs(t), remoteLoginCommand(p, h.remoteKillGraceMs)], p, h.loginOutputMaxBytes, s, 'remote-control'),
|
|
70
|
-
open: (boot, onCode, s) =>
|
|
52
|
+
open: (boot, onCode, s) => ports.login.interaction.open(boot, onCode, s),
|
|
71
53
|
}, signal);
|
|
72
54
|
} };
|
|
73
55
|
}
|
package/lib/login.d.ts
CHANGED
|
@@ -19,13 +19,13 @@ export interface RemoteLogin {
|
|
|
19
19
|
writeCode(code: string): Promise<void>;
|
|
20
20
|
close(): Promise<void>;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface LoginInteraction {
|
|
23
23
|
closed: Promise<void>;
|
|
24
24
|
close(): Promise<void>;
|
|
25
25
|
}
|
|
26
26
|
export interface LoginPorts {
|
|
27
27
|
start(t: SshTarget, p: Provider, s: AbortSignal): Promise<RemoteLogin>;
|
|
28
|
-
open(boot: LoginBoot, onCode: (code: string) => Promise<void>, s: AbortSignal): Promise<
|
|
28
|
+
open(boot: LoginBoot, onCode: (code: string) => Promise<void>, s: AbortSignal): Promise<LoginInteraction>;
|
|
29
29
|
}
|
|
30
30
|
export declare function extractLoginUrl(provider: Provider, text: string): string | undefined;
|
|
31
31
|
export declare function runLogin(t: SshTarget, p: Provider, ports: LoginPorts, parentSignal: AbortSignal): Promise<Result<void>>;
|
package/lib/login.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
const { isClaudeAuthorizeUrl, validateClaudePaste } = createRequire(import.meta.url)('../helper/claude-callback.cjs');
|
|
3
|
-
import { fail, NeedError } from "./needs.js";
|
|
2
|
+
const { isClaudeAuthorizeUrl, isClaudeManualAuthorizeUrl, validateClaudePaste } = createRequire(import.meta.url)('../helper/claude-callback.cjs');
|
|
3
|
+
import { fail, need, NeedError } from "./needs.js";
|
|
4
4
|
export function extractLoginUrl(provider, text) {
|
|
5
5
|
for (const match of text.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '').matchAll(/https:\/\/[^\s<>"']+/g)) {
|
|
6
6
|
try {
|
|
@@ -18,8 +18,9 @@ export async function runLogin(t, p, ports, parentSignal) {
|
|
|
18
18
|
parentSignal.addEventListener('abort', parentAbort, { once: true });
|
|
19
19
|
if (parentSignal.aborted)
|
|
20
20
|
controller.abort();
|
|
21
|
-
let remote,
|
|
21
|
+
let remote, interaction, remove = () => { };
|
|
22
22
|
let result = fail('LOGIN_FAILED');
|
|
23
|
+
const codeFailure = (message) => ({ ok: false, error: { ...need('LOGIN_FAILED'), message } });
|
|
23
24
|
try {
|
|
24
25
|
if (signal.aborted)
|
|
25
26
|
return result;
|
|
@@ -28,7 +29,7 @@ export async function runLogin(t, p, ports, parentSignal) {
|
|
|
28
29
|
const url = await Promise.race([remote.url, cancelled]);
|
|
29
30
|
if (!url.ok)
|
|
30
31
|
return url;
|
|
31
|
-
if (typeof url.value !== 'string' || extractLoginUrl(p, url.value) !== url.value)
|
|
32
|
+
if (typeof url.value !== 'string' || extractLoginUrl(p, url.value) !== url.value || p === 'claude' && !isClaudeManualAuthorizeUrl(url.value))
|
|
32
33
|
return result;
|
|
33
34
|
let deviceCode;
|
|
34
35
|
if (p === 'codex') {
|
|
@@ -42,10 +43,10 @@ export async function runLogin(t, p, ports, parentSignal) {
|
|
|
42
43
|
let codeSent = false, codeError = () => { };
|
|
43
44
|
const failedCode = new Promise(r => codeError = r);
|
|
44
45
|
const boot = p === 'claude' ? { provider: p, url: url.value } : { provider: p, url: url.value, deviceCode: deviceCode };
|
|
45
|
-
|
|
46
|
+
interaction = await ports.open(boot, async (code) => {
|
|
46
47
|
if (p !== 'claude' || codeSent || signal.aborted || !validateClaudePaste(url.value, code)) {
|
|
47
|
-
codeError(
|
|
48
|
-
|
|
48
|
+
codeError(codeFailure('授权码格式不正确或不属于本次登录,请重新发起登录。'));
|
|
49
|
+
throw Error('LOGIN_CODE_REJECTED');
|
|
49
50
|
}
|
|
50
51
|
codeSent = true;
|
|
51
52
|
try {
|
|
@@ -53,9 +54,10 @@ export async function runLogin(t, p, ports, parentSignal) {
|
|
|
53
54
|
}
|
|
54
55
|
catch {
|
|
55
56
|
codeError(fail('LOGIN_FAILED'));
|
|
57
|
+
throw Error('LOGIN_STDIN_FAILED');
|
|
56
58
|
}
|
|
57
59
|
}, signal);
|
|
58
|
-
result = await Promise.race([remote.completion,
|
|
60
|
+
result = await Promise.race([remote.completion.then(r => !r.ok && p === 'claude' ? codeFailure('本次 Claude 登录未完成,主机未确认成功。请重新发起登录。') : r), interaction.closed.then(() => fail('LOGIN_FAILED')), failedCode, cancelled]);
|
|
59
61
|
}
|
|
60
62
|
catch (error) {
|
|
61
63
|
result = error instanceof NeedError ? { ok: false, error: error.need } : fail('LOGIN_FAILED');
|
|
@@ -64,7 +66,7 @@ export async function runLogin(t, p, ports, parentSignal) {
|
|
|
64
66
|
remove();
|
|
65
67
|
parentSignal.removeEventListener('abort', parentAbort);
|
|
66
68
|
// Attempt every cleanup even when one resource fails; surface failure instead of success.
|
|
67
|
-
const cleanup = await Promise.allSettled([
|
|
69
|
+
const cleanup = await Promise.allSettled([interaction?.close(), remote?.close()]);
|
|
68
70
|
if (cleanup.some(r => r.status === 'rejected'))
|
|
69
71
|
result = fail('LOGIN_FAILED');
|
|
70
72
|
}
|
package/lib/needs.js
CHANGED
|
@@ -43,7 +43,7 @@ const entries = {
|
|
|
43
43
|
DEPENDENCY_REQUIRED: { layer: 'integration', message: '远程主机连接的连接组件没有装好,请联系管理员。', requires: '提供方契约与适配器', actor: 'administrator', action: { id: 'supply-dependency', label: '提供集成前置条件', available: false } },
|
|
44
44
|
SETTINGS_REQUIRED: { layer: 'settings', message: '远程主机连接设置暂不可用,请查看技术详情。', requires: '已确认的连接设置', actor: 'administrator', action: { id: 'configure-settings', label: '确认具名设置', available: false } },
|
|
45
45
|
AUTH_STATUS_INVALID: { layer: 'auth', message: '暂时无法确认登录状态,可检查本机网络后重新检查。', requires: '有效的官方 CLI 登录状态', actor: 'administrator', action: { id: 'inspect-auth-status', label: '检查官方 CLI', available: false } },
|
|
46
|
-
LOGIN_FAILED: { layer: 'auth', message: '
|
|
46
|
+
LOGIN_FAILED: { layer: 'auth', message: '登录未完成,可以立即重新发起登录。', requires: '完成 AI 授权', actor: 'employee', action: { id: 'open-login', label: '重新授权', available: true } },
|
|
47
47
|
HOST_TRUST_REQUIRED: { layer: 'ssh', message: '远程主机连接还缺少可信的连接信息,请联系管理员。', requires: 'host.knownHosts', actor: 'administrator', action: { id: 'supply-host-trust', label: '提供主机信任材料', available: false } },
|
|
48
48
|
HOST_KEY_MISMATCH: { layer: 'ssh', message: '主机身份与已开通的信任材料不符,需要管理员检查。', requires: '匹配的主机公钥', actor: 'administrator', action: { id: 'verify-host-trust', label: '检查主机身份', available: false } },
|
|
49
49
|
PROJECT_PROTOCOL_INVALID: { layer: 'projects', message: '本次未能读取工作区位置,可重新打开目录选择器再选。', requires: '匹配版本的工作区服务', actor: 'administrator', action: { id: 'inspect-project-protocol', label: '检查工作区接口', available: false } },
|
package/lib/ports.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface Ports {
|
|
|
35
35
|
status(target: SshTarget, provider: Provider, signal: AbortSignal): Promise<Result<CommandResult>>;
|
|
36
36
|
};
|
|
37
37
|
login?: {
|
|
38
|
+
interaction?: ReturnType<typeof import('./browser-login.ts').createBrowserLogin>;
|
|
38
39
|
run(target: SshTarget, provider: Provider, signal: AbortSignal): Promise<Result<void>>;
|
|
39
40
|
};
|
|
40
41
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import type { Config } from './index.ts';
|
|
2
|
-
export type RuntimeConfig = Config
|
|
3
|
-
|
|
4
|
-
source?: string;
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
export declare function profileSettings(config: Config, profileDir?: string, platform?: string, arch?: string): RuntimeConfig;
|
|
2
|
+
export type RuntimeConfig = Config;
|
|
3
|
+
export declare function profileSettings(config: Config, profileDir?: string, _platform?: string, _arch?: string): RuntimeConfig;
|
package/lib/profile-settings.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { isAbsolute
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// Owner approved technical values, 2026-10-20 settings decision, part two.
|
|
5
|
-
// 组件直接下载;Claude网页遵循员工系统网络,Codex暂保留N主机代理。
|
|
6
|
-
export function profileSettings(config, profileDir, platform = process.platform, arch = process.arch) {
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
import { L_DEFAULTS } from "./defaults.js";
|
|
3
|
+
export function profileSettings(config, profileDir, _platform = process.platform, _arch = process.arch) {
|
|
7
4
|
if (typeof profileDir !== 'string' || !isAbsolute(profileDir))
|
|
8
5
|
return config;
|
|
9
|
-
|
|
10
|
-
return { ...config, commandOutputMaxBytes: config.commandOutputMaxBytes === undefined ? L_DEFAULTS.commandOutputMaxBytes : config.commandOutputMaxBytes, helper: { ...runtime, componentDownloadMaxRedirects: L_DEFAULTS.componentDownloadMaxRedirects, componentObservationIntervalMs: L_DEFAULTS.componentObservationIntervalMs, maxDownloadBytes: L_DEFAULTS.maxDownloadBytes, maxExtractedBytes: L_DEFAULTS.maxExtractedBytes, loginOutputMaxBytes: L_DEFAULTS.loginOutputMaxBytes, ipcMaxBytes: L_DEFAULTS.ipcMaxBytes, remoteKillGraceMs: L_DEFAULTS.remoteKillGraceMs, ...config.helper, ...(platform === 'darwin' && arch === 'arm64' ? { source: COMPONENT_SOURCES.npmmirror.source } : {}), cacheDir: config.helper?.cacheDir === undefined ? join(profileDir, 'ai-workbench-connect', 'login-component-cache') : config.helper.cacheDir } };
|
|
6
|
+
return { ...config, commandOutputMaxBytes: config.commandOutputMaxBytes === undefined ? L_DEFAULTS.commandOutputMaxBytes : config.commandOutputMaxBytes, helper: { remoteKillGraceMs: config.helper?.remoteKillGraceMs === undefined ? L_DEFAULTS.remoteKillGraceMs : config.helper.remoteKillGraceMs, loginOutputMaxBytes: config.helper?.loginOutputMaxBytes === undefined ? L_DEFAULTS.loginOutputMaxBytes : config.helper.loginOutputMaxBytes } };
|
|
11
7
|
}
|
package/lib/remote-login.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Provider } from './api.ts';
|
|
2
|
-
export declare function remoteLoginCommand(provider: Provider, killGraceMs: number
|
|
2
|
+
export declare function remoteLoginCommand(provider: Provider, killGraceMs: number): string;
|
package/lib/remote-login.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
export function remoteLoginCommand(provider, killGraceMs
|
|
2
|
+
export function remoteLoginCommand(provider, killGraceMs) {
|
|
3
3
|
if (provider !== 'claude' && provider !== 'codex')
|
|
4
4
|
throw Error('LOGIN_PROVIDER_INVALID');
|
|
5
5
|
if (!Number.isSafeInteger(killGraceMs) || killGraceMs < 0 || killGraceMs > 2147483647)
|
|
6
6
|
throw Error('REMOTE_KILL_GRACE_REQUIRED');
|
|
7
7
|
const source = readFileSync(new URL('../helper/remote-login.cjs', import.meta.url), 'utf8');
|
|
8
|
-
return "node -e '" + source.replaceAll("'", "'\\''") + "' -- " + provider + ' ' + killGraceMs
|
|
8
|
+
return "node -e '" + source.replaceAll("'", "'\\''") + "' -- " + provider + ' ' + killGraceMs;
|
|
9
9
|
}
|
package/lib/ssh.js
CHANGED
|
@@ -13,7 +13,7 @@ export function proxyCommand(binary, runtimeDir) {
|
|
|
13
13
|
return `${shellQuote(binary)} ssh-proxy --runtime-dir ${shellQuote(runtimeDir)} %h %p`;
|
|
14
14
|
}
|
|
15
15
|
export function sshArgs(t) {
|
|
16
|
-
return ['-F', '/dev/null', '-T', '-o', 'IdentityAgent=none', '-o', 'PubkeyAuthentication=no', '-o', 'PasswordAuthentication=no', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=none', '-o', 'UpdateHostKeys=no', '-o', 'CanonicalizeHostname=no', '-o', 'BatchMode=yes', '-o', 'StrictHostKeyChecking=yes', '-o', 'GlobalKnownHostsFile=/dev/null', '-o', 'UserKnownHostsFile=' + JSON.stringify(t.knownHostsFile.replaceAll('%', '%%')), '-o', 'ProxyCommand=' + t.proxyCommand, '-p', String(t.port), '-l', t.username, t.host];
|
|
16
|
+
return ['-F', '/dev/null', '-T', '-o', 'IdentityAgent=none', '-o', 'PubkeyAuthentication=no', '-o', 'PasswordAuthentication=no', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=none', '-o', 'UpdateHostKeys=no', '-o', 'CanonicalizeHostname=no', '-o', 'BatchMode=yes', '-o', 'ServerAliveInterval=15', '-o', 'ServerAliveCountMax=3', '-o', 'StrictHostKeyChecking=yes', '-o', 'GlobalKnownHostsFile=/dev/null', '-o', 'UserKnownHostsFile=' + JSON.stringify(t.knownHostsFile.replaceAll('%', '%%')), '-o', 'ProxyCommand=' + t.proxyCommand, '-p', String(t.port), '-l', t.username, t.host];
|
|
17
17
|
}
|
|
18
18
|
export async function runRemote(runner, t, command, signal, input) {
|
|
19
19
|
const nonce = randomUUID(), source = await readFile(new URL('../helper/remote-command.cjs', import.meta.url), 'utf8');
|
package/lib/startup.js
CHANGED
|
@@ -188,7 +188,7 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
188
188
|
const mine = generation;
|
|
189
189
|
checkSerial++;
|
|
190
190
|
authorizationId = requestId;
|
|
191
|
-
publish({ ...state, phase: 'authorizing', queuedProviders: [], checkingProviders: [...new Set([...state.checkingProviders, provider])], message: '
|
|
191
|
+
publish({ ...state, phase: 'authorizing', queuedProviders: [], checkingProviders: [...new Set([...state.checkingProviders, provider])], technicalDetails: {}, message: '请在默认浏览器完成本人登录。' });
|
|
192
192
|
const superseded = () => { const failure = authFailure('connect-check-login', 'STATUS_SUPERSEDED'); if (state.requestId === requestId)
|
|
193
193
|
publish({ ...state, phase: 'idle', requestId: undefined, provider: undefined }); result({ requestId, provider, outcome: 'invalidated', need: failure.error }); ask(); return failure; };
|
|
194
194
|
const run = async () => {
|
|
@@ -209,6 +209,24 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
209
209
|
const finalTicket = resultTickets.get(verified);
|
|
210
210
|
if (!login.current || !finalTicket || !currentTicket(finalTicket))
|
|
211
211
|
return superseded();
|
|
212
|
+
if (provider === 'claude' && !verified.ok && verified.error.code === 'LOGIN_FAILED') {
|
|
213
|
+
// A failed attempt is not evidence about the CLI's current sign-in state.
|
|
214
|
+
const refreshed = await observeCheck(provider, () => api.checkLogin(provider));
|
|
215
|
+
if (disposed || mine !== generation)
|
|
216
|
+
return fail(disposed ? 'DISPOSED' : 'CONNECTION_LOST');
|
|
217
|
+
if (!refreshed.current)
|
|
218
|
+
return superseded();
|
|
219
|
+
publish({ ...state, phase: 'idle', requestId: undefined, provider: undefined, technicalDetails: { code: 'LOGIN_FAILED', loginFailureMessage: verified.error.message !== need('LOGIN_FAILED').message ? verified.error.message : undefined } });
|
|
220
|
+
if (disposed || mine !== generation) {
|
|
221
|
+
result({ requestId, provider, outcome: 'invalidated', need: currentNeed(disposed ? 'DISPOSED' : 'CONNECTION_LOST') });
|
|
222
|
+
return fail(disposed ? 'DISPOSED' : 'CONNECTION_LOST');
|
|
223
|
+
}
|
|
224
|
+
result({ requestId, provider, outcome: 'failed', need: verified.error });
|
|
225
|
+
if (disposed || mine !== generation)
|
|
226
|
+
return fail(disposed ? 'DISPOSED' : 'CONNECTION_LOST');
|
|
227
|
+
ask();
|
|
228
|
+
return verified;
|
|
229
|
+
}
|
|
212
230
|
if (!verified.ok || !verified.value.loggedIn) {
|
|
213
231
|
const code = verified.ok ? 'LOGIN_FAILED' : verified.error.code;
|
|
214
232
|
providerFailed(provider, code, verified.ok ? currentNeed(code) : verified.error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-workbench/connect",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.13.1"
|
|
@@ -53,14 +53,12 @@
|
|
|
53
53
|
"@deepseek-ai/schemastery": "3.18.4",
|
|
54
54
|
"@types/js-yaml": "4.0.9",
|
|
55
55
|
"@types/node": "24.0.0",
|
|
56
|
-
"@types/yauzl": "2.10.3",
|
|
57
56
|
"react": "18.3.1",
|
|
58
57
|
"react-test-renderer": "18.3.1",
|
|
59
58
|
"typescript": "5.9.3"
|
|
60
59
|
},
|
|
61
60
|
"dependencies": {
|
|
62
|
-
"js-yaml": "4.3.2"
|
|
63
|
-
"yauzl": "3.4.0"
|
|
61
|
+
"js-yaml": "4.3.2"
|
|
64
62
|
},
|
|
65
63
|
"dsh": {
|
|
66
64
|
"client": {
|
|
@@ -79,8 +77,7 @@
|
|
|
79
77
|
},
|
|
80
78
|
"description": "查看远程主机连接状态并管理 Claude/Codex 登录。",
|
|
81
79
|
"bundleDependencies": [
|
|
82
|
-
"js-yaml"
|
|
83
|
-
"yauzl"
|
|
80
|
+
"js-yaml"
|
|
84
81
|
],
|
|
85
82
|
"publishConfig": {
|
|
86
83
|
"access": "public"
|
package/helper/device-panel.cjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const code=document.getElementById('code'),copy=document.getElementById('copy'),status=document.getElementById('status');
|
|
3
|
-
window.deviceLogin.readCode().then(value=>{code.textContent=value;copy.disabled=false;}).catch(()=>{code.textContent='读取失败';status.textContent='请关闭窗口,回设置查看详情';});
|
|
4
|
-
copy.addEventListener('click',async()=>{try{await window.deviceLogin.copyCode();status.textContent='已复制,请粘贴到下方官方页面';}catch{status.textContent='复制失败,请手动选择上方代码';}});
|
package/helper/device-panel.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
:root{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#202124;background:#f6f7f9;color-scheme:light}*{box-sizing:border-box}body{margin:0}main{height:160px;padding:16px 24px;border-bottom:1px solid #d7dce2;display:grid;grid-template-columns:1fr auto;gap:8px 24px}.label{font-size:12px;color:#586174;display:block}strong{font:700 32px ui-monospace,SFMono-Regular,Consolas,monospace;letter-spacing:2px;user-select:text}.action{display:flex;flex-direction:column;align-items:center;gap:6px;justify-content:center}button{border:0;border-radius:7px;background:#1759bb;color:#fff;font-size:14px;padding:10px 16px;cursor:pointer}button:disabled{opacity:.5;cursor:default}button:focus-visible{outline:3px solid #9bc0fa;outline-offset:3px}#status{font-size:12px;color:#586174}p{grid-column:1/-1;margin:0;font-size:13px;line-height:1.5;color:#465064}
|
package/helper/device-panel.html
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self'; base-uri 'none'; form-action 'none'"><title>登录 Codex</title><link rel="stylesheet" href="device-panel.css"></head><body><main><div><span class="label">本次设备码</span><strong id="code" aria-label="本次设备码">正在读取…</strong></div><div class="action"><button id="copy" type="button" disabled>复制一次性码</button><span id="status" role="status">仅复制本次登录的码</span></div><p>下方网页使用本机网络。登录后复制上方代码,粘贴到官方输码框,再按页面提示确认。当前不支持自动填码。</p></main><script src="device-panel.cjs"></script></body></html>
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
const {contextBridge,ipcRenderer}=require('electron');
|
|
2
|
-
const prefix='--aw-device-channel=',arg=process.argv.find(value=>value.startsWith(prefix));
|
|
3
|
-
if(!arg)throw Error('DEVICE_CHANNEL_REQUIRED');
|
|
4
|
-
const channel=arg.slice(prefix.length);
|
|
5
|
-
contextBridge.exposeInMainWorld('deviceLogin',Object.freeze({readCode:()=>ipcRenderer.invoke(channel+'-read'),copyCode:()=>ipcRenderer.invoke(channel+'-copy')}));
|
package/helper/device-window.cjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const {randomUUID}=require('node:crypto');
|
|
2
|
-
const {join}=require('node:path');
|
|
3
|
-
const {pathToFileURL}=require('node:url');
|
|
4
|
-
function bindDeviceExit(app,close,send,signals=process){
|
|
5
|
-
let finishing;
|
|
6
|
-
const unbind=()=>{signals.removeListener('SIGTERM',finish);app.removeListener('before-quit',beforeQuit);};
|
|
7
|
-
const finish=()=>finishing??=(async()=>{
|
|
8
|
-
try{await close();}catch{send({type:'error',code:'CLEANUP_FAILED'});}
|
|
9
|
-
finally{unbind();app.quit();}
|
|
10
|
-
})();
|
|
11
|
-
const beforeQuit=event=>{event.preventDefault();void finish();};
|
|
12
|
-
signals.on('SIGTERM',finish);app.on('before-quit',beforeQuit);return unbind;
|
|
13
|
-
}
|
|
14
|
-
async function openDeviceWindow({app,BrowserWindow,WebContentsView,session,ipcMain,clipboard},boot,send){
|
|
15
|
-
if(boot.provider!=='codex'||boot.url!=='https://auth.openai.com/codex/device'||typeof boot.deviceCode!=='string'||!boot.deviceCode||/[\x00-\x1f\x7f]/.test(boot.deviceCode))throw Error('DEVICE_BOOT_INVALID');
|
|
16
|
-
const ses=session.fromPartition('aw-device-'+randomUUID(),{cache:false});
|
|
17
|
-
await ses.setProxy({mode:'system'});
|
|
18
|
-
ses.setPermissionRequestHandler((_contents,_permission,callback)=>callback(false));
|
|
19
|
-
ses.on('will-download',event=>event.preventDefault());
|
|
20
|
-
const channel='aw-device-'+randomUUID(),panelFile=join(__dirname,'device-panel.html'),panelUrl=pathToFileURL(panelFile).href;
|
|
21
|
-
const win=new BrowserWindow({title:'登录 Codex',show:true,width:900,height:800,webPreferences:{session:ses,preload:join(__dirname,'device-preload.cjs'),additionalArguments:['--aw-device-channel='+channel],nodeIntegration:false,contextIsolation:true,sandbox:true,devTools:false,spellcheck:false}});
|
|
22
|
-
const page=new WebContentsView({webPreferences:{session:ses,nodeIntegration:false,contextIsolation:true,sandbox:true,devTools:false,spellcheck:false}});
|
|
23
|
-
win.contentView.addChildView(page);
|
|
24
|
-
const layout=()=>{const [width,height]=win.getContentSize();page.setBounds({x:0,y:160,width,height:Math.max(0,height-160)});};layout();win.on('resize',layout);
|
|
25
|
-
let closing,copyAttempted=false,unbindExit=()=>{};const pendingCopies=new Set();
|
|
26
|
-
const check=(event,args)=>{
|
|
27
|
-
if(closing||args.length||event.sender!==win.webContents||event.senderFrame!==win.webContents.mainFrame||event.senderFrame.url!==panelUrl)throw Error('DEVICE_IPC_REJECTED');
|
|
28
|
-
};
|
|
29
|
-
ipcMain.handle(channel+'-read',(event,...args)=>{check(event,args);return boot.deviceCode;});
|
|
30
|
-
ipcMain.handle(channel+'-copy',(event,...args)=>{
|
|
31
|
-
check(event,args);copyAttempted=true;const code=boot.deviceCode;
|
|
32
|
-
const operation=Promise.resolve().then(()=>clipboard.writeText(code)).then(()=>true);
|
|
33
|
-
pendingCopies.add(operation);void operation.then(()=>pendingCopies.delete(operation),()=>pendingCopies.delete(operation));return operation;
|
|
34
|
-
});
|
|
35
|
-
const close=()=>closing??=Promise.resolve().then(async()=>{
|
|
36
|
-
try{
|
|
37
|
-
ipcMain.removeHandler(channel+'-read');ipcMain.removeHandler(channel+'-copy');
|
|
38
|
-
// Do not erase a clipboard the employee has since changed. No clipboard history is retained.
|
|
39
|
-
await Promise.allSettled([...pendingCopies]);
|
|
40
|
-
let clipboardFailed=false;
|
|
41
|
-
try{if(copyAttempted&&(await clipboard.readText())===boot.deviceCode)await clipboard.clear();}catch{clipboardFailed=true;}
|
|
42
|
-
boot.deviceCode='';
|
|
43
|
-
if(!page.webContents.isDestroyed())page.webContents.close({waitForBeforeUnload:false});
|
|
44
|
-
if(!win.isDestroyed())win.destroy();
|
|
45
|
-
const cleaned=await Promise.allSettled([ses.closeAllConnections(),ses.clearStorageData(),ses.clearCache()]);
|
|
46
|
-
if(clipboardFailed||cleaned.some(result=>result.status==='rejected'))throw Error('CLEANUP_FAILED');
|
|
47
|
-
}finally{unbindExit();}
|
|
48
|
-
send({type:'closed'});
|
|
49
|
-
});
|
|
50
|
-
if(app)unbindExit=bindDeviceExit(app,close,send);
|
|
51
|
-
win.on('closed',()=>{void close().catch(()=>send({type:'error',code:'CLEANUP_FAILED'}));});
|
|
52
|
-
win.webContents.setWindowOpenHandler(()=>({action:'deny'}));
|
|
53
|
-
win.webContents.on('will-navigate',(event,url)=>{if((event.url??url)!==panelUrl)event.preventDefault();});
|
|
54
|
-
page.webContents.setWindowOpenHandler(({url})=>{if(url.startsWith('https://'))void page.webContents.loadURL(url).catch(()=>send({type:'error',code:'NAVIGATION_FAILED'}));return {action:'deny'};});
|
|
55
|
-
const httpsOnly=(event,url)=>{if(typeof (event.url??url)!=='string'||!(event.url??url).startsWith('https://'))event.preventDefault();};
|
|
56
|
-
page.webContents.on('will-navigate',httpsOnly);page.webContents.on('will-redirect',httpsOnly);
|
|
57
|
-
try{await win.loadFile(panelFile);await page.webContents.loadURL(boot.url);}catch{if(closing){await closing;return {close};}await close();throw Error('NAVIGATION_FAILED');}
|
|
58
|
-
if(!closing)send({type:'ready'});return {close};
|
|
59
|
-
}
|
|
60
|
-
module.exports={openDeviceWindow,bindDeviceExit};
|
package/helper/main.cjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const {app}=require('electron');
|
|
2
|
-
const {createInterface}=require('node:readline');
|
|
3
|
-
const {openWindow}=require('./window.cjs');
|
|
4
|
-
const input=createInterface({input:process.stdin});let active,started=false;
|
|
5
|
-
const send=event=>{process.stdout.write(JSON.stringify(event)+'\n');if(event.type==='closed')app.quit();};
|
|
6
|
-
input.on('line',async line=>{
|
|
7
|
-
try{
|
|
8
|
-
const message=JSON.parse(line);
|
|
9
|
-
if(started){if(message.type==='close'){await active?.close();app.quit();}return;}
|
|
10
|
-
started=true;
|
|
11
|
-
// Parent creates this private disposable directory; OAuth data remains in a memory session.
|
|
12
|
-
app.setPath('userData',message.userDataDir);app.setPath('sessionData',message.userDataDir);
|
|
13
|
-
app.commandLine.appendSwitch('disable-background-networking');
|
|
14
|
-
app.commandLine.appendSwitch('disable-component-update');
|
|
15
|
-
await app.whenReady();active=await openWindow(require('electron'),message,send);
|
|
16
|
-
}catch{send({type:'error',code:'HELPER_FAILED'});await active?.close();app.quit();}
|
|
17
|
-
});
|
|
18
|
-
input.on('close',async()=>{await active?.close();app.quit();});
|
|
19
|
-
app.on('window-all-closed',()=>{});
|
package/helper/window.cjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const {randomUUID}=require('node:crypto');
|
|
2
|
-
const {isCallback,createClaudeCapture}=require('./claude-callback.cjs');
|
|
3
|
-
async function openWindow(electron,boot,send){
|
|
4
|
-
const {BrowserWindow,session}=electron;
|
|
5
|
-
if(!['claude','codex'].includes(boot.provider))throw new Error('LOGIN_PROVIDER_INVALID');
|
|
6
|
-
if(boot.provider==='codex')return require('./device-window.cjs').openDeviceWindow(electron,boot,send);
|
|
7
|
-
const capture=boot.provider==='claude'?createClaudeCapture(boot.url):null;
|
|
8
|
-
const ses=session.fromPartition('aw-login-'+randomUUID(),{cache:false});
|
|
9
|
-
await ses.setProxy({mode:'system'});
|
|
10
|
-
ses.setPermissionRequestHandler((_contents,_permission,callback)=>callback(false));
|
|
11
|
-
ses.on('will-download',event=>event.preventDefault());
|
|
12
|
-
const win=new BrowserWindow({show:true,webPreferences:{session:ses,nodeIntegration:false,contextIsolation:true,sandbox:true,devTools:false,spellcheck:false}});
|
|
13
|
-
let closing,capturedCode=false;
|
|
14
|
-
const close=()=>closing??=(async()=>{
|
|
15
|
-
if(!win.isDestroyed())win.destroy();
|
|
16
|
-
await ses.closeAllConnections();await ses.clearStorageData();await ses.clearCache();
|
|
17
|
-
send({type:'closed'});
|
|
18
|
-
})();
|
|
19
|
-
win.on('closed',()=>{void close().catch(()=>send({type:'error',code:'CLEANUP_FAILED'}));});
|
|
20
|
-
win.webContents.setWindowOpenHandler(({url})=>{
|
|
21
|
-
if(url.startsWith('https://'))void win.loadURL(url).catch(()=>send({type:'error',code:'NAVIGATION_FAILED'}));
|
|
22
|
-
return {action:'deny'};
|
|
23
|
-
});
|
|
24
|
-
const captureUrl=(url,main,event)=>{
|
|
25
|
-
if(!capture||main!==true||typeof url!=='string')return;
|
|
26
|
-
const result=capture.capture(url);if(result.kind==='unrelated')return;
|
|
27
|
-
event?.preventDefault?.();
|
|
28
|
-
if(result.kind==='code'){capturedCode=true;send({type:'claude-code',code:result.code});}
|
|
29
|
-
else if(result.kind==='error')send({type:'error',code:result.error});
|
|
30
|
-
};
|
|
31
|
-
win.webContents.on('will-navigate',(event,legacyUrl)=>{
|
|
32
|
-
const url=typeof event.url==='string'?event.url:legacyUrl;
|
|
33
|
-
captureUrl(url,true,event);
|
|
34
|
-
if(typeof url!=='string'||!url.startsWith('https://'))event.preventDefault();
|
|
35
|
-
});
|
|
36
|
-
win.webContents.on('will-redirect',(event,legacyUrl,_inPlace,legacyMain)=>{
|
|
37
|
-
captureUrl(typeof event.url==='string'?event.url:legacyUrl,typeof event.isMainFrame==='boolean'?event.isMainFrame:legacyMain,event);
|
|
38
|
-
});
|
|
39
|
-
win.webContents.on('did-navigate',(_event,url)=>captureUrl(url,true));
|
|
40
|
-
try{await win.loadURL(boot.url);}catch(error){
|
|
41
|
-
if(!(capturedCode&&(error?.code==='ERR_ABORTED'||error?.errno===-3))){await close();throw new Error('NAVIGATION_FAILED');}
|
|
42
|
-
}
|
|
43
|
-
send({type:'ready'});
|
|
44
|
-
return {close};
|
|
45
|
-
}
|
|
46
|
-
module.exports={openWindow,isCallback};
|
package/lib/archive.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function unpackZip(zipPath: string, root: string, maxBytes: number, signal?: AbortSignal): Promise<void>;
|
package/lib/archive.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import yauzl from 'yauzl';
|
|
2
|
-
import { createWriteStream, mkdir, symlink } from "./physical-fs.js";
|
|
3
|
-
import { dirname, resolve, relative, isAbsolute } from 'node:path';
|
|
4
|
-
import { pipeline } from 'node:stream/promises';
|
|
5
|
-
export async function unpackZip(zipPath, root, maxBytes, signal) {
|
|
6
|
-
signal?.throwIfAborted();
|
|
7
|
-
const zip = await new Promise((yes, no) => yauzl.open(zipPath, { lazyEntries: true, validateEntrySizes: true }, (e, z) => e ? no(e) : yes(z)));
|
|
8
|
-
const links = [], seen = new Set();
|
|
9
|
-
let total = 0;
|
|
10
|
-
const inside = (path) => { const r = relative(root, path); return r !== '' && !r.startsWith('..') && !isAbsolute(r); };
|
|
11
|
-
try {
|
|
12
|
-
await new Promise((yes, no) => {
|
|
13
|
-
zip.on('error', no);
|
|
14
|
-
zip.on('end', yes);
|
|
15
|
-
zip.on('entry', (entry) => {
|
|
16
|
-
void (async () => {
|
|
17
|
-
signal?.throwIfAborted();
|
|
18
|
-
const path = resolve(root, entry.fileName);
|
|
19
|
-
if (!inside(path) || seen.has(path))
|
|
20
|
-
throw new Error('ZIP_PATH_INVALID');
|
|
21
|
-
seen.add(path);
|
|
22
|
-
total += entry.uncompressedSize;
|
|
23
|
-
if (total > maxBytes)
|
|
24
|
-
throw new Error('EXTRACTED_SIZE_EXCEEDED');
|
|
25
|
-
const mode = (entry.externalFileAttributes >>> 16) & 0xffff, type = mode & 0o170000;
|
|
26
|
-
if (entry.fileName.endsWith('/')) {
|
|
27
|
-
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
28
|
-
zip.readEntry();
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (type !== 0 && type !== 0o100000 && type !== 0o120000)
|
|
32
|
-
throw new Error('ZIP_TYPE_INVALID');
|
|
33
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
34
|
-
const stream = await new Promise((res, rej) => zip.openReadStream(entry, (e, s) => e ? rej(e) : res(s)));
|
|
35
|
-
if (type === 0o120000) {
|
|
36
|
-
const chunks = [];
|
|
37
|
-
for await (const c of stream) {
|
|
38
|
-
signal?.throwIfAborted();
|
|
39
|
-
chunks.push(Buffer.from(c));
|
|
40
|
-
}
|
|
41
|
-
const target = Buffer.concat(chunks).toString('utf8');
|
|
42
|
-
if (isAbsolute(target) || !inside(resolve(dirname(path), target)))
|
|
43
|
-
throw new Error('ZIP_LINK_INVALID');
|
|
44
|
-
links.push({ path, target });
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
await pipeline(stream, createWriteStream(path, { flags: 'wx', mode: mode & 0o111 ? 0o700 : 0o600 }), { signal });
|
|
48
|
-
}
|
|
49
|
-
zip.readEntry();
|
|
50
|
-
})().catch(no);
|
|
51
|
-
});
|
|
52
|
-
zip.readEntry();
|
|
53
|
-
});
|
|
54
|
-
// All ordinary entries are written before symlinks, so no write can traverse an archive symlink.
|
|
55
|
-
for (const link of links) {
|
|
56
|
-
signal?.throwIfAborted();
|
|
57
|
-
await symlink(link.target, link.path);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
zip.close();
|
|
62
|
-
}
|
|
63
|
-
}
|
package/lib/cache.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Result } from './api.ts';
|
|
2
|
-
import { type ComponentProgress } from './component-download.ts';
|
|
3
|
-
export interface HelperSettings {
|
|
4
|
-
source: string;
|
|
5
|
-
cacheDir: string;
|
|
6
|
-
sha256: string;
|
|
7
|
-
maxDownloadBytes: number;
|
|
8
|
-
maxExtractedBytes: number;
|
|
9
|
-
executable: string;
|
|
10
|
-
}
|
|
11
|
-
interface CacheIo {
|
|
12
|
-
download: (source: string) => Promise<Response>;
|
|
13
|
-
unpack: (zip: string, dir: string, maxBytes: number) => Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
export declare function ensureHelper(s: HelperSettings | undefined, io?: {
|
|
16
|
-
download: CacheIo['download'];
|
|
17
|
-
unpack?: CacheIo['unpack'];
|
|
18
|
-
signal?: AbortSignal;
|
|
19
|
-
onProgress?: (progress: ComponentProgress) => void;
|
|
20
|
-
}): Promise<Result<string>>;
|
|
21
|
-
export {};
|