@asaidimu/utils-workspace 7.0.1 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/index.d.mts +433 -230
- package/index.d.ts +433 -230
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +2 -3
package/index.d.mts
CHANGED
|
@@ -3,6 +3,132 @@ import { IndexDefinition, SchemaDefinition, SchemaChange, DataTransform, Predica
|
|
|
3
3
|
import { QueryFilter, PaginationOptions } from '@asaidimu/query';
|
|
4
4
|
import { GoogleGenAI, GenerateContentParameters } from '@google/genai';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Severity levels for structured issues and errors.
|
|
8
|
+
*/
|
|
9
|
+
type Severity = "error" | "warning" | "info";
|
|
10
|
+
/**
|
|
11
|
+
* Represents a detailed validation or operational problem.
|
|
12
|
+
* Designed to be machine-readable while remaining human-friendly.
|
|
13
|
+
*/
|
|
14
|
+
interface Issue {
|
|
15
|
+
/** Machine-readable identifier (e.g., "REQUIRED_FIELD_MISSING"). */
|
|
16
|
+
readonly code: string;
|
|
17
|
+
/** Human-readable description of the problem. */
|
|
18
|
+
readonly message: string;
|
|
19
|
+
/** Field path in a document or state (e.g., "users.0.email"). */
|
|
20
|
+
readonly path?: string;
|
|
21
|
+
/** Optional array index when the issue relates to a specific element. */
|
|
22
|
+
readonly index?: number;
|
|
23
|
+
/** Seriousness of the issue. Defaults to "error". */
|
|
24
|
+
readonly severity?: Severity;
|
|
25
|
+
/** Optional detailed explanation, can be multi-line. */
|
|
26
|
+
readonly description?: string;
|
|
27
|
+
/** Nested issues that caused this one. */
|
|
28
|
+
readonly cause?: readonly Issue[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Standardized error code format: CATEGORY-XXX[-SUFFIX]
|
|
32
|
+
* Examples:
|
|
33
|
+
* - VAL-001 (Validation: required field missing)
|
|
34
|
+
* - DB-002-NF (Database: not found)
|
|
35
|
+
* - AUTH-003-DENIED (Auth: permission denied)
|
|
36
|
+
*/
|
|
37
|
+
interface ErrorCodeMetadata {
|
|
38
|
+
/** The formal error code (e.g., "VAL-001") */
|
|
39
|
+
readonly code: string;
|
|
40
|
+
/** Human-readable name for the error type */
|
|
41
|
+
readonly name: string;
|
|
42
|
+
/** Detailed description of when this error occurs */
|
|
43
|
+
readonly description: string;
|
|
44
|
+
/** Suggested action for handling or resolving the error */
|
|
45
|
+
readonly action?: string;
|
|
46
|
+
/** HTTP status code mapping (if applicable) */
|
|
47
|
+
readonly httpStatus?: number;
|
|
48
|
+
/** Category of the error */
|
|
49
|
+
readonly category: ErrorCategory;
|
|
50
|
+
/** Whether this error should be logged as warning vs error */
|
|
51
|
+
readonly logLevel?: "debug" | "info" | "warn" | "error";
|
|
52
|
+
}
|
|
53
|
+
type ErrorCategory = "validation" | "database" | "auth" | "business" | "system" | "network" | "concurrency" | "custom";
|
|
54
|
+
/**
|
|
55
|
+
* SystemError is the primary error type for all operational and validation errors.
|
|
56
|
+
* Supports both predefined and custom error codes with full metadata.
|
|
57
|
+
*/
|
|
58
|
+
declare class SystemError extends Error {
|
|
59
|
+
readonly code: string;
|
|
60
|
+
readonly codeMetadata: ErrorCodeMetadata;
|
|
61
|
+
readonly severity: Severity;
|
|
62
|
+
readonly path?: string;
|
|
63
|
+
readonly operation?: string;
|
|
64
|
+
readonly issues: readonly Issue[];
|
|
65
|
+
readonly cause?: unknown;
|
|
66
|
+
constructor(params: {
|
|
67
|
+
code: string;
|
|
68
|
+
message?: string;
|
|
69
|
+
severity?: Severity;
|
|
70
|
+
path?: string;
|
|
71
|
+
operation?: string;
|
|
72
|
+
issues?: readonly Issue[];
|
|
73
|
+
cause?: unknown;
|
|
74
|
+
metadata?: Partial<Omit<ErrorCodeMetadata, "code">>;
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Returns a new SystemError with the specified path.
|
|
78
|
+
*/
|
|
79
|
+
withPath(path: string): SystemError;
|
|
80
|
+
/**
|
|
81
|
+
* Returns a new SystemError with the specified operation name.
|
|
82
|
+
*/
|
|
83
|
+
withOperation(operation: string): SystemError;
|
|
84
|
+
/**
|
|
85
|
+
* Returns a new SystemError with the specified issue appended.
|
|
86
|
+
*/
|
|
87
|
+
withIssue(issue: Issue): SystemError;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a new SystemError with multiple issues appended.
|
|
90
|
+
*/
|
|
91
|
+
withIssues(issues: readonly Issue[]): SystemError;
|
|
92
|
+
/**
|
|
93
|
+
* Returns a new SystemError wrapping the specified cause.
|
|
94
|
+
*/
|
|
95
|
+
withCause(cause: unknown): SystemError;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the HTTP status code for this error (if applicable).
|
|
98
|
+
*/
|
|
99
|
+
getHttpStatus(): number | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Formats the error for logging with structured metadata.
|
|
102
|
+
*/
|
|
103
|
+
toLogEntry(): Record<string, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* Produces a human-readable representation suitable for logging.
|
|
106
|
+
*/
|
|
107
|
+
toString(): string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Factory for creating a new SystemError with automatic metadata.
|
|
111
|
+
*/
|
|
112
|
+
declare function createError(code: string, message?: string): SystemError;
|
|
113
|
+
/**
|
|
114
|
+
* A functional wrapper for operations that can fail.
|
|
115
|
+
* Encourages explicit error handling over try/catch blocks.
|
|
116
|
+
*/
|
|
117
|
+
type Result$1<T, E = SystemError> = {
|
|
118
|
+
readonly ok: true;
|
|
119
|
+
readonly value: T;
|
|
120
|
+
} | {
|
|
121
|
+
readonly ok: false;
|
|
122
|
+
readonly error: E;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Type-safe helpers for creating Results.
|
|
126
|
+
*/
|
|
127
|
+
declare const Result$1: {
|
|
128
|
+
ok: <T>(value: T) => Result$1<T, never>;
|
|
129
|
+
fail: <E>(error: E) => Result$1<never, E>;
|
|
130
|
+
};
|
|
131
|
+
|
|
6
132
|
type SerializerResult<T> = {
|
|
7
133
|
value: T | null;
|
|
8
134
|
error?: unknown;
|
|
@@ -66,7 +192,7 @@ declare class Serializer<T = void> {
|
|
|
66
192
|
/**
|
|
67
193
|
* Utility type for representing partial updates to the state, allowing deep nesting.
|
|
68
194
|
* It makes all properties optional and applies the same transformation recursively
|
|
69
|
-
* to nested objects
|
|
195
|
+
* to nested objects, allowing for selective updates while
|
|
70
196
|
* preserving the original structure. It also includes the original type T and
|
|
71
197
|
* undefined as possibilities for the top level and nested values.
|
|
72
198
|
*/
|
|
@@ -122,97 +248,19 @@ declare const Branded: {
|
|
|
122
248
|
};
|
|
123
249
|
|
|
124
250
|
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
type Severity = "error" | "warning" | "info";
|
|
128
|
-
/**
|
|
129
|
-
* Represents a detailed validation or operational problem.
|
|
130
|
-
* Designed to be machine-readable while remaining human-friendly.
|
|
131
|
-
*/
|
|
132
|
-
interface Issue {
|
|
133
|
-
/** Machine-readable identifier (e.g., "REQUIRED_FIELD_MISSING"). */
|
|
134
|
-
readonly code: string;
|
|
135
|
-
/** Human-readable description of the problem. */
|
|
136
|
-
readonly message: string;
|
|
137
|
-
/** Field path in a document or state (e.g., "users.0.email"). */
|
|
138
|
-
readonly path?: string;
|
|
139
|
-
/** Optional array index when the issue relates to a specific element. */
|
|
140
|
-
readonly index?: number;
|
|
141
|
-
/** Seriousness of the issue. Defaults to "error". */
|
|
142
|
-
readonly severity?: Severity;
|
|
143
|
-
/** Optional detailed explanation, can be multi-line. */
|
|
144
|
-
readonly description?: string;
|
|
145
|
-
/** Nested issues that caused this one. */
|
|
146
|
-
readonly cause?: readonly Issue[];
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* SystemError is the primary error type for all operational and validation errors.
|
|
150
|
-
* It provides rich contextual information and supports immutable composition
|
|
151
|
-
* through a fluent API.
|
|
152
|
-
*/
|
|
153
|
-
declare class SystemError extends Error {
|
|
154
|
-
readonly code: string;
|
|
155
|
-
readonly severity: Severity;
|
|
156
|
-
readonly path?: string;
|
|
157
|
-
readonly operation?: string;
|
|
158
|
-
readonly issues: readonly Issue[];
|
|
159
|
-
readonly cause?: unknown;
|
|
160
|
-
constructor(params: {
|
|
161
|
-
code: string;
|
|
162
|
-
message: string;
|
|
163
|
-
severity?: Severity;
|
|
164
|
-
path?: string;
|
|
165
|
-
operation?: string;
|
|
166
|
-
issues?: readonly Issue[];
|
|
167
|
-
cause?: unknown;
|
|
168
|
-
});
|
|
169
|
-
/**
|
|
170
|
-
* Returns a new SystemError with the specified path.
|
|
171
|
-
* Path typically indicates the location in a data structure where the error occurred.
|
|
172
|
-
*/
|
|
173
|
-
withPath(path: string): SystemError;
|
|
174
|
-
/**
|
|
175
|
-
* Returns a new SystemError with the specified operation name.
|
|
176
|
-
* Describes what was being attempted when the error occurred.
|
|
177
|
-
*/
|
|
178
|
-
withOperation(operation: string): SystemError;
|
|
179
|
-
/**
|
|
180
|
-
* Returns a new SystemError with the specified issue appended.
|
|
181
|
-
*/
|
|
182
|
-
withIssue(issue: Issue): SystemError;
|
|
183
|
-
/**
|
|
184
|
-
* Returns a new SystemError with multiple issues appended.
|
|
185
|
-
*/
|
|
186
|
-
withIssues(issues: readonly Issue[]): SystemError;
|
|
187
|
-
/**
|
|
188
|
-
* Returns a new SystemError wrapping the specified cause.
|
|
189
|
-
*/
|
|
190
|
-
withCause(cause: unknown): SystemError;
|
|
191
|
-
/**
|
|
192
|
-
* Produces a human-readable representation suitable for logging.
|
|
193
|
-
*/
|
|
194
|
-
toString(): string;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Factory for creating a new SystemError.
|
|
198
|
-
*/
|
|
199
|
-
declare function createError(code: string, message: string): SystemError;
|
|
200
|
-
/**
|
|
201
|
-
* Predefined common error codes.
|
|
251
|
+
* Predefined common error codes, mapped to the standard ErrorCodes registry.
|
|
202
252
|
*/
|
|
203
253
|
declare const CommonErrors: {
|
|
204
|
-
readonly NOT_FOUND: "
|
|
205
|
-
readonly DUPLICATE_KEY: "
|
|
206
|
-
readonly INVALID_COMMAND: "
|
|
207
|
-
readonly PERMISSION_DENIED: "
|
|
208
|
-
readonly BACKEND_ERROR: "
|
|
209
|
-
readonly INTERNAL_ERROR: "
|
|
210
|
-
readonly VALIDATION_FAILED: "
|
|
211
|
-
readonly CONCURRENCY_ERROR: "
|
|
212
|
-
|
|
213
|
-
readonly
|
|
214
|
-
/** Returned when an operation was explicitly aborted or the system is shutting down. */
|
|
215
|
-
readonly OPERATION_ABORTED: "OPERATION_ABORTED";
|
|
254
|
+
readonly NOT_FOUND: "DB-001-NF";
|
|
255
|
+
readonly DUPLICATE_KEY: "DB-002-DUP";
|
|
256
|
+
readonly INVALID_COMMAND: "BUS-001";
|
|
257
|
+
readonly PERMISSION_DENIED: "AUTH-001-DENIED";
|
|
258
|
+
readonly BACKEND_ERROR: "SYS-002";
|
|
259
|
+
readonly INTERNAL_ERROR: "SYS-001";
|
|
260
|
+
readonly VALIDATION_FAILED: "VAL-001";
|
|
261
|
+
readonly CONCURRENCY_ERROR: "CON-001";
|
|
262
|
+
readonly RESOURCE_LOCKED: "DB-003-LOCK";
|
|
263
|
+
readonly OPERATION_ABORTED: "BUS-002-ABORT";
|
|
216
264
|
};
|
|
217
265
|
|
|
218
266
|
/**
|
|
@@ -335,14 +383,25 @@ interface Event<T extends string = string, P = any, M extends Metadata = {}> {
|
|
|
335
383
|
readonly meta: M;
|
|
336
384
|
}
|
|
337
385
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
386
|
+
* Represents the structured outcome of an Action.
|
|
387
|
+
* Allows an action to specify both a state patch and a computational result.
|
|
388
|
+
*/
|
|
389
|
+
interface ActionOutcome<S extends Record<string, any>, I extends Index, R = any> {
|
|
390
|
+
/** The speculative state patch to be applied to the system. */
|
|
391
|
+
patch?: DeepPartial<State<S, I>>;
|
|
392
|
+
/** The computational return value for the caller. */
|
|
393
|
+
result?: R;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* A pure-ish function that calculates a state patch and/or a result based on a command.
|
|
397
|
+
* Actions are the primary mechanism for logic execution in the CQRS loop.
|
|
340
398
|
*
|
|
341
399
|
* @template S - The Domain State type.
|
|
342
400
|
* @template I - The Index type.
|
|
343
401
|
* @template C - The specific Command type being handled.
|
|
402
|
+
* @template R - The result type.
|
|
344
403
|
*/
|
|
345
|
-
type Action<S extends Record<string, any>, I extends Index, C extends Command<any, any, any
|
|
404
|
+
type Action<S extends Record<string, any>, I extends Index, C extends Command<any, any, any>, R = any> = (state: State<S, I>, command: C) => Result<DeepPartial<State<S, I>> | ActionOutcome<S, I, R>, SystemError> | Promise<Result<DeepPartial<State<S, I>> | ActionOutcome<S, I, R>, SystemError>>;
|
|
346
405
|
type ActionEntry<S extends Record<string, any>, I extends Index, C extends Command<any, any, any>> = {
|
|
347
406
|
action: Action<S, I, C>;
|
|
348
407
|
namespace: string;
|
|
@@ -362,8 +421,8 @@ type Middleware<S extends Record<string, any>, I extends Index> = (api: {
|
|
|
362
421
|
/** Returns the current consistent snapshot of the state. */
|
|
363
422
|
state: () => State<S, I>;
|
|
364
423
|
/** Re-dispatches a command through the full pipeline. */
|
|
365
|
-
dispatch: <C extends Command<any, any, any
|
|
366
|
-
}) => (next: (command: Command<any, any, any>) => Promise<Result<
|
|
424
|
+
dispatch: <C extends Command<any, any, any>, R = any>(command: C) => Promise<Result<R, SystemError>>;
|
|
425
|
+
}) => (next: (command: Command<any, any, any>) => Promise<Result<ActionOutcome<S, I>, SystemError>>) => (command: Command<any, any, any>) => Promise<Result<ActionOutcome<S, I>, SystemError>>;
|
|
367
426
|
/**
|
|
368
427
|
* A collection of named registries that collectively know how to produce
|
|
369
428
|
* a materialized index projection.
|
|
@@ -1047,13 +1106,13 @@ interface CommandRegistry<S extends Record<string, any>, I extends Index = {}> {
|
|
|
1047
1106
|
interface CommandCoordinator<T extends string> {
|
|
1048
1107
|
/**
|
|
1049
1108
|
* Dispatches a single command through the auth → middleware → reducer
|
|
1050
|
-
*
|
|
1109
|
+
* pipeline and commits the resulting state patch.
|
|
1051
1110
|
*
|
|
1052
1111
|
* @param ctx - The verified identity and permissions of the actor.
|
|
1053
1112
|
* @param command - The command carrying intent and payload.
|
|
1054
|
-
* @returns - A Result
|
|
1113
|
+
* @returns - A Result containing the computational return value or a SystemError.
|
|
1055
1114
|
*/
|
|
1056
|
-
dispatch<C extends Command<any, any, any
|
|
1115
|
+
dispatch<C extends Command<any, any, any>, R = any>(ctx: AuthContext<T>, command: C): Promise<Result<R, SystemError>>;
|
|
1057
1116
|
/**
|
|
1058
1117
|
* Executes a sequence of steps as an atomic saga.
|
|
1059
1118
|
*
|
|
@@ -1102,7 +1161,10 @@ interface IRegistry<T> {
|
|
|
1102
1161
|
clear(): void;
|
|
1103
1162
|
/** Creates a deep clone of the registry. */
|
|
1104
1163
|
clone(): IRegistry<T>;
|
|
1164
|
+
/** Returns a record of entrys keyed by a string key */
|
|
1105
1165
|
entries(): Record<string, T>;
|
|
1166
|
+
/** Returns number of items in registry */
|
|
1167
|
+
count(): number;
|
|
1106
1168
|
}
|
|
1107
1169
|
/** The read/write contract for a registry. */
|
|
1108
1170
|
type IRegistryReader<T> = Pick<IRegistry<T>, "get" | "list" | "entries" | "has">;
|
|
@@ -1254,12 +1316,13 @@ declare class Registry<T> implements IRegistry<T> {
|
|
|
1254
1316
|
* Creates a deep clone of the registry.
|
|
1255
1317
|
* @returns A new Registry instance with deeply cloned items
|
|
1256
1318
|
*/
|
|
1257
|
-
clone():
|
|
1319
|
+
clone(): IRegistry<T>;
|
|
1258
1320
|
/**
|
|
1259
1321
|
* Returns all registry entries as a plain object.
|
|
1260
1322
|
* @returns Object with all registry key-value pairs
|
|
1261
1323
|
*/
|
|
1262
1324
|
entries(): Record<string, T>;
|
|
1325
|
+
count(): number;
|
|
1263
1326
|
}
|
|
1264
1327
|
|
|
1265
1328
|
/**
|
|
@@ -1288,7 +1351,7 @@ declare class ExecutionEngine<T extends string, S extends Record<string, any>, I
|
|
|
1288
1351
|
get authorizer(): Authorizer<T, S, I>;
|
|
1289
1352
|
register<C extends Command<any, any, any>>(namespace: string, type: C["type"], reducer: Action<S, I, C>): Result<void, SystemError>;
|
|
1290
1353
|
use(middleware: Middleware<S, I>): void;
|
|
1291
|
-
dispatch<C extends Command<any, any, any
|
|
1354
|
+
dispatch<C extends Command<any, any, any>, R = any>(ctx: AuthContext<T>, command: C): Promise<Result<R, SystemError>>;
|
|
1292
1355
|
transact(ctx: AuthContext<T>, steps: TransactionStep[]): Promise<Result<void, SystemError>>;
|
|
1293
1356
|
/**
|
|
1294
1357
|
* Core dispatch pipeline: auth → middleware chain → reducer → state.
|
|
@@ -1338,7 +1401,7 @@ declare class ExecutionEngine<T extends string, S extends Record<string, any>, I
|
|
|
1338
1401
|
declare class KernelCoordinator<T extends string, S extends Record<string, any>, I extends Index = {}> implements CommandCoordinator<T>, AuthorizationProvider<T, S, I> {
|
|
1339
1402
|
private readonly engine;
|
|
1340
1403
|
private readonly serializer;
|
|
1341
|
-
constructor(engine: ExecutionEngine<T, S, I>, serializer: Serializer<Result<
|
|
1404
|
+
constructor(engine: ExecutionEngine<T, S, I>, serializer: Serializer<Result<any, SystemError>>);
|
|
1342
1405
|
get authorizer(): Authorizer<T, S, I>;
|
|
1343
1406
|
/**
|
|
1344
1407
|
* Dispatches a single command through the serialized execution pipeline.
|
|
@@ -1349,7 +1412,7 @@ declare class KernelCoordinator<T extends string, S extends Record<string, any>,
|
|
|
1349
1412
|
* @param ctx - The verified identity and permissions of the actor.
|
|
1350
1413
|
* @param command - The command carrying intent and payload.
|
|
1351
1414
|
*/
|
|
1352
|
-
dispatch<C extends Command<any, any, any
|
|
1415
|
+
dispatch<C extends Command<any, any, any>, R = any>(ctx: AuthContext<T>, command: C): Promise<Result<R, SystemError>>;
|
|
1353
1416
|
/**
|
|
1354
1417
|
* Executes a multi-step transaction through the serialized pipeline.
|
|
1355
1418
|
*
|
|
@@ -1547,6 +1610,133 @@ declare function createAnonymousContext(): AuthContext<"anonymous">;
|
|
|
1547
1610
|
*/
|
|
1548
1611
|
declare function createUserContext(userId: UUID, scopes?: string[], metadata?: UUID): AuthContext<"user">;
|
|
1549
1612
|
|
|
1613
|
+
/**
|
|
1614
|
+
* A ultra-compact, runtime-scoped tracking registry.
|
|
1615
|
+
* Translates multi-segment semantic components or dynamic types
|
|
1616
|
+
* into 1-token safe base36 structural short-hashes.
|
|
1617
|
+
*/
|
|
1618
|
+
declare class ShortKeyRegistry<T extends string = string> {
|
|
1619
|
+
private readonly counters;
|
|
1620
|
+
private readonly runtimeSalt;
|
|
1621
|
+
constructor();
|
|
1622
|
+
/**
|
|
1623
|
+
* Generates a compact, non-colliding short token key.
|
|
1624
|
+
* Compresses the target scope tracking increment into a deterministic signature.
|
|
1625
|
+
*/
|
|
1626
|
+
next(scope: T): string;
|
|
1627
|
+
/**
|
|
1628
|
+
* Reset local execution indices for context window boundary updates.
|
|
1629
|
+
*/
|
|
1630
|
+
clear(): void;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* Utility class for common blob and binary data operations.
|
|
1635
|
+
* Optimized for environments supporting Node.js, Browsers, and Edge runtimes.
|
|
1636
|
+
*/
|
|
1637
|
+
declare class BlobUtilities {
|
|
1638
|
+
/**
|
|
1639
|
+
* Computes the SHA-256 hash of a given Uint8Array.
|
|
1640
|
+
* @param data The Uint8Array to hash.
|
|
1641
|
+
* @returns A Promise that resolves to the SHA-256 hash as a hexadecimal string.
|
|
1642
|
+
*/
|
|
1643
|
+
static computeSHA256(data: Uint8Array): Promise<string>;
|
|
1644
|
+
/**
|
|
1645
|
+
* Computes a CRC32 checksum of a given Uint8Array for fast data integrity verification.
|
|
1646
|
+
* @param data The Uint8Array to checksum.
|
|
1647
|
+
* @returns The CRC32 checksum as a hexadecimal string.
|
|
1648
|
+
*/
|
|
1649
|
+
static computeCRC32(data: Uint8Array): string;
|
|
1650
|
+
/**
|
|
1651
|
+
* Converts a Uint8Array to a Base64 string.
|
|
1652
|
+
* Uses native Buffer in Node.js/Deno, and falls back to a chunked btoa()
|
|
1653
|
+
* implementation for Browsers and Edge environments to avoid stack overflows.
|
|
1654
|
+
* @param buffer The Uint8Array to convert.
|
|
1655
|
+
* @returns The Base64 encoded string.
|
|
1656
|
+
*/
|
|
1657
|
+
static bufferToBase64(buffer: Uint8Array): string;
|
|
1658
|
+
/**
|
|
1659
|
+
* Converts a Base64 string back to a Uint8Array.
|
|
1660
|
+
* @param base64 The Base64 encoded string.
|
|
1661
|
+
* @returns The decoded Uint8Array.
|
|
1662
|
+
*/
|
|
1663
|
+
static base64ToBuffer(base64: string): Uint8Array;
|
|
1664
|
+
/**
|
|
1665
|
+
* Generates a short, deterministic hash of a string.
|
|
1666
|
+
* Returns a uniformly distributed, fixed-length base36 string.
|
|
1667
|
+
* @param s The string to hash.
|
|
1668
|
+
* @param length The desired length of base36 hash. Defaults to 4.
|
|
1669
|
+
* @returns The short base36 hash string.
|
|
1670
|
+
*/
|
|
1671
|
+
static shortHash(s: string, length?: number): string;
|
|
1672
|
+
/**
|
|
1673
|
+
* Converts a Blob to a Uint8Array.
|
|
1674
|
+
* @param blob The Blob to convert.
|
|
1675
|
+
* @returns A Promise that resolves to the Uint8Array.
|
|
1676
|
+
*/
|
|
1677
|
+
static blobToUint8Array(blob: Blob): Promise<Uint8Array>;
|
|
1678
|
+
/**
|
|
1679
|
+
* Creates a Blob from a Uint8Array.
|
|
1680
|
+
* @param data The Uint8Array to create the blob from.
|
|
1681
|
+
* @param mimeType The MIME type of the blob (e.g., 'application/octet-stream').
|
|
1682
|
+
* @returns The resulting Blob.
|
|
1683
|
+
*/
|
|
1684
|
+
static uint8ArrayToBlob(data: Uint8Array, mimeType?: string): Blob;
|
|
1685
|
+
/**
|
|
1686
|
+
* Encodes a string into a Uint8Array using UTF-8.
|
|
1687
|
+
* @param text The string to encode.
|
|
1688
|
+
* @returns The encoded Uint8Array.
|
|
1689
|
+
*/
|
|
1690
|
+
static textToUint8Array(text: string): Uint8Array;
|
|
1691
|
+
/**
|
|
1692
|
+
* Decodes a Uint8Array into a string using UTF-8.
|
|
1693
|
+
* @param data The Uint8Array to decode.
|
|
1694
|
+
* @returns The decoded string.
|
|
1695
|
+
*/
|
|
1696
|
+
static uint8ArrayToText(data: Uint8Array): string;
|
|
1697
|
+
/**
|
|
1698
|
+
* Converts a Uint8Array to a URL-safe Base64 string.
|
|
1699
|
+
* Replaces '+' with '-', '/' with '_', and removes trailing '=' padding.
|
|
1700
|
+
* @param buffer The Uint8Array to convert.
|
|
1701
|
+
* @returns The URL-safe Base64 encoded string.
|
|
1702
|
+
*/
|
|
1703
|
+
static bufferToUrlSafeBase64(buffer: Uint8Array): string;
|
|
1704
|
+
/**
|
|
1705
|
+
* Converts a URL-safe Base64 string back to a Uint8Array.
|
|
1706
|
+
* Restores padding and replaces characters back to standard Base64.
|
|
1707
|
+
* @param base64 The URL-safe Base64 encoded string.
|
|
1708
|
+
* @returns The decoded Uint8Array.
|
|
1709
|
+
*/
|
|
1710
|
+
static urlSafeBase64ToBuffer(base64: string): Uint8Array;
|
|
1711
|
+
/**
|
|
1712
|
+
* Slices a Blob into chunks of a specified size.
|
|
1713
|
+
* This is useful for uploading large files in parts or feeding data into LLM context windows.
|
|
1714
|
+
* @param blob The Blob to slice.
|
|
1715
|
+
* @param chunkSize The size of each chunk in bytes.
|
|
1716
|
+
* @param options An optional configuration for the chunking process.
|
|
1717
|
+
* @returns An async generator that yields Uint8Arrays of the binary data.
|
|
1718
|
+
*/
|
|
1719
|
+
static chunkBlob(blob: Blob, chunkSize?: number): AsyncGenerator<Uint8Array>;
|
|
1720
|
+
/**
|
|
1721
|
+
* Wraps a Uint8Array with metadata providing business context for ERP systems.
|
|
1722
|
+
* The metadata is stored as a JSON string at the start of the Blob, followed by the length of the length of the metadata length.
|
|
1723
|
+
* @param buffer The binary data to wrap.
|
|
1724
|
+
* @param metadata own a single object containing metadata keys/values.
|
|
1725
|
+
* @returns A Uint8Array containing metadata and binary data.
|
|
1726
|
+
*/
|
|
1727
|
+
static wrapBlobMetadata(buffer: Uint8Array, metadata: Record<string, any>): Uint8Array;
|
|
1728
|
+
/**
|
|
1729
|
+
* Unwraps a Uint8Array containing metadata wrapped by wrapBlobMetadata.
|
|
1730
|
+
* @param wrappedBuffer own a Uint8Array containing metadata and metadata length.
|
|
1731
|
+
* @returns An object containing the original binary data and the metadata object.
|
|
1732
|
+
* @throws Error if the buffer is too small or contains invalid metadata length.
|
|
1733
|
+
*/
|
|
1734
|
+
static unwrapBlobMetadata(wrappedBuffer: Uint8Array): {
|
|
1735
|
+
data: Uint8Array;
|
|
1736
|
+
metadata: Record<string, any>;
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1550
1740
|
type DatabaseConfig = {
|
|
1551
1741
|
factory: StoreFactory;
|
|
1552
1742
|
database: string;
|
|
@@ -1815,7 +2005,7 @@ declare class ModuleAggregator<T extends string, S extends Record<string, any>,
|
|
|
1815
2005
|
}
|
|
1816
2006
|
|
|
1817
2007
|
type ContentCoreState = any;
|
|
1818
|
-
interface Blob extends Identifiable, Timestamped, Versioned {
|
|
2008
|
+
interface Blob$1 extends Identifiable, Timestamped, Versioned {
|
|
1819
2009
|
readonly checksum: SHA256;
|
|
1820
2010
|
readonly size: number;
|
|
1821
2011
|
readonly mime: string;
|
|
@@ -1835,7 +2025,7 @@ interface Blob extends Identifiable, Timestamped, Versioned {
|
|
|
1835
2025
|
* A lightweight reference to a blob.
|
|
1836
2026
|
* Used in content blocks to avoid passing heavy metadata or binary data across boundaries.
|
|
1837
2027
|
*/
|
|
1838
|
-
type BlobRef = Pick<Blob, "id" | "checksum" | "mime" | "size">;
|
|
2028
|
+
type BlobRef = Pick<Blob$1, "id" | "checksum" | "mime" | "size">;
|
|
1839
2029
|
type ResolvedBlob = {
|
|
1840
2030
|
/** Indicates the blob data is available in the local memory space. */
|
|
1841
2031
|
kind: "inline";
|
|
@@ -1977,7 +2167,7 @@ interface ContentDefinition<ContentType extends string, Data extends Record<stri
|
|
|
1977
2167
|
* Scans a content block of this type for actionable side effects.
|
|
1978
2168
|
* Returns a list of Commands to be dispatched against the workspace.
|
|
1979
2169
|
*/
|
|
1980
|
-
parse?: (
|
|
2170
|
+
parse?: (block: Content<ContentType, Data>) => Command<any>[];
|
|
1981
2171
|
}
|
|
1982
2172
|
|
|
1983
2173
|
/**
|
|
@@ -1999,7 +2189,7 @@ interface ToolResultData {
|
|
|
1999
2189
|
/** The output returned by the tool (any JSON-serializable value) */
|
|
2000
2190
|
result: unknown;
|
|
2001
2191
|
/** Identifier that links this result to the original tool-call */
|
|
2002
|
-
|
|
2192
|
+
key: string;
|
|
2003
2193
|
/** Optional error message if the tool execution failed */
|
|
2004
2194
|
error?: string;
|
|
2005
2195
|
}
|
|
@@ -2146,14 +2336,23 @@ interface AgentIndex extends Index {
|
|
|
2146
2336
|
}
|
|
2147
2337
|
/**
|
|
2148
2338
|
* A tool that can be called by an agent.
|
|
2339
|
+
* Descriptions and parameter structures serve both human engineers (for debugging/registry)
|
|
2340
|
+
* and LLMs (for precise function execution routing).
|
|
2149
2341
|
*/
|
|
2150
2342
|
interface ToolDefinition<Name extends string = string, Params extends Record<string, any> = any> {
|
|
2151
2343
|
/** The unique name of the tool. Used in the model response to identify which tool to call. */
|
|
2152
2344
|
name: Name;
|
|
2153
|
-
/** Human-readable description
|
|
2345
|
+
/** Human-readable description explaining what the tool does, its side effects, and when to use it. */
|
|
2154
2346
|
description: string;
|
|
2155
2347
|
/** JSON Schema fragment defining the tool's parameters. */
|
|
2156
|
-
parameters
|
|
2348
|
+
parameters?: Record<string, unknown>;
|
|
2349
|
+
/** * Explicit execution arguments showcasing expected input profiles.
|
|
2350
|
+
* Directly utilized to ground structured model inferences and guide developers.
|
|
2351
|
+
*/
|
|
2352
|
+
example: {
|
|
2353
|
+
input?: Params;
|
|
2354
|
+
explanation: string;
|
|
2355
|
+
};
|
|
2157
2356
|
/**
|
|
2158
2357
|
* The actual implementation function.
|
|
2159
2358
|
* This is executed by the system when the model requests this tool.
|
|
@@ -2407,11 +2606,6 @@ type SnapshotTarget = {
|
|
|
2407
2606
|
kind: "turn";
|
|
2408
2607
|
turn: Turn;
|
|
2409
2608
|
};
|
|
2410
|
-
type SnapshotErrorKind = "session-not-found" | "role-not-found";
|
|
2411
|
-
declare class SnapshotError extends Error {
|
|
2412
|
-
readonly kind: SnapshotErrorKind;
|
|
2413
|
-
constructor(kind: SnapshotErrorKind, message: string);
|
|
2414
|
-
}
|
|
2415
2609
|
/**
|
|
2416
2610
|
* Wraps each effect dispatch outcome so callers can inspect per-effect
|
|
2417
2611
|
* failures without the sequence being aborted by a throw.
|
|
@@ -2549,7 +2743,7 @@ declare class Session {
|
|
|
2549
2743
|
* @param target - Optional discriminated target to build the snapshot
|
|
2550
2744
|
* against. Omit to use the current head of the active chain.
|
|
2551
2745
|
*/
|
|
2552
|
-
snapshot(target?: SnapshotTarget): Promise<Result<SessionSnapshot,
|
|
2746
|
+
snapshot(target?: SnapshotTarget): Promise<Result<SessionSnapshot, SystemError>>;
|
|
2553
2747
|
/**
|
|
2554
2748
|
* Throws if the session has been closed, giving mutations a consistent
|
|
2555
2749
|
* early-exit rather than propagating odd errors from the coordinator.
|
|
@@ -2650,6 +2844,7 @@ type DeleteRoleCommand = Command<"role:delete", {
|
|
|
2650
2844
|
type ExecuteToolCommand = Command<"tool:execute", {
|
|
2651
2845
|
name: string;
|
|
2652
2846
|
parameters: Record<string, any>;
|
|
2847
|
+
key: string;
|
|
2653
2848
|
}>;
|
|
2654
2849
|
/**
|
|
2655
2850
|
* Union of all Agent commands.
|
|
@@ -2662,9 +2857,15 @@ type AgentCommand = AddRoleCommand | UpdateRoleCommand | DeleteRoleCommand | Exe
|
|
|
2662
2857
|
*/
|
|
2663
2858
|
declare class ToolRegistry extends Registry<ToolDefinition<any>> {
|
|
2664
2859
|
/**
|
|
2665
|
-
* Returns a system-prompt section describing
|
|
2860
|
+
* Returns a token-optimized system-prompt section describing available tools
|
|
2861
|
+
* using a neutral, standardized example tool block blueprint.
|
|
2666
2862
|
*/
|
|
2667
2863
|
description(): string;
|
|
2864
|
+
/**
|
|
2865
|
+
* Generates the strict structured array blocks for your response schema.
|
|
2866
|
+
* This is where the aggregation happens effortlessly!
|
|
2867
|
+
*/
|
|
2868
|
+
schema(): any[];
|
|
2668
2869
|
/**
|
|
2669
2870
|
* Returns a JSON Schema array of all tool definitions.
|
|
2670
2871
|
* Useful for providers that support native tool-calling (like OpenAI/Gemini).
|
|
@@ -2701,32 +2902,36 @@ declare class AgentModule implements Module<"user" | "system", Record<string, an
|
|
|
2701
2902
|
roles: RoleStore;
|
|
2702
2903
|
}>;
|
|
2703
2904
|
actions: {
|
|
2704
|
-
"role:add": (_state: State<any, AgentIndex>, command: AddRoleCommand) => Promise<{
|
|
2905
|
+
"role:add": (_state: State<any, AgentIndex>, command: AddRoleCommand) => Promise<Result<{
|
|
2705
2906
|
index: {
|
|
2706
2907
|
roles: {
|
|
2707
2908
|
[x: string]: RoleSummary | undefined;
|
|
2708
2909
|
};
|
|
2709
2910
|
};
|
|
2710
|
-
}
|
|
2911
|
+
}, never>>;
|
|
2711
2912
|
"role:update": (state: State<any, AgentIndex>, command: UpdateRoleCommand) => Promise<{
|
|
2712
|
-
|
|
2913
|
+
readonly ok: false;
|
|
2914
|
+
readonly error: never;
|
|
2713
2915
|
} | {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
[name]: RoleSummary | undefined;
|
|
2717
|
-
};
|
|
2718
|
-
};
|
|
2916
|
+
readonly ok: true;
|
|
2917
|
+
readonly value: {};
|
|
2719
2918
|
}>;
|
|
2720
2919
|
"role:delete": (state: State<any, AgentIndex>, command: DeleteRoleCommand) => Promise<{
|
|
2721
|
-
|
|
2920
|
+
readonly ok: false;
|
|
2921
|
+
readonly error: never;
|
|
2722
2922
|
} | {
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2923
|
+
readonly ok: true;
|
|
2924
|
+
readonly value: {};
|
|
2925
|
+
}>;
|
|
2926
|
+
"tool:execute": (_state: State<any, AgentIndex>, command: ExecuteToolCommand) => Promise<{
|
|
2927
|
+
readonly ok: false;
|
|
2928
|
+
readonly error: SystemError;
|
|
2929
|
+
} | {
|
|
2930
|
+
readonly ok: true;
|
|
2931
|
+
readonly value: {
|
|
2932
|
+
result: any;
|
|
2727
2933
|
};
|
|
2728
2934
|
}>;
|
|
2729
|
-
"tool:execute": (_state: State<any, AgentIndex>, command: ExecuteToolCommand) => Promise<any>;
|
|
2730
2935
|
};
|
|
2731
2936
|
/**
|
|
2732
2937
|
* Rebuilds the AgentIndex from durable storage.
|
|
@@ -2741,17 +2946,17 @@ declare class AgentModule implements Module<"user" | "system", Record<string, an
|
|
|
2741
2946
|
* This implementation addresses the constraint that Anansi should
|
|
2742
2947
|
* not store large binary payloads directly.
|
|
2743
2948
|
*/
|
|
2744
|
-
declare class BlobStore extends BaseStore<Blob, "id", Blob> {
|
|
2949
|
+
declare class BlobStore extends BaseStore<Blob$1, "id", Blob$1> {
|
|
2745
2950
|
private readonly storage;
|
|
2746
|
-
constructor(collection: Collection<Blob>, storage: BlobStorage);
|
|
2951
|
+
constructor(collection: Collection<Blob$1>, storage: BlobStorage);
|
|
2747
2952
|
/**
|
|
2748
2953
|
* Overridden to hydrate the binary data from specialized storage.
|
|
2749
2954
|
*/
|
|
2750
|
-
get(id: UUID): Promise<Blob | null>;
|
|
2955
|
+
get(id: UUID): Promise<Blob$1 | null>;
|
|
2751
2956
|
/**
|
|
2752
2957
|
* Overridden to separate metadata and binary data during creation.
|
|
2753
2958
|
*/
|
|
2754
|
-
add(entity: Blob): Promise<void>;
|
|
2959
|
+
add(entity: Blob$1): Promise<void>;
|
|
2755
2960
|
/**
|
|
2756
2961
|
* Overridden to ensure bytes are purged when the record is deleted.
|
|
2757
2962
|
*/
|
|
@@ -2759,7 +2964,7 @@ declare class BlobStore extends BaseStore<Blob, "id", Blob> {
|
|
|
2759
2964
|
/**
|
|
2760
2965
|
* Finds a blob by its content checksum.
|
|
2761
2966
|
*/
|
|
2762
|
-
findByChecksum(checksum: SHA256): Promise<Blob | null>;
|
|
2967
|
+
findByChecksum(checksum: SHA256): Promise<Blob$1 | null>;
|
|
2763
2968
|
/**
|
|
2764
2969
|
* Resolves a BlobRef to a ResolvedBlob (inline or remote) or null.
|
|
2765
2970
|
*
|
|
@@ -2844,7 +3049,7 @@ declare class ContentModule implements Module<"user" | "system", ContentCoreStat
|
|
|
2844
3049
|
blobs: BlobStore;
|
|
2845
3050
|
}>;
|
|
2846
3051
|
actions: {
|
|
2847
|
-
"content:add": (_: State<ContentCoreState, ContentIndex>, command: AddContentCommand) => Promise<{
|
|
3052
|
+
"content:add": (_: State<ContentCoreState, ContentIndex>, command: AddContentCommand) => Promise<Result<{
|
|
2848
3053
|
index: {
|
|
2849
3054
|
content: {
|
|
2850
3055
|
items: {
|
|
@@ -2855,52 +3060,38 @@ declare class ContentModule implements Module<"user" | "system", ContentCoreStat
|
|
|
2855
3060
|
};
|
|
2856
3061
|
};
|
|
2857
3062
|
};
|
|
2858
|
-
}
|
|
3063
|
+
}, never>>;
|
|
2859
3064
|
"content:update": (state: State<ContentCoreState, ContentIndex>, command: UpdateContentCommand) => Promise<{
|
|
2860
|
-
|
|
3065
|
+
readonly ok: false;
|
|
3066
|
+
readonly error: never;
|
|
2861
3067
|
} | {
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
items: {
|
|
2865
|
-
[x: string]: ContentSummary<any>;
|
|
2866
|
-
};
|
|
2867
|
-
keys: {};
|
|
2868
|
-
};
|
|
2869
|
-
};
|
|
3068
|
+
readonly ok: true;
|
|
3069
|
+
readonly value: {};
|
|
2870
3070
|
}>;
|
|
2871
3071
|
"content:delete": (state: State<ContentCoreState, ContentIndex>, command: DeleteContentCommand) => Promise<{
|
|
2872
|
-
|
|
3072
|
+
readonly ok: false;
|
|
3073
|
+
readonly error: never;
|
|
2873
3074
|
} | {
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
items: {
|
|
2877
|
-
[x: string]: any;
|
|
2878
|
-
};
|
|
2879
|
-
keys: {
|
|
2880
|
-
[x: number]: any;
|
|
2881
|
-
};
|
|
2882
|
-
};
|
|
2883
|
-
};
|
|
3075
|
+
readonly ok: true;
|
|
3076
|
+
readonly value: {};
|
|
2884
3077
|
}>;
|
|
2885
|
-
"blob:register": (state: State<ContentCoreState, ContentIndex>, command: RegisterBlobCommand) => Promise<{
|
|
3078
|
+
"blob:register": (state: State<ContentCoreState, ContentIndex>, command: RegisterBlobCommand) => Promise<Result<{
|
|
2886
3079
|
index: {
|
|
2887
3080
|
content: {
|
|
2888
3081
|
blobs: any;
|
|
2889
3082
|
};
|
|
2890
3083
|
};
|
|
2891
|
-
}
|
|
2892
|
-
"blob:retain": (_state: State<ContentCoreState, ContentIndex>, command: RetainBlobCommand) => Promise<{}
|
|
2893
|
-
"blob:release": (_state: State<ContentCoreState, ContentIndex>, command: ReleaseBlobCommand) => Promise<{}
|
|
3084
|
+
}, never>>;
|
|
3085
|
+
"blob:retain": (_state: State<ContentCoreState, ContentIndex>, command: RetainBlobCommand) => Promise<Result<{}, never>>;
|
|
3086
|
+
"blob:release": (_state: State<ContentCoreState, ContentIndex>, command: ReleaseBlobCommand) => Promise<Result<{}, never>>;
|
|
2894
3087
|
"blob:purge": (state: State<ContentCoreState, ContentIndex>, command: PurgeBlobCommand) => Promise<{
|
|
2895
|
-
|
|
3088
|
+
readonly ok: false;
|
|
3089
|
+
readonly error: never;
|
|
2896
3090
|
} | {
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
blobs: any;
|
|
2900
|
-
};
|
|
2901
|
-
};
|
|
3091
|
+
readonly ok: true;
|
|
3092
|
+
readonly value: {};
|
|
2902
3093
|
}>;
|
|
2903
|
-
"blob:record_remote_id": (_state: State<ContentCoreState, ContentIndex>, command: RecordBlobRemoteIdCommand) => Promise<{}
|
|
3094
|
+
"blob:record_remote_id": (_state: State<ContentCoreState, ContentIndex>, command: RecordBlobRemoteIdCommand) => Promise<Result<{}, never>>;
|
|
2904
3095
|
};
|
|
2905
3096
|
/**
|
|
2906
3097
|
* Rebuilds the ContentIndex from durable storage.
|
|
@@ -2990,84 +3181,68 @@ declare class SessionModule implements Module<"user" | "system", Record<string,
|
|
|
2990
3181
|
turns: TurnStore;
|
|
2991
3182
|
}>;
|
|
2992
3183
|
actions: {
|
|
2993
|
-
"session:create": (_: State<any, SessionIndex>, command: CreateSessionCommand) => Promise<{
|
|
3184
|
+
"session:create": (_: State<any, SessionIndex>, command: CreateSessionCommand) => Promise<Result<{
|
|
2994
3185
|
index: {
|
|
2995
3186
|
sessions: {
|
|
2996
3187
|
[x: string]: SessionSummary;
|
|
2997
3188
|
};
|
|
2998
3189
|
};
|
|
2999
|
-
}
|
|
3190
|
+
}, never>>;
|
|
3000
3191
|
"session:update": (state: State<any, SessionIndex>, command: UpdateSessionCommand) => Promise<{
|
|
3001
|
-
|
|
3192
|
+
readonly ok: false;
|
|
3193
|
+
readonly error: never;
|
|
3002
3194
|
} | {
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
[x: string]: SessionSummary;
|
|
3006
|
-
};
|
|
3007
|
-
};
|
|
3195
|
+
readonly ok: true;
|
|
3196
|
+
readonly value: {};
|
|
3008
3197
|
}>;
|
|
3009
3198
|
"session:fork": (state: State<any, SessionIndex>, command: ForkSessionCommand) => Promise<{
|
|
3010
|
-
|
|
3199
|
+
readonly ok: false;
|
|
3200
|
+
readonly error: never;
|
|
3011
3201
|
} | {
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
[x: string]: SessionSummary;
|
|
3015
|
-
};
|
|
3016
|
-
};
|
|
3202
|
+
readonly ok: true;
|
|
3203
|
+
readonly value: {};
|
|
3017
3204
|
}>;
|
|
3018
3205
|
"session:delete": (state: State<any, SessionIndex>, command: DeleteSessionCommand) => Promise<{
|
|
3019
|
-
|
|
3206
|
+
readonly ok: false;
|
|
3207
|
+
readonly error: never;
|
|
3020
3208
|
} | {
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
[x: string]: any;
|
|
3024
|
-
};
|
|
3025
|
-
};
|
|
3209
|
+
readonly ok: true;
|
|
3210
|
+
readonly value: {};
|
|
3026
3211
|
}>;
|
|
3027
3212
|
"turn:add": (state: State<any, SessionIndex>, command: AddTurnCommand) => Promise<{
|
|
3028
|
-
|
|
3213
|
+
readonly ok: false;
|
|
3214
|
+
readonly error: never;
|
|
3029
3215
|
} | {
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
[x: string]: SessionSummary;
|
|
3033
|
-
};
|
|
3034
|
-
};
|
|
3216
|
+
readonly ok: true;
|
|
3217
|
+
readonly value: {};
|
|
3035
3218
|
}>;
|
|
3036
3219
|
"turn:update": (state: State<any, SessionIndex>, command: UpdateTurnCommand) => Promise<{
|
|
3037
|
-
|
|
3220
|
+
readonly ok: false;
|
|
3221
|
+
readonly error: never;
|
|
3038
3222
|
} | {
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
[x: string]: SessionSummary;
|
|
3042
|
-
};
|
|
3043
|
-
};
|
|
3223
|
+
readonly ok: true;
|
|
3224
|
+
readonly value: {};
|
|
3044
3225
|
}>;
|
|
3045
3226
|
"turn:edit": (state: State<any, SessionIndex>, command: EditTurnCommand) => Promise<{
|
|
3046
|
-
|
|
3227
|
+
readonly ok: false;
|
|
3228
|
+
readonly error: never;
|
|
3047
3229
|
} | {
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
[x: string]: any;
|
|
3051
|
-
};
|
|
3052
|
-
};
|
|
3230
|
+
readonly ok: true;
|
|
3231
|
+
readonly value: {};
|
|
3053
3232
|
}>;
|
|
3054
3233
|
"turn:branch": (state: State<any, SessionIndex>, command: BranchTurnCommand) => Promise<{
|
|
3055
|
-
|
|
3234
|
+
readonly ok: false;
|
|
3235
|
+
readonly error: never;
|
|
3056
3236
|
} | {
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
[x: string]: SessionSummary;
|
|
3060
|
-
};
|
|
3061
|
-
};
|
|
3237
|
+
readonly ok: true;
|
|
3238
|
+
readonly value: {};
|
|
3062
3239
|
}>;
|
|
3063
3240
|
"turn:delete": (state: State<any, SessionIndex>, command: DeleteTurnCommand) => Promise<{
|
|
3064
|
-
|
|
3241
|
+
readonly ok: false;
|
|
3242
|
+
readonly error: never;
|
|
3065
3243
|
} | {
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
[x: string]: SessionSummary;
|
|
3069
|
-
};
|
|
3070
|
-
};
|
|
3244
|
+
readonly ok: true;
|
|
3245
|
+
readonly value: {};
|
|
3071
3246
|
}>;
|
|
3072
3247
|
};
|
|
3073
3248
|
/**
|
|
@@ -3109,14 +3284,23 @@ declare function createWorkspace<T extends string, S extends Record<string, any>
|
|
|
3109
3284
|
aggregator: ModuleAggregator<string, S, I>;
|
|
3110
3285
|
}>;
|
|
3111
3286
|
|
|
3287
|
+
declare const ToolCallRegex: RegExp;
|
|
3112
3288
|
/**
|
|
3113
3289
|
* Registry for managing ContentDefinitions.
|
|
3114
3290
|
* Enables the Kernel to delegate type-specific logic to registered handlers.
|
|
3115
3291
|
*/
|
|
3116
3292
|
declare class ContentRegistry extends Registry<ContentDefinition<any>> {
|
|
3293
|
+
private readonly shortKeys;
|
|
3117
3294
|
constructor(opts: {
|
|
3118
3295
|
logger: Logger$1;
|
|
3296
|
+
empty?: boolean;
|
|
3119
3297
|
});
|
|
3298
|
+
/**
|
|
3299
|
+
* Gets an item by its key.
|
|
3300
|
+
* @param key - The key of the item to retrieve
|
|
3301
|
+
* @returns The item if found, undefined otherwise
|
|
3302
|
+
*/
|
|
3303
|
+
get(key: string): ContentDefinition<any> | undefined;
|
|
3120
3304
|
/**
|
|
3121
3305
|
* Returns the system-prompt section describing all emittable block types.
|
|
3122
3306
|
*/
|
|
@@ -3124,12 +3308,12 @@ declare class ContentRegistry extends Registry<ContentDefinition<any>> {
|
|
|
3124
3308
|
/**
|
|
3125
3309
|
* Returns a plain JSON Schema object scoped to emittable block definitions.
|
|
3126
3310
|
*/
|
|
3127
|
-
schema(filter?: ContentFilter): Record<string, unknown>;
|
|
3311
|
+
schema(filter?: ContentFilter, extra?: Record<string, unknown>[]): Record<string, unknown>;
|
|
3128
3312
|
/**
|
|
3129
|
-
*
|
|
3130
|
-
*
|
|
3131
|
-
* @returns The ContentMode if the type is registered, undefined otherwise.
|
|
3313
|
+
* Updates an existing item with new properties.
|
|
3314
|
+
* Special handling for 'mappings' to ensure provider mappings are merged rather than overwritten.
|
|
3132
3315
|
*/
|
|
3316
|
+
update(key: string, updates: Partial<ContentDefinition<any>>): Result$1<void, SystemError>;
|
|
3133
3317
|
mode(type: string): ContentMode | undefined;
|
|
3134
3318
|
/**
|
|
3135
3319
|
* Converts a raw JSON object from a model response into a workspace content block.
|
|
@@ -3219,7 +3403,7 @@ interface Prompt {
|
|
|
3219
3403
|
* (i.e., the tool has already been executed).
|
|
3220
3404
|
* Empty object if the last assistant turn has no tool calls or no results yet.
|
|
3221
3405
|
*/
|
|
3222
|
-
|
|
3406
|
+
results: Array<ToolResultContent>;
|
|
3223
3407
|
/**
|
|
3224
3408
|
* Non-fatal warnings generated during the build phase.
|
|
3225
3409
|
*/
|
|
@@ -3254,7 +3438,7 @@ interface AssemblerExtension extends PromptSection {
|
|
|
3254
3438
|
* Provider-agnostic system prompt assembler.
|
|
3255
3439
|
*/
|
|
3256
3440
|
interface SystemPromptAssembler {
|
|
3257
|
-
readonly
|
|
3441
|
+
readonly content: ContentRegistry;
|
|
3258
3442
|
build<P, C>(provider: string, prompt: Prompt, mapTurn: (args: {
|
|
3259
3443
|
turn: Turn;
|
|
3260
3444
|
parts: P[];
|
|
@@ -3262,6 +3446,7 @@ interface SystemPromptAssembler {
|
|
|
3262
3446
|
system: string;
|
|
3263
3447
|
transcript: C[];
|
|
3264
3448
|
sections: PromptSection[];
|
|
3449
|
+
schema: any;
|
|
3265
3450
|
}>;
|
|
3266
3451
|
join(sections: PromptSection[]): string;
|
|
3267
3452
|
}
|
|
@@ -3324,6 +3509,8 @@ interface InferenceContext {
|
|
|
3324
3509
|
/** Tokens remaining in the context window after this prompt. */
|
|
3325
3510
|
remaining?: number;
|
|
3326
3511
|
};
|
|
3512
|
+
/** the schema of the response structure */
|
|
3513
|
+
schema: Record<string, any>;
|
|
3327
3514
|
/**
|
|
3328
3515
|
* Sends this prompt to the model.
|
|
3329
3516
|
* @returns The parsed assistant Turn plus any execution side-effects.
|
|
@@ -3459,10 +3646,11 @@ interface Logger {
|
|
|
3459
3646
|
info?: (message: string, ...args: unknown[]) => void;
|
|
3460
3647
|
}
|
|
3461
3648
|
declare class PromptAssembler implements SystemPromptAssembler {
|
|
3649
|
+
readonly content: ContentRegistry;
|
|
3650
|
+
private readonly tools;
|
|
3462
3651
|
private resolver;
|
|
3463
|
-
readonly registry: ContentRegistry;
|
|
3464
3652
|
private readonly logger;
|
|
3465
|
-
constructor(
|
|
3653
|
+
constructor(content: ContentRegistry, tools: ToolRegistry, resolver: BlobResolver, logger?: Logger);
|
|
3466
3654
|
build<P, C>(provider: string, prompt: Prompt, mapTurn: (args: {
|
|
3467
3655
|
turn: Turn;
|
|
3468
3656
|
parts: P[];
|
|
@@ -3470,7 +3658,9 @@ declare class PromptAssembler implements SystemPromptAssembler {
|
|
|
3470
3658
|
system: string;
|
|
3471
3659
|
sections: PromptSection[];
|
|
3472
3660
|
transcript: C[];
|
|
3661
|
+
schema: any;
|
|
3473
3662
|
}>;
|
|
3663
|
+
private buildSchema;
|
|
3474
3664
|
private buildSections;
|
|
3475
3665
|
join(sections: PromptSection[]): string;
|
|
3476
3666
|
}
|
|
@@ -3593,15 +3783,27 @@ declare class TurnBuilder {
|
|
|
3593
3783
|
}): TurnBuilder;
|
|
3594
3784
|
addToolCall(name: string, parameters: Record<string, unknown>, options?: {
|
|
3595
3785
|
key?: string;
|
|
3596
|
-
callId?: string;
|
|
3597
3786
|
label?: string;
|
|
3598
3787
|
topics?: string[];
|
|
3599
3788
|
}): TurnBuilder;
|
|
3600
|
-
addToolResult(
|
|
3789
|
+
addToolResult(key: string, name: string, result: unknown, error?: string, options?: {
|
|
3601
3790
|
key?: string;
|
|
3602
3791
|
label?: string;
|
|
3603
3792
|
topics?: string[];
|
|
3604
3793
|
}): TurnBuilder;
|
|
3794
|
+
/**
|
|
3795
|
+
* Adds a historical tool report block (read‑only archival record).
|
|
3796
|
+
* @param key - Unique key linking to the original tool call.
|
|
3797
|
+
* @param name - Name of the tool that was invoked.
|
|
3798
|
+
* @param parameters - Arguments passed to the tool.
|
|
3799
|
+
* @param result - The result value (if successful). Provide only when `error` is omitted.
|
|
3800
|
+
* @param error - The error message (if failed). Provide only when `result` is omitted.
|
|
3801
|
+
* @param options - Optional block metadata (`label`, `topics`).
|
|
3802
|
+
*/
|
|
3803
|
+
addToolReport(key: string, name: string, parameters: Record<string, unknown>, result?: unknown, error?: string, options?: {
|
|
3804
|
+
label?: string;
|
|
3805
|
+
topics?: string[];
|
|
3806
|
+
}): TurnBuilder;
|
|
3605
3807
|
addBlock(block: Content<any, any>): TurnBuilder;
|
|
3606
3808
|
deleteBlock(blockId: UUID): TurnBuilder;
|
|
3607
3809
|
withId(id: UUID): TurnBuilder;
|
|
@@ -3690,6 +3892,7 @@ declare class Bootstrapper {
|
|
|
3690
3892
|
turns: TurnBuilderFactory;
|
|
3691
3893
|
}>;
|
|
3692
3894
|
}
|
|
3895
|
+
type BootstrappedWorkspace = Awaited<ReturnType<typeof Bootstrapper.workspace>>;
|
|
3693
3896
|
|
|
3694
3897
|
declare const GOOGLE_MODELS: Array<ModelProfile>;
|
|
3695
3898
|
/** Everyday workhorse models: Flash variants + larger Gemma 4s. */
|
|
@@ -3704,10 +3907,10 @@ declare class GoogleGenAIAdapter implements LLMAdapter {
|
|
|
3704
3907
|
private readonly assembler;
|
|
3705
3908
|
private readonly turns;
|
|
3706
3909
|
private readonly registry;
|
|
3707
|
-
private readonly tools?;
|
|
3708
3910
|
private readonly model;
|
|
3709
3911
|
private readonly _models;
|
|
3710
|
-
|
|
3912
|
+
private readonly logger;
|
|
3913
|
+
constructor(client: GoogleGenAI, assembler: SystemPromptAssembler, turns: TurnBuilderFactory, registry: ContentRegistry, logger: Logger$1, options?: {
|
|
3711
3914
|
model: string;
|
|
3712
3915
|
models: Array<ModelProfile>;
|
|
3713
3916
|
});
|
|
@@ -3776,4 +3979,4 @@ declare class MemoryBlobStorage implements BlobStorage {
|
|
|
3776
3979
|
exportAllBytes(): Promise<Array<[SHA256, Uint8Array]>>;
|
|
3777
3980
|
}
|
|
3778
3981
|
|
|
3779
|
-
export { type Action, type ActionEntry, type AgentIndex, AgentModule, type AssemblerExtension, type AuthContext, AuthContextBuilder, type AuthorizationProvider, type Authorizer, BaseStore, type Blob, type BlobRef, type BlobResolver, type BlobStorage, type BootstrapParams, Bootstrapper, type BranchInfo, Branded, type Command, type CommandCoordinator, type CommandRegistry, CommonErrors, ConsoleLogger, type Content, type ContentCoreState, type ContentDefinition, type ContentFilter, type ContentIndex, type ContentMapper, type ContentMode, ContentModule, ContentRegistry, type ContentRetriever, type ContentSummary, type CreateWorkspaceCommand, type CreateWorkspaceParams, DELETE_SYMBOL, type DatabaseConfig, type DeepPartial, type DomainRegistry, type EffectResult, type Entity, type Event, index as GoogleAdapter, type IKernel, type IRegistry, type IRegistryReader, type IWorkspaceDatabase, type Identifiable, type Index, type IndexedDBBlobConfig, IndexedDBBlobStorage, type InferenceContext, type InferenceResults, type Issue, Kernel, type KernelConfig, LLM, type LLMAdapter, type LLMAdapterStatic, type LogEntry, type LogLevel, type Logger$1 as Logger, MemoryBlobStorage, type Metadata, type Middleware, type ModelConstraint, type ModelConstraints, type ModelName, type ModelProfile, type ModelStatus, type Module, ModuleAggregator, type ProjectMetadata, type Prompt, PromptAssembler, type PromptBuilder, type PromptBuilderOptions, type PromptSection, Registry, type ResolvedBlob, Result, type Role, type RoleSummary, type SHA256, type Selector, Session, type SessionIndex, SessionManager, SessionModule, type SessionSnapshot, type SessionSummary, type Severity,
|
|
3982
|
+
export { type Action, type ActionEntry, type ActionOutcome, type AgentIndex, AgentModule, type AssemblerExtension, type AuthContext, AuthContextBuilder, type AuthorizationProvider, type Authorizer, BaseStore, type Blob$1 as Blob, type BlobRef, type BlobResolver, type BlobStorage, BlobUtilities, type BootstrapParams, type BootstrappedWorkspace, Bootstrapper, type BranchInfo, Branded, type Command, type CommandCoordinator, type CommandRegistry, CommonErrors, ConsoleLogger, type Content, type ContentCoreState, type ContentDefinition, type ContentFilter, type ContentIndex, type ContentMapper, type ContentMode, ContentModule, ContentRegistry, type ContentRetriever, type ContentSummary, type CreateWorkspaceCommand, type CreateWorkspaceParams, DELETE_SYMBOL, type DatabaseConfig, type DeepPartial, type DomainRegistry, type EffectResult, type Entity, type Event, index as GoogleAdapter, type IKernel, type IRegistry, type IRegistryReader, type IWorkspaceDatabase, type Identifiable, type Index, type IndexedDBBlobConfig, IndexedDBBlobStorage, type InferenceContext, type InferenceResults, type Issue, Kernel, type KernelConfig, LLM, type LLMAdapter, type LLMAdapterStatic, type LogEntry, type LogLevel, type Logger$1 as Logger, MemoryBlobStorage, type Metadata, type Middleware, type ModelConstraint, type ModelConstraints, type ModelName, type ModelProfile, type ModelStatus, type Module, ModuleAggregator, type ProjectMetadata, type Prompt, PromptAssembler, type PromptBuilder, type PromptBuilderOptions, type PromptSection, Registry, type ResolvedBlob, Result, type Role, type RoleSummary, type SHA256, type Selector, Session, type SessionIndex, SessionManager, SessionModule, type SessionSnapshot, type SessionSummary, type Severity, ShortKeyRegistry, type SnapshotTarget, type State, type StateManager, type StateReader, type Store, type StoreKey, type SyncWorkspaceCommand, SystemAuth, SystemError, type SystemPromptAssembler, type Taggable, type Timestamp, type Timestamped, ToolCallRegex, type ToolDefinition, type TransactionStep, type Turn, TurnBuilderFactory, type TurnNode, type TurnProcessor, TurnTree, type URI, type UUID, type Versioned, type WorkspaceCommand, WorkspaceDatabase, type WorkspaceIndex, WorkspaceModule, type WorkspaceSettings, type WorkspaceState, createAnonymousContext, createAuthContext, createError, createLogger, createUserContext, createWorkspace, deepClone, del, logger, merge };
|