@ai-workbench/connect 0.7.11 → 0.7.14
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/client/index.cjs +28 -8
- package/helper/host-directories.cjs +72 -0
- package/lib/api.d.ts +23 -1
- package/lib/api.js +1 -1
- package/lib/components.d.ts +1 -1
- package/lib/components.js +80 -5
- package/lib/connect.d.ts +3 -0
- package/lib/connect.js +53 -11
- package/lib/connection-messages.d.ts +7 -0
- package/lib/connection-messages.js +6 -0
- package/lib/cordis.d.ts +2 -1
- package/lib/defaults.d.ts +6 -0
- package/lib/defaults.js +2 -0
- package/lib/host-directories.d.ts +53 -0
- package/lib/host-directories.js +76 -0
- package/lib/index.d.ts +8 -1
- package/lib/index.js +9 -4
- package/lib/integration.js +2 -0
- package/lib/local-workspace-context.d.ts +46 -0
- package/lib/local-workspace-context.js +17 -0
- package/lib/needs.js +12 -0
- package/lib/ports.d.ts +2 -0
- package/lib/profile-runtime.js +20 -3
- package/lib/startup.d.ts +1 -1
- package/lib/startup.js +33 -13
- package/lib/workspace-bindings.d.ts +30 -1
- package/lib/workspace-bindings.js +1 -0
- package/lib/workspace-location-types.d.ts +65 -0
- package/lib/workspace-location-types.js +1 -0
- package/lib/workspace-locations.d.ts +45 -0
- package/lib/workspace-locations.js +427 -0
- package/node_modules/argparse/CHANGELOG.md +216 -0
- package/package.json +4 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Result, SshTarget } from './api.ts';
|
|
2
|
+
import type { Runner } from './ssh.ts';
|
|
3
|
+
export interface HostDirectoryIdentity {
|
|
4
|
+
device: string;
|
|
5
|
+
inode: string;
|
|
6
|
+
mtimeNs: string;
|
|
7
|
+
ctimeNs: string;
|
|
8
|
+
}
|
|
9
|
+
export interface HostPermissions {
|
|
10
|
+
read: boolean | null;
|
|
11
|
+
write: boolean | null;
|
|
12
|
+
execute: boolean | null;
|
|
13
|
+
reason?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface HostDirectoryInfo {
|
|
16
|
+
requestedPath: string;
|
|
17
|
+
path: string;
|
|
18
|
+
parentPath: string | null;
|
|
19
|
+
identity: HostDirectoryIdentity;
|
|
20
|
+
entryIdentity: {
|
|
21
|
+
device: string;
|
|
22
|
+
inode: string;
|
|
23
|
+
};
|
|
24
|
+
isSymlink: boolean;
|
|
25
|
+
permissions: HostPermissions;
|
|
26
|
+
}
|
|
27
|
+
export interface HostDirectoryEntry {
|
|
28
|
+
name: string;
|
|
29
|
+
requestedPath: string;
|
|
30
|
+
path?: string;
|
|
31
|
+
identity?: HostDirectoryIdentity;
|
|
32
|
+
entryIdentity: {
|
|
33
|
+
device: string;
|
|
34
|
+
inode: string;
|
|
35
|
+
};
|
|
36
|
+
isSymlink: boolean;
|
|
37
|
+
permissions: HostPermissions;
|
|
38
|
+
errorCode?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface HostDirectoryData extends HostDirectoryInfo {
|
|
41
|
+
entries: HostDirectoryEntry[];
|
|
42
|
+
nextAfter?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface HostDirectoryRequest {
|
|
45
|
+
path?: string;
|
|
46
|
+
after?: string;
|
|
47
|
+
pageSize: number;
|
|
48
|
+
expected?: HostDirectoryIdentity;
|
|
49
|
+
}
|
|
50
|
+
export declare function createHostDirectories(runner: Runner, maxOutputBytes: number): {
|
|
51
|
+
browse: (target: SshTarget, data: HostDirectoryRequest, signal: AbortSignal) => Promise<Result<HostDirectoryData>>;
|
|
52
|
+
inspect: (target: SshTarget, path: string, signal: AbortSignal) => Promise<Result<HostDirectoryInfo>>;
|
|
53
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { runRemote } from "./ssh.js";
|
|
3
|
+
import { fail, ok } from "./needs.js";
|
|
4
|
+
import { AuthDiagnosticError } from "./auth-diagnostics.js";
|
|
5
|
+
const codes = ['HOST_DIRECTORY_INVALID', 'HOST_DIRECTORY_UNREADABLE', 'HOST_DIRECTORY_CHANGED', 'HOST_DIRECTORY_PAGE_TOO_LARGE', 'PROJECT_PROTOCOL_INVALID'];
|
|
6
|
+
const object = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
const decimal = (value) => typeof value === 'string' && /^\d+$/.test(value);
|
|
8
|
+
function validEntryIdentity(value) { return object(value) && decimal(value.device) && decimal(value.inode); }
|
|
9
|
+
function validIdentity(value) { return object(value) && validEntryIdentity(value) && ['mtimeNs', 'ctimeNs'].every(key => typeof value[key] === 'string' && /^-?\d+$/.test(value[key])); }
|
|
10
|
+
function validPermissions(value) { return object(value) && ['read', 'write', 'execute'].every(key => typeof value[key] === 'boolean' || value[key] === null) && ([value.read, value.write, value.execute].includes(null) ? value.reason === 'HOST_PERMISSION_UNKNOWN' : value.reason === undefined); }
|
|
11
|
+
const validPath = (value) => typeof value === 'string' && value.startsWith('/') && !value.includes('\0');
|
|
12
|
+
const validName = (value) => typeof value === 'string' && value !== '' && value !== '.' && value !== '..' && !value.includes('/') && !value.includes('\0');
|
|
13
|
+
function validInfo(value) { return object(value) && validPath(value.requestedPath) && validPath(value.path) && (value.parentPath === null || validPath(value.parentPath)) && validIdentity(value.identity) && validEntryIdentity(value.entryIdentity) && typeof value.isSymlink === 'boolean' && validPermissions(value.permissions); }
|
|
14
|
+
function validEntry(value, parent) {
|
|
15
|
+
if (!object(value) || !validName(value.name) || value.requestedPath !== (parent.endsWith('/') ? parent : parent + '/') + value.name || !validEntryIdentity(value.entryIdentity) || typeof value.isSymlink !== 'boolean' || !validPermissions(value.permissions))
|
|
16
|
+
return false;
|
|
17
|
+
if (value.errorCode !== undefined && !['HOST_DIRECTORY_INVALID', 'HOST_DIRECTORY_UNREADABLE'].includes(value.errorCode))
|
|
18
|
+
return false;
|
|
19
|
+
if (value.path === undefined || value.identity === undefined)
|
|
20
|
+
return value.path === undefined && value.identity === undefined && value.errorCode !== undefined;
|
|
21
|
+
return validPath(value.path) && validIdentity(value.identity) && (value.errorCode !== undefined || value.permissions.read === true && value.permissions.execute === true);
|
|
22
|
+
}
|
|
23
|
+
const binaryCompare = (a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b));
|
|
24
|
+
export function createHostDirectories(runner, maxOutputBytes) {
|
|
25
|
+
async function request(target, operation, data, signal) {
|
|
26
|
+
if (signal.aborted)
|
|
27
|
+
return fail('CONNECTION_LOST');
|
|
28
|
+
if (!Number.isSafeInteger(maxOutputBytes) || maxOutputBytes < 1 || data.path !== undefined && !validPath(data.path) || operation === 'inspect' && data.path === undefined || operation === 'browse' && (!Number.isSafeInteger(data.pageSize) || data.pageSize < 1 || data.expected !== undefined && !validIdentity(data.expected) || data.after !== undefined && (!validName(data.after) || !validIdentity(data.expected))))
|
|
29
|
+
return fail('HOST_DIRECTORY_INVALID');
|
|
30
|
+
try {
|
|
31
|
+
const source = await readFile(new URL('../helper/host-directories.cjs', import.meta.url), 'utf8');
|
|
32
|
+
const command = 'node -e ' + "'" + (source + '\nmain();').replaceAll("'", "'\\''") + "'";
|
|
33
|
+
const raw = await runRemote(runner, target, command, signal, JSON.stringify({ protocolVersion: 1, operation, ...data, maxOutputBytes }));
|
|
34
|
+
if (signal.aborted)
|
|
35
|
+
return fail('CONNECTION_LOST');
|
|
36
|
+
if (raw.exitCode !== 0 || raw.stderr !== '')
|
|
37
|
+
return fail('HOST_DIRECTORY_UNREADABLE');
|
|
38
|
+
if (Buffer.byteLength(raw.stdout, 'utf8') > maxOutputBytes)
|
|
39
|
+
return fail('HOST_DIRECTORY_PAGE_TOO_LARGE');
|
|
40
|
+
let result;
|
|
41
|
+
try {
|
|
42
|
+
result = JSON.parse(raw.stdout);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return fail('PROJECT_PROTOCOL_INVALID');
|
|
46
|
+
}
|
|
47
|
+
if (!object(result) || result.protocolVersion !== 1 || typeof result.ok !== 'boolean')
|
|
48
|
+
return fail('PROJECT_PROTOCOL_INVALID');
|
|
49
|
+
if (!result.ok) {
|
|
50
|
+
const error = result.error;
|
|
51
|
+
const code = object(error) ? codes.find(code => code === error.code) : undefined;
|
|
52
|
+
return fail(code ?? 'PROJECT_PROTOCOL_INVALID');
|
|
53
|
+
}
|
|
54
|
+
if (!validInfo(result.value) || data.path !== undefined && result.value.requestedPath !== data.path)
|
|
55
|
+
return fail('PROJECT_PROTOCOL_INVALID');
|
|
56
|
+
if (operation === 'browse') {
|
|
57
|
+
const value = result.value;
|
|
58
|
+
if (!Array.isArray(value.entries) || value.entries.length > data.pageSize || !value.entries.every(entry => validEntry(entry, value.requestedPath)) || value.entries.some((entry, index) => index > 0 && binaryCompare(value.entries[index - 1].name, entry.name) >= 0 || data.after !== undefined && binaryCompare(entry.name, data.after) <= 0) || value.nextAfter !== undefined && (value.entries.length !== data.pageSize || value.nextAfter !== value.entries[value.entries.length - 1]?.name) || data.expected !== undefined && ['device', 'inode', 'mtimeNs', 'ctimeNs'].some(key => value.identity[key] !== data.expected[key]))
|
|
59
|
+
return fail('PROJECT_PROTOCOL_INVALID');
|
|
60
|
+
}
|
|
61
|
+
return ok(result.value);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (signal.aborted)
|
|
65
|
+
return fail('CONNECTION_LOST');
|
|
66
|
+
if (error instanceof AuthDiagnosticError) {
|
|
67
|
+
if (error.diagnostic.reason === 'OUTPUT_LIMIT_EXCEEDED')
|
|
68
|
+
return fail('HOST_DIRECTORY_PAGE_TOO_LARGE');
|
|
69
|
+
if (error.diagnostic.stage === 'remote-frame')
|
|
70
|
+
return fail('PROJECT_PROTOCOL_INVALID');
|
|
71
|
+
}
|
|
72
|
+
return fail('HOST_DIRECTORY_UNREADABLE');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { browse: (target, data, signal) => request(target, 'browse', data, signal), inspect: (target, path, signal) => request(target, 'inspect', { path }, signal) };
|
|
76
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { CONNECTION_MESSAGES, connectionEmployeeMessage } from './connection-messages.ts';
|
|
1
2
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
3
|
import z from '@deepseek-ai/schemastery';
|
|
3
4
|
export type * from './cordis.ts';
|
|
@@ -12,6 +13,12 @@ export { sshArgs } from './ssh.ts';
|
|
|
12
13
|
export declare const name = "ai-workbench-connect";
|
|
13
14
|
export declare const inject: string[];
|
|
14
15
|
export interface Config {
|
|
16
|
+
connectionMessages?: {
|
|
17
|
+
administratorAfterMs?: number;
|
|
18
|
+
};
|
|
19
|
+
workspaceLocations?: {
|
|
20
|
+
pageSize?: number;
|
|
21
|
+
};
|
|
15
22
|
conversationDetails?: {
|
|
16
23
|
maxEventBytes?: number;
|
|
17
24
|
pageSize?: number;
|
|
@@ -39,7 +46,7 @@ export interface Config {
|
|
|
39
46
|
};
|
|
40
47
|
}
|
|
41
48
|
export declare const Config: z<Config>;
|
|
42
|
-
export declare function register(ctx: Context, ports: Ports, _inventory?: ComponentInventory, extend?: (api: import('./api.ts').ConnectApi) => void): void;
|
|
49
|
+
export declare function register(ctx: Context, ports: Ports, _inventory?: ComponentInventory, extend?: (api: import('./api.ts').ConnectApi) => void, connectionMessages?: Config['connectionMessages']): void;
|
|
43
50
|
export declare function apply(ctx: Context, config?: Config): void;
|
|
44
51
|
export { createProfileEnrollment } from './profile-enrollment.ts';
|
|
45
52
|
export { createWorkspaceBindings } from './workspace-bindings.ts';
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { CONNECTION_MESSAGES, connectionEmployeeMessage } from "./connection-messages.js";
|
|
2
|
+
import { CONNECTION_MESSAGE_DEFAULTS } from "./defaults.js";
|
|
3
|
+
import { WORKSPACE_LOCATION_DEFAULTS } from "./defaults.js";
|
|
1
4
|
import z from '@deepseek-ai/schemastery';
|
|
2
5
|
import { createConversationDetailSettings } from "./conversation-detail-settings.js";
|
|
3
6
|
import { createConnect } from "./connect.js";
|
|
@@ -18,6 +21,8 @@ const positive = () => z.number().step(1).min(1);
|
|
|
18
21
|
// aiWorkbenchNetwork itself is a required Cordis injection; missing N holds this module from loading.
|
|
19
22
|
// Own technical defaults use the approved settings record; no global DSH policy is changed.
|
|
20
23
|
export const Config = z.object({
|
|
24
|
+
connectionMessages: z.object({ administratorAfterMs: positive().max(2147483647).default(CONNECTION_MESSAGE_DEFAULTS.administratorAfterMs).description('connectionMessages.administratorAfterMs:持续断线多久改为“请联系管理员”;默认30000毫秒,范围1至2147483647整数,可修改。改大延后提示、改小提前;只改变提示,不改重连/SSH超时,不重放请求。') }),
|
|
25
|
+
workspaceLocations: z.object({ pageSize: positive().max(Number.MAX_SAFE_INTEGER).default(WORKSPACE_LOCATION_DEFAULTS.pageSize).description('workspaceLocations.pageSize:主机目录每页条数,默认100,可修改;改大增加元数据与内存,超过commandOutputMaxBytes会明确拒绝整页。') }),
|
|
21
26
|
conversationDetails: z.object({
|
|
22
27
|
maxEventBytes: positive().max(Number.MAX_SAFE_INTEGER).default(CONVERSATION_DETAIL_DEFAULTS.maxEventBytes).description('conversationDetails.maxEventBytes:完整UTF-8 JSON事件的字节上限;默认1048576,范围1至9007199254740991整数。改大增加单事件存储与内存;改小会拒收超过新值的新事件,不裁剪或删除旧记录。'),
|
|
23
28
|
pageSize: positive().max(Number.MAX_SAFE_INTEGER).default(CONVERSATION_DETAIL_DEFAULTS.pageSize).description('conversationDetails.pageSize:每页条数;默认100,范围1至9007199254740991整数。改大增加一次读取与界面负担,改小增加继续加载次数,不减少完整快照总数。'),
|
|
@@ -39,9 +44,9 @@ export const Config = z.object({
|
|
|
39
44
|
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,管理员可改'),
|
|
40
45
|
}),
|
|
41
46
|
});
|
|
42
|
-
export function register(ctx, ports, _inventory, extend) {
|
|
47
|
+
export function register(ctx, ports, _inventory, extend, connectionMessages) {
|
|
43
48
|
// 当前独立插件始终检查两品牌;保留旧inventory参数兼容调用,但不以交付清单开关能力。
|
|
44
|
-
const api = createConnect(ports, state => ctx.emit('ai-workbench/connect-state', state), { onConnectionState: state => ctx.emit('ai-workbench/connection-state', state), onPromptState: state => ctx.emit('ai-workbench/login-prompt-state', state), onPromptResult: result => ctx.emit('ai-workbench/login-prompt-result', result) });
|
|
49
|
+
const api = createConnect(ports, state => ctx.emit('ai-workbench/connect-state', state), { connectionMessages, onConnectionState: state => ctx.emit('ai-workbench/connection-state', state), onPromptState: state => ctx.emit('ai-workbench/login-prompt-state', state), onPromptResult: result => ctx.emit('ai-workbench/login-prompt-result', result) });
|
|
45
50
|
extend?.(api);
|
|
46
51
|
ctx.provide('aiWorkbenchConnect', api);
|
|
47
52
|
ctx.effect(() => { void api.refreshLoginPrompts(); return () => api.dispose(); });
|
|
@@ -56,8 +61,8 @@ export function apply(ctx, config = {}) {
|
|
|
56
61
|
const sources = createComponentSources({ profileDir: ctx.get('profileContext')?.dir, metadataMaxBytes: config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes, source: config.helper?.source, sha256: config.helper?.sha256, reason: sourceReason, busy: () => ['downloading', 'verifying', 'unpacking'].includes(component.getState().phase) || ctx.get('aiWorkbenchConnect')?.getLoginPromptState().phase === 'authorizing' });
|
|
57
62
|
ctx.effect(() => () => sources.dispose());
|
|
58
63
|
const ports = configuredPorts(config, network, component, sources);
|
|
59
|
-
register(ctx, ports, config.inventory, api => attachProfileRuntime(ctx, api, ports, config, network));
|
|
60
|
-
registerComponents(ctx, config.inventory, config.helper?.cacheDir, component, sources, config.helper?.componentObservationIntervalMs, config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes);
|
|
64
|
+
register(ctx, ports, config.inventory, api => attachProfileRuntime(ctx, api, ports, config, network), config.connectionMessages);
|
|
65
|
+
registerComponents(ctx, config.inventory, config.helper?.cacheDir, component, sources, config.helper?.componentObservationIntervalMs, config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes, config.connectionMessages?.administratorAfterMs ?? CONNECTION_MESSAGE_DEFAULTS.administratorAfterMs);
|
|
61
66
|
}
|
|
62
67
|
export { createProfileEnrollment } from "./profile-enrollment.js";
|
|
63
68
|
export { createWorkspaceBindings } from "./workspace-bindings.js";
|
package/lib/integration.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHostDirectories } from "./host-directories.js";
|
|
1
2
|
import { ComponentDownloadError } from "./component-download.js";
|
|
2
3
|
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { readEnrollment } from "./enrollment.js";
|
|
@@ -24,6 +25,7 @@ export function configuredPorts(config, provider, component = createComponentPro
|
|
|
24
25
|
const runner = createRunner(config.commandOutputMaxBytes);
|
|
25
26
|
ports.ssh = createSsh(runner, config.commandOutputMaxBytes);
|
|
26
27
|
ports.projects = createProjects(runner);
|
|
28
|
+
ports.hostDirectories = createHostDirectories(runner, config.commandOutputMaxBytes);
|
|
27
29
|
}
|
|
28
30
|
else if (provider)
|
|
29
31
|
ports.ssh = { verify: async () => fail('SETTINGS_REQUIRED'), status: async () => fail('SETTINGS_REQUIRED') };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Result } from './api.ts';
|
|
2
|
+
/** Local metadata; neither OS consent nor an authenticated endpoint identity. */
|
|
3
|
+
export interface LocalWorkspaceContextRequest {
|
|
4
|
+
instanceId: string;
|
|
5
|
+
epoch: number;
|
|
6
|
+
workspaceId: string;
|
|
7
|
+
expectedBindingId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LocalWorkspaceProcess {
|
|
10
|
+
pid: number;
|
|
11
|
+
ppid: number;
|
|
12
|
+
platform: string;
|
|
13
|
+
arch: string;
|
|
14
|
+
executable: string;
|
|
15
|
+
realUid: number;
|
|
16
|
+
effectiveUid: number;
|
|
17
|
+
realGid: number;
|
|
18
|
+
effectiveGid: number;
|
|
19
|
+
account: {
|
|
20
|
+
name: string;
|
|
21
|
+
home: string;
|
|
22
|
+
shell: string | null;
|
|
23
|
+
};
|
|
24
|
+
environment: {
|
|
25
|
+
HOME: string | null;
|
|
26
|
+
PATH: string | null;
|
|
27
|
+
SHELL: string | null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface LocalWorkspaceContext {
|
|
31
|
+
version: 1;
|
|
32
|
+
instanceId: string;
|
|
33
|
+
epoch: number;
|
|
34
|
+
workspaceId: string;
|
|
35
|
+
bindingId: string;
|
|
36
|
+
source: 'local';
|
|
37
|
+
directory: {
|
|
38
|
+
path: string;
|
|
39
|
+
device: number;
|
|
40
|
+
inode: number;
|
|
41
|
+
};
|
|
42
|
+
provenance: 'official-workspace-registry';
|
|
43
|
+
process: LocalWorkspaceProcess;
|
|
44
|
+
}
|
|
45
|
+
/** Read the current backend's OS facts and three named variables. Never spawn a shell. */
|
|
46
|
+
export declare function readLocalWorkspaceProcess(): Result<LocalWorkspaceProcess>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { userInfo } from 'node:os';
|
|
2
|
+
import { fail, ok } from "./needs.js";
|
|
3
|
+
/** Read the current backend's OS facts and three named variables. Never spawn a shell. */
|
|
4
|
+
export function readLocalWorkspaceProcess() {
|
|
5
|
+
if (process.platform !== 'darwin')
|
|
6
|
+
return fail('LOCAL_WORKSPACE_CONTEXT_UNSUPPORTED');
|
|
7
|
+
try {
|
|
8
|
+
const account = userInfo();
|
|
9
|
+
return ok({ pid: process.pid, ppid: process.ppid, platform: process.platform, arch: process.arch, executable: process.execPath,
|
|
10
|
+
realUid: process.getuid(), effectiveUid: process.geteuid(), realGid: process.getgid(), effectiveGid: process.getegid(),
|
|
11
|
+
account: { name: account.username, home: account.homedir, shell: account.shell },
|
|
12
|
+
environment: { HOME: process.env.HOME ?? null, PATH: process.env.PATH ?? null, SHELL: process.env.SHELL ?? null } });
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return fail('LOCAL_WORKSPACE_CONTEXT_UNAVAILABLE');
|
|
16
|
+
}
|
|
17
|
+
}
|
package/lib/needs.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
const entries = {
|
|
2
|
+
LOCAL_WORKSPACE_CONTEXT_UNSUPPORTED: { layer: 'integration', message: '当前平台尚未接入本地工作区进程环境交接。', requires: '已接入平台的本机后端上下文', actor: 'plugin', action: { id: 'inspect-local-workspace-context', label: '查看技术详情', available: false } },
|
|
3
|
+
LOCAL_WORKSPACE_CONTEXT_UNAVAILABLE: { layer: 'integration', message: '本机进程环境无法确认,已停止交接;根因未查明。', requires: '当前进程的真实操作系统账户与环境', actor: 'plugin', action: { id: 'inspect-local-workspace-context', label: '查看技术详情', available: false } },
|
|
4
|
+
HOST_DIRECTORY_INVALID: { layer: 'projects', message: '目录不存在或不是文件夹,请重新选择。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
5
|
+
HOST_DIRECTORY_UNREADABLE: { layer: 'projects', message: '主机目录无法列出,请查看目录权限或连接状态。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
6
|
+
HOST_DIRECTORY_CHANGED: { layer: 'projects', message: '目录内容或位置已变化,请重新浏览后选择。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
7
|
+
HOST_DIRECTORY_PAGE_TOO_LARGE: { layer: 'projects', message: '本页目录元数据超过 commandOutputMaxBytes,请减小每页条数或联系管理员调整。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
8
|
+
WORKSPACE_LOCATION_REQUIRED: { layer: 'projects', message: '请先在远程主机连接设置中选择此工作区的文件来源;旧关联需要确认。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
9
|
+
WORKSPACE_LOCATION_INVALID: { layer: 'projects', message: '工作区位置与当前目录或主机身份不符,请重新选择。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
10
|
+
WORKSPACE_LOCATION_CONFLICT: { layer: 'projects', message: '工作区或连接已变化,请刷新位置后重选。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
11
|
+
WORKSPACE_LOCATION_PROVIDER_REQUIRED: { layer: 'projects', message: '主机文件夹已记录,等待远程提供方接入位置合同后才能执行。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
12
|
+
WORKSPACE_EXECUTION_UNAVAILABLE: { layer: 'projects', message: '本地文件夹已记录,按需远程文件与命令执行尚未接通。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
13
|
+
WORKSPACE_LOCATION_STORAGE_FAILED: { layer: 'projects', message: '工作区位置记录无法读取或保存,已停止操作,请联系管理员。', requires: '当前工作区位置与连接合同', actor: 'employee', action: { id: 'select-workspace-location', label: '查看工作区位置', available: true } },
|
|
2
14
|
REMOTE_DETAIL_INVALID: { layer: 'integration', message: '诊断内容格式无效或含未脱敏认证材料,已拒绝保存。', requires: '有效且已脱敏的诊断与可信连接', actor: 'plugin', action: { id: 'inspect-remote-details', label: '查看技术详情', available: false } },
|
|
3
15
|
REMOTE_DETAIL_SCOPE_INVALID: { layer: 'integration', message: '诊断内容与当前连接、原生会话或已核验品牌关联不符,已拒绝保存。', requires: '有效且已脱敏的诊断与可信连接', actor: 'plugin', action: { id: 'inspect-remote-details', label: '查看技术详情', available: false } },
|
|
4
16
|
REMOTE_DETAIL_STORAGE_FAILED: { layer: 'integration', message: '诊断记录无法持久保存或读取,结果无法确认,请联系管理员。', requires: '有效且已脱敏的诊断与可信连接', actor: 'plugin', action: { id: 'inspect-remote-details', label: '查看技术详情', available: false } },
|
package/lib/ports.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Provider, Result, SshTarget, SessionTarget, HostContext, Project, ProjectList } from './api.ts';
|
|
2
|
+
import type { createHostDirectories } from './host-directories.ts';
|
|
2
3
|
export interface Enrollment {
|
|
3
4
|
authKeyFile?: string;
|
|
4
5
|
hostContext?: HostContext;
|
|
@@ -20,6 +21,7 @@ export type NetworkEvent = {
|
|
|
20
21
|
kind: 'restored';
|
|
21
22
|
};
|
|
22
23
|
export interface Ports {
|
|
24
|
+
hostDirectories?: ReturnType<typeof createHostDirectories>;
|
|
23
25
|
enrollment?: {
|
|
24
26
|
read(signal: AbortSignal): Promise<Result<Enrollment>>;
|
|
25
27
|
};
|
package/lib/profile-runtime.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WORKSPACE_LOCATION_DEFAULTS } from "./defaults.js";
|
|
2
|
+
import { createWorkspaceLocations } from "./workspace-locations.js";
|
|
1
3
|
import { mapNetworkNeed } from "./provider.js";
|
|
2
4
|
import { createProfileEnrollment } from "./profile-enrollment.js";
|
|
3
5
|
import { createWorkspaceBindings } from "./workspace-bindings.js";
|
|
@@ -25,10 +27,14 @@ export function attachProfileRuntime(ctx, api, ports, config, network) {
|
|
|
25
27
|
api.importEnrollment = async () => { const result = await manager.importEnrollment(); if (result.ok && result.value.outcome === 'imported')
|
|
26
28
|
await api.refreshLoginPrompts(); return result; };
|
|
27
29
|
ctx.effect(() => () => manager.dispose());
|
|
30
|
+
let locationRevision = 0;
|
|
28
31
|
let workspaceRevision = 0;
|
|
29
32
|
let lastWorkspaceError;
|
|
30
33
|
ctx.provide('aiWorkbenchWorkspaceDiagnostics', { getLatest: () => lastWorkspaceError });
|
|
31
|
-
ctx.inject(['workspaceRegistry', 'sessions', 'sessionPersistence'], native => {
|
|
34
|
+
ctx.inject(['profileContext', 'workspaceRegistry', 'sessions', 'sessionPersistence'], native => {
|
|
35
|
+
const profile = native.get('profileContext');
|
|
36
|
+
if (!profile || typeof profile.dir !== 'string')
|
|
37
|
+
return;
|
|
32
38
|
const registry = native.get('workspaceRegistry');
|
|
33
39
|
const readHeader = async (id) => {
|
|
34
40
|
const live = native.get('sessions');
|
|
@@ -42,6 +48,17 @@ export function attachProfileRuntime(ctx, api, ports, config, network) {
|
|
|
42
48
|
};
|
|
43
49
|
const bindings = createWorkspaceBindings({ profileDir: profile.dir, metadataMaxBytes: config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes, api, registry,
|
|
44
50
|
readHeader, nextRevision: () => ++workspaceRevision, onState: state => ctx.emit('ai-workbench/workspace-binding-state', state), diagnostic: error => { lastWorkspaceError = error; ctx.emit('ai-workbench/workspace-diagnostic', error); } });
|
|
51
|
+
const locations = createWorkspaceLocations({ profileDir: profile.dir, metadataMaxBytes: config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes, pageSize: config.workspaceLocations?.pageSize ?? WORKSPACE_LOCATION_DEFAULTS.pageSize, nextRevision: () => ++locationRevision, api, registry, readLegacy: bindings.readLegacyLocations, hostDirectories: ports.hostDirectories, onState: state => ctx.emit('ai-workbench/workspace-location-state', state) });
|
|
52
|
+
if (process.platform === 'darwin')
|
|
53
|
+
api.getLocalWorkspaceContext = locations.getLocalWorkspaceContext;
|
|
54
|
+
api.getWorkspaceLocationState = locations.getWorkspaceLocationState;
|
|
55
|
+
api.onWorkspaceLocationState = locations.onWorkspaceLocationState;
|
|
56
|
+
api.refreshWorkspaceLocations = locations.refreshWorkspaceLocations;
|
|
57
|
+
api.browseWorkspaceHostDirectories = locations.browseWorkspaceHostDirectories;
|
|
58
|
+
api.selectWorkspaceLocation = locations.selectWorkspaceLocation;
|
|
59
|
+
native.effect(() => { void locations.refreshWorkspaceLocations(); return api.onConnectionState(() => locations.observeConnection()); });
|
|
60
|
+
native.effect(() => () => { if (api.getLocalWorkspaceContext === locations.getLocalWorkspaceContext)
|
|
61
|
+
delete api.getLocalWorkspaceContext; delete api.getWorkspaceLocationState; delete api.onWorkspaceLocationState; delete api.refreshWorkspaceLocations; delete api.browseWorkspaceHostDirectories; delete api.selectWorkspaceLocation; return locations.dispose(); });
|
|
45
62
|
const settings = ctx.get('aiWorkbenchConversationDetailSettings');
|
|
46
63
|
const context = async () => { const current = api.getModelCatalogTarget('codex'); if (!current.ok)
|
|
47
64
|
return current; const t = current.value.target; try {
|
|
@@ -71,7 +88,7 @@ export function attachProfileRuntime(ctx, api, ports, config, network) {
|
|
|
71
88
|
api.listLoginDiagnostics = loginDiagnostics.listLoginDiagnostics;
|
|
72
89
|
api.getLoginDiagnosticState = loginDiagnostics.getLoginDiagnosticState;
|
|
73
90
|
api.onLoginDiagnosticState = loginDiagnostics.onLoginDiagnosticState;
|
|
74
|
-
const previousContractInfo = api.getContractInfo, detailContractInfo = () => ({ ...previousContractInfo(), remoteConversationDetails: 1, loginDiagnostics: 1 });
|
|
91
|
+
const previousContractInfo = api.getContractInfo, detailContractInfo = () => ({ ...previousContractInfo(), remoteConversationDetails: 1, loginDiagnostics: 1, workspaceLocations: 1, ...(process.platform === 'darwin' && api.getConnectionState().phase !== 'disposed' ? { localWorkspaceContext: 1 } : {}) });
|
|
75
92
|
api.getContractInfo = detailContractInfo;
|
|
76
93
|
native.effect(() => { details.observeConnection(api.getConnectionState()); return api.onConnectionState(details.observeConnection); });
|
|
77
94
|
native.effect(() => { loginDiagnostics.observeConnection(api.getConnectionState()); return api.onConnectionState(loginDiagnostics.observeConnection); });
|
|
@@ -81,7 +98,7 @@ export function attachProfileRuntime(ctx, api, ports, config, network) {
|
|
|
81
98
|
api.getWorkspaceBindingState = bindings.getWorkspaceBindingState;
|
|
82
99
|
api.onWorkspaceBindingState = bindings.onWorkspaceBindingState;
|
|
83
100
|
api.acknowledgeWorkspaceNotice = bindings.acknowledgeWorkspaceNotice;
|
|
84
|
-
api.resolveSessionProject = bindings.resolveSessionProject;
|
|
101
|
+
api.resolveSessionProject = (sessionId, use) => locations.resolveLegacySession(sessionId, () => bindings.resolveSessionProject(sessionId, use));
|
|
85
102
|
native.effect(() => () => { api.resolveSessionProject = async () => fail('DEPENDENCY_REQUIRED'); api.acknowledgeWorkspaceNotice = async () => fail('DEPENDENCY_REQUIRED'); return bindings.dispose(); });
|
|
86
103
|
});
|
|
87
104
|
}
|
package/lib/startup.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConnectApi, ConnectionState, LoginPromptState, LoginPromptResult, LoginState, Provider, NeedCode, Result } from './api.ts';
|
|
2
2
|
export type StartupState = LoginPromptState;
|
|
3
|
-
export declare function employeeMessage(code?: NeedCode): string;
|
|
3
|
+
export declare function employeeMessage(code?: NeedCode, connection?: ConnectionState): string;
|
|
4
4
|
type Operations = Pick<ConnectApi, 'connect' | 'checkLogin' | 'login' | 'getState'>;
|
|
5
5
|
export declare function createStartup(api: Operations, providers: Provider[], emit?: (s: LoginPromptState) => void, result?: (r: LoginPromptResult) => void, instanceId?: string): {
|
|
6
6
|
getState: () => LoginPromptState;
|
package/lib/startup.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { connectionEmployeeMessage, isConnectionInterruption } from "./connection-messages.js";
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { fail, need, ok } from "./needs.js";
|
|
3
|
+
import { fail as baseFail, need, ok } from "./needs.js";
|
|
3
4
|
import { authFailure } from "./auth-diagnostics.js";
|
|
4
|
-
export function employeeMessage(code) {
|
|
5
|
+
export function employeeMessage(code, connection) {
|
|
6
|
+
const message = connectionEmployeeMessage(connection);
|
|
7
|
+
if (message)
|
|
8
|
+
return message;
|
|
5
9
|
if (code === 'ENROLLMENT_RESULT_UNKNOWN' || code === 'ENROLLMENT_REJECTED')
|
|
6
10
|
return need(code).message;
|
|
7
11
|
if (code === 'DEPENDENCY_REQUIRED')
|
|
@@ -17,23 +21,28 @@ export function employeeMessage(code) {
|
|
|
17
21
|
return '远程主机暂时连不上,请联系管理员。';
|
|
18
22
|
}
|
|
19
23
|
export function createStartup(api, providers, emit = () => { }, result = () => { }, instanceId = randomUUID()) {
|
|
20
|
-
let disposed = false, revision = 0, serial = 0, generation = 0, checkSerial = 0, connectionPhase = 'unavailable', observedConnected = false;
|
|
24
|
+
let disposed = false, revision = 0, serial = 0, generation = 0, checkSerial = 0, connectionPhase = 'unavailable', observedConnected = false, observedUnavailable = false;
|
|
21
25
|
let flight, authorization, authorizationId;
|
|
22
26
|
const pending = new Set(), listeners = new Set(), deferred = new Set();
|
|
23
27
|
const providerSerial = new Map();
|
|
24
28
|
const resultTickets = new WeakMap();
|
|
29
|
+
let observedConnection;
|
|
30
|
+
const currentNeed = (code) => { const value = need(code), message = connectionEmployeeMessage(observedConnection); if (message && isConnectionInterruption(code))
|
|
31
|
+
value.message = message; return value; };
|
|
32
|
+
const fail = (code) => { const result = baseFail(code), message = connectionEmployeeMessage(observedConnection); if (!result.ok && message && isConnectionInterruption(code))
|
|
33
|
+
result.error.message = message; return result; };
|
|
25
34
|
let connectionEpoch, connectionInstance;
|
|
26
35
|
let state = { instanceId, revision: 0, phase: 'checking', message: '正在连接远程主机…', logins: {}, queuedProviders: [...providers], checkingProviders: [], providerNeeds: {}, technicalDetails: {} };
|
|
27
|
-
const publish = (next) => { state = { ...next, instanceId, revision: ++revision }; emit(structuredClone(state)); for (const listener of listeners)
|
|
36
|
+
const publish = (next) => { state = { ...next, ...(next.phase !== 'disposed' && connectionEmployeeMessage(observedConnection) ? { message: connectionEmployeeMessage(observedConnection) } : {}), instanceId, revision: ++revision }; emit(structuredClone(state)); for (const listener of listeners)
|
|
28
37
|
listener(structuredClone(state)); };
|
|
29
38
|
const track = (p) => { pending.add(p); void p.then(() => pending.delete(p), () => pending.delete(p)); return p; };
|
|
30
39
|
const close = (outcome, code) => { if (state.requestId && state.provider) {
|
|
31
|
-
const terminal = { requestId: state.requestId, provider: state.provider, outcome, ...(code ? { need:
|
|
40
|
+
const terminal = { requestId: state.requestId, provider: state.provider, outcome, ...(code ? { need: currentNeed(code) } : {}) };
|
|
32
41
|
publish({ ...state, requestId: undefined, provider: undefined });
|
|
33
42
|
result(terminal);
|
|
34
43
|
} };
|
|
35
44
|
const blocked = (code) => { const mine = generation; close('invalidated', code); if (disposed || mine !== generation)
|
|
36
|
-
return; publish({ phase: 'blocked', message: employeeMessage(code), logins: {}, queuedProviders: [], checkingProviders: [], providerNeeds: {}, technicalDetails: { ...state.technicalDetails, code } }); };
|
|
45
|
+
return; publish({ phase: 'blocked', message: employeeMessage(code, observedConnection), logins: {}, queuedProviders: [], checkingProviders: [], providerNeeds: {}, technicalDetails: { ...state.technicalDetails, code } }); };
|
|
37
46
|
const snapshot = () => state.phase === 'disposed' ? fail('DISPOSED') : state.phase === 'blocked' ? fail(state.technicalDetails.code ?? 'AUTH_STATUS_INVALID') : ok(structuredClone(state));
|
|
38
47
|
const ask = () => {
|
|
39
48
|
if (disposed || state.phase === 'blocked' || state.phase === 'disposed')
|
|
@@ -70,7 +79,7 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
70
79
|
const terminal = clearTicket ? { requestId: state.requestId, provider, outcome: logins[provider] === true ? 'logged-in' : 'invalidated', ...(providerNeeds[provider] ? { need: structuredClone(providerNeeds[provider]) } : {}) } : undefined;
|
|
71
80
|
publish({ ...state, ...(clearTicket ? { requestId: undefined, provider: undefined } : {}), logins, providerNeeds, checkingProviders: state.checkingProviders.filter(p => p !== provider) });
|
|
72
81
|
if (terminal)
|
|
73
|
-
result(currentTicket(ticket) ? terminal : { ...terminal, outcome: 'invalidated', need:
|
|
82
|
+
result(currentTicket(ticket) ? terminal : { ...terminal, outcome: 'invalidated', need: currentNeed(disposed ? 'DISPOSED' : 'CONNECTION_LOST') });
|
|
74
83
|
if (!currentTicket(ticket))
|
|
75
84
|
return false;
|
|
76
85
|
if (!flight && !authorization)
|
|
@@ -150,7 +159,7 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
150
159
|
flight = undefined; });
|
|
151
160
|
return promise;
|
|
152
161
|
};
|
|
153
|
-
const providerFailed = (provider, code, sourceNeed =
|
|
162
|
+
const providerFailed = (provider, code, sourceNeed = currentNeed(code)) => {
|
|
154
163
|
const logins = { ...state.logins };
|
|
155
164
|
delete logins[provider];
|
|
156
165
|
publish({ ...state, phase: 'idle', requestId: undefined, provider: undefined, logins, checkingProviders: state.checkingProviders.filter(p => p !== provider), providerNeeds: { ...state.providerNeeds, [provider]: structuredClone(sourceNeed) } });
|
|
@@ -202,8 +211,8 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
202
211
|
return superseded();
|
|
203
212
|
if (!verified.ok || !verified.value.loggedIn) {
|
|
204
213
|
const code = verified.ok ? 'LOGIN_FAILED' : verified.error.code;
|
|
205
|
-
providerFailed(provider, code, verified.ok ?
|
|
206
|
-
result({ requestId, provider, outcome: 'failed', need: verified.ok ?
|
|
214
|
+
providerFailed(provider, code, verified.ok ? currentNeed(code) : verified.error);
|
|
215
|
+
result({ requestId, provider, outcome: 'failed', need: verified.ok ? currentNeed(code) : verified.error });
|
|
207
216
|
return disposed || mine !== generation ? fail(disposed ? 'DISPOSED' : 'CONNECTION_LOST') : verified.ok ? fail(code) : verified;
|
|
208
217
|
}
|
|
209
218
|
deferred.delete(provider);
|
|
@@ -211,7 +220,7 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
211
220
|
delete providerNeeds[provider];
|
|
212
221
|
publish({ ...state, requestId: undefined, provider: undefined, logins: { ...state.logins, [provider]: true }, providerNeeds, checkingProviders: state.checkingProviders.filter(p => p !== provider), phase: 'idle' });
|
|
213
222
|
if (disposed || mine !== generation) {
|
|
214
|
-
result({ requestId, provider, outcome: 'invalidated', need:
|
|
223
|
+
result({ requestId, provider, outcome: 'invalidated', need: currentNeed(disposed ? 'DISPOSED' : 'CONNECTION_LOST') });
|
|
215
224
|
return fail(disposed ? 'DISPOSED' : 'CONNECTION_LOST');
|
|
216
225
|
}
|
|
217
226
|
result({ requestId, provider, outcome: 'logged-in' });
|
|
@@ -223,7 +232,7 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
223
232
|
catch {
|
|
224
233
|
if (disposed || mine !== generation)
|
|
225
234
|
return fail(disposed ? 'DISPOSED' : 'CONNECTION_LOST');
|
|
226
|
-
result({ requestId, provider, outcome: 'failed', need:
|
|
235
|
+
result({ requestId, provider, outcome: 'failed', need: currentNeed('LOGIN_FAILED') });
|
|
227
236
|
providerFailed(provider, 'LOGIN_FAILED');
|
|
228
237
|
return fail('LOGIN_FAILED');
|
|
229
238
|
}
|
|
@@ -267,6 +276,8 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
267
276
|
connectionChanged(next) {
|
|
268
277
|
if (disposed)
|
|
269
278
|
return;
|
|
279
|
+
const previousRecovery = observedConnection?.recovery?.phase;
|
|
280
|
+
observedConnection = structuredClone(next);
|
|
270
281
|
const prior = connectionPhase;
|
|
271
282
|
connectionPhase = next.phase;
|
|
272
283
|
const changed = connectionEpoch !== undefined && (connectionEpoch !== next.epoch || connectionInstance !== next.instanceId);
|
|
@@ -281,14 +292,23 @@ export function createStartup(api, providers, emit = () => { }, result = () => {
|
|
|
281
292
|
return;
|
|
282
293
|
publish({ phase: 'checking', message: '正在连接远程主机…', logins: {}, queuedProviders: [], checkingProviders: [], providerNeeds: {}, technicalDetails: {} });
|
|
283
294
|
}
|
|
295
|
+
if (!changed && prior === next.phase && next.recovery && previousRecovery !== next.recovery.phase) {
|
|
296
|
+
publish({ ...state, message: next.recovery.message });
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
284
299
|
if (next.phase === 'unavailable' || next.phase === 'disposed') {
|
|
300
|
+
if (next.phase === 'unavailable')
|
|
301
|
+
observedUnavailable = true;
|
|
285
302
|
generation++;
|
|
286
303
|
flight = undefined;
|
|
287
304
|
blocked(next.need?.code ?? (next.phase === 'disposed' ? 'DISPOSED' : 'CONNECTION_LOST'));
|
|
288
305
|
}
|
|
289
306
|
else if (next.phase === 'connected' && prior !== 'connected') {
|
|
290
|
-
const restored = observedConnected;
|
|
307
|
+
const restored = observedConnected || observedUnavailable;
|
|
291
308
|
observedConnected = true;
|
|
309
|
+
observedUnavailable = false;
|
|
310
|
+
if (state.phase === 'blocked')
|
|
311
|
+
publish({ ...state, phase: 'checking', message: '正在检查登录状态…' });
|
|
292
312
|
if (restored) {
|
|
293
313
|
const mine = generation;
|
|
294
314
|
queueMicrotask(() => { void Promise.resolve(authorization).then(() => { if (!disposed && mine === generation && connectionPhase === 'connected')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConnectApi, SessionProjectTarget, Result, ConnectionState, WorkspaceBindingState, WorkspaceNoticeReceipt, WorkspaceUse, Provider, SshTarget } from './api.ts';
|
|
1
|
+
import type { ConnectApi, Project, SessionProjectTarget, Result, ConnectionState, WorkspaceBindingState, WorkspaceNoticeReceipt, WorkspaceUse, Provider, SshTarget } from './api.ts';
|
|
2
2
|
export interface NativeWorkspace {
|
|
3
3
|
id: string;
|
|
4
4
|
path: string;
|
|
@@ -9,6 +9,33 @@ export interface NativeWorkspaceRegistry {
|
|
|
9
9
|
get(id: string): NativeWorkspace | undefined;
|
|
10
10
|
list(): NativeWorkspace[];
|
|
11
11
|
}
|
|
12
|
+
interface Claim {
|
|
13
|
+
id: string;
|
|
14
|
+
sessionId: string;
|
|
15
|
+
provider: Provider;
|
|
16
|
+
owner: string;
|
|
17
|
+
deliveryId?: string;
|
|
18
|
+
}
|
|
19
|
+
interface Binding {
|
|
20
|
+
key: string;
|
|
21
|
+
identity: string;
|
|
22
|
+
workspaceId: string;
|
|
23
|
+
localPath: string;
|
|
24
|
+
localDev: number;
|
|
25
|
+
localIno: number;
|
|
26
|
+
project: Project;
|
|
27
|
+
bindingId: string;
|
|
28
|
+
noticeId: string;
|
|
29
|
+
sessionIds: string[];
|
|
30
|
+
accepted?: {
|
|
31
|
+
sessionId: string;
|
|
32
|
+
provider: Provider;
|
|
33
|
+
}[];
|
|
34
|
+
phase: 'intent' | 'bound';
|
|
35
|
+
settings: 'pending' | 'displayed';
|
|
36
|
+
provider: 'pending' | 'claimed' | 'delivered' | 'unknown';
|
|
37
|
+
claim?: Claim;
|
|
38
|
+
}
|
|
12
39
|
export interface WorkspaceBindingOptions {
|
|
13
40
|
profileDir: string;
|
|
14
41
|
metadataMaxBytes: number;
|
|
@@ -23,6 +50,7 @@ export interface WorkspaceBindingOptions {
|
|
|
23
50
|
diagnostic?: (error: unknown) => void;
|
|
24
51
|
}
|
|
25
52
|
export declare function createWorkspaceBindings(options: WorkspaceBindingOptions): {
|
|
53
|
+
readLegacyLocations: () => Promise<Binding[]>;
|
|
26
54
|
observeConnection(state: ConnectionState): void;
|
|
27
55
|
dispose(): Promise<unknown>;
|
|
28
56
|
verifyRemoteConversationScope: (sessionId: string, provider: Provider, target: SshTarget) => Promise<Result<{
|
|
@@ -33,3 +61,4 @@ export declare function createWorkspaceBindings(options: WorkspaceBindingOptions
|
|
|
33
61
|
acknowledgeWorkspaceNotice: (receipt: WorkspaceNoticeReceipt) => Promise<Result<void>>;
|
|
34
62
|
resolveSessionProject: (sessionId: string, use: WorkspaceUse) => Promise<Result<SessionProjectTarget>>;
|
|
35
63
|
};
|
|
64
|
+
export {};
|
|
@@ -364,6 +364,7 @@ export function createWorkspaceBindings(options) {
|
|
|
364
364
|
diagnostic(error);
|
|
365
365
|
} });
|
|
366
366
|
return {
|
|
367
|
+
readLegacyLocations: () => serialized(async () => { await prepare(); return structuredClone(await records()); }),
|
|
367
368
|
observeConnection(state) { if (disposed)
|
|
368
369
|
return; for (const [id, status] of statuses)
|
|
369
370
|
if (status === 'ready')
|