@ai-workbench/connect 0.7.36 → 0.7.38
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 +3 -1
- package/client/index.cjs +63 -28
- package/helper/auth-status.cjs +4 -3
- package/lib/api.d.ts +3 -1
- package/lib/components.js +17 -2
- package/lib/connect.js +137 -8
- package/lib/host-session-projects.d.ts +1 -0
- package/lib/host-session-projects.js +5 -0
- package/lib/needs.js +1 -0
- package/lib/ports.d.ts +3 -0
- package/lib/profile-activation.d.ts +10 -0
- package/lib/profile-activation.js +74 -3
- package/lib/profile-enrollment.d.ts +12 -0
- package/lib/profile-enrollment.js +138 -35
- package/lib/profile-runtime.js +35 -14
- package/lib/provider.d.ts +14 -0
- package/lib/ssh.js +12 -0
- package/lib/startup.d.ts +6 -0
- package/lib/startup.js +10 -1
- package/lib/workspace-locations.d.ts +12 -0
- package/lib/workspace-locations.js +48 -3
- package/package.json +1 -1
|
@@ -94,7 +94,7 @@ export function createWorkspaceLocations(o) {
|
|
|
94
94
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
95
95
|
const result = [], ids = new Set(), active = new Set();
|
|
96
96
|
for (const r of data.items) {
|
|
97
|
-
if (r?.source === 'legacy-host'
|
|
97
|
+
if (r?.source === 'legacy-host')
|
|
98
98
|
continue;
|
|
99
99
|
if (!obj(r) || !token(r.workspaceId) || typeof r.active !== 'boolean' || r.active && active.has(r.workspaceId))
|
|
100
100
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
@@ -102,7 +102,11 @@ export function createWorkspaceLocations(o) {
|
|
|
102
102
|
// 旧记录仅取主机与路径;旧 identity/key/dev/ino 不再属于主机来源合同。
|
|
103
103
|
if (!obj(r.host) || !token(r.host.host) || !obj(r.remote) || !token(r.remote.path) || !isAbsolute(r.remote.path))
|
|
104
104
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
105
|
-
|
|
105
|
+
if (r.host.username !== undefined && !/^emp-[a-z0-9][a-z0-9-]*$/.test(r.host.username))
|
|
106
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
107
|
+
if (r.sessionIds !== undefined && (!Array.isArray(r.sessionIds) || r.sessionIds.some((id) => !token(id)) || new Set(r.sessionIds).size !== r.sessionIds.length))
|
|
108
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
109
|
+
result.push({ workspaceId: r.workspaceId, source: 'host', active: r.active, ...(r.sessionIds !== undefined ? { sessionIds: [...r.sessionIds] } : {}), host: { host: r.host.host, ...(r.host.username ? { username: r.host.username } : {}) }, remote: { path: r.remote.path } });
|
|
106
110
|
}
|
|
107
111
|
else {
|
|
108
112
|
if (r.source !== 'local' || !token(r.bindingId) || !isAbsolute(r.localPath) || !Number.isSafeInteger(r.localDev) || !Number.isSafeInteger(r.localIno) || r.key !== checksum(r) || r.legacyBindingId !== undefined || r.revoked !== undefined || ids.has(r.bindingId))
|
|
@@ -369,7 +373,48 @@ export function createWorkspaceLocations(o) {
|
|
|
369
373
|
return () => { guardStoredBinding(original); if (registeredLocalPath(workspaceId) !== registeredPath)
|
|
370
374
|
reject('WORKSPACE_LOCATION_INVALID'); };
|
|
371
375
|
}
|
|
372
|
-
|
|
376
|
+
async function retireEmployee(expected) {
|
|
377
|
+
return serial(async () => {
|
|
378
|
+
const stored = await records(), registry = o.registry.list();
|
|
379
|
+
const hosts = stored.filter((r) => r.source === 'host' && r.host.host === expected.host);
|
|
380
|
+
for (const workspaceId of new Set(hosts.map(r => r.workspaceId))) {
|
|
381
|
+
const history = hosts.filter(r => r.workspaceId === workspaceId), native = registry.filter(w => w.id === workspaceId);
|
|
382
|
+
const assigned = new Set(history.flatMap(r => r.sessionIds ?? []));
|
|
383
|
+
const unassigned = [...new Set(native.flatMap(w => w.sessionIds))].filter(id => !assigned.has(id));
|
|
384
|
+
let own = history.find(r => r.host.username === expected.username);
|
|
385
|
+
for (const r of history)
|
|
386
|
+
if (!r.host.username) {
|
|
387
|
+
r.host.username = expected.username;
|
|
388
|
+
if (native.length)
|
|
389
|
+
r.sessionIds = [];
|
|
390
|
+
own ??= r;
|
|
391
|
+
}
|
|
392
|
+
if (!own && (unassigned.length || !native.length)) {
|
|
393
|
+
const source = history.find(r => r.active) ?? history[history.length - 1];
|
|
394
|
+
own = { workspaceId, source: 'host', active: false, host: { host: expected.host, username: expected.username }, remote: { ...source.remote } };
|
|
395
|
+
stored.push(own);
|
|
396
|
+
}
|
|
397
|
+
// 仅补本身份尚未归属的会话;旧员工快照和当前来源均保持。
|
|
398
|
+
if (own && native.length)
|
|
399
|
+
own.sessionIds = [...new Set([...(own.sessionIds ?? []), ...unassigned])];
|
|
400
|
+
}
|
|
401
|
+
await save(parseRecords(JSON.stringify({ schemaVersion: 1, items: stored })), async () => { });
|
|
402
|
+
publish(snapshot.items);
|
|
403
|
+
return ok(undefined);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
async function guardEmployee(sessionId, target, source) {
|
|
407
|
+
if (disposed)
|
|
408
|
+
reject('DISPOSED');
|
|
409
|
+
const ids = new Set(o.registry.list().filter(w => w.sessionIds.includes(sessionId)).map(w => w.id));
|
|
410
|
+
// Missing historical registry information keeps the original source-path refusal.
|
|
411
|
+
const stored = await records();
|
|
412
|
+
if (disposed)
|
|
413
|
+
reject('DISPOSED');
|
|
414
|
+
if (stored.some(r => r.source === 'host' && r.host.host === source.host && r.host.host === target.host && r.host.username && r.host.username !== target.username && (r.sessionIds?.includes(sessionId) || r.remote.path === source.path && (!ids.size || r.sessionIds === undefined && ids.has(r.workspaceId)))))
|
|
415
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
416
|
+
}
|
|
417
|
+
return { retireEmployee, guardEmployee, captureWorkspacePickerGuard, getLocalWorkspaceContext, getWorkspaceLocationState: () => ({ ...structuredClone(snapshot), host: currentHost() }), onWorkspaceLocationState(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; }, refreshWorkspaceLocations: () => serial(refresh), browseWorkspaceHostDirectories: (c) => serial(() => browse(c)), selectWorkspaceLocation: (c) => serial(() => select(c)), observeConnection() {
|
|
373
418
|
if (disposed)
|
|
374
419
|
return;
|
|
375
420
|
for (const controller of controllers)
|