@ai-workbench/connect 0.7.23 → 0.7.27
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 +24 -69
- package/client/index.cjs +95 -70
- 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 -10
- package/lib/defaults.js +1 -3
- 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 +3 -12
- package/lib/index.js +14 -26
- package/lib/integration.d.ts +2 -2
- package/lib/integration.js +0 -3
- package/lib/login.d.ts +0 -8
- package/lib/native-workspace.d.ts +10 -0
- package/lib/needs.js +15 -27
- package/lib/network.d.ts +0 -4
- package/lib/network.js +4 -88
- package/lib/ports.d.ts +1 -6
- package/lib/profile-activation.d.ts +0 -3
- package/lib/profile-activation.js +8 -2
- package/lib/profile-runtime.js +60 -153
- package/lib/profile-settings.d.ts +6 -1
- package/lib/profile-settings.js +3 -5
- package/lib/provider.d.ts +1 -15
- package/lib/provider.js +2 -18
- package/lib/startup.js +3 -3
- 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 +372 -0
- package/lib/workspace-location-types.d.ts +3 -7
- package/lib/workspace-locations.d.ts +5 -29
- package/lib/workspace-locations.js +81 -204
- 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 -595
- 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
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>;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { join, isAbsolute } from 'node:path';
|
|
2
|
-
import { lstat, open, realpath, rename, rm } from 'node:fs/promises';
|
|
3
|
-
import { constants } from 'node:fs';
|
|
4
|
-
import { randomUUID } from 'node:crypto';
|
|
5
|
-
import { CONVERSATION_DETAIL_DEFAULTS, L_DEFAULTS } from "./defaults.js";
|
|
6
|
-
import { privateDirectory, readPrivate } from "./private-files.js";
|
|
7
|
-
import { fail, ok } from "./needs.js";
|
|
8
|
-
const queues = new Map();
|
|
9
|
-
export function validDetailSettings(v) { return !!v && typeof v === 'object' && Object.keys(v).sort().join(',') === 'maxEventBytes,pageSize' && [v.maxEventBytes, v.pageSize].every(n => Number.isSafeInteger(n) && n > 0); }
|
|
10
|
-
export function createConversationDetailSettings(options) {
|
|
11
|
-
const root = options.profileDir ? join(options.profileDir, 'ai-workbench-connect') : undefined, file = root ? join(root, 'conversation-detail-settings.json') : undefined;
|
|
12
|
-
let state = { instanceId: randomUUID(), revision: 0, phase: 'loading', source: 'config' }, disposed = false, tail = Promise.resolve();
|
|
13
|
-
const listeners = new Set();
|
|
14
|
-
function publish(next) { state = { ...state, ...next, revision: state.revision + 1 }; for (const fn of listeners)
|
|
15
|
-
fn(); }
|
|
16
|
-
async function directory() { if (!options.profileDir || !root || !isAbsolute(options.profileDir) || await realpath(options.profileDir) !== options.profileDir)
|
|
17
|
-
throw Error('SETTINGS_PROFILE_INVALID'); await privateDirectory(root); if (await realpath(root) !== root)
|
|
18
|
-
throw Error('SETTINGS_PATH_INVALID'); const st = await lstat(root); if ((st.mode & 0o777) !== 0o700)
|
|
19
|
-
throw Error('SETTINGS_PATH_INVALID'); const parent = await open(options.profileDir, constants.O_RDONLY | constants.O_NOFOLLOW); try {
|
|
20
|
-
await parent.sync();
|
|
21
|
-
}
|
|
22
|
-
finally {
|
|
23
|
-
await parent.close();
|
|
24
|
-
} }
|
|
25
|
-
async function existing() { const st = await lstat(file); if (!st.isFile() || st.isSymbolicLink() || st.nlink !== 1 || (st.mode & 0o777) !== 0o600)
|
|
26
|
-
throw Error('SETTINGS_PATH_INVALID'); }
|
|
27
|
-
const ready = (async () => {
|
|
28
|
-
try {
|
|
29
|
-
await directory();
|
|
30
|
-
let values = { ...CONVERSATION_DETAIL_DEFAULTS, ...options.initial }, source = 'config';
|
|
31
|
-
try {
|
|
32
|
-
await existing();
|
|
33
|
-
const saved = JSON.parse(await readPrivate(file, options.metadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes));
|
|
34
|
-
if (saved.version !== 1 || !validDetailSettings(saved.values))
|
|
35
|
-
throw Error('SETTINGS_INVALID');
|
|
36
|
-
values = saved.values;
|
|
37
|
-
source = 'saved';
|
|
38
|
-
}
|
|
39
|
-
catch (e) {
|
|
40
|
-
if (e.code !== 'ENOENT')
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
if (!validDetailSettings(values))
|
|
44
|
-
throw Error('SETTINGS_INVALID');
|
|
45
|
-
if (!disposed)
|
|
46
|
-
publish({ phase: 'ready', values, source });
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
if (!disposed)
|
|
50
|
-
publish({ phase: 'failed', values: undefined, errorCode: 'REMOTE_DETAIL_STORAGE_FAILED' });
|
|
51
|
-
}
|
|
52
|
-
})();
|
|
53
|
-
function save(input) {
|
|
54
|
-
if (!validDetailSettings(input))
|
|
55
|
-
return Promise.resolve(fail('SETTINGS_REQUIRED'));
|
|
56
|
-
const values = structuredClone(input);
|
|
57
|
-
const task = (queues.get(file ?? '') ?? Promise.resolve()).then(async () => {
|
|
58
|
-
await ready;
|
|
59
|
-
if (disposed)
|
|
60
|
-
return fail('DISPOSED');
|
|
61
|
-
if (state.phase === 'failed')
|
|
62
|
-
return fail('REMOTE_DETAIL_STORAGE_FAILED');
|
|
63
|
-
publish({ phase: 'saving', errorCode: undefined });
|
|
64
|
-
let temp;
|
|
65
|
-
try {
|
|
66
|
-
await directory();
|
|
67
|
-
try {
|
|
68
|
-
await existing();
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
if (e.code !== 'ENOENT')
|
|
72
|
-
throw e;
|
|
73
|
-
}
|
|
74
|
-
const bytes = JSON.stringify({ version: 1, values }) + '\n';
|
|
75
|
-
if (Buffer.byteLength(bytes) > (options.metadataMaxBytes ?? L_DEFAULTS.enrollmentMetadataMaxBytes))
|
|
76
|
-
throw Error('SETTINGS_LIMIT');
|
|
77
|
-
temp = join(root, '.conversation-detail-settings-' + randomUUID());
|
|
78
|
-
const h = await open(temp, 'wx', 0o600);
|
|
79
|
-
try {
|
|
80
|
-
await h.writeFile(bytes);
|
|
81
|
-
await h.sync();
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
await h.close();
|
|
85
|
-
}
|
|
86
|
-
if (disposed)
|
|
87
|
-
return fail('DISPOSED');
|
|
88
|
-
await rename(temp, file);
|
|
89
|
-
temp = undefined;
|
|
90
|
-
const dir = await open(root, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
91
|
-
try {
|
|
92
|
-
await dir.sync();
|
|
93
|
-
}
|
|
94
|
-
finally {
|
|
95
|
-
await dir.close();
|
|
96
|
-
}
|
|
97
|
-
if (disposed)
|
|
98
|
-
return fail('DISPOSED');
|
|
99
|
-
publish({ phase: 'ready', values, source: 'saved', errorCode: undefined });
|
|
100
|
-
return ok(undefined);
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
publish({ phase: 'failed', values: undefined, errorCode: 'REMOTE_DETAIL_STORAGE_FAILED' });
|
|
104
|
-
return fail('REMOTE_DETAIL_STORAGE_FAILED');
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
if (temp)
|
|
108
|
-
await rm(temp, { force: true });
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
const done = task.then(() => { }, () => { });
|
|
112
|
-
queues.set(file ?? '', done);
|
|
113
|
-
tail = done;
|
|
114
|
-
void done.then(() => { if (queues.get(file ?? '') === done)
|
|
115
|
-
queues.delete(file ?? ''); });
|
|
116
|
-
return task;
|
|
117
|
-
}
|
|
118
|
-
return { ready, getState: () => structuredClone(state), values: () => state.phase === 'ready' ? structuredClone(state.values) : undefined, onState(fn) { listeners.add(fn); return () => { listeners.delete(fn); }; }, save, async dispose() { disposed = true; await ready; await tail; publish({ phase: 'disposed', values: undefined }); listeners.clear(); } };
|
|
119
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { HostDetailsAdmission } from './host-session-projects.ts';
|
|
2
|
-
import type { LocalDetailsAdmission } from './local-user-turn-acceptance.ts';
|
|
3
|
-
import type { ConnectApi, ConnectionState, Provider, RemoteConversationDetail, RemoteConversationDetailState, Result } from './api.ts';
|
|
4
|
-
export interface ConversationDetailOptions {
|
|
5
|
-
profileDir: string;
|
|
6
|
-
maxEventBytes: number;
|
|
7
|
-
pageSize: number;
|
|
8
|
-
localAcceptance?: LocalDetailsAdmission;
|
|
9
|
-
hostAcceptance?: HostDetailsAdmission;
|
|
10
|
-
storageName?: 'conversation-details' | 'login-diagnostics';
|
|
11
|
-
validate?: (detail: RemoteConversationDetail) => boolean;
|
|
12
|
-
knownKinds?: readonly string[];
|
|
13
|
-
getConnectionState: () => ConnectionState;
|
|
14
|
-
context: () => Promise<Result<{
|
|
15
|
-
identity: string;
|
|
16
|
-
}>>;
|
|
17
|
-
cacheContext?: (identity: string) => void;
|
|
18
|
-
publicationRevision?: () => number;
|
|
19
|
-
scope: (sessionId: string, provider: Provider) => Promise<Result<{
|
|
20
|
-
identity: string;
|
|
21
|
-
}>>;
|
|
22
|
-
onState?: (state: RemoteConversationDetailState) => void;
|
|
23
|
-
}
|
|
24
|
-
export declare function validRemoteConversationDetail(v: any): v is RemoteConversationDetail;
|
|
25
|
-
type DetailsApi = Pick<ConnectApi, 'appendRemoteConversationDetail' | 'getRemoteConversationDetailReceipt' | 'getRemoteConversationDetailState' | 'onRemoteConversationDetailState' | 'listRemoteConversationDetails'>;
|
|
26
|
-
export declare function createConversationDetails(options: ConversationDetailOptions): DetailsApi & {
|
|
27
|
-
observeConnection: (state: ConnectionState) => void;
|
|
28
|
-
dispose: () => Promise<void>;
|
|
29
|
-
};
|
|
30
|
-
export {};
|