claude-code-jsonl-parser 0.1.4-beta.3 → 0.1.4-beta.31
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/README.md +44 -43
- package/dist/index.cjs +73 -69
- package/dist/index.d.cts +111 -94
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +111 -94
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code JSONL
|
|
3
|
-
* 形状の根拠は実サンプルコーパスの調査結果。
|
|
2
|
+
* claude-code-jsonl-parser: type-safe parser for Claude Code JSONL conversation logs.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { parseJsonlFile } from 'claude-code-jsonl-parser'
|
|
7
|
+
*
|
|
8
|
+
* const result = await parseJsonlFile('/path/to/session.jsonl')
|
|
9
|
+
* if (result.isOk) {
|
|
10
|
+
* for (const line of result.value) {
|
|
11
|
+
* if (line._kind === 'known' && line.type === 'assistant') {
|
|
12
|
+
* console.log(line.message.content)
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Type definitions of the Claude Code JSONL entries.
|
|
20
|
+
*
|
|
21
|
+
* This file is maintained by hand.
|
|
22
|
+
* claude-code-jsonl-generator emits `types.generated.ts` for a corpus; diff that output against this file and merge intentionally.
|
|
23
|
+
* Content blocks and message shapes are curated by hand, so never overwrite them wholesale.
|
|
8
24
|
*/
|
|
9
|
-
/** parser
|
|
25
|
+
/** Internal discriminator added by the parser. Separate from the `type` field. */
|
|
10
26
|
type ParsedKind = 'known' | 'unknown' | 'error';
|
|
11
|
-
/** assistant / user / attachment / system
|
|
27
|
+
/** Required metadata shared by assistant / user / attachment / system. */
|
|
12
28
|
interface EntryBase {
|
|
13
29
|
cwd: string;
|
|
14
30
|
entrypoint: string;
|
|
@@ -20,7 +36,7 @@ interface EntryBase {
|
|
|
20
36
|
userType: string;
|
|
21
37
|
uuid: string;
|
|
22
38
|
version: string;
|
|
23
|
-
/**
|
|
39
|
+
/** Optional sidechain / sub-agent related fields (as observed) */
|
|
24
40
|
agentId?: string;
|
|
25
41
|
agentName?: string;
|
|
26
42
|
teamName?: string;
|
|
@@ -28,7 +44,7 @@ interface EntryBase {
|
|
|
28
44
|
sessionKind?: string;
|
|
29
45
|
session_id?: string;
|
|
30
46
|
}
|
|
31
|
-
/** `type: "assistant"
|
|
47
|
+
/** `type: "assistant"`: assistant response (wraps an Anthropic API message). */
|
|
32
48
|
interface AssistantEntry extends EntryBase {
|
|
33
49
|
_kind: 'known';
|
|
34
50
|
type: 'assistant';
|
|
@@ -43,13 +59,13 @@ interface AssistantEntry extends EntryBase {
|
|
|
43
59
|
attributionMcpServer?: string;
|
|
44
60
|
attributionMcpTool?: string;
|
|
45
61
|
}
|
|
46
|
-
/** `user.origin
|
|
62
|
+
/** `user.origin`: kind of origin and accompanying information. */
|
|
47
63
|
interface UserOrigin {
|
|
48
64
|
kind: string;
|
|
49
65
|
from?: string;
|
|
50
66
|
senderTaskId?: string;
|
|
51
67
|
}
|
|
52
|
-
/** `type: "user"
|
|
68
|
+
/** `type: "user"`: wraps user input / tool results. */
|
|
53
69
|
interface UserEntry extends EntryBase {
|
|
54
70
|
_kind: 'known';
|
|
55
71
|
type: 'user';
|
|
@@ -71,13 +87,13 @@ interface UserEntry extends EntryBase {
|
|
|
71
87
|
toolDenialKind?: string;
|
|
72
88
|
toolEndsTurn?: boolean;
|
|
73
89
|
}
|
|
74
|
-
/** `type: "attachment"
|
|
90
|
+
/** `type: "attachment"`: attached data. */
|
|
75
91
|
interface AttachmentEntry extends EntryBase {
|
|
76
92
|
_kind: 'known';
|
|
77
93
|
type: 'attachment';
|
|
78
94
|
attachment: Record<string, unknown>;
|
|
79
95
|
}
|
|
80
|
-
/** `type: "system"
|
|
96
|
+
/** `type: "system"`: system event (refined by `subtype`). */
|
|
81
97
|
interface SystemEntry extends EntryBase {
|
|
82
98
|
_kind: 'known';
|
|
83
99
|
type: 'system';
|
|
@@ -132,7 +148,7 @@ interface AgentNameEntry {
|
|
|
132
148
|
agentName: string;
|
|
133
149
|
sessionId: string;
|
|
134
150
|
}
|
|
135
|
-
/** `type: "agent-setting"
|
|
151
|
+
/** `type: "agent-setting"`: `agentSetting` is a string. */
|
|
136
152
|
interface AgentSettingEntry {
|
|
137
153
|
_kind: 'known';
|
|
138
154
|
type: 'agent-setting';
|
|
@@ -146,7 +162,7 @@ interface RelocatedEntry {
|
|
|
146
162
|
relocatedCwd: string;
|
|
147
163
|
sessionId: string;
|
|
148
164
|
}
|
|
149
|
-
/** `type: "last-prompt"
|
|
165
|
+
/** `type: "last-prompt"`: `lastPrompt` is optional. */
|
|
150
166
|
interface LastPromptEntry {
|
|
151
167
|
_kind: 'known';
|
|
152
168
|
type: 'last-prompt';
|
|
@@ -154,7 +170,7 @@ interface LastPromptEntry {
|
|
|
154
170
|
sessionId: string;
|
|
155
171
|
lastPrompt?: string;
|
|
156
172
|
}
|
|
157
|
-
/** `type: "worktree-state"
|
|
173
|
+
/** `type: "worktree-state"`: `worktreeSession` is an object or null. */
|
|
158
174
|
interface WorktreeStateEntry {
|
|
159
175
|
_kind: 'known';
|
|
160
176
|
type: 'worktree-state';
|
|
@@ -169,7 +185,7 @@ interface BridgeSessionEntry {
|
|
|
169
185
|
lastSequenceNum: number;
|
|
170
186
|
sessionId: string;
|
|
171
187
|
}
|
|
172
|
-
/** `type: "queue-operation"
|
|
188
|
+
/** `type: "queue-operation"`: `content` is optional. */
|
|
173
189
|
interface QueueOperationEntry {
|
|
174
190
|
_kind: 'known';
|
|
175
191
|
type: 'queue-operation';
|
|
@@ -197,7 +213,7 @@ interface FrameLinkEntry {
|
|
|
197
213
|
sessionId: string;
|
|
198
214
|
timestamp: string;
|
|
199
215
|
}
|
|
200
|
-
/** `type: "file-history-snapshot"
|
|
216
|
+
/** `type: "file-history-snapshot"`: has no sessionId. */
|
|
201
217
|
interface FileHistorySnapshotEntry {
|
|
202
218
|
_kind: 'known';
|
|
203
219
|
type: 'file-history-snapshot';
|
|
@@ -205,14 +221,14 @@ interface FileHistorySnapshotEntry {
|
|
|
205
221
|
messageId: string;
|
|
206
222
|
snapshot: Record<string, unknown>;
|
|
207
223
|
}
|
|
208
|
-
/** `type: "started"
|
|
224
|
+
/** `type: "started"`: comes from the workflow journal. Has no sessionId. */
|
|
209
225
|
interface StartedEntry {
|
|
210
226
|
_kind: 'known';
|
|
211
227
|
type: 'started';
|
|
212
228
|
key: string;
|
|
213
229
|
agentId: string;
|
|
214
230
|
}
|
|
215
|
-
/** `type: "result"
|
|
231
|
+
/** `type: "result"`: comes from the workflow journal. `result` has an arbitrary shape. */
|
|
216
232
|
interface ResultEntry {
|
|
217
233
|
_kind: 'known';
|
|
218
234
|
type: 'result';
|
|
@@ -220,26 +236,26 @@ interface ResultEntry {
|
|
|
220
236
|
agentId: string;
|
|
221
237
|
result: unknown;
|
|
222
238
|
}
|
|
223
|
-
/**
|
|
239
|
+
/** All entries of known types. */
|
|
224
240
|
type KnownEntry = AssistantEntry | UserEntry | AttachmentEntry | SystemEntry | ModeEntry | PermissionModeEntry | AiTitleEntry | AgentNameEntry | AgentSettingEntry | RelocatedEntry | LastPromptEntry | WorktreeStateEntry | BridgeSessionEntry | QueueOperationEntry | PrLinkEntry | FrameLinkEntry | FileHistorySnapshotEntry | StartedEntry | ResultEntry;
|
|
225
|
-
/** type
|
|
241
|
+
/** A line with an unknown type, or a known type whose shape did not match. Keeps the raw JSON. */
|
|
226
242
|
interface UnknownEntry {
|
|
227
243
|
_kind: 'unknown';
|
|
228
244
|
lineNumber: number;
|
|
229
245
|
raw: unknown;
|
|
230
|
-
/**
|
|
246
|
+
/** The type value when a guard exists for it but the shape did not match. `undefined` for an unknown type. */
|
|
231
247
|
typeHint?: string;
|
|
232
|
-
/** `typeHint`
|
|
248
|
+
/** When `typeHint` is set, a diagnostic message naming the fields that caused the mismatch. */
|
|
233
249
|
reason?: string;
|
|
234
250
|
}
|
|
235
|
-
/** JSON
|
|
251
|
+
/** A line with a JSON syntax error. */
|
|
236
252
|
interface LineParseError {
|
|
237
253
|
_kind: 'error';
|
|
238
254
|
lineNumber: number;
|
|
239
255
|
rawLine: string;
|
|
240
256
|
message: string;
|
|
241
257
|
}
|
|
242
|
-
/**
|
|
258
|
+
/** Parse result of one line. */
|
|
243
259
|
type ParsedLine = KnownEntry | UnknownEntry | LineParseError;
|
|
244
260
|
/** `{ type: "text", text }`。 */
|
|
245
261
|
interface TextBlock {
|
|
@@ -263,7 +279,7 @@ interface ToolUseBlock {
|
|
|
263
279
|
input: unknown;
|
|
264
280
|
caller?: unknown;
|
|
265
281
|
}
|
|
266
|
-
/**
|
|
282
|
+
/** `{ type: "image", source }` inside a tool_result. */
|
|
267
283
|
interface ImageBlock {
|
|
268
284
|
_kind: 'known';
|
|
269
285
|
type: 'image';
|
|
@@ -273,13 +289,13 @@ interface ImageBlock {
|
|
|
273
289
|
data: string;
|
|
274
290
|
};
|
|
275
291
|
}
|
|
276
|
-
/**
|
|
292
|
+
/** `{ type: "tool_reference", tool_name }` inside a tool_result. */
|
|
277
293
|
interface ToolReferenceBlock {
|
|
278
294
|
_kind: 'known';
|
|
279
295
|
type: 'tool_reference';
|
|
280
296
|
tool_name: string;
|
|
281
297
|
}
|
|
282
|
-
/** tool_result
|
|
298
|
+
/** Union of the elements of a tool_result content array. */
|
|
283
299
|
type ToolResultContentBlock = TextBlock | ImageBlock | ToolReferenceBlock | UnknownContentBlock;
|
|
284
300
|
/** `{ type: "tool_result", tool_use_id, content, is_error? }`。 */
|
|
285
301
|
interface ToolResultBlock {
|
|
@@ -290,20 +306,20 @@ interface ToolResultBlock {
|
|
|
290
306
|
is_error?: boolean;
|
|
291
307
|
}
|
|
292
308
|
/**
|
|
293
|
-
* content
|
|
294
|
-
* `_kind`
|
|
295
|
-
*
|
|
296
|
-
* (
|
|
309
|
+
* Partial fallback for a content block that matches no known shape.
|
|
310
|
+
* `_kind` is the same discriminator as on known blocks: check it for `'unknown'`
|
|
311
|
+
* first, and the known side can then be narrowed safely with `.type`
|
|
312
|
+
* (e.g. `if (block._kind === 'unknown') {...} else if (block.type === 'text') {...}`).
|
|
297
313
|
*/
|
|
298
314
|
interface UnknownContentBlock {
|
|
299
315
|
_kind: 'unknown';
|
|
300
316
|
raw: unknown;
|
|
301
317
|
}
|
|
302
|
-
/** assistant `message.content[]
|
|
318
|
+
/** Union of the elements of assistant `message.content[]`. */
|
|
303
319
|
type AssistantContentBlock = TextBlock | ThinkingBlock | ToolUseBlock | UnknownContentBlock;
|
|
304
|
-
/** user `message.content[]`
|
|
320
|
+
/** Union of the elements of user `message.content[]` (when content is an array). */
|
|
305
321
|
type UserContentBlock = TextBlock | ToolResultBlock | UnknownContentBlock;
|
|
306
|
-
/**
|
|
322
|
+
/** The Anthropic API message of an assistant entry. */
|
|
307
323
|
interface AssistantMessage {
|
|
308
324
|
id: string;
|
|
309
325
|
type: string;
|
|
@@ -318,7 +334,7 @@ interface AssistantMessage {
|
|
|
318
334
|
container?: unknown;
|
|
319
335
|
context_management?: unknown;
|
|
320
336
|
}
|
|
321
|
-
/**
|
|
337
|
+
/** User message. `content` is a string or an array. */
|
|
322
338
|
interface UserMessage {
|
|
323
339
|
role: string;
|
|
324
340
|
content: string | UserContentBlock[];
|
|
@@ -326,9 +342,9 @@ interface UserMessage {
|
|
|
326
342
|
/**
|
|
327
343
|
* Zero-dependency Result / ResultAsync implementation.
|
|
328
344
|
*
|
|
329
|
-
* neverthrow
|
|
345
|
+
* Offers neverthrow-like ergonomics without any external dependency.
|
|
330
346
|
*/
|
|
331
|
-
/**
|
|
347
|
+
/** A success. Holds `value`. */
|
|
332
348
|
interface OkResult<T> {
|
|
333
349
|
readonly isOk: true;
|
|
334
350
|
readonly isErr: false;
|
|
@@ -339,7 +355,7 @@ interface OkResult<T> {
|
|
|
339
355
|
match<U>(onOk: (value: T) => U, _onErr: (error: never) => U): U;
|
|
340
356
|
unwrapOr(_fallback: T): T;
|
|
341
357
|
}
|
|
342
|
-
/**
|
|
358
|
+
/** A failure. Holds `error`. */
|
|
343
359
|
interface ErrResult<E> {
|
|
344
360
|
readonly isOk: false;
|
|
345
361
|
readonly isErr: true;
|
|
@@ -350,120 +366,119 @@ interface ErrResult<E> {
|
|
|
350
366
|
match<U>(_onOk: (value: never) => U, onErr: (error: E) => U): U;
|
|
351
367
|
unwrapOr<T>(fallback: T): T;
|
|
352
368
|
}
|
|
353
|
-
/** `OkResult<T>`
|
|
369
|
+
/** Either `OkResult<T>` or `ErrResult<E>`. */
|
|
354
370
|
type Result<T, E> = OkResult<T> | ErrResult<E>;
|
|
355
371
|
/**
|
|
356
|
-
*
|
|
372
|
+
* Creates a success `Result<T, never>`.
|
|
357
373
|
*
|
|
358
|
-
* @param value -
|
|
374
|
+
* @param value - Success value
|
|
359
375
|
*/
|
|
360
376
|
export declare function ok<T>(value: T): OkResult<T>;
|
|
361
377
|
/**
|
|
362
|
-
*
|
|
378
|
+
* Creates a failure `Result<never, E>`.
|
|
363
379
|
*
|
|
364
|
-
* @param error -
|
|
380
|
+
* @param error - Error value
|
|
365
381
|
*/
|
|
366
382
|
export declare function err<E>(error: E): ErrResult<E>;
|
|
367
383
|
/**
|
|
368
|
-
* `
|
|
384
|
+
* A `PromiseLike<Result<T, E>>` that can be awaited and chained with `map` / `mapErr` / `andThen`.
|
|
369
385
|
*/
|
|
370
386
|
export declare class ResultAsync<T, E> implements PromiseLike<Result<T, E>> {
|
|
371
387
|
private readonly _promise;
|
|
372
388
|
constructor(promise: Promise<Result<T, E>>);
|
|
373
389
|
then<TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((value: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
374
390
|
/**
|
|
375
|
-
* `Promise<T>`
|
|
391
|
+
* Wraps a `Promise<T>` in a `ResultAsync<T, E>`. A rejection is mapped to `E` with `onError`.
|
|
376
392
|
*
|
|
377
|
-
* @param promise -
|
|
378
|
-
* @param onError -
|
|
393
|
+
* @param promise - Target promise
|
|
394
|
+
* @param onError - Error mapper
|
|
379
395
|
*/
|
|
380
396
|
static fromPromise<T, E>(promise: Promise<T>, onError: (reason: unknown) => E): ResultAsync<T, E>;
|
|
381
397
|
/**
|
|
382
|
-
*
|
|
398
|
+
* Wraps a resolved `Result<T, E>` in a `ResultAsync<T, E>`.
|
|
383
399
|
*
|
|
384
|
-
* @param result -
|
|
400
|
+
* @param result - Target result
|
|
385
401
|
*/
|
|
386
402
|
static fromResult<T, E>(result: Result<T, E>): ResultAsync<T, E>;
|
|
387
403
|
/**
|
|
388
|
-
*
|
|
404
|
+
* Transforms the success value.
|
|
389
405
|
*
|
|
390
|
-
* @param fn -
|
|
406
|
+
* @param fn - Synchronous mapper
|
|
391
407
|
*/
|
|
392
408
|
map<U>(fn: (value: T) => U): ResultAsync<U, E>;
|
|
393
409
|
/**
|
|
394
|
-
*
|
|
410
|
+
* Transforms the error value.
|
|
395
411
|
*
|
|
396
|
-
* @param fn -
|
|
412
|
+
* @param fn - Synchronous error mapper
|
|
397
413
|
*/
|
|
398
414
|
mapErr<F>(fn: (error: E) => F): ResultAsync<T, F>;
|
|
399
415
|
/**
|
|
400
|
-
*
|
|
416
|
+
* Chains a step that may fail.
|
|
401
417
|
*
|
|
402
|
-
* @param fn - `ResultAsync<U, F>`
|
|
418
|
+
* @param fn - Mapper returning a `ResultAsync<U, F>` or `Result<U, F>`
|
|
403
419
|
*/
|
|
404
420
|
andThen<U, F>(fn: (value: T) => ResultAsync<U, F> | Result<U, F>): ResultAsync<U, E | F>;
|
|
405
421
|
/**
|
|
406
|
-
*
|
|
422
|
+
* Pattern-matches on success / failure.
|
|
407
423
|
*
|
|
408
|
-
* @param onOk -
|
|
409
|
-
* @param onErr -
|
|
424
|
+
* @param onOk - Success handler
|
|
425
|
+
* @param onErr - Error handler
|
|
410
426
|
*/
|
|
411
427
|
match<U>(onOk: (value: T) => U | Promise<U>, onErr: (error: E) => U | Promise<U>): Promise<U>;
|
|
412
428
|
/**
|
|
413
|
-
*
|
|
429
|
+
* Returns the value on success, or `fallback` on failure.
|
|
414
430
|
*
|
|
415
|
-
* @param fallback -
|
|
431
|
+
* @param fallback - Fallback value
|
|
416
432
|
*/
|
|
417
433
|
unwrapOr(fallback: T): Promise<T>;
|
|
418
434
|
}
|
|
419
|
-
/**
|
|
435
|
+
/** An error caused by file I/O. JSON syntax errors and unknown types are not included. */
|
|
420
436
|
interface FileReadError {
|
|
421
437
|
_tag: 'FileReadError';
|
|
422
438
|
path: string;
|
|
423
|
-
/** Node.js
|
|
439
|
+
/** Node.js error code (`ENOENT`, `EACCES`, ...). `undefined` if unavailable. */
|
|
424
440
|
code?: string;
|
|
425
441
|
message: string;
|
|
426
442
|
}
|
|
427
443
|
/**
|
|
428
|
-
* FileReadError
|
|
444
|
+
* Creates a `FileReadError`.
|
|
429
445
|
*
|
|
430
|
-
* @param path -
|
|
431
|
-
* @param error -
|
|
446
|
+
* @param path - Target path
|
|
447
|
+
* @param error - Caught exception
|
|
432
448
|
*/
|
|
433
449
|
export declare function fileReadError(path: string, error: unknown): FileReadError;
|
|
434
450
|
/**
|
|
435
|
-
* JSONL
|
|
436
|
-
* `text.split('\n')
|
|
437
|
-
* 追加メモリは 1 行分にとどまる (全行配列分の追加確保が発生しない)。
|
|
451
|
+
* Synchronous iterator that parses a JSONL string line by line.
|
|
452
|
+
* It slices one line at a time with `indexOf` instead of building a full line array with `text.split('\n')`, so the extra memory stays at one line.
|
|
438
453
|
*
|
|
439
|
-
*
|
|
454
|
+
* Blank lines (empty after trimming) are skipped and not counted in line numbers.
|
|
440
455
|
*
|
|
441
|
-
* @param text - JSONL
|
|
456
|
+
* @param text - Whole JSONL text
|
|
442
457
|
*/
|
|
443
458
|
export declare function parseJsonlLines(text: string): Iterable<ParsedLine>;
|
|
444
459
|
/**
|
|
445
|
-
* JSONL
|
|
446
|
-
*
|
|
460
|
+
* Parses a whole JSONL string and returns the lines as an array.
|
|
461
|
+
* Per-line errors are represented as array elements, so this function never returns `Err`.
|
|
447
462
|
*
|
|
448
|
-
* @param text - JSONL
|
|
463
|
+
* @param text - Whole JSONL text
|
|
449
464
|
*/
|
|
450
465
|
export declare function parseJsonl(text: string): Result<ParsedLine[], never>;
|
|
451
466
|
/**
|
|
452
|
-
*
|
|
453
|
-
* I/O
|
|
467
|
+
* Asynchronous iterator that reads and parses a file line by line (constant memory).
|
|
468
|
+
* An I/O error is thrown as a `FileReadError` during iteration.
|
|
454
469
|
*
|
|
455
|
-
* @param path - JSONL
|
|
470
|
+
* @param path - JSONL file path
|
|
456
471
|
*/
|
|
457
472
|
export declare function parseJsonlFileStream(path: string): AsyncIterable<ParsedLine>;
|
|
458
473
|
/**
|
|
459
|
-
*
|
|
474
|
+
* Reads a whole file and parses it at once. Only I/O errors become `Err`.
|
|
460
475
|
*
|
|
461
|
-
* @param path - JSONL
|
|
476
|
+
* @param path - JSONL file path
|
|
462
477
|
*/
|
|
463
478
|
export declare function parseJsonlFile(path: string): ResultAsync<ParsedLine[], FileReadError>;
|
|
464
479
|
/**
|
|
465
|
-
*
|
|
466
|
-
*
|
|
480
|
+
* Result of a guard. When `ok` is false, `reason` holds a diagnostic message such
|
|
481
|
+
* as the names of the mismatching fields, so consumers can see what caused the mismatch.
|
|
467
482
|
*/
|
|
468
483
|
interface GuardResult {
|
|
469
484
|
ok: boolean;
|
|
@@ -488,7 +503,7 @@ declare function isFrameLink(v: unknown): GuardResult;
|
|
|
488
503
|
declare function isFileHistorySnapshot(v: unknown): GuardResult;
|
|
489
504
|
declare function isStarted(v: unknown): GuardResult;
|
|
490
505
|
declare function isResult(v: unknown): GuardResult;
|
|
491
|
-
/** type
|
|
506
|
+
/** Map from type string to guard function. */
|
|
492
507
|
export declare const guards: {
|
|
493
508
|
readonly assistant: typeof isAssistant;
|
|
494
509
|
readonly user: typeof isUser;
|
|
@@ -510,28 +525,30 @@ export declare const guards: {
|
|
|
510
525
|
readonly started: typeof isStarted;
|
|
511
526
|
readonly result: typeof isResult;
|
|
512
527
|
};
|
|
513
|
-
/**
|
|
528
|
+
/** Names of the known types. */
|
|
514
529
|
export declare const KNOWN_TYPES: (keyof typeof guards)[];
|
|
515
530
|
/**
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
531
|
+
* Applies the guard of the given type, or returns undefined if no guard exists for it.
|
|
532
|
+
* Returns `{ ok: true }` on a match and `{ ok: false, reason }` on a mismatch, where
|
|
533
|
+
* `reason` names the fields that caused it.
|
|
519
534
|
*
|
|
520
|
-
* @param type -
|
|
521
|
-
* @param v -
|
|
535
|
+
* @param type - Discriminator
|
|
536
|
+
* @param v - Raw JSON to check
|
|
522
537
|
*/
|
|
523
538
|
export declare function guardByType(type: string, v: unknown): GuardResult | undefined;
|
|
524
539
|
/**
|
|
525
|
-
*
|
|
526
|
-
*
|
|
540
|
+
* Normalizes the message.content of an assistant entry.
|
|
541
|
+
* Known blocks are kept as is; unknown ones are demoted to `UnknownContentBlock`.
|
|
542
|
+
* A non-array value becomes a single `UnknownContentBlock`.
|
|
527
543
|
*
|
|
528
|
-
* @param content -
|
|
544
|
+
* @param content - Raw content
|
|
529
545
|
*/
|
|
530
546
|
export declare function normalizeAssistantContent(content: unknown): AssistantContentBlock[];
|
|
531
547
|
/**
|
|
532
|
-
*
|
|
548
|
+
* Normalizes the message.content of a user entry. A string is returned as is and an array is normalized per element.
|
|
549
|
+
* Any other value becomes a single `UnknownContentBlock`.
|
|
533
550
|
*
|
|
534
|
-
* @param content -
|
|
551
|
+
* @param content - Raw content (string or array)
|
|
535
552
|
*/
|
|
536
553
|
export declare function normalizeUserContent(content: unknown): string | UserContentBlock[];
|
|
537
554
|
export type { AgentNameEntry, AgentSettingEntry, AiTitleEntry, AssistantContentBlock, AssistantEntry, AssistantMessage, AttachmentEntry, BridgeSessionEntry, EntryBase, ErrResult, FileHistorySnapshotEntry, FileReadError, FrameLinkEntry, GuardResult, ImageBlock, KnownEntry, LastPromptEntry, LineParseError, ModeEntry, OkResult, ParsedKind, ParsedLine, PermissionModeEntry, PrLinkEntry, QueueOperationEntry, RelocatedEntry, Result, ResultEntry, StartedEntry, SystemEntry, TextBlock, ThinkingBlock, ToolReferenceBlock, ToolResultBlock, ToolResultContentBlock, ToolUseBlock, UnknownContentBlock, UnknownEntry, UserContentBlock, UserEntry, UserMessage, WorktreeStateEntry };
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/generated/types.ts","../src/result.ts","../src/errors.ts","../src/parse.ts","../src/generated/guards.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/generated/types.ts","../src/result.ts","../src/errors.ts","../src/parse.ts","../src/generated/guards.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;KAaY;;UAOK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA;EACA;;;UAQe,uBAAuB;EACtC;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;;;UAIe,kBAAkB;EACjC;EACA;EACA,SAAS;EACT;EACA;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;UAIe,wBAAwB;EACvC;EACA;EACA,YAAY;;;UAIG,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;UAQe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA,iBAAiB;EACjB;;;UAIe;EACf;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA,UAAU;;;UAIK;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA;;;KAQU,aACR,iBACA,YACA,kBACA,cACA,YACA,sBACA,eACA,iBACA,oBACA,iBACA,kBACA,qBACA,qBACA,sBACA,cACA,iBACA,2BACA,eACA;;UAGa;EACf;EACA;EACA;;EAEA;;EAEA;;;UAIe;EACf;EACA;EACA;EACA;;;KAIU,aAAa,aAAa,eAAe;;UAOpC;EACf;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;IACE;IACA;IACA;;;;UAKa;EACf;EACA;EACA;;;KAIU,yBACR,YACA,aACA,qBACA;;UAGa;EACf;EACA;EACA;EACA,kBAAkB;EAClB;;;;;;;;UASe;EACf;EACA;;;KAIU,wBACR,YACA,gBACA,eACA;;KAGQ,mBAAmB,YAAY,kBAAkB;;UAO5C;EACf;EACA;EACA;EACA;EACA,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA,kBAAkB;;;;;;;;UCpZH,SAAS;WACf;WACA;WACA,OAAO;EAChB,IAAI,GAAG,KAAK,OAAO,MAAM,IAAI,SAAS;EAE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