@mikesaintsg/core 0.0.6 → 0.0.7

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 CHANGED
@@ -168,18 +168,31 @@ Implementation classes for cross-package bridges (also available via factory fun
168
168
  | `Ok<T>`, `Err<E>` | Result discriminants |
169
169
  | `Unsubscribe` | Cleanup function type |
170
170
  | `Destroyable` | Interface for resources with cleanup |
171
+ | `AbortableOptions` | Interface for cancellable operations |
171
172
  | `SubscriptionToHook<T>` | Convert subscriptions to hooks |
173
+ | `ChangeSource` | Origin of state change (local/remote) |
174
+ | `ContentHash` | SHA-256 hex string for deduplication |
172
175
  | `Embedding` | Float32Array embedding vector |
176
+ | `EmbeddingModelMetadata` | Embedding model information |
173
177
  | `ToolCall`, `ToolResult`, `ToolSchema` | Tool-related types |
178
+ | `Message`, `MessageRole`, `MessageContent`| Message types for inference |
179
+ | `GenerationOptions`, `GenerationResult` | Generation configuration and result |
174
180
  | `ScoredResult` | Search result with score |
175
181
  | `ContextFrame`, `BuiltContext` | Context management types |
176
182
  | `TokenBudgetState`, `TokenBudgetLevel` | Token budget types |
183
+ | `Actor`, `EngagementState` | ActionLoop shared types |
184
+ | `TransitionEvent`, `DwellRecord` | Transition tracking types |
185
+ | `ModelTier`, `ModelInfo` | Model orchestration types |
186
+ | `StorageInfo`, `PruneResult` | Storage utility types |
187
+ | `HealthStatus`, `SystemHealth` | Health check types |
188
+ | `CircuitState`, `LifecycleState` | System state types |
177
189
 
178
190
  ### Adapter Interfaces
179
191
 
180
192
  | Interface | Category | Description |
181
193
  |-------------------------------------------|---------------|--------------------------------|
182
194
  | `EmbeddingAdapterInterface` | Source | Embedding generation |
195
+ | `ProviderAdapterInterface` | Source | LLM provider integration |
183
196
  | `ToolFormatAdapterInterface` | Transform | Provider tool formatting |
184
197
  | `SimilarityAdapterInterface` | Transform | Vector similarity computation |
185
198
  | `DeduplicationAdapterInterface` | Transform | Frame deduplication |
@@ -187,10 +200,17 @@ Implementation classes for cross-package bridges (also available via factory fun
187
200
  | `PriorityAdapterInterface` | Transform | Frame priority ordering |
188
201
  | `RetryAdapterInterface` | Policy | Retry behavior |
189
202
  | `RateLimitAdapterInterface` | Policy | Rate limiting |
203
+ | `CircuitBreakerAdapterInterface` | Policy | Cascading failure prevention |
190
204
  | `EmbeddingCacheAdapterInterface` | Enhancement | Embedding caching |
191
205
  | `BatchAdapterInterface` | Enhancement | Batch processing |
192
206
  | `RerankerAdapterInterface` | Enhancement | Result reranking |
207
+ | `TelemetryAdapterInterface` | Observability | Monitoring and debugging |
193
208
  | `VectorStorePersistenceAdapterInterface` | Persistence | Vector storage |
209
+ | `SessionPersistenceInterface` | Persistence | Session storage |
210
+ | `EventStorePersistenceAdapterInterface` | Persistence | Transition event storage |
211
+ | `WeightPersistenceAdapterInterface` | Persistence | Predictive weight storage |
212
+ | `StreamerAdapterInterface` | Streaming | Token emission |
213
+ | `SSEParserAdapterInterface` | Streaming | Server-sent events parsing |
194
214
 
195
215
  ### Minimal Cross-Package Interfaces
196
216
 
@@ -204,6 +224,10 @@ Implementation classes for cross-package bridges (also available via factory fun
204
224
  | `VectorStoreMinimal<T>` | Vector store without dependency |
205
225
  | `FormMinimal<T>` | Form state without dependency |
206
226
  | `SerializableSession` | Session serialization interface |
227
+ | `TokenCounterInterface` | Token counting for models |
228
+ | `HealthCheckInterface` | Health check for components |
229
+ | `ActivityTrackerInterface` | User engagement tracking |
230
+ | `ShutdownManagerInterface` | Graceful shutdown coordination |
207
231
 
208
232
  ---
209
233
 
package/dist/index.d.ts CHANGED
@@ -77,6 +77,25 @@ export declare interface ActivityTrackerSubscriptions {
77
77
  /** Actor types for transition attribution */
78
78
  export declare type Actor = 'user' | 'system' | 'automation';
79
79
 
80
+ /** Backpressure configuration */
81
+ export declare interface BackpressureConfig {
82
+ readonly strategy: BackpressureStrategy;
83
+ readonly highWaterMark: number;
84
+ readonly lowWaterMark?: number;
85
+ readonly bufferSize?: number;
86
+ }
87
+
88
+ /** Backpressure state */
89
+ export declare interface BackpressureState {
90
+ readonly currentSize: number;
91
+ readonly highWaterMark: number;
92
+ readonly isPaused: boolean;
93
+ readonly droppedCount: number;
94
+ }
95
+
96
+ /** Backpressure strategy */
97
+ export declare type BackpressureStrategy = 'drop' | 'block' | 'buffer' | 'error';
98
+
80
99
  /**
81
100
  * Batch adapter interface.
82
101
  * Controls batching behavior for bulk operations.
@@ -133,6 +152,57 @@ export declare function chain<T, U, E>(result: Result<T, E>, fn: (value: T) => R
133
152
  /** Origin of state change */
134
153
  export declare type ChangeSource = 'local' | 'remote';
135
154
 
155
+ /**
156
+ * Circuit breaker adapter interface.
157
+ * Prevents cascading failures by tracking error rates.
158
+ */
159
+ export declare interface CircuitBreakerAdapterInterface extends CircuitBreakerSubscriptions {
160
+ /** Execute operation with circuit breaker protection */
161
+ execute<T>(operation: () => Promise<T>): Promise<T>;
162
+ /** Get current circuit state */
163
+ getState(): CircuitBreakerState;
164
+ /** Manually open the circuit */
165
+ open(): void;
166
+ /** Manually close the circuit */
167
+ close(): void;
168
+ /** Reset all counters and close circuit */
169
+ reset(): void;
170
+ /** Check if operation can proceed */
171
+ canExecute(): boolean;
172
+ }
173
+
174
+ /** Circuit breaker configuration */
175
+ export declare interface CircuitBreakerConfig {
176
+ /** Failure threshold before opening circuit (default: 5) */
177
+ readonly failureThreshold: number;
178
+ /** Success threshold to close circuit from half-open (default: 3) */
179
+ readonly successThreshold: number;
180
+ /** Time in ms before attempting half-open (default: 30000) */
181
+ readonly resetTimeoutMs: number;
182
+ /** Time window for counting failures (default: 60000) */
183
+ readonly monitorWindowMs: number;
184
+ }
185
+
186
+ /** Circuit breaker state snapshot */
187
+ export declare interface CircuitBreakerState {
188
+ readonly state: CircuitState;
189
+ readonly failureCount: number;
190
+ readonly successCount: number;
191
+ readonly lastFailureTime: number | undefined;
192
+ readonly lastSuccessTime: number | undefined;
193
+ readonly nextAttemptTime: number | undefined;
194
+ }
195
+
196
+ /** Circuit breaker subscriptions */
197
+ export declare interface CircuitBreakerSubscriptions {
198
+ onStateChange(callback: (state: CircuitState, previous: CircuitState) => void): Unsubscribe;
199
+ onFailure(callback: (error: unknown, failureCount: number) => void): Unsubscribe;
200
+ onSuccess(callback: (successCount: number) => void): Unsubscribe;
201
+ }
202
+
203
+ /** Circuit breaker state */
204
+ export declare type CircuitState = 'closed' | 'open' | 'half-open';
205
+
136
206
  /**
137
207
  * Compute a SHA-256 content hash for text.
138
208
  *
@@ -147,6 +217,41 @@ export declare type ChangeSource = 'local' | 'remote';
147
217
  */
148
218
  export declare function computeContentHash(text: string): Promise<ContentHash>;
149
219
 
220
+ /** Configuration validation error */
221
+ export declare interface ConfigValidationError {
222
+ readonly path: string;
223
+ readonly message: string;
224
+ readonly expected?: string;
225
+ readonly received?: string;
226
+ }
227
+
228
+ /** Configuration validation result */
229
+ export declare interface ConfigValidationResult {
230
+ readonly valid: boolean;
231
+ readonly errors: readonly ConfigValidationError[];
232
+ readonly warnings: readonly ConfigValidationWarning[];
233
+ }
234
+
235
+ /** Configuration validation warning */
236
+ export declare interface ConfigValidationWarning {
237
+ readonly path: string;
238
+ readonly message: string;
239
+ readonly suggestion?: string;
240
+ }
241
+
242
+ /**
243
+ * Configuration validator interface.
244
+ * Validates configuration objects against expected schemas.
245
+ */
246
+ export declare interface ConfigValidatorInterface<T> {
247
+ /** Validate configuration */
248
+ validate(config: unknown): ConfigValidationResult;
249
+ /** Get validated configuration or throw */
250
+ validateOrThrow(config: unknown): T;
251
+ /** Get default configuration */
252
+ getDefaults(): Partial<T>;
253
+ }
254
+
150
255
  /** Content hash for deduplication (SHA-256 hex string) */
151
256
  export declare type ContentHash = string;
152
257
 
@@ -599,6 +704,45 @@ export declare interface GenerationResult {
599
704
  readonly aborted: boolean;
600
705
  }
601
706
 
707
+ /**
708
+ * Health check interface for system components.
709
+ * Implement this to enable health monitoring.
710
+ */
711
+ export declare interface HealthCheckInterface {
712
+ /** Perform health check */
713
+ check(): Promise<HealthCheckResult>;
714
+ /** Get component name */
715
+ getName(): string;
716
+ }
717
+
718
+ /** Individual health check result */
719
+ export declare interface HealthCheckResult {
720
+ readonly name: string;
721
+ readonly status: HealthStatus;
722
+ readonly message?: string;
723
+ readonly latencyMs?: number;
724
+ readonly timestamp: number;
725
+ readonly details?: Readonly<Record<string, unknown>>;
726
+ }
727
+
728
+ /** Health status for a component */
729
+ export declare type HealthStatus = 'healthy' | 'degraded' | 'unhealthy';
730
+
731
+ /** Histogram bucket for distribution metrics */
732
+ export declare interface HistogramBucket {
733
+ readonly le: number;
734
+ readonly count: number;
735
+ }
736
+
737
+ /** Histogram metric data */
738
+ export declare interface HistogramMetric {
739
+ readonly name: string;
740
+ readonly buckets: readonly HistogramBucket[];
741
+ readonly sum: number;
742
+ readonly count: number;
743
+ readonly labels?: Readonly<Record<string, string>>;
744
+ }
745
+
602
746
  /** Intent detection result */
603
747
  export declare interface IntentDetectionResult {
604
748
  readonly original: string;
@@ -702,6 +846,33 @@ export declare interface JSONSchema7 {
702
846
  readonly definitions?: Readonly<Record<string, JSONSchema7>>;
703
847
  }
704
848
 
849
+ /**
850
+ * Lifecycle-aware component interface.
851
+ * Provides standardized lifecycle management.
852
+ */
853
+ export declare interface LifecycleAwareInterface {
854
+ /** Get current lifecycle state */
855
+ getLifecycleState(): LifecycleState;
856
+ /** Subscribe to lifecycle state changes */
857
+ onLifecycleChange(callback: (state: LifecycleState, previous: LifecycleState) => void): Unsubscribe;
858
+ /** Check if component is ready for operations */
859
+ isReady(): boolean;
860
+ }
861
+
862
+ /** Component lifecycle state */
863
+ export declare type LifecycleState = 'created' | 'initializing' | 'ready' | 'degraded' | 'stopping' | 'stopped' | 'error';
864
+
865
+ /** Lifecycle state transition */
866
+ export declare interface LifecycleTransition {
867
+ readonly from: LifecycleState;
868
+ readonly to: LifecycleState;
869
+ readonly timestamp: number;
870
+ readonly reason?: string;
871
+ }
872
+
873
+ /** Log level for telemetry */
874
+ export declare type LogLevel = 'debug' | 'info' | 'warn' | 'error';
875
+
705
876
  /**
706
877
  * Map a function over a success value.
707
878
  *
@@ -754,6 +925,26 @@ export declare interface MessageMetadata {
754
925
  /** Message role */
755
926
  export declare type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
756
927
 
928
+ /** Metric definition */
929
+ export declare interface MetricDefinition {
930
+ readonly name: string;
931
+ readonly type: MetricType;
932
+ readonly description: string;
933
+ readonly unit?: string;
934
+ readonly labels?: readonly string[];
935
+ }
936
+
937
+ /** Metric type discriminator */
938
+ export declare type MetricType = 'counter' | 'gauge' | 'histogram' | 'summary';
939
+
940
+ /** Recorded metric value */
941
+ export declare interface MetricValue {
942
+ readonly name: string;
943
+ readonly value: number;
944
+ readonly labels?: Readonly<Record<string, string>>;
945
+ readonly timestamp: number;
946
+ }
947
+
757
948
  /**
758
949
  * Minimal database access interface for cross-package adapters.
759
950
  * Used by persistence adapters to access IndexedDB without
@@ -838,6 +1029,18 @@ export declare type ModelSelectionStrategy = 'auto' | 'local-only' | 'api-only'
838
1029
  /** Model tier for progressive loading */
839
1030
  export declare type ModelTier = 'fast' | 'balanced' | 'powerful';
840
1031
 
1032
+ /** Mutex for exclusive access */
1033
+ export declare interface MutexInterface {
1034
+ /** Acquire the mutex, waiting if held */
1035
+ acquire(): Promise<void>;
1036
+ /** Release the mutex */
1037
+ release(): void;
1038
+ /** Check if mutex is currently held */
1039
+ isLocked(): boolean;
1040
+ /** Execute operation with mutex held */
1041
+ withLock<T>(operation: () => Promise<T> | T): Promise<T>;
1042
+ }
1043
+
841
1044
  /**
842
1045
  * Navigation guard function type.
843
1046
  * Returns true to allow navigation, false to block.
@@ -1082,6 +1285,20 @@ export declare interface ScoredResult {
1082
1285
  readonly embedding?: Embedding;
1083
1286
  }
1084
1287
 
1288
+ /** Semaphore for limiting concurrent operations */
1289
+ export declare interface SemaphoreInterface {
1290
+ /** Acquire a permit, waiting if necessary */
1291
+ acquire(): Promise<void>;
1292
+ /** Try to acquire a permit without waiting */
1293
+ tryAcquire(): boolean;
1294
+ /** Release a permit */
1295
+ release(): void;
1296
+ /** Get number of available permits */
1297
+ availablePermits(): number;
1298
+ /** Get number of operations waiting for permits */
1299
+ queueLength(): number;
1300
+ }
1301
+
1085
1302
  /**
1086
1303
  * Minimal session interface for serialization.
1087
1304
  * Avoids hard dependency on inference package.
@@ -1169,6 +1386,53 @@ export declare interface SessionPersistenceOptions {
1169
1386
  */
1170
1387
  export declare function shouldSkipFormGuard<TPage extends string>(to: TPage, from: TPage, excludePages: readonly TPage[], onlyFromPages: readonly TPage[] | undefined): boolean;
1171
1388
 
1389
+ /** Shutdown handler registration */
1390
+ export declare interface ShutdownHandler {
1391
+ readonly name: string;
1392
+ readonly priority: ShutdownPriority;
1393
+ readonly timeoutMs?: number;
1394
+ readonly handler: () => Promise<void> | void;
1395
+ }
1396
+
1397
+ /** Shutdown result for individual handler */
1398
+ export declare interface ShutdownHandlerResult {
1399
+ readonly name: string;
1400
+ readonly success: boolean;
1401
+ readonly durationMs: number;
1402
+ readonly error?: Error;
1403
+ }
1404
+
1405
+ /**
1406
+ * Graceful shutdown manager interface.
1407
+ * Coordinates orderly shutdown of system components.
1408
+ */
1409
+ export declare interface ShutdownManagerInterface {
1410
+ /** Register a shutdown handler */
1411
+ register(handler: ShutdownHandler): Unsubscribe;
1412
+ /** Initiate graceful shutdown */
1413
+ shutdown(timeoutMs?: number): Promise<ShutdownResult>;
1414
+ /** Get current shutdown phase */
1415
+ getPhase(): ShutdownPhase;
1416
+ /** Check if shutdown is in progress */
1417
+ isShuttingDown(): boolean;
1418
+ /** Subscribe to phase changes */
1419
+ onPhaseChange(callback: (phase: ShutdownPhase) => void): Unsubscribe;
1420
+ }
1421
+
1422
+ /** Shutdown phase */
1423
+ export declare type ShutdownPhase = 'running' | 'draining' | 'stopping' | 'stopped';
1424
+
1425
+ /** Shutdown handler priority */
1426
+ export declare type ShutdownPriority = 'first' | 'normal' | 'last';
1427
+
1428
+ /** Overall shutdown result */
1429
+ export declare interface ShutdownResult {
1430
+ readonly success: boolean;
1431
+ readonly phase: ShutdownPhase;
1432
+ readonly handlers: readonly ShutdownHandlerResult[];
1433
+ readonly totalDurationMs: number;
1434
+ }
1435
+
1172
1436
  /**
1173
1437
  * Similarity adapter interface.
1174
1438
  * Computes similarity between embedding vectors.
@@ -1314,6 +1578,53 @@ export declare type SubscriptionToHook<T> = {
1314
1578
  [K in keyof T]?: T[K] extends (callback: infer CB) => Unsubscribe ? CB : never;
1315
1579
  };
1316
1580
 
1581
+ /** Aggregated health status for a system */
1582
+ export declare interface SystemHealth {
1583
+ readonly status: HealthStatus;
1584
+ readonly checks: readonly HealthCheckResult[];
1585
+ readonly timestamp: number;
1586
+ readonly version?: string;
1587
+ }
1588
+
1589
+ /**
1590
+ * Telemetry adapter interface.
1591
+ * Provides observability hooks for monitoring and debugging.
1592
+ */
1593
+ export declare interface TelemetryAdapterInterface {
1594
+ /** Start a new span for tracing */
1595
+ startSpan(name: string, attributes?: Readonly<Record<string, unknown>>): TelemetrySpan;
1596
+ /** End an active span */
1597
+ endSpan(span: TelemetrySpan, status?: 'ok' | 'error'): void;
1598
+ /** Record a log event */
1599
+ log(level: LogLevel, message: string, attributes?: Readonly<Record<string, unknown>>): void;
1600
+ /** Record a metric value */
1601
+ recordMetric(name: string, value: number, attributes?: Readonly<Record<string, unknown>>): void;
1602
+ /** Flush pending telemetry data */
1603
+ flush(): Promise<void>;
1604
+ }
1605
+
1606
+ /** Telemetry event for logging and metrics */
1607
+ export declare interface TelemetryEvent {
1608
+ readonly timestamp: number;
1609
+ readonly level: LogLevel;
1610
+ readonly message: string;
1611
+ readonly attributes?: Readonly<Record<string, unknown>>;
1612
+ readonly spanId?: string;
1613
+ readonly traceId?: string;
1614
+ }
1615
+
1616
+ /** Telemetry span for distributed tracing */
1617
+ export declare interface TelemetrySpan {
1618
+ readonly id: string;
1619
+ readonly traceId: string;
1620
+ readonly parentId?: string;
1621
+ readonly name: string;
1622
+ readonly startTime: number;
1623
+ readonly endTime?: number;
1624
+ readonly attributes?: Readonly<Record<string, unknown>>;
1625
+ readonly status: 'ok' | 'error' | 'unset';
1626
+ }
1627
+
1317
1628
  /** Timeout options for generation */
1318
1629
  export declare interface TimeoutOptions {
1319
1630
  readonly requestMs?: number;
@@ -1387,7 +1698,7 @@ export declare class ToolCallBridge implements ToolCallBridgeInterface {
1387
1698
 
1388
1699
  /**
1389
1700
  * Tool call bridge interface.
1390
- * Connects inference tool calls to contextprotocol tool registry.
1701
+ * Connects inference tool calls to contextbuilder tool registry.
1391
1702
  */
1392
1703
  export declare interface ToolCallBridgeInterface {
1393
1704
  /**
@@ -1433,7 +1744,7 @@ export declare interface ToolFormatAdapterInterface {
1433
1744
 
1434
1745
  /**
1435
1746
  * Minimal tool registry interface for bridge functions.
1436
- * Avoids hard dependency on contextprotocol package.
1747
+ * Avoids hard dependency on contextbuilder package.
1437
1748
  */
1438
1749
  export declare interface ToolRegistryMinimal {
1439
1750
  has(name: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikesaintsg/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "description": "Shared types, contracts, and bridge functions for the @mikesaintsg ecosystem. Zero runtime dependencies.",
6
6
  "keywords": [