@everworker/oneringai 0.4.6 → 0.4.8

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.
@@ -98,6 +98,148 @@ interface ReasoningItem {
98
98
  type InputItem = Message | CompactionItem;
99
99
  type OutputItem = Message | CompactionItem | ReasoningItem;
100
100
 
101
+ /**
102
+ * IHistoryJournal - Interface for append-only conversation history logging
103
+ *
104
+ * Provides a durable, append-only log of all conversation messages,
105
+ * independent of context compaction. While the agent's working window
106
+ * (_conversation) may be compacted to fit the LLM context, the journal
107
+ * preserves the full conversation history on disk/database.
108
+ *
109
+ * The journal is a companion capability of IContextStorage — storage
110
+ * implementations that support history logging expose it via the
111
+ * `journal` property. Consumers never configure the journal separately;
112
+ * it comes for free with the storage backend.
113
+ *
114
+ * Access patterns:
115
+ * - **Write**: append-only, per-message, fire-and-forget (non-blocking)
116
+ * - **Read**: on-demand, explicit (never loaded automatically)
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // File storage → FileHistoryJournal (JSONL files)
121
+ * const storage = new FileContextStorage({ agentId: 'my-agent' });
122
+ * storage.journal.append('session-1', [entry]);
123
+ *
124
+ * // Mongo storage → MongoHistoryJournal (collection)
125
+ * const storage = new MongoContextStorage({ agentId: 'my-agent', db });
126
+ * storage.journal.append('session-1', [entry]);
127
+ *
128
+ * // Reading history (on-demand, explicit)
129
+ * const entries = await storage.journal.read('session-1', { limit: 50 });
130
+ * const total = await storage.journal.count('session-1');
131
+ * ```
132
+ */
133
+
134
+ /**
135
+ * Type of history entry, derived from the message's role/purpose.
136
+ */
137
+ type HistoryEntryType = 'user' | 'assistant' | 'tool_result' | 'system';
138
+ /**
139
+ * A single entry in the history journal.
140
+ *
141
+ * Wraps an InputItem with metadata for ordering and filtering.
142
+ * The `item` field is the exact InputItem as it was added to the conversation,
143
+ * preserving full fidelity (including __images, tool_use_id, etc.).
144
+ */
145
+ interface HistoryEntry {
146
+ /** When this entry was recorded (epoch ms) */
147
+ timestamp: number;
148
+ /** Entry type for filtering */
149
+ type: HistoryEntryType;
150
+ /** The actual conversation item (Message or CompactionItem) */
151
+ item: InputItem;
152
+ /**
153
+ * Monotonically increasing turn counter.
154
+ * A "turn" is one user message + one assistant response (+ any tool calls in between).
155
+ * Useful for grouping related messages and pagination.
156
+ */
157
+ turnIndex: number;
158
+ }
159
+ /**
160
+ * Options for reading history entries.
161
+ */
162
+ interface HistoryReadOptions {
163
+ /** Skip this many entries from the start */
164
+ offset?: number;
165
+ /** Maximum number of entries to return */
166
+ limit?: number;
167
+ /** Filter by entry type(s) */
168
+ types?: HistoryEntryType[];
169
+ /** Only entries after this timestamp (epoch ms, inclusive) */
170
+ after?: number;
171
+ /** Only entries before this timestamp (epoch ms, inclusive) */
172
+ before?: number;
173
+ /** Only entries from this turn index onwards (inclusive) */
174
+ fromTurn?: number;
175
+ /** Only entries up to this turn index (inclusive) */
176
+ toTurn?: number;
177
+ }
178
+ /**
179
+ * Append-only history journal for conversation persistence.
180
+ *
181
+ * Implementations:
182
+ * - FileHistoryJournal: JSONL files at ~/.oneringai/agents/<agentId>/sessions/<sessionId>.history.jsonl
183
+ * - (Future) MongoHistoryJournal: MongoDB collection
184
+ * - (Future) RedisHistoryJournal: Redis Streams
185
+ */
186
+ interface IHistoryJournal {
187
+ /**
188
+ * Append entries to the journal.
189
+ *
190
+ * This is the primary write operation, called on every addUserMessage(),
191
+ * addAssistantResponse(), and addToolResults(). Should be fast (append-only).
192
+ *
193
+ * @param sessionId - Session to append to
194
+ * @param entries - One or more history entries to append
195
+ */
196
+ append(sessionId: string, entries: HistoryEntry[]): Promise<void>;
197
+ /**
198
+ * Read history entries with optional filtering and pagination.
199
+ *
200
+ * Entries are returned in chronological order (oldest first).
201
+ *
202
+ * @param sessionId - Session to read from
203
+ * @param options - Filtering and pagination options
204
+ * @returns Array of history entries
205
+ */
206
+ read(sessionId: string, options?: HistoryReadOptions): Promise<HistoryEntry[]>;
207
+ /**
208
+ * Get the total number of entries in the journal.
209
+ *
210
+ * @param sessionId - Session to count
211
+ * @returns Number of entries (0 if session has no journal)
212
+ */
213
+ count(sessionId: string): Promise<number>;
214
+ /**
215
+ * Delete all history for a session.
216
+ *
217
+ * Called when a session is deleted via IContextStorage.delete().
218
+ *
219
+ * @param sessionId - Session to clear
220
+ */
221
+ clear(sessionId: string): Promise<void>;
222
+ /**
223
+ * Stream history entries for large histories.
224
+ *
225
+ * Optional — implementations may omit this if streaming isn't practical
226
+ * (e.g., in-memory storage). Callers should fall back to read() with
227
+ * pagination if stream() is not available.
228
+ *
229
+ * @param sessionId - Session to stream
230
+ * @param options - Same filtering options as read()
231
+ * @returns AsyncIterable of history entries in chronological order
232
+ */
233
+ stream?(sessionId: string, options?: HistoryReadOptions): AsyncIterable<HistoryEntry>;
234
+ /**
235
+ * Get a human-readable location string for debugging/display.
236
+ *
237
+ * @param sessionId - Session ID
238
+ * @returns Location string (file path, MongoDB URI, etc.)
239
+ */
240
+ getLocation?(sessionId: string): string;
241
+ }
242
+
101
243
  /**
102
244
  * Memory entities for WorkingMemory
103
245
  *
@@ -723,6 +865,21 @@ interface IContextStorage {
723
865
  * Falls back to getPath() if not implemented.
724
866
  */
725
867
  getLocation?(): string;
868
+ /**
869
+ * History journal companion for full conversation logging.
870
+ *
871
+ * When present, AgentContextNextGen automatically appends every message
872
+ * to the journal (append-only, fire-and-forget). The journal is never
873
+ * affected by compaction, preserving full conversation history.
874
+ *
875
+ * Storage implementations create the appropriate journal for their backend:
876
+ * - FileContextStorage → FileHistoryJournal (JSONL files)
877
+ * - MongoContextStorage → MongoHistoryJournal (collection)
878
+ *
879
+ * Consumers never configure the journal separately — it comes for free
880
+ * with the storage backend.
881
+ */
882
+ readonly journal?: IHistoryJournal;
726
883
  }
