@free-intelligence/core 1.1.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/LICENSE ADDED
@@ -0,0 +1,77 @@
1
+ Required Notice: Copyright 2026 Bernard Uriza Orozco
2
+ Required Notice: Commercial licensing available — contact bernarduriza@gmail.com
3
+ Required Notice: Source — https://github.com/BernardUriza/free-intelligence
4
+
5
+ # PolyForm Noncommercial License 1.0.0
6
+
7
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
8
+
9
+ ## Acceptance
10
+
11
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
12
+
13
+ ## Copyright License
14
+
15
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Distribution License
18
+
19
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
20
+
21
+ ## Notices
22
+
23
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
24
+
25
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
26
+
27
+ ## Changes and New Works License
28
+
29
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
30
+
31
+ ## Patent License
32
+
33
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
34
+
35
+ ## Noncommercial Purposes
36
+
37
+ Any noncommercial purpose is a permitted purpose.
38
+
39
+ ## Personal Uses
40
+
41
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
42
+
43
+ ## Noncommercial Organizations
44
+
45
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
46
+
47
+ ## Fair Use
48
+
49
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
50
+
51
+ ## No Other Rights
52
+
53
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
54
+
55
+ ## Patent Defense
56
+
57
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
58
+
59
+ ## Violations
60
+
61
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
62
+
63
+ ## No Liability
64
+
65
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
66
+
67
+ ## Definitions
68
+
69
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
70
+
71
+ **You** refers to the individual or entity agreeing to these terms.
72
+
73
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
74
+
75
+ **Your licenses** are all the licenses granted to you for the software under these terms.
76
+
77
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,497 @@
1
+ /**
2
+ * ThemeTokens — the material-agnostic slot contract for a frosted-surface theme.
3
+ *
4
+ * Every `fi-<material>` skin (fi-glass today; future fi-slate, fi-paper, …) fills
5
+ * these same slots with its own values. Consumers — fi-glass's shell/agentic
6
+ * components and the apps themselves — depend only on this shape, never on a
7
+ * concrete material. That is precisely what makes "material = token swap" hold
8
+ * without any material having to depend on another.
9
+ *
10
+ * This is pure data: no React, no styling, no logic. It lives in core so a future
11
+ * material never has to reach into fi-glass just to learn the slot shape.
12
+ */
13
+ interface ThemeTokens {
14
+ /** Backdrop blur radius for frosted surfaces, e.g. `"12px"`. */
15
+ blur: string;
16
+ /** Reduced blur radius for small viewports (≤768px), e.g. `"8px"`. */
17
+ blurCompact: string;
18
+ /** Surface fill opacity, `0..1`. */
19
+ opacity: number;
20
+ /** Backdrop saturation boost, e.g. `"180%"`. */
21
+ saturation: string;
22
+ /** Light surface base fill as an `"r, g, b"` triple, e.g. `"255, 255, 255"`. */
23
+ surfaceLight: string;
24
+ /** Light surface border (full CSS color), e.g. `"rgba(255, 255, 255, 0.18)"`. */
25
+ borderLight: string;
26
+ /** Dark surface fill (full CSS color), e.g. `"rgba(15, 23, 42, 0.7)"`. */
27
+ surfaceDark: string;
28
+ /** Dark surface border (full CSS color), e.g. `"rgba(148, 163, 184, 0.2)"`. */
29
+ borderDark: string;
30
+ }
31
+
32
+ /**
33
+ * Audio produced by synthesize().
34
+ *
35
+ * - `Blob` → a fully-rendered clip; fi-glass calls URL.createObjectURL.
36
+ * - `{ url }` → a ready (possibly streaming) URL; fi-glass uses it directly.
37
+ *
38
+ * Supporting both keeps streaming TTS (hear-while-generating) open without
39
+ * forcing every backend to stream.
40
+ */
41
+ type AudioSource = Blob | {
42
+ url: string;
43
+ };
44
+ /** A selectable TTS voice offered by the adapter. */
45
+ interface VoiceOption {
46
+ /** Stable id passed back to synthesize() (e.g. "nova", "en-US-AvaNeural"). */
47
+ id: string;
48
+ /** Human label for the picker (e.g. "Nova"). */
49
+ label: string;
50
+ /** Optional group header for the picker (e.g. "OpenAI", "Azure Neural"). */
51
+ group?: string;
52
+ }
53
+ /** Result of transcribing one recorded audio chunk. */
54
+ interface TranscriptResult {
55
+ /** Recognized text for this chunk (may be empty). */
56
+ text: string;
57
+ }
58
+ /** Metadata fi-glass passes alongside each transcription chunk. */
59
+ interface TranscribeContext {
60
+ /**
61
+ * 0-based index of this chunk within the current recording. A streaming
62
+ * adapter uses it for session/ordering; a one-shot adapter (single chunk on
63
+ * stop) simply ignores it.
64
+ */
65
+ index: number;
66
+ /** Lets the app abort the in-flight request when recording stops. */
67
+ signal?: AbortSignal;
68
+ }
69
+ /**
70
+ * VoiceAdapter — the app's voice engine, injected whole into fi-glass.
71
+ *
72
+ * Capabilities are a la carte (all members optional):
73
+ * - no adapter -> no voice (UI hides mic + speak)
74
+ * - synthesize present -> TTS available (SpeakButton + AudioPlayer)
75
+ * - transcribe present -> STT available (VoiceMicButton dictation)
76
+ *
77
+ * Add a new capability by adding an optional member here — never by threading a
78
+ * new callback through the components.
79
+ */
80
+ interface VoiceAdapter {
81
+ /** Synthesize speech for `text` in an optional voice id; resolves to audio. */
82
+ synthesize?(text: string, voice?: string): Promise<AudioSource>;
83
+ /** Voices offered in the player's picker. */
84
+ readonly availableVoices?: VoiceOption[];
85
+ /** Voice id used when the caller doesn't specify one. */
86
+ readonly defaultVoice?: string;
87
+ /** Transcribe one recorded audio chunk to text. */
88
+ transcribe?(chunk: Blob, ctx?: TranscribeContext): Promise<TranscriptResult>;
89
+ }
90
+
91
+ /**
92
+ * ChatMessage — the material-agnostic shape of one chat message.
93
+ *
94
+ * Apps may use a richer message type (e.g. aurity's FIMessage with typed
95
+ * metadata); ChatHook is generic over the message type and defaults to this.
96
+ * Pure data — no React, no styling.
97
+ */
98
+ interface ChatMessage {
99
+ /** Stable id (optional for transient/streaming messages). */
100
+ id?: string;
101
+ /** Who authored the message. */
102
+ role: 'user' | 'assistant';
103
+ /** The message text. */
104
+ content: string;
105
+ /** Optional model reasoning rendered before the content. */
106
+ thinking?: string | null;
107
+ /** ISO 8601 timestamp. */
108
+ timestamp: string;
109
+ /** App-specific metadata (tone, voice, model, …). */
110
+ metadata?: Record<string, unknown>;
111
+ }
112
+ /** Streaming state surfaced by a ChatHook while a response is in flight. */
113
+ interface ChatStreamingState {
114
+ status: 'idle' | 'connecting' | 'streaming' | 'thinking' | 'complete' | 'error' | 'aborted';
115
+ content: string;
116
+ thinking: string;
117
+ isStreaming: boolean;
118
+ }
119
+
120
+ /**
121
+ * ChatHook — the conversation contract the fi-glass shell consumes.
122
+ *
123
+ * This is the dependency-inversion spine of the chat shell: ChatWidget never
124
+ * imports a concrete conversation hook, it consumes this interface. aurity
125
+ * implements it with `useFIConversation`; og118 implements its own against its
126
+ * backend. A fat contract (state + actions + streaming) → it earns a place in
127
+ * core (unlike navigation, which is a plain callback prop).
128
+ *
129
+ * Generic over:
130
+ * - `TMessage` — the message type (aurity passes its FIMessage; default ChatMessage).
131
+ * - `TNode` — the UI-slot node type (aurity passes React's ReactNode). Kept
132
+ * generic so core stays framework-agnostic (no React import).
133
+ */
134
+ interface ChatHook<TMessage = ChatMessage, TNode = unknown> {
135
+ messages: TMessage[];
136
+ loading: boolean;
137
+ isTyping: boolean;
138
+ loadingInitial?: boolean;
139
+ hasMoreMessages?: boolean;
140
+ loadingOlder?: boolean;
141
+ streamingMessage?: string;
142
+ streaming?: ChatStreamingState;
143
+ sendMessage: (message: string, metadata?: object) => Promise<void>;
144
+ sendMessageStream?: (message: string, metadata?: object) => Promise<void>;
145
+ loadOlderMessages?: () => Promise<void>;
146
+ clearConversation?: () => void;
147
+ getIntroduction?: () => void;
148
+ startConversation?: () => Promise<void>;
149
+ sendQuickReply?: (reply: string) => Promise<void>;
150
+ conversationState?: {
151
+ quickReplies?: string[];
152
+ actions?: Array<{
153
+ type: string;
154
+ data: unknown;
155
+ }>;
156
+ metadata?: Record<string, unknown>;
157
+ };
158
+ customEmptyState?: TNode;
159
+ customQuickReplies?: TNode;
160
+ }
161
+
162
+ /**
163
+ * AgentStreamEvent — the agent-turn wire contract.
164
+ *
165
+ * Material-agnostic, React-free, and intentionally NOT shaped to any one app's
166
+ * backend. Each app's hook MAPS its real stream onto this union: insult_ai maps
167
+ * its `/chat/stream` SSE frames; og118 maps its own transport; a fi-runner-native
168
+ * hook would map `turn_flow` / `ToolCall` / task_tracker stream events. The
169
+ * fi-glass agent panels and the pure `applyAgentEvent` reducer consume ONLY this
170
+ * union — never a concrete transport, endpoint, or auth.
171
+ *
172
+ * This is the neutral middle: it equals neither insult_ai's frontend shape nor
173
+ * fi-core's task_tracker shape; both map onto it. It is the most consequential
174
+ * contract in the fi-glass roadmap — og118 and every future app inherit it.
175
+ */
176
+ /** Lifecycle status of a single planned step. */
177
+ type StepStatus = 'pending' | 'running' | 'done' | 'failed' | 'cancelled';
178
+ /** Severity a guard can assign. Generic — each app names its own guards. */
179
+ type GuardLevel = 'ok' | 'warning' | 'critical';
180
+ /** A tool invocation surfaced for the live audit trail. */
181
+ interface ToolCall {
182
+ /** Stable id from the provider (e.g. tool_use_id); null while pending. */
183
+ id: string | null;
184
+ /** Tool identifier as the agent named it. */
185
+ name: string;
186
+ /** Originating server/namespace, or null for built-ins. */
187
+ server: string | null;
188
+ /** null = pending, false = ok, true = errored. */
189
+ isError: boolean | null;
190
+ }
191
+ /**
192
+ * A soft guard decision against the declared plan (the stream continues).
193
+ *
194
+ * Core defines the SHAPE of the verdict — not what any guard evaluates. The
195
+ * `reason`/copy is owned by the app; core only carries that a guardrail
196
+ * assessed the plan and emitted a verdict. This is the universal agentic-safety
197
+ * pattern, not a domain concept.
198
+ */
199
+ interface GuardRejection {
200
+ /** Human-readable reason. App owns the wording/copy. */
201
+ reason: string;
202
+ /** Which plan steps tripped the guard. */
203
+ matched: Array<{
204
+ index: number;
205
+ label: string;
206
+ }>;
207
+ /** Guard identifier (app-defined), or null. */
208
+ guard: string | null;
209
+ }
210
+ /** Per-turn observability. All optional; each app fills what it has. */
211
+ interface AgentMeta {
212
+ requestId?: string | null;
213
+ latencyMs?: number | null;
214
+ toolCount?: number | null;
215
+ tokens?: Record<string, unknown> | null;
216
+ /** Worst-case guard verdicts by guard name. */
217
+ guardLevels?: Record<string, GuardLevel> | null;
218
+ attempts?: number | null;
219
+ model?: string | null;
220
+ }
221
+ /**
222
+ * The discriminated union an app's hook emits as a turn unfolds.
223
+ *
224
+ * `plan` carries flat labels (the initial announcement, no status yet); the rich
225
+ * per-step state (PlanStep) is built by the reducer as `step_started`/`step_done`
226
+ * arrive — the separation between "what was announced" and "what has happened".
227
+ *
228
+ * `result.sources` is the generic name for evidence references (e.g. source URLs
229
+ * from RAG or web-search). Apps extract them however they like (insult_ai parses
230
+ * a "Receipts" markdown tail in its own hook — app-specific, stays there).
231
+ */
232
+ type AgentStreamEvent = {
233
+ type: 'open';
234
+ sessionId?: string;
235
+ requestId?: string;
236
+ } | {
237
+ type: 'plan';
238
+ steps: string[];
239
+ } | {
240
+ type: 'plan_rejected';
241
+ rejection: GuardRejection;
242
+ } | {
243
+ type: 'step_started';
244
+ index: number;
245
+ } | {
246
+ type: 'step_done';
247
+ index: number;
248
+ status: 'done' | 'failed' | 'cancelled';
249
+ summary?: string;
250
+ error?: string;
251
+ } | {
252
+ type: 'step_noted';
253
+ index: number;
254
+ note: string;
255
+ } | {
256
+ type: 'plan_amended';
257
+ action: 'insert' | 'replan';
258
+ } | {
259
+ type: 'plan_cancelled';
260
+ reason?: string;
261
+ } | {
262
+ type: 'plan_completed';
263
+ completedCount?: number;
264
+ failedCount?: number;
265
+ cancelledCount?: number;
266
+ } | {
267
+ type: 'plan_failed';
268
+ completedCount?: number;
269
+ failedCount?: number;
270
+ cancelledCount?: number;
271
+ } | {
272
+ type: 'tool_call';
273
+ call: ToolCall;
274
+ } | {
275
+ type: 'text';
276
+ delta: string;
277
+ } | {
278
+ type: 'result';
279
+ text: string;
280
+ sources?: string[];
281
+ meta?: AgentMeta;
282
+ } | {
283
+ type: 'meta';
284
+ meta: AgentMeta;
285
+ } | {
286
+ type: 'error';
287
+ message: string;
288
+ } | {
289
+ type: 'done';
290
+ };
291
+
292
+ /**
293
+ * AgentTurnState — the reduced state the fi-glass agent panels render, plus the
294
+ * pure `applyAgentEvent` reducer that derives it from the wire stream.
295
+ *
296
+ * The reducer is pure (no React, no transport, no I/O) so every app reuses the
297
+ * same event→state logic and only supplies the transport that produces the
298
+ * AgentStreamEvent stream. Immutable: every event returns a new state object.
299
+ */
300
+
301
+ /** One step of the declared plan, enriched with live status. */
302
+ interface PlanStep {
303
+ label: string;
304
+ status: StepStatus;
305
+ summary?: string;
306
+ error?: string;
307
+ /** Free-text annotation from note_step (carried by the step_noted event). */
308
+ note?: string;
309
+ }
310
+ /** Terminal verdict of a whole plan (finalize_plan / cancel_plan). */
311
+ type PlanOutcome = 'completed' | 'failed' | 'cancelled';
312
+ /** The agent's declared plan. Guard-as-quality: rejection is woven in here. */
313
+ interface AgentPlan {
314
+ steps: PlanStep[];
315
+ /** Set when a guard blocks; cleared when a fresh plan is declared. */
316
+ rejection?: GuardRejection | null;
317
+ /**
318
+ * Set when the agent restructures the plan mid-turn (plan_amended). 'replan'
319
+ * is then followed by a fresh `plan` event that reseeds steps and clears this.
320
+ */
321
+ amended?: 'insert' | 'replan' | null;
322
+ /** Terminal plan verdict once finalize_plan / cancel_plan settles it. */
323
+ outcome?: PlanOutcome | null;
324
+ }
325
+ type AgentTurnStatus = 'thinking' | 'streaming' | 'done' | 'error';
326
+ /** The full reduced state of one agentic turn. */
327
+ interface AgentTurnState {
328
+ plan: AgentPlan | null;
329
+ steps: ToolCall[];
330
+ text: string;
331
+ /** Evidence references (e.g. source URLs). App-agnostic name. */
332
+ sources: string[];
333
+ meta: AgentMeta | null;
334
+ status: AgentTurnStatus;
335
+ errorMessage?: string;
336
+ }
337
+ /** A fresh, empty turn — call at the start of each agentic turn. */
338
+ declare function initialAgentTurnState(): AgentTurnState;
339
+ /**
340
+ * Pure reducer: apply one wire event to the turn state, returning a new state.
341
+ *
342
+ * Mirrors the universal turn lifecycle; an app's hook feeds it the events its
343
+ * transport produces. Unknown/transport-only events (`open`) pass through
344
+ * untouched.
345
+ */
346
+ declare function applyAgentEvent(state: AgentTurnState, event: AgentStreamEvent): AgentTurnState;
347
+
348
+ /**
349
+ * Transcript bridge — fold the live agentic turn into flat chat messages.
350
+ *
351
+ * Pure, framework-agnostic (no React, no transport). The agent contract models
352
+ * ONE live turn (AgentTurnState); a conversation surface needs the thread as a
353
+ * flat list. These two helpers bridge `AgentTurnState` → `ChatMessage` so any
354
+ * shell (fi-glass and beyond) can keep a visible transcript without re-deriving
355
+ * the mapping. Moved here from the og118 consumer (DD-002-LESSON): a reusable
356
+ * primitive belongs in the framework, not the app wrapper.
357
+ */
358
+
359
+ /** A user message, ready to render optimistically the instant the user sends. */
360
+ declare function makeUserMessage(text: string): ChatMessage;
361
+ /**
362
+ * Fold a finished turn's answer into an assistant message. Keeps only the
363
+ * material-agnostic content (no AgentTurnState snapshot) — a future gate can add
364
+ * per-turn glass-box rendering without bloating the ChatMessage contract now.
365
+ * Model provenance survives the fold: `turn.meta.model` lands in
366
+ * `metadata.model` so a shell's badge slot ("Powered by …") has real data after
367
+ * persistence, not just during the live turn.
368
+ */
369
+ declare function foldAssistantTurn(turn: AgentTurnState): ChatMessage;
370
+
371
+ /**
372
+ * AgentHook — the agentic-turn contract the fi-glass agent panels consume.
373
+ *
374
+ * Dependency-inversion spine, twin of ChatHook. The app implements it against
375
+ * its own transport (insult_ai: POST /chat/stream SSE → applyAgentEvent;
376
+ * og118: its own). fi-glass NEVER imports the transport, endpoints, or auth.
377
+ *
378
+ * This is DATA + ACTIONS only. Presentation slots (renderSources /
379
+ * renderGuardBanner / icons) live on the AgentPanel props in fi-glass, NOT here
380
+ * — the hook is data, the panel is render. (Cleaner than Curio's ChatHook, which
381
+ * carried customEmptyState.) Because no member references a UI node type, the
382
+ * hook needs no `TNode` generic; only the panel is generic over its node type.
383
+ */
384
+ interface AgentHook {
385
+ /** Current/last turn's reduced state. */
386
+ turn: AgentTurnState;
387
+ /** Whether a turn is actively streaming. */
388
+ isStreaming: boolean;
389
+ /** Start an agentic turn. */
390
+ send: (message: string, metadata?: object) => Promise<void>;
391
+ /** Abort the in-flight turn, if supported. */
392
+ abort?: () => void;
393
+ /** Reset the session/turn. */
394
+ reset?: () => void;
395
+ }
396
+
397
+ /**
398
+ * ConversationRecord — the persisted shape of one local-first conversation.
399
+ *
400
+ * DD-002B1: og118 (and every future fi-glass shell) needs the transcript to
401
+ * survive a refresh and a list of past chats for a sidebar. The record is the
402
+ * unit a ConversationLibrary stores; the summary is the light row a sidebar
403
+ * lists without paying for the full message array. Pure data — no React, no
404
+ * browser, no transport. The `id` doubles as the backend session_id so the
405
+ * local transcript and the server's conversation store key the same thread.
406
+ */
407
+
408
+ interface ConversationRecord {
409
+ /** Stable id. Doubles as the backend session_id for the same thread. */
410
+ id: string;
411
+ /** Human-readable title, derived from the first user message. */
412
+ title: string;
413
+ /** ISO 8601 creation timestamp. */
414
+ createdAt: string;
415
+ /** ISO 8601 timestamp of the last change. */
416
+ updatedAt: string;
417
+ /** The thread, sanitized for storage (role/content/timestamp only). */
418
+ messages: ChatMessage[];
419
+ /** Snippet of the last non-empty message, for the sidebar. */
420
+ preview: string;
421
+ /** Schema version of this record, for forward migrations. */
422
+ schemaVersion: number;
423
+ }
424
+ /** A light row for listing conversations in a sidebar (no messages). */
425
+ interface ConversationSummary {
426
+ id: string;
427
+ title: string;
428
+ createdAt: string;
429
+ updatedAt: string;
430
+ preview: string;
431
+ }
432
+
433
+ /**
434
+ * ConversationLibrary — the storage contract for local-first conversations.
435
+ *
436
+ * A pure async interface: adapters implement it over IndexedDB (fi-glass), a
437
+ * backend, or filesystem (later layers) without core taking a dependency on any
438
+ * of them. `list` returns light summaries (cheap); `get` hydrates one full
439
+ * record; `put` upserts; `delete`/`clear` remove. Keeping the contract in core
440
+ * is what stops a reusable persistence primitive from being trapped in a
441
+ * consumer app (DD-002-LESSON / framework-first-canary).
442
+ */
443
+
444
+ interface ConversationLibrary {
445
+ /** All conversations as light summaries, newest `updatedAt` first. */
446
+ list(): Promise<ConversationSummary[]>;
447
+ /** The full record for `id`, or `null` if none. */
448
+ get(id: string): Promise<ConversationRecord | null>;
449
+ /** Insert or replace a record by its `id`. */
450
+ put(record: ConversationRecord): Promise<void>;
451
+ /** Remove the record for `id` (no-op if absent). */
452
+ delete(id: string): Promise<void>;
453
+ /** Remove every stored conversation. */
454
+ clear(): Promise<void>;
455
+ }
456
+
457
+ /**
458
+ * Conversation helpers — pure, deterministic primitives for building and
459
+ * summarizing ConversationRecords. No React, no browser, no transport.
460
+ *
461
+ * Privacy by structure: `sanitizeConversationMessage` builds a NEW message with
462
+ * exactly the allowed subset (role / content / timestamp). Any other field a
463
+ * ChatMessage may carry now or later — `id`, `thinking`, `metadata`, a future
464
+ * tool payload or token — is dropped by construction, not by an allow/deny list
465
+ * someone must remember to update. The initial privacy guarantee is the
466
+ * restriction, not PII heuristics.
467
+ *
468
+ * Determinism: helpers that stamp a time accept an optional `now` so tests are
469
+ * reproducible; they fall back to the wall clock only when it is omitted.
470
+ */
471
+
472
+ /** Schema version stamped on every record created here. */
473
+ declare const CONVERSATION_SCHEMA_VERSION = 1;
474
+ /**
475
+ * Reduce a ChatMessage to the only fields safe to persist: role, content, and
476
+ * timestamp. Drops id, thinking, metadata, and anything else by construction.
477
+ */
478
+ declare function sanitizeConversationMessage(message: ChatMessage): ChatMessage;
479
+ /** Title from the first non-empty user message; `DEFAULT_TITLE` otherwise. */
480
+ declare function deriveConversationTitle(messages: ChatMessage[], max?: number): string;
481
+ /** Preview from the last non-empty message of any role; `''` otherwise. */
482
+ declare function deriveConversationPreview(messages: ChatMessage[], max?: number): string;
483
+ /** Arguments for {@link createConversationRecord}. */
484
+ interface CreateConversationRecordArgs {
485
+ /** Stable id (doubles as the backend session_id). */
486
+ id: string;
487
+ /** Initial thread; sanitized before storing. Default: empty. */
488
+ messages?: ChatMessage[];
489
+ /** ISO timestamp to stamp createdAt/updatedAt. Default: now. */
490
+ now?: string;
491
+ }
492
+ /** Build a fresh, sanitized record with derived title + preview. */
493
+ declare function createConversationRecord(args: CreateConversationRecordArgs): ConversationRecord;
494
+ /** Project a record to its light summary — excludes `messages`. */
495
+ declare function summarizeConversation(record: ConversationRecord): ConversationSummary;
496
+
497
+ export { type AgentHook, type AgentMeta, type AgentPlan, type AgentStreamEvent, type AgentTurnState, type AgentTurnStatus, type AudioSource, CONVERSATION_SCHEMA_VERSION, type ChatHook, type ChatMessage, type ChatStreamingState, type ConversationLibrary, type ConversationRecord, type ConversationSummary, type CreateConversationRecordArgs, type GuardLevel, type GuardRejection, type PlanOutcome, type PlanStep, type StepStatus, type ThemeTokens, type ToolCall, type TranscribeContext, type TranscriptResult, type VoiceAdapter, type VoiceOption, applyAgentEvent, createConversationRecord, deriveConversationPreview, deriveConversationTitle, foldAssistantTurn, initialAgentTurnState, makeUserMessage, sanitizeConversationMessage, summarizeConversation };