/** * Session → sharegpt SFT dataset exporter (Dataset-uploader.md §2.1). * * Reads the local sessions DB read-only (default `~/.spectral/sessions.db`) * and maps stored messages to sharegpt conversation samples: * * user row → { from: "human", value: content } * assistant row → events_jsonl parsed in event order: * concatenated text_delta → { from: "gpt" } * each tool_call → { from: "function_call", * value: JSON.stringify({name, arguments}) } * matching tool_result → { from: "observation", * value: text of result.content, * "[ERROR] " prefix when isError } * thinking_* events → DISCARDED (non-thinking target) * * Per-turn expansion: each assistant message row that produces at least one * entry becomes one sample — `{ conversations: [all entries up to and * including this turn], system?, tools? }`. `system`/`tools` are plain * parameters (the assembling index.ts passes `ctx.getSystemPrompt()` and * the runtime tool registry). `system` is attached ONLY to samples from * sessions whose `active_agent` equals the MOST COMMON active_agent among * the exported sessions (the ExtensionContext exposes no current-agent * accessor, so this heuristic is the documented fallback); sessions with a * different — or null — active_agent get no system field. * * Subagent handling: when `includeSubagents` is false (default) every * observation is capped at MAX_OBSERVATION_CHARS with a "...[truncated]" * marker (subagent transcripts are the dominant source of oversized * observations). */ interface ReadOnlyStatement { all(...params: unknown[]): unknown[]; } interface ReadOnlyDb { prepare(sql: string): ReadOnlyStatement; close(): void; } /** Open a SQLite database file read-only (file must already exist). */ export declare function openReadOnlySqlite(path: string): ReadOnlyDb; export interface SharegptEntry { from: "human" | "gpt" | "function_call" | "observation"; value: string; } /** OpenAI-style tool definition, as stored in the sample `tools` field. */ export interface ToolDefinition { type: "function"; function: { name: string; description?: string; parameters?: unknown; }; } export interface SharegptSample { conversations: SharegptEntry[]; system?: string; tools?: ToolDefinition[]; } export interface ExportSessionsOptions { /** Path to the sessions DB. Default: `/sessions.db`. */ dbPath?: string; /** Restrict the export to these session ids. */ sessionIds?: string[]; /** Max number of sessions (newest first by updated_at). */ limit?: number; /** Only sessions with updated_at >= since (ISO 8601 string). */ since?: string; /** * When true, observations are NOT capped (subagent transcripts kept * intact). Default false → observations capped at MAX_OBSERVATION_CHARS. */ includeSubagents?: boolean; /** Output JSONL path. Default: `/datasets/export-.jsonl`. */ outputPath?: string; /** * System prompt to attach to samples of sessions whose `active_agent` * matches the most common active_agent among the exported sessions; * omitted when null/empty. */ system?: string | null; /** Tool registry to attach to every sample; omitted when null/empty. */ tools?: ToolDefinition[] | undefined; } export interface ExportSessionsResult { /** Number of sessions processed. */ sessions: number; /** Number of sharegpt samples written. */ samples: number; /** Total bytes written to the output file(s). */ bytes: number; /** Count of tool calls per tool name (per call event, not per sample). */ toolCoverage: Record; /** Output file paths (always a single JSONL in v1). */ files: string[]; /** * The active_agent value that received the system prompt (the most * common active_agent among the exported sessions), when a system * prompt was provided. null when no system prompt was attached. */ systemAgent: string | null; /** Number of sessions whose samples had the system prompt attached. */ systemSessionCount: number; } /** * Cap for observation text when `includeSubagents` is false. history- * projection's 256 KB field cap is too large for training data, so this * module defines its own tighter limit. */ export declare const MAX_OBSERVATION_CHARS = 4000; export declare const OBSERVATION_TRUNCATION_MARKER = "...[truncated]"; interface ToolResultContentPart { type?: string; text?: string; } interface AssistantEvent { type: string; delta?: string; id?: string; name?: string; args?: unknown; result?: { content?: ToolResultContentPart[]; } | null; isError?: boolean; } export interface ParsedAssistantTurn { entries: SharegptEntry[]; /** Tool names invoked by this turn's tool_call events (in order). */ toolNames: string[]; } /** Extract the plain text of a tool_result payload (concatenated text parts). */ export declare function extractResultText(result: AssistantEvent["result"]): string; /** * Parse an assistant row's events_jsonl into sharegpt entries, in event * order. Thinking events are discarded. When `capChars` is non-null, * observation values are truncated to it + OBSERVATION_TRUNCATION_MARKER. */ export declare function parseAssistantEvents(eventsJsonl: string, capChars?: number | null): ParsedAssistantTurn; /** * Export sessions from the local sessions DB to a sharegpt JSONL file. * * The DB is opened strictly read-only; the output file is written next to * (or at) `outputPath`. One JSON sample per line. */ export declare function exportSessions(options?: ExportSessionsOptions): ExportSessionsResult; export {}; //# sourceMappingURL=exporter.d.ts.map