@mikesaintsg/core 0.0.1
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 +365 -0
- package/dist/index.d.ts +1299 -0
- package/dist/index.js +828 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1299 @@
|
|
|
1
|
+
/** Cancellable operation options */
|
|
2
|
+
export declare interface AbortableOptions {
|
|
3
|
+
readonly signal?: AbortSignal;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Anthropic embedding adapter options */
|
|
7
|
+
export declare interface AnthropicEmbeddingAdapterOptions {
|
|
8
|
+
readonly apiKey: string;
|
|
9
|
+
readonly model?: string;
|
|
10
|
+
readonly baseURL?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Anthropic provider adapter options */
|
|
14
|
+
export declare interface AnthropicProviderAdapterOptions {
|
|
15
|
+
readonly apiKey: string;
|
|
16
|
+
readonly model?: string;
|
|
17
|
+
readonly baseURL?: string;
|
|
18
|
+
readonly defaultOptions?: GenerationDefaults;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Anthropic tool schema format */
|
|
22
|
+
export declare interface AnthropicTool {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly description: string;
|
|
25
|
+
readonly input_schema: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Anthropic tool format adapter options */
|
|
29
|
+
export declare interface AnthropicToolFormatAdapterOptions {
|
|
30
|
+
readonly toolChoice?: 'auto' | 'any' | {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Anthropic tool use content block */
|
|
36
|
+
export declare interface AnthropicToolUse {
|
|
37
|
+
readonly type: 'tool_use';
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Batched embedding adapter interface - extends base with batching */
|
|
44
|
+
export declare interface BatchedEmbeddingAdapterInterface extends EmbeddingAdapterInterface {
|
|
45
|
+
queue(text: string, options?: AbortableOptions): Promise<Embedding>;
|
|
46
|
+
queueBatch(texts: readonly string[], options?: AbortableOptions): Promise<readonly Embedding[]>;
|
|
47
|
+
flush(): Promise<void>;
|
|
48
|
+
getPendingCount(): number;
|
|
49
|
+
getCache(): EmbeddingCacheInterface | undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Default timeout for bridge operations in milliseconds */
|
|
53
|
+
export declare const BRIDGE_DEFAULT_TIMEOUT = 30000;
|
|
54
|
+
|
|
55
|
+
/** Assembled context ready for inference */
|
|
56
|
+
export declare interface BuiltContext {
|
|
57
|
+
readonly frames: readonly ContextFrame[];
|
|
58
|
+
readonly totalTokens: number;
|
|
59
|
+
readonly budget: TokenBudgetState;
|
|
60
|
+
readonly truncated: boolean;
|
|
61
|
+
readonly truncationInfo?: TruncationInfo;
|
|
62
|
+
readonly deduplication?: DeduplicationResult;
|
|
63
|
+
readonly timestamp: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Chain results (flatMap). Apply a function that returns a Result to a success value.
|
|
68
|
+
*
|
|
69
|
+
* @param result - The result to chain
|
|
70
|
+
* @param fn - Function returning a new Result
|
|
71
|
+
* @returns The result of applying fn, or the original error
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const parsed = chain(ok('42'), s => {
|
|
76
|
+
* const n = parseInt(s, 10)
|
|
77
|
+
* return isNaN(n) ? err('PARSE_ERROR') : ok(n)
|
|
78
|
+
* })
|
|
79
|
+
* // parsed = ok(42)
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function chain<T, U, E>(result: Result<T, E>, fn: (value: T) => Result<U, E>): Result<U, E>;
|
|
83
|
+
|
|
84
|
+
/** Origin of state change */
|
|
85
|
+
export declare type ChangeSource = 'local' | 'remote';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Compute a SHA-256 content hash for text.
|
|
89
|
+
*
|
|
90
|
+
* @param text - The text to hash
|
|
91
|
+
* @returns A hex string content hash
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const hash = await computeContentHash('Hello, world!')
|
|
96
|
+
* // hash = 'a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e'
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function computeContentHash(text: string): Promise<ContentHash>;
|
|
100
|
+
|
|
101
|
+
/** Content hash for deduplication (SHA-256 hex string) */
|
|
102
|
+
export declare type ContentHash = string;
|
|
103
|
+
|
|
104
|
+
/** Context frame - atomic unit of context */
|
|
105
|
+
export declare interface ContextFrame {
|
|
106
|
+
readonly id: string;
|
|
107
|
+
readonly type: FrameType;
|
|
108
|
+
readonly content: string;
|
|
109
|
+
readonly contentHash: ContentHash;
|
|
110
|
+
readonly priority: FramePriority;
|
|
111
|
+
readonly tokenEstimate: number;
|
|
112
|
+
readonly createdAt: number;
|
|
113
|
+
readonly metadata?: FrameMetadata;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Core package error.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* throw new CoreError('ADAPTER_ERROR', 'Failed to connect to OpenAI')
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare class CoreError extends Error {
|
|
125
|
+
readonly code: CoreErrorCode;
|
|
126
|
+
readonly cause: Error | undefined;
|
|
127
|
+
constructor(code: CoreErrorCode, message: string, cause?: Error);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Core package error codes */
|
|
131
|
+
export declare type CoreErrorCode = 'ADAPTER_ERROR' | 'BRIDGE_ERROR' | 'VALIDATION_ERROR' | 'NOT_FOUND' | 'TIMEOUT' | 'ABORTED';
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Create an Anthropic-compatible embedding adapter.
|
|
135
|
+
*
|
|
136
|
+
* Note: Anthropic recommends Voyage AI for embeddings, so this adapter
|
|
137
|
+
* uses the Voyage AI API. The apiKey should be a Voyage AI API key.
|
|
138
|
+
*
|
|
139
|
+
* @param options - Adapter configuration
|
|
140
|
+
* @returns An embedding adapter for Anthropic/Voyage
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const adapter = createAnthropicEmbeddingAdapter({
|
|
145
|
+
* apiKey: process.env.VOYAGE_API_KEY,
|
|
146
|
+
* model: 'voyage-2',
|
|
147
|
+
* })
|
|
148
|
+
*
|
|
149
|
+
* const embeddings = await adapter.embed(['Hello, world!'])
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function createAnthropicEmbeddingAdapter(options: AnthropicEmbeddingAdapterOptions): EmbeddingAdapterInterface;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Create an Anthropic tool format adapter.
|
|
156
|
+
*
|
|
157
|
+
* @param options - Adapter options
|
|
158
|
+
* @returns A tool format adapter for Anthropic
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const adapter = createAnthropicToolFormatAdapter({
|
|
163
|
+
* toolChoice: 'auto',
|
|
164
|
+
* })
|
|
165
|
+
*
|
|
166
|
+
* const formatted = adapter.formatSchemas(schemas)
|
|
167
|
+
* const calls = adapter.parseToolCalls(response)
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function createAnthropicToolFormatAdapter(_options?: AnthropicToolFormatAdapterOptions): ToolFormatAdapterInterface;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Create a batched embedding adapter that wraps any embedding adapter.
|
|
174
|
+
*
|
|
175
|
+
* @param adapter - The base embedding adapter to wrap
|
|
176
|
+
* @param options - Batching configuration options
|
|
177
|
+
* @returns A batched embedding adapter instance
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const baseAdapter = createOpenAIEmbeddingAdapter({ apiKey: '...' })
|
|
182
|
+
* const cache = createEmbeddingCache({ maxEntries: 1000 })
|
|
183
|
+
*
|
|
184
|
+
* const batched = createBatchedEmbeddingAdapter(baseAdapter, {
|
|
185
|
+
* maxBatchSize: 100,
|
|
186
|
+
* flushDelayMs: 50,
|
|
187
|
+
* deduplicate: true,
|
|
188
|
+
* cache,
|
|
189
|
+
* })
|
|
190
|
+
*
|
|
191
|
+
* // These will be batched together
|
|
192
|
+
* const [e1, e2] = await Promise.all([
|
|
193
|
+
* batched.queue('text 1'),
|
|
194
|
+
* batched.queue('text 2'),
|
|
195
|
+
* ])
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function createBatchedEmbeddingAdapter(adapter: EmbeddingAdapterInterface, options?: EmbeddingBatchOptions): BatchedEmbeddingAdapterInterface;
|
|
199
|
+
|
|
200
|
+
/** Factory function for creating embedding cache */
|
|
201
|
+
export declare type CreateEmbeddingCache = (options?: EmbeddingCacheOptions) => EmbeddingCacheInterface;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Create an in-memory embedding cache with LRU eviction.
|
|
205
|
+
*
|
|
206
|
+
* @param options - Cache configuration options
|
|
207
|
+
* @returns An embedding cache instance
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const cache = createEmbeddingCache({
|
|
212
|
+
* maxEntries: 1000,
|
|
213
|
+
* ttlMs: 60 * 60 * 1000, // 1 hour
|
|
214
|
+
* })
|
|
215
|
+
*
|
|
216
|
+
* cache.set('hash123', embedding)
|
|
217
|
+
* const cached = cache.get('hash123')
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function createEmbeddingCache(options?: EmbeddingCacheOptions): EmbeddingCacheInterface;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Create a navigation guard that prevents leaving when form is dirty.
|
|
224
|
+
*
|
|
225
|
+
* @param options - Form dirty guard configuration options
|
|
226
|
+
* @returns A navigation guard function
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { createForm } from '@mikesaintsg/form'
|
|
231
|
+
* import { createFormDirtyGuard } from '@mikesaintsg/core'
|
|
232
|
+
*
|
|
233
|
+
* const form = createForm({ ... })
|
|
234
|
+
*
|
|
235
|
+
* const guard = createFormDirtyGuard({
|
|
236
|
+
* form,
|
|
237
|
+
* confirmFn: (message) => window.confirm(message),
|
|
238
|
+
* message: 'You have unsaved changes. Continue?',
|
|
239
|
+
* excludePages: ['settings'],
|
|
240
|
+
* })
|
|
241
|
+
*
|
|
242
|
+
* // Use with router
|
|
243
|
+
* router.beforeNavigate(guard)
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export declare function createFormDirtyGuard<TFormData = unknown, TPage extends string = string>(options: FormDirtyGuardOptions<TFormData, TPage>): NavigationGuard<TPage>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Create an HTTP persistence adapter for VectorStore.
|
|
250
|
+
*
|
|
251
|
+
* @param options - Adapter configuration
|
|
252
|
+
* @returns A persistence adapter using HTTP
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```ts
|
|
256
|
+
* const adapter = createHTTPVectorStorePersistence({
|
|
257
|
+
* baseURL: 'https://api.example.com/vectors',
|
|
258
|
+
* headers: { 'Authorization': 'Bearer token' },
|
|
259
|
+
* })
|
|
260
|
+
*
|
|
261
|
+
* await adapter.save({ id: 'doc1', content: 'hello', embedding: new Float32Array([...]) })
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export declare function createHTTPVectorStorePersistence(options: HTTPPersistenceOptions): VectorStorePersistenceAdapterInterface;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Create an IndexedDB persistence adapter for VectorStore.
|
|
268
|
+
*
|
|
269
|
+
* @param options - Adapter configuration
|
|
270
|
+
* @returns A persistence adapter using IndexedDB
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { createDatabase } from '@mikesaintsg/indexeddb'
|
|
275
|
+
*
|
|
276
|
+
* const db = await createDatabase({ name: 'vectors' })
|
|
277
|
+
* const adapter = createIndexedDBVectorStorePersistence({
|
|
278
|
+
* database: db,
|
|
279
|
+
* documentsStore: 'embeddings',
|
|
280
|
+
* })
|
|
281
|
+
*
|
|
282
|
+
* await adapter.save({ id: 'doc1', content: 'hello', embedding: new Float32Array([...]) })
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
export declare function createIndexedDBVectorStorePersistence(options: IndexedDBVectorStorePersistenceOptions): VectorStorePersistenceAdapterInterface;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Create an OpenAI embedding adapter.
|
|
289
|
+
*
|
|
290
|
+
* @param options - OpenAI adapter configuration
|
|
291
|
+
* @returns An embedding adapter for OpenAI
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* const adapter = createOpenAIEmbeddingAdapter({
|
|
296
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
297
|
+
* model: 'text-embedding-3-small',
|
|
298
|
+
* })
|
|
299
|
+
*
|
|
300
|
+
* const embeddings = await adapter.embed(['Hello, world!'])
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export declare function createOpenAIEmbeddingAdapter(options: OpenAIEmbeddingAdapterOptions): EmbeddingAdapterInterface;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Create an OpenAI tool format adapter.
|
|
307
|
+
*
|
|
308
|
+
* @param options - Adapter options
|
|
309
|
+
* @returns A tool format adapter for OpenAI
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* const adapter = createOpenAIToolFormatAdapter({
|
|
314
|
+
* toolChoice: 'auto',
|
|
315
|
+
* })
|
|
316
|
+
*
|
|
317
|
+
* const formatted = adapter.formatSchemas(schemas)
|
|
318
|
+
* const calls = adapter.parseToolCalls(response)
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export declare function createOpenAIToolFormatAdapter(_options?: OpenAIToolFormatAdapterOptions): ToolFormatAdapterInterface;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Create an OPFS persistence adapter for VectorStore.
|
|
325
|
+
*
|
|
326
|
+
* @param options - Adapter configuration
|
|
327
|
+
* @returns A persistence adapter using OPFS
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* import { createDirectory } from '@mikesaintsg/filesystem'
|
|
332
|
+
*
|
|
333
|
+
* const dir = await createDirectory({ name: 'vectors' })
|
|
334
|
+
* const adapter = createOPFSVectorStorePersistence({
|
|
335
|
+
* directory: dir,
|
|
336
|
+
* chunkSize: 50,
|
|
337
|
+
* })
|
|
338
|
+
*
|
|
339
|
+
* await adapter.save({ id: 'doc1', content: 'hello', embedding: new Float32Array([...]) })
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
export declare function createOPFSVectorStorePersistence(options: OPFSVectorStorePersistenceOptions): VectorStorePersistenceAdapterInterface;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Create a retrieval tool for use with contextprotocol tool registry.
|
|
346
|
+
*
|
|
347
|
+
* @param options - Retrieval tool configuration options
|
|
348
|
+
* @returns A tool schema and handler for registration
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { createVectorStore } from '@mikesaintsg/vectorstore'
|
|
353
|
+
* import { createToolRegistry } from '@mikesaintsg/contextprotocol'
|
|
354
|
+
* import { createRetrievalTool } from '@mikesaintsg/core'
|
|
355
|
+
*
|
|
356
|
+
* const vectorStore = createVectorStore({ ... })
|
|
357
|
+
* const registry = createToolRegistry()
|
|
358
|
+
*
|
|
359
|
+
* const { schema, handler } = createRetrievalTool({
|
|
360
|
+
* vectorStore,
|
|
361
|
+
* name: 'search_docs',
|
|
362
|
+
* description: 'Search documentation for relevant information',
|
|
363
|
+
* defaultLimit: 5,
|
|
364
|
+
* scoreThreshold: 0.7,
|
|
365
|
+
* })
|
|
366
|
+
*
|
|
367
|
+
* registry.register({ ...schema, execute: handler })
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export declare function createRetrievalTool<TMetadata = unknown>(options: RetrievalToolOptions<TMetadata>): RetrievalToolCreated;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Create a session persistence adapter for storing inference sessions.
|
|
374
|
+
*
|
|
375
|
+
* @param options - Session persistence configuration options
|
|
376
|
+
* @returns A session persistence instance
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { createDatabase } from '@mikesaintsg/indexeddb'
|
|
381
|
+
* import { createSessionPersistence } from '@mikesaintsg/core'
|
|
382
|
+
*
|
|
383
|
+
* const db = await createDatabase({ name: 'sessions' })
|
|
384
|
+
* const persistence = createSessionPersistence({
|
|
385
|
+
* database: db,
|
|
386
|
+
* storeName: 'chat_sessions',
|
|
387
|
+
* autoprune: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
388
|
+
* })
|
|
389
|
+
*
|
|
390
|
+
* // Save session
|
|
391
|
+
* await persistence.save('session-1', session)
|
|
392
|
+
*
|
|
393
|
+
* // Load session
|
|
394
|
+
* const savedSession = await persistence.load('session-1')
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
export declare function createSessionPersistence(options: SessionPersistenceOptions): SessionPersistenceInterface;
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Create a tool call bridge.
|
|
401
|
+
*
|
|
402
|
+
* @param options - Bridge configuration options
|
|
403
|
+
* @returns A tool call bridge instance
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* import { createToolRegistry } from '@mikesaintsg/contextprotocol'
|
|
408
|
+
* import { createToolCallBridge } from '@mikesaintsg/core'
|
|
409
|
+
*
|
|
410
|
+
* const registry = createToolRegistry()
|
|
411
|
+
* registry.register(weatherTool)
|
|
412
|
+
*
|
|
413
|
+
* const bridge = createToolCallBridge({
|
|
414
|
+
* registry,
|
|
415
|
+
* timeout: 30000,
|
|
416
|
+
* onError: (error, toolCall) => console.error(`Tool ${toolCall.name} failed:`, error),
|
|
417
|
+
* })
|
|
418
|
+
*
|
|
419
|
+
* // Execute tool calls from LLM response
|
|
420
|
+
* const results = await bridge.executeAll(response.toolCalls)
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
export declare function createToolCallBridge(options: ToolCallBridgeOptions): ToolCallBridgeInterface;
|
|
424
|
+
|
|
425
|
+
/** Deduplication result summary */
|
|
426
|
+
export declare interface DeduplicationResult {
|
|
427
|
+
readonly originalCount: number;
|
|
428
|
+
readonly deduplicatedCount: number;
|
|
429
|
+
readonly removedFrames: readonly ContextFrame[];
|
|
430
|
+
readonly mergedFrames: readonly ContextFrame[];
|
|
431
|
+
readonly tokensSaved: number;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Deserialize a stored document from JSON storage.
|
|
436
|
+
* Converts array embeddings back to Float32Array.
|
|
437
|
+
*
|
|
438
|
+
* @param data - The plain object from JSON.parse
|
|
439
|
+
* @returns A StoredDocument with proper Float32Array embedding
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* const data = JSON.parse(json)
|
|
444
|
+
* const doc = deserializeStoredDocument(data)
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
export declare function deserializeStoredDocument(data: Record<string, unknown>): StoredDocument;
|
|
448
|
+
|
|
449
|
+
/** Base ecosystem error */
|
|
450
|
+
export declare abstract class EcosystemError extends Error {
|
|
451
|
+
abstract readonly code: string;
|
|
452
|
+
readonly cause: Error | undefined;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Embedding vector */
|
|
456
|
+
export declare type Embedding = Float32Array;
|
|
457
|
+
|
|
458
|
+
/** Default flush delay in milliseconds for batched embeddings */
|
|
459
|
+
export declare const EMBEDDING_BATCH_DEFAULT_FLUSH_DELAY_MS = 50;
|
|
460
|
+
|
|
461
|
+
/** Default maximum batch size for embedding requests */
|
|
462
|
+
export declare const EMBEDDING_BATCH_DEFAULT_MAX_SIZE = 100;
|
|
463
|
+
|
|
464
|
+
/** Default maximum entries for embedding cache */
|
|
465
|
+
export declare const EMBEDDING_CACHE_DEFAULT_MAX_ENTRIES = 1000;
|
|
466
|
+
|
|
467
|
+
/** Embedding generation contract */
|
|
468
|
+
export declare interface EmbeddingAdapterInterface {
|
|
469
|
+
embed(texts: readonly string[], options?: AbortableOptions): Promise<readonly Embedding[]>;
|
|
470
|
+
getModelMetadata(): EmbeddingModelMetadata;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** Embedding batch options */
|
|
474
|
+
export declare interface EmbeddingBatchOptions {
|
|
475
|
+
readonly maxBatchSize?: number;
|
|
476
|
+
readonly flushDelayMs?: number;
|
|
477
|
+
readonly deduplicate?: boolean;
|
|
478
|
+
readonly cache?: EmbeddingCacheInterface;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** Embedding cache entry */
|
|
482
|
+
export declare interface EmbeddingCacheEntry {
|
|
483
|
+
readonly embedding: Embedding;
|
|
484
|
+
readonly contentHash: ContentHash;
|
|
485
|
+
readonly modelId: string;
|
|
486
|
+
readonly createdAt: number;
|
|
487
|
+
readonly hitCount: number;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** Embedding cache interface */
|
|
491
|
+
export declare interface EmbeddingCacheInterface {
|
|
492
|
+
get(contentHash: ContentHash): Embedding | undefined;
|
|
493
|
+
set(contentHash: ContentHash, embedding: Embedding): void;
|
|
494
|
+
has(contentHash: ContentHash): boolean;
|
|
495
|
+
remove(contentHash: ContentHash): boolean;
|
|
496
|
+
clear(): void;
|
|
497
|
+
getStats(): EmbeddingCacheStats;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** LRU cache eviction options */
|
|
501
|
+
export declare interface EmbeddingCacheOptions {
|
|
502
|
+
readonly maxEntries?: number;
|
|
503
|
+
readonly maxBytes?: number;
|
|
504
|
+
readonly ttlMs?: number;
|
|
505
|
+
readonly onEvict?: (contentHash: ContentHash, embedding: Embedding) => void;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Embedding cache statistics */
|
|
509
|
+
export declare interface EmbeddingCacheStats {
|
|
510
|
+
readonly entries: number;
|
|
511
|
+
readonly hits: number;
|
|
512
|
+
readonly misses: number;
|
|
513
|
+
readonly hitRate: number;
|
|
514
|
+
readonly estimatedBytes: number;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/** Embedding model info */
|
|
518
|
+
export declare interface EmbeddingModelMetadata {
|
|
519
|
+
readonly provider: string;
|
|
520
|
+
readonly model: string;
|
|
521
|
+
readonly dimensions: number;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** Failure result */
|
|
525
|
+
export declare interface Err<E> {
|
|
526
|
+
readonly ok: false;
|
|
527
|
+
readonly error: E;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Create a failure result.
|
|
532
|
+
*
|
|
533
|
+
* @param error - The error value
|
|
534
|
+
* @returns An Err result containing the error
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* const result = err('NOT_FOUND')
|
|
539
|
+
* // result.ok === false
|
|
540
|
+
* // result.error === 'NOT_FOUND'
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
export declare function err<E>(error: E): Err<E>;
|
|
544
|
+
|
|
545
|
+
/** Extract error code type */
|
|
546
|
+
export declare type ErrorCode<T extends EcosystemError> = T['code'];
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Estimate the byte size of an embedding.
|
|
550
|
+
*
|
|
551
|
+
* @param embedding - The embedding to measure
|
|
552
|
+
* @returns The byte length of the embedding
|
|
553
|
+
*/
|
|
554
|
+
export declare function estimateEmbeddingBytes(embedding: Embedding): number;
|
|
555
|
+
|
|
556
|
+
/** Default form dirty guard message */
|
|
557
|
+
export declare const FORM_DIRTY_DEFAULT_MESSAGE = "You have unsaved changes. Are you sure you want to leave?";
|
|
558
|
+
|
|
559
|
+
/** Form dirty guard options */
|
|
560
|
+
export declare interface FormDirtyGuardOptions<TFormData = unknown, TPage extends string = string> {
|
|
561
|
+
readonly form: FormMinimal<TFormData>;
|
|
562
|
+
readonly confirmFn: (message: string) => Promise<boolean> | boolean;
|
|
563
|
+
readonly message?: string;
|
|
564
|
+
readonly excludePages?: readonly TPage[];
|
|
565
|
+
readonly onlyFromPages?: readonly TPage[];
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Minimal form interface for bridge functions.
|
|
570
|
+
* Avoids hard dependency on form packages.
|
|
571
|
+
*/
|
|
572
|
+
export declare interface FormMinimal<_TFormData = unknown> {
|
|
573
|
+
isDirty(): boolean;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** Frame metadata */
|
|
577
|
+
export declare interface FrameMetadata {
|
|
578
|
+
readonly sectionId?: string;
|
|
579
|
+
readonly filePath?: string;
|
|
580
|
+
readonly fileVersion?: number;
|
|
581
|
+
readonly toolName?: string;
|
|
582
|
+
readonly score?: number;
|
|
583
|
+
readonly tags?: readonly string[];
|
|
584
|
+
readonly expiresAt?: number;
|
|
585
|
+
readonly source?: string;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/** Frame priority levels */
|
|
589
|
+
export declare type FramePriority = 'critical' | 'high' | 'normal' | 'low' | 'optional';
|
|
590
|
+
|
|
591
|
+
/** Frame summary for reporting */
|
|
592
|
+
export declare interface FrameSummary {
|
|
593
|
+
readonly id: string;
|
|
594
|
+
readonly type: FrameType;
|
|
595
|
+
readonly tokenEstimate: number;
|
|
596
|
+
readonly reason: TruncationReason;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** Frame type discriminator */
|
|
600
|
+
export declare type FrameType = 'system' | 'instruction' | 'section' | 'file' | 'document' | 'example' | 'tool' | 'memory' | 'retrieval' | 'custom';
|
|
601
|
+
|
|
602
|
+
/** Generation defaults for provider adapters */
|
|
603
|
+
export declare interface GenerationDefaults {
|
|
604
|
+
readonly temperature?: number;
|
|
605
|
+
readonly maxTokens?: number;
|
|
606
|
+
readonly topP?: number;
|
|
607
|
+
readonly stop?: readonly string[];
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** Default timeout for HTTP persistence requests in milliseconds */
|
|
611
|
+
export declare const HTTP_DEFAULT_TIMEOUT = 30000;
|
|
612
|
+
|
|
613
|
+
/** HTTP persistence options */
|
|
614
|
+
export declare interface HTTPPersistenceOptions {
|
|
615
|
+
readonly baseURL: string;
|
|
616
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
617
|
+
readonly timeout?: number;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** Default documents store name for IndexedDB persistence */
|
|
621
|
+
export declare const INDEXEDDB_DEFAULT_DOCUMENTS_STORE = "documents";
|
|
622
|
+
|
|
623
|
+
/** Default metadata store name for IndexedDB persistence */
|
|
624
|
+
export declare const INDEXEDDB_DEFAULT_METADATA_STORE = "metadata";
|
|
625
|
+
|
|
626
|
+
/** IndexedDB VectorStore persistence options */
|
|
627
|
+
export declare interface IndexedDBVectorStorePersistenceOptions {
|
|
628
|
+
readonly database: MinimalDatabaseAccess;
|
|
629
|
+
readonly documentsStore?: string;
|
|
630
|
+
readonly metadataStore?: string;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** In-memory embedding cache options */
|
|
634
|
+
export declare interface InMemoryEmbeddingCacheOptions {
|
|
635
|
+
readonly maxEntries?: number;
|
|
636
|
+
readonly ttlMs?: number;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Type guard to check if an error is a CoreError.
|
|
641
|
+
*
|
|
642
|
+
* @param error - The value to check
|
|
643
|
+
* @returns True if the error is a CoreError
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```ts
|
|
647
|
+
* try {
|
|
648
|
+
* await adapter.embed(['text'])
|
|
649
|
+
* } catch (error) {
|
|
650
|
+
* if (isCoreError(error)) {
|
|
651
|
+
* console.log('Code:', error.code)
|
|
652
|
+
* }
|
|
653
|
+
* }
|
|
654
|
+
* ```
|
|
655
|
+
*/
|
|
656
|
+
export declare function isCoreError(error: unknown): error is CoreError;
|
|
657
|
+
|
|
658
|
+
/** Type guard for ecosystem errors */
|
|
659
|
+
export declare function isEcosystemError(error: unknown): error is EcosystemError;
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Check if a result is a failure.
|
|
663
|
+
*
|
|
664
|
+
* @param result - The result to check
|
|
665
|
+
* @returns True if the result is Err, false otherwise
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```ts
|
|
669
|
+
* const result: Result<number, string> = err('NOT_FOUND')
|
|
670
|
+
* if (isErr(result)) {
|
|
671
|
+
* console.log(result.error) // TypeScript knows result is Err<string>
|
|
672
|
+
* }
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Check if a result is a success.
|
|
679
|
+
*
|
|
680
|
+
* @param result - The result to check
|
|
681
|
+
* @returns True if the result is Ok, false otherwise
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* const result: Result<number, string> = ok(42)
|
|
686
|
+
* if (isOk(result)) {
|
|
687
|
+
* console.log(result.value) // TypeScript knows result is Ok<number>
|
|
688
|
+
* }
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
|
|
692
|
+
|
|
693
|
+
/** JSON Schema 7 subset for tool parameters */
|
|
694
|
+
export declare interface JSONSchema7 {
|
|
695
|
+
readonly type?: string | readonly string[];
|
|
696
|
+
readonly properties?: Readonly<Record<string, JSONSchema7>>;
|
|
697
|
+
readonly items?: JSONSchema7 | readonly JSONSchema7[];
|
|
698
|
+
readonly required?: readonly string[];
|
|
699
|
+
readonly enum?: readonly unknown[];
|
|
700
|
+
readonly const?: unknown;
|
|
701
|
+
readonly format?: string;
|
|
702
|
+
readonly minimum?: number;
|
|
703
|
+
readonly maximum?: number;
|
|
704
|
+
readonly minLength?: number;
|
|
705
|
+
readonly maxLength?: number;
|
|
706
|
+
readonly pattern?: string;
|
|
707
|
+
readonly description?: string;
|
|
708
|
+
readonly default?: unknown;
|
|
709
|
+
readonly additionalProperties?: boolean | JSONSchema7;
|
|
710
|
+
readonly anyOf?: readonly JSONSchema7[];
|
|
711
|
+
readonly oneOf?: readonly JSONSchema7[];
|
|
712
|
+
readonly allOf?: readonly JSONSchema7[];
|
|
713
|
+
readonly $ref?: string;
|
|
714
|
+
readonly definitions?: Readonly<Record<string, JSONSchema7>>;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/** Internal LRU cache entry with access tracking */
|
|
718
|
+
export declare interface LRUCacheEntry {
|
|
719
|
+
readonly embedding: Embedding;
|
|
720
|
+
readonly createdAt: number;
|
|
721
|
+
hitCount: number;
|
|
722
|
+
lastAccess: number;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Map a function over a success value.
|
|
727
|
+
*
|
|
728
|
+
* @param result - The result to map over
|
|
729
|
+
* @param fn - Function to apply to the success value
|
|
730
|
+
* @returns A new result with the mapped value, or the original error
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* ```ts
|
|
734
|
+
* const doubled = map(ok(5), x => x * 2) // ok(10)
|
|
735
|
+
* const failed = map(err('oops'), x => x * 2) // err('oops')
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
738
|
+
export declare function map<T, U, E>(result: Result<T, E>, fn: (value: T) => U): Result<U, E>;
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Map a function over an error value.
|
|
742
|
+
*
|
|
743
|
+
* @param result - The result to map over
|
|
744
|
+
* @param fn - Function to apply to the error value
|
|
745
|
+
* @returns A new result with the mapped error, or the original value
|
|
746
|
+
*
|
|
747
|
+
* @example
|
|
748
|
+
* ```ts
|
|
749
|
+
* const wrapped = mapErr(err('oops'), e => new Error(e)) // err(Error('oops'))
|
|
750
|
+
* const unchanged = mapErr(ok(42), e => new Error(e)) // ok(42)
|
|
751
|
+
* ```
|
|
752
|
+
*/
|
|
753
|
+
export declare function mapErr<T, E, F>(result: Result<T, E>, fn: (error: E) => F): Result<T, F>;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Minimal database access interface for cross-package adapters.
|
|
757
|
+
* Used by vectorstore persistence adapters to access IndexedDB without
|
|
758
|
+
* creating a hard dependency on the indexeddb package.
|
|
759
|
+
*/
|
|
760
|
+
export declare interface MinimalDatabaseAccess<T = unknown> {
|
|
761
|
+
store<S extends T>(name: string): MinimalStoreAccess<S>;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Minimal directory access interface for cross-package adapters.
|
|
766
|
+
* Used by vectorstore OPFS persistence adapters without creating
|
|
767
|
+
* a hard dependency on the filesystem package.
|
|
768
|
+
*/
|
|
769
|
+
export declare interface MinimalDirectoryAccess {
|
|
770
|
+
getFile(name: string): Promise<MinimalFileAccess | undefined>;
|
|
771
|
+
createFile(name: string): Promise<MinimalFileAccess>;
|
|
772
|
+
hasFile(name: string): Promise<boolean>;
|
|
773
|
+
removeFile(name: string): Promise<void>;
|
|
774
|
+
listFiles(): Promise<readonly MinimalFileAccess[]>;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Minimal file access interface for cross-package adapters.
|
|
779
|
+
*/
|
|
780
|
+
export declare interface MinimalFileAccess {
|
|
781
|
+
getName(): string;
|
|
782
|
+
getText(): Promise<string>;
|
|
783
|
+
getArrayBuffer(): Promise<ArrayBuffer>;
|
|
784
|
+
write(data: string | ArrayBuffer): Promise<void>;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Minimal store access interface for cross-package adapters.
|
|
789
|
+
* Provides only the operations needed by persistence adapters.
|
|
790
|
+
*/
|
|
791
|
+
export declare interface MinimalStoreAccess<T> {
|
|
792
|
+
get(key: IDBValidKey): Promise<T | undefined>;
|
|
793
|
+
set(value: T, key?: IDBValidKey): Promise<IDBValidKey>;
|
|
794
|
+
remove(key: IDBValidKey): Promise<void>;
|
|
795
|
+
all(): Promise<readonly T[]>;
|
|
796
|
+
clear(): Promise<void>;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Navigation guard function type.
|
|
801
|
+
* Returns true to allow navigation, false to block.
|
|
802
|
+
*/
|
|
803
|
+
export declare type NavigationGuard<TPage extends string = string> = (to: TPage, from: TPage) => Promise<boolean> | boolean;
|
|
804
|
+
|
|
805
|
+
/** Success result */
|
|
806
|
+
export declare interface Ok<T> {
|
|
807
|
+
readonly ok: true;
|
|
808
|
+
readonly value: T;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Create a success result.
|
|
813
|
+
*
|
|
814
|
+
* @param value - The success value
|
|
815
|
+
* @returns An Ok result containing the value
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```ts
|
|
819
|
+
* const result = ok(42)
|
|
820
|
+
* // result.ok === true
|
|
821
|
+
* // result.value === 42
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
export declare function ok<T>(value: T): Ok<T>;
|
|
825
|
+
|
|
826
|
+
/** OpenAI API base URL */
|
|
827
|
+
export declare const OPENAI_API_BASE_URL = "https://api.openai.com/v1";
|
|
828
|
+
|
|
829
|
+
/** Default dimensions for OpenAI text-embedding-3-small */
|
|
830
|
+
export declare const OPENAI_DEFAULT_EMBEDDING_DIMENSIONS = 1536;
|
|
831
|
+
|
|
832
|
+
/** Default OpenAI embedding model */
|
|
833
|
+
export declare const OPENAI_DEFAULT_EMBEDDING_MODEL = "text-embedding-3-small";
|
|
834
|
+
|
|
835
|
+
/** OpenAI embedding adapter options */
|
|
836
|
+
export declare interface OpenAIEmbeddingAdapterOptions {
|
|
837
|
+
readonly apiKey: string;
|
|
838
|
+
readonly model?: string;
|
|
839
|
+
readonly baseURL?: string;
|
|
840
|
+
readonly dimensions?: number;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/** OpenAI embedding data item */
|
|
844
|
+
export declare interface OpenAIEmbeddingData {
|
|
845
|
+
readonly object: 'embedding';
|
|
846
|
+
readonly index: number;
|
|
847
|
+
readonly embedding: readonly number[];
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** OpenAI embedding API response */
|
|
851
|
+
export declare interface OpenAIEmbeddingResponse {
|
|
852
|
+
readonly object: 'list';
|
|
853
|
+
readonly data: readonly OpenAIEmbeddingData[];
|
|
854
|
+
readonly model: string;
|
|
855
|
+
readonly usage: OpenAIEmbeddingUsage;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/** OpenAI embedding usage stats */
|
|
859
|
+
export declare interface OpenAIEmbeddingUsage {
|
|
860
|
+
readonly prompt_tokens: number;
|
|
861
|
+
readonly total_tokens: number;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/** OpenAI provider adapter options */
|
|
865
|
+
export declare interface OpenAIProviderAdapterOptions {
|
|
866
|
+
readonly apiKey: string;
|
|
867
|
+
readonly model?: string;
|
|
868
|
+
readonly baseURL?: string;
|
|
869
|
+
readonly organization?: string;
|
|
870
|
+
readonly defaultOptions?: GenerationDefaults;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/** OpenAI tool schema format */
|
|
874
|
+
export declare interface OpenAITool {
|
|
875
|
+
readonly type: 'function';
|
|
876
|
+
readonly function: OpenAIToolFunction;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** OpenAI tool call from response */
|
|
880
|
+
export declare interface OpenAIToolCall {
|
|
881
|
+
readonly id: string;
|
|
882
|
+
readonly type: 'function';
|
|
883
|
+
readonly function: OpenAIToolCallFunction;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** OpenAI tool call function */
|
|
887
|
+
export declare interface OpenAIToolCallFunction {
|
|
888
|
+
readonly name: string;
|
|
889
|
+
readonly arguments: string;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/** OpenAI tool format adapter options */
|
|
893
|
+
export declare interface OpenAIToolFormatAdapterOptions {
|
|
894
|
+
readonly toolChoice?: 'auto' | 'none' | 'required' | {
|
|
895
|
+
readonly name: string;
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/** OpenAI tool function definition */
|
|
900
|
+
export declare interface OpenAIToolFunction {
|
|
901
|
+
readonly name: string;
|
|
902
|
+
readonly description: string;
|
|
903
|
+
readonly parameters: unknown;
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/** Default chunk size for OPFS persistence */
|
|
907
|
+
export declare const OPFS_DEFAULT_CHUNK_SIZE = 100;
|
|
908
|
+
|
|
909
|
+
/** Documents file name prefix for OPFS persistence */
|
|
910
|
+
export declare const OPFS_DOCUMENTS_PREFIX = "chunk_";
|
|
911
|
+
|
|
912
|
+
/** Metadata file name for OPFS persistence */
|
|
913
|
+
export declare const OPFS_METADATA_FILE = "_metadata.json";
|
|
914
|
+
|
|
915
|
+
/** OPFS VectorStore persistence options */
|
|
916
|
+
export declare interface OPFSVectorStorePersistenceOptions {
|
|
917
|
+
readonly directory: MinimalDirectoryAccess;
|
|
918
|
+
readonly chunkSize?: number;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* Generic error data interface for package-specific errors.
|
|
923
|
+
* Use this as a base for error data interfaces in packages.
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```ts
|
|
927
|
+
* export type MyErrorCode = 'NOT_FOUND' | 'INVALID' | 'TIMEOUT'
|
|
928
|
+
* export interface MyErrorData extends PackageErrorData<MyErrorCode> {
|
|
929
|
+
* readonly extra?: string
|
|
930
|
+
* }
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
933
|
+
export declare interface PackageErrorData<TCode extends string> {
|
|
934
|
+
readonly code: TCode;
|
|
935
|
+
readonly cause?: Error;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/** Pending embedding request in batch queue */
|
|
939
|
+
export declare interface PendingEmbeddingRequest {
|
|
940
|
+
readonly text: string;
|
|
941
|
+
readonly contentHash: ContentHash;
|
|
942
|
+
resolve: (embedding: Embedding) => void;
|
|
943
|
+
reject: (error: unknown) => void;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Provider adapter interface for LLM providers.
|
|
948
|
+
* Implemented by OpenAI, Anthropic, and other provider adapters.
|
|
949
|
+
*/
|
|
950
|
+
export declare interface ProviderAdapterInterface {
|
|
951
|
+
getId(): string;
|
|
952
|
+
supportsTools(): boolean;
|
|
953
|
+
supportsStreaming(): boolean;
|
|
954
|
+
getCapabilities(): ProviderCapabilities;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/** Provider capabilities information */
|
|
958
|
+
export declare interface ProviderCapabilities {
|
|
959
|
+
readonly supportsTools: boolean;
|
|
960
|
+
readonly supportsStreaming: boolean;
|
|
961
|
+
readonly supportsVision: boolean;
|
|
962
|
+
readonly supportsFunctions: boolean;
|
|
963
|
+
readonly models: readonly string[];
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/** Prune result information */
|
|
967
|
+
export declare interface PruneResult {
|
|
968
|
+
readonly prunedCount: number;
|
|
969
|
+
readonly remainingCount: number;
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/** Result union */
|
|
973
|
+
export declare type Result<T, E> = Ok<T> | Err<E>;
|
|
974
|
+
|
|
975
|
+
/** Default retrieval limit for retrieval tool */
|
|
976
|
+
export declare const RETRIEVAL_DEFAULT_LIMIT = 10;
|
|
977
|
+
|
|
978
|
+
/** Maximum retrieval limit for retrieval tool */
|
|
979
|
+
export declare const RETRIEVAL_MAX_LIMIT = 100;
|
|
980
|
+
|
|
981
|
+
/** Retrieval tool created by factory */
|
|
982
|
+
export declare interface RetrievalToolCreated {
|
|
983
|
+
readonly schema: ToolSchema;
|
|
984
|
+
readonly handler: (args: Readonly<Record<string, unknown>>) => Promise<readonly unknown[]>;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
/** Retrieval tool factory options */
|
|
988
|
+
export declare interface RetrievalToolOptions<TMetadata = unknown> {
|
|
989
|
+
readonly vectorStore: VectorStoreMinimal<TMetadata>;
|
|
990
|
+
readonly name: string;
|
|
991
|
+
readonly description: string;
|
|
992
|
+
readonly defaultLimit?: number;
|
|
993
|
+
readonly maxLimit?: number;
|
|
994
|
+
readonly scoreThreshold?: number;
|
|
995
|
+
readonly formatResult?: (result: ScoredResult) => unknown;
|
|
996
|
+
readonly extendParameters?: Readonly<Record<string, JSONSchema7>>;
|
|
997
|
+
readonly buildFilter?: (params: Readonly<Record<string, unknown>>) => TMetadata | undefined;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/** Scored result from similarity search or retrieval */
|
|
1001
|
+
export declare interface ScoredResult {
|
|
1002
|
+
readonly id: string;
|
|
1003
|
+
readonly content: string;
|
|
1004
|
+
readonly score: number;
|
|
1005
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1006
|
+
readonly embedding?: Embedding;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Minimal session interface for serialization.
|
|
1011
|
+
* Avoids hard dependency on inference package.
|
|
1012
|
+
*/
|
|
1013
|
+
export declare interface SerializableSession {
|
|
1014
|
+
getMessages(): readonly SerializedMessage[];
|
|
1015
|
+
getMetadata(): SessionMetadata;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** Serialized message for persistence */
|
|
1019
|
+
export declare interface SerializedMessage {
|
|
1020
|
+
readonly role: 'user' | 'assistant' | 'system' | 'tool';
|
|
1021
|
+
readonly content: string;
|
|
1022
|
+
readonly toolCalls?: readonly ToolCall[];
|
|
1023
|
+
readonly toolResult?: ToolResult;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** Serialized session for storage */
|
|
1027
|
+
export declare interface SerializedSession {
|
|
1028
|
+
readonly id: string;
|
|
1029
|
+
readonly messages: readonly SerializedMessage[];
|
|
1030
|
+
readonly metadata: SessionMetadata;
|
|
1031
|
+
readonly updatedAt: number;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Serialize a stored document for JSON storage.
|
|
1036
|
+
* Converts Float32Array embeddings to regular arrays.
|
|
1037
|
+
*
|
|
1038
|
+
* @param doc - The document to serialize
|
|
1039
|
+
* @returns A plain object suitable for JSON.stringify
|
|
1040
|
+
*
|
|
1041
|
+
* @example
|
|
1042
|
+
* ```ts
|
|
1043
|
+
* const serialized = serializeStoredDocument(doc)
|
|
1044
|
+
* const json = JSON.stringify(serialized)
|
|
1045
|
+
* ```
|
|
1046
|
+
*/
|
|
1047
|
+
export declare function serializeStoredDocument(doc: StoredDocument): Record<string, unknown>;
|
|
1048
|
+
|
|
1049
|
+
/** Session metadata for persistence */
|
|
1050
|
+
export declare interface SessionMetadata {
|
|
1051
|
+
readonly model: string;
|
|
1052
|
+
readonly provider: string;
|
|
1053
|
+
readonly createdAt: number;
|
|
1054
|
+
readonly system?: string;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
/**
|
|
1058
|
+
* Session persistence interface.
|
|
1059
|
+
* Connects inference sessions to IndexedDB storage.
|
|
1060
|
+
*/
|
|
1061
|
+
export declare interface SessionPersistenceInterface {
|
|
1062
|
+
save(id: string, session: SerializableSession): Promise<void>;
|
|
1063
|
+
load(id: string): Promise<SerializedSession | undefined>;
|
|
1064
|
+
delete(id: string): Promise<void>;
|
|
1065
|
+
list(): Promise<readonly string[]>;
|
|
1066
|
+
prune(maxAgeMs: number): Promise<number>;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/** Session persistence options */
|
|
1070
|
+
export declare interface SessionPersistenceOptions {
|
|
1071
|
+
readonly database: MinimalDatabaseAccess;
|
|
1072
|
+
readonly storeName: string;
|
|
1073
|
+
readonly autoprune?: number;
|
|
1074
|
+
readonly onSaveError?: (error: unknown, sessionId: string) => void;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/** Storage information (quota and usage) */
|
|
1078
|
+
export declare interface StorageInfo {
|
|
1079
|
+
readonly usage: number;
|
|
1080
|
+
readonly quota: number;
|
|
1081
|
+
readonly available: number;
|
|
1082
|
+
readonly percentUsed: number;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/** Stored document for persistence */
|
|
1086
|
+
export declare interface StoredDocument {
|
|
1087
|
+
readonly id: string;
|
|
1088
|
+
readonly content: string;
|
|
1089
|
+
readonly embedding: Embedding;
|
|
1090
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
1091
|
+
readonly contentHash?: ContentHash;
|
|
1092
|
+
readonly createdAt?: number;
|
|
1093
|
+
readonly updatedAt?: number;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/** Converts subscription methods to hook callbacks for options */
|
|
1097
|
+
export declare type SubscriptionToHook<T> = {
|
|
1098
|
+
[K in keyof T]?: T[K] extends (callback: infer CB) => Unsubscribe ? CB : never;
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
/** Token budget level */
|
|
1102
|
+
export declare type TokenBudgetLevel = 'ok' | 'warning' | 'critical' | 'exceeded';
|
|
1103
|
+
|
|
1104
|
+
/** Token budget state */
|
|
1105
|
+
export declare interface TokenBudgetState {
|
|
1106
|
+
readonly used: number;
|
|
1107
|
+
readonly available: number;
|
|
1108
|
+
readonly reserved: number;
|
|
1109
|
+
readonly max: number;
|
|
1110
|
+
readonly usage: number;
|
|
1111
|
+
readonly level: TokenBudgetLevel;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/** Tool call from LLM response */
|
|
1115
|
+
export declare interface ToolCall {
|
|
1116
|
+
readonly id: string;
|
|
1117
|
+
readonly name: string;
|
|
1118
|
+
readonly arguments: Record<string, unknown>;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Tool call bridge interface.
|
|
1123
|
+
* Connects inference tool calls to contextprotocol tool registry.
|
|
1124
|
+
*/
|
|
1125
|
+
export declare interface ToolCallBridgeInterface {
|
|
1126
|
+
execute(toolCall: ToolCall): Promise<ToolResult>;
|
|
1127
|
+
executeAll(toolCalls: readonly ToolCall[]): Promise<readonly ToolResult[]>;
|
|
1128
|
+
hasTool(name: string): boolean;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/** Tool call bridge options */
|
|
1132
|
+
export declare interface ToolCallBridgeOptions {
|
|
1133
|
+
readonly registry: ToolRegistryMinimal;
|
|
1134
|
+
readonly timeout?: number;
|
|
1135
|
+
readonly onError?: (error: unknown, toolCall: ToolCall) => void;
|
|
1136
|
+
readonly onBeforeExecute?: (toolCall: ToolCall) => void;
|
|
1137
|
+
readonly onAfterExecute?: (toolCall: ToolCall, result: unknown) => void;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* Tool format adapter interface.
|
|
1142
|
+
* Converts between internal tool representations and provider-specific formats.
|
|
1143
|
+
*/
|
|
1144
|
+
export declare interface ToolFormatAdapterInterface {
|
|
1145
|
+
formatSchemas(schemas: readonly ToolSchema[]): unknown;
|
|
1146
|
+
parseToolCalls(response: unknown): readonly ToolCall[];
|
|
1147
|
+
formatResult(result: ToolResult): unknown;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Minimal tool registry interface for bridge functions.
|
|
1152
|
+
* Avoids hard dependency on contextprotocol package.
|
|
1153
|
+
*/
|
|
1154
|
+
export declare interface ToolRegistryMinimal {
|
|
1155
|
+
has(name: string): boolean;
|
|
1156
|
+
execute(name: string, args: Readonly<Record<string, unknown>>): Promise<unknown>;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/** Tool execution result */
|
|
1160
|
+
export declare interface ToolResult {
|
|
1161
|
+
readonly callId: string;
|
|
1162
|
+
readonly name: string;
|
|
1163
|
+
readonly success: boolean;
|
|
1164
|
+
readonly value?: unknown;
|
|
1165
|
+
readonly error?: string;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
/** Tool schema definition */
|
|
1169
|
+
export declare interface ToolSchema {
|
|
1170
|
+
readonly name: string;
|
|
1171
|
+
readonly description: string;
|
|
1172
|
+
readonly parameters: JSONSchema7;
|
|
1173
|
+
readonly returns?: JSONSchema7;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/** Truncation information */
|
|
1177
|
+
export declare interface TruncationInfo {
|
|
1178
|
+
readonly originalFrameCount: number;
|
|
1179
|
+
readonly keptFrameCount: number;
|
|
1180
|
+
readonly removedFrames: readonly FrameSummary[];
|
|
1181
|
+
readonly strategy: TruncationStrategy;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/** Why a frame was truncated */
|
|
1185
|
+
export declare type TruncationReason = 'budget_exceeded' | 'priority_too_low' | 'expired' | 'deduplicated' | 'manual';
|
|
1186
|
+
|
|
1187
|
+
/** Truncation strategy */
|
|
1188
|
+
export declare type TruncationStrategy = 'priority' | 'fifo' | 'lifo' | 'score' | 'custom';
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* @mikesaintsg/core
|
|
1192
|
+
*
|
|
1193
|
+
* Type definitions for the core library.
|
|
1194
|
+
* All public types and interfaces are defined here as the SOURCE OF TRUTH.
|
|
1195
|
+
*/
|
|
1196
|
+
/** Cleanup function returned by event subscriptions */
|
|
1197
|
+
export declare type Unsubscribe = () => void;
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Unwrap a result, returning the value or a default.
|
|
1201
|
+
*
|
|
1202
|
+
* @param result - The result to unwrap
|
|
1203
|
+
* @param defaultValue - Value to return if result is an error
|
|
1204
|
+
* @returns The success value or the default value
|
|
1205
|
+
*
|
|
1206
|
+
* @example
|
|
1207
|
+
* ```ts
|
|
1208
|
+
* const value = unwrap(ok(42), 0) // 42
|
|
1209
|
+
* const fallback = unwrap(err('oops'), 0) // 0
|
|
1210
|
+
* ```
|
|
1211
|
+
*/
|
|
1212
|
+
export declare function unwrap<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Unwrap a result, throwing if it's an error.
|
|
1216
|
+
*
|
|
1217
|
+
* @param result - The result to unwrap
|
|
1218
|
+
* @returns The success value
|
|
1219
|
+
* @throws The error if result is Err
|
|
1220
|
+
*
|
|
1221
|
+
* @example
|
|
1222
|
+
* ```ts
|
|
1223
|
+
* const value = unwrapOrThrow(ok(42)) // 42
|
|
1224
|
+
* unwrapOrThrow(err(new Error('oops'))) // throws Error('oops')
|
|
1225
|
+
* ```
|
|
1226
|
+
*/
|
|
1227
|
+
export declare function unwrapOrThrow<T, E>(result: Result<T, E>): T;
|
|
1228
|
+
|
|
1229
|
+
/** Metadata key for VectorStore in persistence */
|
|
1230
|
+
export declare const VECTORSTORE_METADATA_KEY = "vectorstore_metadata";
|
|
1231
|
+
|
|
1232
|
+
/** VectorStore metadata for persistence */
|
|
1233
|
+
export declare interface VectorStoreMetadata {
|
|
1234
|
+
readonly dimensions: number;
|
|
1235
|
+
readonly model: string;
|
|
1236
|
+
readonly provider: string;
|
|
1237
|
+
readonly documentCount: number;
|
|
1238
|
+
readonly createdAt: number;
|
|
1239
|
+
readonly updatedAt: number;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Minimal vectorstore interface for bridge functions.
|
|
1244
|
+
* Avoids hard dependency on vectorstore package.
|
|
1245
|
+
*/
|
|
1246
|
+
export declare interface VectorStoreMinimal<TMetadata = unknown> {
|
|
1247
|
+
search(query: string, options?: VectorStoreSearchOptions<TMetadata>): Promise<readonly ScoredResult[]>;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* VectorStore persistence adapter interface.
|
|
1252
|
+
* Implemented by IndexedDB, OPFS, and HTTP adapters.
|
|
1253
|
+
*/
|
|
1254
|
+
export declare interface VectorStorePersistenceAdapterInterface {
|
|
1255
|
+
load(): Promise<readonly StoredDocument[]>;
|
|
1256
|
+
loadMetadata(): Promise<VectorStoreMetadata | undefined>;
|
|
1257
|
+
save(docs: StoredDocument | readonly StoredDocument[]): Promise<void>;
|
|
1258
|
+
saveMetadata(metadata: VectorStoreMetadata): Promise<void>;
|
|
1259
|
+
remove(ids: string | readonly string[]): Promise<void>;
|
|
1260
|
+
clear(): Promise<void>;
|
|
1261
|
+
isAvailable(): Promise<boolean>;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
/** VectorStore search options */
|
|
1265
|
+
export declare interface VectorStoreSearchOptions<TMetadata = unknown> {
|
|
1266
|
+
readonly limit?: number;
|
|
1267
|
+
readonly filter?: TMetadata;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/** Voyage AI API base URL */
|
|
1271
|
+
export declare const VOYAGE_API_BASE_URL = "https://api.voyageai.com/v1";
|
|
1272
|
+
|
|
1273
|
+
/** Default dimensions for Voyage AI voyage-2 */
|
|
1274
|
+
export declare const VOYAGE_DEFAULT_EMBEDDING_DIMENSIONS = 1024;
|
|
1275
|
+
|
|
1276
|
+
/** Default Voyage AI embedding model (recommended by Anthropic) */
|
|
1277
|
+
export declare const VOYAGE_DEFAULT_EMBEDDING_MODEL = "voyage-2";
|
|
1278
|
+
|
|
1279
|
+
/** Voyage AI embedding data item */
|
|
1280
|
+
export declare interface VoyageEmbeddingData {
|
|
1281
|
+
readonly object: 'embedding';
|
|
1282
|
+
readonly index: number;
|
|
1283
|
+
readonly embedding: readonly number[];
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
/** Voyage AI embedding API response */
|
|
1287
|
+
export declare interface VoyageEmbeddingResponse {
|
|
1288
|
+
readonly object: 'list';
|
|
1289
|
+
readonly data: readonly VoyageEmbeddingData[];
|
|
1290
|
+
readonly model: string;
|
|
1291
|
+
readonly usage: VoyageEmbeddingUsage;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/** Voyage AI embedding usage stats */
|
|
1295
|
+
export declare interface VoyageEmbeddingUsage {
|
|
1296
|
+
readonly total_tokens: number;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
export { }
|