MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / readJsonlFile

Function readJsonlFile

apps/kimi-code/src/utils/persistence.ts:69–94  ·  view source on GitHub ↗
(
  filePath: string,
  lineSchema: z.ZodType<T>,
)

Source from the content-addressed store, hash-verified

67}
68
69export async function readJsonlFile<T>(
70 filePath: string,
71 lineSchema: z.ZodType<T>,
72): Promise<T[]> {
73 let raw: string;
74 try {
75 raw = await readFile(filePath, 'utf-8');
76 } catch (error) {
77 if (isNotFound(error)) return [];
78 throw error;
79 }
80
81 const entries: T[] = [];
82 for (const line of raw.split('\n')) {
83 const trimmed = line.trim();
84 if (trimmed.length === 0) continue;
85 try {
86 const parsed = JSON.parse(trimmed) as unknown;
87 const result = lineSchema.safeParse(parsed);
88 if (result.success) entries.push(result.data);
89 } catch {
90 // JSONL is append-only user data; tolerate bad rows and keep the rest.
91 }
92 }
93 return entries;
94}
95
96export async function appendJsonlLine<T>(
97 filePath: string,

Callers 2

loadInputHistoryFunction · 0.90

Calls 3

isNotFoundFunction · 0.70
readFileFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected