@ai-workbench/connect 0.7.22 → 0.7.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -67
- package/client/index.cjs +93 -65
- package/helper/host-directories.cjs +8 -1
- package/lib/api.d.ts +21 -163
- package/lib/component-download.d.ts +1 -1
- package/lib/component-download.js +1 -1
- package/lib/component-source.d.ts +6 -27
- package/lib/component-source.js +10 -138
- package/lib/components.d.ts +1 -1
- package/lib/components.js +86 -98
- package/lib/connect.d.ts +0 -3
- package/lib/connect.js +15 -62
- package/lib/connection-messages.d.ts +2 -3
- package/lib/connection-messages.js +5 -4
- package/lib/conversation-log.d.ts +9 -0
- package/lib/conversation-log.js +44 -0
- package/lib/cordis.d.ts +1 -4
- package/lib/defaults.d.ts +0 -7
- package/lib/defaults.js +0 -2
- package/lib/enrollment.js +1 -8
- package/lib/host-directories.d.ts +6 -4
- package/lib/host-directories.js +4 -4
- package/lib/host-session-projects.d.ts +8 -58
- package/lib/host-session-projects.js +45 -270
- package/lib/index.d.ts +2 -11
- package/lib/index.js +11 -23
- package/lib/integration.d.ts +2 -2
- package/lib/integration.js +0 -2
- package/lib/native-workspace.d.ts +10 -0
- package/lib/needs.js +13 -25
- package/lib/ports.d.ts +1 -6
- package/lib/profile-runtime.js +59 -152
- package/lib/profile-settings.d.ts +6 -1
- package/lib/profile-settings.js +3 -5
- package/lib/startup.js +2 -2
- package/lib/workspace-directory-picker-types.d.ts +44 -0
- package/lib/workspace-directory-picker-types.js +1 -0
- package/lib/workspace-directory-picker.d.ts +30 -0
- package/lib/workspace-directory-picker.js +394 -0
- package/lib/workspace-location-types.d.ts +3 -7
- package/lib/workspace-locations.d.ts +6 -30
- package/lib/workspace-locations.js +83 -177
- package/package.json +3 -2
- package/helper/projects.cjs +0 -57
- package/lib/conversation-detail-settings.d.ts +0 -32
- package/lib/conversation-detail-settings.js +0 -119
- package/lib/conversation-details.d.ts +0 -30
- package/lib/conversation-details.js +0 -591
- package/lib/host-session-store.d.ts +0 -27
- package/lib/host-session-store.js +0 -130
- package/lib/local-acceptance-store.d.ts +0 -18
- package/lib/local-acceptance-store.js +0 -133
- package/lib/local-user-turn-acceptance.d.ts +0 -76
- package/lib/local-user-turn-acceptance.js +0 -289
- package/lib/local-user-turn-types.d.ts +0 -40
- package/lib/login-diagnostics.d.ts +0 -28
- package/lib/login-diagnostics.js +0 -57
- package/lib/projects.d.ts +0 -4
- package/lib/projects.js +0 -41
- package/lib/workspace-bindings.d.ts +0 -64
- package/lib/workspace-bindings.js +0 -379
- /package/lib/{local-user-turn-types.js → native-workspace.js} +0 -0
|
@@ -1,72 +1,22 @@
|
|
|
1
|
-
import type { ConnectApi, HostSessionProjectTarget,
|
|
2
|
-
import type { HostWorkspaceResolveContext
|
|
1
|
+
import type { ConnectApi, HostSessionProjectTarget, Result, WorkspaceUse } from './api.ts';
|
|
2
|
+
import type { HostWorkspaceResolveContext } from './workspace-location-types.ts';
|
|
3
3
|
import type { createWorkspaceLocations } from './workspace-locations.ts';
|
|
4
|
-
import type { NativeWorkspaceRegistry } from './workspace
|
|
4
|
+
import type { NativeWorkspaceRegistry } from './native-workspace.ts';
|
|
5
5
|
interface Session {
|
|
6
6
|
header: Record<string, any>;
|
|
7
|
-
seq: number;
|
|
8
|
-
}
|
|
9
|
-
interface Event {
|
|
10
|
-
seq: number;
|
|
11
|
-
type: string;
|
|
12
|
-
data: any;
|
|
13
|
-
}
|
|
14
|
-
interface Services {
|
|
15
|
-
sessions: {
|
|
16
|
-
get(id: string): Session | undefined;
|
|
17
|
-
flush(session: Session): Promise<boolean>;
|
|
18
|
-
};
|
|
19
|
-
persistence: {
|
|
20
|
-
identity?: symbol;
|
|
21
|
-
open(id: string, access: 'read'): Promise<{
|
|
22
|
-
id: string;
|
|
23
|
-
access: string;
|
|
24
|
-
header: Record<string, any>;
|
|
25
|
-
inheritedEventCount: number;
|
|
26
|
-
read(): Promise<{
|
|
27
|
-
events: readonly Event[];
|
|
28
|
-
}>;
|
|
29
|
-
close(): Promise<void>;
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
32
7
|
}
|
|
33
8
|
interface Options {
|
|
34
|
-
profileDir: string;
|
|
35
|
-
metadataMaxBytes: number;
|
|
36
9
|
api: ConnectApi;
|
|
37
10
|
registry: NativeWorkspaceRegistry;
|
|
38
|
-
services: () =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
context: () => Promise<Result<{
|
|
44
|
-
identity: string;
|
|
45
|
-
guard?: () => void;
|
|
46
|
-
}>>;
|
|
47
|
-
isHostBindingRevoked: (id: string) => boolean;
|
|
11
|
+
services: () => {
|
|
12
|
+
sessions: {
|
|
13
|
+
get(id: string): Session | undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
48
16
|
withHostBinding: ReturnType<typeof createWorkspaceLocations>['withHostBinding'];
|
|
49
17
|
}
|
|
50
|
-
export declare function changedSessionBinding(): never;
|
|
51
18
|
export declare function createHostSessionProjects(o: Options): {
|
|
52
|
-
active: () => boolean;
|
|
53
|
-
observe: (session: Session, event: Event) => void;
|
|
54
|
-
observeLocations: (state: WorkspaceLocationState) => void;
|
|
55
|
-
observeSessionDisposed: (session: Session) => void;
|
|
56
19
|
resolve: (id: string, use: WorkspaceUse, input: HostWorkspaceResolveContext) => Promise<Result<HostSessionProjectTarget>>;
|
|
57
|
-
readScope: (sessionId: string, provider: Provider, ref?: string, detail?: Pick<RemoteConversationDetail, "sessionId" | "provider" | "instanceId" | "epoch">, expectedIdentity?: string) => Promise<Result<{
|
|
58
|
-
identity: string;
|
|
59
|
-
guard: () => void;
|
|
60
|
-
cacheGuard: () => void;
|
|
61
|
-
}>>;
|
|
62
|
-
withWrite: <T>(detail: RemoteConversationDetail, run: (proof: {
|
|
63
|
-
identity: string;
|
|
64
|
-
hostBindingRef: string;
|
|
65
|
-
guard: () => void;
|
|
66
|
-
}) => Promise<Result<T>>) => Promise<Result<T>>;
|
|
67
|
-
compatible: (id: string, header: any, source: "host" | "local" | "legacy-host", bindingId?: string) => void;
|
|
68
|
-
hasSession: (id: string) => boolean;
|
|
69
20
|
dispose(): void;
|
|
70
21
|
};
|
|
71
|
-
export type HostDetailsAdmission = ReturnType<typeof createHostSessionProjects>;
|
|
72
22
|
export {};
|
|
@@ -1,287 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { basename } from 'node:path';
|
|
1
|
+
import { basename, isAbsolute } from 'node:path';
|
|
3
2
|
import { realpath } from 'node:fs/promises';
|
|
4
|
-
import {
|
|
5
|
-
import { hostProjectStore } from "./host-session-store.js";
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
6
4
|
import { fail, ok, need, NeedError } from "./needs.js";
|
|
7
5
|
const text = (v) => typeof v === 'string' && !!v && !/[\x00-\x1f\x7f]/.test(v);
|
|
8
|
-
const int = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
9
6
|
function reject(code) { throw new NeedError(need(code)); }
|
|
10
|
-
|
|
11
|
-
const
|
|
7
|
+
function changedSessionBinding() {
|
|
8
|
+
const n = need('PROJECT_BINDING_INVALID');
|
|
9
|
+
n.message = '文件来源已改,请新建会话继续';
|
|
10
|
+
n.actor = 'employee';
|
|
11
|
+
n.requires = '新会话与当前文件来源';
|
|
12
|
+
n.action = { id: 'new-session', label: '新建会话继续', available: false };
|
|
13
|
+
throw new NeedError(n);
|
|
14
|
+
}
|
|
12
15
|
export function createHostSessionProjects(o) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
disposed = true; return !disposed; }
|
|
17
|
-
function life(c) { const now = o.api.getConnectionState(); if (!active() || now.phase === 'disposed')
|
|
18
|
-
reject('DISPOSED'); if (now.phase !== 'connected' || now.instanceId !== c.instanceId || now.epoch !== c.epoch)
|
|
19
|
-
reject('CONNECTION_LOST'); }
|
|
20
|
-
function mapping(id, workspaceId) { const list = o.registry.list().filter(w => w.sessionIds.includes(id)), registered = o.registry.get(workspaceId); if (list.length !== 1 || list[0].id !== workspaceId || !registered || registered.path !== list[0].path || !registered.sessionIds.includes(id)) {
|
|
21
|
-
for (const r of store.read())
|
|
22
|
-
if (r.sessionId === id)
|
|
23
|
-
blocked.add(r.id);
|
|
24
|
-
changedSessionBinding();
|
|
25
|
-
} }
|
|
26
|
-
function compatible(id, header, source, bindingId) {
|
|
27
|
-
const existing = store.read().filter(r => r.sessionId === id && sameSessionHeader(r.header, header));
|
|
28
|
-
if (existing.some(r => source !== 'host' || r.bindingId !== bindingId))
|
|
29
|
-
changedSessionBinding();
|
|
30
|
-
}
|
|
31
|
-
function observe(session, event) {
|
|
32
|
-
if (!active() || o.services().sessions.get(session.header.id) !== session)
|
|
33
|
-
return;
|
|
34
|
-
if (event.type === 'turn/start')
|
|
35
|
-
observed.set(session, new Map([[event.seq, { seq: event.seq, type: event.type, data: { turn: event.data.turn } }]]));
|
|
36
|
-
else if (event.type === 'turn/end')
|
|
37
|
-
observed.delete(session);
|
|
38
|
-
else if (event.type === 'user/message' && event.data?.source?.kind === 'user')
|
|
39
|
-
observed.get(session)?.set(event.seq, { seq: event.seq, type: event.type, data: { id: event.data.id } });
|
|
40
|
-
}
|
|
41
|
-
function capture(id, use, c) {
|
|
42
|
-
if (!text(id) || !use || Object.keys(use).sort().join(',') !== 'provider,purpose' || !['claude', 'codex'].includes(use.provider) || use.purpose !== 'user-turn')
|
|
43
|
-
reject('PROJECT_BINDING_REQUIRED');
|
|
44
|
-
if (!c || Object.keys(c).sort().join(',') !== 'epoch,expectedBindingId,instanceId,workspaceId' || !text(c.instanceId) || !int(c.epoch) || !text(c.workspaceId) || !text(c.expectedBindingId))
|
|
45
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
46
|
-
life(c);
|
|
47
|
-
const services = o.services(), session = services.sessions.get(id);
|
|
48
|
-
if (!session || !int(session.seq) || !validHeader(session.header) || session.header.id !== id)
|
|
49
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
50
|
-
const header = structuredClone(session.header), watermark = session.seq, proof = observed.get(session);
|
|
51
|
-
if (!proof || ![...proof.values()].some(e => e.type === 'user/message'))
|
|
52
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
53
|
-
const guard = () => { life(c); mapping(id, c.workspaceId); if (o.services().sessions.get(id) !== session || canonical(session.header) !== canonical(header) || session.seq !== watermark)
|
|
54
|
-
reject('LOCAL_USER_TURN_CHANGED'); };
|
|
55
|
-
guard();
|
|
56
|
-
return { services, session, header, watermark, proof, guard };
|
|
57
|
-
}
|
|
58
|
-
async function verify(c, provider, path, guard) {
|
|
59
|
-
if (typeof c.header.cwd !== 'string' || await realpath(c.header.cwd) !== path)
|
|
60
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
61
|
-
guard();
|
|
62
|
-
if (!await c.services.sessions.flush(c.session))
|
|
63
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
64
|
-
guard();
|
|
65
|
-
const handle = await c.services.persistence.open(c.header.id, 'read');
|
|
66
|
-
let events = [], inherited = 0;
|
|
67
|
-
try {
|
|
68
|
-
guard();
|
|
69
|
-
if (handle.id !== c.header.id || handle.access !== 'read' || !sameSessionHeader(handle.header, c.header) || !int(handle.inheritedEventCount))
|
|
70
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
71
|
-
inherited = handle.inheritedEventCount;
|
|
72
|
-
events = (await handle.read()).events;
|
|
73
|
-
guard();
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
await handle.close();
|
|
77
|
-
}
|
|
78
|
-
guard();
|
|
79
|
-
if (!Array.isArray(events) || events.length < c.watermark || events.some((e, i) => e.seq !== i))
|
|
80
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
81
|
-
let start, step, input, route, routeContext;
|
|
82
|
-
for (const e of events.slice(0, c.watermark)) {
|
|
83
|
-
if (e.type === 'turn/start') {
|
|
84
|
-
start = e;
|
|
85
|
-
step = undefined;
|
|
86
|
-
input = undefined;
|
|
87
|
-
route = undefined;
|
|
88
|
-
routeContext = undefined;
|
|
89
|
-
}
|
|
90
|
-
else if (e.type === 'turn/end') {
|
|
91
|
-
start = undefined;
|
|
92
|
-
step = undefined;
|
|
93
|
-
input = undefined;
|
|
94
|
-
route = undefined;
|
|
95
|
-
routeContext = undefined;
|
|
96
|
-
}
|
|
97
|
-
else if (e.type === 'step/start')
|
|
98
|
-
step = e;
|
|
99
|
-
else if (e.type === 'step/end')
|
|
100
|
-
step = undefined;
|
|
101
|
-
else if (e.type === 'user/message' && start && e.data?.source?.kind === 'user' && c.proof.has(e.seq))
|
|
102
|
-
input = e;
|
|
103
|
-
else if (e.type === 'request/header')
|
|
104
|
-
route = e.data?.header?.config?.provider;
|
|
105
|
-
else if (e.type === 'request/context')
|
|
106
|
-
routeContext = e.data?.provider;
|
|
107
|
-
}
|
|
108
|
-
const expected = provider === 'claude' ? 'claude-code-workbench' : 'codex-remote';
|
|
109
|
-
if (!start || !step || !input || !int(start.data.turn) || step.data.turn !== start.data.turn || [start.seq, step.seq, input.seq].some(n => n < inherited) || !c.proof.has(start.seq) || c.proof.get(start.seq)?.data.turn !== start.data.turn || !text(input.data.id) || !c.proof.has(input.seq) || c.proof.get(input.seq)?.data.id !== input.data.id || route !== expected || routeContext !== undefined && routeContext !== expected)
|
|
110
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
111
|
-
}
|
|
112
|
-
function revoke(bindingId) { const items = store.read(); let changed = false; for (const r of items)
|
|
113
|
-
if (r.bindingId === bindingId && !r.revoked) {
|
|
114
|
-
r.revoked = true;
|
|
115
|
-
changed = true;
|
|
116
|
-
} if (changed) {
|
|
117
|
-
try {
|
|
118
|
-
store.save(items, () => { });
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
uncertain = true;
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
124
|
-
} }
|
|
16
|
+
// 同一运行期的重连保留来源选择;不迁移旧测试会话。
|
|
17
|
+
const sources = new Map();
|
|
18
|
+
let disposed = false;
|
|
125
19
|
async function resolve(id, use, input) {
|
|
126
|
-
let c, location, provider;
|
|
127
|
-
try {
|
|
128
|
-
location = structuredClone(input);
|
|
129
|
-
provider = use?.provider;
|
|
130
|
-
c = capture(id, structuredClone(use), location);
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
return resultError(e);
|
|
134
|
-
}
|
|
135
20
|
try {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
21
|
+
if (!text(id) || !use || Object.keys(use).sort().join(',') !== 'provider,purpose' || !['claude', 'codex'].includes(use.provider) || use.purpose !== 'user-turn')
|
|
22
|
+
reject('PROJECT_BINDING_REQUIRED');
|
|
23
|
+
const provider = use.provider, c = structuredClone(input);
|
|
24
|
+
if (!c || Object.keys(c).sort().join(',') !== 'epoch,expectedBindingId,instanceId,workspaceId' || !text(c.instanceId) || !Number.isSafeInteger(c.epoch) || c.epoch < 0 || !text(c.workspaceId) || !text(c.expectedBindingId))
|
|
25
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
26
|
+
const session = o.services().sessions.get(id);
|
|
27
|
+
if (!session || session.header.id !== id || !text(session.header.cwd) || !isAbsolute(session.header.cwd))
|
|
28
|
+
reject('PROJECT_BINDING_REQUIRED');
|
|
29
|
+
const header = structuredClone(session.header), source = { workspaceId: c.workspaceId, bindingId: c.expectedBindingId, source: 'host' };
|
|
30
|
+
const guard = () => {
|
|
31
|
+
const now = o.api.getConnectionState();
|
|
32
|
+
if (disposed || now.phase === 'disposed')
|
|
33
|
+
reject('DISPOSED');
|
|
34
|
+
if (now.phase !== 'connected' || now.instanceId !== c.instanceId || now.epoch !== c.epoch)
|
|
35
|
+
reject('CONNECTION_LOST');
|
|
36
|
+
const matches = o.registry.list().filter(w => w.sessionIds.includes(id)), registered = o.registry.get(c.workspaceId);
|
|
37
|
+
if (matches.length !== 1 || matches[0].id !== c.workspaceId || !registered || registered.path !== matches[0].path || !registered.sessionIds.includes(id))
|
|
147
38
|
changedSessionBinding();
|
|
148
|
-
|
|
39
|
+
if (o.services().sessions.get(id) !== session || !isDeepStrictEqual(session.header, header))
|
|
40
|
+
reject('PROJECT_BINDING_INVALID');
|
|
41
|
+
const previous = sources.get(id);
|
|
42
|
+
if (previous && !isDeepStrictEqual(previous, source))
|
|
43
|
+
changedSessionBinding();
|
|
44
|
+
};
|
|
45
|
+
guard();
|
|
46
|
+
return await o.withHostBinding(c, async (value) => {
|
|
47
|
+
if (await realpath(header.cwd) !== value.local.path)
|
|
48
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
149
49
|
const ready = await o.api.ensureReady(provider);
|
|
150
|
-
guard();
|
|
151
50
|
if (!ready.ok)
|
|
152
51
|
return ready;
|
|
153
|
-
if (
|
|
52
|
+
if (!isDeepStrictEqual(ready.value, value.target))
|
|
154
53
|
reject('CONNECTION_LOST');
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
commit = () => {
|
|
158
|
-
guard();
|
|
159
|
-
const items = store.read();
|
|
160
|
-
if (items.some(r => r.bindingId === location.expectedBindingId && r.revoked))
|
|
161
|
-
reject('HOST_DIRECTORY_CHANGED');
|
|
162
|
-
const existing = items.find(r => r.sessionId === id && r.provider === provider && sameSessionHeader(r.header, c.header) && r.bindingId === location.expectedBindingId && r.instanceId === location.instanceId && r.epoch === location.epoch && r.runtimeId === runtimeId);
|
|
163
|
-
if (uncertain && (!existing || existing.id !== uncertainRecordId))
|
|
164
|
-
reject('REMOTE_DETAIL_STORAGE_FAILED');
|
|
165
|
-
if (existing) {
|
|
166
|
-
if (blocked.has(existing.id))
|
|
167
|
-
changedSessionBinding();
|
|
168
|
-
if (canonical(existing.header) !== canonical(c.header) || existing.identity !== context.value.identity || canonical(existing.local) !== canonical(value.local))
|
|
169
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
170
|
-
store.verify(existing, guard);
|
|
171
|
-
uncertain = false;
|
|
172
|
-
uncertainRecordId = undefined;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
const record = { id: randomUUID(), sessionId: id, provider, header: c.header, identity: context.value.identity, workspaceId: location.workspaceId, bindingId: location.expectedBindingId, instanceId: location.instanceId, epoch: location.epoch, runtimeId, local: value.local, directory: value.directory, revoked: false, key: '' };
|
|
176
|
-
items.push(record);
|
|
177
|
-
try {
|
|
178
|
-
store.save(items, guard);
|
|
179
|
-
}
|
|
180
|
-
catch (e) {
|
|
181
|
-
if (e instanceof NeedError)
|
|
182
|
-
throw e;
|
|
183
|
-
uncertain = true;
|
|
184
|
-
uncertainRecordId = record.id;
|
|
185
|
-
throw new NeedError(need('REMOTE_DETAIL_STORAGE_FAILED'));
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
guard();
|
|
189
|
-
};
|
|
190
|
-
guard();
|
|
191
|
-
return ok({ instanceId: location.instanceId, epoch: location.epoch, sessionId: id, workspaceId: location.workspaceId, bindingId: location.expectedBindingId, bindingRevision: value.revision, source: 'host', directory: structuredClone(value.directory), project: { name: basename(value.directory.path) || '/', path: value.directory.path }, target: structuredClone(value.target) });
|
|
192
|
-
}, () => commit());
|
|
193
|
-
if (result.ok)
|
|
194
|
-
c.guard();
|
|
195
|
-
return result;
|
|
54
|
+
return ok({ instanceId: c.instanceId, epoch: c.epoch, sessionId: id, workspaceId: c.workspaceId, bindingId: c.expectedBindingId, bindingRevision: value.revision, source: 'host', directory: structuredClone(value.directory), project: { name: basename(value.directory.path) || '/', path: value.directory.path }, target: structuredClone(value.target) });
|
|
55
|
+
}, () => { guard(); sources.set(id, source); });
|
|
196
56
|
}
|
|
197
57
|
catch (e) {
|
|
198
|
-
return
|
|
58
|
+
return e instanceof NeedError ? { ok: false, error: e.need } : fail('PROJECT_BINDING_INVALID');
|
|
199
59
|
}
|
|
200
60
|
}
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
const before = o.api.getConnectionState();
|
|
204
|
-
life(before);
|
|
205
|
-
const items = store.read(), context = await o.context();
|
|
206
|
-
life(before);
|
|
207
|
-
if (!context.ok)
|
|
208
|
-
return context;
|
|
209
|
-
const live = o.services().sessions.get(sessionId), revision = revisions.get(sessionId) ?? 0, rawHeader = await o.readHeader(sessionId), header = rawHeader && structuredClone(rawHeader);
|
|
210
|
-
life(before);
|
|
211
|
-
context.value.guard?.();
|
|
212
|
-
const record = ref ? items.find(r => r.id === ref) : undefined;
|
|
213
|
-
if (ref && !record)
|
|
214
|
-
reject('REMOTE_DETAIL_STORAGE_FAILED');
|
|
215
|
-
if (record && detail && (record.sessionId !== detail.sessionId || record.provider !== detail.provider || record.instanceId !== detail.instanceId || record.epoch !== detail.epoch || expectedIdentity !== undefined && record.identity !== expectedIdentity))
|
|
216
|
-
reject('REMOTE_DETAIL_STORAGE_FAILED');
|
|
217
|
-
const admitted = (record ? [record] : items).filter(r => r.identity === context.value.identity && r.sessionId === sessionId && r.provider === provider && sameSessionHeader(r.header, header));
|
|
218
|
-
if (!admitted.length)
|
|
219
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
220
|
-
const guard = () => { life(before); context.value.guard?.(); const current = o.services().sessions.get(sessionId); if (revision !== (revisions.get(sessionId) ?? 0) || live && current !== live || current && canonical(current.header) !== canonical(header))
|
|
221
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID'); const now = store.read(); for (const r of admitted) {
|
|
222
|
-
const same = now.find(n => n.id === r.id);
|
|
223
|
-
if (!same || canonical({ ...same, revoked: false, key: '' }) !== canonical({ ...r, revoked: false, key: '' }))
|
|
224
|
-
reject('REMOTE_DETAIL_STORAGE_FAILED');
|
|
225
|
-
} };
|
|
226
|
-
guard();
|
|
227
|
-
return ok({ identity: context.value.identity, guard, cacheGuard: () => { guard(); if (!live || o.services().sessions.get(sessionId) !== live)
|
|
228
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID'); } });
|
|
229
|
-
}
|
|
230
|
-
catch (e) {
|
|
231
|
-
return resultError(e);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
async function withWrite(detail, run) {
|
|
235
|
-
try {
|
|
236
|
-
const before = o.api.getConnectionState();
|
|
237
|
-
life(before);
|
|
238
|
-
if (uncertain)
|
|
239
|
-
reject('REMOTE_DETAIL_STORAGE_FAILED');
|
|
240
|
-
const r = store.read().find(r => r.sessionId === detail.sessionId && r.provider === detail.provider && r.instanceId === before.instanceId && r.epoch === before.epoch && r.runtimeId === runtimeId && !r.revoked && !blocked.has(r.id));
|
|
241
|
-
if (!r)
|
|
242
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
243
|
-
if (detail.instanceId !== r.instanceId || detail.epoch !== r.epoch)
|
|
244
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
245
|
-
const header = await o.readHeader(r.sessionId);
|
|
246
|
-
life(before);
|
|
247
|
-
if (canonical(header) !== canonical(r.header))
|
|
248
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
249
|
-
let finalGuard = () => life(before);
|
|
250
|
-
const result = await o.withHostBinding({ instanceId: r.instanceId, epoch: r.epoch, workspaceId: r.workspaceId, expectedBindingId: r.bindingId }, async (value, bindingGuard) => {
|
|
251
|
-
const context = await o.context();
|
|
252
|
-
life(before);
|
|
253
|
-
if (!context.ok)
|
|
254
|
-
return context;
|
|
255
|
-
if (context.value.identity !== r.identity)
|
|
256
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID');
|
|
257
|
-
const guard = () => { life(before); context.value.guard?.(); bindingGuard(); mapping(r.sessionId, r.workspaceId); const current = o.services().sessions.get(r.sessionId); if (!current || canonical(current.header) !== canonical(r.header))
|
|
258
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID'); if (canonical(value.local) !== canonical(r.local))
|
|
259
|
-
reject('WORKSPACE_LOCATION_INVALID'); const same = store.read().find(n => n.id === r.id); if (!same || canonical(same) !== canonical(r) || same.revoked)
|
|
260
|
-
reject('REMOTE_DETAIL_SCOPE_INVALID'); };
|
|
261
|
-
guard();
|
|
262
|
-
finalGuard = guard;
|
|
263
|
-
return run({ identity: r.identity, hostBindingRef: r.id, guard });
|
|
264
|
-
}, () => finalGuard(), false);
|
|
265
|
-
if (result.ok)
|
|
266
|
-
finalGuard();
|
|
267
|
-
return result;
|
|
268
|
-
}
|
|
269
|
-
catch (e) {
|
|
270
|
-
return resultError(e);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
function observeLocations(state) { if (!active() || state.phase !== 'ready')
|
|
274
|
-
return; const items = store.read(), bindings = new Set(items.map(r => r.bindingId)); for (const binding of bindings) {
|
|
275
|
-
const r = items.find(r => r.bindingId === binding), item = state.items.find(i => i.workspaceId === r.workspaceId);
|
|
276
|
-
if (!item) {
|
|
277
|
-
if (!o.registry.get(r.workspaceId))
|
|
278
|
-
revoke(binding);
|
|
279
|
-
}
|
|
280
|
-
else if (item.bindingId !== binding || item.source !== 'host' || o.isHostBindingRevoked(binding))
|
|
281
|
-
revoke(binding);
|
|
282
|
-
} }
|
|
283
|
-
function observeSessionDisposed(session) { for (const r of store.read())
|
|
284
|
-
if (r.sessionId === session.header.id && sameSessionHeader(r.header, session.header))
|
|
285
|
-
blocked.add(r.id); observed.delete(session); revisions.set(session.header.id, (revisions.get(session.header.id) ?? 0) + 1); }
|
|
286
|
-
return { active, observe, observeLocations, observeSessionDisposed, resolve, readScope, withWrite, compatible, hasSession: (id) => store.read().some(r => r.sessionId === id), dispose() { disposed = true; } };
|
|
61
|
+
return { resolve, dispose() { disposed = true; } };
|
|
287
62
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -13,15 +13,9 @@ export { sshArgs } from './ssh.ts';
|
|
|
13
13
|
export declare const name = "ai-workbench-connect";
|
|
14
14
|
export declare const inject: string[];
|
|
15
15
|
export interface Config {
|
|
16
|
-
connectionMessages?: {
|
|
17
|
-
administratorAfterMs?: number;
|
|
18
|
-
};
|
|
19
16
|
workspaceLocations?: {
|
|
20
17
|
pageSize?: number;
|
|
21
|
-
|
|
22
|
-
conversationDetails?: {
|
|
23
|
-
maxEventBytes?: number;
|
|
24
|
-
pageSize?: number;
|
|
18
|
+
pickerSlotPriority?: number;
|
|
25
19
|
};
|
|
26
20
|
inventory?: ComponentInventory;
|
|
27
21
|
enrollmentMetadataMaxBytes?: number;
|
|
@@ -30,12 +24,10 @@ export interface Config {
|
|
|
30
24
|
commandOutputMaxBytes?: number;
|
|
31
25
|
network?: (NetworkSettings & AssemblySettings);
|
|
32
26
|
helper?: {
|
|
33
|
-
componentDownloadSource?: 'github' | 'npmmirror';
|
|
34
27
|
componentObservationIntervalMs?: number;
|
|
35
28
|
componentDownloadMaxRedirects?: number;
|
|
36
29
|
remoteKillGraceMs?: number;
|
|
37
30
|
maxRedirects?: number;
|
|
38
|
-
source?: string;
|
|
39
31
|
sha256?: string;
|
|
40
32
|
cacheDir?: string;
|
|
41
33
|
maxDownloadBytes?: number;
|
|
@@ -46,8 +38,7 @@ export interface Config {
|
|
|
46
38
|
};
|
|
47
39
|
}
|
|
48
40
|
export declare const Config: z<Config>;
|
|
49
|
-
export declare function register(ctx: Context, ports: Ports, _inventory?: ComponentInventory, extend?: (api: import('./api.ts').ConnectApi) => void
|
|
41
|
+
export declare function register(ctx: Context, ports: Ports, _inventory?: ComponentInventory, extend?: (api: import('./api.ts').ConnectApi) => void): void;
|
|
50
42
|
export declare function apply(ctx: Context, config?: Config): void;
|
|
51
43
|
export { createProfileEnrollment } from './profile-enrollment.ts';
|
|
52
|
-
export { createWorkspaceBindings } from './workspace-bindings.ts';
|
|
53
44
|
export { profileSettings } from './profile-settings.ts';
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
export { CONNECTION_MESSAGES, connectionEmployeeMessage } from "./connection-messages.js";
|
|
2
|
-
import { CONNECTION_MESSAGE_DEFAULTS } from "./defaults.js";
|
|
3
2
|
import { WORKSPACE_LOCATION_DEFAULTS } from "./defaults.js";
|
|
4
3
|
import z from '@deepseek-ai/schemastery';
|
|
5
|
-
import { createConversationDetailSettings } from "./conversation-detail-settings.js";
|
|
6
4
|
import { createConnect } from "./connect.js";
|
|
7
5
|
import { configuredPorts } from "./integration.js";
|
|
8
6
|
import { attachProfileRuntime } from "./profile-runtime.js";
|
|
9
7
|
import { profileSettings } from "./profile-settings.js";
|
|
10
|
-
import { createComponentSources
|
|
8
|
+
import { createComponentSources } from "./component-source.js";
|
|
11
9
|
import { createComponentProgress } from "./component-download.js";
|
|
12
|
-
import { L_DEFAULTS, NETWORK_DEFAULTS
|
|
10
|
+
import { L_DEFAULTS, NETWORK_DEFAULTS } from "./defaults.js";
|
|
13
11
|
import { registerComponents } from "./components.js";
|
|
14
12
|
export { writeNetworkConfig, createNetworkClient } from "./network.js";
|
|
15
13
|
export { createConnect } from "./connect.js";
|
|
@@ -21,49 +19,39 @@ const positive = () => z.number().step(1).min(1);
|
|
|
21
19
|
// aiWorkbenchNetwork itself is a required Cordis injection; missing N holds this module from loading.
|
|
22
20
|
// Own technical defaults use the approved settings record; no global DSH policy is changed.
|
|
23
21
|
export const Config = z.object({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
maxEventBytes: positive().max(Number.MAX_SAFE_INTEGER).default(CONVERSATION_DETAIL_DEFAULTS.maxEventBytes).description('conversationDetails.maxEventBytes:完整UTF-8 JSON事件的字节上限;默认1048576,范围1至9007199254740991整数。改大增加单事件存储与内存;改小会拒收超过新值的新事件,不裁剪或删除旧记录。'),
|
|
28
|
-
pageSize: positive().max(Number.MAX_SAFE_INTEGER).default(CONVERSATION_DETAIL_DEFAULTS.pageSize).description('conversationDetails.pageSize:每页条数;默认100,范围1至9007199254740991整数。改大增加一次读取与界面负担,改小增加继续加载次数,不减少完整快照总数。'),
|
|
29
|
-
}).description('管理员诊断记录设置:不自动过期、不按条数淘汰、没有隐藏总条数上限,本版没有清除入口。'),
|
|
30
|
-
enrollmentMetadataMaxBytes: positive().max(2147483647).default(L_DEFAULTS.enrollmentMetadataMaxBytes).description('开通元数据、工作区关联文件、本地接纳关系文件、诊断设置文件及设置提交JSON各单份文件的字节上限;默认1048576,可由管理员修改;改小可能拒绝设置读取/提交,不读取key内容'),
|
|
22
|
+
workspaceLocations: z.object({ pickerSlotPriority: z.transform(z.number().step(1).min(Number.MIN_SAFE_INTEGER).max(-1), value => { if (!Number.isSafeInteger(value))
|
|
23
|
+
throw new TypeError('slot优先级必须是安全负整数'); return value; }, true).default(-10).description('workspaceLocations.pickerSlotPriority:统一目录选择器的官方slot优先级,默认-10,可修改为安全负整数;数值更低者显示,必须低于官方native的0,同优先级冲突会明确报错。'), pageSize: positive().max(Number.MAX_SAFE_INTEGER).default(WORKSPACE_LOCATION_DEFAULTS.pageSize).description('workspaceLocations.pageSize:主机目录每页条数,默认100,可修改;改大增加元数据与内存,超过commandOutputMaxBytes会明确拒绝整页。') }),
|
|
24
|
+
enrollmentMetadataMaxBytes: positive().max(2147483647).default(L_DEFAULTS.enrollmentMetadataMaxBytes).description('开通元数据、工作区来源与选择器状态等单份文件的字节上限;默认1048576,可由管理员修改;改小可能无法读取已有元数据,不读取凭据内容'),
|
|
31
25
|
inventory: z.object({ network: z.string(), connect: z.string(), claude: z.string(), codex: z.string() }).description('由已安装组件的实际版本自动生成,只读信息,不作为功能开关'),
|
|
32
26
|
enrollmentPackageDir: z.string().description('连接资料目录:由管理员安装时配置,员工无需手填'),
|
|
33
27
|
trustDir: z.string().description('主机信任缓存目录:由管理员安装时配置'),
|
|
34
28
|
commandOutputMaxBytes: positive().default(L_DEFAULTS.commandOutputMaxBytes).description('远程命令输出内存上限(字节),默认1048576,管理员可修改'),
|
|
35
29
|
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), downloadMaxRedirects: z.number().step(1).min(0).default(NETWORK_DEFAULTS.downloadMaxRedirects), proxyListen: z.string().default(NETWORK_DEFAULTS.proxyListen), 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), httpMaxResponseHeaderBytes: positive().default(NETWORK_DEFAULTS.httpMaxResponseHeaderBytes), controlMaxBytes: positive() }).description('远程网络连接设置:使用默认技术参数,管理员可修改;路径根据当前用户和应用配置目录生成,员工无需填写'),
|
|
36
30
|
helper: z.object({
|
|
37
|
-
componentDownloadSource: z.union([z.const('github'), z.const('npmmirror')]).description('未保存设置节选择时的初始下载源;未设且无旧source时默认npmmirror(已验证可达的中国镜像),可选github;不自动测速/换源,版本与SHA固定'),
|
|
38
31
|
componentObservationIntervalMs: z.number().step(1).min(1).max(2147483647).default(L_DEFAULTS.componentObservationIntervalMs).description('无进展观察刷新间隔毫秒,默认1000;只刷新秒数,不超时/重试/换源'),
|
|
39
32
|
componentDownloadMaxRedirects: z.number().step(1).min(0).default(L_DEFAULTS.componentDownloadMaxRedirects).description('组件直接HTTPS下载的重定向次数上限;默认3,0拒绝重定向;管理员可改,不改变网页登录网络'),
|
|
40
33
|
remoteKillGraceMs: z.number().step(1).min(0).max(2147483647).default(L_DEFAULTS.remoteKillGraceMs).description('远端本轮登录进程组结束宽限毫秒;默认1000,0立即KILL,管理员可改'),
|
|
41
34
|
maxRedirects: z.number().step(1).min(0).description('兼容旧配置;当前由网络连接组件的downloadMaxRedirects设置控制,此项不再生效'),
|
|
42
|
-
|
|
35
|
+
sha256: z.string().description('darwin-arm64默认使用Electron 44.0.0对应的下载SHA256;管理员可改,必须校验'),
|
|
43
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,管理员可改'),
|
|
44
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,管理员可改'),
|
|
45
38
|
}),
|
|
46
39
|
});
|
|
47
|
-
export function register(ctx, ports, _inventory, extend
|
|
40
|
+
export function register(ctx, ports, _inventory, extend) {
|
|
48
41
|
// 当前独立插件始终检查两品牌;保留旧inventory参数兼容调用,但不以交付清单开关能力。
|
|
49
|
-
const api = createConnect(ports, state => ctx.emit('ai-workbench/connect-state', state), {
|
|
42
|
+
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) });
|
|
50
43
|
extend?.(api);
|
|
51
44
|
ctx.provide('aiWorkbenchConnect', api);
|
|
52
45
|
ctx.effect(() => { void api.refreshLoginPrompts(); return () => api.dispose(); });
|
|
53
46
|
}
|
|
54
47
|
export function apply(ctx, config = {}) {
|
|
55
|
-
const sourceReason = config.helper?.componentDownloadSource !== undefined ? '管理员通过 helper.componentDownloadSource 指定此下载源。' : config.helper?.source !== undefined ? '管理员通过 helper.source 指定此下载源。' : DEFAULT_SOURCE_REASON;
|
|
56
48
|
config = profileSettings(config, ctx.get('profileContext')?.dir);
|
|
57
|
-
const detailSettings = createConversationDetailSettings({ profileDir: ctx.get('profileContext')?.dir, initial: config.conversationDetails, metadataMaxBytes: config.enrollmentMetadataMaxBytes });
|
|
58
|
-
ctx.provide('aiWorkbenchConversationDetailSettings', detailSettings);
|
|
59
|
-
ctx.effect(() => () => detailSettings.dispose());
|
|
60
49
|
const network = ctx.get('aiWorkbenchNetwork'), component = createComponentProgress();
|
|
61
|
-
const sources = createComponentSources({
|
|
50
|
+
const sources = createComponentSources({ sha256: config.helper?.sha256 });
|
|
62
51
|
ctx.effect(() => () => sources.dispose());
|
|
63
52
|
const ports = configuredPorts(config, network, component, sources);
|
|
64
|
-
register(ctx, ports, config.inventory, api => attachProfileRuntime(ctx, api, ports, config, network)
|
|
65
|
-
registerComponents(ctx, config.inventory, config.helper?.cacheDir, component, sources, config.helper?.componentObservationIntervalMs, config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes
|
|
53
|
+
register(ctx, ports, config.inventory, api => attachProfileRuntime(ctx, api, ports, config, network));
|
|
54
|
+
registerComponents(ctx, config.inventory, config.helper?.cacheDir, component, sources, config.helper?.componentObservationIntervalMs, config.enrollmentMetadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes);
|
|
66
55
|
}
|
|
67
56
|
export { createProfileEnrollment } from "./profile-enrollment.js";
|
|
68
|
-
export { createWorkspaceBindings } from "./workspace-bindings.js";
|
|
69
57
|
export { profileSettings } from "./profile-settings.js";
|
package/lib/integration.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentSources } from './component-source.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RuntimeConfig } from './profile-settings.ts';
|
|
3
3
|
import type { Ports } from './ports.ts';
|
|
4
4
|
import { type NetworkProvider } from './provider.ts';
|
|
5
5
|
import { type ComponentProgressStore } from './component-download.ts';
|
|
6
|
-
export declare function configuredPorts(config:
|
|
6
|
+
export declare function configuredPorts(config: RuntimeConfig, provider?: NetworkProvider, component?: ComponentProgressStore, sources?: ComponentSources): Ports;
|
package/lib/integration.js
CHANGED
|
@@ -5,7 +5,6 @@ import { readEnrollment } from "./enrollment.js";
|
|
|
5
5
|
import { adaptNetwork } from "./provider.js";
|
|
6
6
|
import { createRunner, createRemoteLogin } from "./processes.js";
|
|
7
7
|
import { createSsh, sshArgs } from "./ssh.js";
|
|
8
|
-
import { createProjects } from "./projects.js";
|
|
9
8
|
import { remoteLoginCommand } from "./remote-login.js";
|
|
10
9
|
import { runLogin } from "./login.js";
|
|
11
10
|
import { ensureHelper } from "./cache.js";
|
|
@@ -24,7 +23,6 @@ export function configuredPorts(config, provider, component = createComponentPro
|
|
|
24
23
|
if (config.commandOutputMaxBytes !== undefined) {
|
|
25
24
|
const runner = createRunner(config.commandOutputMaxBytes);
|
|
26
25
|
ports.ssh = createSsh(runner, config.commandOutputMaxBytes);
|
|
27
|
-
ports.projects = createProjects(runner);
|
|
28
26
|
ports.hostDirectories = createHostDirectories(runner, config.commandOutputMaxBytes);
|
|
29
27
|
}
|
|
30
28
|
else if (provider)
|