@gobing-ai/ts-llm-jsonl-importer 0.2.1

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/src/types.ts ADDED
@@ -0,0 +1,89 @@
1
+ import type { DbAdapter } from '@gobing-ai/ts-db';
2
+ import type { z } from 'zod';
3
+
4
+ /** Built-in source identifiers supported by the importer. */
5
+ export type LlmJsonlSource = 'pi' | 'claude' | 'codex' | 'gemini' | 'opencode' | 'antigravity' | 'openclaw';
6
+
7
+ /** Import mode controlling checkpoint behavior. */
8
+ export type ImportMode = 'full' | 'incremental' | 'force-file';
9
+
10
+ /** Split strategy for turning a raw JSONL object into one or more ETL records. */
11
+ export type SplitConfig =
12
+ | {
13
+ readonly mode: 'one-to-one';
14
+ }
15
+ | {
16
+ readonly mode: 'one-to-many';
17
+ readonly field: string;
18
+ readonly targetTable?: string;
19
+ }
20
+ | {
21
+ readonly mode: 'custom';
22
+ readonly split: (raw: JsonObject) => readonly JsonObject[];
23
+ readonly targetTable?: string;
24
+ };
25
+
26
+ /** JSON-compatible record used at the importer boundary. */
27
+ export type JsonObject = Record<string, unknown>;
28
+
29
+ /** Transform function for mapped canonical fields. */
30
+ export type FieldTransform = (value: unknown, raw: JsonObject, context: TransformContext) => unknown;
31
+
32
+ /** Context available while normalizing a split record. */
33
+ export interface TransformContext {
34
+ readonly source: LlmJsonlSource;
35
+ readonly sourceFile: string;
36
+ readonly sourceLine: number;
37
+ readonly splitIndex: number;
38
+ }
39
+
40
+ /** Declarative importer configuration for one LLM history source. */
41
+ export interface SourceDefinition<TRecord extends JsonObject = JsonObject> {
42
+ readonly source: LlmJsonlSource;
43
+ readonly displayName: string;
44
+ readonly defaultRoots: readonly string[];
45
+ readonly filePatterns: readonly string[];
46
+ readonly targetTable: string;
47
+ readonly splitConfig: SplitConfig;
48
+ readonly fieldMap: Readonly<Record<string, string>>;
49
+ readonly fieldTransforms: Readonly<Record<string, FieldTransform>>;
50
+ readonly schema: z.ZodType<TRecord>;
51
+ }
52
+
53
+ /** Redaction rule applied before hashing and persistence. */
54
+ export interface RedactionRule {
55
+ readonly name: string;
56
+ readonly pattern: RegExp;
57
+ readonly replacement: string;
58
+ }
59
+
60
+ /** Options for one importer run. */
61
+ export interface ImportOptions {
62
+ readonly db: DbAdapter;
63
+ readonly mode?: ImportMode;
64
+ readonly roots?: readonly string[];
65
+ readonly files?: readonly string[];
66
+ readonly dryRun?: boolean;
67
+ readonly redactionRules?: readonly RedactionRule[];
68
+ readonly now?: () => Date;
69
+ }
70
+
71
+ /** Structured importer error that can be reported without persisting raw input. */
72
+ export interface ImportIssue {
73
+ readonly sourceFile: string;
74
+ readonly sourceLine: number;
75
+ readonly reason: string;
76
+ }
77
+
78
+ /** Summary produced by the importer control function. */
79
+ export interface ImportResult {
80
+ readonly source: LlmJsonlSource;
81
+ readonly mode: ImportMode;
82
+ readonly scannedFiles: number;
83
+ readonly processedLines: number;
84
+ readonly importedRecords: number;
85
+ readonly skippedDuplicates: number;
86
+ readonly parseErrors: readonly ImportIssue[];
87
+ readonly validationErrors: readonly ImportIssue[];
88
+ readonly checkpointUpdates: number;
89
+ }