@ai-workbench/connect 0.7.23 → 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.
Files changed (62) hide show
  1. package/README.md +20 -73
  2. package/client/index.cjs +93 -65
  3. package/helper/host-directories.cjs +8 -1
  4. package/lib/api.d.ts +21 -163
  5. package/lib/component-download.d.ts +1 -1
  6. package/lib/component-download.js +1 -1
  7. package/lib/component-source.d.ts +6 -27
  8. package/lib/component-source.js +10 -138
  9. package/lib/components.d.ts +1 -1
  10. package/lib/components.js +86 -98
  11. package/lib/connect.d.ts +0 -3
  12. package/lib/connect.js +15 -62
  13. package/lib/connection-messages.d.ts +2 -3
  14. package/lib/connection-messages.js +5 -4
  15. package/lib/conversation-log.d.ts +9 -0
  16. package/lib/conversation-log.js +44 -0
  17. package/lib/cordis.d.ts +1 -4
  18. package/lib/defaults.d.ts +0 -7
  19. package/lib/defaults.js +0 -2
  20. package/lib/enrollment.js +1 -8
  21. package/lib/host-directories.d.ts +6 -4
  22. package/lib/host-directories.js +4 -4
  23. package/lib/host-session-projects.d.ts +8 -58
  24. package/lib/host-session-projects.js +45 -270
  25. package/lib/index.d.ts +2 -11
  26. package/lib/index.js +11 -23
  27. package/lib/integration.d.ts +2 -2
  28. package/lib/integration.js +0 -2
  29. package/lib/native-workspace.d.ts +10 -0
  30. package/lib/needs.js +13 -25
  31. package/lib/ports.d.ts +1 -6
  32. package/lib/profile-runtime.js +59 -152
  33. package/lib/profile-settings.d.ts +6 -1
  34. package/lib/profile-settings.js +3 -5
  35. package/lib/startup.js +2 -2
  36. package/lib/workspace-directory-picker-types.d.ts +44 -0
  37. package/lib/workspace-directory-picker-types.js +1 -0
  38. package/lib/workspace-directory-picker.d.ts +30 -0
  39. package/lib/workspace-directory-picker.js +394 -0
  40. package/lib/workspace-location-types.d.ts +3 -7
  41. package/lib/workspace-locations.d.ts +5 -29
  42. package/lib/workspace-locations.js +81 -204
  43. package/package.json +3 -2
  44. package/helper/projects.cjs +0 -57
  45. package/lib/conversation-detail-settings.d.ts +0 -32
  46. package/lib/conversation-detail-settings.js +0 -119
  47. package/lib/conversation-details.d.ts +0 -30
  48. package/lib/conversation-details.js +0 -595
  49. package/lib/host-session-store.d.ts +0 -27
  50. package/lib/host-session-store.js +0 -130
  51. package/lib/local-acceptance-store.d.ts +0 -18
  52. package/lib/local-acceptance-store.js +0 -133
  53. package/lib/local-user-turn-acceptance.d.ts +0 -76
  54. package/lib/local-user-turn-acceptance.js +0 -289
  55. package/lib/local-user-turn-types.d.ts +0 -40
  56. package/lib/login-diagnostics.d.ts +0 -28
  57. package/lib/login-diagnostics.js +0 -57
  58. package/lib/projects.d.ts +0 -4
  59. package/lib/projects.js +0 -41
  60. package/lib/workspace-bindings.d.ts +0 -64
  61. package/lib/workspace-bindings.js +0 -379
  62. /package/lib/{local-user-turn-types.js → native-workspace.js} +0 -0
@@ -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 {};