@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
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
export { d as AdapterCapabilities, b as AdapterDependency, c as AdapterExtension, e as AdapterFactory, A as AdapterManifest, a as AdapterType, t as AttachWorkspaceRequest, y as CaptureSnapshotRequest, C as CreateEnvironmentRequest, n as EnvironmentDescriptor, m as EnvironmentEndpoint, l as EnvironmentLease, p as EnvironmentProviderCapabilities, k as EnvironmentResources, j as EnvironmentStatus, o as EnvironmentStatusResult, h as ExecuteOptions, E as ExecutionRequest, g as ExecutionResult, i as IEnvironmentProvider, f as IExecutionBackend, I as ILogPersistence, x as ISnapshotProvider, q as IWorkspaceProvider, L as LogPersistenceConfig, M as MaterializeWorkspaceRequest, R as RestoreSnapshotRequest, B as RestoreSnapshotResult, z as SnapshotDescriptor, F as SnapshotGarbageCollectRequest, G as SnapshotGarbageCollectResult, H as SnapshotProviderCapabilities, S as SnapshotStatus, D as SnapshotStatusResult, u as WorkspaceAttachment, s as WorkspaceDescriptor, r as WorkspaceMount, w as WorkspaceProviderCapabilities, W as WorkspaceStatus, v as WorkspaceStatusResult } from './snapshot-provider-nE9wuc1C.cjs';
|
|
2
|
+
import { i as ILLM, I as IAnalytics, r as LLMProtocolCapabilities, j as LLMOptions, k as LLMResponse, x as LLMMessage, y as LLMToolCallOptions, z as LLMToolCallResponse, N as IEmbeddings, f as IVectorStore, h as VectorFilter, g as VectorSearchResult, V as VectorRecord, O as ICache, Q as IStorage, E as EventsQuery, c as EventsResponse, d as EventsStats, B as BufferStatus, D as DlqStatus, W as ILogger, P as IConfig, _ as IEventBus, a1 as IInvoke, a4 as IArtifacts } from './artifacts-DrVnkLzu.cjs';
|
|
3
|
+
export { a5 as ArtifactMeta, a6 as ArtifactWriteOptions, $ as EventHandler, J as ILLMRouter, X as ILogBuffer, a2 as InvokeRequest, a3 as InvokeResponse, H as LLMAdapterBinding, s as LLMCacheCapability, u as LLMCacheDecisionTrace, o as LLMCacheMode, m as LLMCachePolicy, p as LLMCacheScope, F as LLMCapability, l as LLMExecutionPolicy, a7 as LLMRequestMetadata, G as LLMResolution, t as LLMStreamCapability, q as LLMStreamMode, n as LLMStreamPolicy, C as LLMTier, v as LLMTool, w as LLMToolCall, Y as LogLevel, a as LogQuery, L as LogRecord, T as TIER_ORDER, a0 as Unsubscribe, U as UseLLMOptions, K as isTierHigher, M as isTierLower } from './artifacts-DrVnkLzu.cjs';
|
|
4
|
+
export { I as ILogReader, L as LogCapabilities, a as LogQueryOptions, b as LogQueryResult, c as LogSearchOptions, d as LogSearchResult, e as LogStats } from './log-reader-BVohbSMB.cjs';
|
|
5
|
+
export { j as CronContext, C as CronExpression, k as CronHandler, i as CronJob, h as ICronManager, d as IJobScheduler, l as IResourceManager, I as IWorkflowEngine, J as JobDefinition, g as JobFilter, e as JobHandle, f as JobStatus, o as ResourceAvailability, n as ResourceSlot, m as ResourceType, R as RetryPolicy, T as TenantQuotas, c as WorkflowFilter, W as WorkflowOptions, a as WorkflowRun, b as WorkflowStepRun } from './resources-DaufJFad.cjs';
|
|
6
|
+
import './database-DGV6a1nj.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @module @kb-labs/core-platform/wrappers/analytics-llm
|
|
10
|
+
* AnalyticsLLM - ILLM wrapper that tracks usage to analytics.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* ILLM wrapper that tracks all LLM calls to analytics.
|
|
15
|
+
*
|
|
16
|
+
* Features:
|
|
17
|
+
* - Tracks every LLM completion with token usage
|
|
18
|
+
* - Records model, prompt/completion tokens, timestamps
|
|
19
|
+
* - Transparent (implements ILLM interface)
|
|
20
|
+
* - Automatically calculates cost estimates
|
|
21
|
+
*
|
|
22
|
+
* Tracked metrics:
|
|
23
|
+
* - llm.completion.started
|
|
24
|
+
* - llm.completion.completed (with usage, duration, model)
|
|
25
|
+
* - llm.completion.error (with error details)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const trackedLLM = new AnalyticsLLM(realLLM, analytics);
|
|
30
|
+
*
|
|
31
|
+
* // Automatically tracked
|
|
32
|
+
* const response = await trackedLLM.complete('Hello');
|
|
33
|
+
* // → Tracks: model, tokens, duration
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare class AnalyticsLLM implements ILLM {
|
|
37
|
+
private realLLM;
|
|
38
|
+
private analytics;
|
|
39
|
+
constructor(realLLM: ILLM, analytics: IAnalytics);
|
|
40
|
+
getProtocolCapabilities(): Promise<LLMProtocolCapabilities>;
|
|
41
|
+
/**
|
|
42
|
+
* Generate a completion with analytics tracking.
|
|
43
|
+
*/
|
|
44
|
+
complete(prompt: string, options?: LLMOptions): Promise<LLMResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Stream a completion.
|
|
47
|
+
* Note: Streaming is harder to track token-by-token, so we track start/end only.
|
|
48
|
+
*/
|
|
49
|
+
stream(prompt: string, options?: LLMOptions): AsyncIterable<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Chat with native tool calling support (optional).
|
|
52
|
+
* Proxies to underlying LLM if it supports chatWithTools.
|
|
53
|
+
*/
|
|
54
|
+
chatWithTools(messages: LLMMessage[], options: LLMToolCallOptions): Promise<LLMToolCallResponse>;
|
|
55
|
+
private trackCacheOutcome;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @module @kb-labs/core-platform/wrappers/analytics-embeddings
|
|
60
|
+
* Analytics wrapper for IEmbeddings that tracks usage
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Analytics wrapper for embeddings adapter.
|
|
65
|
+
* Tracks all embedding operations to analytics.
|
|
66
|
+
*/
|
|
67
|
+
declare class AnalyticsEmbeddings implements IEmbeddings {
|
|
68
|
+
private realEmbeddings;
|
|
69
|
+
private analytics;
|
|
70
|
+
constructor(realEmbeddings: IEmbeddings, analytics: IAnalytics);
|
|
71
|
+
get dimensions(): number;
|
|
72
|
+
getDimensions(): Promise<number>;
|
|
73
|
+
embed(text: string): Promise<number[]>;
|
|
74
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @module @kb-labs/core-platform/wrappers/analytics-vector-store
|
|
79
|
+
* Analytics wrapper for IVectorStore that tracks usage
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Analytics wrapper for vector store adapter.
|
|
84
|
+
* Tracks all vector operations to analytics.
|
|
85
|
+
*/
|
|
86
|
+
declare class AnalyticsVectorStore implements IVectorStore {
|
|
87
|
+
private realVectorStore;
|
|
88
|
+
private analytics;
|
|
89
|
+
constructor(realVectorStore: IVectorStore, analytics: IAnalytics);
|
|
90
|
+
search(query: number[], limit: number, filter?: VectorFilter): Promise<VectorSearchResult[]>;
|
|
91
|
+
upsert(vectors: VectorRecord[]): Promise<void>;
|
|
92
|
+
delete(ids: string[]): Promise<void>;
|
|
93
|
+
count(): Promise<number>;
|
|
94
|
+
get(ids: string[]): Promise<VectorRecord[]>;
|
|
95
|
+
query(filter: VectorFilter): Promise<VectorRecord[]>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @module @kb-labs/core-platform/wrappers/analytics-cache
|
|
100
|
+
* Analytics wrapper for ICache that tracks usage
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Analytics wrapper for cache adapter.
|
|
105
|
+
* Tracks all cache operations including hit/miss rates.
|
|
106
|
+
*/
|
|
107
|
+
declare class AnalyticsCache implements ICache {
|
|
108
|
+
private realCache;
|
|
109
|
+
private analytics;
|
|
110
|
+
constructor(realCache: ICache, analytics: IAnalytics);
|
|
111
|
+
get<T>(key: string): Promise<T | null>;
|
|
112
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
113
|
+
delete(key: string): Promise<void>;
|
|
114
|
+
clear(pattern?: string): Promise<void>;
|
|
115
|
+
zadd(key: string, score: number, member: string): Promise<void>;
|
|
116
|
+
zrangebyscore(key: string, min: number, max: number): Promise<string[]>;
|
|
117
|
+
zrem(key: string, member: string): Promise<void>;
|
|
118
|
+
setIfNotExists<T>(key: string, value: T, ttl?: number): Promise<boolean>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @module @kb-labs/core-platform/wrappers/analytics-storage
|
|
123
|
+
* Analytics wrapper for IStorage that tracks usage
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Analytics wrapper for storage adapter.
|
|
128
|
+
* Tracks all file operations including read/write bandwidth.
|
|
129
|
+
*/
|
|
130
|
+
declare class AnalyticsStorage implements IStorage {
|
|
131
|
+
private realStorage;
|
|
132
|
+
private analytics;
|
|
133
|
+
constructor(realStorage: IStorage, analytics: IAnalytics);
|
|
134
|
+
read(path: string): Promise<Buffer | null>;
|
|
135
|
+
write(path: string, data: Buffer): Promise<void>;
|
|
136
|
+
delete(path: string): Promise<void>;
|
|
137
|
+
list(prefix: string): Promise<string[]>;
|
|
138
|
+
exists(path: string): Promise<boolean>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @module @kb-labs/core-platform/wrappers/scoped-analytics
|
|
143
|
+
* Analytics wrapper that overrides source attribution for plugin execution
|
|
144
|
+
*
|
|
145
|
+
* Problem: All analytics events show source from root package.json (@kb-labs/ai-review)
|
|
146
|
+
* Solution: Use IAnalytics.setSource() to override source.product with actual plugin ID
|
|
147
|
+
*
|
|
148
|
+
* Used by: core-sandbox/handler-executor to inject plugin-specific source
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* ScopedAnalytics - wraps IAnalytics to override source attribution
|
|
153
|
+
*
|
|
154
|
+
* This wrapper uses the new setSource() method to modify the analytics
|
|
155
|
+
* adapter's source before delegating all calls.
|
|
156
|
+
*
|
|
157
|
+
* Design:
|
|
158
|
+
* - Calls setSource() on underlying adapter if available (FileAnalytics, future HTTP adapters)
|
|
159
|
+
* - For adapters without setSource() (NoOpAnalytics), just delegates (no-op is fine)
|
|
160
|
+
* - Transparently delegates all IAnalytics methods
|
|
161
|
+
* - Safe to nest with other wrappers (AnalyticsEmbeddings, QueuedEmbeddings)
|
|
162
|
+
*
|
|
163
|
+
* Usage:
|
|
164
|
+
* ```typescript
|
|
165
|
+
* const scoped = new ScopedAnalytics(platform.analytics, {
|
|
166
|
+
* product: '@kb-labs/mind',
|
|
167
|
+
* version: '0.1.0'
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* await scoped.track('mind.rag-index.started', { scope: 'default' });
|
|
171
|
+
* // Event will have source.product = '@kb-labs/mind' instead of root package
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare class ScopedAnalytics implements IAnalytics {
|
|
175
|
+
private readonly realAnalytics;
|
|
176
|
+
private readonly scopedSource;
|
|
177
|
+
constructor(realAnalytics: IAnalytics, scopedSource: {
|
|
178
|
+
product: string;
|
|
179
|
+
version: string;
|
|
180
|
+
});
|
|
181
|
+
track(event: string, properties?: Record<string, unknown>): Promise<void>;
|
|
182
|
+
identify(userId: string, traits?: Record<string, unknown>): Promise<void>;
|
|
183
|
+
flush(): Promise<void>;
|
|
184
|
+
getEvents(query?: EventsQuery): Promise<EventsResponse>;
|
|
185
|
+
getStats(): Promise<EventsStats>;
|
|
186
|
+
getBufferStatus(): Promise<BufferStatus | null>;
|
|
187
|
+
getDlqStatus(): Promise<DlqStatus | null>;
|
|
188
|
+
/**
|
|
189
|
+
* Get current source from underlying adapter
|
|
190
|
+
*/
|
|
191
|
+
getSource(): {
|
|
192
|
+
product: string;
|
|
193
|
+
version: string;
|
|
194
|
+
} | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Delegate setSource to underlying adapter
|
|
197
|
+
*/
|
|
198
|
+
setSource(source: {
|
|
199
|
+
product: string;
|
|
200
|
+
version: string;
|
|
201
|
+
}): void;
|
|
202
|
+
/**
|
|
203
|
+
* Get the scoped source (for testing/debugging)
|
|
204
|
+
*/
|
|
205
|
+
getScopedSource(): {
|
|
206
|
+
product: string;
|
|
207
|
+
version: string;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Get the underlying analytics adapter (for introspection)
|
|
211
|
+
*/
|
|
212
|
+
getUnderlyingAdapter(): IAnalytics;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Create scoped analytics wrapper
|
|
216
|
+
*
|
|
217
|
+
* @param analytics - Original analytics adapter
|
|
218
|
+
* @param scopedSource - Override source (plugin ID and version)
|
|
219
|
+
* @returns Scoped analytics wrapper
|
|
220
|
+
*/
|
|
221
|
+
declare function createScopedAnalytics(analytics: IAnalytics, scopedSource: {
|
|
222
|
+
product: string;
|
|
223
|
+
version: string;
|
|
224
|
+
}): ScopedAnalytics;
|
|
225
|
+
/**
|
|
226
|
+
* Check if adapter is already scoped
|
|
227
|
+
*/
|
|
228
|
+
declare function isScopedAnalytics(analytics: IAnalytics): analytics is ScopedAnalytics;
|
|
229
|
+
/**
|
|
230
|
+
* Unwrap scoped analytics to get original adapter
|
|
231
|
+
*/
|
|
232
|
+
declare function unwrapScopedAnalytics(analytics: IAnalytics): IAnalytics;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @module @kb-labs/core-platform/logging/prefixed-logger
|
|
236
|
+
*
|
|
237
|
+
* Prefixed logger wrapper that prevents plugins from overriding system observability fields.
|
|
238
|
+
*
|
|
239
|
+
* ## Problem
|
|
240
|
+
*
|
|
241
|
+
* When plugins call `ctx.platform.logger.child({ reqId: 'custom' })`, they can accidentally
|
|
242
|
+
* override system observability fields like `reqId`, `traceId`, `tenantId`, etc.
|
|
243
|
+
*
|
|
244
|
+
* ## Solution
|
|
245
|
+
*
|
|
246
|
+
* This wrapper automatically renames conflicting fields by adding a `plugin_` prefix:
|
|
247
|
+
* - `reqId` → `plugin_reqId`
|
|
248
|
+
* - `traceId` → `plugin_traceId`
|
|
249
|
+
* - etc.
|
|
250
|
+
*
|
|
251
|
+
* Non-conflicting fields pass through unchanged.
|
|
252
|
+
*
|
|
253
|
+
* ## Example
|
|
254
|
+
*
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const baseLogger = platform.logger.child({ reqId: 'req-123', traceId: 'trace-456' });
|
|
257
|
+
* const prefixed = createPrefixedLogger(baseLogger);
|
|
258
|
+
*
|
|
259
|
+
* // Plugin tries to override system fields
|
|
260
|
+
* const pluginLogger = prefixed.child({ reqId: 'custom', userId: '789' });
|
|
261
|
+
* pluginLogger.info('test');
|
|
262
|
+
*
|
|
263
|
+
* // Result:
|
|
264
|
+
* {
|
|
265
|
+
* reqId: 'req-123', // ← System field preserved
|
|
266
|
+
* plugin_reqId: 'custom', // ← Plugin field renamed
|
|
267
|
+
* userId: '789', // ← Non-conflicting field unchanged
|
|
268
|
+
* msg: 'test'
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* System observability fields that should not be overridden by plugins.
|
|
275
|
+
*
|
|
276
|
+
* These fields are set by the platform based on hostContext and should remain
|
|
277
|
+
* immutable throughout the plugin execution lifecycle.
|
|
278
|
+
*/
|
|
279
|
+
declare const SYSTEM_LOG_FIELDS: Set<string>;
|
|
280
|
+
/**
|
|
281
|
+
* Create a prefixed logger that renames conflicting fields.
|
|
282
|
+
*
|
|
283
|
+
* @param baseLogger - Base logger instance
|
|
284
|
+
* @param options - Configuration options
|
|
285
|
+
* @returns Wrapped logger with field prefixing
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const enrichedLogger = platform.logger.child({ reqId: 'req-123' });
|
|
290
|
+
* const prefixed = createPrefixedLogger(enrichedLogger);
|
|
291
|
+
*
|
|
292
|
+
* // Plugins can't override system fields
|
|
293
|
+
* const userLogger = prefixed.child({ reqId: 'custom', foo: 'bar' });
|
|
294
|
+
* // → { reqId: 'req-123', plugin_reqId: 'custom', foo: 'bar' }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
declare function createPrefixedLogger(baseLogger: ILogger, options?: {
|
|
298
|
+
/** Prefix for renamed fields (default: 'plugin_') */
|
|
299
|
+
prefix?: string;
|
|
300
|
+
/** Warn in development when renaming fields (default: true) */
|
|
301
|
+
warnOnRename?: boolean;
|
|
302
|
+
/** Custom set of protected fields (default: SYSTEM_LOG_FIELDS) */
|
|
303
|
+
protectedFields?: Set<string>;
|
|
304
|
+
}): ILogger;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* @module @kb-labs/core-platform/learning/history-store
|
|
308
|
+
* Abstraction for storing and querying query history.
|
|
309
|
+
*/
|
|
310
|
+
interface HistoryRecord {
|
|
311
|
+
id: string;
|
|
312
|
+
query: string;
|
|
313
|
+
queryHash: string;
|
|
314
|
+
scopeId: string;
|
|
315
|
+
timestamp: number;
|
|
316
|
+
topChunkIds: string[];
|
|
317
|
+
resultChunkIds: string[];
|
|
318
|
+
reasoningPlan?: unknown;
|
|
319
|
+
queryVector?: number[];
|
|
320
|
+
metadata?: Record<string, unknown>;
|
|
321
|
+
}
|
|
322
|
+
interface HistoryFindOptions {
|
|
323
|
+
scopeId: string;
|
|
324
|
+
queryHash?: string;
|
|
325
|
+
queryVector?: number[];
|
|
326
|
+
limit?: number;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* History store interface.
|
|
330
|
+
* Implementations: memory, file-based (platform storage), optional vector-backed.
|
|
331
|
+
*/
|
|
332
|
+
interface IHistoryStore {
|
|
333
|
+
save(record: HistoryRecord): Promise<void>;
|
|
334
|
+
find(options: HistoryFindOptions): Promise<HistoryRecord[]>;
|
|
335
|
+
popular(scopeId: string, limit?: number): Promise<Array<{
|
|
336
|
+
query: string;
|
|
337
|
+
count: number;
|
|
338
|
+
}>>;
|
|
339
|
+
saveReasoningPlan?(record: HistoryRecord): Promise<void>;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @module @kb-labs/core-platform/learning/feedback-store
|
|
344
|
+
* Abstraction for storing user feedback on answers.
|
|
345
|
+
*/
|
|
346
|
+
type FeedbackType = 'explicit' | 'implicit' | 'self';
|
|
347
|
+
interface FeedbackRecord {
|
|
348
|
+
id: string;
|
|
349
|
+
queryId: string;
|
|
350
|
+
chunkId: string;
|
|
351
|
+
scopeId: string;
|
|
352
|
+
type: FeedbackType;
|
|
353
|
+
score: number;
|
|
354
|
+
metadata?: Record<string, unknown>;
|
|
355
|
+
timestamp: number;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Feedback store interface.
|
|
359
|
+
* Implementations: memory, file-based (platform storage).
|
|
360
|
+
*/
|
|
361
|
+
interface IFeedbackStore {
|
|
362
|
+
save(record: FeedbackRecord): Promise<void>;
|
|
363
|
+
list(scopeId: string, limit?: number): Promise<FeedbackRecord[]>;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* In-memory history store with basic similarity search.
|
|
368
|
+
* Intended as a fallback when persistent storage is not configured.
|
|
369
|
+
*/
|
|
370
|
+
declare class MemoryHistoryStore implements IHistoryStore {
|
|
371
|
+
private readonly entries;
|
|
372
|
+
private readonly maxEntries;
|
|
373
|
+
constructor(maxEntries?: number);
|
|
374
|
+
save(record: HistoryRecord): Promise<void>;
|
|
375
|
+
find(options: HistoryFindOptions): Promise<HistoryRecord[]>;
|
|
376
|
+
popular(scopeId: string, limit?: number): Promise<Array<{
|
|
377
|
+
query: string;
|
|
378
|
+
count: number;
|
|
379
|
+
}>>;
|
|
380
|
+
saveReasoningPlan(record: HistoryRecord): Promise<void>;
|
|
381
|
+
private cosineSimilarity;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* In-memory feedback store. Simple FIFO with optional cap.
|
|
386
|
+
*/
|
|
387
|
+
declare class MemoryFeedbackStore implements IFeedbackStore {
|
|
388
|
+
private readonly entries;
|
|
389
|
+
private readonly maxEntries;
|
|
390
|
+
constructor(maxEntries?: number);
|
|
391
|
+
save(record: FeedbackRecord): Promise<void>;
|
|
392
|
+
list(scopeId: string, limit?: number): Promise<FeedbackRecord[]>;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
interface FileHistoryStoreOptions {
|
|
396
|
+
basePath?: string;
|
|
397
|
+
filePrefix?: string;
|
|
398
|
+
maxRecordsPerFile?: number;
|
|
399
|
+
maxFiles?: number;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* File-based history store using platform.storage (JSONL segments with basic rotation).
|
|
403
|
+
*/
|
|
404
|
+
declare class FileHistoryStore implements IHistoryStore {
|
|
405
|
+
private readonly storage;
|
|
406
|
+
private readonly basePath;
|
|
407
|
+
private readonly filePrefix;
|
|
408
|
+
private readonly maxRecordsPerFile;
|
|
409
|
+
private readonly maxFiles;
|
|
410
|
+
constructor(storage: IStorage, options?: FileHistoryStoreOptions);
|
|
411
|
+
save(record: HistoryRecord): Promise<void>;
|
|
412
|
+
find(options: HistoryFindOptions): Promise<HistoryRecord[]>;
|
|
413
|
+
popular(scopeId: string, limit?: number): Promise<Array<{
|
|
414
|
+
query: string;
|
|
415
|
+
count: number;
|
|
416
|
+
}>>;
|
|
417
|
+
saveReasoningPlan(record: HistoryRecord): Promise<void>;
|
|
418
|
+
private getWritableFile;
|
|
419
|
+
private getFilesSorted;
|
|
420
|
+
private segmentPath;
|
|
421
|
+
private enforceRotation;
|
|
422
|
+
private ensureTrailingSlash;
|
|
423
|
+
private cosineSimilarity;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
interface FileFeedbackStoreOptions {
|
|
427
|
+
basePath?: string;
|
|
428
|
+
filePrefix?: string;
|
|
429
|
+
maxRecordsPerFile?: number;
|
|
430
|
+
maxFiles?: number;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* File-based feedback store using platform.storage (JSONL segments with basic rotation).
|
|
434
|
+
*/
|
|
435
|
+
declare class FileFeedbackStore implements IFeedbackStore {
|
|
436
|
+
private readonly storage;
|
|
437
|
+
private readonly basePath;
|
|
438
|
+
private readonly filePrefix;
|
|
439
|
+
private readonly maxRecordsPerFile;
|
|
440
|
+
private readonly maxFiles;
|
|
441
|
+
constructor(storage: IStorage, options?: FileFeedbackStoreOptions);
|
|
442
|
+
save(record: FeedbackRecord): Promise<void>;
|
|
443
|
+
list(scopeId: string, limit?: number): Promise<FeedbackRecord[]>;
|
|
444
|
+
private getWritableFile;
|
|
445
|
+
private getFilesSorted;
|
|
446
|
+
private segmentPath;
|
|
447
|
+
private enforceRotation;
|
|
448
|
+
private ensureTrailingSlash;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* @module @kb-labs/core-platform/runs/run-types
|
|
453
|
+
* Full-cycle run state model and event schema.
|
|
454
|
+
*/
|
|
455
|
+
/**
|
|
456
|
+
* Top-level full-cycle run status.
|
|
457
|
+
*/
|
|
458
|
+
type RunStatus = "queued" | "provisioning" | "executing" | "gating" | "human_review" | "finalizing" | "completed" | "failed" | "failed_by_review" | "cancelled";
|
|
459
|
+
/**
|
|
460
|
+
* Run step status.
|
|
461
|
+
*/
|
|
462
|
+
type RunStepStatus = "pending" | "in_progress" | "retrying" | "skipped" | "completed" | "failed" | "cancelled";
|
|
463
|
+
/**
|
|
464
|
+
* Run step definition.
|
|
465
|
+
*/
|
|
466
|
+
interface RunStepDefinition {
|
|
467
|
+
id: string;
|
|
468
|
+
name: string;
|
|
469
|
+
plugin?: string;
|
|
470
|
+
action?: string;
|
|
471
|
+
timeoutMs?: number;
|
|
472
|
+
retryLimit?: number;
|
|
473
|
+
metadata?: Record<string, unknown>;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Run creation request.
|
|
477
|
+
*/
|
|
478
|
+
interface CreateRunRequest {
|
|
479
|
+
taskRef: string;
|
|
480
|
+
templateId: string;
|
|
481
|
+
actorId?: string;
|
|
482
|
+
tenantId?: string;
|
|
483
|
+
priority?: "low" | "medium" | "high" | "critical";
|
|
484
|
+
metadata?: Record<string, unknown>;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Run record.
|
|
488
|
+
*/
|
|
489
|
+
interface RunRecord {
|
|
490
|
+
runId: string;
|
|
491
|
+
status: RunStatus;
|
|
492
|
+
taskRef: string;
|
|
493
|
+
templateId: string;
|
|
494
|
+
actorId?: string;
|
|
495
|
+
tenantId?: string;
|
|
496
|
+
environmentId?: string;
|
|
497
|
+
createdAt: string;
|
|
498
|
+
updatedAt: string;
|
|
499
|
+
startedAt?: string;
|
|
500
|
+
completedAt?: string;
|
|
501
|
+
metadata?: Record<string, unknown>;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Run step record.
|
|
505
|
+
*/
|
|
506
|
+
interface RunStepRecord {
|
|
507
|
+
runId: string;
|
|
508
|
+
stepId: string;
|
|
509
|
+
status: RunStepStatus;
|
|
510
|
+
attempt: number;
|
|
511
|
+
startedAt?: string;
|
|
512
|
+
completedAt?: string;
|
|
513
|
+
errorCode?: string;
|
|
514
|
+
errorMessage?: string;
|
|
515
|
+
metadata?: Record<string, unknown>;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Run event type.
|
|
519
|
+
*/
|
|
520
|
+
type RunEventType = "run.created" | "run.status.changed" | "run.failed" | "run.completed" | "run.cancelled" | "run.review.approved" | "run.review.rejected" | "step.started" | "step.completed" | "step.failed" | "environment.provisioning" | "environment.ready" | "environment.destroyed";
|
|
521
|
+
/**
|
|
522
|
+
* Timeline event for run auditability.
|
|
523
|
+
*/
|
|
524
|
+
interface RunEvent {
|
|
525
|
+
eventId: string;
|
|
526
|
+
runId: string;
|
|
527
|
+
type: RunEventType;
|
|
528
|
+
at: string;
|
|
529
|
+
fromStatus?: RunStatus;
|
|
530
|
+
toStatus?: RunStatus;
|
|
531
|
+
stepId?: string;
|
|
532
|
+
environmentId?: string;
|
|
533
|
+
reason?: string;
|
|
534
|
+
payload?: Record<string, unknown>;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Terminal run statuses.
|
|
538
|
+
*/
|
|
539
|
+
declare const TERMINAL_RUN_STATUSES: ReadonlySet<RunStatus>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* @module @kb-labs/core-platform/platform-adapters
|
|
543
|
+
* Unified interface for all platform adapters.
|
|
544
|
+
* Used by IPC servers to access adapters for proxying.
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Platform adapters container interface.
|
|
549
|
+
* Provides access to all platform adapters for IPC proxying.
|
|
550
|
+
*
|
|
551
|
+
* This interface is implemented by PlatformContainer in core-runtime.
|
|
552
|
+
* IPC servers in core-ipc use this interface to access adapters.
|
|
553
|
+
*/
|
|
554
|
+
interface IPlatformAdapters {
|
|
555
|
+
/** Logger adapter */
|
|
556
|
+
readonly logger: ILogger;
|
|
557
|
+
/** Analytics adapter (telemetry, events) */
|
|
558
|
+
readonly analytics: IAnalytics;
|
|
559
|
+
/** Vector store adapter (Qdrant, Pinecone, etc.) */
|
|
560
|
+
readonly vectorStore: IVectorStore;
|
|
561
|
+
/** LLM adapter (OpenAI, Anthropic, etc.) */
|
|
562
|
+
readonly llm: ILLM;
|
|
563
|
+
/** Embeddings adapter (OpenAI, Cohere, etc.) */
|
|
564
|
+
readonly embeddings: IEmbeddings;
|
|
565
|
+
/** Cache adapter (Redis, in-memory, etc.) */
|
|
566
|
+
readonly cache: ICache;
|
|
567
|
+
/** Config adapter (file, env, remote, etc.) */
|
|
568
|
+
readonly config: IConfig;
|
|
569
|
+
/** Storage adapter (S3, filesystem, etc.) */
|
|
570
|
+
readonly storage: IStorage;
|
|
571
|
+
/** Event bus adapter (in-memory, Redis, etc.) */
|
|
572
|
+
readonly eventBus: IEventBus;
|
|
573
|
+
/** Invoke adapter (cross-plugin invocation) */
|
|
574
|
+
readonly invoke: IInvoke;
|
|
575
|
+
/** Artifacts adapter (build outputs, generated files) */
|
|
576
|
+
readonly artifacts: IArtifacts;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export { AnalyticsCache, AnalyticsEmbeddings, AnalyticsLLM, AnalyticsStorage, AnalyticsVectorStore, type CreateRunRequest, type FeedbackRecord, type FeedbackType, FileFeedbackStore, type FileFeedbackStoreOptions, FileHistoryStore, type FileHistoryStoreOptions, type HistoryFindOptions, type HistoryRecord, IAnalytics, IArtifacts, ICache, IConfig, IEmbeddings, IEventBus, type IFeedbackStore, type IHistoryStore, IInvoke, ILLM, ILogger, type IPlatformAdapters, IStorage, IVectorStore, LLMMessage, LLMOptions, LLMProtocolCapabilities, LLMResponse, LLMToolCallOptions, LLMToolCallResponse, MemoryFeedbackStore, MemoryHistoryStore, type RunEvent, type RunEventType, type RunRecord, type RunStatus, type RunStepDefinition, type RunStepRecord, type RunStepStatus, SYSTEM_LOG_FIELDS, ScopedAnalytics, TERMINAL_RUN_STATUSES, VectorFilter, VectorRecord, VectorSearchResult, createPrefixedLogger, createScopedAnalytics, isScopedAnalytics, unwrapScopedAnalytics };
|