727
884
  /**
728
885
  * Options for listing sessions
@@ -1055,12 +1212,6 @@ declare class ToolCatalogRegistry {
1055
1212
  static reset(): void;
1056
1213
  }
1057
1214
 
1058
- /**
1059
- * AgentContextNextGen - Type Definitions
1060
- *
1061
- * Clean, minimal type definitions for the next-generation context manager.
1062
- */
1063
-
1064
1215
  /**
1065
1216
  * A single auth identity: connector + optional account alias.
1066
1217
  *
@@ -1569,6 +1720,13 @@ interface AgentContextNextGenConfig {
1569
1720
  * Default: 0 (disabled - relies on each tool's own timeout)
1570
1721
  */
1571
1722
  toolExecutionTimeout?: number;
1723
+ /**
1724
+ * Filter which message types are written to the history journal.
1725
+ * When set, only entries matching these types are appended.
1726
+ * Default: undefined (all types journaled).
1727
+ * Example: ['user', 'assistant'] to exclude tool_result entries.
1728
+ */
1729
+ journalFilter?: HistoryEntryType[];
1572
1730
  }
1573
1731
  /**
1574
1732
  * Default configuration values
@@ -1809,7 +1967,11 @@ declare enum StreamEventType {
1809
1967
  REASONING_DELTA = "response.reasoning.delta",
1810
1968
  REASONING_DONE = "response.reasoning.done",
1811
1969
  RESPONSE_COMPLETE = "response.complete",
1812
- ERROR = "response.error"
1970
+ RETRY = "response.retry",
1971
+ ERROR = "response.error",
1972
+ AUDIO_CHUNK_READY = "response.audio_chunk.ready",
1973
+ AUDIO_CHUNK_ERROR = "response.audio_chunk.error",
1974
+ AUDIO_STREAM_COMPLETE = "response.audio_stream.complete"
1813
1975
  }
1814
1976
  /**
1815
1977
  * Base interface for all stream events
@@ -1920,6 +2082,18 @@ interface ResponseCompleteEvent extends BaseStreamEvent {
1920
2082
  usage: TokenUsage;
1921
2083
  iterations: number;
1922
2084
  duration_ms?: number;
2085
+ /** Raw provider stop reason for diagnostics (e.g., 'end_turn', 'max_tokens', 'SAFETY') */
2086
+ stop_reason?: string;
2087
+ }
2088
+ /**
2089
+ * Retry event - emitted when agent retries an empty/incomplete LLM response
2090
+ */
2091
+ interface RetryEvent extends BaseStreamEvent {
2092
+ type: StreamEventType.RETRY;
2093
+ attempt: number;
2094
+ max_attempts: number;
2095
+ reason: string;
2096
+ delay_ms: number;
1923
2097
  }
