@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.
@@ -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' || r?.source === 'host' && r.active === false)
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
- result.push({ workspaceId: r.workspaceId, source: 'host', active: r.active, host: { host: r.host.host }, remote: { path: r.remote.path } });
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
- return { 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() {
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-workbench/connect",
3
- "version": "0.7.36",
3
+ "version": "0.7.38",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24.13.1"