@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,314 @@
|
|
|
1
|
+
import { a as LogQuery, L as LogRecord } from './artifacts-DrVnkLzu.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module @kb-labs/core-platform/adapters/log-reader
|
|
5
|
+
* Read-only adapter interface for querying logs.
|
|
6
|
+
*
|
|
7
|
+
* Purpose:
|
|
8
|
+
* - Abstract log storage backends (SQLite, ring buffer, remote API)
|
|
9
|
+
* - Provide unified read API for all log queries
|
|
10
|
+
* - Enable configuration-driven backend selection
|
|
11
|
+
*
|
|
12
|
+
* Separation Rationale:
|
|
13
|
+
* - ILogger: Write logs (info, error, warn) + extensions (buffer, persistence)
|
|
14
|
+
* - ILogReader: Read logs (query, getById, search) - this interface
|
|
15
|
+
*
|
|
16
|
+
* Design:
|
|
17
|
+
* - REST API and plugins use this adapter instead of directly accessing ILogBuffer or ILogPersistence
|
|
18
|
+
* - Implementation automatically selects best backend (persistence > buffer > error)
|
|
19
|
+
* - Graceful degradation if backends unavailable
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // In REST API or plugin
|
|
24
|
+
* const reader = platform.getAdapter<ILogReader>('logReader');
|
|
25
|
+
*
|
|
26
|
+
* const logs = await reader.query(
|
|
27
|
+
* { level: 'error', from: Date.now() - 3600000 },
|
|
28
|
+
* { limit: 50 }
|
|
29
|
+
* );
|
|
30
|
+
*
|
|
31
|
+
* const log = await reader.getById('log-123');
|
|
32
|
+
*
|
|
33
|
+
* const results = await reader.search('authentication failed');
|
|
34
|
+
*
|
|
35
|
+
* const unsubscribe = reader.subscribe((log) => {
|
|
36
|
+
* console.log('New log:', log);
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Query options for log retrieval.
|
|
43
|
+
*/
|
|
44
|
+
interface LogQueryOptions {
|
|
45
|
+
/** Maximum number of logs to return (default: 100) */
|
|
46
|
+
limit?: number;
|
|
47
|
+
/** Number of logs to skip for pagination (default: 0) */
|
|
48
|
+
offset?: number;
|
|
49
|
+
/** Sort by field (default: 'timestamp') */
|
|
50
|
+
sortBy?: "timestamp" | "level";
|
|
51
|
+
/** Sort order (default: 'desc' - newest first) */
|
|
52
|
+
sortOrder?: "asc" | "desc";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Result of log query operation.
|
|
56
|
+
*/
|
|
57
|
+
interface LogQueryResult {
|
|
58
|
+
/** Logs matching query criteria */
|
|
59
|
+
logs: LogRecord[];
|
|
60
|
+
/** Total number of logs matching query (ignoring limit/offset) */
|
|
61
|
+
total: number;
|
|
62
|
+
/** True if more results are available (offset + logs.length < total) */
|
|
63
|
+
hasMore: boolean;
|
|
64
|
+
/** Source of data (for debugging/monitoring) */
|
|
65
|
+
source: "buffer" | "persistence" | "hybrid";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Search options for full-text search.
|
|
69
|
+
*/
|
|
70
|
+
interface LogSearchOptions {
|
|
71
|
+
/** Maximum number of logs to return (default: 100) */
|
|
72
|
+
limit?: number;
|
|
73
|
+
/** Number of logs to skip for pagination (default: 0) */
|
|
74
|
+
offset?: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Result of log search operation.
|
|
78
|
+
*/
|
|
79
|
+
interface LogSearchResult {
|
|
80
|
+
/** Logs matching search query */
|
|
81
|
+
logs: LogRecord[];
|
|
82
|
+
/** Total number of logs matching search */
|
|
83
|
+
total: number;
|
|
84
|
+
/** True if more results are available */
|
|
85
|
+
hasMore: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Statistics about available log storage.
|
|
89
|
+
*/
|
|
90
|
+
interface LogStats {
|
|
91
|
+
/** Ring buffer statistics (if available) */
|
|
92
|
+
buffer?: {
|
|
93
|
+
/** Current number of logs in buffer */
|
|
94
|
+
size: number;
|
|
95
|
+
/** Maximum buffer capacity */
|
|
96
|
+
maxSize: number;
|
|
97
|
+
/** Timestamp of oldest log in buffer (null if empty) */
|
|
98
|
+
oldestTimestamp: number | null;
|
|
99
|
+
/** Timestamp of newest log in buffer (null if empty) */
|
|
100
|
+
newestTimestamp: number | null;
|
|
101
|
+
};
|
|
102
|
+
/** Persistent storage statistics (if available) */
|
|
103
|
+
persistence?: {
|
|
104
|
+
/** Total number of logs in storage */
|
|
105
|
+
totalLogs: number;
|
|
106
|
+
/** Timestamp of oldest log (0 if empty) */
|
|
107
|
+
oldestTimestamp: number;
|
|
108
|
+
/** Timestamp of newest log (0 if empty) */
|
|
109
|
+
newestTimestamp: number;
|
|
110
|
+
/** Storage size in bytes */
|
|
111
|
+
sizeBytes: number;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Capabilities of available log backends.
|
|
116
|
+
*/
|
|
117
|
+
interface LogCapabilities {
|
|
118
|
+
/** Ring buffer available (real-time streaming) */
|
|
119
|
+
hasBuffer: boolean;
|
|
120
|
+
/** Persistent storage available (historical queries) */
|
|
121
|
+
hasPersistence: boolean;
|
|
122
|
+
/** Full-text search available (FTS) */
|
|
123
|
+
hasSearch: boolean;
|
|
124
|
+
/** Real-time streaming available (SSE) */
|
|
125
|
+
hasStreaming: boolean;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Read-only log adapter interface.
|
|
129
|
+
*
|
|
130
|
+
* This adapter abstracts log storage backends (SQLite, ring buffer, remote API, etc.).
|
|
131
|
+
* REST API and plugins use this instead of directly accessing ILogBuffer or ILogPersistence.
|
|
132
|
+
*
|
|
133
|
+
* Implementations automatically select best backend:
|
|
134
|
+
* 1. If persistence available → use it (complete historical data)
|
|
135
|
+
* 2. If only buffer available → use it (recent logs only)
|
|
136
|
+
* 3. If neither → error 503
|
|
137
|
+
*
|
|
138
|
+
* Common implementations:
|
|
139
|
+
* - HybridLogReader: Combines persistence + buffer with automatic fallback
|
|
140
|
+
* - PersistenceLogReader: SQLite/PostgreSQL only
|
|
141
|
+
* - BufferLogReader: Ring buffer only
|
|
142
|
+
* - RemoteLogReader: Fetch from remote API
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Get adapter from platform
|
|
147
|
+
* const reader = platform.getAdapter<ILogReader>('logReader');
|
|
148
|
+
*
|
|
149
|
+
* // Query recent errors
|
|
150
|
+
* const errors = await reader.query(
|
|
151
|
+
* { level: 'error', from: Date.now() - 3600000 },
|
|
152
|
+
* { limit: 10 }
|
|
153
|
+
* );
|
|
154
|
+
*
|
|
155
|
+
* // Get specific log
|
|
156
|
+
* const log = await reader.getById('log-123');
|
|
157
|
+
*
|
|
158
|
+
* // Full-text search
|
|
159
|
+
* const results = await reader.search('authentication failed');
|
|
160
|
+
*
|
|
161
|
+
* // Subscribe to real-time stream
|
|
162
|
+
* const unsubscribe = reader.subscribe((log) => {
|
|
163
|
+
* if (log.level === 'error') {
|
|
164
|
+
* console.error('New error:', log);
|
|
165
|
+
* }
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
interface ILogReader {
|
|
170
|
+
/**
|
|
171
|
+
* Query logs with filters and pagination.
|
|
172
|
+
*
|
|
173
|
+
* Automatically selects best backend:
|
|
174
|
+
* - Persistence (if available): complete historical data
|
|
175
|
+
* - Buffer (if available): recent logs only
|
|
176
|
+
* - Neither: throws error
|
|
177
|
+
*
|
|
178
|
+
* @param filters - Query filters (level, source, time range)
|
|
179
|
+
* @param options - Pagination and sorting options
|
|
180
|
+
* @returns Promise with logs, total count, and pagination info
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const reader = platform.getAdapter<ILogReader>('logReader');
|
|
185
|
+
*
|
|
186
|
+
* // Get last 50 error logs
|
|
187
|
+
* const result = await reader.query(
|
|
188
|
+
* { level: 'error' },
|
|
189
|
+
* { limit: 50, sortBy: 'timestamp', sortOrder: 'desc' }
|
|
190
|
+
* );
|
|
191
|
+
*
|
|
192
|
+
* console.log(result.logs); // Array of 50 logs
|
|
193
|
+
* console.log(result.total); // Total matching logs
|
|
194
|
+
* console.log(result.hasMore); // true if more pages exist
|
|
195
|
+
* console.log(result.source); // 'persistence' | 'buffer'
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
query(filters: LogQuery, options?: LogQueryOptions): Promise<LogQueryResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Get single log record by ID.
|
|
201
|
+
*
|
|
202
|
+
* Searches both ring buffer and persistence (if available).
|
|
203
|
+
*
|
|
204
|
+
* @param id - Log record ID
|
|
205
|
+
* @returns Promise with log record or null if not found
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const log = await reader.getById('log-abc123');
|
|
210
|
+
* if (log) {
|
|
211
|
+
* console.log(log.message);
|
|
212
|
+
* console.log(log.fields);
|
|
213
|
+
* }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
getById(id: string): Promise<LogRecord | null>;
|
|
217
|
+
/**
|
|
218
|
+
* Full-text search logs by text query.
|
|
219
|
+
*
|
|
220
|
+
* Uses database FTS (Full-Text Search) if available, otherwise falls back
|
|
221
|
+
* to simple text matching in buffer.
|
|
222
|
+
*
|
|
223
|
+
* @param searchText - Search query (database-specific syntax supported)
|
|
224
|
+
* @param options - Pagination options
|
|
225
|
+
* @returns Promise with matching logs
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* // Simple search
|
|
230
|
+
* const results = await reader.search('authentication failed');
|
|
231
|
+
*
|
|
232
|
+
* // Advanced search (SQLite FTS5 syntax)
|
|
233
|
+
* const results = await reader.search('auth* AND (error OR warn)');
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
search(searchText: string, options?: LogSearchOptions): Promise<LogSearchResult>;
|
|
237
|
+
/**
|
|
238
|
+
* Subscribe to real-time log stream.
|
|
239
|
+
*
|
|
240
|
+
* Requires ring buffer to be available. If not, throws error.
|
|
241
|
+
*
|
|
242
|
+
* @param callback - Function to call on each new log
|
|
243
|
+
* @param filters - Optional filters to apply to stream
|
|
244
|
+
* @returns Unsubscribe function to stop receiving logs
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* // Subscribe to all logs
|
|
249
|
+
* const unsubscribe = reader.subscribe((log) => {
|
|
250
|
+
* console.log('New log:', log.message);
|
|
251
|
+
* });
|
|
252
|
+
*
|
|
253
|
+
* // Subscribe to errors only
|
|
254
|
+
* const unsubscribe = reader.subscribe(
|
|
255
|
+
* (log) => console.error('Error:', log),
|
|
256
|
+
* { level: 'error' }
|
|
257
|
+
* );
|
|
258
|
+
*
|
|
259
|
+
* // Later: unsubscribe()
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
subscribe(callback: (log: LogRecord) => void, filters?: LogQuery): () => void;
|
|
263
|
+
/**
|
|
264
|
+
* Get statistics about available log storage.
|
|
265
|
+
*
|
|
266
|
+
* Returns combined statistics from both ring buffer and persistence
|
|
267
|
+
* (if available).
|
|
268
|
+
*
|
|
269
|
+
* @returns Promise with statistics
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const stats = await reader.getStats();
|
|
274
|
+
*
|
|
275
|
+
* if (stats.buffer) {
|
|
276
|
+
* console.log('Buffer size:', stats.buffer.size);
|
|
277
|
+
* console.log('Buffer max:', stats.buffer.maxSize);
|
|
278
|
+
* }
|
|
279
|
+
*
|
|
280
|
+
* if (stats.persistence) {
|
|
281
|
+
* console.log('Total logs:', stats.persistence.totalLogs);
|
|
282
|
+
* console.log('DB size:', stats.persistence.sizeBytes);
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
getStats(): Promise<LogStats>;
|
|
287
|
+
/**
|
|
288
|
+
* Check which backends and features are available.
|
|
289
|
+
*
|
|
290
|
+
* Useful for conditionally enabling UI features or choosing query strategies.
|
|
291
|
+
*
|
|
292
|
+
* @returns Object with boolean flags for each capability
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* const caps = reader.getCapabilities();
|
|
297
|
+
*
|
|
298
|
+
* if (caps.hasSearch) {
|
|
299
|
+
* // Show search UI
|
|
300
|
+
* }
|
|
301
|
+
*
|
|
302
|
+
* if (caps.hasStreaming) {
|
|
303
|
+
* // Enable real-time log streaming
|
|
304
|
+
* }
|
|
305
|
+
*
|
|
306
|
+
* if (caps.hasPersistence) {
|
|
307
|
+
* // Show "View All Logs" button
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
getCapabilities(): LogCapabilities;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export type { ILogReader as I, LogCapabilities as L, LogQueryOptions as a, LogQueryResult as b, LogSearchOptions as c, LogSearchResult as d, LogStats as e };
|