1924
2098
  /**
1925
2099
  * Reasoning/thinking delta - incremental reasoning output
@@ -1950,11 +2124,49 @@ interface ErrorEvent extends BaseStreamEvent {
1950
2124
  };
1951
2125
  recoverable: boolean;
1952
2126
  }
2127
+ /**
2128
+ * Audio chunk ready - TTS synthesis complete for a text chunk
2129
+ */
2130
+ interface AudioChunkReadyEvent extends BaseStreamEvent {
2131
+ type: StreamEventType.AUDIO_CHUNK_READY;
2132
+ /** Sequential index for ordered playback */
2133
+ chunk_index: number;
2134
+ /** Sub-chunk index within a chunk (for streaming TTS mode) */
2135
+ sub_index?: number;
2136
+ /** Source text that was synthesized */
2137
+ text: string;
2138
+ /** Audio data as base64 string (survives JSON/IPC serialization) */
2139
+ audio_base64: string;
2140
+ /** Audio format */
2141
+ format: string;
2142
+ /** Duration in seconds (if available from TTS provider) */
2143
+ duration_seconds?: number;
2144
+ /** Characters used for this chunk */
2145
+ characters_used?: number;
2146
+ }
2147
+ /**
2148
+ * Audio chunk error - TTS synthesis failed for a text chunk
2149
+ */
2150
+ interface AudioChunkErrorEvent extends BaseStreamEvent {
2151
+ type: StreamEventType.AUDIO_CHUNK_ERROR;
2152
+ chunk_index: number;
2153
+ text: string;
2154
+ error: string;
2155
+ }
2156
+ /**
2157
+ * Audio stream complete - all TTS chunks have been processed
2158
+ */
2159
+ interface AudioStreamCompleteEvent extends BaseStreamEvent {
2160
+ type: StreamEventType.AUDIO_STREAM_COMPLETE;
2161
+ total_chunks: number;
2162
+ total_characters: number;
2163
+ total_duration_seconds?: number;
2164
+ }
1953
2165
  /**
1954
2166
  * Union type of all stream events
1955
2167
  * Discriminated by 'type' field for type narrowing
1956
2168
  */
