@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
72 lines (71 loc) • 2.77 kB
JavaScript
/**
* Conversation Memory Types for NeuroLink
* Provides type-safe conversation storage and context management
*
* ## Timestamp Conventions
*
* NeuroLink uses two timestamp formats throughout the conversation system:
*
* ### Unix Milliseconds (number)
* Used for internal storage, event timestamps, and performance-critical operations.
* - `SessionMemory.createdAt` - Session creation time as Unix epoch milliseconds
* - `SessionMemory.lastActivity` - Last activity time as Unix epoch milliseconds
* - `SessionMemory.lastCountedAt` - Token count timestamp as Unix epoch milliseconds
* - `ConversationMemoryEvents.*.timestamp` - Event timestamps as Unix epoch milliseconds
* - `ChatMessage.metadata.timestamp` - Optional numeric timestamp for internal tracking
*
* Example: `1735689600000` represents January 1, 2025, 00:00:00 UTC
*
* ### ISO 8601 String (string)
* Used for human-readable fields and API responses.
* - `ChatMessage.timestamp` - Message timestamp as ISO 8601 string
* - `ConversationBase.createdAt` - Conversation creation as ISO 8601 string
* - `ConversationBase.updatedAt` - Last update as ISO 8601 string
* - `ConversationSummary.firstMessage.timestamp` - Message preview timestamp
* - `ConversationSummary.lastMessage.timestamp` - Message preview timestamp
*
* Example: `"2025-01-01T00:00:00.000Z"`
*
* ### Conversion Guidelines
* - Unix ms to ISO: `new Date(unixMs).toISOString()`
* - ISO to Unix ms: `new Date(isoString).getTime()`
* - Current time (Unix ms): `Date.now()`
* - Current time (ISO): `new Date().toISOString()`
*/
/**
* Error types specific to conversation memory
*/
export class ConversationMemoryError extends Error {
code;
details;
constructor(message, code, details) {
super(message);
this.code = code;
this.details = details;
this.name = "ConversationMemoryError";
}
}
/**
* Raised when a write reaches a session that was permanently erased. The
* erasure tombstone outlives the session's data, so a late writer cannot
* resurrect it.
*/
export class ConversationSessionErasedError extends Error {
code = "SESSION_ERASED";
constructor() {
super("Session permanently erased; write refused");
this.name = "ConversationSessionErasedError";
}
}
/**
* Raised when a fenced write cannot prove it belongs to the store epoch it was
* admitted under: the context is missing or not fenced, the Redis server
* restarted, or its eviction counter moved.
*/
export class ConversationWriterEpochError extends Error {
code = "SESSION_WRITER_EPOCH_LOST";
constructor() {
super("Conversation writer epoch is unavailable or changed; write refused");
this.name = "ConversationWriterEpochError";
}
}