@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/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @kb-labs/core-platform
|
|
2
|
+
|
|
3
|
+
> Pure abstractions for KB Labs platform. Zero dependencies.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This package contains **only interfaces** - no implementations with external dependencies.
|
|
8
|
+
All plugins and adapters depend on these interfaces.
|
|
9
|
+
|
|
10
|
+
## Structure
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
src/
|
|
14
|
+
├── adapters/ # Replaceable adapter interfaces
|
|
15
|
+
│ ├── analytics.ts # IAnalytics
|
|
16
|
+
│ ├── vector-store.ts # IVectorStore
|
|
17
|
+
│ ├── llm.ts # ILLM
|
|
18
|
+
│ ├── embeddings.ts # IEmbeddings
|
|
19
|
+
│ ├── cache.ts # ICache
|
|
20
|
+
│ ├── storage.ts # IStorage
|
|
21
|
+
│ ├── logger.ts # ILogger
|
|
22
|
+
│ └── event-bus.ts # IEventBus
|
|
23
|
+
├── core/ # Core feature interfaces (not replaceable)
|
|
24
|
+
│ ├── workflow.ts # IWorkflowEngine
|
|
25
|
+
│ ├── jobs.ts # IJobScheduler
|
|
26
|
+
│ ├── cron.ts # ICronManager
|
|
27
|
+
│ └── resources.ts # IResourceManager
|
|
28
|
+
└── noop/ # NoOp + In-memory implementations
|
|
29
|
+
├── adapters/ # NoOpAnalytics, MemoryCache, etc.
|
|
30
|
+
└── core/ # NoOpWorkflowEngine, etc.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### In Plugins
|
|
36
|
+
```typescript
|
|
37
|
+
import type { IAnalytics, IVectorStore } from '@kb-labs/core-platform';
|
|
38
|
+
|
|
39
|
+
// Get through PluginContext
|
|
40
|
+
export async function handler(ctx: PluginContext) {
|
|
41
|
+
await ctx.analytics.track('event');
|
|
42
|
+
await ctx.vectorStore.search([...]);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### In Adapters
|
|
47
|
+
```typescript
|
|
48
|
+
import type { IAnalytics } from '@kb-labs/core-platform';
|
|
49
|
+
|
|
50
|
+
export function createAdapter(): IAnalytics {
|
|
51
|
+
return {
|
|
52
|
+
async track(event, props) { /* ... */ },
|
|
53
|
+
async identify(userId, traits) { /* ... */ },
|
|
54
|
+
async flush() { /* ... */ },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Using NoOp Implementations
|
|
60
|
+
```typescript
|
|
61
|
+
import {
|
|
62
|
+
NoOpAnalytics,
|
|
63
|
+
MemoryCache,
|
|
64
|
+
MockLLM,
|
|
65
|
+
} from '@kb-labs/core-platform/noop';
|
|
66
|
+
|
|
67
|
+
// For testing
|
|
68
|
+
const analytics = new NoOpAnalytics();
|
|
69
|
+
const cache = new MemoryCache();
|
|
70
|
+
const llm = new MockLLM();
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Adapter Interfaces
|
|
74
|
+
|
|
75
|
+
| Interface | Description | NoOp Implementation |
|
|
76
|
+
|-----------|-------------|---------------------|
|
|
77
|
+
| `IAnalytics` | Event tracking and user identification | `NoOpAnalytics` |
|
|
78
|
+
| `IVectorStore` | Vector similarity search | `MemoryVectorStore` |
|
|
79
|
+
| `ILLM` | Large language model completion | `MockLLM` |
|
|
80
|
+
| `IEmbeddings` | Text embeddings generation | `MockEmbeddings` |
|
|
81
|
+
| `ICache` | Key-value caching with TTL | `MemoryCache` |
|
|
82
|
+
| `IStorage` | File/blob storage | `MemoryStorage` |
|
|
83
|
+
| `ILogger` | Structured logging | `ConsoleLogger` |
|
|
84
|
+
| `IEventBus` | Pub/sub event system | `MemoryEventBus` |
|
|
85
|
+
|
|
86
|
+
## Core Feature Interfaces
|
|
87
|
+
|
|
88
|
+
| Interface | Description | NoOp Implementation |
|
|
89
|
+
|-----------|-------------|---------------------|
|
|
90
|
+
| `IWorkflowEngine` | Workflow execution and management | `NoOpWorkflowEngine` (throws) |
|
|
91
|
+
| `IJobScheduler` | Background job scheduling | `NoOpJobScheduler` (sync) |
|
|
92
|
+
| `ICronManager` | Cron job registration | `NoOpCronManager` |
|
|
93
|
+
| `IResourceManager` | Resource quotas and limits | `NoOpResourceManager` (unlimited) |
|
|
94
|
+
|
|
95
|
+
## Rules
|
|
96
|
+
|
|
97
|
+
1. **Zero external dependencies** - only TypeScript types
|
|
98
|
+
2. **Export types, not implementations** - implementations in noop/
|
|
99
|
+
3. **Follow Pyramid Rule** - package name = core-platform
|
|
100
|
+
|
|
101
|
+
## Related Packages
|
|
102
|
+
|
|
103
|
+
- `@kb-labs/core-runtime` - DI container and core implementations
|
|
104
|
+
- `@kb-labs/plugin-runtime` - PluginContext using these interfaces
|
|
105
|
+
|
|
106
|
+
## ADR
|
|
107
|
+
|
|
108
|
+
See [ADR-0040: Platform Core Adapter Architecture](../../docs/adr/0040-platform-core-adapter-architecture.md)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ulid = require('ulid');
|
|
4
|
+
|
|
5
|
+
// src/adapters/llm-types.ts
|
|
6
|
+
var TIER_ORDER = [
|
|
7
|
+
"small",
|
|
8
|
+
"medium",
|
|
9
|
+
"large"
|
|
10
|
+
];
|
|
11
|
+
function isTierHigher(a, b) {
|
|
12
|
+
return TIER_ORDER.indexOf(a) > TIER_ORDER.indexOf(b);
|
|
13
|
+
}
|
|
14
|
+
function isTierLower(a, b) {
|
|
15
|
+
return TIER_ORDER.indexOf(a) < TIER_ORDER.indexOf(b);
|
|
16
|
+
}
|
|
17
|
+
function generateLogId() {
|
|
18
|
+
return ulid.ulid();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.TIER_ORDER = TIER_ORDER;
|
|
22
|
+
exports.generateLogId = generateLogId;
|
|
23
|
+
exports.isTierHigher = isTierHigher;
|
|
24
|
+
exports.isTierLower = isTierLower;
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
26
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/llm-types.ts","../../src/adapters/logger.ts"],"names":["ulid"],"mappings":";;;;;AAqIO,IAAM,UAAA,GAAiC;AAAA,EAC5C,OAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAKO,SAAS,YAAA,CAAa,GAAY,CAAA,EAAqB;AAC5D,EAAA,OAAO,WAAW,OAAA,CAAQ,CAAC,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAC,CAAA;AACrD;AAKO,SAAS,WAAA,CAAY,GAAY,CAAA,EAAqB;AAC3D,EAAA,OAAO,WAAW,OAAA,CAAQ,CAAC,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAC,CAAA;AACrD;ACxHO,SAAS,aAAA,GAAwB;AACtC,EAAA,OAAOA,SAAA,EAAK;AACd","file":"index.cjs","sourcesContent":["/**\n * @module @kb-labs/core-platform/adapters/llm-types\n * LLM tier and capability types for adaptive model routing.\n *\n * These types define the abstract layer between plugins and LLM providers.\n * Plugins request tiers/capabilities, platform resolves to actual models.\n *\n * @example\n * ```typescript\n * import { LLMTier, LLMCapability, UseLLMOptions } from '@kb-labs/sdk';\n *\n * // Plugin requests by tier (user decides what model)\n * const llm = useLLM({ tier: 'small' });\n * const llm = useLLM({ tier: 'large', capabilities: ['reasoning'] });\n * ```\n */\n\nimport type { ILLM, LLMExecutionPolicy } from './llm.js';\n\n/**\n * Model quality tier - user-defined slots.\n *\n * Tiers are NOT tied to specific models. They are abstract slots\n * that the user fills with whatever models they want in config.\n *\n * Plugin intent:\n * - `small` - \"This task is simple, doesn't need much\"\n * - `medium` - \"Standard task\"\n * - `large` - \"Complex task, need maximum quality\"\n *\n * User decides what model maps to each tier in their config.\n */\nexport type LLMTier = \"small\" | \"medium\" | \"large\";\n\n/**\n * Model capabilities - task-optimized features.\n *\n * - `fast` - Lowest latency (for real-time responses)\n * - `reasoning` - Complex reasoning (o1, opus-level thinking)\n * - `coding` - Code-optimized (better at code generation/review)\n * - `vision` - Image input support\n */\nexport type LLMCapability = \"reasoning\" | \"coding\" | \"vision\" | \"fast\";\n\n/**\n * Options for useLLM() - plugin-facing API.\n *\n * Plugins specify what they need abstractly.\n * Platform resolves to actual provider/model based on user config.\n */\nexport interface UseLLMOptions {\n /**\n * Quality tier (user-defined slot).\n * Platform adapts if exact tier unavailable:\n * - Escalates up (small → medium) silently\n * - Degrades down (large → medium) with warning\n */\n tier?: LLMTier;\n\n /**\n * Required capabilities.\n * Platform selects model that supports ALL requested capabilities.\n */\n capabilities?: LLMCapability[];\n\n /**\n * Optional execution policy applied to this bound LLM instance.\n * Can be overridden per-call via LLMOptions.execution.\n */\n execution?: LLMExecutionPolicy;\n}\n\n/**\n * Resolution result from tier/capability matching.\n * Internal type used by LLMRouter.\n */\nexport interface LLMResolution {\n /** Resolved provider ID (e.g., 'openai', 'anthropic') */\n provider: string;\n /** Resolved model name */\n model: string;\n /** Resource name for ResourceBroker (e.g., 'llm:openai') */\n resource: string;\n /** Original requested tier */\n requestedTier: LLMTier | undefined;\n /** Actual tier being used */\n actualTier: LLMTier;\n /** Whether this was escalated/degraded */\n adapted: boolean;\n /** Warning message if degraded */\n warning?: string;\n}\n\n/**\n * Resolved adapter binding — immutable snapshot of a tier resolution.\n * Returned by resolveAdapter() to avoid global state mutation.\n */\nexport interface LLMAdapterBinding {\n /** The concrete adapter instance (already wrapped with analytics, etc.) */\n adapter: ILLM;\n /** Resolved model name */\n model: string;\n /** Actual tier used */\n tier: LLMTier;\n}\n\n/**\n * LLM Router interface - extends ILLM with routing capabilities.\n * Implemented by @kb-labs/llm-router.\n */\nexport interface ILLMRouter {\n /** Get configured tier (what user set in config) */\n getConfiguredTier(): LLMTier;\n\n /** Resolve tier request to actual model (mutates router state — legacy) */\n resolve(options?: UseLLMOptions): LLMResolution;\n\n /**\n * Resolve tier and return an immutable adapter binding.\n * Does NOT mutate router state — safe for concurrent useLLM() calls.\n */\n resolveAdapter(options?: UseLLMOptions): Promise<LLMAdapterBinding>;\n\n /** Check if capability is available */\n hasCapability(capability: LLMCapability): boolean;\n\n /** Get available capabilities */\n getCapabilities(): LLMCapability[];\n}\n\n/**\n * Tier order for resolution (lowest to highest).\n */\nexport const TIER_ORDER: readonly LLMTier[] = [\n \"small\",\n \"medium\",\n \"large\",\n] as const;\n\n/**\n * Check if tier A is higher than tier B.\n */\nexport function isTierHigher(a: LLMTier, b: LLMTier): boolean {\n return TIER_ORDER.indexOf(a) > TIER_ORDER.indexOf(b);\n}\n\n/**\n * Check if tier A is lower than tier B.\n */\nexport function isTierLower(a: LLMTier, b: LLMTier): boolean {\n return TIER_ORDER.indexOf(a) < TIER_ORDER.indexOf(b);\n}\n","/**\n * @module @kb-labs/core-platform/adapters/logger\n * Logger abstraction for structured logging.\n */\n\nimport { ulid } from \"ulid\";\n\n/**\n * Log level enumeration\n */\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\";\n\n/**\n * Generate unique log ID using ULID.\n *\n * ULIDs are:\n * - Lexicographically sortable (timestamp-based)\n * - 26 characters (more compact than UUID's 36)\n * - URL-safe (base32 encoded)\n * - Monotonically increasing within same millisecond\n *\n * All logger adapters MUST use this function to ensure ID consistency.\n *\n * @returns ULID string (e.g., \"01ARZ3NDEKTSV4RRFFQ69G5FAV\")\n *\n * @example\n * ```typescript\n * const logId = generateLogId();\n * console.log(logId); // \"01HQVX5P7G3QR9Z8X5N4Y2K6E1\"\n * ```\n */\nexport function generateLogId(): string {\n return ulid();\n}\n\n/**\n * Structured log record\n */\nexport interface LogRecord {\n /** Unique log ID (ULID). Generated by logger adapter using generateLogId() */\n id: string;\n /** Timestamp (milliseconds since epoch) */\n timestamp: number;\n /** Log level */\n level: LogLevel;\n /** Log message */\n message: string;\n /** Structured fields (metadata) */\n fields: Record<string, unknown>;\n /** Source identifier (e.g., 'rest', 'workflow', 'cli') */\n source: string;\n}\n\n/**\n * Query filters for log retrieval\n */\nexport interface LogQuery {\n /** Minimum log level (inclusive) */\n level?: LogLevel;\n /** Filter by source */\n source?: string;\n /** Start timestamp (milliseconds since epoch) */\n from?: number;\n /** End timestamp (milliseconds since epoch) */\n to?: number;\n /** Maximum number of logs to return */\n limit?: number;\n}\n\n/**\n * Log buffer interface for streaming/querying logs\n */\nexport interface ILogBuffer {\n /**\n * Append log record to buffer\n */\n append(record: LogRecord): void;\n\n /**\n * Query logs with filters\n */\n query(query?: LogQuery): LogRecord[];\n\n /**\n * Subscribe to real-time log stream\n * @returns Unsubscribe function\n */\n subscribe(callback: (record: LogRecord) => void): () => void;\n\n /**\n * Get buffer statistics\n */\n getStats(): {\n total: number;\n bufferSize: number;\n oldestTimestamp: number | null;\n newestTimestamp: number | null;\n };\n}\n\n/**\n * Logger adapter interface.\n * Implementations: @kb-labs/adapters-pino (production), ConsoleLogger (noop)\n */\nexport interface ILogger {\n /**\n * Log info message.\n * @param message - Log message\n * @param meta - Optional metadata\n */\n info(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Log warning message.\n * @param message - Log message\n * @param meta - Optional metadata\n */\n warn(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Log error message.\n * @param message - Log message\n * @param error - Optional error object\n * @param meta - Optional metadata\n */\n error(message: string, error?: Error, meta?: Record<string, unknown>): void;\n\n /**\n * Log fatal error message (critical failures).\n * @param message - Log message\n * @param error - Optional error object\n * @param meta - Optional metadata\n */\n fatal(message: string, error?: Error, meta?: Record<string, unknown>): void;\n\n /**\n * Log debug message.\n * @param message - Log message\n * @param meta - Optional metadata\n */\n debug(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Log trace message (most verbose).\n * @param message - Log message\n * @param meta - Optional metadata\n */\n trace(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Create a child logger with additional context.\n * @param bindings - Context bindings (e.g., { plugin: 'mind', tenant: 'acme' })\n */\n child(bindings: Record<string, unknown>): ILogger;\n\n /**\n * Get log buffer for streaming/querying (optional feature).\n * Not all logger implementations support buffering.\n * @returns Log buffer if streaming is enabled, undefined otherwise\n */\n getLogBuffer?(): ILogBuffer | undefined;\n\n /**\n * Register callback for every log event (optional feature).\n * Used by platform to connect logger extensions (ring buffer, persistence).\n *\n * Extensions are called fire-and-forget (async errors are caught and logged).\n * Multiple extensions can be registered and will be called in priority order.\n *\n * @param callback - Function to call on each log event\n * @returns Unsubscribe function to remove the callback\n *\n * @example\n * ```typescript\n * const unsubscribe = logger.onLog((record) => {\n * ringBuffer.append(record);\n * persistence.write(record).catch(console.error);\n * });\n *\n * // Later: unsubscribe()\n * ```\n */\n onLog?(callback: (record: LogRecord) => void): () => void;\n}\n"]}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { L as LogRecord, a as LogQuery } from '../artifacts-DrVnkLzu.cjs';
|
|
3
|
+
export { A as AnalyticsContext, b as AnalyticsEvent, a5 as ArtifactMeta, a6 as ArtifactWriteOptions, B as BufferStatus, e as DailyStats, D as DlqStatus, $ as EventHandler, E as EventsQuery, c as EventsResponse, d as EventsStats, I as IAnalytics, a4 as IArtifacts, O as ICache, P as IConfig, N as IEmbeddings, _ as IEventBus, a1 as IInvoke, i as ILLM, J as ILLMRouter, X as ILogBuffer, W as ILogger, Q as IStorage, f as IVectorStore, 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, x as LLMMessage, j as LLMOptions, r as LLMProtocolCapabilities, G as LLMResolution, k as LLMResponse, t as LLMStreamCapability, q as LLMStreamMode, n as LLMStreamPolicy, C as LLMTier, v as LLMTool, w as LLMToolCall, y as LLMToolCallOptions, z as LLMToolCallResponse, Y as LogLevel, S as StatsQuery, R as StorageMetadata, T as TIER_ORDER, a0 as Unsubscribe, U as UseLLMOptions, h as VectorFilter, V as VectorRecord, g as VectorSearchResult, Z as generateLogId, K as isTierHigher, M as isTierLower } from '../artifacts-DrVnkLzu.cjs';
|
|
4
|
+
export { B as BaseDocument, D as DocumentFilter, c as DocumentUpdate, F as FilterOperators, d as FindOptions, g as IDatabaseProvider, b as IDocumentDatabase, e as IKeyValueDatabase, I as ISQLDatabase, f as ITimeSeriesDatabase, S as SQLQueryResult, a as SQLTransaction, T as TimeSeriesPoint } from '../database-DGV6a1nj.cjs';
|
|
5
|
+
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';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @module @kb-labs/core-platform/adapters/log-ring-buffer
|
|
9
|
+
* Ring buffer adapter interface for real-time log streaming.
|
|
10
|
+
*
|
|
11
|
+
* Purpose:
|
|
12
|
+
* - In-memory buffer with fixed size and TTL
|
|
13
|
+
* - Real-time subscription support (SSE)
|
|
14
|
+
* - Low latency access to recent logs
|
|
15
|
+
*
|
|
16
|
+
* Not for:
|
|
17
|
+
* - Historical queries (use ILogPersistence)
|
|
18
|
+
* - Cross-process log aggregation
|
|
19
|
+
* - Long-term storage
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Ring buffer for real-time log streaming.
|
|
24
|
+
*
|
|
25
|
+
* Design:
|
|
26
|
+
* - Fixed-size circular buffer (default 1000 logs)
|
|
27
|
+
* - Automatic eviction of oldest logs when buffer is full
|
|
28
|
+
* - Time-to-live expiration (default 1 hour)
|
|
29
|
+
* - Real-time subscription support for SSE streaming
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const buffer = createRingBufferAdapter({ maxSize: 1000, ttl: 3600000 });
|
|
34
|
+
*
|
|
35
|
+
* // Append logs
|
|
36
|
+
* buffer.append({ timestamp: Date.now(), level: 'info', message: 'Hello' });
|
|
37
|
+
*
|
|
38
|
+
* // Subscribe to real-time stream
|
|
39
|
+
* const unsubscribe = buffer.subscribe((log) => {
|
|
40
|
+
* console.log('New log:', log);
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Query recent logs
|
|
44
|
+
* const recentErrors = buffer.query({ level: 'error' });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
interface ILogRingBuffer {
|
|
48
|
+
/**
|
|
49
|
+
* Append log record to buffer.
|
|
50
|
+
* Evicts oldest record if buffer is full.
|
|
51
|
+
*
|
|
52
|
+
* @param record - Log record to append
|
|
53
|
+
*/
|
|
54
|
+
append(record: LogRecord): void;
|
|
55
|
+
/**
|
|
56
|
+
* Query logs from buffer.
|
|
57
|
+
*
|
|
58
|
+
* @param query - Optional filter (level, timestamp range, source)
|
|
59
|
+
* @returns Array of logs matching query (most recent first)
|
|
60
|
+
*/
|
|
61
|
+
query(query?: LogQuery): LogRecord[];
|
|
62
|
+
/**
|
|
63
|
+
* Subscribe to real-time log events.
|
|
64
|
+
* Callback is called for each new log record appended to buffer.
|
|
65
|
+
*
|
|
66
|
+
* @param callback - Called for each new log record
|
|
67
|
+
* @returns Unsubscribe function
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const unsubscribe = buffer.subscribe((log) => {
|
|
72
|
+
* if (log.level === 'error') {
|
|
73
|
+
* notifyUser(log);
|
|
74
|
+
* }
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Later: stop subscription
|
|
78
|
+
* unsubscribe();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
subscribe(callback: (record: LogRecord) => void): () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Get buffer statistics.
|
|
84
|
+
*
|
|
85
|
+
* @returns Buffer stats including size, capacity, and eviction count
|
|
86
|
+
*/
|
|
87
|
+
getStats(): {
|
|
88
|
+
/** Current number of logs in buffer */
|
|
89
|
+
size: number;
|
|
90
|
+
/** Maximum buffer size */
|
|
91
|
+
maxSize: number;
|
|
92
|
+
/** Timestamp of oldest log in buffer (0 if empty) */
|
|
93
|
+
oldestTimestamp: number;
|
|
94
|
+
/** Timestamp of newest log in buffer (0 if empty) */
|
|
95
|
+
newestTimestamp: number;
|
|
96
|
+
/** Total number of logs evicted due to size/TTL */
|
|
97
|
+
evictions: number;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Clear all logs from buffer.
|
|
101
|
+
* Useful for testing or manual cleanup.
|
|
102
|
+
*/
|
|
103
|
+
clear(): void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Configuration for log ring buffer adapter.
|
|
107
|
+
*/
|
|
108
|
+
interface LogRingBufferConfig {
|
|
109
|
+
/**
|
|
110
|
+
* Maximum number of logs to keep in memory.
|
|
111
|
+
* When buffer is full, oldest log is evicted.
|
|
112
|
+
*
|
|
113
|
+
* @default 1000
|
|
114
|
+
*/
|
|
115
|
+
maxSize?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Time-to-live for logs in milliseconds.
|
|
118
|
+
* Logs older than this are automatically evicted.
|
|
119
|
+
*
|
|
120
|
+
* @default 3600000 (1 hour)
|
|
121
|
+
*/
|
|
122
|
+
ttl?: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { type ILogRingBuffer, LogQuery, LogRecord, type LogRingBufferConfig };
|
|
@@ -0,0 +1,125 @@
|
|
|
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--COac4P-.js';
|
|
2
|
+
import { L as LogRecord, a as LogQuery } from '../artifacts-DrVnkLzu.js';
|
|
3
|
+
export { A as AnalyticsContext, b as AnalyticsEvent, a5 as ArtifactMeta, a6 as ArtifactWriteOptions, B as BufferStatus, e as DailyStats, D as DlqStatus, $ as EventHandler, E as EventsQuery, c as EventsResponse, d as EventsStats, I as IAnalytics, a4 as IArtifacts, O as ICache, P as IConfig, N as IEmbeddings, _ as IEventBus, a1 as IInvoke, i as ILLM, J as ILLMRouter, X as ILogBuffer, W as ILogger, Q as IStorage, f as IVectorStore, 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, x as LLMMessage, j as LLMOptions, r as LLMProtocolCapabilities, G as LLMResolution, k as LLMResponse, t as LLMStreamCapability, q as LLMStreamMode, n as LLMStreamPolicy, C as LLMTier, v as LLMTool, w as LLMToolCall, y as LLMToolCallOptions, z as LLMToolCallResponse, Y as LogLevel, S as StatsQuery, R as StorageMetadata, T as TIER_ORDER, a0 as Unsubscribe, U as UseLLMOptions, h as VectorFilter, V as VectorRecord, g as VectorSearchResult, Z as generateLogId, K as isTierHigher, M as isTierLower } from '../artifacts-DrVnkLzu.js';
|
|
4
|
+
export { B as BaseDocument, D as DocumentFilter, c as DocumentUpdate, F as FilterOperators, d as FindOptions, g as IDatabaseProvider, b as IDocumentDatabase, e as IKeyValueDatabase, I as ISQLDatabase, f as ITimeSeriesDatabase, S as SQLQueryResult, a as SQLTransaction, T as TimeSeriesPoint } from '../database-DGV6a1nj.js';
|
|
5
|
+
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-uOHBLBax.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @module @kb-labs/core-platform/adapters/log-ring-buffer
|
|
9
|
+
* Ring buffer adapter interface for real-time log streaming.
|
|
10
|
+
*
|
|
11
|
+
* Purpose:
|
|
12
|
+
* - In-memory buffer with fixed size and TTL
|
|
13
|
+
* - Real-time subscription support (SSE)
|
|
14
|
+
* - Low latency access to recent logs
|
|
15
|
+
*
|
|
16
|
+
* Not for:
|
|
17
|
+
* - Historical queries (use ILogPersistence)
|
|
18
|
+
* - Cross-process log aggregation
|
|
19
|
+
* - Long-term storage
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Ring buffer for real-time log streaming.
|
|
24
|
+
*
|
|
25
|
+
* Design:
|
|
26
|
+
* - Fixed-size circular buffer (default 1000 logs)
|
|
27
|
+
* - Automatic eviction of oldest logs when buffer is full
|
|
28
|
+
* - Time-to-live expiration (default 1 hour)
|
|
29
|
+
* - Real-time subscription support for SSE streaming
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const buffer = createRingBufferAdapter({ maxSize: 1000, ttl: 3600000 });
|
|
34
|
+
*
|
|
35
|
+
* // Append logs
|
|
36
|
+
* buffer.append({ timestamp: Date.now(), level: 'info', message: 'Hello' });
|
|
37
|
+
*
|
|
38
|
+
* // Subscribe to real-time stream
|
|
39
|
+
* const unsubscribe = buffer.subscribe((log) => {
|
|
40
|
+
* console.log('New log:', log);
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Query recent logs
|
|
44
|
+
* const recentErrors = buffer.query({ level: 'error' });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
interface ILogRingBuffer {
|
|
48
|
+
/**
|
|
49
|
+
* Append log record to buffer.
|
|
50
|
+
* Evicts oldest record if buffer is full.
|
|
51
|
+
*
|
|
52
|
+
* @param record - Log record to append
|
|
53
|
+
*/
|
|
54
|
+
append(record: LogRecord): void;
|
|
55
|
+
/**
|
|
56
|
+
* Query logs from buffer.
|
|
57
|
+
*
|
|
58
|
+
* @param query - Optional filter (level, timestamp range, source)
|
|
59
|
+
* @returns Array of logs matching query (most recent first)
|
|
60
|
+
*/
|
|
61
|
+
query(query?: LogQuery): LogRecord[];
|
|
62
|
+
/**
|
|
63
|
+
* Subscribe to real-time log events.
|
|
64
|
+
* Callback is called for each new log record appended to buffer.
|
|
65
|
+
*
|
|
66
|
+
* @param callback - Called for each new log record
|
|
67
|
+
* @returns Unsubscribe function
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const unsubscribe = buffer.subscribe((log) => {
|
|
72
|
+
* if (log.level === 'error') {
|
|
73
|
+
* notifyUser(log);
|
|
74
|
+
* }
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Later: stop subscription
|
|
78
|
+
* unsubscribe();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
subscribe(callback: (record: LogRecord) => void): () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Get buffer statistics.
|
|
84
|
+
*
|
|
85
|
+
* @returns Buffer stats including size, capacity, and eviction count
|
|
86
|
+
*/
|
|
87
|
+
getStats(): {
|
|
88
|
+
/** Current number of logs in buffer */
|
|
89
|
+
size: number;
|
|
90
|
+
/** Maximum buffer size */
|
|
91
|
+
maxSize: number;
|
|
92
|
+
/** Timestamp of oldest log in buffer (0 if empty) */
|
|
93
|
+
oldestTimestamp: number;
|
|
94
|
+
/** Timestamp of newest log in buffer (0 if empty) */
|
|
95
|
+
newestTimestamp: number;
|
|
96
|
+
/** Total number of logs evicted due to size/TTL */
|
|
97
|
+
evictions: number;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Clear all logs from buffer.
|
|
101
|
+
* Useful for testing or manual cleanup.
|
|
102
|
+
*/
|
|
103
|
+
clear(): void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Configuration for log ring buffer adapter.
|
|
107
|
+
*/
|
|
108
|
+
interface LogRingBufferConfig {
|
|
109
|
+
/**
|
|
110
|
+
* Maximum number of logs to keep in memory.
|
|
111
|
+
* When buffer is full, oldest log is evicted.
|
|
112
|
+
*
|
|
113
|
+
* @default 1000
|
|
114
|
+
*/
|
|
115
|
+
maxSize?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Time-to-live for logs in milliseconds.
|
|
118
|
+
* Logs older than this are automatically evicted.
|
|
119
|
+
*
|
|
120
|
+
* @default 3600000 (1 hour)
|
|
121
|
+
*/
|
|
122
|
+
ttl?: number;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { type ILogRingBuffer, LogQuery, LogRecord, type LogRingBufferConfig };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ulid } from 'ulid';
|
|
2
|
+
|
|
3
|
+
// src/adapters/llm-types.ts
|
|
4
|
+
var TIER_ORDER = [
|
|
5
|
+
"small",
|
|
6
|
+
"medium",
|
|
7
|
+
"large"
|
|
8
|
+
];
|
|
9
|
+
function isTierHigher(a, b) {
|
|
10
|
+
return TIER_ORDER.indexOf(a) > TIER_ORDER.indexOf(b);
|
|
11
|
+
}
|
|
12
|
+
function isTierLower(a, b) {
|
|
13
|
+
return TIER_ORDER.indexOf(a) < TIER_ORDER.indexOf(b);
|
|
14
|
+
}
|
|
15
|
+
function generateLogId() {
|
|
16
|
+
return ulid();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { TIER_ORDER, generateLogId, isTierHigher, isTierLower };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/llm-types.ts","../../src/adapters/logger.ts"],"names":[],"mappings":";;;AAqIO,IAAM,UAAA,GAAiC;AAAA,EAC5C,OAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAKO,SAAS,YAAA,CAAa,GAAY,CAAA,EAAqB;AAC5D,EAAA,OAAO,WAAW,OAAA,CAAQ,CAAC,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAC,CAAA;AACrD;AAKO,SAAS,WAAA,CAAY,GAAY,CAAA,EAAqB;AAC3D,EAAA,OAAO,WAAW,OAAA,CAAQ,CAAC,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAC,CAAA;AACrD;ACxHO,SAAS,aAAA,GAAwB;AACtC,EAAA,OAAO,IAAA,EAAK;AACd","file":"index.js","sourcesContent":["/**\n * @module @kb-labs/core-platform/adapters/llm-types\n * LLM tier and capability types for adaptive model routing.\n *\n * These types define the abstract layer between plugins and LLM providers.\n * Plugins request tiers/capabilities, platform resolves to actual models.\n *\n * @example\n * ```typescript\n * import { LLMTier, LLMCapability, UseLLMOptions } from '@kb-labs/sdk';\n *\n * // Plugin requests by tier (user decides what model)\n * const llm = useLLM({ tier: 'small' });\n * const llm = useLLM({ tier: 'large', capabilities: ['reasoning'] });\n * ```\n */\n\nimport type { ILLM, LLMExecutionPolicy } from './llm.js';\n\n/**\n * Model quality tier - user-defined slots.\n *\n * Tiers are NOT tied to specific models. They are abstract slots\n * that the user fills with whatever models they want in config.\n *\n * Plugin intent:\n * - `small` - \"This task is simple, doesn't need much\"\n * - `medium` - \"Standard task\"\n * - `large` - \"Complex task, need maximum quality\"\n *\n * User decides what model maps to each tier in their config.\n */\nexport type LLMTier = \"small\" | \"medium\" | \"large\";\n\n/**\n * Model capabilities - task-optimized features.\n *\n * - `fast` - Lowest latency (for real-time responses)\n * - `reasoning` - Complex reasoning (o1, opus-level thinking)\n * - `coding` - Code-optimized (better at code generation/review)\n * - `vision` - Image input support\n */\nexport type LLMCapability = \"reasoning\" | \"coding\" | \"vision\" | \"fast\";\n\n/**\n * Options for useLLM() - plugin-facing API.\n *\n * Plugins specify what they need abstractly.\n * Platform resolves to actual provider/model based on user config.\n */\nexport interface UseLLMOptions {\n /**\n * Quality tier (user-defined slot).\n * Platform adapts if exact tier unavailable:\n * - Escalates up (small → medium) silently\n * - Degrades down (large → medium) with warning\n */\n tier?: LLMTier;\n\n /**\n * Required capabilities.\n * Platform selects model that supports ALL requested capabilities.\n */\n capabilities?: LLMCapability[];\n\n /**\n * Optional execution policy applied to this bound LLM instance.\n * Can be overridden per-call via LLMOptions.execution.\n */\n execution?: LLMExecutionPolicy;\n}\n\n/**\n * Resolution result from tier/capability matching.\n * Internal type used by LLMRouter.\n */\nexport interface LLMResolution {\n /** Resolved provider ID (e.g., 'openai', 'anthropic') */\n provider: string;\n /** Resolved model name */\n model: string;\n /** Resource name for ResourceBroker (e.g., 'llm:openai') */\n resource: string;\n /** Original requested tier */\n requestedTier: LLMTier | undefined;\n /** Actual tier being used */\n actualTier: LLMTier;\n /** Whether this was escalated/degraded */\n adapted: boolean;\n /** Warning message if degraded */\n warning?: string;\n}\n\n/**\n * Resolved adapter binding — immutable snapshot of a tier resolution.\n * Returned by resolveAdapter() to avoid global state mutation.\n */\nexport interface LLMAdapterBinding {\n /** The concrete adapter instance (already wrapped with analytics, etc.) */\n adapter: ILLM;\n /** Resolved model name */\n model: string;\n /** Actual tier used */\n tier: LLMTier;\n}\n\n/**\n * LLM Router interface - extends ILLM with routing capabilities.\n * Implemented by @kb-labs/llm-router.\n */\nexport interface ILLMRouter {\n /** Get configured tier (what user set in config) */\n getConfiguredTier(): LLMTier;\n\n /** Resolve tier request to actual model (mutates router state — legacy) */\n resolve(options?: UseLLMOptions): LLMResolution;\n\n /**\n * Resolve tier and return an immutable adapter binding.\n * Does NOT mutate router state — safe for concurrent useLLM() calls.\n */\n resolveAdapter(options?: UseLLMOptions): Promise<LLMAdapterBinding>;\n\n /** Check if capability is available */\n hasCapability(capability: LLMCapability): boolean;\n\n /** Get available capabilities */\n getCapabilities(): LLMCapability[];\n}\n\n/**\n * Tier order for resolution (lowest to highest).\n */\nexport const TIER_ORDER: readonly LLMTier[] = [\n \"small\",\n \"medium\",\n \"large\",\n] as const;\n\n/**\n * Check if tier A is higher than tier B.\n */\nexport function isTierHigher(a: LLMTier, b: LLMTier): boolean {\n return TIER_ORDER.indexOf(a) > TIER_ORDER.indexOf(b);\n}\n\n/**\n * Check if tier A is lower than tier B.\n */\nexport function isTierLower(a: LLMTier, b: LLMTier): boolean {\n return TIER_ORDER.indexOf(a) < TIER_ORDER.indexOf(b);\n}\n","/**\n * @module @kb-labs/core-platform/adapters/logger\n * Logger abstraction for structured logging.\n */\n\nimport { ulid } from \"ulid\";\n\n/**\n * Log level enumeration\n */\nexport type LogLevel = \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\";\n\n/**\n * Generate unique log ID using ULID.\n *\n * ULIDs are:\n * - Lexicographically sortable (timestamp-based)\n * - 26 characters (more compact than UUID's 36)\n * - URL-safe (base32 encoded)\n * - Monotonically increasing within same millisecond\n *\n * All logger adapters MUST use this function to ensure ID consistency.\n *\n * @returns ULID string (e.g., \"01ARZ3NDEKTSV4RRFFQ69G5FAV\")\n *\n * @example\n * ```typescript\n * const logId = generateLogId();\n * console.log(logId); // \"01HQVX5P7G3QR9Z8X5N4Y2K6E1\"\n * ```\n */\nexport function generateLogId(): string {\n return ulid();\n}\n\n/**\n * Structured log record\n */\nexport interface LogRecord {\n /** Unique log ID (ULID). Generated by logger adapter using generateLogId() */\n id: string;\n /** Timestamp (milliseconds since epoch) */\n timestamp: number;\n /** Log level */\n level: LogLevel;\n /** Log message */\n message: string;\n /** Structured fields (metadata) */\n fields: Record<string, unknown>;\n /** Source identifier (e.g., 'rest', 'workflow', 'cli') */\n source: string;\n}\n\n/**\n * Query filters for log retrieval\n */\nexport interface LogQuery {\n /** Minimum log level (inclusive) */\n level?: LogLevel;\n /** Filter by source */\n source?: string;\n /** Start timestamp (milliseconds since epoch) */\n from?: number;\n /** End timestamp (milliseconds since epoch) */\n to?: number;\n /** Maximum number of logs to return */\n limit?: number;\n}\n\n/**\n * Log buffer interface for streaming/querying logs\n */\nexport interface ILogBuffer {\n /**\n * Append log record to buffer\n */\n append(record: LogRecord): void;\n\n /**\n * Query logs with filters\n */\n query(query?: LogQuery): LogRecord[];\n\n /**\n * Subscribe to real-time log stream\n * @returns Unsubscribe function\n */\n subscribe(callback: (record: LogRecord) => void): () => void;\n\n /**\n * Get buffer statistics\n */\n getStats(): {\n total: number;\n bufferSize: number;\n oldestTimestamp: number | null;\n newestTimestamp: number | null;\n };\n}\n\n/**\n * Logger adapter interface.\n * Implementations: @kb-labs/adapters-pino (production), ConsoleLogger (noop)\n */\nexport interface ILogger {\n /**\n * Log info message.\n * @param message - Log message\n * @param meta - Optional metadata\n */\n info(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Log warning message.\n * @param message - Log message\n * @param meta - Optional metadata\n */\n warn(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Log error message.\n * @param message - Log message\n * @param error - Optional error object\n * @param meta - Optional metadata\n */\n error(message: string, error?: Error, meta?: Record<string, unknown>): void;\n\n /**\n * Log fatal error message (critical failures).\n * @param message - Log message\n * @param error - Optional error object\n * @param meta - Optional metadata\n */\n fatal(message: string, error?: Error, meta?: Record<string, unknown>): void;\n\n /**\n * Log debug message.\n * @param message - Log message\n * @param meta - Optional metadata\n */\n debug(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Log trace message (most verbose).\n * @param message - Log message\n * @param meta - Optional metadata\n */\n trace(message: string, meta?: Record<string, unknown>): void;\n\n /**\n * Create a child logger with additional context.\n * @param bindings - Context bindings (e.g., { plugin: 'mind', tenant: 'acme' })\n */\n child(bindings: Record<string, unknown>): ILogger;\n\n /**\n * Get log buffer for streaming/querying (optional feature).\n * Not all logger implementations support buffering.\n * @returns Log buffer if streaming is enabled, undefined otherwise\n */\n getLogBuffer?(): ILogBuffer | undefined;\n\n /**\n * Register callback for every log event (optional feature).\n * Used by platform to connect logger extensions (ring buffer, persistence).\n *\n * Extensions are called fire-and-forget (async errors are caught and logged).\n * Multiple extensions can be registered and will be called in priority order.\n *\n * @param callback - Function to call on each log event\n * @returns Unsubscribe function to remove the callback\n *\n * @example\n * ```typescript\n * const unsubscribe = logger.onLog((record) => {\n * ringBuffer.append(record);\n * persistence.write(record).catch(console.error);\n * });\n *\n * // Later: unsubscribe()\n * ```\n */\n onLog?(callback: (record: LogRecord) => void): () => void;\n}\n"]}
|