@kognitivedev/shared
v0.2.8
Published
Foundation utilities for the Kognitive AI framework
Maintainers
Readme
@kognitivedev/shared
Foundation utilities for the Kognitive AI framework — EventBus, Cache, Logger, Errors, Retry, and OpenTelemetry integration.
Installation
bun add @kognitivedev/sharedExports
Events
InMemoryEventBus— typed pub/sub:emit(),on(),once(),removeAll()
Cache
InMemoryCacheAdapter— TTL-based cache:get(),set(),delete(),clear()
Logger
ConsoleLogger— structured logging with prefixNoopLogger— silent logger for testing
Errors
KognitiveError,RetryableError,ValidationError,TimeoutError,NotFoundError,ApprovalDeniedError
Utilities
withRetry(fn, options)— exponential backoff retrygenerateId()— UUID generation
Telemetry
withSpan(name, fn, attributes?)— OpenTelemetry span wrapper (no-op if OTEL not installed)createSpan(),endSpan()— manual span control
Streaming
StreamMode—"values" | "updates" | "messages" | "custom" | "debug"StreamEvent—{ event: string; data: unknown }parseStreamModes(input)— validate and parse comma-separated mode stringcreateSSEEncoder()—TransformStream<StreamEvent, Uint8Array>for SSE wire formatsseHeaders()— standard SSE response headers
Types
ResourceId—{ organizationId?, projectId, userId?, sessionId? }Result<T, E>— discriminated union withok()/err()helpers