codebuff 1.0.176 → 1.0.177
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/dist/checkpoints/checkpoint-manager.d.ts +73 -0
- package/dist/checkpoints/checkpoint-manager.js +193 -0
- package/dist/checkpoints/checkpoint-manager.js.map +1 -0
- package/dist/{checkpoint-file-manager.d.ts → checkpoints/file-manager.d.ts} +10 -0
- package/dist/{checkpoint-file-manager.js → checkpoints/file-manager.js} +92 -35
- package/dist/checkpoints/file-manager.js.map +1 -0
- package/dist/cli.js +20 -18
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +7 -6
- package/dist/client.js +20 -15
- package/dist/client.js.map +1 -1
- package/dist/common/actions.d.ts +120 -120
- package/dist/common/advanced-analyzer.d.ts +19 -0
- package/dist/common/advanced-analyzer.js +140 -0
- package/dist/common/advanced-analyzer.js.map +1 -0
- package/dist/common/browser-actions.d.ts +44 -44
- package/dist/common/message-image-handling.d.ts +41 -0
- package/dist/common/message-image-handling.js +57 -0
- package/dist/common/message-image-handling.js.map +1 -0
- package/dist/common/types/agent-state.d.ts +26 -26
- package/dist/common/types/message.d.ts +14 -14
- package/dist/common/types/usage.d.ts +2 -2
- package/dist/common/util/credentials.d.ts +2 -2
- package/dist/common/util/process-stream.d.ts +8 -0
- package/dist/common/util/process-stream.js +102 -0
- package/dist/common/util/process-stream.js.map +1 -0
- package/dist/common/websockets/websocket-schema.d.ts +368 -368
- package/dist/index.js +1 -1
- package/dist/menu.js +1 -1
- package/dist/menu.js.map +1 -1
- package/dist/project-files.js +2 -2
- package/dist/project-files.js.map +1 -1
- package/dist/workers/checkpoint-worker.js +47 -0
- package/dist/workers/checkpoint-worker.js.map +1 -0
- package/dist/workers/project-context.d.ts +1 -0
- package/dist/{worker-script-project-context.js → workers/project-context.js} +5 -5
- package/dist/workers/project-context.js.map +1 -0
- package/package.json +1 -1
- package/dist/checkpoint-file-manager.js.map +0 -1
- package/dist/checkpoints.d.ts +0 -64
- package/dist/checkpoints.js +0 -162
- package/dist/checkpoints.js.map +0 -1
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +0 -7
- package/dist/common/logger.js.map +0 -1
- package/dist/common/util/constants.d.ts +0 -1
- package/dist/common/util/constants.js +0 -7
- package/dist/common/util/constants.js.map +0 -1
- package/dist/common/util/helpers.d.ts +0 -1
- package/dist/common/util/helpers.js +0 -6
- package/dist/common/util/helpers.js.map +0 -1
- package/dist/common/util/token-counter.d.ts +0 -3
- package/dist/common/util/token-counter.js +0 -27
- package/dist/common/util/token-counter.js.map +0 -1
- package/dist/worker-script-project-context.js.map +0 -1
- /package/dist/{worker-script-project-context.d.ts → workers/checkpoint-worker.d.ts} +0 -0
|
@@ -5,12 +5,12 @@ export declare const ToolCallSchema: z.ZodObject<{
|
|
|
5
5
|
parameters: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
6
6
|
id: z.ZodString;
|
|
7
7
|
}, "strip", z.ZodTypeAny, {
|
|
8
|
-
name: string;
|
|
9
8
|
id: string;
|
|
9
|
+
name: string;
|
|
10
10
|
parameters: Record<string, string>;
|
|
11
11
|
}, {
|
|
12
|
-
name: string;
|
|
13
12
|
id: string;
|
|
13
|
+
name: string;
|
|
14
14
|
parameters: Record<string, string>;
|
|
15
15
|
}>;
|
|
16
16
|
export type ToolCall = z.infer<typeof ToolCallSchema>;
|
|
@@ -19,12 +19,12 @@ export declare const ToolResultSchema: z.ZodObject<{
|
|
|
19
19
|
result: z.ZodString;
|
|
20
20
|
id: z.ZodString;
|
|
21
21
|
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
name: string;
|
|
23
22
|
id: string;
|
|
23
|
+
name: string;
|
|
24
24
|
result: string;
|
|
25
25
|
}, {
|
|
26
|
-
name: string;
|
|
27
26
|
id: string;
|
|
27
|
+
name: string;
|
|
28
28
|
result: string;
|
|
29
29
|
}>;
|
|
30
30
|
export type ToolResult = z.infer<typeof ToolResultSchema>;
|
|
@@ -42,13 +42,13 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
42
42
|
diffCached: z.ZodString;
|
|
43
43
|
lastCommitMessages: z.ZodString;
|
|
44
44
|
}, "strip", z.ZodTypeAny, {
|
|
45
|
-
status: string;
|
|
46
45
|
diff: string;
|
|
46
|
+
status: string;
|
|
47
47
|
diffCached: string;
|
|
48
48
|
lastCommitMessages: string;
|
|
49
49
|
}, {
|
|
50
|
-
status: string;
|
|
51
50
|
diff: string;
|
|
51
|
+
status: string;
|
|
52
52
|
diffCached: string;
|
|
53
53
|
lastCommitMessages: string;
|
|
54
54
|
}>;
|
|
@@ -92,8 +92,8 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
92
92
|
fileTokenScores: Record<string, Record<string, number>>;
|
|
93
93
|
knowledgeFiles: Record<string, string>;
|
|
94
94
|
gitChanges: {
|
|
95
|
-
status: string;
|
|
96
95
|
diff: string;
|
|
96
|
+
status: string;
|
|
97
97
|
diffCached: string;
|
|
98
98
|
lastCommitMessages: string;
|
|
99
99
|
};
|
|
@@ -118,8 +118,8 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
118
118
|
fileTokenScores: Record<string, Record<string, number>>;
|
|
119
119
|
knowledgeFiles: Record<string, string>;
|
|
120
120
|
gitChanges: {
|
|
121
|
-
status: string;
|
|
122
121
|
diff: string;
|
|
122
|
+
status: string;
|
|
123
123
|
diffCached: string;
|
|
124
124
|
lastCommitMessages: string;
|
|
125
125
|
};
|
|
@@ -177,16 +177,16 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
177
177
|
}>>;
|
|
178
178
|
}, "strip", z.ZodTypeAny, {
|
|
179
179
|
type: "tool_use";
|
|
180
|
-
name: string;
|
|
181
180
|
id: string;
|
|
181
|
+
name: string;
|
|
182
182
|
input: Record<string, any>;
|
|
183
183
|
cache_control?: {
|
|
184
184
|
type: "ephemeral";
|
|
185
185
|
} | undefined;
|
|
186
186
|
}, {
|
|
187
187
|
type: "tool_use";
|
|
188
|
-
name: string;
|
|
189
188
|
id: string;
|
|
189
|
+
name: string;
|
|
190
190
|
input: Record<string, any>;
|
|
191
191
|
cache_control?: {
|
|
192
192
|
type: "ephemeral";
|
|
@@ -203,15 +203,15 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
203
203
|
type: "ephemeral";
|
|
204
204
|
}>>;
|
|
205
205
|
}, "strip", z.ZodTypeAny, {
|
|
206
|
-
content: string;
|
|
207
206
|
type: "tool_result";
|
|
207
|
+
content: string;
|
|
208
208
|
tool_use_id: string;
|
|
209
209
|
cache_control?: {
|
|
210
210
|
type: "ephemeral";
|
|
211
211
|
} | undefined;
|
|
212
212
|
}, {
|
|
213
|
-
content: string;
|
|
214
213
|
type: "tool_result";
|
|
214
|
+
content: string;
|
|
215
215
|
tool_use_id: string;
|
|
216
216
|
cache_control?: {
|
|
217
217
|
type: "ephemeral";
|
|
@@ -260,6 +260,7 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
260
260
|
} | undefined;
|
|
261
261
|
}>]>, "many">]>;
|
|
262
262
|
}, "strip", z.ZodTypeAny, {
|
|
263
|
+
role: "user" | "assistant";
|
|
263
264
|
content: string | ({
|
|
264
265
|
type: "text";
|
|
265
266
|
text: string;
|
|
@@ -268,15 +269,15 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
268
269
|
} | undefined;
|
|
269
270
|
} | {
|
|
270
271
|
type: "tool_use";
|
|
271
|
-
name: string;
|
|
272
272
|
id: string;
|
|
273
|
+
name: string;
|
|
273
274
|
input: Record<string, any>;
|
|
274
275
|
cache_control?: {
|
|
275
276
|
type: "ephemeral";
|
|
276
277
|
} | undefined;
|
|
277
278
|
} | {
|
|
278
|
-
content: string;
|
|
279
279
|
type: "tool_result";
|
|
280
|
+
content: string;
|
|
280
281
|
tool_use_id: string;
|
|
281
282
|
cache_control?: {
|
|
282
283
|
type: "ephemeral";
|
|
@@ -292,8 +293,8 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
292
293
|
type: "ephemeral";
|
|
293
294
|
} | undefined;
|
|
294
295
|
})[];
|
|
295
|
-
role: "user" | "assistant";
|
|
296
296
|
}, {
|
|
297
|
+
role: "user" | "assistant";
|
|
297
298
|
content: string | ({
|
|
298
299
|
type: "text";
|
|
299
300
|
text: string;
|
|
@@ -302,15 +303,15 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
302
303
|
} | undefined;
|
|
303
304
|
} | {
|
|
304
305
|
type: "tool_use";
|
|
305
|
-
name: string;
|
|
306
306
|
id: string;
|
|
307
|
+
name: string;
|
|
307
308
|
input: Record<string, any>;
|
|
308
309
|
cache_control?: {
|
|
309
310
|
type: "ephemeral";
|
|
310
311
|
} | undefined;
|
|
311
312
|
} | {
|
|
312
|
-
content: string;
|
|
313
313
|
type: "tool_result";
|
|
314
|
+
content: string;
|
|
314
315
|
tool_use_id: string;
|
|
315
316
|
cache_control?: {
|
|
316
317
|
type: "ephemeral";
|
|
@@ -326,7 +327,6 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
326
327
|
type: "ephemeral";
|
|
327
328
|
} | undefined;
|
|
328
329
|
})[];
|
|
329
|
-
role: "user" | "assistant";
|
|
330
330
|
}>, "many">;
|
|
331
331
|
}, "strip", z.ZodTypeAny, {
|
|
332
332
|
agentContext: string;
|
|
@@ -336,8 +336,8 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
336
336
|
fileTokenScores: Record<string, Record<string, number>>;
|
|
337
337
|
knowledgeFiles: Record<string, string>;
|
|
338
338
|
gitChanges: {
|
|
339
|
-
status: string;
|
|
340
339
|
diff: string;
|
|
340
|
+
status: string;
|
|
341
341
|
diffCached: string;
|
|
342
342
|
lastCommitMessages: string;
|
|
343
343
|
};
|
|
@@ -358,6 +358,7 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
358
358
|
userKnowledgeFiles?: Record<string, string> | undefined;
|
|
359
359
|
};
|
|
360
360
|
messageHistory: {
|
|
361
|
+
role: "user" | "assistant";
|
|
361
362
|
content: string | ({
|
|
362
363
|
type: "text";
|
|
363
364
|
text: string;
|
|
@@ -366,15 +367,15 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
366
367
|
} | undefined;
|
|
367
368
|
} | {
|
|
368
369
|
type: "tool_use";
|
|
369
|
-
name: string;
|
|
370
370
|
id: string;
|
|
371
|
+
name: string;
|
|
371
372
|
input: Record<string, any>;
|
|
372
373
|
cache_control?: {
|
|
373
374
|
type: "ephemeral";
|
|
374
375
|
} | undefined;
|
|
375
376
|
} | {
|
|
376
|
-
content: string;
|
|
377
377
|
type: "tool_result";
|
|
378
|
+
content: string;
|
|
378
379
|
tool_use_id: string;
|
|
379
380
|
cache_control?: {
|
|
380
381
|
type: "ephemeral";
|
|
@@ -390,7 +391,6 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
390
391
|
type: "ephemeral";
|
|
391
392
|
} | undefined;
|
|
392
393
|
})[];
|
|
393
|
-
role: "user" | "assistant";
|
|
394
394
|
}[];
|
|
395
395
|
}, {
|
|
396
396
|
agentContext: string;
|
|
@@ -400,8 +400,8 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
400
400
|
fileTokenScores: Record<string, Record<string, number>>;
|
|
401
401
|
knowledgeFiles: Record<string, string>;
|
|
402
402
|
gitChanges: {
|
|
403
|
-
status: string;
|
|
404
403
|
diff: string;
|
|
404
|
+
status: string;
|
|
405
405
|
diffCached: string;
|
|
406
406
|
lastCommitMessages: string;
|
|
407
407
|
};
|
|
@@ -422,6 +422,7 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
422
422
|
userKnowledgeFiles?: Record<string, string> | undefined;
|
|
423
423
|
};
|
|
424
424
|
messageHistory: {
|
|
425
|
+
role: "user" | "assistant";
|
|
425
426
|
content: string | ({
|
|
426
427
|
type: "text";
|
|
427
428
|
text: string;
|
|
@@ -430,15 +431,15 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
430
431
|
} | undefined;
|
|
431
432
|
} | {
|
|
432
433
|
type: "tool_use";
|
|
433
|
-
name: string;
|
|
434
434
|
id: string;
|
|
435
|
+
name: string;
|
|
435
436
|
input: Record<string, any>;
|
|
436
437
|
cache_control?: {
|
|
437
438
|
type: "ephemeral";
|
|
438
439
|
} | undefined;
|
|
439
440
|
} | {
|
|
440
|
-
content: string;
|
|
441
441
|
type: "tool_result";
|
|
442
|
+
content: string;
|
|
442
443
|
tool_use_id: string;
|
|
443
444
|
cache_control?: {
|
|
444
445
|
type: "ephemeral";
|
|
@@ -454,7 +455,6 @@ export declare const AgentStateSchema: z.ZodObject<{
|
|
|
454
455
|
type: "ephemeral";
|
|
455
456
|
} | undefined;
|
|
456
457
|
})[];
|
|
457
|
-
role: "user" | "assistant";
|
|
458
458
|
}[];
|
|
459
459
|
}>;
|
|
460
460
|
export type AgentState = z.infer<typeof AgentStateSchema>;
|
|
@@ -35,16 +35,16 @@ declare const MessageContentObjectSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
35
35
|
}>>;
|
|
36
36
|
}, "strip", z.ZodTypeAny, {
|
|
37
37
|
type: "tool_use";
|
|
38
|
-
name: string;
|
|
39
38
|
id: string;
|
|
39
|
+
name: string;
|
|
40
40
|
input: Record<string, any>;
|
|
41
41
|
cache_control?: {
|
|
42
42
|
type: "ephemeral";
|
|
43
43
|
} | undefined;
|
|
44
44
|
}, {
|
|
45
45
|
type: "tool_use";
|
|
46
|
-
name: string;
|
|
47
46
|
id: string;
|
|
47
|
+
name: string;
|
|
48
48
|
input: Record<string, any>;
|
|
49
49
|
cache_control?: {
|
|
50
50
|
type: "ephemeral";
|
|
@@ -61,15 +61,15 @@ declare const MessageContentObjectSchema: z.ZodUnion<[z.ZodObject<{
|
|
|
61
61
|
type: "ephemeral";
|
|
62
62
|
}>>;
|
|
63
63
|
}, "strip", z.ZodTypeAny, {
|
|
64
|
-
content: string;
|
|
65
64
|
type: "tool_result";
|
|
65
|
+
content: string;
|
|
66
66
|
tool_use_id: string;
|
|
67
67
|
cache_control?: {
|
|
68
68
|
type: "ephemeral";
|
|
69
69
|
} | undefined;
|
|
70
70
|
}, {
|
|
71
|
-
content: string;
|
|
72
71
|
type: "tool_result";
|
|
72
|
+
content: string;
|
|
73
73
|
tool_use_id: string;
|
|
74
74
|
cache_control?: {
|
|
75
75
|
type: "ephemeral";
|
|
@@ -155,16 +155,16 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
155
155
|
}>>;
|
|
156
156
|
}, "strip", z.ZodTypeAny, {
|
|
157
157
|
type: "tool_use";
|
|
158
|
-
name: string;
|
|
159
158
|
id: string;
|
|
159
|
+
name: string;
|
|
160
160
|
input: Record<string, any>;
|
|
161
161
|
cache_control?: {
|
|
162
162
|
type: "ephemeral";
|
|
163
163
|
} | undefined;
|
|
164
164
|
}, {
|
|
165
165
|
type: "tool_use";
|
|
166
|
-
name: string;
|
|
167
166
|
id: string;
|
|
167
|
+
name: string;
|
|
168
168
|
input: Record<string, any>;
|
|
169
169
|
cache_control?: {
|
|
170
170
|
type: "ephemeral";
|
|
@@ -181,15 +181,15 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
181
181
|
type: "ephemeral";
|
|
182
182
|
}>>;
|
|
183
183
|
}, "strip", z.ZodTypeAny, {
|
|
184
|
-
content: string;
|
|
185
184
|
type: "tool_result";
|
|
185
|
+
content: string;
|
|
186
186
|
tool_use_id: string;
|
|
187
187
|
cache_control?: {
|
|
188
188
|
type: "ephemeral";
|
|
189
189
|
} | undefined;
|
|
190
190
|
}, {
|
|
191
|
-
content: string;
|
|
192
191
|
type: "tool_result";
|
|
192
|
+
content: string;
|
|
193
193
|
tool_use_id: string;
|
|
194
194
|
cache_control?: {
|
|
195
195
|
type: "ephemeral";
|
|
@@ -238,6 +238,7 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
238
238
|
} | undefined;
|
|
239
239
|
}>]>, "many">]>;
|
|
240
240
|
}, "strip", z.ZodTypeAny, {
|
|
241
|
+
role: "user" | "assistant";
|
|
241
242
|
content: string | ({
|
|
242
243
|
type: "text";
|
|
243
244
|
text: string;
|
|
@@ -246,15 +247,15 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
246
247
|
} | undefined;
|
|
247
248
|
} | {
|
|
248
249
|
type: "tool_use";
|
|
249
|
-
name: string;
|
|
250
250
|
id: string;
|
|
251
|
+
name: string;
|
|
251
252
|
input: Record<string, any>;
|
|
252
253
|
cache_control?: {
|
|
253
254
|
type: "ephemeral";
|
|
254
255
|
} | undefined;
|
|
255
256
|
} | {
|
|
256
|
-
content: string;
|
|
257
257
|
type: "tool_result";
|
|
258
|
+
content: string;
|
|
258
259
|
tool_use_id: string;
|
|
259
260
|
cache_control?: {
|
|
260
261
|
type: "ephemeral";
|
|
@@ -270,8 +271,8 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
270
271
|
type: "ephemeral";
|
|
271
272
|
} | undefined;
|
|
272
273
|
})[];
|
|
273
|
-
role: "user" | "assistant";
|
|
274
274
|
}, {
|
|
275
|
+
role: "user" | "assistant";
|
|
275
276
|
content: string | ({
|
|
276
277
|
type: "text";
|
|
277
278
|
text: string;
|
|
@@ -280,15 +281,15 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
280
281
|
} | undefined;
|
|
281
282
|
} | {
|
|
282
283
|
type: "tool_use";
|
|
283
|
-
name: string;
|
|
284
284
|
id: string;
|
|
285
|
+
name: string;
|
|
285
286
|
input: Record<string, any>;
|
|
286
287
|
cache_control?: {
|
|
287
288
|
type: "ephemeral";
|
|
288
289
|
} | undefined;
|
|
289
290
|
} | {
|
|
290
|
-
content: string;
|
|
291
291
|
type: "tool_result";
|
|
292
|
+
content: string;
|
|
292
293
|
tool_use_id: string;
|
|
293
294
|
cache_control?: {
|
|
294
295
|
type: "ephemeral";
|
|
@@ -304,7 +305,6 @@ export declare const MessageSchema: z.ZodObject<{
|
|
|
304
305
|
type: "ephemeral";
|
|
305
306
|
} | undefined;
|
|
306
307
|
})[];
|
|
307
|
-
role: "user" | "assistant";
|
|
308
308
|
}>;
|
|
309
309
|
export type Message = z.infer<typeof MessageSchema>;
|
|
310
310
|
export type MessageContentObject = z.infer<typeof MessageContentObjectSchema>;
|
|
@@ -8,17 +8,17 @@ export declare const usageDataSchema: z.ZodObject<{
|
|
|
8
8
|
overageRate: z.ZodNullable<z.ZodNumber>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
creditsUsed: number;
|
|
11
|
+
overageRate: number | null;
|
|
11
12
|
totalQuota: number;
|
|
12
13
|
remainingCredits: number;
|
|
13
14
|
subscriptionActive: boolean;
|
|
14
15
|
nextQuotaReset: Date;
|
|
15
|
-
overageRate: number | null;
|
|
16
16
|
}, {
|
|
17
17
|
creditsUsed: number;
|
|
18
|
+
overageRate: number | null;
|
|
18
19
|
totalQuota: number;
|
|
19
20
|
remainingCredits: number;
|
|
20
21
|
subscriptionActive: boolean;
|
|
21
22
|
nextQuotaReset: Date;
|
|
22
|
-
overageRate: number | null;
|
|
23
23
|
}>;
|
|
24
24
|
export type UsageData = z.infer<typeof usageDataSchema>;
|
|
@@ -7,15 +7,15 @@ export declare const userSchema: z.ZodObject<{
|
|
|
7
7
|
fingerprintId: z.ZodString;
|
|
8
8
|
fingerprintHash: z.ZodString;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
email: string;
|
|
11
10
|
name: string | null;
|
|
11
|
+
email: string;
|
|
12
12
|
id: string;
|
|
13
13
|
fingerprintId: string;
|
|
14
14
|
authToken: string;
|
|
15
15
|
fingerprintHash: string;
|
|
16
16
|
}, {
|
|
17
|
-
email: string;
|
|
18
17
|
name: string | null;
|
|
18
|
+
email: string;
|
|
19
19
|
id: string;
|
|
20
20
|
fingerprintId: string;
|
|
21
21
|
authToken: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function processStreamWithTags<T extends string>(stream: AsyncGenerator<T> | ReadableStream<T>, tags: {
|
|
2
|
+
[tagName: string]: {
|
|
3
|
+
attributeNames: string[];
|
|
4
|
+
onTagStart: (attributes: Record<string, string>) => void;
|
|
5
|
+
onTagEnd: (content: string, attributes: Record<string, string>) => boolean;
|
|
6
|
+
};
|
|
7
|
+
}): AsyncGenerator<string, void, unknown>;
|
|
8
|
+
export declare function parseAttributes(attributesString: string, attributeNames: string[]): Record<string, string>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processStreamWithTags = processStreamWithTags;
|
|
4
|
+
exports.parseAttributes = parseAttributes;
|
|
5
|
+
async function* processStreamWithTags(stream, tags) {
|
|
6
|
+
let buffer = '';
|
|
7
|
+
let insideTag = null;
|
|
8
|
+
let currentAttributes = {};
|
|
9
|
+
let streamCompleted = false;
|
|
10
|
+
const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
|
+
const tagNames = Object.keys(tags);
|
|
12
|
+
const openTagRegex = new RegExp(`<(${tagNames.map(escapeRegExp).join('|')})\\s*([^>]*)>`);
|
|
13
|
+
const closeTagRegex = new RegExp(`</(${tagNames.map(escapeRegExp).join('|')})>`);
|
|
14
|
+
function* parseBuffer(chunk) {
|
|
15
|
+
const isEOF = chunk === undefined;
|
|
16
|
+
if (chunk) {
|
|
17
|
+
yield chunk;
|
|
18
|
+
}
|
|
19
|
+
let didParse = true;
|
|
20
|
+
while (!streamCompleted && didParse) {
|
|
21
|
+
didParse = false;
|
|
22
|
+
if (insideTag === null) {
|
|
23
|
+
// Outside a tag: try to find the next opening tag
|
|
24
|
+
const openMatch = buffer.match(openTagRegex);
|
|
25
|
+
if (openMatch && openMatch.index !== undefined) {
|
|
26
|
+
const [fullMatch, openTag, attributesString] = openMatch;
|
|
27
|
+
const beforeTag = buffer.slice(0, openMatch.index);
|
|
28
|
+
const afterMatchIndex = openMatch.index + fullMatch.length;
|
|
29
|
+
// Move buffer forward
|
|
30
|
+
buffer = buffer.slice(afterMatchIndex);
|
|
31
|
+
// We are now inside this tag
|
|
32
|
+
insideTag = openTag;
|
|
33
|
+
currentAttributes = parseAttributes(attributesString, tags[openTag].attributeNames);
|
|
34
|
+
// Call onTagStart
|
|
35
|
+
tags[openTag].onTagStart(currentAttributes);
|
|
36
|
+
didParse = true;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// No opening tag found. If it's EOF, yield remaining text.
|
|
40
|
+
if (isEOF && buffer.length > 0) {
|
|
41
|
+
buffer = '';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Inside a tag: try to find the closing tag
|
|
47
|
+
const closeMatch = buffer.match(closeTagRegex);
|
|
48
|
+
if (closeMatch && closeMatch.index !== undefined) {
|
|
49
|
+
const [fullMatch, closeTag] = closeMatch;
|
|
50
|
+
const content = buffer.slice(0, closeMatch.index);
|
|
51
|
+
// Move buffer forward
|
|
52
|
+
buffer = buffer.slice(closeMatch.index + fullMatch.length);
|
|
53
|
+
// Close the tag
|
|
54
|
+
const complete = tags[insideTag].onTagEnd(content, currentAttributes);
|
|
55
|
+
insideTag = null;
|
|
56
|
+
currentAttributes = {};
|
|
57
|
+
if (complete) {
|
|
58
|
+
// If onTagEnd signals completion, set streamCompleted and return
|
|
59
|
+
streamCompleted = true;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
didParse = true;
|
|
63
|
+
}
|
|
64
|
+
else if (isEOF) {
|
|
65
|
+
// We reached EOF without finding a closing tag
|
|
66
|
+
// Treat remaining buffer as content and close the tag
|
|
67
|
+
if (buffer.length > 0) {
|
|
68
|
+
const complete = tags[insideTag].onTagEnd(buffer, currentAttributes);
|
|
69
|
+
yield '</' + insideTag + '>';
|
|
70
|
+
buffer = '';
|
|
71
|
+
insideTag = null;
|
|
72
|
+
currentAttributes = {};
|
|
73
|
+
if (complete) {
|
|
74
|
+
streamCompleted = true;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for await (const chunk of stream) {
|
|
83
|
+
if (streamCompleted)
|
|
84
|
+
continue;
|
|
85
|
+
buffer += chunk;
|
|
86
|
+
yield* parseBuffer(chunk);
|
|
87
|
+
}
|
|
88
|
+
if (!streamCompleted) {
|
|
89
|
+
// After the stream ends, try parsing one last time in case there's leftover text
|
|
90
|
+
yield* parseBuffer(undefined);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function parseAttributes(attributesString, attributeNames) {
|
|
94
|
+
const attributes = {};
|
|
95
|
+
const regex = new RegExp(`(${attributeNames.join('|')})="([^"]*)"`, 'g');
|
|
96
|
+
let match;
|
|
97
|
+
while ((match = regex.exec(attributesString)) !== null) {
|
|
98
|
+
attributes[match[1]] = match[2];
|
|
99
|
+
}
|
|
100
|
+
return attributes;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=process-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-stream.js","sourceRoot":"","sources":["../../src/util/process-stream.ts"],"names":[],"mappings":";;AAAA,sDAoHC;AAED,0CAWC;AAjIM,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC1C,MAA6C,EAC7C,IAMC;IAED,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,SAAS,GAAkB,IAAI,CAAA;IACnC,IAAI,iBAAiB,GAA2B,EAAE,CAAA;IAClD,IAAI,eAAe,GAAG,KAAK,CAAA;IAE3B,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,EAAE,CACtC,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClC,MAAM,YAAY,GAAG,IAAI,MAAM,CAC7B,KAAK,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,C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