@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
|
@@ -5,15 +5,16 @@ import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from
|
|
|
5
5
|
import { privateDirectory, readPrivate, readPrivateSync } from "./private-files.js";
|
|
6
6
|
import { fail, ok, need, NeedError } from "./needs.js";
|
|
7
7
|
import { readLocalWorkspaceProcess } from "./local-workspace-context.js";
|
|
8
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
8
9
|
const queues = new Map();
|
|
9
10
|
const hash = (v) => createHash('sha256').update(JSON.stringify(v)).digest('hex');
|
|
10
11
|
const token = (v) => typeof v === 'string' && v.length > 0 && !/[\x00-\x1f\x7f]/.test(v);
|
|
11
12
|
const obj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
12
|
-
const checksum = (r) => hash([r.workspaceId, r.localPath, r.localDev, r.localIno, r.bindingId, r.source, r.active, r.remote, r.identity, r.host,
|
|
13
|
+
const checksum = (r, historicalRevoked) => hash([r.workspaceId, r.localPath, r.localDev, r.localIno, r.bindingId, r.source, r.active, r.remote, r.identity, r.host, undefined, ...(historicalRevoked === undefined ? [] : [historicalRevoked])]);
|
|
13
14
|
const sameNative = (a, b) => a.workspaceId === b.workspaceId && a.localPath === b.localPath && a.localDev === b.localDev && a.localIno === b.localIno;
|
|
14
15
|
const sameDirectory = (a, b) => a.path === b.path && a.requestedPath === b.requestedPath && a.isSymlink === b.isSymlink && JSON.stringify(a.identity) === JSON.stringify(b.identity) && JSON.stringify(a.entryIdentity) === JSON.stringify(b.entryIdentity);
|
|
15
16
|
export function createWorkspaceLocations(o) {
|
|
16
|
-
const controllers = new Set()
|
|
17
|
+
const controllers = new Set();
|
|
17
18
|
const root = join(o.profileDir, 'ai-workbench-connect'), file = join(root, 'locations.json'), secret = randomBytes(32), listeners = new Set();
|
|
18
19
|
let disposed = false, revision = 0, tail = Promise.resolve();
|
|
19
20
|
let snapshot = { ...connection(), host: currentHost(), revision: 0, phase: 'loading', pageSize: o.pageSize, items: [] };
|
|
@@ -29,7 +30,6 @@ export function createWorkspaceLocations(o) {
|
|
|
29
30
|
}
|
|
30
31
|
function publish(items, error) {
|
|
31
32
|
snapshot = { ...connection(), host: currentHost(), revision: (revision = o.nextRevision?.() ?? revision + 1), phase: disposed ? 'disposed' : error ? 'failed' : 'ready', pageSize: o.pageSize, items, ...(error ? { need: need(error) } : {}) };
|
|
32
|
-
// An internal durability failure must not hide invalidation from settings.
|
|
33
33
|
let failed = false, firstError;
|
|
34
34
|
const notify = (listener) => { try {
|
|
35
35
|
listener(structuredClone(snapshot));
|
|
@@ -59,8 +59,8 @@ export function createWorkspaceLocations(o) {
|
|
|
59
59
|
return e instanceof NeedError ? { ok: false, error: e.need } : fail('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const settled = task.then(() => { }, () => { });
|
|
63
|
+
tail = settled;
|
|
64
64
|
queues.set(file, settled);
|
|
65
65
|
void settled.then(() => {
|
|
66
66
|
if (queues.get(file) === settled)
|
|
@@ -87,18 +87,30 @@ export function createWorkspaceLocations(o) {
|
|
|
87
87
|
return [];
|
|
88
88
|
throw e;
|
|
89
89
|
}
|
|
90
|
+
return parseRecords(raw);
|
|
91
|
+
}
|
|
92
|
+
function parseRecords(raw) {
|
|
90
93
|
const data = JSON.parse(raw);
|
|
91
94
|
if (!obj(data) || data.schemaVersion !== 1 || !Array.isArray(data.items))
|
|
92
95
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
96
|
+
const items = data.items.filter(r => !obj(r) || r.source !== 'legacy-host');
|
|
93
97
|
const ids = new Set(), active = new Set();
|
|
94
|
-
for (const r of
|
|
95
|
-
if (!obj(r) || !token(r.bindingId) || !token(r.workspaceId) || !isAbsolute(r.localPath) || !Number.isSafeInteger(r.localDev) || !Number.isSafeInteger(r.localIno) || !['local', 'host'
|
|
98
|
+
for (const r of items) {
|
|
99
|
+
if (!obj(r) || !token(r.bindingId) || !token(r.workspaceId) || !isAbsolute(r.localPath) || !Number.isSafeInteger(r.localDev) || !Number.isSafeInteger(r.localIno) || !['local', 'host'].includes(r.source) || typeof r.active !== 'boolean' || r.legacyBindingId !== undefined || r.revoked !== undefined && (r.source !== 'host' || !['HOST_DIRECTORY_CHANGED', 'HOST_DIRECTORY_UNREADABLE'].includes(r.revoked)) || r.key !== checksum(r, r.revoked) || ids.has(r.bindingId) || r.active && active.has(r.workspaceId) || r.source !== 'local' && (!obj(r.remote) || !isAbsolute(r.remote.path) || !isAbsolute(r.remote.requestedPath) || !obj(r.remote.identity) || !obj(r.remote.entryIdentity) || !obj(r.remote.permissions) || !obj(r.host) || !token(r.host.host) || !token(r.host.username) || !Number.isSafeInteger(r.host.port) || !(/^[a-f0-9]{64}$/.test(r.identity))))
|
|
96
100
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
97
101
|
ids.add(r.bindingId);
|
|
98
102
|
if (r.active)
|
|
99
103
|
active.add(r.workspaceId);
|
|
104
|
+
delete r.revoked;
|
|
100
105
|
}
|
|
101
|
-
return
|
|
106
|
+
return items;
|
|
107
|
+
}
|
|
108
|
+
function guardStoredBinding(expected) {
|
|
109
|
+
const current = parseRecords(readPrivateSync(file, o.metadataMaxBytes)).find(r => r.active && r.workspaceId === expected.workspaceId);
|
|
110
|
+
if (!current)
|
|
111
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
112
|
+
if (!isDeepStrictEqual(current, expected))
|
|
113
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
102
114
|
}
|
|
103
115
|
async function save(items, beforeCommit, context) {
|
|
104
116
|
for (const r of items)
|
|
@@ -153,14 +165,14 @@ export function createWorkspaceLocations(o) {
|
|
|
153
165
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
154
166
|
check(c);
|
|
155
167
|
await prepare();
|
|
156
|
-
const stored = await records(),
|
|
168
|
+
const stored = await records(), n = await native(c.workspaceId);
|
|
157
169
|
check(c);
|
|
158
|
-
const current = stored.find(r => r.active && r.workspaceId === c.workspaceId)
|
|
159
|
-
if ((current?.bindingId ??
|
|
170
|
+
const current = stored.find(r => r.active && r.workspaceId === c.workspaceId);
|
|
171
|
+
if ((current?.bindingId ?? null) !== c.expectedBindingId)
|
|
160
172
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
161
|
-
if (current && !sameNative(current, n)
|
|
173
|
+
if (current && !sameNative(current, n))
|
|
162
174
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
163
|
-
return { stored,
|
|
175
|
+
return { stored, n, current };
|
|
164
176
|
}
|
|
165
177
|
async function remote(c, run) {
|
|
166
178
|
check(c);
|
|
@@ -199,8 +211,6 @@ export function createWorkspaceLocations(o) {
|
|
|
199
211
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
|
-
function bindingNeed(r) { const code = r.revoked ?? revokedBindings.get(r.bindingId) ?? (o.isHostBindingRevoked?.(r.bindingId) ? 'HOST_DIRECTORY_CHANGED' : undefined); if (code)
|
|
203
|
-
revokedBindings.set(r.bindingId, code); return code; }
|
|
204
214
|
function directoryChange(a, b) {
|
|
205
215
|
if (a.path !== b.path || a.requestedPath !== b.requestedPath || a.identity.device !== b.identity.device || a.identity.inode !== b.identity.inode || a.entryIdentity.device !== b.entryIdentity.device || a.entryIdentity.inode !== b.entryIdentity.inode || a.isSymlink !== b.isSymlink)
|
|
206
216
|
return 'HOST_DIRECTORY_CHANGED';
|
|
@@ -209,22 +219,7 @@ export function createWorkspaceLocations(o) {
|
|
|
209
219
|
if (['read', 'write', 'execute'].some(k => typeof a.permissions[k] === 'boolean' && typeof b.permissions[k] === 'boolean' && a.permissions[k] !== b.permissions[k]))
|
|
210
220
|
return 'HOST_DIRECTORY_CHANGED';
|
|
211
221
|
}
|
|
212
|
-
async function
|
|
213
|
-
// Confirmed observation cannot be forgotten if durable publication fails.
|
|
214
|
-
revokedBindings.set(r.bindingId, code);
|
|
215
|
-
r.revoked = code;
|
|
216
|
-
try {
|
|
217
|
-
await save(stored, async () => { check(c); if (!sameNative(r, await native(r.workspaceId)))
|
|
218
|
-
reject('WORKSPACE_LOCATION_INVALID'); }, c);
|
|
219
|
-
check(c);
|
|
220
|
-
}
|
|
221
|
-
catch (e) {
|
|
222
|
-
if (exact(c))
|
|
223
|
-
publish(snapshot.items.map(i => i.bindingId === r.bindingId ? { ...i, status: 'invalid', need: need(code) } : i));
|
|
224
|
-
throw e;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
async function items(stored, legacy, inspectHost = false, c = connection()) {
|
|
222
|
+
async function items(stored, inspectHost = false, c = connection()) {
|
|
228
223
|
const result = [];
|
|
229
224
|
for (const w of o.registry.list()) {
|
|
230
225
|
let n;
|
|
@@ -235,16 +230,14 @@ export function createWorkspaceLocations(o) {
|
|
|
235
230
|
result.push({ workspaceId: w.id, workspaceName: w.title, localPath: w.path, bindingId: null, source: null, status: 'invalid', execution: 'not-selected', need: need('WORKSPACE_LOCATION_INVALID') });
|
|
236
231
|
continue;
|
|
237
232
|
}
|
|
238
|
-
const r = stored.find(r => r.active && r.workspaceId === w.id)
|
|
239
|
-
const base = { workspaceId: w.id, workspaceName: w.title || w.id, localPath: n.localPath, bindingId: r?.bindingId ??
|
|
233
|
+
const r = stored.find(r => r.active && r.workspaceId === w.id);
|
|
234
|
+
const base = { workspaceId: w.id, workspaceName: w.title || w.id, localPath: n.localPath, bindingId: r?.bindingId ?? null };
|
|
240
235
|
if (r) {
|
|
241
236
|
let valid = sameNative(r, n), error;
|
|
242
|
-
if (r.source === 'host')
|
|
243
|
-
error = bindingNeed(r);
|
|
244
237
|
if (valid && r.source !== 'local') {
|
|
245
238
|
try {
|
|
246
239
|
valid = (await target(c)).identity === r.identity;
|
|
247
|
-
if (valid &&
|
|
240
|
+
if (valid && inspectHost && r.source === 'host') {
|
|
248
241
|
const t = await target(c);
|
|
249
242
|
check(c);
|
|
250
243
|
const inspected = o.hostDirectories ? await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal)) : fail('DEPENDENCY_REQUIRED');
|
|
@@ -254,7 +247,6 @@ export function createWorkspaceLocations(o) {
|
|
|
254
247
|
else {
|
|
255
248
|
const changed = directoryChange(r.remote, inspected.value);
|
|
256
249
|
if (changed) {
|
|
257
|
-
await invalidate(stored, r, changed, c);
|
|
258
250
|
error = changed;
|
|
259
251
|
}
|
|
260
252
|
else if (Object.values(inspected.value.permissions).includes(null))
|
|
@@ -268,10 +260,7 @@ export function createWorkspaceLocations(o) {
|
|
|
268
260
|
error = e instanceof NeedError ? e.need.code : 'WORKSPACE_LOCATION_STORAGE_FAILED';
|
|
269
261
|
}
|
|
270
262
|
}
|
|
271
|
-
result.push({ ...base, source: r.source, status: valid && !error ? 'selected' : 'invalid', execution: r.source === 'local' ? 'local-pending' :
|
|
272
|
-
}
|
|
273
|
-
else if (old) {
|
|
274
|
-
result.push({ ...base, source: 'legacy-host', status: 'legacy-confirmation-required', execution: 'not-selected', legacyPath: old.project.path, ...(!sameNative(old, n) ? { need: need('WORKSPACE_LOCATION_INVALID') } : {}) });
|
|
263
|
+
result.push({ ...base, source: r.source, status: valid && !error ? 'selected' : 'invalid', execution: r.source === 'local' ? 'local-pending' : 'host-pending', ...(r.remote ? { remote: r.remote, host: r.host } : {}), ...(!valid || error ? { need: need(error ?? 'WORKSPACE_LOCATION_INVALID') } : {}) });
|
|
275
264
|
}
|
|
276
265
|
else
|
|
277
266
|
result.push({ ...base, source: null, status: 'unselected', execution: 'not-selected' });
|
|
@@ -282,8 +271,8 @@ export function createWorkspaceLocations(o) {
|
|
|
282
271
|
try {
|
|
283
272
|
check(c);
|
|
284
273
|
await prepare();
|
|
285
|
-
const stored = await records()
|
|
286
|
-
const next = await items(stored,
|
|
274
|
+
const stored = await records();
|
|
275
|
+
const next = await items(stored, true, c);
|
|
287
276
|
check(c);
|
|
288
277
|
publish(next);
|
|
289
278
|
return ok(structuredClone(snapshot));
|
|
@@ -327,8 +316,8 @@ export function createWorkspaceLocations(o) {
|
|
|
327
316
|
async function select(c) {
|
|
328
317
|
if (!obj(c))
|
|
329
318
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
330
|
-
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId', 'source', ...(c.source === 'host' ? ['selectionToken'] :
|
|
331
|
-
if (!['local', 'host'
|
|
319
|
+
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId', 'source', ...(c.source === 'host' ? ['selectionToken'] : [])]);
|
|
320
|
+
if (!['local', 'host'].includes(c.source))
|
|
332
321
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
333
322
|
const x = await context(c);
|
|
334
323
|
let r = { ...x.n, bindingId: randomUUID(), source: c.source, active: true, key: '' };
|
|
@@ -336,28 +325,15 @@ export function createWorkspaceLocations(o) {
|
|
|
336
325
|
const t = await target(c);
|
|
337
326
|
if (!o.hostDirectories)
|
|
338
327
|
reject('DEPENDENCY_REQUIRED');
|
|
339
|
-
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
selected = s.info;
|
|
345
|
-
}
|
|
346
|
-
else {
|
|
347
|
-
if (c.confirmLegacy !== true || !x.old || x.old.phase !== 'bound' || x.old.identity !== t.identity || !sameNative(x.old, x.n))
|
|
348
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
349
|
-
const inspected = await remote(c, signal => o.hostDirectories.inspect(t.value, x.old.project.path, signal));
|
|
350
|
-
check(c);
|
|
351
|
-
if (!inspected.ok)
|
|
352
|
-
return inspected;
|
|
353
|
-
selected = inspected.value;
|
|
354
|
-
r.legacyBindingId = x.old.bindingId;
|
|
355
|
-
}
|
|
356
|
-
const inspected = await remote(c, signal => o.hostDirectories.inspect(t.value, selected.requestedPath, signal));
|
|
328
|
+
const selected = unseal(c.selectionToken);
|
|
329
|
+
if (selected.kind !== 'selection' || !sameNative(selected.native, x.n) || selected.identity !== t.identity || JSON.stringify(selected.context) !== JSON.stringify({ instanceId: c.instanceId, epoch: c.epoch, workspaceId: c.workspaceId, expectedBindingId: c.expectedBindingId }))
|
|
330
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
331
|
+
const selectedInfo = selected.info;
|
|
332
|
+
const inspected = await remote(c, signal => o.hostDirectories.inspect(t.value, selectedInfo.requestedPath, signal));
|
|
357
333
|
check(c);
|
|
358
334
|
if (!inspected.ok)
|
|
359
335
|
return inspected;
|
|
360
|
-
if (!sameDirectory(
|
|
336
|
+
if (!sameDirectory(selectedInfo, inspected.value))
|
|
361
337
|
reject('HOST_DIRECTORY_CHANGED');
|
|
362
338
|
if (inspected.value.permissions.read !== true || inspected.value.permissions.execute !== true)
|
|
363
339
|
reject('HOST_DIRECTORY_UNREADABLE');
|
|
@@ -366,7 +342,7 @@ export function createWorkspaceLocations(o) {
|
|
|
366
342
|
if (!sameNative(await native(c.workspaceId), x.n))
|
|
367
343
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
368
344
|
check(c);
|
|
369
|
-
if (x.current &&
|
|
345
|
+
if (x.current && x.current.source === r.source && JSON.stringify(x.current.remote) === JSON.stringify(r.remote) && x.current.identity === r.identity)
|
|
370
346
|
return ok(structuredClone(snapshot));
|
|
371
347
|
for (const old of x.stored)
|
|
372
348
|
if (old.active && old.workspaceId === c.workspaceId)
|
|
@@ -379,11 +355,14 @@ export function createWorkspaceLocations(o) {
|
|
|
379
355
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
380
356
|
check(c);
|
|
381
357
|
}, c);
|
|
382
|
-
publish(await items(x.stored
|
|
358
|
+
publish(await items(x.stored));
|
|
383
359
|
check(c);
|
|
384
360
|
return ok(structuredClone(snapshot));
|
|
385
361
|
}
|
|
362
|
+
function checkPending(id) { if (o.isWorkspacePending?.(id))
|
|
363
|
+
reject('WORKSPACE_PICKER_ROLLBACK_FAILED'); }
|
|
386
364
|
function checkLocalContext(c) {
|
|
365
|
+
checkPending(c.workspaceId);
|
|
387
366
|
const current = o.api.getConnectionState();
|
|
388
367
|
if (disposed || current.phase === 'disposed')
|
|
389
368
|
reject('DISPOSED');
|
|
@@ -400,7 +379,6 @@ export function createWorkspaceLocations(o) {
|
|
|
400
379
|
checkLocalContext(c);
|
|
401
380
|
await prepare();
|
|
402
381
|
const stored = await records();
|
|
403
|
-
checkLocalContext(c);
|
|
404
382
|
const record = stored.find(r => r.active && r.workspaceId === c.workspaceId);
|
|
405
383
|
if (!record || record.bindingId !== c.expectedBindingId)
|
|
406
384
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
@@ -408,18 +386,15 @@ export function createWorkspaceLocations(o) {
|
|
|
408
386
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
409
387
|
const registeredPath = registeredLocalPath(c.workspaceId);
|
|
410
388
|
const first = await native(c.workspaceId);
|
|
411
|
-
checkLocalContext(c);
|
|
412
389
|
if (!sameNative(record, first))
|
|
413
390
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
414
391
|
const facts = readLocalWorkspaceProcess();
|
|
415
392
|
if (!facts.ok)
|
|
416
393
|
return facts;
|
|
417
394
|
const latest = (await records()).find(r => r.active && r.workspaceId === c.workspaceId);
|
|
418
|
-
checkLocalContext(c);
|
|
419
395
|
if (!latest || latest.bindingId !== record.bindingId || latest.source !== 'local' || !sameNative(record, latest))
|
|
420
396
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
421
397
|
const last = await native(c.workspaceId);
|
|
422
|
-
checkLocalContext(c);
|
|
423
398
|
if (!sameNative(record, last))
|
|
424
399
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
425
400
|
// Final synchronous registry check closes changes during the preceding filesystem awaits.
|
|
@@ -434,63 +409,30 @@ export function createWorkspaceLocations(o) {
|
|
|
434
409
|
return Promise.resolve(fail('DISPOSED'));
|
|
435
410
|
if (!obj(request) || Object.keys(request).sort().join(',') !== 'epoch,expectedBindingId,instanceId,workspaceId' || !token(request.instanceId) || !Number.isSafeInteger(request.epoch) || request.epoch < 0 || !token(request.workspaceId) || !token(request.expectedBindingId))
|
|
436
411
|
return Promise.resolve(fail('WORKSPACE_LOCATION_INVALID'));
|
|
412
|
+
if (o.isWorkspacePending?.(request.workspaceId))
|
|
413
|
+
return Promise.resolve(fail('WORKSPACE_PICKER_ROLLBACK_FAILED'));
|
|
437
414
|
// Copy before queueing: retaining the caller's input cannot change this operation's scope.
|
|
438
415
|
const c = { instanceId: request.instanceId, epoch: request.epoch, workspaceId: request.workspaceId, expectedBindingId: request.expectedBindingId };
|
|
439
416
|
return serial(() => localContext(c));
|
|
440
417
|
}
|
|
441
|
-
|
|
442
|
-
const c = connection();
|
|
443
|
-
check(c);
|
|
444
|
-
await prepare();
|
|
445
|
-
check(c);
|
|
446
|
-
const workspaces = o.registry.list().filter(w => w.sessionIds.includes(sessionId));
|
|
447
|
-
if (workspaces.length !== 1)
|
|
448
|
-
return fail('WORKSPACE_LOCATION_REQUIRED');
|
|
449
|
-
const stored = await records();
|
|
450
|
-
check(c);
|
|
451
|
-
const r = stored.find(r => r.active && r.workspaceId === workspaces[0].id);
|
|
452
|
-
if (!r)
|
|
453
|
-
return fail('WORKSPACE_LOCATION_REQUIRED');
|
|
454
|
-
if (!sameNative(r, await native(r.workspaceId)))
|
|
455
|
-
return fail('WORKSPACE_LOCATION_INVALID');
|
|
456
|
-
check(c);
|
|
457
|
-
if (r.source === 'local')
|
|
458
|
-
return fail('WORKSPACE_EXECUTION_UNAVAILABLE');
|
|
459
|
-
if (r.source === 'host')
|
|
460
|
-
return fail('WORKSPACE_LOCATION_PROVIDER_REQUIRED');
|
|
461
|
-
const t = await target(c), legacy = (await o.readLegacy()).find(old => old.bindingId === r.legacyBindingId);
|
|
462
|
-
check(c);
|
|
463
|
-
if (!legacy || r.identity !== t.identity || legacy.identity !== t.identity || legacy.project.path !== r.remote?.path)
|
|
464
|
-
return fail('WORKSPACE_LOCATION_INVALID');
|
|
465
|
-
const current = o.hostDirectories ? await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal)) : undefined;
|
|
466
|
-
check(c);
|
|
467
|
-
if (!current?.ok || r.remote.path !== current.value.path || r.remote.requestedPath !== current.value.requestedPath || r.remote.identity.device !== current.value.identity.device || r.remote.identity.inode !== current.value.identity.inode || JSON.stringify(r.remote.entryIdentity) !== JSON.stringify(current.value.entryIdentity))
|
|
468
|
-
return fail('WORKSPACE_LOCATION_INVALID');
|
|
469
|
-
return ok(undefined);
|
|
470
|
-
}
|
|
471
|
-
// Same queue as selection: a successful callback cannot race a new source UUID.
|
|
472
|
-
function withHostBinding(input, run, finalize = () => { }, inspectRemote = true) {
|
|
418
|
+
function withHostBinding(input, run, finalize = () => { }) {
|
|
473
419
|
const c = structuredClone(input);
|
|
474
420
|
return serial(async () => {
|
|
475
421
|
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId']);
|
|
476
422
|
if (!token(c.expectedBindingId))
|
|
477
423
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
424
|
+
checkPending(c.workspaceId);
|
|
478
425
|
const x = await context(c), r = x.current;
|
|
479
426
|
if (!r || r.source !== 'host' || !r.remote)
|
|
480
427
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
481
|
-
const invalid = bindingNeed(r);
|
|
482
|
-
if (invalid)
|
|
483
|
-
reject(invalid);
|
|
484
428
|
const t = await target(c);
|
|
485
429
|
check(c);
|
|
486
430
|
if (t.identity !== r.identity)
|
|
487
431
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
488
432
|
const bytes = await readPrivate(file, o.metadataMaxBytes), registeredPath = registeredLocalPath(c.workspaceId);
|
|
489
433
|
const guard = () => {
|
|
434
|
+
checkPending(c.workspaceId);
|
|
490
435
|
check(c);
|
|
491
|
-
const invalid = bindingNeed(r);
|
|
492
|
-
if (invalid)
|
|
493
|
-
reject(invalid);
|
|
494
436
|
const now = o.api.getConnectionState();
|
|
495
437
|
if (now.phase !== 'connected')
|
|
496
438
|
reject('CONNECTION_LOST');
|
|
@@ -515,92 +457,56 @@ export function createWorkspaceLocations(o) {
|
|
|
515
457
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
516
458
|
}
|
|
517
459
|
};
|
|
518
|
-
const inspect = async () => {
|
|
519
|
-
guard();
|
|
520
|
-
if (!o.hostDirectories)
|
|
521
|
-
reject('DEPENDENCY_REQUIRED');
|
|
522
|
-
const current = await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal));
|
|
523
|
-
guard();
|
|
524
|
-
if (!current.ok)
|
|
525
|
-
throw new NeedError(current.error);
|
|
526
|
-
const a = r.remote, b = current.value;
|
|
527
|
-
const changed = directoryChange(a, b);
|
|
528
|
-
if (changed) {
|
|
529
|
-
await invalidate(x.stored, r, changed, c);
|
|
530
|
-
const next = await items(x.stored, x.legacy, false, c);
|
|
531
|
-
check(c);
|
|
532
|
-
publish(next);
|
|
533
|
-
reject(changed);
|
|
534
|
-
}
|
|
535
|
-
if (Object.values(b.permissions).includes(null))
|
|
536
|
-
reject('HOST_DIRECTORY_UNREADABLE');
|
|
537
|
-
return b;
|
|
538
|
-
};
|
|
539
|
-
const directory = inspectRemote ? await inspect() : structuredClone(r.remote), value = { directory, target: structuredClone(t.value), local: { path: x.n.localPath, device: x.n.localDev, inode: x.n.localIno }, revision: snapshot.revision };
|
|
540
|
-
const result = await run(value, guard);
|
|
541
460
|
guard();
|
|
461
|
+
if (!o.hostDirectories)
|
|
462
|
+
reject('DEPENDENCY_REQUIRED');
|
|
463
|
+
const current = await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal));
|
|
464
|
+
if (!current.ok)
|
|
465
|
+
throw new NeedError(current.error);
|
|
466
|
+
const changed = directoryChange(r.remote, current.value);
|
|
467
|
+
if (changed)
|
|
468
|
+
reject(changed);
|
|
469
|
+
if (Object.values(current.value.permissions).includes(null))
|
|
470
|
+
reject('HOST_DIRECTORY_UNREADABLE');
|
|
471
|
+
const value = { directory: current.value, target: structuredClone(t.value), local: { path: x.n.localPath, device: x.n.localDev, inode: x.n.localIno }, revision: snapshot.revision };
|
|
472
|
+
const result = await run(value, guard);
|
|
542
473
|
if (!result.ok)
|
|
543
474
|
return result;
|
|
544
|
-
// Do not treat directory content timestamps as identity changes.
|
|
545
475
|
guard();
|
|
546
476
|
finalize();
|
|
547
|
-
guard();
|
|
548
477
|
return result;
|
|
549
478
|
});
|
|
550
479
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
const registeredPath = registeredLocalPath(c.workspaceId);
|
|
559
|
-
const guard = () => {
|
|
560
|
-
checkLocalContext(c);
|
|
561
|
-
if (registeredLocalPath(c.workspaceId) !== registeredPath)
|
|
562
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
563
|
-
try {
|
|
564
|
-
const path = realpathSync(registeredPath), st = lstatSync(path);
|
|
565
|
-
if (path !== x.n.localPath || !st.isDirectory() || st.isSymbolicLink() || st.dev !== x.n.localDev || st.ino !== x.n.localIno)
|
|
566
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
567
|
-
}
|
|
568
|
-
catch (e) {
|
|
569
|
-
if (e instanceof NeedError)
|
|
570
|
-
throw e;
|
|
571
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
572
|
-
}
|
|
573
|
-
checkLocalContext(c);
|
|
574
|
-
};
|
|
575
|
-
guard();
|
|
576
|
-
return run({ path: x.n.localPath, device: x.n.localDev, inode: x.n.localIno }, guard);
|
|
577
|
-
});
|
|
480
|
+
function captureWorkspacePickerGuard(workspaceId, expectedBindingId) {
|
|
481
|
+
const original = parseRecords(readPrivateSync(file, o.metadataMaxBytes)).find(r => r.active && r.workspaceId === workspaceId);
|
|
482
|
+
if (!original || original.bindingId !== expectedBindingId)
|
|
483
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
484
|
+
const registeredPath = registeredLocalPath(workspaceId);
|
|
485
|
+
return () => { guardStoredBinding(original); if (registeredLocalPath(workspaceId) !== registeredPath)
|
|
486
|
+
reject('WORKSPACE_LOCATION_INVALID'); };
|
|
578
487
|
}
|
|
579
|
-
return {
|
|
580
|
-
const c = connection(), before = await guard(id);
|
|
581
|
-
if (!before.ok)
|
|
582
|
-
return before;
|
|
583
|
-
check(c);
|
|
584
|
-
const result = await resolve();
|
|
585
|
-
check(c);
|
|
586
|
-
const after = await guard(id);
|
|
587
|
-
check(c);
|
|
588
|
-
return after.ok ? result : after;
|
|
589
|
-
}), observeConnection() {
|
|
488
|
+
return { captureWorkspacePickerGuard, withHostBinding, 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() {
|
|
590
489
|
if (disposed)
|
|
591
490
|
return;
|
|
592
491
|
for (const controller of controllers)
|
|
593
492
|
controller.abort();
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
493
|
+
const connected = o.api.getConnectionState().phase === 'connected';
|
|
494
|
+
publish(snapshot.items.map(item => {
|
|
495
|
+
if (item.source !== 'host')
|
|
496
|
+
return item;
|
|
497
|
+
if (!connected)
|
|
498
|
+
return { ...item, need: need('CONNECTION_LOST') };
|
|
499
|
+
if (item.need?.code === 'CONNECTION_LOST' || item.need?.code === 'WORKSPACE_LOCATION_CONFLICT') {
|
|
500
|
+
const { need: _, ...selected } = item;
|
|
501
|
+
return selected;
|
|
502
|
+
}
|
|
503
|
+
return item;
|
|
504
|
+
}));
|
|
599
505
|
}, dispose() {
|
|
600
506
|
disposed = true;
|
|
601
507
|
for (const controller of controllers)
|
|
602
508
|
controller.abort();
|
|
603
509
|
listeners.clear();
|
|
604
|
-
return tail;
|
|
510
|
+
return tail.then(() => { });
|
|
605
511
|
} };
|
|
606
512
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-workbench/connect",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.13.1"
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"@deepseek-ai/dsh-client-runtime",
|
|
70
70
|
"@deepseek-ai/dsh-client-ui-settings",
|
|
71
71
|
"@deepseek-ai/dsh-client-ui-slots",
|
|
72
|
-
"@deepseek-ai/dsh-client-locale"
|
|
72
|
+
"@deepseek-ai/dsh-client-locale",
|
|
73
|
+
"@deepseek-ai/dsh-client-ui-workspace"
|
|
73
74
|
]
|
|
74
75
|
},
|
|
75
76
|
"bundle": {
|
package/helper/projects.cjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
const fs=require('node:fs/promises');
|
|
2
|
-
const path=require('node:path');
|
|
3
|
-
const {spawnSync}=require('node:child_process');
|
|
4
|
-
function validName(name){return typeof name==='string'&&name!==''&&name!=='.'&&name!=='..'&&!/[\\/\x00-\x1f\x7f]/.test(name);}
|
|
5
|
-
// Repository selection must come solely from trusted root, never the remote shell's Git overrides.
|
|
6
|
-
const gitEnvironment=()=>Object.fromEntries(Object.entries(process.env).filter(([key])=>!key.startsWith('GIT_')));
|
|
7
|
-
const outputPath=text=>text.endsWith('\n')?text.slice(0,-1):text;
|
|
8
|
-
const error=code=>({protocolVersion:1,ok:false,error:{code}});
|
|
9
|
-
async function execute(request){
|
|
10
|
-
if(request?.protocolVersion!==1||!['list','create'].includes(request.operation))return error('PROJECT_PROTOCOL_INVALID');
|
|
11
|
-
if(request.operation==='create'&&!validName(request.name))return error('PROJECT_NAME_INVALID');
|
|
12
|
-
const root=request.root;
|
|
13
|
-
try{
|
|
14
|
-
if(typeof root!=='string'||!path.isAbsolute(root))return error('PROJECT_ROOT_INVALID');
|
|
15
|
-
const st=await fs.lstat(root);
|
|
16
|
-
if(!st.isDirectory()||st.isSymbolicLink()||st.uid!==process.getuid()||(st.mode&0o077)!==0||await fs.realpath(root)!==root)return error('PROJECT_ROOT_INVALID');
|
|
17
|
-
}catch{return error('PROJECT_ROOT_INVALID');}
|
|
18
|
-
if(request.operation==='create'){
|
|
19
|
-
const destination=path.join(root,request.name);let created=false;
|
|
20
|
-
try{
|
|
21
|
-
await fs.mkdir(destination,{mode:0o700});created=true;
|
|
22
|
-
const result=spawnSync('git',['-c','init.templateDir=','init','--quiet','--',destination],{encoding:'utf8',stdio:['ignore','pipe','pipe'],env:gitEnvironment()});
|
|
23
|
-
if(result.status!==0)return error('PROJECT_INIT_FAILED');
|
|
24
|
-
const verified=spawnSync('git',['-C',destination,'rev-parse','--show-toplevel'],{encoding:'utf8',stdio:['ignore','pipe','pipe'],env:gitEnvironment()});
|
|
25
|
-
if(verified.status!==0||outputPath(verified.stdout)!==destination)return error('PROJECT_INIT_FAILED');
|
|
26
|
-
return {protocolVersion:1,ok:true,value:{name:request.name,path:destination}};
|
|
27
|
-
}catch(e){return error(!created&&e.code==='EEXIST'?'PROJECT_EXISTS':'PROJECT_CREATE_FAILED');}
|
|
28
|
-
}
|
|
29
|
-
try{
|
|
30
|
-
const projects=[],unavailable=[];
|
|
31
|
-
for(const name of (await fs.readdir(root)).sort()){
|
|
32
|
-
const directory=path.join(root,name),st=await fs.lstat(directory);let reason;
|
|
33
|
-
if(!validName(name))reason='invalid-name';
|
|
34
|
-
else if(st.isSymbolicLink())reason='symlink';
|
|
35
|
-
else if(!st.isDirectory())reason='not-directory';
|
|
36
|
-
else if(st.uid!==process.getuid()||(st.mode&0o077)!==0)reason='permissions';
|
|
37
|
-
else{
|
|
38
|
-
let metadata=false;try{await fs.lstat(path.join(directory,'.git'));metadata=true;}catch(e){if(e.code!=='ENOENT')throw e;}
|
|
39
|
-
if(!metadata)reason='not-git';
|
|
40
|
-
else{
|
|
41
|
-
const git=spawnSync('git',['-C',directory,'rev-parse','--show-toplevel'],{encoding:'utf8',stdio:['ignore','pipe','pipe'],env:gitEnvironment()});
|
|
42
|
-
if(git.status!==0)reason='invalid-git';
|
|
43
|
-
else if(outputPath(git.stdout)!==directory)reason='outside-root';
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if(reason)unavailable.push({name,reason});else projects.push({name,path:directory});
|
|
47
|
-
}
|
|
48
|
-
return {protocolVersion:1,ok:true,value:{projects,unavailable}};
|
|
49
|
-
}catch{return error('PROJECT_LIST_FAILED');}
|
|
50
|
-
}
|
|
51
|
-
async function main(){
|
|
52
|
-
let input='';for await(const chunk of process.stdin)input+=chunk;
|
|
53
|
-
let result;try{result=await execute(JSON.parse(input));}catch{result=error('PROJECT_PROTOCOL_INVALID');}
|
|
54
|
-
process.stdout.write(JSON.stringify(result)+'\n');
|
|
55
|
-
}
|
|
56
|
-
module.exports={execute,validName};
|
|
57
|
-
if(require.main===module)void main();
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export interface ConversationDetailSettingsValues {
|
|
2
|
-
maxEventBytes: number;
|
|
3
|
-
pageSize: number;
|
|
4
|
-
}
|
|
5
|
-
export interface ConversationDetailSettingsState {
|
|
6
|
-
instanceId: string;
|
|
7
|
-
revision: number;
|
|
8
|
-
phase: 'loading' | 'ready' | 'saving' | 'failed' | 'disposed';
|
|
9
|
-
values?: ConversationDetailSettingsValues;
|
|
10
|
-
source: 'config' | 'saved';
|
|
11
|
-
errorCode?: 'SETTINGS_REQUIRED' | 'REMOTE_DETAIL_STORAGE_FAILED';
|
|
12
|
-
}
|
|
13
|
-
export declare function validDetailSettings(v: any): v is ConversationDetailSettingsValues;
|
|
14
|
-
export declare function createConversationDetailSettings(options: {
|
|
15
|
-
profileDir?: string;
|
|
16
|
-
initial?: Partial<ConversationDetailSettingsValues>;
|
|
17
|
-
metadataMaxBytes?: number;
|
|
18
|
-
}): {
|
|
19
|
-
ready: Promise<void>;
|
|
20
|
-
getState: () => ConversationDetailSettingsState;
|
|
21
|
-
values: () => ConversationDetailSettingsValues | undefined;
|
|
22
|
-
onState(fn: () => void): () => void;
|
|
23
|
-
save: (input: ConversationDetailSettingsValues) => Promise<{
|
|
24
|
-
ok: false;
|
|
25
|
-
error: import("./api.ts").ConnectNeed;
|
|
26
|
-
} | {
|
|
27
|
-
ok: true;
|
|
28
|
-
value: undefined;
|
|
29
|
-
}>;
|
|
30
|
-
dispose(): Promise<void>;
|
|
31
|
-
};
|
|
32
|
-
export type ConversationDetailSettings = ReturnType<typeof createConversationDetailSettings>;
|