@kb-labs/core-platform 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/dist/adapters/index.cjs +26 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +125 -0
- package/dist/adapters/index.d.ts +125 -0
- package/dist/adapters/index.js +21 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/artifacts-BUghvkUU.d.cts +273 -0
- package/dist/artifacts-Bd-1UVTw.d.ts +273 -0
- package/dist/artifacts-DrVnkLzu.d.cts +1374 -0
- package/dist/artifacts-DrVnkLzu.d.ts +1374 -0
- package/dist/core/index.cjs +4 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/database-DGV6a1nj.d.cts +427 -0
- package/dist/database-DGV6a1nj.d.ts +427 -0
- package/dist/index.cjs +1405 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +579 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +1381 -0
- package/dist/index.js.map +1 -0
- package/dist/log-reader-BVohbSMB.d.cts +314 -0
- package/dist/log-reader-uOHBLBax.d.ts +314 -0
- package/dist/noop/adapters/index.cjs +656 -0
- package/dist/noop/adapters/index.cjs.map +1 -0
- package/dist/noop/adapters/index.d.cts +71 -0
- package/dist/noop/adapters/index.d.ts +71 -0
- package/dist/noop/adapters/index.js +637 -0
- package/dist/noop/adapters/index.js.map +1 -0
- package/dist/noop/core/index.cjs +217 -0
- package/dist/noop/core/index.cjs.map +1 -0
- package/dist/noop/core/index.d.cts +94 -0
- package/dist/noop/core/index.d.ts +94 -0
- package/dist/noop/core/index.js +212 -0
- package/dist/noop/core/index.js.map +1 -0
- package/dist/noop/index.cjs +806 -0
- package/dist/noop/index.cjs.map +1 -0
- package/dist/noop/index.d.cts +36 -0
- package/dist/noop/index.d.ts +36 -0
- package/dist/noop/index.js +787 -0
- package/dist/noop/index.js.map +1 -0
- package/dist/resources-DaufJFad.d.cts +419 -0
- package/dist/resources-DaufJFad.d.ts +419 -0
- package/dist/serializable/index.cjs +162 -0
- package/dist/serializable/index.cjs.map +1 -0
- package/dist/serializable/index.d.cts +352 -0
- package/dist/serializable/index.d.ts +352 -0
- package/dist/serializable/index.js +152 -0
- package/dist/serializable/index.js.map +1 -0
- package/dist/snapshot-provider--COac4P-.d.ts +923 -0
- package/dist/snapshot-provider-nE9wuc1C.d.cts +923 -0
- package/package.json +92 -0
|
@@ -0,0 +1,1374 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @kb-labs/core-platform/adapters/analytics
|
|
3
|
+
* Analytics abstraction for tracking events and user identification.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Query parameters for fetching analytics events
|
|
7
|
+
*/
|
|
8
|
+
interface EventsQuery {
|
|
9
|
+
type?: string | string[];
|
|
10
|
+
source?: string;
|
|
11
|
+
actor?: string;
|
|
12
|
+
from?: string;
|
|
13
|
+
to?: string;
|
|
14
|
+
limit?: number;
|
|
15
|
+
offset?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Analytics event structure (matches kb.v1 schema from @kb-labs/analytics)
|
|
19
|
+
*/
|
|
20
|
+
interface AnalyticsEvent {
|
|
21
|
+
id: string;
|
|
22
|
+
schema: "kb.v1";
|
|
23
|
+
type: string;
|
|
24
|
+
ts: string;
|
|
25
|
+
ingestTs: string;
|
|
26
|
+
source: {
|
|
27
|
+
product: string;
|
|
28
|
+
version: string;
|
|
29
|
+
};
|
|
30
|
+
runId: string;
|
|
31
|
+
actor?: {
|
|
32
|
+
type: "user" | "agent" | "ci";
|
|
33
|
+
id?: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
};
|
|
36
|
+
ctx?: Record<string, string | number | boolean | null>;
|
|
37
|
+
payload?: unknown;
|
|
38
|
+
hashMeta?: {
|
|
39
|
+
algo: "hmac-sha256";
|
|
40
|
+
saltId: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Response for events query
|
|
45
|
+
*/
|
|
46
|
+
interface EventsResponse {
|
|
47
|
+
events: AnalyticsEvent[];
|
|
48
|
+
total: number;
|
|
49
|
+
hasMore: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Aggregated statistics across events
|
|
53
|
+
*/
|
|
54
|
+
interface EventsStats {
|
|
55
|
+
totalEvents: number;
|
|
56
|
+
byType: Record<string, number>;
|
|
57
|
+
bySource: Record<string, number>;
|
|
58
|
+
byActor: Record<string, number>;
|
|
59
|
+
timeRange: {
|
|
60
|
+
from: string;
|
|
61
|
+
to: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Daily aggregated statistics for time-series visualization
|
|
66
|
+
*/
|
|
67
|
+
interface DailyStats {
|
|
68
|
+
date: string;
|
|
69
|
+
count: number;
|
|
70
|
+
metrics?: Record<string, number>;
|
|
71
|
+
breakdown?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Extended query for getDailyStats — adds time bucketing and breakdown support on top of EventsQuery.
|
|
75
|
+
* Adapters implement what they can; unsupported fields are silently ignored (graceful degradation).
|
|
76
|
+
*/
|
|
77
|
+
interface StatsQuery extends EventsQuery {
|
|
78
|
+
/**
|
|
79
|
+
* Time bucket granularity. Default: 'day'.
|
|
80
|
+
* Controls the format of DailyStats.date in the response.
|
|
81
|
+
*/
|
|
82
|
+
groupBy?: "hour" | "day" | "week" | "month";
|
|
83
|
+
/**
|
|
84
|
+
* Dot-notation path to a field to split results by (e.g. 'payload.model', 'payload.tier', 'source.product').
|
|
85
|
+
* When specified, each time bucket returns multiple DailyStats rows — one per unique value of this field.
|
|
86
|
+
* Rows include a `breakdown` field with the field value.
|
|
87
|
+
* Adapters that do not support breakdownBy return data without breakdown (no error).
|
|
88
|
+
*/
|
|
89
|
+
breakdownBy?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Specific payload metric field names to aggregate (e.g. ['totalCost', 'totalTokens']).
|
|
92
|
+
* When omitted, adapters aggregate all metrics they know about for the given event type.
|
|
93
|
+
*/
|
|
94
|
+
metrics?: string[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* WAL buffer status (if applicable)
|
|
98
|
+
*/
|
|
99
|
+
interface BufferStatus {
|
|
100
|
+
segments: number;
|
|
101
|
+
totalSizeBytes: number;
|
|
102
|
+
oldestEventTs: string | null;
|
|
103
|
+
newestEventTs: string | null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Dead-Letter Queue status (if applicable)
|
|
107
|
+
*/
|
|
108
|
+
interface DlqStatus {
|
|
109
|
+
failedEvents: number;
|
|
110
|
+
oldestFailureTs: string | null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Context for analytics events (automatically populated).
|
|
114
|
+
* Adapters use this to enrich events with source, actor, and runId.
|
|
115
|
+
*/
|
|
116
|
+
interface AnalyticsContext {
|
|
117
|
+
/**
|
|
118
|
+
* Source of events (product name and version).
|
|
119
|
+
* Automatically extracted from package.json.
|
|
120
|
+
*/
|
|
121
|
+
source: {
|
|
122
|
+
product: string;
|
|
123
|
+
version: string;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Run ID for correlating events in a single execution.
|
|
127
|
+
* Automatically generated per-execution (e.g., CLI invocation, REST request).
|
|
128
|
+
*/
|
|
129
|
+
runId: string;
|
|
130
|
+
/**
|
|
131
|
+
* Actor performing the action (user, agent, CI).
|
|
132
|
+
* Auto-detected from environment (git config, CI env vars, etc).
|
|
133
|
+
*/
|
|
134
|
+
actor?: {
|
|
135
|
+
type: "user" | "agent" | "ci";
|
|
136
|
+
id?: string;
|
|
137
|
+
name?: string;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Tenant ID for multi-tenancy support.
|
|
141
|
+
*/
|
|
142
|
+
tenantId?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Additional context (workspace path, branch, etc).
|
|
145
|
+
*/
|
|
146
|
+
ctx?: Record<string, string | number | boolean | null>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Analytics adapter interface.
|
|
150
|
+
* Implementations: @kb-labs/analytics-adapter (production), NoOpAnalytics (noop)
|
|
151
|
+
*/
|
|
152
|
+
interface IAnalytics {
|
|
153
|
+
/**
|
|
154
|
+
* Track an analytics event.
|
|
155
|
+
* @param event - Event name (e.g., 'user.signup', 'workflow.completed')
|
|
156
|
+
* @param properties - Optional event properties
|
|
157
|
+
*/
|
|
158
|
+
track(event: string, properties?: Record<string, unknown>): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Identify a user for analytics tracking.
|
|
161
|
+
* @param userId - Unique user identifier
|
|
162
|
+
* @param traits - Optional user traits (name, email, etc.)
|
|
163
|
+
*/
|
|
164
|
+
identify(userId: string, traits?: Record<string, unknown>): Promise<void>;
|
|
165
|
+
/**
|
|
166
|
+
* Flush all pending analytics events.
|
|
167
|
+
* Call before process exit to ensure all events are sent.
|
|
168
|
+
*/
|
|
169
|
+
flush(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Get analytics events (optional - for reading/visualization).
|
|
172
|
+
* Not implemented by NoOpAnalytics.
|
|
173
|
+
*/
|
|
174
|
+
getEvents?(query?: EventsQuery): Promise<EventsResponse>;
|
|
175
|
+
/**
|
|
176
|
+
* Get aggregated statistics (optional - for dashboards).
|
|
177
|
+
* Not implemented by NoOpAnalytics.
|
|
178
|
+
*/
|
|
179
|
+
getStats?(): Promise<EventsStats>;
|
|
180
|
+
/**
|
|
181
|
+
* Get buffer status (optional - for monitoring).
|
|
182
|
+
* Returns null if buffer not applicable (e.g., HTTP-only analytics).
|
|
183
|
+
*/
|
|
184
|
+
getBufferStatus?(): Promise<BufferStatus | null>;
|
|
185
|
+
/**
|
|
186
|
+
* Get DLQ status (optional - for monitoring).
|
|
187
|
+
* Returns null if DLQ not applicable.
|
|
188
|
+
*/
|
|
189
|
+
getDlqStatus?(): Promise<DlqStatus | null>;
|
|
190
|
+
/**
|
|
191
|
+
* Get current source attribution (optional).
|
|
192
|
+
*
|
|
193
|
+
* Returns the current source (product name and version) used for events.
|
|
194
|
+
* This is useful for saving and restoring source in nested plugin execution.
|
|
195
|
+
*
|
|
196
|
+
* @returns Current source, or undefined if not available
|
|
197
|
+
*
|
|
198
|
+
* Implementation notes:
|
|
199
|
+
* - FileAnalytics: Returns current context.source
|
|
200
|
+
* - NoOpAnalytics: Not needed (no events tracked)
|
|
201
|
+
* - Future HTTP/Cloud adapters: Should implement this
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const analytics = platform.analytics;
|
|
206
|
+
* const originalSource = analytics.getSource?.();
|
|
207
|
+
*
|
|
208
|
+
* try {
|
|
209
|
+
* analytics.setSource?.({ product: '@kb-labs/mind', version: '0.1.0' });
|
|
210
|
+
* await analytics.track('mind.event', {...});
|
|
211
|
+
* } finally {
|
|
212
|
+
* if (originalSource) {
|
|
213
|
+
* analytics.setSource?.(originalSource);
|
|
214
|
+
* }
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
getSource?(): {
|
|
219
|
+
product: string;
|
|
220
|
+
version: string;
|
|
221
|
+
} | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* Override source attribution for scoped execution (optional).
|
|
224
|
+
*
|
|
225
|
+
* This method allows wrapping analytics adapters to override the source
|
|
226
|
+
* (product name and version) for events tracked during plugin execution.
|
|
227
|
+
*
|
|
228
|
+
* Use case: When a plugin (@kb-labs/mind) runs in a subprocess, we want
|
|
229
|
+
* analytics events to show source.product = '@kb-labs/mind' instead of
|
|
230
|
+
* the root package (@kb-labs/ai-review).
|
|
231
|
+
*
|
|
232
|
+
* @param source - New source to use for future events
|
|
233
|
+
*
|
|
234
|
+
* Implementation notes:
|
|
235
|
+
* - FileAnalytics: Updates internal context.source
|
|
236
|
+
* - NoOpAnalytics: Not needed (no events tracked)
|
|
237
|
+
* - Future HTTP/Cloud adapters: Should implement this
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const analytics = platform.analytics;
|
|
242
|
+
* if (analytics.setSource) {
|
|
243
|
+
* analytics.setSource({
|
|
244
|
+
* product: '@kb-labs/mind',
|
|
245
|
+
* version: '0.1.0'
|
|
246
|
+
* });
|
|
247
|
+
* }
|
|
248
|
+
* await analytics.track('mind.rag-index.started', {...});
|
|
249
|
+
* // Event will have source.product = '@kb-labs/mind'
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
setSource?(source: {
|
|
253
|
+
product: string;
|
|
254
|
+
version: string;
|
|
255
|
+
}): void;
|
|
256
|
+
/**
|
|
257
|
+
* Get time-bucketed aggregated statistics (optional - for time-series visualization).
|
|
258
|
+
*
|
|
259
|
+
* Groups events by time bucket and returns aggregated counts and metrics.
|
|
260
|
+
* Useful for rendering charts and graphs.
|
|
261
|
+
*
|
|
262
|
+
* @param query - StatsQuery extending EventsQuery with groupBy, breakdownBy, metrics
|
|
263
|
+
* @returns Array of stats sorted by date ascending. When breakdownBy is used,
|
|
264
|
+
* multiple rows per time bucket are returned (one per unique breakdown value).
|
|
265
|
+
*
|
|
266
|
+
* Implementation notes:
|
|
267
|
+
* - FileAnalytics: Groups events in memory using date-fns; supports all StatsQuery fields
|
|
268
|
+
* - PostgresAnalytics: Uses SQL GROUP BY + date_trunc() for efficiency
|
|
269
|
+
* - NoOpAnalytics: Not implemented (returns empty array)
|
|
270
|
+
* - Adapters that don't support breakdownBy/groupBy silently ignore those fields
|
|
271
|
+
*
|
|
272
|
+
* The metrics object contains aggregated values specific to the event type:
|
|
273
|
+
* - LLM events: totalTokens, totalCost, avgDurationMs
|
|
274
|
+
* - Embeddings events: totalTokens, totalCost, avgDurationMs
|
|
275
|
+
* - VectorStore events: totalSearches, totalUpserts, totalDeletes, avgDurationMs
|
|
276
|
+
* - Cache events: totalHits, totalMisses, totalSets, hitRate
|
|
277
|
+
* - Storage events: totalBytesRead, totalBytesWritten, avgDurationMs
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* // Basic daily stats
|
|
282
|
+
* const daily = await analytics.getDailyStats?.({
|
|
283
|
+
* type: 'llm.completion.completed',
|
|
284
|
+
* from: '2026-01-01T00:00:00Z',
|
|
285
|
+
* to: '2026-01-31T23:59:59Z',
|
|
286
|
+
* });
|
|
287
|
+
* // [{ date: '2026-01-01', count: 45, metrics: { totalTokens: 12500, totalCost: 2.34 } }, ...]
|
|
288
|
+
*
|
|
289
|
+
* // Hourly breakdown by model
|
|
290
|
+
* const byModel = await analytics.getDailyStats?.({
|
|
291
|
+
* type: ['llm.chatWithTools.completed', 'llm.completion.completed'],
|
|
292
|
+
* groupBy: 'hour',
|
|
293
|
+
* breakdownBy: 'payload.model',
|
|
294
|
+
* metrics: ['totalCost', 'totalTokens'],
|
|
295
|
+
* });
|
|
296
|
+
* // [
|
|
297
|
+
* // { date: '2026-01-01T10', count: 12, breakdown: 'gpt-4o-mini', metrics: { totalCost: 0.05 } },
|
|
298
|
+
* // { date: '2026-01-01T10', count: 3, breakdown: 'gpt-5.1-codex-max', metrics: { totalCost: 1.20 } },
|
|
299
|
+
* // ]
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
getDailyStats?(query?: StatsQuery): Promise<DailyStats[]>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @module @kb-labs/core-platform/adapters/vector-store
|
|
307
|
+
* Vector store abstraction for semantic search operations.
|
|
308
|
+
*/
|
|
309
|
+
/**
|
|
310
|
+
* Vector record for storage.
|
|
311
|
+
*/
|
|
312
|
+
interface VectorRecord {
|
|
313
|
+
/** Unique identifier */
|
|
314
|
+
id: string;
|
|
315
|
+
/** Embedding vector */
|
|
316
|
+
vector: number[];
|
|
317
|
+
/** Optional metadata */
|
|
318
|
+
metadata?: Record<string, unknown>;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Search result from vector store.
|
|
322
|
+
*/
|
|
323
|
+
interface VectorSearchResult {
|
|
324
|
+
/** Record identifier */
|
|
325
|
+
id: string;
|
|
326
|
+
/** Similarity score (0-1, higher is more similar) */
|
|
327
|
+
score: number;
|
|
328
|
+
/** Record metadata */
|
|
329
|
+
metadata?: Record<string, unknown>;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Filter for vector search.
|
|
333
|
+
*/
|
|
334
|
+
interface VectorFilter {
|
|
335
|
+
/** Field name to filter on */
|
|
336
|
+
field: string;
|
|
337
|
+
/** Filter operator */
|
|
338
|
+
operator: "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in" | "nin";
|
|
339
|
+
/** Filter value */
|
|
340
|
+
value: unknown;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Vector store adapter interface.
|
|
344
|
+
* Implementations: @kb-labs/mind-qdrant (production), MemoryVectorStore (noop)
|
|
345
|
+
*/
|
|
346
|
+
interface IVectorStore {
|
|
347
|
+
/**
|
|
348
|
+
* Search for similar vectors.
|
|
349
|
+
* @param query - Query embedding vector
|
|
350
|
+
* @param limit - Maximum number of results
|
|
351
|
+
* @param filter - Optional metadata filter
|
|
352
|
+
*/
|
|
353
|
+
search(query: number[], limit: number, filter?: VectorFilter): Promise<VectorSearchResult[]>;
|
|
354
|
+
/**
|
|
355
|
+
* Upsert vectors into the store.
|
|
356
|
+
* @param vectors - Array of vector records to upsert
|
|
357
|
+
*/
|
|
358
|
+
upsert(vectors: VectorRecord[]): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Delete vectors by IDs.
|
|
361
|
+
* @param ids - Array of vector IDs to delete
|
|
362
|
+
*/
|
|
363
|
+
delete(ids: string[]): Promise<void>;
|
|
364
|
+
/**
|
|
365
|
+
* Get total count of vectors in the store.
|
|
366
|
+
*/
|
|
367
|
+
count(): Promise<number>;
|
|
368
|
+
/**
|
|
369
|
+
* Get vectors by IDs (optional method for bulk retrieval).
|
|
370
|
+
* Allows any plugin to retrieve multiple vectors efficiently.
|
|
371
|
+
* @param ids - Array of vector IDs to retrieve
|
|
372
|
+
* @returns Array of vector records
|
|
373
|
+
*/
|
|
374
|
+
get?(ids: string[]): Promise<VectorRecord[]>;
|
|
375
|
+
/**
|
|
376
|
+
* Query vectors by metadata filter (optional method for advanced filtering).
|
|
377
|
+
* Allows any plugin to retrieve vectors based on custom metadata criteria.
|
|
378
|
+
* @param filter - Metadata filter to apply
|
|
379
|
+
* @returns Array of matching vector records
|
|
380
|
+
*/
|
|
381
|
+
query?(filter: VectorFilter): Promise<VectorRecord[]>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @module @kb-labs/core-platform/adapters/llm-types
|
|
386
|
+
* LLM tier and capability types for adaptive model routing.
|
|
387
|
+
*
|
|
388
|
+
* These types define the abstract layer between plugins and LLM providers.
|
|
389
|
+
* Plugins request tiers/capabilities, platform resolves to actual models.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```typescript
|
|
393
|
+
* import { LLMTier, LLMCapability, UseLLMOptions } from '@kb-labs/sdk';
|
|
394
|
+
*
|
|
395
|
+
* // Plugin requests by tier (user decides what model)
|
|
396
|
+
* const llm = useLLM({ tier: 'small' });
|
|
397
|
+
* const llm = useLLM({ tier: 'large', capabilities: ['reasoning'] });
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Model quality tier - user-defined slots.
|
|
403
|
+
*
|
|
404
|
+
* Tiers are NOT tied to specific models. They are abstract slots
|
|
405
|
+
* that the user fills with whatever models they want in config.
|
|
406
|
+
*
|
|
407
|
+
* Plugin intent:
|
|
408
|
+
* - `small` - "This task is simple, doesn't need much"
|
|
409
|
+
* - `medium` - "Standard task"
|
|
410
|
+
* - `large` - "Complex task, need maximum quality"
|
|
411
|
+
*
|
|
412
|
+
* User decides what model maps to each tier in their config.
|
|
413
|
+
*/
|
|
414
|
+
type LLMTier = "small" | "medium" | "large";
|
|
415
|
+
/**
|
|
416
|
+
* Model capabilities - task-optimized features.
|
|
417
|
+
*
|
|
418
|
+
* - `fast` - Lowest latency (for real-time responses)
|
|
419
|
+
* - `reasoning` - Complex reasoning (o1, opus-level thinking)
|
|
420
|
+
* - `coding` - Code-optimized (better at code generation/review)
|
|
421
|
+
* - `vision` - Image input support
|
|
422
|
+
*/
|
|
423
|
+
type LLMCapability = "reasoning" | "coding" | "vision" | "fast";
|
|
424
|
+
/**
|
|
425
|
+
* Options for useLLM() - plugin-facing API.
|
|
426
|
+
*
|
|
427
|
+
* Plugins specify what they need abstractly.
|
|
428
|
+
* Platform resolves to actual provider/model based on user config.
|
|
429
|
+
*/
|
|
430
|
+
interface UseLLMOptions {
|
|
431
|
+
/**
|
|
432
|
+
* Quality tier (user-defined slot).
|
|
433
|
+
* Platform adapts if exact tier unavailable:
|
|
434
|
+
* - Escalates up (small → medium) silently
|
|
435
|
+
* - Degrades down (large → medium) with warning
|
|
436
|
+
*/
|
|
437
|
+
tier?: LLMTier;
|
|
438
|
+
/**
|
|
439
|
+
* Required capabilities.
|
|
440
|
+
* Platform selects model that supports ALL requested capabilities.
|
|
441
|
+
*/
|
|
442
|
+
capabilities?: LLMCapability[];
|
|
443
|
+
/**
|
|
444
|
+
* Optional execution policy applied to this bound LLM instance.
|
|
445
|
+
* Can be overridden per-call via LLMOptions.execution.
|
|
446
|
+
*/
|
|
447
|
+
execution?: LLMExecutionPolicy;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Resolution result from tier/capability matching.
|
|
451
|
+
* Internal type used by LLMRouter.
|
|
452
|
+
*/
|
|
453
|
+
interface LLMResolution {
|
|
454
|
+
/** Resolved provider ID (e.g., 'openai', 'anthropic') */
|
|
455
|
+
provider: string;
|
|
456
|
+
/** Resolved model name */
|
|
457
|
+
model: string;
|
|
458
|
+
/** Resource name for ResourceBroker (e.g., 'llm:openai') */
|
|
459
|
+
resource: string;
|
|
460
|
+
/** Original requested tier */
|
|
461
|
+
requestedTier: LLMTier | undefined;
|
|
462
|
+
/** Actual tier being used */
|
|
463
|
+
actualTier: LLMTier;
|
|
464
|
+
/** Whether this was escalated/degraded */
|
|
465
|
+
adapted: boolean;
|
|
466
|
+
/** Warning message if degraded */
|
|
467
|
+
warning?: string;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Resolved adapter binding — immutable snapshot of a tier resolution.
|
|
471
|
+
* Returned by resolveAdapter() to avoid global state mutation.
|
|
472
|
+
*/
|
|
473
|
+
interface LLMAdapterBinding {
|
|
474
|
+
/** The concrete adapter instance (already wrapped with analytics, etc.) */
|
|
475
|
+
adapter: ILLM;
|
|
476
|
+
/** Resolved model name */
|
|
477
|
+
model: string;
|
|
478
|
+
/** Actual tier used */
|
|
479
|
+
tier: LLMTier;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* LLM Router interface - extends ILLM with routing capabilities.
|
|
483
|
+
* Implemented by @kb-labs/llm-router.
|
|
484
|
+
*/
|
|
485
|
+
interface ILLMRouter {
|
|
486
|
+
/** Get configured tier (what user set in config) */
|
|
487
|
+
getConfiguredTier(): LLMTier;
|
|
488
|
+
/** Resolve tier request to actual model (mutates router state — legacy) */
|
|
489
|
+
resolve(options?: UseLLMOptions): LLMResolution;
|
|
490
|
+
/**
|
|
491
|
+
* Resolve tier and return an immutable adapter binding.
|
|
492
|
+
* Does NOT mutate router state — safe for concurrent useLLM() calls.
|
|
493
|
+
*/
|
|
494
|
+
resolveAdapter(options?: UseLLMOptions): Promise<LLMAdapterBinding>;
|
|
495
|
+
/** Check if capability is available */
|
|
496
|
+
hasCapability(capability: LLMCapability): boolean;
|
|
497
|
+
/** Get available capabilities */
|
|
498
|
+
getCapabilities(): LLMCapability[];
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Tier order for resolution (lowest to highest).
|
|
502
|
+
*/
|
|
503
|
+
declare const TIER_ORDER: readonly LLMTier[];
|
|
504
|
+
/**
|
|
505
|
+
* Check if tier A is higher than tier B.
|
|
506
|
+
*/
|
|
507
|
+
declare function isTierHigher(a: LLMTier, b: LLMTier): boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Check if tier A is lower than tier B.
|
|
510
|
+
*/
|
|
511
|
+
declare function isTierLower(a: LLMTier, b: LLMTier): boolean;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @module @kb-labs/core-platform/adapters/llm
|
|
515
|
+
* LLM (Large Language Model) abstraction for text generation.
|
|
516
|
+
*/
|
|
517
|
+
/**
|
|
518
|
+
* Metadata for LLM request tracking and analytics.
|
|
519
|
+
* Passed through the chain from LLMRouter to AnalyticsLLM.
|
|
520
|
+
*/
|
|
521
|
+
interface LLMRequestMetadata {
|
|
522
|
+
/** Tier used for this request */
|
|
523
|
+
tier?: LLMTier;
|
|
524
|
+
/** Provider identifier (e.g., 'openai', 'anthropic') */
|
|
525
|
+
provider?: string;
|
|
526
|
+
/** Resource name in broker (e.g., 'llm:openai') */
|
|
527
|
+
resource?: string;
|
|
528
|
+
/** Cache/stream decision trace produced by runtime policy orchestrator */
|
|
529
|
+
cacheDecisionTrace?: LLMCacheDecisionTrace;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Cache policy modes for prompt/context caching.
|
|
533
|
+
*/
|
|
534
|
+
type LLMCacheMode = "prefer" | "require" | "bypass";
|
|
535
|
+
/**
|
|
536
|
+
* Abstract cache scopes (adapter maps this to vendor-specific API).
|
|
537
|
+
*/
|
|
538
|
+
type LLMCacheScope = "prefix" | "segments" | "full_request";
|
|
539
|
+
/**
|
|
540
|
+
* Streaming policy modes.
|
|
541
|
+
*/
|
|
542
|
+
type LLMStreamMode = "prefer" | "require" | "off";
|
|
543
|
+
/**
|
|
544
|
+
* Cache policy requested by caller.
|
|
545
|
+
*/
|
|
546
|
+
interface LLMCachePolicy {
|
|
547
|
+
/** prefer (default), require, bypass */
|
|
548
|
+
mode?: LLMCacheMode;
|
|
549
|
+
/** Abstract scope selector for adapter mapping */
|
|
550
|
+
scope?: LLMCacheScope;
|
|
551
|
+
/** Requested TTL in seconds (best effort) */
|
|
552
|
+
ttlSec?: number;
|
|
553
|
+
/** Optional stable key hint for deterministic cache reuse */
|
|
554
|
+
key?: string;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Streaming policy requested by caller.
|
|
558
|
+
*/
|
|
559
|
+
interface LLMStreamPolicy {
|
|
560
|
+
/** prefer (default), require, off */
|
|
561
|
+
mode?: LLMStreamMode;
|
|
562
|
+
/**
|
|
563
|
+
* If streaming is unavailable and mode=prefer,
|
|
564
|
+
* fallback to complete() and emit a single chunk.
|
|
565
|
+
*/
|
|
566
|
+
fallbackToComplete?: boolean;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Unified execution policy (vendor-agnostic).
|
|
570
|
+
*/
|
|
571
|
+
interface LLMExecutionPolicy {
|
|
572
|
+
cache?: LLMCachePolicy;
|
|
573
|
+
stream?: LLMStreamPolicy;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Cache capability descriptor for adapter protocol negotiation.
|
|
577
|
+
*/
|
|
578
|
+
interface LLMCacheCapability {
|
|
579
|
+
supported: boolean;
|
|
580
|
+
protocol?: "auto_prefix" | "explicit_breakpoints" | "explicit_handle";
|
|
581
|
+
scopes?: LLMCacheScope[];
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Stream capability descriptor for adapter protocol negotiation.
|
|
585
|
+
*/
|
|
586
|
+
interface LLMStreamCapability {
|
|
587
|
+
supported: boolean;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Adapter protocol capabilities.
|
|
591
|
+
*/
|
|
592
|
+
interface LLMProtocolCapabilities {
|
|
593
|
+
cache: LLMCacheCapability;
|
|
594
|
+
stream: LLMStreamCapability;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Runtime trace of cache/stream decision applied before adapter call.
|
|
598
|
+
*/
|
|
599
|
+
interface LLMCacheDecisionTrace {
|
|
600
|
+
cacheRequestedMode: LLMCacheMode;
|
|
601
|
+
cacheSupported: boolean;
|
|
602
|
+
cacheAppliedMode: LLMCacheMode;
|
|
603
|
+
streamRequestedMode: LLMStreamMode;
|
|
604
|
+
streamSupported: boolean;
|
|
605
|
+
streamAppliedMode: LLMStreamMode;
|
|
606
|
+
streamFallback?: "complete";
|
|
607
|
+
reason?: string;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Options for LLM completion.
|
|
611
|
+
*/
|
|
612
|
+
interface LLMOptions {
|
|
613
|
+
/** Model identifier (e.g., 'gpt-4', 'claude-3-opus') */
|
|
614
|
+
model?: string;
|
|
615
|
+
/** Sampling temperature (0-2) */
|
|
616
|
+
temperature?: number;
|
|
617
|
+
/** Maximum tokens to generate */
|
|
618
|
+
maxTokens?: number;
|
|
619
|
+
/** Stop sequences */
|
|
620
|
+
stop?: string[];
|
|
621
|
+
/** System prompt/instruction */
|
|
622
|
+
systemPrompt?: string;
|
|
623
|
+
/** Metadata for analytics and observability (set by LLMRouter) */
|
|
624
|
+
metadata?: LLMRequestMetadata;
|
|
625
|
+
/** Vendor-agnostic runtime execution policy (cache/stream semantics) */
|
|
626
|
+
execution?: LLMExecutionPolicy;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* LLM completion response.
|
|
630
|
+
*/
|
|
631
|
+
interface LLMResponse {
|
|
632
|
+
/** Generated text content */
|
|
633
|
+
content: string;
|
|
634
|
+
/** Token usage statistics */
|
|
635
|
+
usage: {
|
|
636
|
+
promptTokens: number;
|
|
637
|
+
completionTokens: number;
|
|
638
|
+
/**
|
|
639
|
+
* Prompt tokens served from cache (provider-reported, optional).
|
|
640
|
+
* Example: OpenAI cached prompt tokens, Anthropic cache_read_input_tokens.
|
|
641
|
+
*/
|
|
642
|
+
cacheReadTokens?: number;
|
|
643
|
+
/**
|
|
644
|
+
* Prompt tokens written to cache (provider-reported, optional).
|
|
645
|
+
* Example: Anthropic cache_creation_input_tokens.
|
|
646
|
+
*/
|
|
647
|
+
cacheWriteTokens?: number;
|
|
648
|
+
/**
|
|
649
|
+
* Provider-reported billable prompt tokens (if available).
|
|
650
|
+
* If absent, analytics can derive estimates from cacheReadTokens and pricing rules.
|
|
651
|
+
*/
|
|
652
|
+
billablePromptTokens?: number;
|
|
653
|
+
/**
|
|
654
|
+
* Optional vendor-specific usage data for advanced analytics.
|
|
655
|
+
*/
|
|
656
|
+
providerUsage?: Record<string, unknown>;
|
|
657
|
+
};
|
|
658
|
+
/** Model used for generation */
|
|
659
|
+
model: string;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Tool definition for native tool calling.
|
|
663
|
+
*/
|
|
664
|
+
interface LLMTool {
|
|
665
|
+
/** Tool name (must be valid identifier) */
|
|
666
|
+
name: string;
|
|
667
|
+
/** Human-readable description */
|
|
668
|
+
description: string;
|
|
669
|
+
/** JSON Schema for tool input parameters */
|
|
670
|
+
inputSchema: Record<string, any>;
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Tool call from LLM.
|
|
674
|
+
*/
|
|
675
|
+
interface LLMToolCall {
|
|
676
|
+
/** Unique call ID */
|
|
677
|
+
id: string;
|
|
678
|
+
/** Tool name */
|
|
679
|
+
name: string;
|
|
680
|
+
/** Tool input (validated against schema) */
|
|
681
|
+
input: unknown;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Message in a conversation.
|
|
685
|
+
*/
|
|
686
|
+
interface LLMMessage {
|
|
687
|
+
/** Message role */
|
|
688
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
689
|
+
/** Message content (text or tool results) */
|
|
690
|
+
content: string;
|
|
691
|
+
/** Tool call ID (for tool role - identifies which tool call this result belongs to) */
|
|
692
|
+
toolCallId?: string;
|
|
693
|
+
/** Tool calls made by assistant (for assistant role - when LLM requests tool execution) */
|
|
694
|
+
toolCalls?: LLMToolCall[];
|
|
695
|
+
/** Metadata from tool execution (e.g., reflection results, file counts, etc.) */
|
|
696
|
+
metadata?: Record<string, unknown>;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Options for native tool calling.
|
|
700
|
+
*/
|
|
701
|
+
interface LLMToolCallOptions extends LLMOptions {
|
|
702
|
+
/** Available tools */
|
|
703
|
+
tools: LLMTool[];
|
|
704
|
+
/**
|
|
705
|
+
* Control tool usage:
|
|
706
|
+
* - 'auto': LLM decides whether to call tools
|
|
707
|
+
* - 'required': LLM must call at least one tool
|
|
708
|
+
* - 'none': LLM cannot call tools (text-only response)
|
|
709
|
+
* - { type: 'function', function: { name: 'tool_name' } }: Force specific tool
|
|
710
|
+
*/
|
|
711
|
+
toolChoice?: "auto" | "required" | "none" | {
|
|
712
|
+
type: "function";
|
|
713
|
+
function: {
|
|
714
|
+
name: string;
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Response from native tool calling.
|
|
720
|
+
*/
|
|
721
|
+
interface LLMToolCallResponse extends LLMResponse {
|
|
722
|
+
/** Tool calls requested by LLM (if any) */
|
|
723
|
+
toolCalls?: LLMToolCall[];
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* LLM adapter interface.
|
|
727
|
+
* Implementations: @kb-labs/shared-openai, @kb-labs/shared-anthropic (production), MockLLM (noop)
|
|
728
|
+
*/
|
|
729
|
+
interface ILLM {
|
|
730
|
+
/**
|
|
731
|
+
* Generate a completion for the given prompt.
|
|
732
|
+
* @param prompt - Text prompt
|
|
733
|
+
* @param options - Optional generation options
|
|
734
|
+
*/
|
|
735
|
+
complete(prompt: string, options?: LLMOptions): Promise<LLMResponse>;
|
|
736
|
+
/**
|
|
737
|
+
* Stream a completion for the given prompt.
|
|
738
|
+
* @param prompt - Text prompt
|
|
739
|
+
* @param options - Optional generation options
|
|
740
|
+
*/
|
|
741
|
+
stream(prompt: string, options?: LLMOptions): AsyncIterable<string>;
|
|
742
|
+
/**
|
|
743
|
+
* Optional protocol capability handshake.
|
|
744
|
+
* When omitted, callers should assume: stream=true, cache=false.
|
|
745
|
+
*/
|
|
746
|
+
getProtocolCapabilities?(): LLMProtocolCapabilities | Promise<LLMProtocolCapabilities>;
|
|
747
|
+
/**
|
|
748
|
+
* Chat with native tool calling support (optional).
|
|
749
|
+
*
|
|
750
|
+
* If implemented, enables native LLM tool calling (e.g., OpenAI function calling, Claude tool use).
|
|
751
|
+
* If not implemented, AgentExecutor falls back to text-based tool prompting.
|
|
752
|
+
*
|
|
753
|
+
* @param messages - Conversation history
|
|
754
|
+
* @param options - Options including tools and tool choice
|
|
755
|
+
* @returns Response with optional tool calls
|
|
756
|
+
*/
|
|
757
|
+
chatWithTools?(messages: LLMMessage[], options: LLMToolCallOptions): Promise<LLMToolCallResponse>;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* @module @kb-labs/core-platform/adapters/embeddings
|
|
762
|
+
* Embeddings abstraction for text-to-vector conversion.
|
|
763
|
+
*/
|
|
764
|
+
/**
|
|
765
|
+
* Embeddings adapter interface.
|
|
766
|
+
* Implementations: @kb-labs/shared-openai (production), MockEmbeddings (noop)
|
|
767
|
+
*/
|
|
768
|
+
interface IEmbeddings {
|
|
769
|
+
/**
|
|
770
|
+
* Generate embedding vector for a single text.
|
|
771
|
+
* @param text - Input text
|
|
772
|
+
* @returns Embedding vector
|
|
773
|
+
*/
|
|
774
|
+
embed(text: string): Promise<number[]>;
|
|
775
|
+
/**
|
|
776
|
+
* Generate embedding vectors for multiple texts.
|
|
777
|
+
* @param texts - Array of input texts
|
|
778
|
+
* @returns Array of embedding vectors (same order as input)
|
|
779
|
+
*/
|
|
780
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
781
|
+
/**
|
|
782
|
+
* Dimension of the embedding vectors.
|
|
783
|
+
*/
|
|
784
|
+
readonly dimensions: number;
|
|
785
|
+
/**
|
|
786
|
+
* Get the dimensions of the embeddings.
|
|
787
|
+
* This method is needed for IPC/Unix Socket transport to access the dimensions property.
|
|
788
|
+
* Implementations should return the same value as the dimensions property.
|
|
789
|
+
*/
|
|
790
|
+
getDimensions(): Promise<number>;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* @module @kb-labs/core-platform/adapters/cache
|
|
795
|
+
* Cache abstraction for key-value storage with TTL support.
|
|
796
|
+
*/
|
|
797
|
+
/**
|
|
798
|
+
* Cache adapter interface.
|
|
799
|
+
* Implementations: @kb-labs/core-redis (production), MemoryCache (noop)
|
|
800
|
+
*/
|
|
801
|
+
interface ICache {
|
|
802
|
+
/**
|
|
803
|
+
* Get a value from cache.
|
|
804
|
+
* @param key - Cache key
|
|
805
|
+
* @returns Cached value or null if not found/expired
|
|
806
|
+
*/
|
|
807
|
+
get<T>(key: string): Promise<T | null>;
|
|
808
|
+
/**
|
|
809
|
+
* Set a value in cache.
|
|
810
|
+
* @param key - Cache key
|
|
811
|
+
* @param value - Value to cache
|
|
812
|
+
* @param ttl - Time to live in milliseconds (optional)
|
|
813
|
+
*/
|
|
814
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
815
|
+
/**
|
|
816
|
+
* Delete a value from cache.
|
|
817
|
+
* @param key - Cache key
|
|
818
|
+
*/
|
|
819
|
+
delete(key: string): Promise<void>;
|
|
820
|
+
/**
|
|
821
|
+
* Clear cache entries matching a pattern.
|
|
822
|
+
* @param pattern - Glob pattern (e.g., 'user:*')
|
|
823
|
+
*/
|
|
824
|
+
clear(pattern?: string): Promise<void>;
|
|
825
|
+
/**
|
|
826
|
+
* Add member to sorted set with score.
|
|
827
|
+
* @param key - Sorted set key
|
|
828
|
+
* @param score - Numeric score (typically timestamp)
|
|
829
|
+
* @param member - Member to add
|
|
830
|
+
*/
|
|
831
|
+
zadd(key: string, score: number, member: string): Promise<void>;
|
|
832
|
+
/**
|
|
833
|
+
* Get members from sorted set by score range.
|
|
834
|
+
* @param key - Sorted set key
|
|
835
|
+
* @param min - Minimum score (inclusive)
|
|
836
|
+
* @param max - Maximum score (inclusive)
|
|
837
|
+
* @returns Array of members in score order
|
|
838
|
+
*/
|
|
839
|
+
zrangebyscore(key: string, min: number, max: number): Promise<string[]>;
|
|
840
|
+
/**
|
|
841
|
+
* Remove member from sorted set.
|
|
842
|
+
* @param key - Sorted set key
|
|
843
|
+
* @param member - Member to remove
|
|
844
|
+
*/
|
|
845
|
+
zrem(key: string, member: string): Promise<void>;
|
|
846
|
+
/**
|
|
847
|
+
* Set key-value pair only if key does not exist (atomic operation).
|
|
848
|
+
* Used for distributed locking and preventing race conditions.
|
|
849
|
+
* @param key - Cache key
|
|
850
|
+
* @param value - Value to set
|
|
851
|
+
* @param ttl - Time to live in milliseconds (optional)
|
|
852
|
+
* @returns true if value was set, false if key already exists
|
|
853
|
+
*/
|
|
854
|
+
setIfNotExists<T>(key: string, value: T, ttl?: number): Promise<boolean>;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* @module @kb-labs/core-platform/adapters/storage
|
|
859
|
+
* Storage abstraction for file/blob operations.
|
|
860
|
+
*/
|
|
861
|
+
/**
|
|
862
|
+
* Metadata for storage objects.
|
|
863
|
+
* Used by listWithMetadata() and stat().
|
|
864
|
+
*/
|
|
865
|
+
interface StorageMetadata {
|
|
866
|
+
/** File path */
|
|
867
|
+
path: string;
|
|
868
|
+
/** File size in bytes */
|
|
869
|
+
size: number;
|
|
870
|
+
/** Last modified timestamp (ISO 8601) */
|
|
871
|
+
lastModified: string;
|
|
872
|
+
/** Content type (MIME) - optional */
|
|
873
|
+
contentType?: string;
|
|
874
|
+
/** ETag for versioning - optional */
|
|
875
|
+
etag?: string;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Storage adapter interface.
|
|
879
|
+
* Implementations: @kb-labs/core-fs (production), MemoryStorage (noop)
|
|
880
|
+
*
|
|
881
|
+
* **Backward compatibility:**
|
|
882
|
+
* - Core methods (read, write, delete, list, exists) are required
|
|
883
|
+
* - Extended methods (readStream, writeStream, copy, move, listWithMetadata, stat) are optional
|
|
884
|
+
* - Adapters can implement extended methods for better performance
|
|
885
|
+
*/
|
|
886
|
+
interface IStorage {
|
|
887
|
+
/**
|
|
888
|
+
* Read file contents.
|
|
889
|
+
* @param path - File path
|
|
890
|
+
* @returns File contents or null if not found
|
|
891
|
+
*/
|
|
892
|
+
read(path: string): Promise<Buffer | null>;
|
|
893
|
+
/**
|
|
894
|
+
* Write file contents.
|
|
895
|
+
* @param path - File path
|
|
896
|
+
* @param data - File contents
|
|
897
|
+
*/
|
|
898
|
+
write(path: string, data: Buffer): Promise<void>;
|
|
899
|
+
/**
|
|
900
|
+
* Delete a file.
|
|
901
|
+
* @param path - File path
|
|
902
|
+
*/
|
|
903
|
+
delete(path: string): Promise<void>;
|
|
904
|
+
/**
|
|
905
|
+
* List files matching a prefix.
|
|
906
|
+
* @param prefix - Path prefix (e.g., 'docs/')
|
|
907
|
+
* @returns Array of file paths
|
|
908
|
+
*/
|
|
909
|
+
list(prefix: string): Promise<string[]>;
|
|
910
|
+
/**
|
|
911
|
+
* Check if a file exists.
|
|
912
|
+
* @param path - File path
|
|
913
|
+
*/
|
|
914
|
+
exists(path: string): Promise<boolean>;
|
|
915
|
+
/**
|
|
916
|
+
* Read file as stream (for large files).
|
|
917
|
+
* @param path - File path
|
|
918
|
+
* @returns Readable stream or null if not found
|
|
919
|
+
*
|
|
920
|
+
* **Optional:** If not implemented, runtime will fallback to read() + buffer wrapping.
|
|
921
|
+
*/
|
|
922
|
+
readStream?(path: string): Promise<NodeJS.ReadableStream | null>;
|
|
923
|
+
/**
|
|
924
|
+
* Write file from stream (for large files).
|
|
925
|
+
* @param path - File path
|
|
926
|
+
* @param stream - Readable stream
|
|
927
|
+
*
|
|
928
|
+
* **Optional:** If not implemented, runtime will fallback to stream → buffer → write().
|
|
929
|
+
*/
|
|
930
|
+
writeStream?(path: string, stream: NodeJS.ReadableStream): Promise<void>;
|
|
931
|
+
/**
|
|
932
|
+
* Copy file within storage.
|
|
933
|
+
* @param sourcePath - Source file path
|
|
934
|
+
* @param destPath - Destination file path
|
|
935
|
+
*
|
|
936
|
+
* **Optional:** If not implemented, runtime will fallback to read() + write().
|
|
937
|
+
*/
|
|
938
|
+
copy?(sourcePath: string, destPath: string): Promise<void>;
|
|
939
|
+
/**
|
|
940
|
+
* Move file within storage.
|
|
941
|
+
* @param sourcePath - Source file path
|
|
942
|
+
* @param destPath - Destination file path
|
|
943
|
+
*
|
|
944
|
+
* **Optional:** If not implemented, runtime will fallback to copy() + delete().
|
|
945
|
+
*/
|
|
946
|
+
move?(sourcePath: string, destPath: string): Promise<void>;
|
|
947
|
+
/**
|
|
948
|
+
* List files with metadata (size, lastModified, etc).
|
|
949
|
+
* @param prefix - Path prefix (e.g., 'docs/')
|
|
950
|
+
* @returns Array of file metadata
|
|
951
|
+
*
|
|
952
|
+
* **Optional:** If not implemented, runtime will fallback to list() + stat() for each file.
|
|
953
|
+
*/
|
|
954
|
+
listWithMetadata?(prefix: string): Promise<StorageMetadata[]>;
|
|
955
|
+
/**
|
|
956
|
+
* Get file metadata without reading contents.
|
|
957
|
+
* @param path - File path
|
|
958
|
+
* @returns File metadata or null if not found
|
|
959
|
+
*
|
|
960
|
+
* **Optional:** If not implemented, runtime will fallback to exists() + read() (inefficient).
|
|
961
|
+
*/
|
|
962
|
+
stat?(path: string): Promise<StorageMetadata | null>;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* @module @kb-labs/core-platform/adapters/config
|
|
967
|
+
* Configuration adapter interface
|
|
968
|
+
*
|
|
969
|
+
* Provides access to kb.config.json with product-specific extraction.
|
|
970
|
+
* Supports both Profiles v2 and legacy config structures.
|
|
971
|
+
*/
|
|
972
|
+
/**
|
|
973
|
+
* Configuration adapter interface.
|
|
974
|
+
*
|
|
975
|
+
* Provides product-specific configuration from kb.config.json.
|
|
976
|
+
* This adapter is available through platform.config and can be accessed
|
|
977
|
+
* via IPC in child processes.
|
|
978
|
+
*
|
|
979
|
+
* @example
|
|
980
|
+
* ```typescript
|
|
981
|
+
* // Get Mind product config
|
|
982
|
+
* const mindConfig = await platform.config.getConfig('mind');
|
|
983
|
+
* console.log(mindConfig.scopes);
|
|
984
|
+
*
|
|
985
|
+
* // Get Workflow config with specific profile
|
|
986
|
+
* const workflowConfig = await platform.config.getConfig('workflow', 'production');
|
|
987
|
+
* ```
|
|
988
|
+
*/
|
|
989
|
+
interface IConfig {
|
|
990
|
+
/**
|
|
991
|
+
* Get product-specific configuration.
|
|
992
|
+
*
|
|
993
|
+
* Extracts configuration for the specified product from kb.config.json.
|
|
994
|
+
* Supports both Profiles v2 structure and legacy structure.
|
|
995
|
+
*
|
|
996
|
+
* **Profiles v2 structure:**
|
|
997
|
+
* ```json
|
|
998
|
+
* {
|
|
999
|
+
* "profiles": [
|
|
1000
|
+
* {
|
|
1001
|
+
* "id": "default",
|
|
1002
|
+
* "products": {
|
|
1003
|
+
* "mind": { "scopes": [...] },
|
|
1004
|
+
* "workflow": { "maxConcurrency": 10 }
|
|
1005
|
+
* }
|
|
1006
|
+
* }
|
|
1007
|
+
* ]
|
|
1008
|
+
* }
|
|
1009
|
+
* ```
|
|
1010
|
+
*
|
|
1011
|
+
* **Legacy structure:**
|
|
1012
|
+
* ```json
|
|
1013
|
+
* {
|
|
1014
|
+
* "knowledge": { "scopes": [...] }, // for "mind" product
|
|
1015
|
+
* "workflow": { "maxConcurrency": 10 }
|
|
1016
|
+
* }
|
|
1017
|
+
* ```
|
|
1018
|
+
*
|
|
1019
|
+
* @param productId - Product identifier (e.g., 'mind', 'workflow', 'plugins')
|
|
1020
|
+
* @param profileId - Profile identifier (defaults to 'default' or KB_PROFILE env var)
|
|
1021
|
+
* @returns Product-specific config or undefined if not found
|
|
1022
|
+
*/
|
|
1023
|
+
getConfig(productId: string, profileId?: string): Promise<any>;
|
|
1024
|
+
/**
|
|
1025
|
+
* Get raw kb.config.json data.
|
|
1026
|
+
*
|
|
1027
|
+
* Returns the entire config object without any product/profile extraction.
|
|
1028
|
+
* Useful for custom parsing or when you need access to multiple products.
|
|
1029
|
+
*
|
|
1030
|
+
* @returns Raw config object or undefined if not loaded
|
|
1031
|
+
*/
|
|
1032
|
+
getRawConfig(): Promise<any>;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* @module @kb-labs/core-platform/adapters/logger
|
|
1037
|
+
* Logger abstraction for structured logging.
|
|
1038
|
+
*/
|
|
1039
|
+
/**
|
|
1040
|
+
* Log level enumeration
|
|
1041
|
+
*/
|
|
1042
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
1043
|
+
/**
|
|
1044
|
+
* Generate unique log ID using ULID.
|
|
1045
|
+
*
|
|
1046
|
+
* ULIDs are:
|
|
1047
|
+
* - Lexicographically sortable (timestamp-based)
|
|
1048
|
+
* - 26 characters (more compact than UUID's 36)
|
|
1049
|
+
* - URL-safe (base32 encoded)
|
|
1050
|
+
* - Monotonically increasing within same millisecond
|
|
1051
|
+
*
|
|
1052
|
+
* All logger adapters MUST use this function to ensure ID consistency.
|
|
1053
|
+
*
|
|
1054
|
+
* @returns ULID string (e.g., "01ARZ3NDEKTSV4RRFFQ69G5FAV")
|
|
1055
|
+
*
|
|
1056
|
+
* @example
|
|
1057
|
+
* ```typescript
|
|
1058
|
+
* const logId = generateLogId();
|
|
1059
|
+
* console.log(logId); // "01HQVX5P7G3QR9Z8X5N4Y2K6E1"
|
|
1060
|
+
* ```
|
|
1061
|
+
*/
|
|
1062
|
+
declare function generateLogId(): string;
|
|
1063
|
+
/**
|
|
1064
|
+
* Structured log record
|
|
1065
|
+
*/
|
|
1066
|
+
interface LogRecord {
|
|
1067
|
+
/** Unique log ID (ULID). Generated by logger adapter using generateLogId() */
|
|
1068
|
+
id: string;
|
|
1069
|
+
/** Timestamp (milliseconds since epoch) */
|
|
1070
|
+
timestamp: number;
|
|
1071
|
+
/** Log level */
|
|
1072
|
+
level: LogLevel;
|
|
1073
|
+
/** Log message */
|
|
1074
|
+
message: string;
|
|
1075
|
+
/** Structured fields (metadata) */
|
|
1076
|
+
fields: Record<string, unknown>;
|
|
1077
|
+
/** Source identifier (e.g., 'rest', 'workflow', 'cli') */
|
|
1078
|
+
source: string;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Query filters for log retrieval
|
|
1082
|
+
*/
|
|
1083
|
+
interface LogQuery {
|
|
1084
|
+
/** Minimum log level (inclusive) */
|
|
1085
|
+
level?: LogLevel;
|
|
1086
|
+
/** Filter by source */
|
|
1087
|
+
source?: string;
|
|
1088
|
+
/** Start timestamp (milliseconds since epoch) */
|
|
1089
|
+
from?: number;
|
|
1090
|
+
/** End timestamp (milliseconds since epoch) */
|
|
1091
|
+
to?: number;
|
|
1092
|
+
/** Maximum number of logs to return */
|
|
1093
|
+
limit?: number;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Log buffer interface for streaming/querying logs
|
|
1097
|
+
*/
|
|
1098
|
+
interface ILogBuffer {
|
|
1099
|
+
/**
|
|
1100
|
+
* Append log record to buffer
|
|
1101
|
+
*/
|
|
1102
|
+
append(record: LogRecord): void;
|
|
1103
|
+
/**
|
|
1104
|
+
* Query logs with filters
|
|
1105
|
+
*/
|
|
1106
|
+
query(query?: LogQuery): LogRecord[];
|
|
1107
|
+
/**
|
|
1108
|
+
* Subscribe to real-time log stream
|
|
1109
|
+
* @returns Unsubscribe function
|
|
1110
|
+
*/
|
|
1111
|
+
subscribe(callback: (record: LogRecord) => void): () => void;
|
|
1112
|
+
/**
|
|
1113
|
+
* Get buffer statistics
|
|
1114
|
+
*/
|
|
1115
|
+
getStats(): {
|
|
1116
|
+
total: number;
|
|
1117
|
+
bufferSize: number;
|
|
1118
|
+
oldestTimestamp: number | null;
|
|
1119
|
+
newestTimestamp: number | null;
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Logger adapter interface.
|
|
1124
|
+
* Implementations: @kb-labs/adapters-pino (production), ConsoleLogger (noop)
|
|
1125
|
+
*/
|
|
1126
|
+
interface ILogger {
|
|
1127
|
+
/**
|
|
1128
|
+
* Log info message.
|
|
1129
|
+
* @param message - Log message
|
|
1130
|
+
* @param meta - Optional metadata
|
|
1131
|
+
*/
|
|
1132
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
1133
|
+
/**
|
|
1134
|
+
* Log warning message.
|
|
1135
|
+
* @param message - Log message
|
|
1136
|
+
* @param meta - Optional metadata
|
|
1137
|
+
*/
|
|
1138
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
1139
|
+
/**
|
|
1140
|
+
* Log error message.
|
|
1141
|
+
* @param message - Log message
|
|
1142
|
+
* @param error - Optional error object
|
|
1143
|
+
* @param meta - Optional metadata
|
|
1144
|
+
*/
|
|
1145
|
+
error(message: string, error?: Error, meta?: Record<string, unknown>): void;
|
|
1146
|
+
/**
|
|
1147
|
+
* Log fatal error message (critical failures).
|
|
1148
|
+
* @param message - Log message
|
|
1149
|
+
* @param error - Optional error object
|
|
1150
|
+
* @param meta - Optional metadata
|
|
1151
|
+
*/
|
|
1152
|
+
fatal(message: string, error?: Error, meta?: Record<string, unknown>): void;
|
|
1153
|
+
/**
|
|
1154
|
+
* Log debug message.
|
|
1155
|
+
* @param message - Log message
|
|
1156
|
+
* @param meta - Optional metadata
|
|
1157
|
+
*/
|
|
1158
|
+
debug(message: string, meta?: Record<string, unknown>): void;
|
|
1159
|
+
/**
|
|
1160
|
+
* Log trace message (most verbose).
|
|
1161
|
+
* @param message - Log message
|
|
1162
|
+
* @param meta - Optional metadata
|
|
1163
|
+
*/
|
|
1164
|
+
trace(message: string, meta?: Record<string, unknown>): void;
|
|
1165
|
+
/**
|
|
1166
|
+
* Create a child logger with additional context.
|
|
1167
|
+
* @param bindings - Context bindings (e.g., { plugin: 'mind', tenant: 'acme' })
|
|
1168
|
+
*/
|
|
1169
|
+
child(bindings: Record<string, unknown>): ILogger;
|
|
1170
|
+
/**
|
|
1171
|
+
* Get log buffer for streaming/querying (optional feature).
|
|
1172
|
+
* Not all logger implementations support buffering.
|
|
1173
|
+
* @returns Log buffer if streaming is enabled, undefined otherwise
|
|
1174
|
+
*/
|
|
1175
|
+
getLogBuffer?(): ILogBuffer | undefined;
|
|
1176
|
+
/**
|
|
1177
|
+
* Register callback for every log event (optional feature).
|
|
1178
|
+
* Used by platform to connect logger extensions (ring buffer, persistence).
|
|
1179
|
+
*
|
|
1180
|
+
* Extensions are called fire-and-forget (async errors are caught and logged).
|
|
1181
|
+
* Multiple extensions can be registered and will be called in priority order.
|
|
1182
|
+
*
|
|
1183
|
+
* @param callback - Function to call on each log event
|
|
1184
|
+
* @returns Unsubscribe function to remove the callback
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```typescript
|
|
1188
|
+
* const unsubscribe = logger.onLog((record) => {
|
|
1189
|
+
* ringBuffer.append(record);
|
|
1190
|
+
* persistence.write(record).catch(console.error);
|
|
1191
|
+
* });
|
|
1192
|
+
*
|
|
1193
|
+
* // Later: unsubscribe()
|
|
1194
|
+
* ```
|
|
1195
|
+
*/
|
|
1196
|
+
onLog?(callback: (record: LogRecord) => void): () => void;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* @module @kb-labs/core-platform/adapters/event-bus
|
|
1201
|
+
* Event bus abstraction for pub/sub messaging.
|
|
1202
|
+
*/
|
|
1203
|
+
/**
|
|
1204
|
+
* Event handler function type.
|
|
1205
|
+
*/
|
|
1206
|
+
type EventHandler<T> = (event: T) => Promise<void>;
|
|
1207
|
+
/**
|
|
1208
|
+
* Unsubscribe function returned by subscribe.
|
|
1209
|
+
*/
|
|
1210
|
+
type Unsubscribe = () => void;
|
|
1211
|
+
/**
|
|
1212
|
+
* Event bus adapter interface.
|
|
1213
|
+
* Implementations: MemoryEventBus (noop), can be extended with Redis/Kafka
|
|
1214
|
+
*/
|
|
1215
|
+
interface IEventBus {
|
|
1216
|
+
/**
|
|
1217
|
+
* Publish an event to a topic.
|
|
1218
|
+
* @param topic - Event topic (e.g., 'workflow.completed')
|
|
1219
|
+
* @param event - Event payload
|
|
1220
|
+
*/
|
|
1221
|
+
publish<T>(topic: string, event: T): Promise<void>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Subscribe to events on a topic.
|
|
1224
|
+
* @param topic - Event topic (supports wildcards: 'workflow.*')
|
|
1225
|
+
* @param handler - Event handler function
|
|
1226
|
+
* @returns Unsubscribe function
|
|
1227
|
+
*/
|
|
1228
|
+
subscribe<T>(topic: string, handler: EventHandler<T>): Unsubscribe;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* @module @kb-labs/core-platform/adapters/invoke
|
|
1233
|
+
* Inter-plugin invocation adapter interface.
|
|
1234
|
+
*/
|
|
1235
|
+
/**
|
|
1236
|
+
* Request to invoke another plugin command.
|
|
1237
|
+
*/
|
|
1238
|
+
interface InvokeRequest {
|
|
1239
|
+
/** Target plugin ID (e.g., 'mind-engine') */
|
|
1240
|
+
pluginId: string;
|
|
1241
|
+
/** Command to execute (e.g., 'rag-query') */
|
|
1242
|
+
command: string;
|
|
1243
|
+
/** Input payload for the command */
|
|
1244
|
+
input?: unknown;
|
|
1245
|
+
/** Timeout in milliseconds (optional) */
|
|
1246
|
+
timeout?: number;
|
|
1247
|
+
/** Additional metadata */
|
|
1248
|
+
metadata?: Record<string, unknown>;
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Response from plugin invocation.
|
|
1252
|
+
*/
|
|
1253
|
+
interface InvokeResponse<T = unknown> {
|
|
1254
|
+
/** Whether the invocation succeeded */
|
|
1255
|
+
success: boolean;
|
|
1256
|
+
/** Result data (if success) */
|
|
1257
|
+
data?: T;
|
|
1258
|
+
/** Error message (if failure) */
|
|
1259
|
+
error?: string;
|
|
1260
|
+
/** Execution metadata (duration, etc.) */
|
|
1261
|
+
metadata?: Record<string, unknown>;
|
|
1262
|
+
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Inter-plugin invocation adapter.
|
|
1265
|
+
*
|
|
1266
|
+
* Allows plugins to call commands from other plugins.
|
|
1267
|
+
* The runtime enforces permissions and sandboxing.
|
|
1268
|
+
*
|
|
1269
|
+
* @example
|
|
1270
|
+
* ```typescript
|
|
1271
|
+
* // In plugin A, call plugin B
|
|
1272
|
+
* const response = await ctx.platform.invoke?.call({
|
|
1273
|
+
* pluginId: 'plugin-b',
|
|
1274
|
+
* command: 'process-data',
|
|
1275
|
+
* input: { data: [...] },
|
|
1276
|
+
* });
|
|
1277
|
+
*
|
|
1278
|
+
* if (response?.success) {
|
|
1279
|
+
* console.log(response.data);
|
|
1280
|
+
* }
|
|
1281
|
+
* ```
|
|
1282
|
+
*/
|
|
1283
|
+
interface IInvoke {
|
|
1284
|
+
/**
|
|
1285
|
+
* Invoke a command in another plugin.
|
|
1286
|
+
*
|
|
1287
|
+
* @param request - Invocation request
|
|
1288
|
+
* @returns Response with result or error
|
|
1289
|
+
*/
|
|
1290
|
+
call<T = unknown>(request: InvokeRequest): Promise<InvokeResponse<T>>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Check if a plugin/command is available for invocation.
|
|
1293
|
+
*
|
|
1294
|
+
* @param pluginId - Target plugin ID
|
|
1295
|
+
* @param command - Command name (optional, checks plugin availability)
|
|
1296
|
+
* @returns True if available
|
|
1297
|
+
*/
|
|
1298
|
+
isAvailable(pluginId: string, command?: string): Promise<boolean>;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* @module @kb-labs/core-platform/adapters/artifacts
|
|
1303
|
+
* Artifact storage interface.
|
|
1304
|
+
*/
|
|
1305
|
+
/**
|
|
1306
|
+
* Artifact metadata.
|
|
1307
|
+
*/
|
|
1308
|
+
interface ArtifactMeta {
|
|
1309
|
+
/** Artifact key/path */
|
|
1310
|
+
key: string;
|
|
1311
|
+
/** Content type (e.g., 'application/json') */
|
|
1312
|
+
contentType?: string;
|
|
1313
|
+
/** Size in bytes */
|
|
1314
|
+
size?: number;
|
|
1315
|
+
/** Creation timestamp */
|
|
1316
|
+
createdAt?: Date;
|
|
1317
|
+
/** Last modified timestamp */
|
|
1318
|
+
updatedAt?: Date;
|
|
1319
|
+
/** Custom metadata */
|
|
1320
|
+
metadata?: Record<string, unknown>;
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1323
|
+
* Artifact write options.
|
|
1324
|
+
*/
|
|
1325
|
+
interface ArtifactWriteOptions {
|
|
1326
|
+
/** Content type */
|
|
1327
|
+
contentType?: string;
|
|
1328
|
+
/** Custom metadata */
|
|
1329
|
+
metadata?: Record<string, unknown>;
|
|
1330
|
+
/** TTL in seconds (optional expiration) */
|
|
1331
|
+
ttl?: number;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Artifact storage interface.
|
|
1335
|
+
* Provides structured storage for plugin outputs.
|
|
1336
|
+
*/
|
|
1337
|
+
interface IArtifacts {
|
|
1338
|
+
/**
|
|
1339
|
+
* Write an artifact.
|
|
1340
|
+
* @param key - Artifact key/path
|
|
1341
|
+
* @param data - Data to write (will be serialized)
|
|
1342
|
+
* @param options - Write options
|
|
1343
|
+
*/
|
|
1344
|
+
write(key: string, data: unknown, options?: ArtifactWriteOptions): Promise<void>;
|
|
1345
|
+
/**
|
|
1346
|
+
* Read an artifact.
|
|
1347
|
+
* @param key - Artifact key/path
|
|
1348
|
+
* @returns Artifact data or null if not found
|
|
1349
|
+
*/
|
|
1350
|
+
read<T = unknown>(key: string): Promise<T | null>;
|
|
1351
|
+
/**
|
|
1352
|
+
* Check if artifact exists.
|
|
1353
|
+
* @param key - Artifact key/path
|
|
1354
|
+
*/
|
|
1355
|
+
exists(key: string): Promise<boolean>;
|
|
1356
|
+
/**
|
|
1357
|
+
* Delete an artifact.
|
|
1358
|
+
* @param key - Artifact key/path
|
|
1359
|
+
*/
|
|
1360
|
+
delete(key: string): Promise<void>;
|
|
1361
|
+
/**
|
|
1362
|
+
* List artifacts by prefix.
|
|
1363
|
+
* @param prefix - Key prefix
|
|
1364
|
+
* @returns List of artifact metadata
|
|
1365
|
+
*/
|
|
1366
|
+
list(prefix: string): Promise<ArtifactMeta[]>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Get artifact metadata.
|
|
1369
|
+
* @param key - Artifact key/path
|
|
1370
|
+
*/
|
|
1371
|
+
getMeta(key: string): Promise<ArtifactMeta | null>;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
export { type EventHandler as $, type AnalyticsContext as A, type BufferStatus as B, type LLMTier as C, type DlqStatus as D, type EventsQuery as E, type LLMCapability as F, type LLMResolution as G, type LLMAdapterBinding as H, type IAnalytics as I, type ILLMRouter as J, isTierHigher as K, type LogRecord as L, isTierLower as M, type IEmbeddings as N, type ICache as O, type IConfig as P, type IStorage as Q, type StorageMetadata as R, type StatsQuery as S, TIER_ORDER as T, type UseLLMOptions as U, type VectorRecord as V, type ILogger as W, type ILogBuffer as X, type LogLevel as Y, generateLogId as Z, type IEventBus as _, type LogQuery as a, type Unsubscribe as a0, type IInvoke as a1, type InvokeRequest as a2, type InvokeResponse as a3, type IArtifacts as a4, type ArtifactMeta as a5, type ArtifactWriteOptions as a6, type LLMRequestMetadata as a7, type AnalyticsEvent as b, type EventsResponse as c, type EventsStats as d, type DailyStats as e, type IVectorStore as f, type VectorSearchResult as g, type VectorFilter as h, type ILLM as i, type LLMOptions as j, type LLMResponse as k, type LLMExecutionPolicy as l, type LLMCachePolicy as m, type LLMStreamPolicy as n, type LLMCacheMode as o, type LLMCacheScope as p, type LLMStreamMode as q, type LLMProtocolCapabilities as r, type LLMCacheCapability as s, type LLMStreamCapability as t, type LLMCacheDecisionTrace as u, type LLMTool as v, type LLMToolCall as w, type LLMMessage as x, type LLMToolCallOptions as y, type LLMToolCallResponse as z };
|