@asaidimu/utils-workspace 4.0.3 → 5.0.0
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/index.d.mts +2096 -1878
- package/index.d.ts +2096 -1878
- package/index.js +1 -288
- package/index.mjs +1 -287
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,2060 +1,2278 @@
|
|
|
1
|
-
import { QueryFilter, PaginationOptions } from '@asaidimu/query';
|
|
2
1
|
import { IndexDefinition, SchemaDefinition, SchemaChange, DataTransform } from '@asaidimu/anansi';
|
|
3
|
-
import {
|
|
4
|
-
import * as _google_genai from '@google/genai';
|
|
5
|
-
import { GenerateContentParameters, GenerateContentResponse, GoogleGenAI } from '@google/genai';
|
|
2
|
+
import { QueryFilter, PaginationOptions } from '@asaidimu/query';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
5
|
+
* Buffers write operations across one or more stores and commits them atomically.
|
|
6
|
+
*
|
|
7
|
+
* ## How atomicity works
|
|
8
|
+
*
|
|
9
|
+
* ### IndexedDB stores (same database)
|
|
10
|
+
* At commit time, TransactionContext collects the names of every IDB store that
|
|
11
|
+
* received operations, then opens a **single** `IDBTransaction` spanning all of
|
|
12
|
+
* them via `ConnectionManager.openTransaction`. Each store's `executeInTransaction`
|
|
13
|
+
* receives that shared transaction object and performs its writes against it
|
|
14
|
+
* without opening a new transaction of its own. IDB commits or aborts the
|
|
15
|
+
* entire multi-store transaction as one unit.
|
|
16
|
+
*
|
|
17
|
+
* ### MemoryStore
|
|
18
|
+
* MemoryStore's `executeInTransaction` receives `null` for the shared transaction.
|
|
19
|
+
* It applies ops against an internal staging map and returns. If a later
|
|
20
|
+
* participant fails, TransactionContext calls `rollbackMemory` on each
|
|
21
|
+
* MemoryStore that already applied its staged ops. MemoryStore restores its
|
|
22
|
+
* pre-transaction snapshot.
|
|
23
|
+
*
|
|
24
|
+
* ### Mixed (IDB + Memory in the same transaction)
|
|
25
|
+
* All IDB stores are committed first as a single atomic IDB transaction, then
|
|
26
|
+
* each MemoryStore is committed. If a MemoryStore fails after IDB has already
|
|
27
|
+
* committed, the IDB side cannot be rolled back — this is an inherent limitation
|
|
28
|
+
* of mixing two different storage engines. In practice the schema store is
|
|
29
|
+
* always MemoryStore-or-IDB consistently, so mixed transactions should not arise
|
|
30
|
+
* in normal usage.
|
|
13
31
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
declare class TransactionContext {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
/**
|
|
35
|
+
* Flat list of every operation staged so far, in the order they were added.
|
|
36
|
+
* We keep the store reference alongside the op so commit() can group them.
|
|
37
|
+
*/
|
|
38
|
+
private staged;
|
|
39
|
+
private done;
|
|
40
|
+
constructor();
|
|
41
|
+
/**
|
|
42
|
+
* Stages a single write operation against a store.
|
|
43
|
+
* Does NOT touch the store — no I/O happens until commit().
|
|
44
|
+
*/
|
|
45
|
+
addOp<T extends Record<string, any>>(store: Store<T>, type: "put" | "delete" | "add", data: any): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Commits all staged operations atomically.
|
|
48
|
+
*
|
|
49
|
+
* For IDB stores: opens one shared IDBTransaction across all participating
|
|
50
|
+
* stores, then dispatches ops to each store's executeInTransaction.
|
|
51
|
+
* For MemoryStores: dispatches sequentially; rolls back on failure.
|
|
52
|
+
*/
|
|
53
|
+
commit(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Discards all staged operations. No I/O has occurred so there is nothing
|
|
56
|
+
* to undo — we simply clear the buffer.
|
|
57
|
+
*/
|
|
58
|
+
rollback(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Opens ONE IDBTransaction across all participating IDB stores and lets
|
|
61
|
+
* each store execute its ops against the shared transaction handle.
|
|
62
|
+
*
|
|
63
|
+
* We obtain the IDBDatabase from the first store (they all share the same
|
|
64
|
+
* ConnectionManager / database) and open the transaction ourselves so that
|
|
65
|
+
* the commit/abort lifecycle belongs entirely to this method.
|
|
66
|
+
*/
|
|
67
|
+
private commitIDB;
|
|
68
|
+
/**
|
|
69
|
+
* Commits MemoryStore groups sequentially.
|
|
70
|
+
* Maintains a list of stores that have already applied their ops; if any
|
|
71
|
+
* store throws, all previously-applied stores are rolled back via the
|
|
72
|
+
* store-level `_rollbackMemory(snapshot)` escape hatch.
|
|
73
|
+
*/
|
|
74
|
+
private commitMemory;
|
|
75
|
+
completed(): boolean;
|
|
76
|
+
}
|
|
17
77
|
|
|
78
|
+
interface CursorCallbackResult<T> {
|
|
79
|
+
value: T | null;
|
|
80
|
+
done: boolean;
|
|
81
|
+
offset?: number;
|
|
82
|
+
}
|
|
18
83
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
84
|
+
* Callback function for cursor iteration over store records.
|
|
85
|
+
*
|
|
86
|
+
* @template T - The type of records stored.
|
|
87
|
+
* @param value - The current record value (cloned, not a live reference).
|
|
88
|
+
* @param key - The key (ID) of the current record.
|
|
89
|
+
* @param cursor - The underlying cursor object (implementation-specific; may be `null` in memory adapters).
|
|
90
|
+
* @returns A promise resolving to an object indicating whether iteration should stop,
|
|
91
|
+
* and an optional offset to advance.
|
|
22
92
|
*/
|
|
23
|
-
|
|
24
|
-
/** RFC 4122 compliant Universally Unique Identifier. */
|
|
25
|
-
type UUID = string;
|
|
26
|
-
/** ISO-8601 formatted UTC timestamp string. */
|
|
27
|
-
type Timestamp = string;
|
|
28
|
-
/** Uniform Resource Identifier string. */
|
|
29
|
-
type URI = string;
|
|
30
|
-
/** Hexadecimal representation of a SHA-256 hash. */
|
|
31
|
-
type SHA256 = string;
|
|
32
|
-
/** Special marker used to denote a role with no specific instructions or identity. */
|
|
33
|
-
declare const EMPTY_SYSTEM_ROLE = "__system__";
|
|
93
|
+
type CursorCallback<T> = (value: T, key: string | number, cursor: any) => Promise<CursorCallbackResult<T>>;
|
|
34
94
|
/**
|
|
35
|
-
* A
|
|
36
|
-
* Encourages explicit error handling over try/catch blocks.
|
|
95
|
+
* A generic representation of a key range, replacing the browser-specific IDBKeyRange.
|
|
37
96
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
error: E;
|
|
44
|
-
};
|
|
45
|
-
/** Occurs when attempting to create a resource with a key that already exists. */
|
|
46
|
-
type DuplicateKeyError = {
|
|
47
|
-
code: 'DUPLICATE_KEY';
|
|
48
|
-
resource: string;
|
|
49
|
-
key: string;
|
|
50
|
-
};
|
|
51
|
-
/** Occurs when a requested resource cannot be found by its unique identifier. */
|
|
52
|
-
type NotFoundError = {
|
|
53
|
-
code: 'NOT_FOUND';
|
|
54
|
-
resource: string;
|
|
55
|
-
id: string;
|
|
56
|
-
};
|
|
57
|
-
/** Triggered when a command payload fails validation or is logically inconsistent. */
|
|
58
|
-
type InvalidCommandError = {
|
|
59
|
-
code: 'INVALID_COMMAND';
|
|
60
|
-
reason: string;
|
|
61
|
-
};
|
|
62
|
-
/** Generic wrapper for unexpected infrastructure or downstream service failures. */
|
|
63
|
-
type BackendError = {
|
|
64
|
-
code: 'BACKEND_ERROR';
|
|
65
|
-
reason: string;
|
|
66
|
-
};
|
|
67
|
-
/** Specific errors related to blob storage, retrieval, or corruption. */
|
|
68
|
-
type BlobError = {
|
|
69
|
-
code: 'BLOB_ERROR';
|
|
70
|
-
reason: string;
|
|
71
|
-
};
|
|
72
|
-
/** Triggered when the current actor lacks sufficient privileges for a command. */
|
|
73
|
-
type PermissionDeniedError = {
|
|
74
|
-
code: 'PERMISSION_DENIED';
|
|
75
|
-
command: Command;
|
|
76
|
-
reason: string;
|
|
77
|
-
};
|
|
78
|
-
/** Union of all possible error types within the Workspace domain. */
|
|
79
|
-
type WorkspaceError = DuplicateKeyError | NotFoundError | InvalidCommandError | BackendError | PermissionDeniedError | BlobError;
|
|
80
|
-
/** Global user preferences and defaults for the workspace. */
|
|
81
|
-
interface Settings {
|
|
82
|
-
/** Default language code (e.g., 'en-US'). */
|
|
83
|
-
language: string;
|
|
84
|
-
/** The name of the role used when starting a new session. */
|
|
85
|
-
defaultRole?: string;
|
|
86
|
-
/** Global instructions appended to all system prompts. */
|
|
87
|
-
prompt?: string;
|
|
97
|
+
interface StoreKeyRange {
|
|
98
|
+
lower?: any;
|
|
99
|
+
upper?: any;
|
|
100
|
+
lowerOpen?: boolean;
|
|
101
|
+
upperOpen?: boolean;
|
|
88
102
|
}
|
|
89
|
-
/** * Represents the project-level metadata.
|
|
90
|
-
* Allows for extensible metadata fields via the generic Metadata type.
|
|
91
|
-
*/
|
|
92
|
-
type Project<Metadata extends Record<string, any> = Record<string, any>> = Metadata & {
|
|
93
|
-
id: UUID;
|
|
94
|
-
name: string;
|
|
95
|
-
};
|
|
96
|
-
/** Supported mime-types for image assets. */
|
|
97
|
-
type ImageMediaType = 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
|
|
98
|
-
/** Supported mime-types for text-based or structured documents. */
|
|
99
|
-
type DocumentMediaType = 'application/pdf' | 'application/json' | 'text/plain' | 'text/html' | 'text/markdown' | 'text/csv' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
100
|
-
/** Union of all media types handled by the blob system. */
|
|
101
|
-
type BlobMediaType = ImageMediaType | DocumentMediaType;
|
|
102
|
-
/**
|
|
103
|
-
* A lightweight reference to a blob.
|
|
104
|
-
* Used in content blocks to avoid passing heavy metadata or binary data.
|
|
105
|
-
*/
|
|
106
|
-
type BlobRef = Pick<BlobRecord, 'sha256' | 'mediaType' | 'sizeBytes' | 'filename' | 'previewUrl'>;
|
|
107
103
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
104
|
+
* A single buffered operation staged inside a TransactionContext.
|
|
105
|
+
* Kept intentionally minimal — the context only needs to know what to
|
|
106
|
+
* replay against a store during commit.
|
|
110
107
|
*/
|
|
111
|
-
type
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
mediaType: BlobMediaType;
|
|
115
|
-
data: Uint8Array;
|
|
108
|
+
type BufferedOperation<T> = {
|
|
109
|
+
type: "add" | "put";
|
|
110
|
+
data: T | T[];
|
|
116
111
|
} | {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
mediaType: BlobMediaType;
|
|
120
|
-
fileId: string;
|
|
121
|
-
providerId: string;
|
|
122
|
-
timestamp: Timestamp;
|
|
112
|
+
type: "delete";
|
|
113
|
+
data: string | number | (string | number)[];
|
|
123
114
|
};
|
|
124
115
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
116
|
+
* Storage adapter interface for a single object store (collection).
|
|
117
|
+
*
|
|
118
|
+
* Stores own their indexes. Index lifecycle (create, drop) and index-aware reads
|
|
119
|
+
* (findByIndex) are part of this contract so that both MemoryStore and IndexedDBStore
|
|
120
|
+
* implement them natively — MemoryStore via in-memory index maps, IndexedDB via its
|
|
121
|
+
* native index mechanism.
|
|
122
|
+
*
|
|
123
|
+
* @template T - The type of objects stored. Must include the key path property.
|
|
127
124
|
*/
|
|
128
|
-
interface
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
id:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
125
|
+
interface Store<T extends Record<string, any> = Record<string, any>> {
|
|
126
|
+
/**
|
|
127
|
+
* Returns the name of this store (the IDB object store / collection name).
|
|
128
|
+
* Used by TransactionContext to group operations and open a correctly-scoped
|
|
129
|
+
* multi-store IDB transaction at commit time.
|
|
130
|
+
*/
|
|
131
|
+
name(): string;
|
|
132
|
+
/**
|
|
133
|
+
* Opens the store, ensuring underlying storage structures exist.
|
|
134
|
+
*/
|
|
135
|
+
open(): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Adds one or more records to the store.
|
|
138
|
+
* If a record does not have a value for the store's key path, an automatic
|
|
139
|
+
* key may be assigned. Throws if a record with the same key already exists.
|
|
140
|
+
*/
|
|
141
|
+
add(data: T | T[]): Promise<string | number | (string | number)[]>;
|
|
142
|
+
/**
|
|
143
|
+
* Removes all records from the store without destroying index structures.
|
|
144
|
+
*/
|
|
145
|
+
clear(): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the total number of records in the store.
|
|
148
|
+
*/
|
|
149
|
+
count(): Promise<number>;
|
|
150
|
+
/**
|
|
151
|
+
* Deletes one or more records by their keys.
|
|
152
|
+
*/
|
|
153
|
+
delete(id: string | number | (string | number)[]): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Retrieves a single record by its primary key.
|
|
156
|
+
*/
|
|
157
|
+
getById(id: string | number): Promise<T | undefined>;
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves the first record matching an exact index key (point lookup).
|
|
160
|
+
* Useful for unique indexes — returns the single matching record or undefined.
|
|
161
|
+
*
|
|
162
|
+
* @param indexName - The name of the index to query.
|
|
163
|
+
* @param key - The exact key value to look up.
|
|
164
|
+
*/
|
|
165
|
+
getByIndex(indexName: string, key: any): Promise<T | undefined>;
|
|
166
|
+
/**
|
|
167
|
+
* Retrieves all records from a named index, optionally filtered by a key range.
|
|
168
|
+
* Use this for range scans over an index (e.g. all records where age >= 18).
|
|
169
|
+
*
|
|
170
|
+
* @param indexName - The name of the index to query.
|
|
171
|
+
* @param keyRange - Optional range to filter results.
|
|
172
|
+
*/
|
|
173
|
+
getByKeyRange(indexName: string, keyRange?: StoreKeyRange): Promise<T[]>;
|
|
174
|
+
/**
|
|
175
|
+
* Retrieves all records from the store without index involvement.
|
|
176
|
+
*/
|
|
177
|
+
getAll(): Promise<T[]>;
|
|
178
|
+
/**
|
|
179
|
+
* Inserts or replaces a record. Validates OCC if a record with the same key exists.
|
|
180
|
+
*/
|
|
181
|
+
put(data: T): Promise<string | number>;
|
|
182
|
+
/**
|
|
183
|
+
* Iterates over records using a cursor, allowing early termination and skipping.
|
|
184
|
+
*
|
|
185
|
+
* @param callback - Invoked for each record; return `{ done: true }` to stop,
|
|
186
|
+
* `{ offset: n }` to skip ahead n records.
|
|
187
|
+
* @param direction - Iteration order.
|
|
188
|
+
* @param keyRange - Optional range to restrict iteration.
|
|
189
|
+
*/
|
|
190
|
+
cursor(callback: CursorCallback<T>, direction?: "forward" | "backward", keyRange?: StoreKeyRange): Promise<T | null>;
|
|
191
|
+
/**
|
|
192
|
+
* Executes a batch of write operations atomically within this store.
|
|
193
|
+
* All operations succeed or fail together.
|
|
194
|
+
*
|
|
195
|
+
* Used for standalone (single-store) atomic writes. For cross-store atomicity,
|
|
196
|
+
* use executeInTransaction instead.
|
|
197
|
+
*/
|
|
198
|
+
batch(operations: Array<{
|
|
199
|
+
type: "add" | "put";
|
|
200
|
+
data: T | T[];
|
|
201
|
+
} | {
|
|
202
|
+
type: "delete";
|
|
203
|
+
data: string | number | (string | number)[];
|
|
204
|
+
}>): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Registers a new index on the store. Idempotent — no-op if the index already exists.
|
|
207
|
+
* For IndexedDB, this triggers a database version upgrade.
|
|
208
|
+
* For MemoryStore, this builds the index map from existing records.
|
|
209
|
+
*
|
|
210
|
+
* @param definition - The full index definition from the schema.
|
|
211
|
+
*/
|
|
212
|
+
createIndex(definition: IndexDefinition): Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Removes a named index from the store.
|
|
215
|
+
* For IndexedDB, this triggers a database version upgrade.
|
|
216
|
+
* For MemoryStore, this drops the in-memory index map.
|
|
217
|
+
*
|
|
218
|
+
* @param name - The index name as declared in IndexDefinition.name.
|
|
219
|
+
*/
|
|
220
|
+
dropIndex(name: string): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Returns all records matching an exact index key.
|
|
223
|
+
* Unlike getByIndex (which returns only the first match), this returns all matches —
|
|
224
|
+
* essential for non-unique indexes where multiple records share the same indexed value.
|
|
225
|
+
*
|
|
226
|
+
* @param indexName - The name of the index to query.
|
|
227
|
+
* @param value - The exact value to look up.
|
|
228
|
+
*/
|
|
229
|
+
findByIndex(indexName: string, value: any): Promise<T[]>;
|
|
230
|
+
/**
|
|
231
|
+
* Executes a set of buffered operations as part of a cross-store atomic transaction.
|
|
232
|
+
*
|
|
233
|
+
* For IndexedDBStore: `sharedTx` is the single IDBTransaction opened across all
|
|
234
|
+
* participating stores. Operations are applied directly to `sharedTx.objectStore(name)`
|
|
235
|
+
* without opening a new transaction — IDB commits or aborts the whole thing atomically.
|
|
236
|
+
*
|
|
237
|
+
* For MemoryStore: `sharedTx` is null. The store applies ops against its own staging
|
|
238
|
+
* area. The caller (TransactionContext) is responsible for coordinating rollback across
|
|
239
|
+
* all MemoryStores if any participant fails.
|
|
240
|
+
*
|
|
241
|
+
* This method must NOT open, commit, or abort any transaction itself.
|
|
242
|
+
*
|
|
243
|
+
* @param ops - The buffered operations to apply.
|
|
244
|
+
* @param sharedTx - The shared IDBTransaction (IndexedDB only), or null (MemoryStore).
|
|
245
|
+
*/
|
|
246
|
+
executeInTransaction(ops: BufferedOperation<T>[], sharedTx: IDBTransaction | null): Promise<void>;
|
|
234
247
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
248
|
+
interface Collection<T> {
|
|
249
|
+
/**
|
|
250
|
+
* Finds a single document matching the query.
|
|
251
|
+
*/
|
|
252
|
+
find: (query: QueryFilter<T>) => Promise<Document<T> | null>;
|
|
253
|
+
/**
|
|
254
|
+
* Lists documents with pagination. Returns an AsyncIterator so consumers can
|
|
255
|
+
* wrap it in their own iteration protocol (e.g. for-await-of via AsyncIterable).
|
|
256
|
+
*/
|
|
257
|
+
list: (query: PaginationOptions) => Promise<AsyncIterator<Document<T>[]>>;
|
|
258
|
+
/**
|
|
259
|
+
* Filters all documents matching the query.
|
|
260
|
+
*/
|
|
261
|
+
filter: (query: QueryFilter<T>) => Promise<Document<T>[]>;
|
|
262
|
+
/**
|
|
263
|
+
* Creates a new document in the collection.
|
|
264
|
+
*
|
|
265
|
+
* When a TransactionContext is provided the initial store.add is buffered into
|
|
266
|
+
* the transaction rather than written immediately. The document is returned in
|
|
267
|
+
* its fully initialised in-memory state regardless — callers can use it before
|
|
268
|
+
* the transaction commits.
|
|
269
|
+
*
|
|
270
|
+
* @param initial - The initial data for the document.
|
|
271
|
+
* @param tx - Optional transaction to buffer the write into.
|
|
272
|
+
*/
|
|
273
|
+
create: (initial: T, tx?: TransactionContext) => Promise<Document<T>>;
|
|
274
|
+
/**
|
|
275
|
+
* Updates all documents matching the query with the provided partial data.
|
|
276
|
+
* Returns the number of documents updated.
|
|
277
|
+
*/
|
|
278
|
+
update: (query: QueryFilter<T>, data: Partial<T>, tx?: TransactionContext) => Promise<number>;
|
|
279
|
+
/**
|
|
280
|
+
* Deletes all documents matching the query.
|
|
281
|
+
* Returns the number of documents deleted.
|
|
282
|
+
*/
|
|
283
|
+
delete: (query: QueryFilter<T>, tx?: TransactionContext) => Promise<number>;
|
|
284
|
+
/**
|
|
285
|
+
* Subscribes to collection-level events.
|
|
286
|
+
*/
|
|
287
|
+
subscribe: (event: CollectionEventType | TelemetryEventType, callback: (event: CollectionEvent<T> | TelemetryEvent) => void) => () => void;
|
|
288
|
+
/**
|
|
289
|
+
* Validates data against the collection's schema.
|
|
290
|
+
*/
|
|
291
|
+
validate(data: Record<string, any>): Promise<{
|
|
292
|
+
value?: any;
|
|
293
|
+
issues: Array<{
|
|
294
|
+
message: string;
|
|
295
|
+
path: Array<string>;
|
|
296
|
+
}>;
|
|
297
|
+
}>;
|
|
298
|
+
invalidate(): void;
|
|
264
299
|
}
|
|
265
300
|
/**
|
|
266
|
-
*
|
|
267
|
-
* This is used for rendering threaded/branching conversations.
|
|
301
|
+
* Event payload for Collection events.
|
|
268
302
|
*/
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
timestamp:
|
|
277
|
-
roleSnapshot?: string;
|
|
278
|
-
parent: {
|
|
279
|
-
id: UUID;
|
|
280
|
-
version: number;
|
|
281
|
-
} | null;
|
|
282
|
-
/** Map of version numbers to an array of child turn IDs. */
|
|
283
|
-
children: Record<number, UUID[]>;
|
|
284
|
-
}
|
|
285
|
-
/** UI helper for navigating between different versions of a turn (e.g. "2 of 5"). */
|
|
286
|
-
interface BranchInfo {
|
|
287
|
-
versions: number[];
|
|
288
|
-
currentIndex: number;
|
|
289
|
-
total: number;
|
|
290
|
-
hasPrev: boolean;
|
|
291
|
-
hasNext: boolean;
|
|
292
|
-
}
|
|
293
|
-
/** A system persona containing specific instructions and associated preferences. */
|
|
294
|
-
interface Role {
|
|
295
|
-
/** Unique identifier name (e.g. "software-architect"). */
|
|
296
|
-
name: string;
|
|
297
|
-
/** Human-readable display label. */
|
|
298
|
-
label: string;
|
|
299
|
-
description?: string;
|
|
300
|
-
/** The core instructions (system prompt) for this persona. */
|
|
301
|
-
persona: string;
|
|
302
|
-
/** Array of Preference IDs associated with this role. */
|
|
303
|
-
preferences: UUID[];
|
|
304
|
-
}
|
|
305
|
-
/** A specific user preference or "memory" that informs model behavior. */
|
|
306
|
-
interface Preference {
|
|
307
|
-
id: UUID;
|
|
308
|
-
content: string;
|
|
309
|
-
/** Topics used for retrieval-augmented generation (RAG). */
|
|
310
|
-
topics: string[];
|
|
311
|
-
timestamp: Timestamp;
|
|
312
|
-
}
|
|
313
|
-
/** Discriminated union of types that can be injected into the AI context. */
|
|
314
|
-
type ContextContent = {
|
|
315
|
-
kind: 'text';
|
|
316
|
-
value: string;
|
|
317
|
-
} | {
|
|
318
|
-
kind: 'json';
|
|
319
|
-
value: unknown;
|
|
320
|
-
} | {
|
|
321
|
-
kind: 'blob';
|
|
322
|
-
sha256: SHA256;
|
|
323
|
-
mediaType: BlobMediaType;
|
|
324
|
-
sizeBytes: number;
|
|
325
|
-
filename?: string;
|
|
326
|
-
} | {
|
|
327
|
-
kind: 'remote';
|
|
328
|
-
uri: URI;
|
|
329
|
-
mediaType?: BlobMediaType;
|
|
303
|
+
type CollectionEventType = "document:create" | "collection:read" | "migration:start" | "migration:end";
|
|
304
|
+
type CollectionEvent<T> = {
|
|
305
|
+
type: CollectionEventType;
|
|
306
|
+
document?: T;
|
|
307
|
+
model?: string;
|
|
308
|
+
method?: keyof Collection<T>;
|
|
309
|
+
metadata?: Record<string, unknown>;
|
|
310
|
+
timestamp: number;
|
|
330
311
|
};
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
312
|
+
interface Database {
|
|
313
|
+
/**
|
|
314
|
+
* Opens an existing collection by name.
|
|
315
|
+
*/
|
|
316
|
+
collection: <T>(schemaName: string) => Promise<Collection<T>>;
|
|
317
|
+
/**
|
|
318
|
+
* Creates a new collection from a schema definition.
|
|
319
|
+
*/
|
|
320
|
+
createCollection: <T>(schema: SchemaDefinition) => Promise<Collection<T>>;
|
|
321
|
+
/**
|
|
322
|
+
* Deletes a collection and its schema record.
|
|
323
|
+
*/
|
|
324
|
+
deleteCollection: (schemaName: string) => Promise<boolean>;
|
|
325
|
+
/**
|
|
326
|
+
* Updates an existing collection's schema record.
|
|
327
|
+
*/
|
|
328
|
+
updateCollection: (schema: SchemaDefinition) => Promise<boolean>;
|
|
329
|
+
/**
|
|
330
|
+
* Migrates an existing collection's data and schema definition.
|
|
331
|
+
* Processes data in a streaming fashion to avoid loading the full collection
|
|
332
|
+
* into memory.
|
|
333
|
+
*/
|
|
334
|
+
migrateCollection: <T>(name: string, opts: CollectionMigrationOptions, batchSize?: number) => Promise<Collection<T>>;
|
|
335
|
+
/**
|
|
336
|
+
* Executes a callback within a TransactionContext.
|
|
337
|
+
* Writes buffered inside the callback are flushed atomically on commit.
|
|
338
|
+
* If the callback throws, the buffer is discarded (no writes are flushed).
|
|
339
|
+
*/
|
|
340
|
+
transaction: (callback: (tx: TransactionContext) => Promise<void>) => Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Subscribes to database-level events.
|
|
343
|
+
*/
|
|
344
|
+
subscribe: (event: DatabaseEventType | "telemetry", callback: (event: DatabaseEvent | TelemetryEvent) => void) => () => void;
|
|
345
|
+
/**
|
|
346
|
+
* Releases in-memory references and event bus subscriptions.
|
|
347
|
+
* Does not delete any persisted data.
|
|
348
|
+
*/
|
|
349
|
+
close: () => void;
|
|
350
|
+
clear: () => Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* Ensures a collection exists; creates it if it doesn't. Idempotent.
|
|
353
|
+
*/
|
|
354
|
+
ensureCollection: (schema: SchemaDefinition) => Promise<void>;
|
|
355
|
+
/**
|
|
356
|
+
* Ensures multiple collections exist; creates any that don't. Idempotent.
|
|
357
|
+
*/
|
|
358
|
+
setupCollections: (schemas: SchemaDefinition[]) => Promise<void>;
|
|
339
359
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
360
|
+
type CollectionMigrationOptions = {
|
|
361
|
+
changes: SchemaChange<any>[];
|
|
362
|
+
description: string;
|
|
363
|
+
rollback?: SchemaChange<any>[];
|
|
364
|
+
transform?: string | DataTransform<any, any>;
|
|
365
|
+
};
|
|
366
|
+
type DatabaseEventType = "collection:create" | "collection:delete" | "collection:update" | "collection:read" | "migrate";
|
|
367
|
+
type DatabaseEvent = {
|
|
368
|
+
type: DatabaseEventType;
|
|
369
|
+
schema?: SchemaDefinition | Partial<SchemaDefinition>;
|
|
370
|
+
timestamp: number;
|
|
371
|
+
};
|
|
372
|
+
type DocumentMetadata = {
|
|
373
|
+
$id?: string;
|
|
374
|
+
$created?: string | Date;
|
|
375
|
+
$updated?: string | Date;
|
|
376
|
+
$version?: number;
|
|
377
|
+
};
|
|
378
|
+
type Document<T> = {
|
|
379
|
+
readonly [K in keyof T]: T[K];
|
|
380
|
+
} & DocumentMetadata & {
|
|
381
|
+
read: () => Promise<boolean>;
|
|
382
|
+
save: (tx?: TransactionContext) => Promise<boolean>;
|
|
383
|
+
update: (props: Partial<T>, tx?: TransactionContext) => Promise<boolean>;
|
|
384
|
+
delete: (tx?: TransactionContext) => Promise<boolean>;
|
|
385
|
+
subscribe: (event: DocumentEventType | TelemetryEventType, callback: (event: DocumentEvent<T> | TelemetryEvent) => void) => () => void;
|
|
386
|
+
state(): T;
|
|
387
|
+
$metadata(): DocumentMetadata;
|
|
388
|
+
};
|
|
389
|
+
type DocumentEventType = "document:create" | "document:write" | "document:update" | "document:delete" | "document:read";
|
|
390
|
+
type DocumentEvent<T> = {
|
|
391
|
+
type: DocumentEventType;
|
|
392
|
+
data?: Partial<T>;
|
|
393
|
+
timestamp: number;
|
|
394
|
+
};
|
|
395
|
+
type TelemetryEventType = "telemetry";
|
|
396
|
+
type TelemetryEvent = {
|
|
397
|
+
type: TelemetryEventType;
|
|
398
|
+
method: string;
|
|
399
|
+
timestamp: number;
|
|
400
|
+
source: any;
|
|
348
401
|
metadata: {
|
|
349
|
-
|
|
350
|
-
|
|
402
|
+
args: any[];
|
|
403
|
+
performance: {
|
|
404
|
+
durationMs: number;
|
|
405
|
+
};
|
|
406
|
+
source: {
|
|
407
|
+
level: "database" | "collection" | "document";
|
|
408
|
+
collection?: string;
|
|
409
|
+
document?: string;
|
|
410
|
+
};
|
|
411
|
+
result?: {
|
|
412
|
+
type: "array" | string;
|
|
413
|
+
size?: number;
|
|
414
|
+
};
|
|
415
|
+
error: {
|
|
416
|
+
message: string;
|
|
417
|
+
name: string;
|
|
418
|
+
stack?: string;
|
|
419
|
+
} | null;
|
|
351
420
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Interface defining the shape of the EventBus.
|
|
425
|
+
* @template TEventMap - A record mapping event names to their respective payload types.
|
|
426
|
+
*/
|
|
427
|
+
interface EventBus<TEventMap extends Record<string, any>> {
|
|
428
|
+
/**
|
|
429
|
+
* Subscribes to a specific event by name.
|
|
430
|
+
* @param eventName - The name of the event to subscribe to.
|
|
431
|
+
* @param callback - The function to call when the event is emitted.
|
|
432
|
+
* @returns A function to unsubscribe from the event.
|
|
433
|
+
*/
|
|
434
|
+
subscribe: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void) => () => void;
|
|
435
|
+
/**
|
|
436
|
+
* Subscribes to an event and automatically unsubscribes after it fires once.
|
|
437
|
+
* @param eventName - The name of the event to subscribe to.
|
|
438
|
+
* @param callback - The function to call when the event is emitted.
|
|
439
|
+
* @returns A function to cancel the one-shot subscription before it fires.
|
|
440
|
+
*/
|
|
441
|
+
once: <TEventName extends keyof TEventMap>(eventName: TEventName, callback: (payload: TEventMap[TEventName]) => void) => () => void;
|
|
442
|
+
/**
|
|
443
|
+
* Emits an event with a payload to all subscribed listeners.
|
|
444
|
+
* @param event - An object containing the event name and payload.
|
|
445
|
+
*/
|
|
446
|
+
emit: <TEventName extends keyof TEventMap>(event: {
|
|
447
|
+
name: TEventName;
|
|
448
|
+
payload: TEventMap[TEventName];
|
|
449
|
+
}) => void;
|
|
450
|
+
/**
|
|
451
|
+
* Retrieves metrics about event bus usage.
|
|
452
|
+
* @returns An object containing various metrics.
|
|
453
|
+
*/
|
|
454
|
+
metrics: () => EventMetrics;
|
|
455
|
+
/**
|
|
456
|
+
* Clears all subscriptions and resets metrics.
|
|
457
|
+
* After calling clear(), the bus is fully reset and can be reused —
|
|
458
|
+
* cross-tab communication is re-established if it was previously enabled.
|
|
459
|
+
*/
|
|
460
|
+
clear: () => void;
|
|
387
461
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
462
|
+
/**
|
|
463
|
+
* Interface defining the metrics tracked by the EventBus.
|
|
464
|
+
*/
|
|
465
|
+
interface EventMetrics {
|
|
466
|
+
/** Total number of events emitted (both sync and deferred paths). */
|
|
467
|
+
totalEvents: number;
|
|
468
|
+
/** Number of active subscriptions across all event names. */
|
|
469
|
+
activeSubscriptions: number;
|
|
470
|
+
/** Map of event names to their emission counts. */
|
|
471
|
+
eventCounts: Map<string, number>;
|
|
472
|
+
/** Average duration of event dispatch in milliseconds. */
|
|
473
|
+
averageEmitDuration: number;
|
|
393
474
|
}
|
|
394
|
-
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Utility type for representing partial updates to the state, allowing deep nesting.
|
|
478
|
+
* It makes all properties optional and applies the same transformation recursively
|
|
479
|
+
* to nested objects and array elements, allowing for selective updates while
|
|
480
|
+
* preserving the original structure. It also includes the original type T and
|
|
481
|
+
* undefined as possibilities for the top level and nested values.
|
|
482
|
+
*/
|
|
483
|
+
type DeepPartial<T> = T extends object ? T extends readonly (infer U)[] ? readonly (DeepPartial<U> | undefined)[] | undefined | T : T extends (infer U)[] ? (DeepPartial<U> | undefined)[] | undefined | T : {
|
|
484
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> | undefined : T[K] | undefined;
|
|
485
|
+
} | undefined | T : T | undefined;
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* This file contains the primary domain models, data structures, and command types
|
|
489
|
+
* for the AI Workspace. It acts as the "Source of Truth" for all modules.
|
|
490
|
+
*/
|
|
491
|
+
|
|
492
|
+
/** RFC 4122 compliant Universally Unique Identifier. */
|
|
493
|
+
type UUID = string;
|
|
494
|
+
/** ISO-8601 formatted UTC timestamp string. */
|
|
495
|
+
type Timestamp = string;
|
|
496
|
+
/** Uniform Resource Identifier string. */
|
|
497
|
+
type URI = string;
|
|
498
|
+
/** Hexadecimal representation of a SHA-256 hash. */
|
|
499
|
+
type SHA256 = string;
|
|
500
|
+
/** Special marker used to denote a role with no specific instructions or identity. */
|
|
501
|
+
declare const EMPTY_SYSTEM_ROLE = "__system__";
|
|
502
|
+
/**
|
|
503
|
+
* A functional wrapper for operations that can fail.
|
|
504
|
+
* Encourages explicit error handling over try/catch blocks.
|
|
505
|
+
* @template T - The type of the value returned on success.
|
|
506
|
+
* @template E - The type of the error returned on failure.
|
|
507
|
+
*/
|
|
508
|
+
type Result<T, E = WorkspaceError> = {
|
|
509
|
+
/** Indicates the operation was successful. */
|
|
510
|
+
ok: true;
|
|
511
|
+
/** The resulting value of the successful operation. */
|
|
512
|
+
value: T;
|
|
513
|
+
} | {
|
|
514
|
+
/** Indicates the operation failed. */
|
|
515
|
+
ok: false;
|
|
516
|
+
/** The error details explaining the failure. */
|
|
517
|
+
error: E;
|
|
518
|
+
};
|
|
519
|
+
/** Occurs when attempting to create a resource with a key that already exists. */
|
|
520
|
+
type DuplicateKeyError = {
|
|
521
|
+
/** Error discriminator code. */
|
|
522
|
+
code: "DUPLICATE_KEY";
|
|
523
|
+
/** The type of resource that caused the collision (e.g., 'role', 'session'). */
|
|
524
|
+
resource: string;
|
|
525
|
+
/** The specific key that duplicated an existing entry. */
|
|
395
526
|
key: string;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
527
|
+
};
|
|
528
|
+
/** Occurs when a requested resource cannot be found by its unique identifier. */
|
|
529
|
+
type NotFoundError = {
|
|
530
|
+
/** Error discriminator code. */
|
|
531
|
+
code: "NOT_FOUND";
|
|
532
|
+
/** The type of resource that was requested. */
|
|
533
|
+
resource: string;
|
|
534
|
+
/** The ID that yielded no results. */
|
|
535
|
+
id: string;
|
|
536
|
+
};
|
|
537
|
+
/** Triggered when a command payload fails validation or is logically inconsistent. */
|
|
538
|
+
type InvalidCommandError = {
|
|
539
|
+
/** Error discriminator code. */
|
|
540
|
+
code: "INVALID_COMMAND";
|
|
541
|
+
/** Detailed explanation of why the command was rejected. */
|
|
542
|
+
reason: string;
|
|
543
|
+
};
|
|
544
|
+
/** Generic wrapper for unexpected infrastructure or downstream service failures. */
|
|
545
|
+
type BackendError = {
|
|
546
|
+
/** Error discriminator code. */
|
|
547
|
+
code: "BACKEND_ERROR";
|
|
548
|
+
/** Description of the underlying system failure. */
|
|
549
|
+
reason: string;
|
|
550
|
+
};
|
|
551
|
+
/** Specific errors related to blob storage, retrieval, or corruption. */
|
|
552
|
+
type BlobError = {
|
|
553
|
+
/** Error discriminator code. */
|
|
554
|
+
code: "BLOB_ERROR";
|
|
555
|
+
/** Description of the blob operation failure. */
|
|
556
|
+
reason: string;
|
|
557
|
+
};
|
|
558
|
+
/** Triggered when the current actor lacks sufficient privileges for a command. */
|
|
559
|
+
type PermissionDeniedError = {
|
|
560
|
+
/** Error discriminator code. */
|
|
561
|
+
code: "PERMISSION_DENIED";
|
|
562
|
+
/** The command that was attempted and subsequently blocked. */
|
|
563
|
+
command: BaseCommand;
|
|
564
|
+
/** Explanation of the missing permissions or blocked action. */
|
|
565
|
+
reason: string;
|
|
566
|
+
};
|
|
567
|
+
/** Union of all possible error types within the Workspace domain. */
|
|
568
|
+
type WorkspaceError = DuplicateKeyError | NotFoundError | InvalidCommandError | BackendError | PermissionDeniedError | BlobError;
|
|
569
|
+
/** Global user preferences and defaults for the workspace. */
|
|
570
|
+
interface Settings {
|
|
571
|
+
/** Default language code used for generic formatting (e.g., 'en-US'). */
|
|
572
|
+
language: string;
|
|
573
|
+
/** The ID or name of the role used when a new session is instantiated without one. */
|
|
574
|
+
defaultRole?: string;
|
|
575
|
+
/** Global system instructions appended to the LLM context across all sessions. */
|
|
576
|
+
prompt?: string;
|
|
403
577
|
}
|
|
404
|
-
|
|
578
|
+
/**
|
|
579
|
+
* Represents the project-level metadata container.
|
|
580
|
+
* Allows for extensible metadata fields via the generic Metadata type.
|
|
581
|
+
* @template Metadata - Custom schema for additional project fields.
|
|
582
|
+
*/
|
|
583
|
+
type Project<Metadata extends Record<string, any> = Record<string, any>> = Metadata & {
|
|
584
|
+
/** Unique identifier for the project. */
|
|
405
585
|
id: UUID;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
topic: string;
|
|
419
|
-
contextKeys: string[];
|
|
420
|
-
preferences: UUID[];
|
|
421
|
-
tasks: UUID[];
|
|
422
|
-
metadata?: {
|
|
423
|
-
created?: Timestamp;
|
|
424
|
-
updated?: Timestamp;
|
|
425
|
-
entries?: number;
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
/** The complete in-memory read-model of the Workspace state. */
|
|
429
|
-
interface Index {
|
|
430
|
-
roles: Record<string, RoleSummary>;
|
|
431
|
-
preferences: Record<UUID, PreferenceSummary>;
|
|
432
|
-
context: Record<string, ContextSummary>;
|
|
433
|
-
sessions: Record<UUID, SessionMeta>;
|
|
434
|
-
tasks: Record<UUID, TaskSummary>;
|
|
435
|
-
topics: Record<string, TopicIndex>;
|
|
436
|
-
blobs: Record<SHA256, BlobRecord>;
|
|
437
|
-
tools: Record<string, ToolSummary>;
|
|
438
|
-
}
|
|
439
|
-
/** The root container for a user's workspace. */
|
|
440
|
-
interface Workspace<ProjectMetadata extends Record<string, any> = Record<string, any>> {
|
|
441
|
-
id: UUID;
|
|
442
|
-
settings: Settings;
|
|
443
|
-
project: Project<ProjectMetadata>;
|
|
444
|
-
index: Index;
|
|
445
|
-
}
|
|
446
|
-
/** * Format used for exporting/importing a complete workspace state,
|
|
447
|
-
* including all historical turns and binary records.
|
|
586
|
+
/** Human-readable display name for the project. */
|
|
587
|
+
name: string;
|
|
588
|
+
};
|
|
589
|
+
/** Supported mime-types for image assets. */
|
|
590
|
+
type ImageMediaType = "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
591
|
+
/** Supported mime-types for text-based or structured documents. */
|
|
592
|
+
type DocumentMediaType = "application/pdf" | "application/json" | "text/plain" | "text/html" | "text/markdown" | "text/csv" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
593
|
+
/** Union of all media types handled by the blob system. */
|
|
594
|
+
type BlobMediaType = ImageMediaType | DocumentMediaType;
|
|
595
|
+
/**
|
|
596
|
+
* A lightweight reference to a blob.
|
|
597
|
+
* Used in content blocks to avoid passing heavy metadata or binary data across boundaries.
|
|
448
598
|
*/
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
599
|
+
type BlobRef = Pick<BlobRecord, "sha256" | "mediaType" | "sizeBytes" | "filename" | "previewUrl">;
|
|
600
|
+
/**
|
|
601
|
+
* Represents a blob that has been fetched into memory.
|
|
602
|
+
* Can be 'inline' (binary data present) or 'remote' (stored in an external provider).
|
|
603
|
+
*/
|
|
604
|
+
type ResolvedBlob = {
|
|
605
|
+
/** Indicates the blob data is available in the local memory space. */
|
|
606
|
+
kind: "inline";
|
|
607
|
+
/** The unique content hash of the blob. */
|
|
608
|
+
sha256: SHA256;
|
|
609
|
+
/** The registered mime-type of the data. */
|
|
610
|
+
mediaType: BlobMediaType;
|
|
611
|
+
/** The raw binary representation of the file. */
|
|
612
|
+
data: Uint8Array;
|
|
613
|
+
} | {
|
|
614
|
+
/** Indicates the blob exists on an external provider and must be referenced by ID. */
|
|
615
|
+
kind: "remote";
|
|
616
|
+
/** The unique content hash of the blob. */
|
|
617
|
+
sha256: SHA256;
|
|
618
|
+
/** The registered mime-type of the data. */
|
|
619
|
+
mediaType: BlobMediaType;
|
|
620
|
+
/** The external provider's unique identifier for this file. */
|
|
621
|
+
fileId: string;
|
|
622
|
+
/** The identifier of the external provider (e.g., 'openai', 'gemini'). */
|
|
623
|
+
providerId: string;
|
|
624
|
+
/** The UTC timestamp when the file was registered with the remote provider. */
|
|
625
|
+
timestamp: Timestamp;
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* The authoritative registry entry for a file in the system.
|
|
629
|
+
* Includes reference counting for garbage collection and remote mappings.
|
|
630
|
+
*/
|
|
631
|
+
interface BlobRecord {
|
|
632
|
+
/** The unique SHA-256 hash representing the blob's binary content. */
|
|
633
|
+
sha256: SHA256;
|
|
634
|
+
/** The recognized MIME type of the blob data. */
|
|
635
|
+
mediaType: BlobMediaType;
|
|
636
|
+
/** The total size of the blob payload in bytes. */
|
|
637
|
+
sizeBytes: number;
|
|
638
|
+
/** The original or user-assigned filename, if available. */
|
|
639
|
+
filename?: string;
|
|
640
|
+
/** A secure, temporary URL for previewing the blob in a UI context, if applicable. */
|
|
641
|
+
previewUrl?: string;
|
|
642
|
+
/** Number of content blocks currently referencing this blob. Prevents premature garbage collection. */
|
|
643
|
+
refCount: number;
|
|
644
|
+
/** Map of external provider IDs to their specific remote file identifiers and upload timestamps. */
|
|
645
|
+
remoteIds: Record<string, {
|
|
646
|
+
/** The external provider's specific file ID. */
|
|
647
|
+
id: string;
|
|
648
|
+
/** The timestamp the mapping was created. */
|
|
649
|
+
timestamp: Timestamp;
|
|
457
650
|
}>;
|
|
458
|
-
|
|
459
|
-
|
|
651
|
+
/** The UTC timestamp when this blob was first registered in the workspace. */
|
|
652
|
+
createdAt: Timestamp;
|
|
653
|
+
/** The UTC timestamp of the most recent interaction or reference to this blob. */
|
|
654
|
+
lastUsedAt: Timestamp;
|
|
460
655
|
}
|
|
461
|
-
/**
|
|
462
|
-
interface
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
656
|
+
/**
|
|
657
|
+
* Base interface for all content blocks inside a turn.
|
|
658
|
+
* @template BlockType - String literal restricting the block type.
|
|
659
|
+
*/
|
|
660
|
+
interface BaseContentBlock<BlockType extends string> {
|
|
661
|
+
/** Unique identifier for the specific content block instance. */
|
|
662
|
+
id: UUID;
|
|
663
|
+
/** Discriminator used to determine the shape and rendering of the block. */
|
|
664
|
+
type: BlockType;
|
|
665
|
+
/** Extensible key-value store for block-specific properties. */
|
|
666
|
+
[key: string]: any;
|
|
470
667
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
/** The ID of the user or system component that initiated the command. */
|
|
476
|
-
actor?: string;
|
|
477
|
-
description?: string;
|
|
478
|
-
synthetic?: boolean;
|
|
668
|
+
/** Standard text content within a turn. */
|
|
669
|
+
interface TextBlock extends BaseContentBlock<"text"> {
|
|
670
|
+
/** The raw markdown or plain text content. */
|
|
671
|
+
text: string;
|
|
479
672
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
673
|
+
/** An image asset within a turn, optionally containing the resolved binary data. */
|
|
674
|
+
interface ImageBlock extends BaseContentBlock<"image"> {
|
|
675
|
+
/** Lightweight pointer to the blob record. */
|
|
676
|
+
ref?: BlobRef;
|
|
677
|
+
/** Fully resolved blob containing actual data or remote pointers. */
|
|
678
|
+
blob?: ResolvedBlob;
|
|
679
|
+
/** Accessible description of the image content. */
|
|
680
|
+
altText?: string;
|
|
487
681
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
682
|
+
/** A document asset within a turn. */
|
|
683
|
+
interface DocumentBlock extends BaseContentBlock<"document"> {
|
|
684
|
+
/** Lightweight pointer to the blob record. */
|
|
685
|
+
ref?: BlobRef;
|
|
686
|
+
/** Fully resolved blob containing actual document data or remote pointers. */
|
|
687
|
+
blob?: ResolvedBlob;
|
|
688
|
+
/** Human-readable title or filename of the document. */
|
|
689
|
+
title?: string;
|
|
491
690
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
691
|
+
/** Captured request from the AI to execute a specific tool. */
|
|
692
|
+
interface ToolUseBlock extends BaseContentBlock<"tool:use"> {
|
|
693
|
+
/** The exact registered name of the tool to be executed. */
|
|
694
|
+
name: string;
|
|
695
|
+
/** The parameter arguments provided by the model for the tool execution. */
|
|
696
|
+
input: Record<string, unknown>;
|
|
497
697
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
698
|
+
/** The resulting output (or error) from a tool execution. */
|
|
699
|
+
interface ToolResultBlock extends BaseContentBlock<"tool:result"> {
|
|
700
|
+
/** The UUID of the original ToolUseBlock that triggered this execution. */
|
|
701
|
+
useId: UUID;
|
|
702
|
+
/** The serialized output of the tool, or a structured JSON response. */
|
|
703
|
+
content: string | Record<string, unknown>;
|
|
704
|
+
/** Flag indicating whether the tool execution resulted in an error state. */
|
|
705
|
+
isError?: boolean;
|
|
503
706
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
707
|
+
/** Internal "Chain of Thought" or reasoning generated by the model. */
|
|
708
|
+
interface ThinkingBlock extends BaseContentBlock<"thinking"> {
|
|
709
|
+
/** The internal reasoning text produced by the model before the final response. */
|
|
710
|
+
thinking: string;
|
|
507
711
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
712
|
+
/** A condensed summary of previous conversation history. */
|
|
713
|
+
interface SummaryBlock extends BaseContentBlock<"summary"> {
|
|
714
|
+
/** The distilled summary text replacing older conversation turns. */
|
|
715
|
+
text: string;
|
|
716
|
+
}
|
|
717
|
+
/** Notates that the session has switched from one Role persona to another. */
|
|
718
|
+
interface RoleTransitionBlock extends BaseContentBlock<"role:transition"> {
|
|
719
|
+
/** The name of the role the session is leaving (undefined if it was a system default). */
|
|
720
|
+
previousRole?: string;
|
|
721
|
+
/** The name of the new role the session is adopting. */
|
|
722
|
+
newRole: string;
|
|
723
|
+
}
|
|
724
|
+
/** Union of all possible content types that can exist within a conversation Turn. */
|
|
725
|
+
type ContentBlock = TextBlock | ImageBlock | DocumentBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock | SummaryBlock | RoleTransitionBlock;
|
|
726
|
+
/** Definition of a tool available to the AI. */
|
|
727
|
+
interface ToolSummary {
|
|
728
|
+
/** The unique, system-level name of the tool (e.g., 'web_search'). */
|
|
729
|
+
name: string;
|
|
730
|
+
/** Human-readable explanation of what the tool does, exposed to the AI model. */
|
|
731
|
+
description: string;
|
|
732
|
+
/** JSON Schema defining the required input arguments and their types. */
|
|
733
|
+
parameters: {
|
|
734
|
+
/** Root type of the parameter schema, usually 'object'. */
|
|
735
|
+
type: "object";
|
|
736
|
+
/** Map of property names to their respective sub-schemas. */
|
|
737
|
+
properties: Record<string, any>;
|
|
738
|
+
/** Array of property names that must be provided to execute the tool. */
|
|
739
|
+
required: string[];
|
|
512
740
|
};
|
|
741
|
+
/** Semantic tags used to help the model dynamically find relevant tools via RAG. */
|
|
742
|
+
topics: string[];
|
|
513
743
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
744
|
+
/** An instance of a tool being called with specific arguments. */
|
|
745
|
+
interface ToolCall {
|
|
746
|
+
/** The unique execution identifier for this specific call instance. */
|
|
747
|
+
id: UUID;
|
|
748
|
+
/** The UUID or string identifier of the tool being requested. */
|
|
749
|
+
tool: UUID;
|
|
750
|
+
/** The fully parsed arguments mapped to the tool's required parameters. */
|
|
751
|
+
arguments: Record<string, any>;
|
|
752
|
+
}
|
|
753
|
+
/** A request for authorization before executing a command or tool. */
|
|
754
|
+
type AuthRequest = {
|
|
755
|
+
/** Discriminator indicating a state mutation authorization request. */
|
|
756
|
+
type: "command";
|
|
757
|
+
/** The specific command attempting to execute. */
|
|
758
|
+
payload: BaseCommand;
|
|
759
|
+
} | {
|
|
760
|
+
/** Discriminator indicating an external tool execution authorization request. */
|
|
761
|
+
type: "tool";
|
|
762
|
+
/** The specific tool call payload attempting to execute. */
|
|
763
|
+
payload: ToolCall;
|
|
764
|
+
};
|
|
765
|
+
/** Identifies whether a turn originated from the user, the AI, a tool, or the system. */
|
|
766
|
+
type SystemActor = "user" | "assistant" | "tool" | "system";
|
|
767
|
+
/**
|
|
768
|
+
* The flat storage format for a conversation turn.
|
|
769
|
+
* Supports versioning and parent-pointers for branching conversation trees (DAG).
|
|
770
|
+
*/
|
|
771
|
+
interface Turn {
|
|
772
|
+
/** The unique identifier for this specific turn instance. */
|
|
773
|
+
id: UUID;
|
|
774
|
+
/** The UUID of the chat session this turn belongs to, used for fast filtering. */
|
|
775
|
+
session: UUID;
|
|
776
|
+
/** Incrementing number representing edits to the same turn ID. */
|
|
777
|
+
version: number;
|
|
778
|
+
/** The entity (user, model, system) that produced this turn's content. */
|
|
779
|
+
actor: SystemActor;
|
|
780
|
+
/** An ordered array of content blocks comprising the payload of this turn. */
|
|
781
|
+
blocks: BaseContentBlock<string>[];
|
|
782
|
+
/** The UTC timestamp when this turn was originally created or received. */
|
|
783
|
+
timestamp: Timestamp;
|
|
784
|
+
/** Name of the role (persona) active at the exact time this turn occurred. */
|
|
785
|
+
role?: string;
|
|
786
|
+
/** Link to the preceding turn in the conversation tree, defining the DAG graph. */
|
|
787
|
+
parent?: {
|
|
788
|
+
/** The ID of the parent turn. */
|
|
517
789
|
id: UUID;
|
|
790
|
+
/** The specific version of the parent turn. */
|
|
791
|
+
version: number;
|
|
518
792
|
};
|
|
793
|
+
/** Local model constraints applied explicitly at the time of this turn. */
|
|
794
|
+
constraints?: ModelConstraintMap;
|
|
519
795
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
796
|
+
/** Unique composite key used to lookup a specific turn version. */
|
|
797
|
+
type TurnKey = Pick<Turn, "version" | "id" | "session">;
|
|
798
|
+
/**
|
|
799
|
+
* An in-memory representation of a turn, including all its versions and children.
|
|
800
|
+
* This is used for rendering threaded/branching conversations in UI.
|
|
801
|
+
*/
|
|
802
|
+
interface TurnNode {
|
|
803
|
+
/** The unique root identifier for this turn across all its versions. */
|
|
804
|
+
id: UUID;
|
|
805
|
+
/** Map of version numbers to the specific Turn data payloads. */
|
|
806
|
+
versions: Record<number, Turn>;
|
|
807
|
+
/** The version integer currently displayed or active in the primary chat view. */
|
|
808
|
+
activeVersion: number;
|
|
809
|
+
/** The entity that produced this turn's root concept. */
|
|
810
|
+
actor: SystemActor;
|
|
811
|
+
/** The content blocks of the *active* version for quick rendering. */
|
|
812
|
+
blocks: BaseContentBlock<string>[];
|
|
813
|
+
/** The UTC timestamp of the original turn creation. */
|
|
814
|
+
timestamp: Timestamp;
|
|
815
|
+
/** The role name active when this node was created. */
|
|
816
|
+
roleSnapshot?: string;
|
|
817
|
+
/** Reference to the preceding turn in the conversation DAG. */
|
|
818
|
+
parent?: {
|
|
819
|
+
/** Parent turn ID. */
|
|
523
820
|
id: UUID;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
topics: string[];
|
|
527
|
-
preferences?: UUID[];
|
|
821
|
+
/** Parent turn version. */
|
|
822
|
+
version: number;
|
|
528
823
|
};
|
|
824
|
+
/** Map of version numbers to arrays of child turn IDs spawned from that specific version. */
|
|
825
|
+
children: Record<number, UUID[]>;
|
|
529
826
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
827
|
+
/** UI helper for navigating between different versions of a turn (e.g. "2 of 5"). */
|
|
828
|
+
interface BranchInfo {
|
|
829
|
+
/** Array of all available version numbers for a turn. */
|
|
830
|
+
versions: number[];
|
|
831
|
+
/** The array index currently being viewed. */
|
|
832
|
+
currentIndex: number;
|
|
833
|
+
/** The total count of available versions. */
|
|
834
|
+
total: number;
|
|
835
|
+
/** Indicates if an older version exists to navigate back to. */
|
|
836
|
+
hasPrev: boolean;
|
|
837
|
+
/** Indicates if a newer version exists to navigate forward to. */
|
|
838
|
+
hasNext: boolean;
|
|
533
839
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
840
|
+
/** Unique string identifier for a model (e.g., 'gemini-2.0-flash'). */
|
|
841
|
+
type ModelName = string;
|
|
842
|
+
/** Execution constraints applied to a specific model. */
|
|
843
|
+
interface ModelConstraint {
|
|
844
|
+
/** Sampling temperature. 0.0 = deterministic, higher = more creative. */
|
|
845
|
+
temperature?: number;
|
|
846
|
+
/** Limits and stop boundaries for token generation. */
|
|
847
|
+
tokens: {
|
|
848
|
+
/** Maximum output tokens for this request. Overrides adapter defaults. */
|
|
849
|
+
max?: number;
|
|
850
|
+
/** Stop sequences — generation halts immediately when any of these are produced. */
|
|
851
|
+
stops?: string[];
|
|
852
|
+
/** Thinking/reasoning budget in tokens. (For supported models only). */
|
|
853
|
+
thought?: number;
|
|
538
854
|
};
|
|
539
855
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
856
|
+
/** Map of model names to their explicit, active constraints. */
|
|
857
|
+
type ModelConstraintMap = Record<ModelName, ModelConstraint>;
|
|
858
|
+
/** A system persona containing specific instructions and associated preferences. */
|
|
859
|
+
interface Role {
|
|
860
|
+
/** Unique identifier name used system-wide (e.g. "software-architect"). */
|
|
861
|
+
name: string;
|
|
862
|
+
/** Human-readable display label shown in the UI. */
|
|
863
|
+
label: string;
|
|
864
|
+
/** Optional human-readable description of what this persona is intended for. */
|
|
865
|
+
description?: string;
|
|
866
|
+
/** The core instructions (system prompt base) establishing this persona's behavior. */
|
|
867
|
+
persona: string;
|
|
868
|
+
/** Array of Preference UUIDs explicitly bound to this role. */
|
|
869
|
+
preferences: UUID[];
|
|
870
|
+
/** Array of semantic Topics associated with this role to guide RAG retrieval. */
|
|
871
|
+
topics: string[];
|
|
872
|
+
/** Model constraints natively attached at the role level. */
|
|
873
|
+
constraints?: ModelConstraintMap;
|
|
545
874
|
}
|
|
546
|
-
|
|
547
|
-
interface
|
|
548
|
-
|
|
549
|
-
|
|
875
|
+
/** A specific user preference or "memory" that informs model behavior. */
|
|
876
|
+
interface Preference {
|
|
877
|
+
/** Unique identifier for the preference entry. */
|
|
878
|
+
id: UUID;
|
|
879
|
+
/** The actual text content representing the instruction or fact to remember. */
|
|
880
|
+
content: string;
|
|
881
|
+
/** Topics used for semantic alignment and retrieval-augmented generation (RAG). */
|
|
882
|
+
topics: string[];
|
|
883
|
+
/** UTC timestamp of when this preference was established or last updated. */
|
|
884
|
+
timestamp: Timestamp;
|
|
550
885
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
886
|
+
/** Discriminated union of types that can be injected into the AI context. */
|
|
887
|
+
type ContextContent = {
|
|
888
|
+
/** Denotes raw, unstructured text. */
|
|
889
|
+
kind: "text";
|
|
890
|
+
/** The text payload to inject. */
|
|
891
|
+
value: string;
|
|
892
|
+
} | {
|
|
893
|
+
/** Denotes structured JSON data. */
|
|
894
|
+
kind: "json";
|
|
895
|
+
/** The JSON payload. */
|
|
896
|
+
value: unknown;
|
|
897
|
+
} | {
|
|
898
|
+
/** Denotes a reference to a registered blob in the workspace store. */
|
|
899
|
+
kind: "blob";
|
|
900
|
+
/** The hash linking to the full blob record. */
|
|
901
|
+
sha256: SHA256;
|
|
902
|
+
/** The mime-type of the blob. */
|
|
903
|
+
mediaType: BlobMediaType;
|
|
904
|
+
/** File size in bytes. */
|
|
905
|
+
sizeBytes: number;
|
|
906
|
+
/** Human-readable filename. */
|
|
907
|
+
filename?: string;
|
|
908
|
+
} | {
|
|
909
|
+
/** Denotes data living at an external HTTP URI. */
|
|
910
|
+
kind: "remote";
|
|
911
|
+
/** The fully qualified URI to the external resource. */
|
|
912
|
+
uri: URI;
|
|
913
|
+
/** Optional hint for the expected mime-type at the remote destination. */
|
|
914
|
+
mediaType?: BlobMediaType;
|
|
915
|
+
};
|
|
916
|
+
/** A contextual item (file, snippet, or data) attached to a session or prompt. */
|
|
917
|
+
interface Context {
|
|
918
|
+
/** Unique lookup key for this context entry. */
|
|
919
|
+
key: string;
|
|
920
|
+
/** Topics linking this context to relevant sessions or roles. */
|
|
921
|
+
topics: string[];
|
|
922
|
+
/** The actual payload of the context block. */
|
|
923
|
+
content: ContextContent;
|
|
924
|
+
/** UTC timestamp of when the context was added. */
|
|
925
|
+
timestamp: Timestamp;
|
|
926
|
+
/** Extensible key-value store for application-specific contextual metadata. */
|
|
927
|
+
metadata?: Record<string, any>;
|
|
558
928
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
929
|
+
/** Metadata for a conversation session, stored in the persistent collection. */
|
|
930
|
+
interface SessionMetadata {
|
|
931
|
+
/** Unique identifier for the chat session. */
|
|
932
|
+
id: UUID;
|
|
933
|
+
/** Human-readable title or label for the session. */
|
|
934
|
+
label: string;
|
|
935
|
+
/** The active Role (persona) name guiding this specific session. */
|
|
936
|
+
role: string;
|
|
937
|
+
/** Semantic topics governing what context and tools are active for this session. */
|
|
938
|
+
topics: string[];
|
|
939
|
+
/** Array of UUIDs pointing to explicitly active preferences for this session. */
|
|
940
|
+
preferences: UUID[];
|
|
941
|
+
/** Timestamps detailing the session lifecycle. */
|
|
942
|
+
metadata: {
|
|
943
|
+
/** UTC timestamp of session creation. */
|
|
944
|
+
created?: Timestamp;
|
|
945
|
+
/** UTC timestamp of the last activity within the session. */
|
|
946
|
+
updated?: Timestamp;
|
|
563
947
|
};
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
turn: Turn;
|
|
948
|
+
/** The current chronological leaf-node of the conversation DAG. */
|
|
949
|
+
head?: {
|
|
950
|
+
/** The ID of the most recent turn. */
|
|
951
|
+
id: UUID;
|
|
952
|
+
/** The active version of the most recent turn. */
|
|
953
|
+
version: number;
|
|
571
954
|
};
|
|
955
|
+
/** Overriding execution constraints active at the session level. */
|
|
956
|
+
constraints?: ModelConstraintMap;
|
|
572
957
|
}
|
|
573
|
-
/**
|
|
574
|
-
interface
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
958
|
+
/** In-memory summary of a Role. */
|
|
959
|
+
interface RoleSummary {
|
|
960
|
+
/** The unique identifier string for the role. */
|
|
961
|
+
name: string;
|
|
962
|
+
/** The UI-friendly label for the role. */
|
|
963
|
+
label: string;
|
|
964
|
+
/** A brief summary of the role's purpose. */
|
|
965
|
+
description?: string;
|
|
966
|
+
/** Integer count of how many preference records are tied to this role. */
|
|
967
|
+
preferences: number;
|
|
968
|
+
/** Topics relevant to this role. */
|
|
969
|
+
topics?: string[];
|
|
970
|
+
/** The top-level constraints baked into the role. */
|
|
971
|
+
constraints?: ModelConstraintMap;
|
|
580
972
|
}
|
|
581
|
-
/**
|
|
582
|
-
interface
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
973
|
+
/** In-memory summary of a Preference. */
|
|
974
|
+
interface PreferenceSummary {
|
|
975
|
+
/** Unique identifier for the preference. */
|
|
976
|
+
id: UUID;
|
|
977
|
+
/** The topics linking this preference to the rest of the workspace. */
|
|
978
|
+
topics: string[];
|
|
979
|
+
/** UTC timestamp of the last update. */
|
|
980
|
+
timestamp: Timestamp;
|
|
981
|
+
/** A truncated preview string of the preference content. */
|
|
982
|
+
snippet?: string;
|
|
591
983
|
}
|
|
592
|
-
/**
|
|
593
|
-
interface
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
version: number;
|
|
611
|
-
newHead: TurnRef | null;
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
interface SwitchRole extends BaseCommand {
|
|
615
|
-
type: 'session:role:switch';
|
|
616
|
-
payload: {
|
|
617
|
-
sessionId: UUID;
|
|
618
|
-
role: string;
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
interface AddSessionTopics extends BaseCommand {
|
|
622
|
-
type: 'session:topics:add';
|
|
623
|
-
payload: {
|
|
624
|
-
sessionId: UUID;
|
|
625
|
-
topics: string[];
|
|
626
|
-
};
|
|
627
|
-
}
|
|
628
|
-
interface OverrideSessionPreferences extends BaseCommand {
|
|
629
|
-
type: 'session:preferences:override';
|
|
630
|
-
payload: {
|
|
631
|
-
sessionId: UUID;
|
|
632
|
-
preferences: UUID[];
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
/** Creates a new session starting from the state of an existing one. */
|
|
636
|
-
interface ForkSession extends BaseCommand {
|
|
637
|
-
type: 'session:fork';
|
|
638
|
-
payload: {
|
|
639
|
-
sourceSessionId: UUID;
|
|
640
|
-
newSessionId: UUID;
|
|
641
|
-
label: string;
|
|
642
|
-
role?: string;
|
|
643
|
-
topics?: string[];
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
interface UpdateSession extends BaseCommand {
|
|
647
|
-
type: 'session:update';
|
|
648
|
-
payload: {
|
|
649
|
-
sessionId: UUID;
|
|
650
|
-
label?: string;
|
|
651
|
-
role?: string;
|
|
652
|
-
topics?: string[];
|
|
653
|
-
preferences?: UUID[];
|
|
654
|
-
task?: UUID | null;
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
interface DeleteSession extends BaseCommand {
|
|
658
|
-
type: 'session:delete';
|
|
659
|
-
payload: {
|
|
660
|
-
sessionId: UUID;
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
interface RegisterBlob extends BaseCommand {
|
|
664
|
-
type: 'blob:register';
|
|
665
|
-
payload: {
|
|
666
|
-
data: Uint8Array;
|
|
667
|
-
mediaType: BlobMediaType;
|
|
668
|
-
filename?: string;
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
/** Increases reference count to prevent garbage collection. */
|
|
672
|
-
interface RetainBlob extends BaseCommand {
|
|
673
|
-
type: 'blob:retain';
|
|
674
|
-
payload: {
|
|
675
|
-
sha256: SHA256;
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
/** Decreases reference count. */
|
|
679
|
-
interface ReleaseBlob extends BaseCommand {
|
|
680
|
-
type: 'blob:release';
|
|
681
|
-
payload: {
|
|
682
|
-
sha256: SHA256;
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
/** Immediately removes a blob regardless of reference count. */
|
|
686
|
-
interface PurgeBlob extends BaseCommand {
|
|
687
|
-
type: 'blob:purge';
|
|
688
|
-
payload: {
|
|
689
|
-
sha256: SHA256;
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
/** Maps a local blob to an external provider's file ID. */
|
|
693
|
-
interface RecordBlobRemoteId extends BaseCommand {
|
|
694
|
-
type: 'blob:record_remote_id';
|
|
695
|
-
payload: {
|
|
696
|
-
sha256: SHA256;
|
|
697
|
-
providerId: string;
|
|
698
|
-
fileId: string;
|
|
699
|
-
timestamp?: Timestamp;
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
type BlobCommand = RegisterBlob | RetainBlob | ReleaseBlob | PurgeBlob | RecordBlobRemoteId;
|
|
703
|
-
interface CallTool extends BaseCommand {
|
|
704
|
-
type: 'tool:call';
|
|
705
|
-
payload: ToolCall;
|
|
706
|
-
}
|
|
707
|
-
/** Union of all possible commands that can be dispatched to the Workspace Manager. */
|
|
708
|
-
type Command = CreateWorkspace | AddRole | UpdateRole | DeleteRole | AddPreference | UpdatePreference | DeletePreference | CreateSession | UpdateSession | AddContext | UpdateContext | DeleteContext | AddTask | UpdateTask | DeleteTask | AddTurn | SaveTurn | EditTurn | BranchTurn | DeleteTurn | SwitchRole | AddSessionTopics | OverrideSessionPreferences | ForkSession | DeleteSession | BlobCommand | CallTool;
|
|
709
|
-
/** Configuration for token counting and management during prompt generation. */
|
|
710
|
-
interface TokenBudget {
|
|
711
|
-
total: number;
|
|
712
|
-
estimator?: (text: string) => number;
|
|
713
|
-
blobTokensPerKB?: number;
|
|
984
|
+
/** In-memory summary of a Context entry. */
|
|
985
|
+
interface ContextSummary {
|
|
986
|
+
/** The unique key for the context item. */
|
|
987
|
+
key: string;
|
|
988
|
+
/** Associated semantic topics. */
|
|
989
|
+
topics: string[];
|
|
990
|
+
/** UTC timestamp of addition. */
|
|
991
|
+
timestamp: Timestamp;
|
|
992
|
+
/** MIME type, if applicable to the content kind. */
|
|
993
|
+
mime?: string;
|
|
994
|
+
/** File size in bytes, if applicable. */
|
|
995
|
+
size?: number;
|
|
996
|
+
/** Truncated text preview or URL for visual representation. */
|
|
997
|
+
preview?: string;
|
|
998
|
+
/** Origin or source string indicating where the context came from. */
|
|
999
|
+
source?: string;
|
|
1000
|
+
/** Flattened representation of the context's internal metadata. */
|
|
1001
|
+
metadata?: Record<string, any>;
|
|
714
1002
|
}
|
|
715
|
-
/**
|
|
716
|
-
interface
|
|
1003
|
+
/** Maps topics to the various entities that reference them. */
|
|
1004
|
+
interface TopicIndex {
|
|
1005
|
+
/** The exact string name of the topic. */
|
|
717
1006
|
topic: string;
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
persona: string;
|
|
731
|
-
preferences: Preference[];
|
|
732
|
-
context: Context[];
|
|
733
|
-
task: Task | null;
|
|
734
|
-
};
|
|
735
|
-
/** Additional context items injected separately. */
|
|
736
|
-
context: Context[];
|
|
737
|
-
/** The conversation history. */
|
|
738
|
-
transcript: {
|
|
739
|
-
turns: Turn[];
|
|
740
|
-
};
|
|
741
|
-
budget: {
|
|
742
|
-
total: number;
|
|
743
|
-
used: number;
|
|
744
|
-
breakdown: Record<string, number>;
|
|
745
|
-
};
|
|
746
|
-
/** Statistics on what was removed to fit within the token limit. */
|
|
747
|
-
truncated: {
|
|
748
|
-
preferences: number;
|
|
749
|
-
interactions: number;
|
|
750
|
-
context: number;
|
|
751
|
-
};
|
|
752
|
-
warnings: string[];
|
|
753
|
-
conflicts: PreferenceConflict[];
|
|
754
|
-
}
|
|
755
|
-
/** Typed events emitted by the Workspace when data changes. */
|
|
756
|
-
interface WorkspaceEvents {
|
|
757
|
-
/** Emitted when the index or core settings change. */
|
|
758
|
-
'workspace:changed': DeepPartial<Workspace>;
|
|
759
|
-
/** Emitted when a blob is registered, updated, or removed. */
|
|
760
|
-
'blobs:changed': {
|
|
761
|
-
sha256: SHA256;
|
|
762
|
-
record: BlobRecord | null;
|
|
1007
|
+
/** Array of context keys that fall under this topic. */
|
|
1008
|
+
contextKeys: string[];
|
|
1009
|
+
/** Array of preference UUIDs that fall under this topic. */
|
|
1010
|
+
preferences: UUID[];
|
|
1011
|
+
/** Aggregated metadata regarding topic usage. */
|
|
1012
|
+
metadata?: {
|
|
1013
|
+
/** When the topic was first registered. */
|
|
1014
|
+
created?: Timestamp;
|
|
1015
|
+
/** When the topic was last updated or applied. */
|
|
1016
|
+
updated?: Timestamp;
|
|
1017
|
+
/** Total number of workspace items referencing this topic. */
|
|
1018
|
+
entries?: number;
|
|
763
1019
|
};
|
|
764
1020
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
* @param sessionId - The session in which the turn was generated.
|
|
793
|
-
* @returns An array of Commands to synchronize the Workspace state.
|
|
794
|
-
*/
|
|
795
|
-
process(turn: Turn, sessionId?: UUID): Command[];
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Manages the lifecycle and execution of external tools.
|
|
799
|
-
* Acts as a central hub for discovering available capabilities and
|
|
800
|
-
* routing tool calls to their respective executors.
|
|
801
|
-
*/
|
|
802
|
-
interface ToolRegistry {
|
|
803
|
-
/**
|
|
804
|
-
* Subscribes to changes in the tool ecosystem.
|
|
805
|
-
* @param callback - Invoked whenever tools are added, removed, or updated.
|
|
806
|
-
*/
|
|
807
|
-
onRegistryChanged(callback: (tools: ToolSummary[]) => void): void;
|
|
808
|
-
/**
|
|
809
|
-
* Retrieves a list of all currently registered and available tools.
|
|
810
|
-
* @returns An array of summaries describing tool capabilities and schemas.
|
|
811
|
-
*/
|
|
812
|
-
list(): ToolSummary[];
|
|
813
|
-
/**
|
|
814
|
-
* Executes a tool call in a stateless manner.
|
|
815
|
-
* * @template T - The expected return type of the tool execution.
|
|
816
|
-
* @param call - The specific tool call requested by the model.
|
|
817
|
-
* @returns A promise resolving to a Result wrapper containing the tool output.
|
|
818
|
-
*/
|
|
819
|
-
execute<T = any>(call: ToolCall): Promise<Result<T>>;
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Enforces security and authorization policies.
|
|
823
|
-
* * The PermissionGuard ensures that the current execution context (User/Session)
|
|
824
|
-
* has the necessary privileges to perform a requested action or tool call.
|
|
825
|
-
*/
|
|
826
|
-
interface PermissionGuard {
|
|
827
|
-
/**
|
|
828
|
-
* Validates if the current context has the right to execute the request.
|
|
829
|
-
* * @param request - The authentication payload and target action.
|
|
830
|
-
* @returns A Result containing the authorized payload or an error.
|
|
831
|
-
*/
|
|
832
|
-
authenticate(request: AuthRequest): Promise<Result<AuthRequest["payload"] | null>>;
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* Bridge between the internal Workspace types and external LLM APIs.
|
|
836
|
-
* This generic adapter allows the system to remain vendor-agnostic by
|
|
837
|
-
* centralizing the translation logic for different providers (Google, OpenAI, etc.).
|
|
838
|
-
* @template TRequest - The specific request shape expected by the provider SDK.
|
|
839
|
-
* @template TRequestParams - Extra parameters for the request (e.g., model name, temperature).
|
|
840
|
-
* @template TResponse - The raw response shape returned by the provider SDK.
|
|
841
|
-
*/
|
|
842
|
-
interface LLMAdapter<TRequest, TRequestParams, TResponse> {
|
|
843
|
-
/**
|
|
844
|
-
* Maps the internal `Prompt` to the vendor-specific request format.
|
|
845
|
-
* * @param params - The prompt and provider-specific configuration.
|
|
846
|
-
* @returns The formatted request object ready for the SDK.
|
|
847
|
-
*/
|
|
848
|
-
/**
|
|
849
|
-
* Prepares the request and identifies necessary side-effects (like uploads).
|
|
850
|
-
*/
|
|
851
|
-
prepare(params: {
|
|
852
|
-
prompt: Prompt;
|
|
853
|
-
} & TRequestParams): Promise<{
|
|
854
|
-
request: TRequest;
|
|
855
|
-
effects?: Command[];
|
|
856
|
-
}>;
|
|
857
|
-
/**
|
|
858
|
-
* Maps the vendor-specific response back to an internal `Turn`.
|
|
859
|
-
* * @param params - The raw response received from the model API.
|
|
860
|
-
* @returns A Result containing standardized Turn object or an error.
|
|
861
|
-
*/
|
|
862
|
-
parse(params: {
|
|
863
|
-
response: TResponse;
|
|
864
|
-
}): Result<Turn, WorkspaceError>;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* Buffers write operations across one or more stores and commits them atomically.
|
|
869
|
-
*
|
|
870
|
-
* ## How atomicity works
|
|
871
|
-
*
|
|
872
|
-
* ### IndexedDB stores (same database)
|
|
873
|
-
* At commit time, TransactionContext collects the names of every IDB store that
|
|
874
|
-
* received operations, then opens a **single** `IDBTransaction` spanning all of
|
|
875
|
-
* them via `ConnectionManager.openTransaction`. Each store's `executeInTransaction`
|
|
876
|
-
* receives that shared transaction object and performs its writes against it
|
|
877
|
-
* without opening a new transaction of its own. IDB commits or aborts the
|
|
878
|
-
* entire multi-store transaction as one unit.
|
|
879
|
-
*
|
|
880
|
-
* ### MemoryStore
|
|
881
|
-
* MemoryStore's `executeInTransaction` receives `null` for the shared transaction.
|
|
882
|
-
* It applies ops against an internal staging map and returns. If a later
|
|
883
|
-
* participant fails, TransactionContext calls `rollbackMemory` on each
|
|
884
|
-
* MemoryStore that already applied its staged ops. MemoryStore restores its
|
|
885
|
-
* pre-transaction snapshot.
|
|
886
|
-
*
|
|
887
|
-
* ### Mixed (IDB + Memory in the same transaction)
|
|
888
|
-
* All IDB stores are committed first as a single atomic IDB transaction, then
|
|
889
|
-
* each MemoryStore is committed. If a MemoryStore fails after IDB has already
|
|
890
|
-
* committed, the IDB side cannot be rolled back — this is an inherent limitation
|
|
891
|
-
* of mixing two different storage engines. In practice the schema store is
|
|
892
|
-
* always MemoryStore-or-IDB consistently, so mixed transactions should not arise
|
|
893
|
-
* in normal usage.
|
|
894
|
-
*/
|
|
895
|
-
declare class TransactionContext {
|
|
896
|
-
readonly id: string;
|
|
897
|
-
/**
|
|
898
|
-
* Flat list of every operation staged so far, in the order they were added.
|
|
899
|
-
* We keep the store reference alongside the op so commit() can group them.
|
|
900
|
-
*/
|
|
901
|
-
private staged;
|
|
902
|
-
private done;
|
|
903
|
-
constructor();
|
|
904
|
-
/**
|
|
905
|
-
* Stages a single write operation against a store.
|
|
906
|
-
* Does NOT touch the store — no I/O happens until commit().
|
|
907
|
-
*/
|
|
908
|
-
addOp<T extends Record<string, any>>(store: Store<T>, type: "put" | "delete" | "add", data: any): Promise<void>;
|
|
909
|
-
/**
|
|
910
|
-
* Commits all staged operations atomically.
|
|
911
|
-
*
|
|
912
|
-
* For IDB stores: opens one shared IDBTransaction across all participating
|
|
913
|
-
* stores, then dispatches ops to each store's executeInTransaction.
|
|
914
|
-
* For MemoryStores: dispatches sequentially; rolls back on failure.
|
|
915
|
-
*/
|
|
916
|
-
commit(): Promise<void>;
|
|
917
|
-
/**
|
|
918
|
-
* Discards all staged operations. No I/O has occurred so there is nothing
|
|
919
|
-
* to undo — we simply clear the buffer.
|
|
920
|
-
*/
|
|
921
|
-
rollback(): void;
|
|
922
|
-
/**
|
|
923
|
-
* Opens ONE IDBTransaction across all participating IDB stores and lets
|
|
924
|
-
* each store execute its ops against the shared transaction handle.
|
|
925
|
-
*
|
|
926
|
-
* We obtain the IDBDatabase from the first store (they all share the same
|
|
927
|
-
* ConnectionManager / database) and open the transaction ourselves so that
|
|
928
|
-
* the commit/abort lifecycle belongs entirely to this method.
|
|
929
|
-
*/
|
|
930
|
-
private commitIDB;
|
|
931
|
-
/**
|
|
932
|
-
* Commits MemoryStore groups sequentially.
|
|
933
|
-
* Maintains a list of stores that have already applied their ops; if any
|
|
934
|
-
* store throws, all previously-applied stores are rolled back via the
|
|
935
|
-
* store-level `_rollbackMemory(snapshot)` escape hatch.
|
|
936
|
-
*/
|
|
937
|
-
private commitMemory;
|
|
938
|
-
completed(): boolean;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
interface CursorCallbackResult<T> {
|
|
942
|
-
value: T | null;
|
|
943
|
-
done: boolean;
|
|
944
|
-
offset?: number;
|
|
945
|
-
}
|
|
946
|
-
/**
|
|
947
|
-
* Callback function for cursor iteration over store records.
|
|
948
|
-
*
|
|
949
|
-
* @template T - The type of records stored.
|
|
950
|
-
* @param value - The current record value (cloned, not a live reference).
|
|
951
|
-
* @param key - The key (ID) of the current record.
|
|
952
|
-
* @param cursor - The underlying cursor object (implementation-specific; may be `null` in memory adapters).
|
|
953
|
-
* @returns A promise resolving to an object indicating whether iteration should stop,
|
|
954
|
-
* and an optional offset to advance.
|
|
955
|
-
*/
|
|
956
|
-
type CursorCallback<T> = (value: T, key: string | number, cursor: any) => Promise<CursorCallbackResult<T>>;
|
|
957
|
-
/**
|
|
958
|
-
* A generic representation of a key range, replacing the browser-specific IDBKeyRange.
|
|
959
|
-
*/
|
|
960
|
-
interface StoreKeyRange {
|
|
961
|
-
lower?: any;
|
|
962
|
-
upper?: any;
|
|
963
|
-
lowerOpen?: boolean;
|
|
964
|
-
upperOpen?: boolean;
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* A single buffered operation staged inside a TransactionContext.
|
|
968
|
-
* Kept intentionally minimal — the context only needs to know what to
|
|
969
|
-
* replay against a store during commit.
|
|
970
|
-
*/
|
|
971
|
-
type BufferedOperation<T> = {
|
|
972
|
-
type: "add" | "put";
|
|
973
|
-
data: T | T[];
|
|
974
|
-
} | {
|
|
975
|
-
type: "delete";
|
|
976
|
-
data: string | number | (string | number)[];
|
|
977
|
-
};
|
|
978
|
-
/**
|
|
979
|
-
* Storage adapter interface for a single object store (collection).
|
|
980
|
-
*
|
|
981
|
-
* Stores own their indexes. Index lifecycle (create, drop) and index-aware reads
|
|
982
|
-
* (findByIndex) are part of this contract so that both MemoryStore and IndexedDBStore
|
|
983
|
-
* implement them natively — MemoryStore via in-memory index maps, IndexedDB via its
|
|
984
|
-
* native index mechanism.
|
|
985
|
-
*
|
|
986
|
-
* @template T - The type of objects stored. Must include the key path property.
|
|
987
|
-
*/
|
|
988
|
-
interface Store<T extends Record<string, any> = Record<string, any>> {
|
|
989
|
-
/**
|
|
990
|
-
* Returns the name of this store (the IDB object store / collection name).
|
|
991
|
-
* Used by TransactionContext to group operations and open a correctly-scoped
|
|
992
|
-
* multi-store IDB transaction at commit time.
|
|
993
|
-
*/
|
|
994
|
-
name(): string;
|
|
995
|
-
/**
|
|
996
|
-
* Opens the store, ensuring underlying storage structures exist.
|
|
997
|
-
*/
|
|
998
|
-
open(): Promise<void>;
|
|
999
|
-
/**
|
|
1000
|
-
* Adds one or more records to the store.
|
|
1001
|
-
* If a record does not have a value for the store's key path, an automatic
|
|
1002
|
-
* key may be assigned. Throws if a record with the same key already exists.
|
|
1003
|
-
*/
|
|
1004
|
-
add(data: T | T[]): Promise<string | number | (string | number)[]>;
|
|
1005
|
-
/**
|
|
1006
|
-
* Removes all records from the store without destroying index structures.
|
|
1007
|
-
*/
|
|
1008
|
-
clear(): Promise<void>;
|
|
1009
|
-
/**
|
|
1010
|
-
* Returns the total number of records in the store.
|
|
1011
|
-
*/
|
|
1012
|
-
count(): Promise<number>;
|
|
1013
|
-
/**
|
|
1014
|
-
* Deletes one or more records by their keys.
|
|
1015
|
-
*/
|
|
1016
|
-
delete(id: string | number | (string | number)[]): Promise<void>;
|
|
1017
|
-
/**
|
|
1018
|
-
* Retrieves a single record by its primary key.
|
|
1019
|
-
*/
|
|
1020
|
-
getById(id: string | number): Promise<T | undefined>;
|
|
1021
|
-
/**
|
|
1022
|
-
* Retrieves the first record matching an exact index key (point lookup).
|
|
1023
|
-
* Useful for unique indexes — returns the single matching record or undefined.
|
|
1024
|
-
*
|
|
1025
|
-
* @param indexName - The name of the index to query.
|
|
1026
|
-
* @param key - The exact key value to look up.
|
|
1027
|
-
*/
|
|
1028
|
-
getByIndex(indexName: string, key: any): Promise<T | undefined>;
|
|
1029
|
-
/**
|
|
1030
|
-
* Retrieves all records from a named index, optionally filtered by a key range.
|
|
1031
|
-
* Use this for range scans over an index (e.g. all records where age >= 18).
|
|
1032
|
-
*
|
|
1033
|
-
* @param indexName - The name of the index to query.
|
|
1034
|
-
* @param keyRange - Optional range to filter results.
|
|
1035
|
-
*/
|
|
1036
|
-
getByKeyRange(indexName: string, keyRange?: StoreKeyRange): Promise<T[]>;
|
|
1037
|
-
/**
|
|
1038
|
-
* Retrieves all records from the store without index involvement.
|
|
1039
|
-
*/
|
|
1040
|
-
getAll(): Promise<T[]>;
|
|
1041
|
-
/**
|
|
1042
|
-
* Inserts or replaces a record. Validates OCC if a record with the same key exists.
|
|
1043
|
-
*/
|
|
1044
|
-
put(data: T): Promise<string | number>;
|
|
1045
|
-
/**
|
|
1046
|
-
* Iterates over records using a cursor, allowing early termination and skipping.
|
|
1047
|
-
*
|
|
1048
|
-
* @param callback - Invoked for each record; return `{ done: true }` to stop,
|
|
1049
|
-
* `{ offset: n }` to skip ahead n records.
|
|
1050
|
-
* @param direction - Iteration order.
|
|
1051
|
-
* @param keyRange - Optional range to restrict iteration.
|
|
1052
|
-
*/
|
|
1053
|
-
cursor(callback: CursorCallback<T>, direction?: "forward" | "backward", keyRange?: StoreKeyRange): Promise<T | null>;
|
|
1054
|
-
/**
|
|
1055
|
-
* Executes a batch of write operations atomically within this store.
|
|
1056
|
-
* All operations succeed or fail together.
|
|
1057
|
-
*
|
|
1058
|
-
* Used for standalone (single-store) atomic writes. For cross-store atomicity,
|
|
1059
|
-
* use executeInTransaction instead.
|
|
1060
|
-
*/
|
|
1061
|
-
batch(operations: Array<{
|
|
1062
|
-
type: "add" | "put";
|
|
1063
|
-
data: T | T[];
|
|
1064
|
-
} | {
|
|
1065
|
-
type: "delete";
|
|
1066
|
-
data: string | number | (string | number)[];
|
|
1067
|
-
}>): Promise<void>;
|
|
1068
|
-
/**
|
|
1069
|
-
* Registers a new index on the store. Idempotent — no-op if the index already exists.
|
|
1070
|
-
* For IndexedDB, this triggers a database version upgrade.
|
|
1071
|
-
* For MemoryStore, this builds the index map from existing records.
|
|
1072
|
-
*
|
|
1073
|
-
* @param definition - The full index definition from the schema.
|
|
1074
|
-
*/
|
|
1075
|
-
createIndex(definition: IndexDefinition): Promise<void>;
|
|
1076
|
-
/**
|
|
1077
|
-
* Removes a named index from the store.
|
|
1078
|
-
* For IndexedDB, this triggers a database version upgrade.
|
|
1079
|
-
* For MemoryStore, this drops the in-memory index map.
|
|
1080
|
-
*
|
|
1081
|
-
* @param name - The index name as declared in IndexDefinition.name.
|
|
1082
|
-
*/
|
|
1083
|
-
dropIndex(name: string): Promise<void>;
|
|
1084
|
-
/**
|
|
1085
|
-
* Returns all records matching an exact index key.
|
|
1086
|
-
* Unlike getByIndex (which returns only the first match), this returns all matches —
|
|
1087
|
-
* essential for non-unique indexes where multiple records share the same indexed value.
|
|
1088
|
-
*
|
|
1089
|
-
* @param indexName - The name of the index to query.
|
|
1090
|
-
* @param value - The exact value to look up.
|
|
1091
|
-
*/
|
|
1092
|
-
findByIndex(indexName: string, value: any): Promise<T[]>;
|
|
1093
|
-
/**
|
|
1094
|
-
* Executes a set of buffered operations as part of a cross-store atomic transaction.
|
|
1095
|
-
*
|
|
1096
|
-
* For IndexedDBStore: `sharedTx` is the single IDBTransaction opened across all
|
|
1097
|
-
* participating stores. Operations are applied directly to `sharedTx.objectStore(name)`
|
|
1098
|
-
* without opening a new transaction — IDB commits or aborts the whole thing atomically.
|
|
1099
|
-
*
|
|
1100
|
-
* For MemoryStore: `sharedTx` is null. The store applies ops against its own staging
|
|
1101
|
-
* area. The caller (TransactionContext) is responsible for coordinating rollback across
|
|
1102
|
-
* all MemoryStores if any participant fails.
|
|
1103
|
-
*
|
|
1104
|
-
* This method must NOT open, commit, or abort any transaction itself.
|
|
1105
|
-
*
|
|
1106
|
-
* @param ops - The buffered operations to apply.
|
|
1107
|
-
* @param sharedTx - The shared IDBTransaction (IndexedDB only), or null (MemoryStore).
|
|
1108
|
-
*/
|
|
1109
|
-
executeInTransaction(ops: BufferedOperation<T>[], sharedTx: IDBTransaction | null): Promise<void>;
|
|
1110
|
-
}
|
|
1111
|
-
interface Collection<T> {
|
|
1112
|
-
/**
|
|
1113
|
-
* Finds a single document matching the query.
|
|
1114
|
-
*/
|
|
1115
|
-
find: (query: QueryFilter<T>) => Promise<Document<T> | null>;
|
|
1116
|
-
/**
|
|
1117
|
-
* Lists documents with pagination. Returns an AsyncIterator so consumers can
|
|
1118
|
-
* wrap it in their own iteration protocol (e.g. for-await-of via AsyncIterable).
|
|
1119
|
-
*/
|
|
1120
|
-
list: (query: PaginationOptions) => Promise<AsyncIterator<Document<T>[]>>;
|
|
1121
|
-
/**
|
|
1122
|
-
* Filters all documents matching the query.
|
|
1123
|
-
*/
|
|
1124
|
-
filter: (query: QueryFilter<T>) => Promise<Document<T>[]>;
|
|
1125
|
-
/**
|
|
1126
|
-
* Creates a new document in the collection.
|
|
1127
|
-
*
|
|
1128
|
-
* When a TransactionContext is provided the initial store.add is buffered into
|
|
1129
|
-
* the transaction rather than written immediately. The document is returned in
|
|
1130
|
-
* its fully initialised in-memory state regardless — callers can use it before
|
|
1131
|
-
* the transaction commits.
|
|
1132
|
-
*
|
|
1133
|
-
* @param initial - The initial data for the document.
|
|
1134
|
-
* @param tx - Optional transaction to buffer the write into.
|
|
1135
|
-
*/
|
|
1136
|
-
create: (initial: T, tx?: TransactionContext) => Promise<Document<T>>;
|
|
1137
|
-
/**
|
|
1138
|
-
* Subscribes to collection-level events.
|
|
1139
|
-
*/
|
|
1140
|
-
subscribe: (event: CollectionEventType | TelemetryEventType, callback: (event: CollectionEvent<T> | TelemetryEvent) => void) => () => void;
|
|
1141
|
-
/**
|
|
1142
|
-
* Validates data against the collection's schema.
|
|
1143
|
-
*/
|
|
1144
|
-
validate(data: Record<string, any>): Promise<{
|
|
1145
|
-
value?: any;
|
|
1146
|
-
issues: Array<{
|
|
1147
|
-
message: string;
|
|
1148
|
-
path: Array<string>;
|
|
1149
|
-
}>;
|
|
1150
|
-
}>;
|
|
1151
|
-
invalidate(): void;
|
|
1021
|
+
/** The complete in-memory read-model of the Workspace state. */
|
|
1022
|
+
interface Index {
|
|
1023
|
+
/** Lookup dictionary of Roles by their string name. */
|
|
1024
|
+
roles: Record<string, RoleSummary>;
|
|
1025
|
+
/** Lookup dictionary of Preferences by their UUID. */
|
|
1026
|
+
preferences: Record<UUID, PreferenceSummary>;
|
|
1027
|
+
/** Lookup dictionary of Context entries by their specific key. */
|
|
1028
|
+
context: Record<string, ContextSummary>;
|
|
1029
|
+
/** Lookup dictionary of active Sessions by their UUID. */
|
|
1030
|
+
sessions: Record<UUID, SessionMetadata>;
|
|
1031
|
+
/** Lookup dictionary of semantic Topics by their string name. */
|
|
1032
|
+
topics: Record<string, TopicIndex>;
|
|
1033
|
+
/** Lookup dictionary of authoritative Blob records by their SHA-256 hash. */
|
|
1034
|
+
blobs: Record<SHA256, BlobRecord>;
|
|
1035
|
+
/** Lookup dictionary of registered Tool capabilities by their string name. */
|
|
1036
|
+
tools: Record<string, ToolSummary>;
|
|
1037
|
+
}
|
|
1038
|
+
/** The root container for a user's workspace. */
|
|
1039
|
+
interface Workspace<ProjectMetadata extends Record<string, any> = Record<string, any>> {
|
|
1040
|
+
/** Unique identifier for the entire workspace environment. */
|
|
1041
|
+
id: UUID;
|
|
1042
|
+
/** Global user and systemic settings. */
|
|
1043
|
+
settings: Settings;
|
|
1044
|
+
/** High-level project metadata. */
|
|
1045
|
+
project: Project<ProjectMetadata>;
|
|
1046
|
+
/** The in-memory read-projection of all underlying stores. */
|
|
1047
|
+
index: Index;
|
|
1152
1048
|
}
|
|
1153
1049
|
/**
|
|
1154
|
-
*
|
|
1050
|
+
* Format used for exporting/importing a complete workspace state,
|
|
1051
|
+
* including all historical turns and binary records.
|
|
1155
1052
|
*/
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
createCollection: <T>(schema: SchemaDefinition) => Promise<Collection<T>>;
|
|
1174
|
-
/**
|
|
1175
|
-
* Deletes a collection and its schema record.
|
|
1176
|
-
*/
|
|
1177
|
-
deleteCollection: (schemaName: string) => Promise<boolean>;
|
|
1178
|
-
/**
|
|
1179
|
-
* Updates an existing collection's schema record.
|
|
1180
|
-
*/
|
|
1181
|
-
updateCollection: (schema: SchemaDefinition) => Promise<boolean>;
|
|
1182
|
-
/**
|
|
1183
|
-
* Migrates an existing collection's data and schema definition.
|
|
1184
|
-
* Processes data in a streaming fashion to avoid loading the full collection
|
|
1185
|
-
* into memory.
|
|
1186
|
-
*/
|
|
1187
|
-
migrateCollection: <T>(name: string, opts: CollectionMigrationOptions, batchSize?: number) => Promise<Collection<T>>;
|
|
1188
|
-
/**
|
|
1189
|
-
* Executes a callback within a TransactionContext.
|
|
1190
|
-
* Writes buffered inside the callback are flushed atomically on commit.
|
|
1191
|
-
* If the callback throws, the buffer is discarded (no writes are flushed).
|
|
1192
|
-
*/
|
|
1193
|
-
transaction: (callback: (tx: TransactionContext) => Promise<void>) => Promise<void>;
|
|
1194
|
-
/**
|
|
1195
|
-
* Subscribes to database-level events.
|
|
1196
|
-
*/
|
|
1197
|
-
subscribe: (event: DatabaseEventType | "telemetry", callback: (event: DatabaseEvent | TelemetryEvent) => void) => () => void;
|
|
1198
|
-
/**
|
|
1199
|
-
* Releases in-memory references and event bus subscriptions.
|
|
1200
|
-
* Does not delete any persisted data.
|
|
1201
|
-
*/
|
|
1202
|
-
close: () => void;
|
|
1203
|
-
clear: () => Promise<void>;
|
|
1204
|
-
/**
|
|
1205
|
-
* Ensures a collection exists; creates it if it doesn't. Idempotent.
|
|
1206
|
-
*/
|
|
1207
|
-
ensureCollection: (schema: SchemaDefinition) => Promise<void>;
|
|
1208
|
-
/**
|
|
1209
|
-
* Ensures multiple collections exist; creates any that don't. Idempotent.
|
|
1210
|
-
*/
|
|
1211
|
-
setupCollections: (schemas: SchemaDefinition[]) => Promise<void>;
|
|
1053
|
+
interface WorkspaceBundle {
|
|
1054
|
+
/** Schema version identifier for serialization compatibility. */
|
|
1055
|
+
format: "aiworkspace/4.0";
|
|
1056
|
+
/** The core workspace root data. */
|
|
1057
|
+
workspace: Workspace;
|
|
1058
|
+
/** All exported role definitions. */
|
|
1059
|
+
roles: Record<string, Role>;
|
|
1060
|
+
/** All exported preference objects. */
|
|
1061
|
+
preferences: Record<UUID, Preference>;
|
|
1062
|
+
/** All exported context entries. */
|
|
1063
|
+
context: Record<string, Context>;
|
|
1064
|
+
/** All exported sessions, deeply hydrated with their complete turn history. */
|
|
1065
|
+
sessions: Record<UUID, SessionMetadata & {
|
|
1066
|
+
turns: Turn[];
|
|
1067
|
+
}>;
|
|
1068
|
+
/** All exported blob definitions (may contain base64 binary strings or remote mappings). */
|
|
1069
|
+
blobs: Record<SHA256, BlobRecord>;
|
|
1212
1070
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1071
|
+
/** Base structure for all state-mutating commands in the system. */
|
|
1072
|
+
interface BaseCommand<T = any> {
|
|
1073
|
+
/** Discriminator for the specific command type. */
|
|
1074
|
+
type: string;
|
|
1075
|
+
/** UTC timestamp of when the command was issued. */
|
|
1076
|
+
timestamp: Timestamp;
|
|
1077
|
+
/** The ID of the user, system component, or tool that initiated the command. */
|
|
1078
|
+
actor?: SystemActor;
|
|
1079
|
+
/** An optional, human-readable reason or annotation for the execution. */
|
|
1080
|
+
description?: string;
|
|
1081
|
+
/** Indicates this command was automatically fired as a side-effect of another command. */
|
|
1082
|
+
synthetic?: boolean;
|
|
1083
|
+
/** Payload */
|
|
1084
|
+
payload: T;
|
|
1085
|
+
}
|
|
1086
|
+
interface CreateWorkspace extends BaseCommand {
|
|
1087
|
+
type: "workspace:create";
|
|
1088
|
+
/** Payload detailing initial setup values for the environment. */
|
|
1089
|
+
payload: {
|
|
1090
|
+
id: UUID;
|
|
1091
|
+
settings: Settings;
|
|
1092
|
+
project: Project;
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
interface AddRole extends BaseCommand {
|
|
1096
|
+
type: "role:add";
|
|
1097
|
+
/** The complete role object to inject into the workspace. */
|
|
1098
|
+
payload: Role;
|
|
1099
|
+
}
|
|
1100
|
+
interface UpdateRole extends BaseCommand {
|
|
1101
|
+
type: "role:update";
|
|
1102
|
+
/** Delta properties to merge into the existing role definition. */
|
|
1103
|
+
payload: Partial<Role> & {
|
|
1104
|
+
name: string;
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
interface DeleteRole extends BaseCommand {
|
|
1108
|
+
type: "role:delete";
|
|
1109
|
+
/** Name of the role to destroy. */
|
|
1110
|
+
payload: {
|
|
1111
|
+
name: string;
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
interface AddPreference extends BaseCommand {
|
|
1115
|
+
type: "preference:add";
|
|
1116
|
+
/** The complete preference object to register. */
|
|
1117
|
+
payload: Preference;
|
|
1118
|
+
}
|
|
1119
|
+
interface UpdatePreference extends BaseCommand {
|
|
1120
|
+
type: "preference:update";
|
|
1121
|
+
/** Delta properties to merge into the existing preference record. */
|
|
1122
|
+
payload: Partial<Preference> & {
|
|
1123
|
+
id: UUID;
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
interface DeletePreference extends BaseCommand {
|
|
1127
|
+
type: "preference:delete";
|
|
1128
|
+
/** UUID of the preference to drop. */
|
|
1129
|
+
payload: {
|
|
1130
|
+
id: UUID;
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
interface CreateSession extends BaseCommand {
|
|
1134
|
+
type: "session:create";
|
|
1135
|
+
/** Initial setup parameters for the new conversation session. */
|
|
1136
|
+
payload: {
|
|
1137
|
+
id: UUID;
|
|
1138
|
+
label: string;
|
|
1139
|
+
role: string;
|
|
1140
|
+
topics: string[];
|
|
1141
|
+
preferences: UUID[];
|
|
1142
|
+
metadata: {
|
|
1143
|
+
created?: Timestamp;
|
|
1144
|
+
updated?: Timestamp;
|
|
1264
1145
|
};
|
|
1265
|
-
error: {
|
|
1266
|
-
message: string;
|
|
1267
|
-
name: string;
|
|
1268
|
-
stack?: string;
|
|
1269
|
-
} | null;
|
|
1270
1146
|
};
|
|
1271
|
-
};
|
|
1272
|
-
|
|
1273
|
-
interface WorkspaceDatabase {
|
|
1274
|
-
/**
|
|
1275
|
-
* Open the database. Registers core schemas followed by any extension
|
|
1276
|
-
* schemas supplied by the caller (domain plugins).
|
|
1277
|
-
*
|
|
1278
|
-
* Idempotent — safe to call multiple times; subsequent calls are no-ops
|
|
1279
|
-
* if the database is already open.
|
|
1280
|
-
*/
|
|
1281
|
-
open(extensionSchemas?: SchemaDefinition[]): Promise<void>;
|
|
1282
|
-
/**
|
|
1283
|
-
* Access a collection by schema name.
|
|
1284
|
-
* Throws if the schema has not been registered.
|
|
1285
|
-
*/
|
|
1286
|
-
collection<T>(schemaName: string): Promise<Collection<T>>;
|
|
1287
|
-
/**
|
|
1288
|
-
* Close the database connection.
|
|
1289
|
-
*/
|
|
1290
|
-
close(): void;
|
|
1291
1147
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1148
|
+
interface AddContext extends BaseCommand {
|
|
1149
|
+
type: "context:add";
|
|
1150
|
+
/** The new context object to write to the store. */
|
|
1151
|
+
payload: Context;
|
|
1152
|
+
}
|
|
1153
|
+
interface UpdateContext extends BaseCommand {
|
|
1154
|
+
type: "context:update";
|
|
1155
|
+
/** Delta properties to update an existing context record. */
|
|
1156
|
+
payload: Partial<Context> & {
|
|
1157
|
+
key: string;
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
interface DeleteContext extends BaseCommand {
|
|
1161
|
+
type: "context:delete";
|
|
1162
|
+
/** Key of the context entry to destroy. */
|
|
1163
|
+
payload: {
|
|
1164
|
+
key: string;
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
/** Updates an existing turn record in storage. */
|
|
1168
|
+
interface UpdateTurn extends BaseCommand {
|
|
1169
|
+
type: "turn:update";
|
|
1170
|
+
/** The session scope and the fully updated turn structure. */
|
|
1171
|
+
payload: {
|
|
1172
|
+
sessionId: UUID;
|
|
1173
|
+
turn: Turn;
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
/** Appends a new turn to a session. */
|
|
1177
|
+
interface AddTurn extends BaseCommand {
|
|
1178
|
+
type: "turn:add";
|
|
1179
|
+
/** The session scope and the new turn to mount. */
|
|
1180
|
+
payload: {
|
|
1181
|
+
sessionId: UUID;
|
|
1182
|
+
turn: Turn;
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
/** Creates a new version of an existing turn. */
|
|
1186
|
+
interface EditTurn extends BaseCommand {
|
|
1187
|
+
type: "turn:edit";
|
|
1188
|
+
/** Details for incrementing a specific turn's iteration without losing history. */
|
|
1189
|
+
payload: {
|
|
1190
|
+
sessionId: UUID;
|
|
1191
|
+
turnId: UUID;
|
|
1192
|
+
newBlocks: ContentBlock[];
|
|
1193
|
+
newVersion: number;
|
|
1194
|
+
roleSnapshot?: string;
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
1197
|
+
/** Creates a new branch in the conversation history from a specific turn. */
|
|
1198
|
+
interface BranchTurn extends BaseCommand {
|
|
1199
|
+
type: "turn:branch";
|
|
1200
|
+
/** The turn object that initiates the new divergent history line. */
|
|
1201
|
+
payload: {
|
|
1202
|
+
sessionId: UUID;
|
|
1203
|
+
turn: Turn;
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
/** Reference to a specific iteration of a turn. */
|
|
1207
|
+
interface TurnRef {
|
|
1208
|
+
/** The ID of the referenced turn. */
|
|
1209
|
+
id: UUID;
|
|
1210
|
+
/** The exact version number of the referenced turn. */
|
|
1211
|
+
version: number;
|
|
1212
|
+
}
|
|
1213
|
+
/** Removes a specific version of a turn and updates the session head if necessary. */
|
|
1214
|
+
interface DeleteTurn extends BaseCommand {
|
|
1215
|
+
type: "turn:delete";
|
|
1216
|
+
/** Identification payload to target the precise turn version for destruction. */
|
|
1217
|
+
payload: {
|
|
1218
|
+
sessionId: UUID;
|
|
1219
|
+
turnId: UUID;
|
|
1220
|
+
version: number;
|
|
1221
|
+
/** The fallback position if deleting the current head. */
|
|
1222
|
+
newHead?: TurnRef;
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
interface SwitchSessionRole extends BaseCommand {
|
|
1226
|
+
type: "session:role:switch";
|
|
1227
|
+
/** Defines the transition of a session from one persona to another. */
|
|
1228
|
+
payload: {
|
|
1229
|
+
sessionId: UUID;
|
|
1230
|
+
roleName: string;
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
interface AddSessionTopics extends BaseCommand {
|
|
1234
|
+
type: "session:topics:add";
|
|
1235
|
+
/** Appends semantic tags to an existing session for RAG alignment. */
|
|
1236
|
+
payload: {
|
|
1237
|
+
sessionId: UUID;
|
|
1238
|
+
topics: string[];
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
interface OverrideSessionPreferences extends BaseCommand {
|
|
1242
|
+
type: "session:preferences:override";
|
|
1243
|
+
/** Replaces the explicit preference list attached to a session. */
|
|
1244
|
+
payload: {
|
|
1245
|
+
sessionId: UUID;
|
|
1246
|
+
preferences: UUID[];
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
/** Creates a new session starting from the state of an existing one. */
|
|
1250
|
+
interface ForkSession extends BaseCommand {
|
|
1251
|
+
type: "session:fork";
|
|
1252
|
+
/** Data defining the divergence point and initial overrides for the new fork. */
|
|
1253
|
+
payload: {
|
|
1254
|
+
sessionId: UUID;
|
|
1255
|
+
newSessionId: UUID;
|
|
1256
|
+
label: string;
|
|
1257
|
+
role?: string;
|
|
1258
|
+
topics?: string[];
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
interface UpdateSession extends BaseCommand {
|
|
1262
|
+
type: "session:update";
|
|
1263
|
+
/** Modifiable metadata fields for an ongoing session. */
|
|
1264
|
+
payload: {
|
|
1265
|
+
sessionId: UUID;
|
|
1266
|
+
label?: string;
|
|
1267
|
+
role?: string;
|
|
1268
|
+
topics?: string[];
|
|
1269
|
+
preferences?: UUID[];
|
|
1270
|
+
metadata?: SessionMetadata["metadata"];
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
interface DeleteSession extends BaseCommand {
|
|
1274
|
+
type: "session:delete";
|
|
1275
|
+
/** Identifier of the session to terminate and purge. */
|
|
1276
|
+
payload: {
|
|
1277
|
+
sessionId: UUID;
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
interface RegisterBlob extends BaseCommand {
|
|
1281
|
+
type: "blob:register";
|
|
1282
|
+
/** Standard payload for intaking new binary data into the blob system. */
|
|
1283
|
+
payload: {
|
|
1284
|
+
data: Uint8Array;
|
|
1285
|
+
mediaType: BlobMediaType;
|
|
1286
|
+
filename?: string;
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
/** Increases reference count to prevent garbage collection. */
|
|
1290
|
+
interface RetainBlob extends BaseCommand {
|
|
1291
|
+
type: "blob:retain";
|
|
1292
|
+
/** The hash targeting the specific blob to protect. */
|
|
1293
|
+
payload: {
|
|
1294
|
+
sha256: SHA256;
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
/** Decreases reference count. */
|
|
1298
|
+
interface ReleaseBlob extends BaseCommand {
|
|
1299
|
+
type: "blob:release";
|
|
1300
|
+
/** The hash targeting the specific blob to un-protect. */
|
|
1301
|
+
payload: {
|
|
1302
|
+
sha256: SHA256;
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
/** Immediately removes a blob regardless of reference count. */
|
|
1306
|
+
interface PurgeBlob extends BaseCommand {
|
|
1307
|
+
type: "blob:purge";
|
|
1308
|
+
/** The hash targeting the specific blob for immediate destruction. */
|
|
1309
|
+
payload: {
|
|
1310
|
+
sha256: SHA256;
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
/** Maps a local blob to an external provider's file ID. */
|
|
1314
|
+
interface RecordBlobRemoteId extends BaseCommand {
|
|
1315
|
+
type: "blob:record_remote_id";
|
|
1316
|
+
/** Payload linking local workspace data to an external API's asset registry. */
|
|
1317
|
+
payload: {
|
|
1318
|
+
sha256: SHA256;
|
|
1319
|
+
providerId: string;
|
|
1320
|
+
fileId: string;
|
|
1321
|
+
timestamp?: Timestamp;
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
/** Union of all blob management commands. */
|
|
1325
|
+
type BlobCommand = RegisterBlob | RetainBlob | ReleaseBlob | PurgeBlob | RecordBlobRemoteId;
|
|
1326
|
+
/** Entity representing a categorization or grouping mechanism. */
|
|
1327
|
+
interface Topic {
|
|
1328
|
+
/** Core string identifier (e.g., 'machine-learning'). */
|
|
1313
1329
|
name: string;
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
|
|
1322
|
-
*/
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
*/
|
|
1333
|
-
|
|
1330
|
+
/** UI-friendly presentation string. */
|
|
1331
|
+
label?: string;
|
|
1332
|
+
/** Deep description of what the topic encompasses. */
|
|
1333
|
+
description?: string;
|
|
1334
|
+
/** Extensible key-value store for topic-specific attributes. */
|
|
1335
|
+
metadata?: Record<string, any>;
|
|
1336
|
+
/** Timestamp of initial topic creation. */
|
|
1337
|
+
created: Timestamp;
|
|
1338
|
+
/** Timestamp of the most recent modification. */
|
|
1339
|
+
updated: Timestamp;
|
|
1340
|
+
}
|
|
1341
|
+
interface AddTopic extends BaseCommand {
|
|
1342
|
+
type: "topic:add";
|
|
1343
|
+
/** Fully formed topic object to inject. */
|
|
1344
|
+
payload: Topic;
|
|
1345
|
+
}
|
|
1346
|
+
interface UpdateTopic extends BaseCommand {
|
|
1347
|
+
type: "topic:update";
|
|
1348
|
+
/** Delta properties for modifying an existing topic. */
|
|
1349
|
+
payload: Partial<Topic> & {
|
|
1350
|
+
name: string;
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
interface DeleteTopic extends BaseCommand {
|
|
1354
|
+
type: "topic:delete";
|
|
1355
|
+
/** Rules for removing a topic, optionally destroying linked resources. */
|
|
1356
|
+
payload: {
|
|
1357
|
+
name: string;
|
|
1358
|
+
cascade?: boolean;
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
interface MergeTopics extends BaseCommand {
|
|
1362
|
+
type: "topic:merge";
|
|
1363
|
+
/** Consolidates two separate topics, migrating all relationships to the target. */
|
|
1364
|
+
payload: {
|
|
1365
|
+
source: string;
|
|
1366
|
+
target: string;
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
/** Executes a tool payload securely. */
|
|
1370
|
+
interface ToolCallCommand extends BaseCommand {
|
|
1371
|
+
type: "tool:call";
|
|
1372
|
+
/** Payload detailing the execution request for a registered tool. */
|
|
1373
|
+
payload: ToolCall;
|
|
1374
|
+
}
|
|
1375
|
+
/** Union of all possible commands that can be dispatched to the Workspace Manager. */
|
|
1376
|
+
type Command = CreateWorkspace | AddRole | UpdateRole | DeleteRole | AddPreference | UpdatePreference | DeletePreference | CreateSession | UpdateSession | ForkSession | DeleteSession | SwitchSessionRole | AddSessionTopics | OverrideSessionPreferences | AddContext | UpdateContext | DeleteContext | UpdateTurn | AddTurn | EditTurn | BranchTurn | DeleteTurn | RegisterBlob | RetainBlob | ReleaseBlob | PurgeBlob | RecordBlobRemoteId | AddTopic | UpdateTopic | DeleteTopic | MergeTopics | ToolCallCommand;
|
|
1334
1377
|
/**
|
|
1335
|
-
*
|
|
1336
|
-
* -
|
|
1337
|
-
*
|
|
1378
|
+
* Standard reducer pattern for updating workspace state.
|
|
1379
|
+
* @template T - Custom contextual additions for the reducer parameters.
|
|
1380
|
+
* @template R - The payload type the reducer expects to process.
|
|
1338
1381
|
*/
|
|
1339
|
-
|
|
1382
|
+
type WorkspaceReducer<T = any, R = any> = (
|
|
1383
|
+
/** Combined system context containing current state and active configurations. */
|
|
1384
|
+
ctx: {
|
|
1385
|
+
workspace: Workspace;
|
|
1386
|
+
} & T,
|
|
1387
|
+
/** The payload defining the intended mutation. */
|
|
1388
|
+
payload: R) => Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
1340
1389
|
/**
|
|
1341
|
-
*
|
|
1342
|
-
* - Returns the step's own `ref` if provided.
|
|
1343
|
-
* - Otherwise returns `${taskRef}_${index+1}` (e.g., "a3f9_2").
|
|
1344
|
-
*
|
|
1345
|
-
* The underscore separator avoids confusion with colons, slashes, or
|
|
1346
|
-
* numeric suffixes that could be misinterpreted by LLMs.
|
|
1390
|
+
* Middleware wrapper for observing or intercepting command dispatches.
|
|
1347
1391
|
*/
|
|
1348
|
-
|
|
1392
|
+
type WorkspaceMiddleware = (
|
|
1393
|
+
/** Comprehensive payload including the state, the executing command, and the intended state delta. */
|
|
1394
|
+
ctx: {
|
|
1395
|
+
workspace: Workspace;
|
|
1396
|
+
command: BaseCommand;
|
|
1397
|
+
patch: DeepPartial<Workspace>;
|
|
1398
|
+
} & WorkspaceContext) => Promise<DeepPartial<Workspace>>;
|
|
1399
|
+
/** A fully hydrated and normalized session structure. */
|
|
1400
|
+
interface ResolvedSession {
|
|
1401
|
+
/** The ID of the session. */
|
|
1402
|
+
sessionId: UUID;
|
|
1403
|
+
/** The active, fully resolved persona definition. */
|
|
1404
|
+
role: Role;
|
|
1405
|
+
/** The deduplicated, prioritized array of active preferences. */
|
|
1406
|
+
preferences: Preference[];
|
|
1407
|
+
/** RAG-retrieved context items relevant to the current conversation. */
|
|
1408
|
+
context: Context[];
|
|
1409
|
+
/** The linear conversation sequence flattened from the DAG structure. */
|
|
1410
|
+
transcript: Turn[];
|
|
1411
|
+
/** Dictionary of completely resolved local and remote binary assets. */
|
|
1412
|
+
blobs: Map<SHA256, ResolvedBlob>;
|
|
1413
|
+
/** The global system prompt overlay, if present. */
|
|
1414
|
+
instructions?: string;
|
|
1415
|
+
/** Array of warning strings generated during the resolution process. */
|
|
1416
|
+
warnings: string[];
|
|
1417
|
+
}
|
|
1418
|
+
/** Typed events emitted by the Workspace when data changes. */
|
|
1419
|
+
interface WorkspaceEvents {
|
|
1420
|
+
/** Emitted when the index or core settings change. */
|
|
1421
|
+
"workspace:changed": DeepPartial<Workspace>;
|
|
1422
|
+
/** Emitted when a blob is registered, updated, or removed. */
|
|
1423
|
+
"blobs:changed": {
|
|
1424
|
+
/** Hash of the affected blob. */
|
|
1425
|
+
sha256: SHA256;
|
|
1426
|
+
/** The actual modified record, or undefined if deleted. */
|
|
1427
|
+
record?: BlobRecord;
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
/** Complete snapshot of the session provided to the PromptBuilder. */
|
|
1431
|
+
interface SessionSnapshot {
|
|
1432
|
+
/** Session identifier. */
|
|
1433
|
+
id: UUID;
|
|
1434
|
+
/** Top-level session definition fields. */
|
|
1435
|
+
meta: SessionMetadata;
|
|
1436
|
+
/** The active role — persona, instructions, role-level constraints. */
|
|
1437
|
+
role: Role;
|
|
1438
|
+
/** Unfiltered, unranked preferences attached strictly to the role or session. */
|
|
1439
|
+
preferences: Preference[];
|
|
1440
|
+
/** All context entries whose topics overlap with the session's active topics. */
|
|
1441
|
+
context: Context[];
|
|
1442
|
+
/** Full active chain from TurnTree — oldest to newest. Untruncated. */
|
|
1443
|
+
transcript: Turn[];
|
|
1444
|
+
/** The session's active semantic topic set. */
|
|
1445
|
+
topics: string[];
|
|
1446
|
+
/** Global workspace instructions from Settings.prompt, if set. */
|
|
1447
|
+
instructions?: string;
|
|
1448
|
+
/** Model constraints structured by their hierarchical application level. */
|
|
1449
|
+
constraints: {
|
|
1450
|
+
/** Broadest constraints explicitly linked to the active role. */
|
|
1451
|
+
role?: ModelConstraintMap;
|
|
1452
|
+
/** Overriding constraints attached to the active session. */
|
|
1453
|
+
session?: ModelConstraintMap;
|
|
1454
|
+
/** The most explicit constraints captured at the last user turn. */
|
|
1455
|
+
turn?: ModelConstraintMap;
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1349
1458
|
|
|
1350
1459
|
/**
|
|
1351
|
-
*
|
|
1352
|
-
*
|
|
1353
|
-
* Two concerns live here together deliberately:
|
|
1354
|
-
* 1. Raw bytes — stored and retrieved by SHA-256.
|
|
1355
|
-
* 2. BlobRecord — the registry entry that tracks ref counts and remote IDs.
|
|
1460
|
+
* Output of PromptBuilder.build(). Input to LLMAdapter.resolve().
|
|
1356
1461
|
*
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1462
|
+
* Contains fully ranked and conflict-resolved preferences, context, and a
|
|
1463
|
+
* catalogue of blob references — but is NOT truncated and does NOT contain
|
|
1464
|
+
* resolved binary blob data. The adapter is responsible for:
|
|
1465
|
+
* - Deciding what fits within the model's context window.
|
|
1466
|
+
* - Resolving only the BlobRefs that survive truncation.
|
|
1467
|
+
* - Uploading inline blobs to the provider where required.
|
|
1359
1468
|
*/
|
|
1360
|
-
interface
|
|
1361
|
-
/**
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
/**
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
loadRecord(sha256: SHA256): Promise<BlobRecord | null>;
|
|
1379
|
-
/** Delete a BlobRecord. Called when a blob is fully evicted. */
|
|
1380
|
-
deleteRecord(sha256: SHA256): Promise<void>;
|
|
1381
|
-
/** Return all stored BlobRecords. Used for bundle export and GC sweeps. */
|
|
1382
|
-
listRecords(): Promise<BlobRecord[]>;
|
|
1383
|
-
/**
|
|
1384
|
-
* Export all bytes as an iterable of [sha256, Uint8Array] pairs.
|
|
1385
|
-
* Used for workspace export / migration.
|
|
1386
|
-
*/
|
|
1387
|
-
exportAllBytes(): Promise<Array<[SHA256, Uint8Array]>>;
|
|
1469
|
+
interface Prompt {
|
|
1470
|
+
/** Correlates this prompt to its session for logging and evaluation. */
|
|
1471
|
+
session: UUID;
|
|
1472
|
+
/** System-level instructions, context, and preferences. */
|
|
1473
|
+
system: {
|
|
1474
|
+
/** The active role's persona string. */
|
|
1475
|
+
persona: string;
|
|
1476
|
+
/** Global or session-level instructions. */
|
|
1477
|
+
instructions?: string;
|
|
1478
|
+
/** Conflict-resolved, relevance-ordered preferences. */
|
|
1479
|
+
preferences: Preference[];
|
|
1480
|
+
/** Ranked context entries (text and json kinds only). Blob context is
|
|
1481
|
+
* represented as referential blocks in the transcript instead. */
|
|
1482
|
+
context: Context[];
|
|
1483
|
+
};
|
|
1484
|
+
/** Active conversation chain, oldest to newest. May include synthetic turns.
|
|
1485
|
+
* Image and document blocks carry a BlobRef only; the adapter resolves them. */
|
|
1486
|
+
transcript: Turn[];
|
|
1388
1487
|
/**
|
|
1389
|
-
*
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1488
|
+
* Lightweight catalogue of every blob referenced anywhere in this prompt
|
|
1489
|
+
* (system.context or transcript), keyed by SHA256.
|
|
1490
|
+
*
|
|
1491
|
+
* Values are BlobRefs — metadata only, no binary data. The adapter uses
|
|
1492
|
+
* this catalogue to resolve or upload blobs for whichever turns and context
|
|
1493
|
+
* entries survive its truncation pass.
|
|
1393
1494
|
*/
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
constructor(db: WorkspaceDatabase);
|
|
1400
|
-
private turns;
|
|
1401
|
-
private sessions;
|
|
1402
|
-
/**
|
|
1403
|
-
* Compound filter for a specific (sessionId, id, version) tuple.
|
|
1404
|
-
* Uses only declared schema fields — never $id.
|
|
1405
|
-
*/
|
|
1406
|
-
private turnFilter;
|
|
1407
|
-
private loadRaw;
|
|
1408
|
-
getHead(sessionId: UUID): Promise<TurnRef | null>;
|
|
1409
|
-
setHead(sessionId: UUID, head: TurnRef | null): Promise<void>;
|
|
1410
|
-
save(sessionId: UUID, turn: Turn, head?: TurnRef | null): Promise<Turn>;
|
|
1411
|
-
append(sessionId: UUID, turn: Turn): Promise<Turn>;
|
|
1412
|
-
appendBatch(sessionId: UUID, turns: Turn[], finalHead: TurnRef | null): Promise<void>;
|
|
1413
|
-
replaceVersion(sessionId: UUID, newTurn: Turn): Promise<void>;
|
|
1414
|
-
branch(sessionId: UUID, newTurn: Turn): Promise<void>;
|
|
1415
|
-
loadAllTurns(sessionId: UUID): Promise<Turn[]>;
|
|
1416
|
-
loadTurnVersions(sessionId: UUID, turnId: UUID): Promise<Turn[]>;
|
|
1417
|
-
buildNodes(turns: Turn[], head: TurnRef | null, dirtyBuffer?: readonly Turn[]): Record<UUID, TurnNode>;
|
|
1418
|
-
buildNodeGraph(sessionId: UUID, dirtyBuffer?: readonly Turn[]): Promise<Record<UUID, TurnNode>>;
|
|
1419
|
-
getActiveChain(sessionId: UUID, dirtyBuffer?: readonly Turn[]): Promise<Turn[]>;
|
|
1420
|
-
buildActiveChain(sessionId: UUID): Promise<TurnNode[]>;
|
|
1421
|
-
getTurnSiblings(turnId: UUID, sessionId: UUID): Promise<TurnNode[]>;
|
|
1422
|
-
branchInfo(turnId: UUID, sessionId: UUID): Promise<BranchInfo>;
|
|
1423
|
-
deleteSubtree(sessionId: UUID, turnId: UUID, version: number, newHead: TurnRef | null): Promise<void>;
|
|
1424
|
-
copyTranscript(sourceSessionId: UUID, targetSessionId: UUID): Promise<void>;
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
interface BlobStoreConfig {
|
|
1495
|
+
blobs: Map<SHA256, BlobRef>;
|
|
1496
|
+
/** The role object — for inspection and adapter use. */
|
|
1497
|
+
role: Role;
|
|
1498
|
+
/** Model constraints to be merged by the adapter (turn > session > role). */
|
|
1499
|
+
constraints: ModelConstraintMap;
|
|
1428
1500
|
/**
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1501
|
+
* Non-fatal warnings generated during the build phase.
|
|
1502
|
+
* Adapters and callers should surface or log these.
|
|
1503
|
+
* Examples: summarizer failures, unresolvable blob refs.
|
|
1432
1504
|
*/
|
|
1433
|
-
|
|
1505
|
+
warnings: string[];
|
|
1434
1506
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
/**
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
/**
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1507
|
+
/**
|
|
1508
|
+
* Reflects the current state of the LLM adapter (limits, headroom, and readiness).
|
|
1509
|
+
*/
|
|
1510
|
+
interface AdapterStatus {
|
|
1511
|
+
/** Provider name (e.g., "google", "anthropic", "openai"). */
|
|
1512
|
+
provider: string;
|
|
1513
|
+
/** Model identifier (e.g., "claude-sonnet-4-6", "gemini-2.0-flash"). */
|
|
1514
|
+
model: string;
|
|
1515
|
+
/** Whether the adapter is currently able to accept requests. */
|
|
1516
|
+
ready: boolean;
|
|
1517
|
+
/** Token window limits and current usage. */
|
|
1518
|
+
window: {
|
|
1519
|
+
/** Total context window size in tokens. */
|
|
1520
|
+
size: number;
|
|
1521
|
+
/** Maximum output tokens for this model. */
|
|
1522
|
+
out: number;
|
|
1523
|
+
/** Tokens remaining — estimated or as reported by the provider. */
|
|
1524
|
+
free?: number;
|
|
1525
|
+
};
|
|
1526
|
+
/** Capability flags for this model. */
|
|
1527
|
+
feature: {
|
|
1528
|
+
/** Whether the model can process image inputs. */
|
|
1529
|
+
vision: boolean;
|
|
1530
|
+
/** Whether the model supports tool/function calling. */
|
|
1531
|
+
tools: boolean;
|
|
1532
|
+
/** Whether the model supports structured JSON output mode. */
|
|
1533
|
+
json: boolean;
|
|
1534
|
+
/** Whether the provider supports prompt caching. */
|
|
1535
|
+
cache: boolean;
|
|
1536
|
+
/** Whether the adapter supports streaming. */
|
|
1537
|
+
streaming: boolean;
|
|
1538
|
+
/** Whether the model supports extended thinking/reasoning tokens. */
|
|
1539
|
+
thinking: boolean;
|
|
1540
|
+
};
|
|
1541
|
+
/** Pricing tiers for this model. */
|
|
1542
|
+
pricing: Array<{
|
|
1543
|
+
unit: 'token' | 'call';
|
|
1544
|
+
/** Exponent: price is per 10^scale units. */
|
|
1545
|
+
scale: number;
|
|
1546
|
+
/** Price per unit in USD. */
|
|
1547
|
+
cost: {
|
|
1548
|
+
input: number;
|
|
1549
|
+
output: number;
|
|
1550
|
+
cache?: {
|
|
1551
|
+
read: number;
|
|
1552
|
+
write: number;
|
|
1553
|
+
};
|
|
1554
|
+
};
|
|
1472
1555
|
}>;
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1556
|
+
/** Current rate limit state. */
|
|
1557
|
+
rate: {
|
|
1558
|
+
/** Current saturation as a fraction of the most constrained limit (0.0 to 1.0). */
|
|
1559
|
+
load: number;
|
|
1560
|
+
/** Milliseconds until the next request is permitted. */
|
|
1561
|
+
timeout?: number;
|
|
1562
|
+
/** The hard limits enforced by the provider. */
|
|
1563
|
+
capacity: Array<{
|
|
1564
|
+
unit: 'token' | 'call';
|
|
1565
|
+
/** Maximum units allowed per period. */
|
|
1566
|
+
max: number;
|
|
1567
|
+
/** Period length in seconds. */
|
|
1568
|
+
period: number;
|
|
1569
|
+
}>;
|
|
1570
|
+
};
|
|
1571
|
+
/** Adapter-level notes, e.g. model deprecation warnings. */
|
|
1572
|
+
notes?: string[];
|
|
1481
1573
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
cache?: CacheConfig;
|
|
1491
|
-
}
|
|
1492
|
-
declare class ContentStore {
|
|
1493
|
-
private readonly db;
|
|
1494
|
-
readonly tree: TurnTree;
|
|
1495
|
-
readonly blobs: BlobStore;
|
|
1496
|
-
private readonly roleCache;
|
|
1497
|
-
private readonly preferenceCache;
|
|
1498
|
-
private readonly contextCache;
|
|
1499
|
-
private readonly taskCache;
|
|
1500
|
-
private bus;
|
|
1501
|
-
subscribe<TEventName extends keyof WorkspaceEvents>(event: TEventName, callback: (payload: WorkspaceEvents[TEventName]) => void): () => void;
|
|
1502
|
-
private constructor();
|
|
1503
|
-
static create(db: WorkspaceDatabase, blobStorage: BlobStorage, eventBus: EventBus<WorkspaceEvents>, config?: ContentStoreConfig): Promise<ContentStore>;
|
|
1504
|
-
private init;
|
|
1505
|
-
getTurnTree(): TurnTree;
|
|
1506
|
-
getRole(name: string): Promise<Result<Role, WorkspaceError>>;
|
|
1507
|
-
saveRole(role: Role): Promise<void>;
|
|
1508
|
-
deleteRole(name: string): Promise<void>;
|
|
1509
|
-
getPreference(id: UUID): Promise<Result<Preference, WorkspaceError>>;
|
|
1510
|
-
savePreference(preference: Preference): Promise<void>;
|
|
1511
|
-
deletePreference(id: UUID): Promise<void>;
|
|
1512
|
-
getContext(key: string): Promise<Result<Context, WorkspaceError>>;
|
|
1513
|
-
saveContext(context: Context): Promise<void>;
|
|
1514
|
-
deleteContext(key: string): Promise<void>;
|
|
1515
|
-
getContextByTopics(indexState: Index, topics: string[]): Promise<Context[]>;
|
|
1516
|
-
getTask(id: UUID): Promise<Result<Task, WorkspaceError>>;
|
|
1517
|
-
saveTask(task: Task): Promise<void>;
|
|
1518
|
-
deleteTask(id: UUID): Promise<void>;
|
|
1519
|
-
getTasksByTopics(indexState: Index, topics: string[]): Promise<Task[]>;
|
|
1520
|
-
saveSession(meta: SessionMeta): Promise<void>;
|
|
1521
|
-
updateSessionMeta(sessionId: UUID, patch: DeepPartial<SessionMeta>): Promise<void>;
|
|
1522
|
-
deleteSession(sessionId: UUID): Promise<void>;
|
|
1523
|
-
registerBlob(data: Uint8Array, mediaType: BlobMediaType, filename?: string): Promise<Result<BlobRef, WorkspaceError>>;
|
|
1524
|
-
retainBlob(sha256: SHA256): Promise<Result<void, WorkspaceError>>;
|
|
1525
|
-
releaseBlob(sha256: SHA256): Promise<Result<void, WorkspaceError>>;
|
|
1526
|
-
purgeBlob(sha256: SHA256): Promise<Result<void, WorkspaceError>>;
|
|
1527
|
-
recordBlobRemoteId(sha256: SHA256, providerId: string, fileId: string): Promise<Result<void, WorkspaceError>>;
|
|
1528
|
-
getBlobRecord(sha256: SHA256): BlobRecord | null;
|
|
1529
|
-
getAllBlobRecords(): Record<SHA256, BlobRecord>;
|
|
1530
|
-
getBlobResolver(): BlobStore['resolveRefs'];
|
|
1531
|
-
appendTurn(sessionId: UUID, turn: Turn): Promise<Result<Turn, WorkspaceError>>;
|
|
1532
|
-
saveTurn(sessionId: UUID, turn: Turn): Promise<Result<Turn, WorkspaceError>>;
|
|
1533
|
-
editTurn(sessionId: UUID, turnId: UUID, newBlocks: ContentBlock[], newVersion: number, roleSnapshot?: string): Promise<Result<void, WorkspaceError>>;
|
|
1534
|
-
branchTurn(sessionId: UUID, newTurn: Turn): Promise<Result<void, WorkspaceError>>;
|
|
1535
|
-
deleteTurnSubtree(sessionId: UUID, turnId: UUID, version: number, newHead: TurnRef | null): Promise<Result<void, WorkspaceError>>;
|
|
1536
|
-
copyTranscript(sourceSessionId: UUID, targetSessionId: UUID): Promise<void>;
|
|
1537
|
-
resolveSession(workspace: Workspace, sessionId: UUID, transcript?: Turn[]): Promise<Result<EffectiveSession, WorkspaceError>>;
|
|
1538
|
-
gc(): Promise<number>;
|
|
1574
|
+
/**
|
|
1575
|
+
* The result of `PreparedPrompt.execute()`. Contains the turn and derived effects.
|
|
1576
|
+
*/
|
|
1577
|
+
interface ExecuteResult {
|
|
1578
|
+
/** The newly generated assistant turn. */
|
|
1579
|
+
turn: Turn;
|
|
1580
|
+
/** Side-effect commands to dispatch against the workspace. */
|
|
1581
|
+
effects: BaseCommand[];
|
|
1539
1582
|
}
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1583
|
+
/**
|
|
1584
|
+
* The complete, final prompt exactly as the model will receive it.
|
|
1585
|
+
* Generic, provider-agnostic, fully inspectable, and executable.
|
|
1586
|
+
*/
|
|
1587
|
+
interface PreparedPrompt {
|
|
1588
|
+
/** The complete system instruction broken into labelled sections for inspection. */
|
|
1589
|
+
system: Array<{
|
|
1590
|
+
/** Origin label for this section (e.g., "persona", "context:project-brief"). */
|
|
1591
|
+
label: string;
|
|
1592
|
+
/** Text content exactly as it will be sent to the model. */
|
|
1593
|
+
content: string;
|
|
1594
|
+
/** Optional structured metadata for richer UI display. */
|
|
1595
|
+
metadata?: Record<string, any>;
|
|
1596
|
+
}>;
|
|
1597
|
+
/** Final transcript turns that will be sent after adapter-level truncation. */
|
|
1598
|
+
transcript: Turn[];
|
|
1599
|
+
/** Final context entries included after adapter-level truncation. */
|
|
1600
|
+
context: Context[];
|
|
1601
|
+
/** Final preferences included after adapter-level truncation. */
|
|
1602
|
+
preferences: Preference[];
|
|
1603
|
+
/** The resolved model constraints for this request. */
|
|
1604
|
+
constraints: ModelConstraint;
|
|
1605
|
+
/** Token accounting (estimated or exact). */
|
|
1606
|
+
tokens: {
|
|
1607
|
+
/** Breakdown by section. Keys are adapter-defined. */
|
|
1608
|
+
breakdown: Record<string, number>;
|
|
1609
|
+
/** Total input tokens — estimated or exact. */
|
|
1610
|
+
total: number;
|
|
1611
|
+
/** Whether total is an estimate or exact (provider-supplied). */
|
|
1612
|
+
source: 'estimated' | 'exact';
|
|
1613
|
+
/** Maximum output tokens configured for this request. */
|
|
1614
|
+
output?: number;
|
|
1615
|
+
/** Tokens remaining in the context window after this prompt. */
|
|
1616
|
+
remaining?: number;
|
|
1617
|
+
};
|
|
1556
1618
|
/**
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1619
|
+
* Sends this prompt to the model.
|
|
1620
|
+
* @returns The parsed assistant Turn plus any execution side-effects.
|
|
1559
1621
|
*/
|
|
1560
|
-
|
|
1622
|
+
execute(): Promise<Result<ExecuteResult, WorkspaceError>>;
|
|
1561
1623
|
/**
|
|
1562
|
-
*
|
|
1624
|
+
* Streaming variant of execute(). Yields partial turns as tokens arrive.
|
|
1625
|
+
* Present only if the adapter and model support streaming.
|
|
1563
1626
|
*/
|
|
1564
|
-
|
|
1565
|
-
reduce(workspace: Workspace, command: Command): Result<DeepPartial<Workspace>, WorkspaceError>;
|
|
1566
|
-
dispatch(workspace: Workspace, command: Command): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
1567
|
-
resolveSession(workspace: Workspace, sessionId: UUID, transcript?: Turn[]): Promise<Result<EffectiveSession, WorkspaceError>>;
|
|
1568
|
-
private handleContentSideEffects;
|
|
1569
|
-
}
|
|
1570
|
-
|
|
1571
|
-
interface ContextRelevanceConfig {
|
|
1572
|
-
recentMessageWindow?: number;
|
|
1573
|
-
minScore?: number;
|
|
1574
|
-
freshnessHalfLifeDays?: number;
|
|
1575
|
-
}
|
|
1576
|
-
interface ContextRankingInput {
|
|
1577
|
-
entries: Context[];
|
|
1578
|
-
recentMessages: string[];
|
|
1579
|
-
config: ContextRelevanceConfig;
|
|
1580
|
-
}
|
|
1581
|
-
interface ContextRetriever {
|
|
1582
|
-
rank(input: ContextRankingInput): Context[];
|
|
1583
|
-
}
|
|
1584
|
-
interface PlanningInput {
|
|
1585
|
-
systemInstructions?: string;
|
|
1586
|
-
persona: string;
|
|
1587
|
-
preferences: Preference[];
|
|
1588
|
-
context: Context[];
|
|
1589
|
-
task: Task | null;
|
|
1590
|
-
transcript: Turn[];
|
|
1591
|
-
budget?: TokenBudget;
|
|
1592
|
-
}
|
|
1593
|
-
interface PlanningOutput {
|
|
1594
|
-
preferences: Preference[];
|
|
1595
|
-
context: Context[];
|
|
1596
|
-
task: Task | null;
|
|
1597
|
-
transcript: Turn[];
|
|
1598
|
-
truncated: {
|
|
1599
|
-
preferences: number;
|
|
1600
|
-
interactions: number;
|
|
1601
|
-
context: number;
|
|
1602
|
-
};
|
|
1603
|
-
breakdown: Record<string, number>;
|
|
1604
|
-
totalUsed: number;
|
|
1605
|
-
lastRoleBeforeTruncation: string | null;
|
|
1606
|
-
}
|
|
1607
|
-
interface TokenPlanner {
|
|
1608
|
-
plan(input: PlanningInput): PlanningOutput;
|
|
1609
|
-
}
|
|
1610
|
-
interface AssemblyInput {
|
|
1611
|
-
session: EffectiveSession;
|
|
1612
|
-
plan: PlanningOutput;
|
|
1613
|
-
resolvedBlobs: Map<SHA256, ResolvedBlob>;
|
|
1614
|
-
summaryBlockText: string | null;
|
|
1615
|
-
warnings: string[];
|
|
1616
|
-
conflicts: PreferenceConflict[];
|
|
1617
|
-
budgetTotal: number;
|
|
1618
|
-
}
|
|
1619
|
-
declare class PromptAssembler {
|
|
1620
|
-
assemble(input: AssemblyInput): Prompt;
|
|
1621
|
-
private buildReferentialBlock;
|
|
1622
|
-
private resolveTurnBlocks;
|
|
1623
|
-
}
|
|
1624
|
-
declare class PromptBuilder {
|
|
1625
|
-
private retriever;
|
|
1626
|
-
private planner;
|
|
1627
|
-
private assembler;
|
|
1628
|
-
private summarizer?;
|
|
1629
|
-
private blobResolver;
|
|
1630
|
-
constructor(dependencies: {
|
|
1631
|
-
blobResolver: BlobStore['resolveRefs'];
|
|
1632
|
-
retriever?: ContextRetriever;
|
|
1633
|
-
planner?: TokenPlanner;
|
|
1634
|
-
assembler?: PromptAssembler;
|
|
1635
|
-
summarizer?: Summarizer;
|
|
1636
|
-
});
|
|
1637
|
-
build(session: EffectiveSession, options?: {
|
|
1638
|
-
tokenBudget?: TokenBudget;
|
|
1639
|
-
relevanceConfig?: ContextRelevanceConfig;
|
|
1640
|
-
providerId?: string;
|
|
1641
|
-
}): Promise<Prompt>;
|
|
1642
|
-
private collectUsedBlobRefs;
|
|
1643
|
-
private deduplicateBlobRefs;
|
|
1644
|
-
private extractRecentUserQueries;
|
|
1645
|
-
private resolvePreferenceConflicts;
|
|
1627
|
+
executeStream?(): AsyncIterable<Partial<Turn> | ExecuteResult>;
|
|
1646
1628
|
}
|
|
1647
1629
|
|
|
1648
1630
|
/**
|
|
1649
|
-
* A
|
|
1650
|
-
*
|
|
1631
|
+
* A simple LRU (Least Recently Used) cache implementation.
|
|
1632
|
+
* Used for caching frequently accessed entities in memory.
|
|
1651
1633
|
*/
|
|
1652
|
-
declare class
|
|
1653
|
-
private
|
|
1654
|
-
private
|
|
1655
|
-
constructor(
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
addSummary(text: string): TurnBuilder;
|
|
1662
|
-
addRoleTransition(previousRole: string | null, newRole: string): TurnBuilder;
|
|
1663
|
-
addThinking(thinking: string): TurnBuilder;
|
|
1634
|
+
declare class LRUCache<K, V> {
|
|
1635
|
+
private cache;
|
|
1636
|
+
private readonly maxSize;
|
|
1637
|
+
constructor(maxSize: number);
|
|
1638
|
+
/**
|
|
1639
|
+
* Retrieves an item from the cache.
|
|
1640
|
+
* Moves the item to the end of the cache (most recently used).
|
|
1641
|
+
*/
|
|
1642
|
+
get(key: K): V | undefined;
|
|
1664
1643
|
/**
|
|
1665
|
-
* Adds
|
|
1666
|
-
*
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
withTimestamp(timestamp: Timestamp): TurnBuilder;
|
|
1682
|
-
withParent(parent: TurnRef): TurnBuilder;
|
|
1683
|
-
withRoleSnapshot(roleSnapshot: string): TurnBuilder;
|
|
1684
|
-
build(): Turn;
|
|
1644
|
+
* Adds or updates an item in the cache.
|
|
1645
|
+
* If the cache exceeds maxSize, the least recently used item is removed.
|
|
1646
|
+
*/
|
|
1647
|
+
set(key: K, value: V): void;
|
|
1648
|
+
/**
|
|
1649
|
+
* Checks if a key exists in the cache without refreshing it.
|
|
1650
|
+
*/
|
|
1651
|
+
has(key: K): boolean;
|
|
1652
|
+
/**
|
|
1653
|
+
* Removes an item from the cache.
|
|
1654
|
+
*/
|
|
1655
|
+
delete(key: K): void;
|
|
1656
|
+
/**
|
|
1657
|
+
* Clears all items from the cache.
|
|
1658
|
+
*/
|
|
1659
|
+
clear(): void;
|
|
1685
1660
|
}
|
|
1686
1661
|
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1662
|
+
/**
|
|
1663
|
+
* Persistence contract for binary blob content and blob registry records.
|
|
1664
|
+
*
|
|
1665
|
+
* This is a hybrid interface because backends (like IndexedDB) need to
|
|
1666
|
+
* ensure atomicity between storing raw bytes and their associated metadata.
|
|
1667
|
+
*/
|
|
1668
|
+
interface BlobStorage {
|
|
1669
|
+
/** Store raw bytes for a blob. */
|
|
1670
|
+
storeBytes(sha256: SHA256, data: Uint8Array): Promise<void>;
|
|
1671
|
+
/** Load raw bytes. Returns null if not found locally. */
|
|
1672
|
+
loadBytes(sha256: SHA256): Promise<Uint8Array | null>;
|
|
1673
|
+
/** Returns true if bytes are stored locally for this SHA-256. */
|
|
1674
|
+
hasBytes(sha256: SHA256): Promise<boolean>;
|
|
1675
|
+
/** Delete raw bytes. */
|
|
1676
|
+
deleteBytes(sha256: SHA256): Promise<void>;
|
|
1677
|
+
/** Persist a BlobRecord (registry metadata). */
|
|
1678
|
+
saveRecord(record: BlobRecord): Promise<void>;
|
|
1679
|
+
/** Load a BlobRecord by SHA-256. */
|
|
1680
|
+
loadRecord(sha256: SHA256): Promise<BlobRecord | null>;
|
|
1681
|
+
/** Delete a BlobRecord. */
|
|
1682
|
+
deleteRecord(sha256: SHA256): Promise<void>;
|
|
1683
|
+
/** Return all stored BlobRecords. Used for GC and export. */
|
|
1684
|
+
listRecords(): Promise<BlobRecord[]>;
|
|
1685
|
+
/** Export all bytes for migration. */
|
|
1686
|
+
exportAllBytes(): Promise<Array<[SHA256, Uint8Array]>>;
|
|
1687
|
+
/** Optional atomic operation: store bytes and save record in one transaction. */
|
|
1688
|
+
registerBlob?(record: BlobRecord, data: Uint8Array): Promise<void>;
|
|
1690
1689
|
}
|
|
1691
1690
|
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1691
|
+
/**
|
|
1692
|
+
* Manages the registry of binary blobs.
|
|
1693
|
+
* Uses a hybrid BlobStorage for bytes and records, ensuring atomicity.
|
|
1694
|
+
*/
|
|
1695
|
+
declare class BlobStore {
|
|
1696
|
+
private readonly storage;
|
|
1697
|
+
private readonly cache;
|
|
1698
|
+
private readonly bus;
|
|
1699
|
+
constructor(storage: BlobStorage, cache: LRUCache<SHA256, BlobRecord>, bus: EventBus<WorkspaceEvents>);
|
|
1699
1700
|
/**
|
|
1700
|
-
*
|
|
1701
|
+
* Registers a new blob. Uses atomic registerBlob if available.
|
|
1701
1702
|
*/
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1703
|
+
register(data: Uint8Array, mediaType: BlobMediaType, filename?: string): Promise<Result<BlobRef, WorkspaceError>>;
|
|
1704
|
+
retain(sha256: SHA256): Promise<Result<void, WorkspaceError>>;
|
|
1705
|
+
release(sha256: SHA256): Promise<Result<void, WorkspaceError>>;
|
|
1706
|
+
purge(sha256: SHA256): Promise<Result<void, WorkspaceError>>;
|
|
1707
|
+
recordRemoteId(sha256: SHA256, providerId: string, fileId: string, timestamp?: string): Promise<Result<void, WorkspaceError>>;
|
|
1708
|
+
getRecord(sha256: SHA256): Promise<BlobRecord | null>;
|
|
1707
1709
|
/**
|
|
1708
|
-
*
|
|
1710
|
+
* All records — used to seed Index.blobs on init.
|
|
1709
1711
|
*/
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
topics(workspace: Workspace): string[];
|
|
1713
|
-
/** Returns the list of preference IDs overriding defaults for this session. */
|
|
1714
|
-
preferences(workspace: Workspace): UUID[];
|
|
1712
|
+
getAllRecords(): Promise<Record<SHA256, BlobRecord>>;
|
|
1713
|
+
private reference;
|
|
1715
1714
|
/**
|
|
1716
|
-
*
|
|
1715
|
+
* Resolves a BlobRef to a ResolvedBlob (inline or remote) or null.
|
|
1716
|
+
*
|
|
1717
|
+
* Resolution precedence:
|
|
1718
|
+
* 1. adapter provided and remote mapping exists for that adapter → remote blob (no local fallback)
|
|
1719
|
+
* 2. adapter provided but remote mapping missing → local bytes (if available)
|
|
1720
|
+
* 3. no adapter → local bytes (if available)
|
|
1721
|
+
* 4. otherwise → null (unresolvable)
|
|
1717
1722
|
*/
|
|
1718
|
-
|
|
1723
|
+
resolve(ref: BlobRef, adapter?: string): Promise<Result<ResolvedBlob | null, WorkspaceError>>;
|
|
1719
1724
|
/**
|
|
1720
|
-
*
|
|
1725
|
+
* Resolves multiple BlobRefs concurrently.
|
|
1726
|
+
* Uses the same optional adapter for all refs (or none).
|
|
1721
1727
|
*/
|
|
1722
|
-
|
|
1728
|
+
resolveMany(refs: BlobRef[], adapter?: string): Promise<Result<Map<SHA256, ResolvedBlob>, WorkspaceError>>;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
declare class ContextStore {
|
|
1732
|
+
private readonly collection;
|
|
1733
|
+
private readonly cache;
|
|
1734
|
+
constructor(collection: Collection<Context>, cache: LRUCache<string, Context>);
|
|
1735
|
+
get(key: string): Promise<Context | null>;
|
|
1736
|
+
add(context: Context): Promise<void>;
|
|
1737
|
+
list(): Promise<Context[]>;
|
|
1738
|
+
update(key: string, updates: Partial<Context>): Promise<Context | null>;
|
|
1739
|
+
delete(key: string): Promise<boolean>;
|
|
1723
1740
|
/**
|
|
1724
|
-
*
|
|
1741
|
+
* Retrieves all context items referenced by the given topics using the in-memory index.
|
|
1725
1742
|
*/
|
|
1726
|
-
|
|
1743
|
+
getByTopics(index: Index, topics: string[]): Promise<Context[]>;
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
declare class PreferenceStore {
|
|
1747
|
+
private readonly collection;
|
|
1748
|
+
private readonly cache;
|
|
1749
|
+
constructor(collection: Collection<Preference>, cache: LRUCache<UUID, Preference>);
|
|
1750
|
+
get(id: UUID): Promise<Preference | null>;
|
|
1751
|
+
add(preference: Preference): Promise<void>;
|
|
1752
|
+
update(id: UUID, updates: Partial<Preference>): Promise<Preference | null>;
|
|
1753
|
+
delete(id: UUID): Promise<boolean>;
|
|
1754
|
+
load(ids: UUID[]): Promise<Preference[]>;
|
|
1755
|
+
list(): Promise<Preference[]>;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* Atomic store for Role entities.
|
|
1760
|
+
* Receives a pre-resolved Collection and manages its own LRU cache.
|
|
1761
|
+
*/
|
|
1762
|
+
declare class RoleStore {
|
|
1763
|
+
private readonly collection;
|
|
1764
|
+
private readonly cache;
|
|
1765
|
+
constructor(collection: Collection<Role>, cache: LRUCache<string, Role>);
|
|
1727
1766
|
/**
|
|
1728
|
-
*
|
|
1767
|
+
* Retrieves a role by its unique name.
|
|
1729
1768
|
*/
|
|
1730
|
-
|
|
1769
|
+
get(name: string): Promise<Role | null>;
|
|
1731
1770
|
/**
|
|
1732
|
-
*
|
|
1733
|
-
* of TurnNode objects, following the head pointer and parent links.
|
|
1771
|
+
* Adds a new role to the collection.
|
|
1734
1772
|
*/
|
|
1735
|
-
|
|
1773
|
+
add(role: Role): Promise<void>;
|
|
1736
1774
|
/**
|
|
1737
|
-
*
|
|
1775
|
+
* Updates an existing role.
|
|
1738
1776
|
*/
|
|
1739
|
-
|
|
1777
|
+
update(name: string, updates: Partial<Role>): Promise<Role | null>;
|
|
1740
1778
|
/**
|
|
1741
|
-
*
|
|
1742
|
-
* current index, and navigation capabilities.
|
|
1779
|
+
* Deletes a role by name.
|
|
1743
1780
|
*/
|
|
1744
|
-
|
|
1781
|
+
delete(name: string): Promise<boolean>;
|
|
1745
1782
|
/**
|
|
1746
|
-
*
|
|
1783
|
+
* Lists all roles.
|
|
1747
1784
|
*/
|
|
1748
|
-
|
|
1785
|
+
list(): Promise<Role[]>;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
declare class SessionStore {
|
|
1789
|
+
private readonly collection;
|
|
1790
|
+
private readonly cache;
|
|
1791
|
+
constructor(collection: Collection<SessionMetadata>, cache: LRUCache<UUID, SessionMetadata>);
|
|
1792
|
+
get(id: UUID): Promise<SessionMetadata | null>;
|
|
1793
|
+
add(session: SessionMetadata): Promise<void>;
|
|
1794
|
+
update(id: UUID, updates: Partial<SessionMetadata>): Promise<SessionMetadata | null>;
|
|
1795
|
+
delete(id: UUID): Promise<boolean>;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
declare class TopicStore {
|
|
1799
|
+
private readonly collection;
|
|
1800
|
+
private readonly cache;
|
|
1801
|
+
constructor(collection: Collection<Topic>, cache: LRUCache<string, Topic>);
|
|
1802
|
+
get(name: string): Promise<Topic | null>;
|
|
1803
|
+
add(topic: Topic): Promise<void>;
|
|
1804
|
+
update(name: string, updates: Partial<Topic>): Promise<Topic | null>;
|
|
1805
|
+
delete(name: string): Promise<boolean>;
|
|
1806
|
+
getMany(names: string[]): Promise<Topic[]>;
|
|
1749
1807
|
/**
|
|
1750
|
-
*
|
|
1751
|
-
* @param workspace Current workspace state.
|
|
1752
|
-
* @param newLabel New human‑readable label.
|
|
1753
|
-
* @returns A patch to merge into the workspace state.
|
|
1808
|
+
* Checks if a topic is referenced by any entity in the workspace index.
|
|
1754
1809
|
*/
|
|
1755
|
-
|
|
1810
|
+
referencedBy(name: string, index: Index): boolean;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
declare class TurnStore {
|
|
1814
|
+
private readonly collection;
|
|
1815
|
+
private readonly cache;
|
|
1816
|
+
constructor(collection: Collection<Turn>, cache: LRUCache<string, Document<Turn>>);
|
|
1817
|
+
private key;
|
|
1818
|
+
private find;
|
|
1819
|
+
get(key: {
|
|
1820
|
+
id: UUID;
|
|
1821
|
+
session: UUID;
|
|
1822
|
+
version: number;
|
|
1823
|
+
}): Promise<Turn | null>;
|
|
1824
|
+
add(turn: Turn): Promise<void>;
|
|
1825
|
+
update(key: TurnKey, updates: Partial<Turn>): Promise<Turn | null>;
|
|
1826
|
+
listBySession(sessionId: UUID): Promise<Turn[]>;
|
|
1827
|
+
delete(key: TurnKey): Promise<boolean>;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
interface WorkspaceDatabase {
|
|
1756
1831
|
/**
|
|
1757
|
-
*
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1760
|
-
*
|
|
1832
|
+
* Open the database. Registers core schemas followed by any extension
|
|
1833
|
+
* schemas supplied by the caller (domain plugins).
|
|
1834
|
+
*
|
|
1835
|
+
* Idempotent — safe to call multiple times; subsequent calls are no-ops
|
|
1836
|
+
* if the database is already open.
|
|
1761
1837
|
*/
|
|
1762
|
-
|
|
1838
|
+
open(extensionSchemas?: SchemaDefinition[]): Promise<void>;
|
|
1763
1839
|
/**
|
|
1764
|
-
*
|
|
1765
|
-
*
|
|
1766
|
-
* @param topics Topics to add.
|
|
1767
|
-
* @returns A patch to merge into the workspace state.
|
|
1840
|
+
* Access a collection by schema name.
|
|
1841
|
+
* Throws if the schema has not been registered.
|
|
1768
1842
|
*/
|
|
1769
|
-
|
|
1843
|
+
collection<T>(schemaName: string): Promise<Collection<T>>;
|
|
1770
1844
|
/**
|
|
1771
|
-
*
|
|
1772
|
-
* @param workspace Current workspace state.
|
|
1773
|
-
* @param preferenceIds New array of preference IDs.
|
|
1774
|
-
* @returns A patch to merge into the workspace state.
|
|
1845
|
+
* Close the database connection.
|
|
1775
1846
|
*/
|
|
1776
|
-
|
|
1847
|
+
close(): void;
|
|
1848
|
+
/** get the underlying database connection. */
|
|
1849
|
+
database(): Database;
|
|
1850
|
+
}
|
|
1851
|
+
declare function createWorkspaceDatabase(db: Database): WorkspaceDatabase;
|
|
1852
|
+
/**
|
|
1853
|
+
* Collection name constants
|
|
1854
|
+
* Defines the names of the collections used in the Workspace database.
|
|
1855
|
+
* Use these instead of raw strings throughout the codebase so a typo is a
|
|
1856
|
+
* compile-time error rather than a silent runtime miss.
|
|
1857
|
+
*/
|
|
1858
|
+
declare const COLLECTIONS: {
|
|
1859
|
+
readonly ROLE: "role";
|
|
1860
|
+
readonly PREFERENCE: "preference";
|
|
1861
|
+
readonly CONTEXT: "context";
|
|
1862
|
+
readonly SESSION: "session";
|
|
1863
|
+
readonly TURN: "turn";
|
|
1864
|
+
readonly BLOB: "blob";
|
|
1865
|
+
readonly TOPIC: "topic";
|
|
1866
|
+
};
|
|
1867
|
+
type Collections = typeof COLLECTIONS[keyof typeof COLLECTIONS];
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* The full set of stores passed to every reducer and middleware call.
|
|
1871
|
+
* Applications extend this with their own stores (e.g., `interface AppContext extends WorkspaceContext`).
|
|
1872
|
+
*/
|
|
1873
|
+
interface WorkspaceContext {
|
|
1874
|
+
/** Store for managing system personas and roles. */
|
|
1875
|
+
roles: RoleStore;
|
|
1876
|
+
/** Store for managing global and session-level user preferences. */
|
|
1877
|
+
preferences: PreferenceStore;
|
|
1878
|
+
/** Store for managing RAG-retrievable context entries. */
|
|
1879
|
+
context: ContextStore;
|
|
1880
|
+
/** Store for managing active and archived conversation sessions. */
|
|
1881
|
+
sessions: SessionStore;
|
|
1882
|
+
/** Store for managing topic metadata and indexing. */
|
|
1883
|
+
topics: TopicStore;
|
|
1884
|
+
/** Store for managing blob binary data and references. */
|
|
1885
|
+
blobs: BlobStore;
|
|
1886
|
+
/** Store for managing conversation turns and history. */
|
|
1887
|
+
turns: TurnStore;
|
|
1888
|
+
/** Optional registry for managing available tools. */
|
|
1889
|
+
tools?: ToolRegistry;
|
|
1890
|
+
/** The current state of the workspace. */
|
|
1891
|
+
workspace: Workspace;
|
|
1892
|
+
/** The underlying database used by the workspace */
|
|
1893
|
+
db: WorkspaceDatabase;
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Ranks and filters context entries by relevance to the current conversation.
|
|
1897
|
+
* The default implementation uses token overlap and recency weighting, but
|
|
1898
|
+
* applications may substitute embedding-based or hybrid retrieval.
|
|
1899
|
+
*/
|
|
1900
|
+
interface ContextRetriever {
|
|
1901
|
+
/**
|
|
1902
|
+
* Ranks context entries by relevance to the current conversation.
|
|
1903
|
+
*
|
|
1904
|
+
* @param input - The payload containing entries to rank and context signals.
|
|
1905
|
+
* @param input.entries - All context entries available for this session.
|
|
1906
|
+
* @param input.recentMessages - Recent user message texts used as the query.
|
|
1907
|
+
* @param input.topics - Topics related to this session.
|
|
1908
|
+
* @param input.config - Optional retriever-specific configuration.
|
|
1909
|
+
* @returns Ranked context entries, most relevant first.
|
|
1910
|
+
*/
|
|
1911
|
+
rank(input: {
|
|
1912
|
+
entries: Context[];
|
|
1913
|
+
recentMessages: string[];
|
|
1914
|
+
topics: string[];
|
|
1915
|
+
config?: Record<string, any>;
|
|
1916
|
+
}): Context[];
|
|
1917
|
+
}
|
|
1918
|
+
/**
|
|
1919
|
+
* Configuration options for the PromptBuilder execution.
|
|
1920
|
+
*/
|
|
1921
|
+
interface PromptBuilderOptions {
|
|
1777
1922
|
/**
|
|
1778
|
-
*
|
|
1779
|
-
* @param workspace Current workspace state.
|
|
1780
|
-
* @param taskId ID of the task to link, or null to unlink.
|
|
1781
|
-
* @returns A patch to merge into the workspace state.
|
|
1923
|
+
* Forwarded to ContextRetriever.rank(). Use to tune retrieval behaviour per-call.
|
|
1782
1924
|
*/
|
|
1783
|
-
|
|
1925
|
+
retrieverConfig?: Record<string, any>;
|
|
1784
1926
|
/**
|
|
1785
|
-
*
|
|
1786
|
-
* @param workspace Current workspace state.
|
|
1787
|
-
* @returns A patch to merge into the workspace state.
|
|
1927
|
+
* When true, PromptBuilder will call the Summarizer to compress old turns before returning the Prompt.
|
|
1788
1928
|
*/
|
|
1789
|
-
|
|
1929
|
+
summarize?: boolean;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Transforms a SessionSnapshot into a standardized Prompt.
|
|
1933
|
+
* Extracts messages, ranks context, resolves blob references, and handles preference conflicts.
|
|
1934
|
+
* The produced Prompt contains the full resolved data, delegating token truncation to the LLMAdapter.
|
|
1935
|
+
*/
|
|
1936
|
+
interface PromptBuilder {
|
|
1790
1937
|
/**
|
|
1791
|
-
*
|
|
1792
|
-
*
|
|
1793
|
-
* @param
|
|
1794
|
-
* @param
|
|
1795
|
-
* @param
|
|
1796
|
-
* @
|
|
1797
|
-
* @returns A patch to merge into the workspace state.
|
|
1938
|
+
* Builds a standardized Prompt from a SessionSnapshot.
|
|
1939
|
+
*
|
|
1940
|
+
* @param snapshot - Raw session data assembled by Session.
|
|
1941
|
+
* @param ctx - WorkspaceContext for blob and context store access.
|
|
1942
|
+
* @param options - Optional retriever and summarizer configuration.
|
|
1943
|
+
* @returns A Result containing the fully resolved Prompt or a WorkspaceError.
|
|
1798
1944
|
*/
|
|
1799
|
-
|
|
1945
|
+
build(snapshot: SessionSnapshot, ctx: WorkspaceContext, options?: PromptBuilderOptions): Promise<Result<Prompt, WorkspaceError>>;
|
|
1946
|
+
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Bridge between a Prompt and a specific LLM provider's SDK.
|
|
1949
|
+
* Owns all model-specific decisions including truncation, token budgeting, formatting, and serialisation.
|
|
1950
|
+
*
|
|
1951
|
+
* @template TRequestParams - Extra params the caller passes to resolve() (e.g. model name, temperature).
|
|
1952
|
+
*/
|
|
1953
|
+
interface LLMAdapter<TRequestParams extends Record<string, any> = {}> {
|
|
1800
1954
|
/**
|
|
1801
|
-
*
|
|
1802
|
-
*
|
|
1803
|
-
* @returns
|
|
1955
|
+
* Returns the current state of the adapter. Callable at any time without a prompt.
|
|
1956
|
+
*
|
|
1957
|
+
* @returns The adapter's status, including context windows and rate limits.
|
|
1804
1958
|
*/
|
|
1805
|
-
|
|
1806
|
-
dispatch(workspace: Workspace, command: Command): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
1959
|
+
status(): Promise<AdapterStatus>;
|
|
1807
1960
|
/**
|
|
1808
|
-
*
|
|
1809
|
-
*
|
|
1810
|
-
* @param
|
|
1811
|
-
* @returns
|
|
1961
|
+
* Processes a Prompt into a PreparedPrompt — the complete, final representation of what the model will receive.
|
|
1962
|
+
*
|
|
1963
|
+
* @param params - The input prompt and any additional provider-specific parameters.
|
|
1964
|
+
* @returns The prepared, executable prompt bound to the provider's SDK.
|
|
1812
1965
|
*/
|
|
1813
|
-
|
|
1966
|
+
resolve(params: {
|
|
1967
|
+
prompt: Prompt;
|
|
1968
|
+
} & TRequestParams): Promise<PreparedPrompt>;
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Analyzes assistant turn output for workspace side effects.
|
|
1972
|
+
* Implementations scan blocks and emit Commands that the Session dispatches.
|
|
1973
|
+
*/
|
|
1974
|
+
interface TurnProcessor {
|
|
1814
1975
|
/**
|
|
1815
|
-
*
|
|
1976
|
+
* Scans an assistant turn for actionable blocks.
|
|
1977
|
+
*
|
|
1978
|
+
* @param turn - The turn containing blocks to process.
|
|
1979
|
+
* @param sessionId - The UUID of the session the turn belongs to.
|
|
1980
|
+
* @returns Commands to dispatch against the workspace.
|
|
1816
1981
|
*/
|
|
1817
|
-
|
|
1982
|
+
process(turn: {
|
|
1983
|
+
blocks: BaseContentBlock<string>[];
|
|
1984
|
+
}, sessionId?: UUID): BaseCommand[];
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Compresses old transcript turns to reclaim token budget.
|
|
1988
|
+
*/
|
|
1989
|
+
interface Summarizer {
|
|
1818
1990
|
/**
|
|
1819
|
-
*
|
|
1991
|
+
* Compresses older turns into a summary string.
|
|
1992
|
+
*
|
|
1993
|
+
* @param transcript - The full array of turns to evaluate.
|
|
1994
|
+
* @param tokenBudget - The maximum allowed tokens for the context window.
|
|
1995
|
+
* @returns The generated summary string and the uncompressed remaining turns.
|
|
1820
1996
|
*/
|
|
1821
|
-
|
|
1997
|
+
summarize(transcript: Turn[], tokenBudget: number): Promise<{
|
|
1998
|
+
summary: string;
|
|
1999
|
+
remaining: Turn[];
|
|
2000
|
+
}>;
|
|
2001
|
+
}
|
|
2002
|
+
/**
|
|
2003
|
+
* Manages the registration, tracking, and execution of AI tools.
|
|
2004
|
+
*/
|
|
2005
|
+
interface ToolRegistry {
|
|
1822
2006
|
/**
|
|
1823
|
-
*
|
|
1824
|
-
* @param
|
|
1825
|
-
* @param name Unique identifier for the role (e.g., "software-architect").
|
|
1826
|
-
* @param label Human-readable display label.
|
|
1827
|
-
* @param persona The system prompt / instructions for this role.
|
|
1828
|
-
* @param description Optional description.
|
|
1829
|
-
* @param preferenceIds Optional array of preference IDs to associate.
|
|
1830
|
-
* @returns A patch to merge into the workspace state.
|
|
2007
|
+
* Subscribes to changes in the tool registry.
|
|
2008
|
+
* @param callback - Triggered with the updated list of tool summaries.
|
|
1831
2009
|
*/
|
|
1832
|
-
|
|
2010
|
+
onRegistryChanged(callback: (tools: ToolSummary[]) => void): void;
|
|
1833
2011
|
/**
|
|
1834
|
-
*
|
|
1835
|
-
* @
|
|
1836
|
-
* @param name Name of the role to update (must exist).
|
|
1837
|
-
* @param updates Partial updates (label, description, persona, preferences).
|
|
1838
|
-
* @returns A patch to merge into the workspace state.
|
|
2012
|
+
* Retrieves all currently registered tools.
|
|
2013
|
+
* @returns An array of ToolSummary definitions.
|
|
1839
2014
|
*/
|
|
1840
|
-
|
|
2015
|
+
list(): ToolSummary[];
|
|
1841
2016
|
/**
|
|
1842
|
-
*
|
|
1843
|
-
* @param
|
|
1844
|
-
* @
|
|
1845
|
-
* @returns A patch to merge into the workspace state.
|
|
2017
|
+
* Executes a specific tool call request.
|
|
2018
|
+
* @param call - The tool call payload with arguments.
|
|
2019
|
+
* @returns A Result containing the tool's output.
|
|
1846
2020
|
*/
|
|
1847
|
-
|
|
2021
|
+
execute<T = any>(call: ToolCall): Promise<Result<T>>;
|
|
2022
|
+
}
|
|
2023
|
+
/**
|
|
2024
|
+
* Secures commands and tool executions by authenticating requests.
|
|
2025
|
+
*/
|
|
2026
|
+
interface PermissionGuard {
|
|
1848
2027
|
/**
|
|
1849
|
-
*
|
|
1850
|
-
*
|
|
1851
|
-
* @
|
|
1852
|
-
* @param turn The Turn object (can be built with startTurn()).
|
|
1853
|
-
* @returns A patch to merge into the workspace state.
|
|
2028
|
+
* Authenticates a request before execution.
|
|
2029
|
+
* @param request - The authorization request containing a command or tool payload.
|
|
2030
|
+
* @returns A Result with the authenticated payload or undefined if unhandled.
|
|
1854
2031
|
*/
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
2032
|
+
authenticate(request: AuthRequest): Promise<Result<null>>;
|
|
2033
|
+
}
|
|
2034
|
+
type BlobResolver = (ref: BlobRef, provider?: string) => Promise<Result<ResolvedBlob | null, WorkspaceError>>;
|
|
2035
|
+
|
|
2036
|
+
declare class WorkspaceManager {
|
|
2037
|
+
private registry;
|
|
2038
|
+
private middlewares;
|
|
2039
|
+
private serializer;
|
|
2040
|
+
private bus;
|
|
2041
|
+
private _getWorkspace;
|
|
2042
|
+
private updateWorkspace;
|
|
2043
|
+
private guard?;
|
|
2044
|
+
private readonly _ctx;
|
|
2045
|
+
constructor(params: {
|
|
2046
|
+
ctx: Omit<WorkspaceContext, "workspace">;
|
|
2047
|
+
getWorkspace: () => Workspace;
|
|
2048
|
+
updateWorkspace: (workspace: DeepPartial<Workspace>) => Promise<void>;
|
|
2049
|
+
guard?: PermissionGuard;
|
|
2050
|
+
bus: EventBus<WorkspaceEvents>;
|
|
2051
|
+
});
|
|
1860
2052
|
/**
|
|
1861
|
-
*
|
|
1862
|
-
* @param
|
|
1863
|
-
* @
|
|
1864
|
-
* @param newBlocks New content blocks for the turn.
|
|
1865
|
-
* @param roleSnapshot Optional role name to record with this version.
|
|
1866
|
-
* @returns A patch to merge into the workspace state.
|
|
2053
|
+
* Registers a reducer for a specific command type.
|
|
2054
|
+
* @param reducer The reducer function to handle the command.
|
|
2055
|
+
* @returns The WorkspaceManager instance for chaining.
|
|
1867
2056
|
*/
|
|
1868
|
-
|
|
2057
|
+
register(type: string, reducer: WorkspaceReducer): this;
|
|
1869
2058
|
/**
|
|
1870
|
-
*
|
|
1871
|
-
* @param
|
|
1872
|
-
* @
|
|
1873
|
-
* @returns A patch to merge into the workspace state.
|
|
2059
|
+
* Registers a middleware function.
|
|
2060
|
+
* @param middleware The middleware function to apply.
|
|
2061
|
+
* @returns The WorkspaceManager instance for chaining.
|
|
1874
2062
|
*/
|
|
1875
|
-
|
|
2063
|
+
use(middleware: WorkspaceMiddleware): this;
|
|
1876
2064
|
/**
|
|
1877
|
-
*
|
|
1878
|
-
* @
|
|
1879
|
-
* @param turnId ID of the turn to delete.
|
|
1880
|
-
* @param version Version number of the turn to delete.
|
|
1881
|
-
* @param newHead Optional new head pointer after deletion.
|
|
1882
|
-
* @returns A patch to merge into the workspace state.
|
|
2065
|
+
* Retrieves the current state of the workspace.
|
|
2066
|
+
* @returns The current Workspace state.
|
|
1883
2067
|
*/
|
|
1884
|
-
|
|
2068
|
+
workspace(): Workspace;
|
|
1885
2069
|
/**
|
|
1886
|
-
*
|
|
1887
|
-
*
|
|
1888
|
-
* @param
|
|
1889
|
-
* @
|
|
1890
|
-
* @returns A patch to merge into the workspace state.
|
|
2070
|
+
* Dispatches a command to modify the workspace state.
|
|
2071
|
+
* It ensures commands are processed sequentially and applies middleware.
|
|
2072
|
+
* @param command The command to dispatch.
|
|
2073
|
+
* @returns A promise resolving to the DeepPartial<Workspace> representing the applied patch.
|
|
1891
2074
|
*/
|
|
1892
|
-
|
|
2075
|
+
dispatch(command: BaseCommand): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
1893
2076
|
/**
|
|
1894
|
-
*
|
|
1895
|
-
*
|
|
1896
|
-
* @param
|
|
1897
|
-
* @
|
|
1898
|
-
* @returns A patch to merge into the workspace state.
|
|
2077
|
+
* Subscribes to workspace events.
|
|
2078
|
+
* @param event The event name to subscribe to.
|
|
2079
|
+
* @param listener The callback function to execute when the event is emitted.
|
|
2080
|
+
* @returns unsubscribe
|
|
1899
2081
|
*/
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
2082
|
+
subscribe<K extends keyof WorkspaceEvents>(event: K, listener: (payload: WorkspaceEvents[K]) => void): () => void;
|
|
2083
|
+
ctx(): {
|
|
2084
|
+
context: ContextStore;
|
|
2085
|
+
roles: RoleStore;
|
|
2086
|
+
preferences: PreferenceStore;
|
|
2087
|
+
sessions: SessionStore;
|
|
2088
|
+
topics: TopicStore;
|
|
2089
|
+
blobs: BlobStore;
|
|
2090
|
+
turns: TurnStore;
|
|
2091
|
+
tools?: ToolRegistry | undefined;
|
|
2092
|
+
db: WorkspaceDatabase;
|
|
2093
|
+
workspace: Workspace<Record<string, any>>;
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
declare class WorkspaceApi {
|
|
2098
|
+
private readonly manager;
|
|
2099
|
+
constructor(manager: WorkspaceManager);
|
|
2100
|
+
private get workspace();
|
|
2101
|
+
roles(): Promise<Role[]>;
|
|
2102
|
+
role(name: string): Promise<Role | null>;
|
|
2103
|
+
createRole(name: string, label: string, persona: string, description?: string, preferenceIds?: UUID[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2104
|
+
updateRole(name: string, updates: Partial<Pick<Role, "label" | "description" | "persona" | "preferences">>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2105
|
+
deleteRole(name: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2106
|
+
addPreference(content: string, topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2107
|
+
preferences(): Promise<Preference[]>;
|
|
2108
|
+
addContext(key: string, content: ContextContent, topics: string[], metadata?: Record<string, any>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2109
|
+
context(): Promise<Context[]>;
|
|
2110
|
+
registerBlob(data: Uint8Array, mediaType: BlobMediaType, filename?: string): Promise<Result<{
|
|
1912
2111
|
sha256: SHA256;
|
|
1913
2112
|
ref: BlobRef;
|
|
1914
2113
|
}, WorkspaceError>>;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
declare class Session {
|
|
2117
|
+
private readonly _id;
|
|
2118
|
+
private readonly manager;
|
|
2119
|
+
private readonly processor;
|
|
2120
|
+
private readonly turnRepository;
|
|
2121
|
+
/** Global workspace operations available under session.workspace */
|
|
2122
|
+
readonly workspace: WorkspaceApi;
|
|
2123
|
+
private _role;
|
|
2124
|
+
private _preferences;
|
|
2125
|
+
private tree;
|
|
2126
|
+
private constructor();
|
|
2127
|
+
static create(sessionId: UUID, manager: WorkspaceManager, processor: TurnProcessor): Promise<Session>;
|
|
2128
|
+
private _setRole;
|
|
2129
|
+
private _setPreference;
|
|
2130
|
+
id(): UUID;
|
|
2131
|
+
private ws;
|
|
2132
|
+
meta(): SessionMetadata | undefined;
|
|
2133
|
+
label(): string | undefined;
|
|
2134
|
+
role(): Role | undefined;
|
|
2135
|
+
topics(): string[];
|
|
2136
|
+
preferences(): Preference[];
|
|
2137
|
+
head(): TurnRef | null;
|
|
2138
|
+
turns(): TurnNode[];
|
|
2139
|
+
siblings(turnId: UUID): Promise<TurnNode[]>;
|
|
2140
|
+
branchInfo(turnId: UUID): Promise<BranchInfo>;
|
|
2141
|
+
getTurn(turnId: UUID): Promise<TurnNode | undefined>;
|
|
2142
|
+
rename(newLabel: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2143
|
+
setTopics(topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2144
|
+
addTopics(topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2145
|
+
setPreferences(preferenceIds: UUID[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2146
|
+
fork(newSessionId: UUID, label: string, role?: string, topics?: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2147
|
+
dispatch(command: BaseCommand): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2148
|
+
switchRole(newRole: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2149
|
+
addTurn(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2150
|
+
recordUserTurn(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2151
|
+
recordAssistantTurn(turn: Turn, recordDenial?: boolean): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2152
|
+
private buildDenialTurn;
|
|
2153
|
+
private describeCommand;
|
|
2154
|
+
editTurn(turnId: UUID, newBlocks: ContentBlock[], roleSnapshot?: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2155
|
+
branch(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2156
|
+
deleteTurn(turnId: UUID, version: number, newHead: TurnRef | null): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2157
|
+
switchVersionLeft(turnId: UUID): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2158
|
+
switchVersionRight(turnId: UUID): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
|
|
2159
|
+
private switchVersion;
|
|
1915
2160
|
/**
|
|
1916
|
-
*
|
|
1917
|
-
*
|
|
1918
|
-
*
|
|
1919
|
-
*
|
|
2161
|
+
* Assembles a SessionSnapshot from in-memory state for PromptBuilder.
|
|
2162
|
+
*
|
|
2163
|
+
* This is the handoff point between Session (state management) and
|
|
2164
|
+
* PromptBuilder (prompt preparation). Session's responsibility ends here.
|
|
2165
|
+
*
|
|
2166
|
+
* The only async step is loading context entries by topic from the store.
|
|
2167
|
+
* Role and preferences are already in memory from open().
|
|
2168
|
+
*
|
|
2169
|
+
* Returns undefined if the session no longer exists in the workspace index.
|
|
1920
2170
|
*/
|
|
1921
|
-
|
|
2171
|
+
snapshot(): Promise<SessionSnapshot | undefined>;
|
|
2172
|
+
private refreshTurnTree;
|
|
1922
2173
|
private findSubtreeTip;
|
|
1923
2174
|
}
|
|
1924
2175
|
|
|
1925
|
-
interface SessionManagerConfig {
|
|
1926
|
-
}
|
|
1927
|
-
interface OpenResult {
|
|
1928
|
-
session: Session;
|
|
1929
|
-
patch: DeepPartial<Workspace>;
|
|
1930
|
-
}
|
|
1931
2176
|
declare class SessionManager {
|
|
1932
|
-
private readonly
|
|
1933
|
-
private readonly
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
* Retrieves the metadata for a specific session without hydrating a Session object.
|
|
1941
|
-
*/
|
|
1942
|
-
meta(workspace: Workspace, sessionId: UUID): SessionMeta | undefined;
|
|
1943
|
-
/**
|
|
1944
|
-
* Creates a new session and returns a hydrated Session instance.
|
|
1945
|
-
* This method dispatches a 'session:create' command which is validated by the
|
|
1946
|
-
* reducer (checking for unique IDs and valid roles) and persisted
|
|
1947
|
-
* to the content store.
|
|
1948
|
-
*/
|
|
1949
|
-
create(workspace: Workspace, params: {
|
|
2177
|
+
private readonly manager;
|
|
2178
|
+
private readonly processor;
|
|
2179
|
+
private openOnce;
|
|
2180
|
+
constructor(manager: WorkspaceManager, processor: TurnProcessor);
|
|
2181
|
+
open(sessionId: UUID): Promise<Session>;
|
|
2182
|
+
close(sessionId: UUID): void;
|
|
2183
|
+
delete(sessionId: UUID): Promise<Result<undefined, WorkspaceError>>;
|
|
2184
|
+
create(params: {
|
|
1950
2185
|
label: string;
|
|
1951
|
-
role
|
|
1952
|
-
topics
|
|
2186
|
+
role: string;
|
|
2187
|
+
topics: string[];
|
|
1953
2188
|
preferences?: UUID[];
|
|
1954
|
-
}): Promise<
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
close(_: Session): Promise<void>;
|
|
2189
|
+
}): Promise<Session>;
|
|
2190
|
+
list(): SessionMetadata[];
|
|
2191
|
+
metadata(sessionId: UUID): SessionMetadata | undefined;
|
|
1958
2192
|
}
|
|
1959
2193
|
|
|
1960
2194
|
/**
|
|
1961
|
-
*
|
|
1962
|
-
*
|
|
1963
|
-
* access to IndexedDB.
|
|
2195
|
+
* A fluent builder for creating Turn objects.
|
|
2196
|
+
* This class helps construct a Turn object by adding various content blocks.
|
|
1964
2197
|
*/
|
|
1965
|
-
declare class
|
|
1966
|
-
private readonly
|
|
1967
|
-
private
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
2198
|
+
declare class TurnBuilder {
|
|
2199
|
+
private readonly _actor;
|
|
2200
|
+
private _turn;
|
|
2201
|
+
constructor(_actor: SystemActor, session: string, initialTurn?: Turn);
|
|
2202
|
+
addText(text: string): TurnBuilder;
|
|
2203
|
+
addImage(ref?: BlobRef, altText?: string): TurnBuilder;
|
|
2204
|
+
addDocument(ref?: BlobRef, title?: string): TurnBuilder;
|
|
2205
|
+
addToolUse(name: string, input: Record<string, unknown>): TurnBuilder;
|
|
2206
|
+
addToolResult(useId: UUID, content: string | Record<string, unknown>, isError?: boolean): TurnBuilder;
|
|
2207
|
+
addSummary(text: string): TurnBuilder;
|
|
2208
|
+
addRoleTransition(previousRole: string | undefined, newRole: string): TurnBuilder;
|
|
2209
|
+
addThinking(thinking: string): TurnBuilder;
|
|
2210
|
+
addBlock(block: ContentBlock): TurnBuilder;
|
|
2211
|
+
deleteBlock(blockId: UUID): TurnBuilder;
|
|
2212
|
+
editTextBlock(blockId: UUID, newText: string): TurnBuilder;
|
|
2213
|
+
withId(id: UUID): TurnBuilder;
|
|
2214
|
+
withVersion(version: number): TurnBuilder;
|
|
2215
|
+
withTimestamp(timestamp: Timestamp): TurnBuilder;
|
|
2216
|
+
withParent(parent: TurnRef): TurnBuilder;
|
|
2217
|
+
withRoleSnapshot(roleSnapshot: string): TurnBuilder;
|
|
2218
|
+
build(): Turn;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
declare class TurnRepository {
|
|
2222
|
+
private readonly turnStore;
|
|
2223
|
+
private readonly sessionStore;
|
|
2224
|
+
constructor(turnStore: TurnStore, sessionStore: SessionStore);
|
|
2225
|
+
loadAllTurns(sessionId: UUID): Promise<Turn[]>;
|
|
2226
|
+
loadHead(sessionId: UUID): Promise<TurnRef | null>;
|
|
1983
2227
|
}
|
|
1984
2228
|
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2229
|
+
declare class TurnTree {
|
|
2230
|
+
private readonly nodes;
|
|
2231
|
+
private readonly _head;
|
|
2232
|
+
private constructor();
|
|
2233
|
+
static build(sessionId: UUID, repository: TurnRepository): Promise<TurnTree>;
|
|
2234
|
+
head(): TurnRef | null;
|
|
2235
|
+
chain(): TurnNode[];
|
|
2236
|
+
getTurnSiblings(turnId: UUID): TurnNode[];
|
|
2237
|
+
branchInfo(turnId: UUID): BranchInfo;
|
|
2238
|
+
graph(): Readonly<Record<UUID, TurnNode>>;
|
|
1988
2239
|
}
|
|
2240
|
+
|
|
2241
|
+
declare function success<T>(value: T): Result<T, never>;
|
|
2242
|
+
declare function ok<T>(value: T): Result<T, never>;
|
|
2243
|
+
declare function error<E extends WorkspaceError>(err: E): Result<never, E>;
|
|
2244
|
+
declare function omitNullUndefined<T extends Record<string, any>>(obj: T): Partial<T>;
|
|
2245
|
+
declare function del<T>(): T;
|
|
2246
|
+
declare const merge: <T extends object>(original: T, changes: DeepPartial<T> | symbol) => T;
|
|
2247
|
+
declare function computeSHA256(data: Uint8Array): Promise<SHA256>;
|
|
1989
2248
|
/**
|
|
1990
|
-
*
|
|
1991
|
-
*
|
|
1992
|
-
*
|
|
1993
|
-
* no base64 encoding at rest. This is important for large files.
|
|
1994
|
-
*
|
|
1995
|
-
* Transaction discipline: never await inside an active transaction.
|
|
1996
|
-
* All multi-step operations chain synchronous IDB request handlers
|
|
1997
|
-
* inside a single Promise.
|
|
2249
|
+
* Converts a Uint8Array to a Base64 string.
|
|
2250
|
+
* Uses native Buffer in Node.js/Deno, and falls back to a chunked btoa()
|
|
2251
|
+
* implementation for Browsers and Edge environments to avoid stack overflows.
|
|
1998
2252
|
*/
|
|
1999
|
-
declare
|
|
2000
|
-
private readonly dbName;
|
|
2001
|
-
private db;
|
|
2002
|
-
constructor(config?: IndexedDBBlobConfig);
|
|
2003
|
-
open(): Promise<void>;
|
|
2004
|
-
private createSchema;
|
|
2005
|
-
close(): void;
|
|
2006
|
-
deleteDatabase(): Promise<void>;
|
|
2007
|
-
private getDB;
|
|
2008
|
-
private readTx;
|
|
2009
|
-
private writeTx;
|
|
2010
|
-
storeBytes(sha256: SHA256, data: Uint8Array): Promise<void>;
|
|
2011
|
-
loadBytes(sha256: SHA256): Promise<Uint8Array | null>;
|
|
2012
|
-
hasBytes(sha256: SHA256): Promise<boolean>;
|
|
2013
|
-
deleteBytes(sha256: SHA256): Promise<void>;
|
|
2014
|
-
saveRecord(record: BlobRecord): Promise<void>;
|
|
2015
|
-
loadRecord(sha256: SHA256): Promise<BlobRecord | null>;
|
|
2016
|
-
deleteRecord(sha256: SHA256): Promise<void>;
|
|
2017
|
-
listRecords(): Promise<BlobRecord[]>;
|
|
2018
|
-
exportAllBytes(): Promise<Array<[SHA256, Uint8Array]>>;
|
|
2019
|
-
/**
|
|
2020
|
-
* Atomically stores bytes and saves a record together.
|
|
2021
|
-
* Preferred over calling storeBytes + saveRecord separately when both
|
|
2022
|
-
* are new — avoids a window where bytes exist without a record.
|
|
2023
|
-
*/
|
|
2024
|
-
registerBlob(record: BlobRecord, data: Uint8Array): Promise<void>;
|
|
2025
|
-
}
|
|
2253
|
+
declare function bufferToBase64(buffer: Uint8Array): string;
|
|
2026
2254
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
request: {
|
|
2040
|
-
model: string;
|
|
2041
|
-
contents: _google_genai.Content[];
|
|
2042
|
-
config: {
|
|
2043
|
-
systemInstruction: _google_genai.Content;
|
|
2044
|
-
thinkingConfig: {
|
|
2045
|
-
includeThoughts: boolean;
|
|
2046
|
-
};
|
|
2047
|
-
responseMimeType: string;
|
|
2048
|
-
responseSchema: _google_genai.Schema;
|
|
2049
|
-
};
|
|
2050
|
-
};
|
|
2051
|
-
}>;
|
|
2052
|
-
/**
|
|
2053
|
-
* Parses the GenerateContentResponse into a Turn (assistant turn).
|
|
2054
|
-
*/
|
|
2055
|
-
parse({ response }: {
|
|
2056
|
-
response: GenerateContentResponse;
|
|
2057
|
-
}): Result<Turn, WorkspaceError>;
|
|
2255
|
+
interface CreateWorkspaceParams {
|
|
2256
|
+
db: Database;
|
|
2257
|
+
blobStorage: BlobStorage;
|
|
2258
|
+
eventBus?: EventBus<WorkspaceEvents>;
|
|
2259
|
+
getWorkspace: () => Workspace;
|
|
2260
|
+
setWorkspace: (workspace: DeepPartial<Workspace>) => Promise<void>;
|
|
2261
|
+
processor: TurnProcessor;
|
|
2262
|
+
guard?: PermissionGuard;
|
|
2263
|
+
toolRegistry?: ToolRegistry;
|
|
2264
|
+
extensionSchemas?: SchemaDefinition[];
|
|
2265
|
+
extensionReducers?: Record<string, WorkspaceReducer<any>>;
|
|
2266
|
+
extensionMiddleware?: WorkspaceMiddleware[];
|
|
2058
2267
|
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Boot factory for the Workspace library.
|
|
2270
|
+
* Resolves all collections and initializes entity stores.
|
|
2271
|
+
*/
|
|
2272
|
+
declare function createWorkspace(params: CreateWorkspaceParams): Promise<{
|
|
2273
|
+
manager: WorkspaceManager;
|
|
2274
|
+
sessions: SessionManager;
|
|
2275
|
+
ctx: Omit<WorkspaceContext, "workspace">;
|
|
2276
|
+
}>;
|
|
2059
2277
|
|
|
2060
|
-
export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type
|
|
2278
|
+
export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTopic, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BaseContentBlock, type BlobCommand, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobResolver, type BranchInfo, type BranchTurn, COLLECTIONS, type Collections, type Command, type ContentBlock, type Context, type ContextContent, type ContextRetriever, type ContextSummary, type CreateSession, type CreateWorkspace, type CreateWorkspaceParams, type DeepPartial, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTopic, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type ForkSession, type ImageBlock, type ImageMediaType, type Index, type InvalidCommandError, type LLMAdapter, LRUCache, type MergeTopics, type ModelConstraint, type ModelConstraintMap, type ModelName, type NotFoundError, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceSummary, type Project, type PromptBuilder, type PromptBuilderOptions, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type ResolvedBlob, type ResolvedSession, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, Session, SessionManager, type SessionMetadata, type SessionSnapshot, type Settings, type Summarizer, type SummaryBlock, type SwitchSessionRole, type SystemActor, type TextBlock, type ThinkingBlock, type Timestamp, type ToolCall, type ToolCallCommand, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type Topic, type TopicIndex, type Turn, TurnBuilder, type TurnKey, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTopic, type UpdateTurn, type Workspace, type WorkspaceBundle, type WorkspaceContext, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, WorkspaceManager, type WorkspaceMiddleware, type WorkspaceReducer, bufferToBase64, computeSHA256, createWorkspace, createWorkspaceDatabase, del, error, merge, ok, omitNullUndefined, success };
|