1957
- type StreamEvent = ResponseCreatedEvent | ResponseInProgressEvent | OutputTextDeltaEvent | OutputTextDoneEvent | ReasoningDeltaEvent | ReasoningDoneEvent | ToolCallStartEvent | ToolCallArgumentsDeltaEvent | ToolCallArgumentsDoneEvent | ToolExecutionStartEvent | ToolExecutionDoneEvent | IterationCompleteEvent$1 | ResponseCompleteEvent | ErrorEvent;
2169
+ type StreamEvent = ResponseCreatedEvent | ResponseInProgressEvent | OutputTextDeltaEvent | OutputTextDoneEvent | ReasoningDeltaEvent | ReasoningDoneEvent | ToolCallStartEvent | ToolCallArgumentsDeltaEvent | ToolCallArgumentsDoneEvent | ToolExecutionStartEvent | ToolExecutionDoneEvent | IterationCompleteEvent$1 | ResponseCompleteEvent | RetryEvent | ErrorEvent | AudioChunkReadyEvent | AudioChunkErrorEvent | AudioStreamCompleteEvent;
1958
2170
  /**
1959
2171
  * Type guard to check if event is a specific type
1960
2172
  */
@@ -1970,6 +2182,9 @@ declare function isReasoningDelta(event: StreamEvent): event is ReasoningDeltaEv
1970
2182
  declare function isReasoningDone(event: StreamEvent): event is ReasoningDoneEvent;
1971
2183
  declare function isResponseComplete(event: StreamEvent): event is ResponseCompleteEvent;
1972
2184
  declare function isErrorEvent(event: StreamEvent): event is ErrorEvent;
2185
+ declare function isAudioChunkReady(event: StreamEvent): event is AudioChunkReadyEvent;
2186
+ declare function isAudioChunkError(event: StreamEvent): event is AudioChunkErrorEvent;
2187
+ declare function isAudioStreamComplete(event: StreamEvent): event is AudioStreamCompleteEvent;
1973
2188
 
1974
2189
  /**
1975
2190
  * Text generation provider interface
@@ -2228,6 +2443,14 @@ interface ExecutionEmptyOutputEvent {
2228
2443
  duration: number;
2229
2444
  usage?: TokenUsage;
2230
2445
  }
2446
+ interface ExecutionRetryEvent {
2447
+ executionId: string;
2448
+ attempt: number;
2449
+ maxAttempts: number;
2450
+ reason: string;
2451
+ delayMs: number;
2452
+ timestamp: Date;
2453
+ }
2231
2454
  interface ExecutionMaxIterationsEvent {
2232
2455
  executionId: string;
2233
2456
  iteration: number;
@@ -2346,6 +2569,7 @@ interface AgenticLoopEvents {
2346
2569
  'tool:timeout': ToolTimeoutEvent;
2347
2570
  'hook:error': HookErrorEvent;
2348
2571
  'execution:empty_output': ExecutionEmptyOutputEvent;
2572
+ 'execution:retry': ExecutionRetryEvent;
2349
2573
  'circuit:opened': CircuitOpenedEvent;
2350
2574
  'circuit:half-open': CircuitHalfOpenEvent;
2351
2575
  'circuit:closed': CircuitClosedEvent;
@@ -2563,6 +2787,10 @@ declare class HookManager {
2563
2787
  * Clear all hooks and reset error tracking
2564
2788
  */
2565
2789
  clear(): void;
2790
+ /**
2791
+ * Destroy the hook manager and release all references
2792
+ */
2793
+ destroy(): void;
2566
2794
  /**
2567
2795
  * Re-enable a disabled hook
2568
2796
  */
@@ -2573,4 +2801,4 @@ declare class HookManager {
2573
2801
  getDisabledHooks(): string[];
2574
2802
  }
2575
2803
 
2576
- export { StreamEventType as $, type AgentContextNextGenConfig as A, type BeforeCompactionCallback as B, type ContextFeatures as C, type HookName as D, ExecutionContext as E, type FunctionToolDefinition as F, type ITokenEstimator as G, type HookConfig as H, type IContextStorage as I, type ToolCategoryScope as J, type CompactionContext as K, type LLMResponse as L, type MemoryEntry as M, type CompactionResult as N, type OutputItem as O, type PriorityCalculator as P, type StaleEntryInfo as Q, type PriorityContext as R, type SerializedContextState as S, type Tool as T, type MemoryIndex as U, type TaskStatusForMemory as V, type WorkingMemoryConfig as W, type WorkingMemoryAccess as X, type ContextStorageListOptions as Y, type ContextSessionSummary as Z, type TokenUsage as _, type MemoryScope as a, getToolCallDescription as a$, type TextGenerateOptions as a0, type ModelCapabilities as a1, MessageRole as a2, type AfterToolContext as a3, type AgentEventName as a4, type AgenticLoopEventName as a5, type AgenticLoopEvents as a6, type ApprovalResult as a7, type ApproveToolContext as a8, type BeforeToolContext as a9, type OversizedInputResult as aA, type PluginConfigs as aB, type ReasoningDeltaEvent as aC, type ReasoningDoneEvent as aD, type ReasoningItem as aE, type ResponseCompleteEvent as aF, type ResponseCreatedEvent as aG, type ResponseInProgressEvent as aH, type SimpleScope as aI, type TaskAwareScope as aJ, type ThinkingContent as aK, type ToolCallArgumentsDeltaEvent as aL, type ToolCallArgumentsDoneEvent as aM, type ToolCallStartEvent as aN, ToolCallState as aO, ToolCatalogRegistry as aP, type ToolCategoryDefinition as aQ, type ToolExecutionContext as aR, type ToolExecutionDoneEvent as aS, type ToolExecutionStartEvent as aT, type ToolModification as aU, type ToolResultContent as aV, type ToolUseContent as aW, calculateEntrySize as aX, defaultDescribeCall as aY, forPlan as aZ, forTasks as a_, type BuiltInTool as aa, CONTEXT_SESSION_FORMAT_VERSION as ab, type ToolRegistryEntry as ac, type CatalogToolEntry as ad, type CompactionItem as ae, type ConnectorCategoryInfo as af, ContentType as ag, DEFAULT_CONFIG as ah, DEFAULT_FEATURES as ai, DEFAULT_MEMORY_CONFIG as aj, type ErrorEvent as ak, type ExecutionConfig as al, type Hook as am, HookManager as an, type InputImageContent as ao, type InputTextContent as ap, type IterationCompleteEvent$1 as aq, type JSONSchema as ar, MEMORY_PRIORITY_VALUES as as, type MemoryEntryInput as at, type MemoryIndexEntry as au, type Message as av, type ModifyingHook as aw, type OutputTextContent as ax, type OutputTextDeltaEvent as ay, type OutputTextDoneEvent as az, type ToolFunction as b, isErrorEvent as b0, isOutputTextDelta as b1, isReasoningDelta as b2, isReasoningDone as b3, isResponseComplete as b4, isSimpleScope as b5, isStreamEvent as b6, isTaskAwareScope as b7, isTerminalMemoryStatus as b8, isToolCallArgumentsDelta as b9, isToolCallArgumentsDone as ba, isToolCallStart as bb, scopeEquals as bc, scopeMatches as bd, type ExecutionCompleteEvent as be, type ExecutionStartEvent as bf, type LLMRequestEvent as bg, type LLMResponseEvent as bh, type ToolCompleteEvent as bi, type ToolStartEvent as bj, type ToolContext as c, type ToolPermissionConfig as d, type ContextBudget as e, type ToolCall as f, type IContextPluginNextGen as g, type MemoryPriority as h, type MemoryTier as i, type ContextEvents as j, type AuthIdentity as k, type ICompactionStrategy as l, type InputItem as m, type Content as n, type PreparedContext as o, type ToolResult as p, type ConsolidationResult as q, type StoredContextSession as r, type ITextProvider as s, type ContextSessionMetadata as t, type StreamEvent as u, type HistoryMode as v, type AgentEvents as w, type AgentResponse as x, type ExecutionMetrics as y, type AuditEntry as z };
2804
+ export { type MemoryIndex as $, type AgentContextNextGenConfig as A, type BeforeCompactionCallback as B, type ContextFeatures as C, type AuditEntry as D, ExecutionContext as E, type FunctionToolDefinition as F, type HookName as G, type HookConfig as H, type IContextStorage as I, type ITokenEstimator as J, type ToolCategoryScope as K, type LLMResponse as L, type MemoryEntry as M, type CompactionContext as N, type OutputItem as O, type PriorityCalculator as P, type CompactionResult as Q, type AudioChunkReadyEvent as R, type SerializedContextState as S, type Tool as T, type ContextStorageListOptions as U, type ContextSessionSummary as V, type WorkingMemoryConfig as W, type HistoryEntry as X, type HistoryReadOptions as Y, type StaleEntryInfo as Z, type PriorityContext as _, type MemoryScope as a, type ToolModification as a$, type TaskStatusForMemory as a0, type WorkingMemoryAccess as a1, type TokenUsage as a2, StreamEventType as a3, type TextGenerateOptions as a4, type ModelCapabilities as a5, MessageRole as a6, type AfterToolContext as a7, type AgentEventName as a8, type AgenticLoopEventName as a9, type MemoryEntryInput as aA, type MemoryIndexEntry as aB, type Message as aC, type ModifyingHook as aD, type OutputTextContent as aE, type OutputTextDeltaEvent as aF, type OutputTextDoneEvent as aG, type OversizedInputResult as aH, type PluginConfigs as aI, type ReasoningDeltaEvent as aJ, type ReasoningDoneEvent as aK, type ReasoningItem as aL, type ResponseCompleteEvent as aM, type ResponseCreatedEvent as aN, type ResponseInProgressEvent as aO, type SimpleScope as aP, type TaskAwareScope as aQ, type ThinkingContent as aR, type ToolCallArgumentsDeltaEvent as aS, type ToolCallArgumentsDoneEvent as aT, type ToolCallStartEvent as aU, ToolCallState as aV, ToolCatalogRegistry as aW, type ToolCategoryDefinition as aX, type ToolExecutionContext as aY, type ToolExecutionDoneEvent as aZ, type ToolExecutionStartEvent as a_, type AgenticLoopEvents as aa, type ApprovalResult as ab, type ApproveToolContext as ac, type AudioChunkErrorEvent as ad, type AudioStreamCompleteEvent as ae, type BeforeToolContext as af, type BuiltInTool as ag, CONTEXT_SESSION_FORMAT_VERSION as ah, type ToolRegistryEntry as ai, type CatalogToolEntry as aj, type CompactionItem as ak, type ConnectorCategoryInfo as al, ContentType as am, DEFAULT_CONFIG as an, DEFAULT_FEATURES as ao, DEFAULT_MEMORY_CONFIG as ap, type ErrorEvent as aq, type ExecutionConfig as ar, type HistoryEntryType as as, type Hook as at, HookManager as au, type InputImageContent as av, type InputTextContent as aw, type IterationCompleteEvent$1 as ax, type JSONSchema as ay, MEMORY_PRIORITY_VALUES as az, type ToolFunction as b, type ToolResultContent as b0, type ToolUseContent as b1, calculateEntrySize as b2, defaultDescribeCall as b3, forPlan as b4, forTasks as b5, getToolCallDescription as b6, isAudioChunkError as b7, isAudioChunkReady as b8, isAudioStreamComplete as b9, isErrorEvent as ba, isOutputTextDelta as bb, isReasoningDelta as bc, isReasoningDone as bd, isResponseComplete as be, isSimpleScope as bf, isStreamEvent as bg, isTaskAwareScope as bh, isTerminalMemoryStatus as bi, isToolCallArgumentsDelta as bj, isToolCallArgumentsDone as bk, isToolCallStart as bl, scopeEquals as bm, scopeMatches as bn, type ExecutionCompleteEvent as bo, type ExecutionStartEvent as bp, type LLMRequestEvent as bq, type LLMResponseEvent as br, type ToolCompleteEvent as bs, type ToolStartEvent as bt, type ToolContext as c, type ToolPermissionConfig as d, type ContextBudget as e, type ToolCall as f, type IContextPluginNextGen as g, type MemoryPriority as h, type MemoryTier as i, type ContextEvents as j, type AuthIdentity as k, type ICompactionStrategy as l, type InputItem as m, type Content as n, type PreparedContext as o, type ToolResult as p, type IHistoryJournal as q, type ConsolidationResult as r, type StoredContextSession as s, type ITextProvider as t, type ContextSessionMetadata as u, type StreamEvent as v, type HistoryMode as w, type AgentEvents as x, type AgentResponse as y, type ExecutionMetrics as z };