@dexto/core 1.5.2 → 1.5.4
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/agent/DextoAgent.cjs +296 -2
- package/dist/agent/DextoAgent.d.ts +114 -0
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +287 -2
- package/dist/agent/schemas.d.ts +93 -21
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/approval/manager.cjs +16 -0
- package/dist/approval/manager.d.ts +10 -0
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +16 -0
- package/dist/approval/types.d.ts +11 -0
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/context/compaction/overflow.cjs +6 -10
- package/dist/context/compaction/overflow.d.ts +14 -11
- package/dist/context/compaction/overflow.d.ts.map +1 -1
- package/dist/context/compaction/overflow.js +6 -10
- package/dist/context/compaction/providers/reactive-overflow-provider.cjs +15 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts +15 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts.map +1 -1
- package/dist/context/compaction/providers/reactive-overflow-provider.js +15 -0
- package/dist/context/compaction/schemas.cjs +22 -2
- package/dist/context/compaction/schemas.d.ts +45 -0
- package/dist/context/compaction/schemas.d.ts.map +1 -1
- package/dist/context/compaction/schemas.js +22 -2
- package/dist/context/compaction/strategies/reactive-overflow.cjs +166 -26
- package/dist/context/compaction/strategies/reactive-overflow.d.ts +21 -0
- package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -1
- package/dist/context/compaction/strategies/reactive-overflow.js +166 -26
- package/dist/context/manager.cjs +278 -31
- package/dist/context/manager.d.ts +192 -5
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +285 -32
- package/dist/context/types.d.ts +6 -0
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/utils.cjs +77 -11
- package/dist/context/utils.d.ts +86 -8
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +71 -11
- package/dist/events/index.cjs +7 -1
- package/dist/events/index.d.ts +58 -7
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +7 -1
- package/dist/filesystem/filesystem-service.cjs +18 -15
- package/dist/filesystem/filesystem-service.d.ts +3 -3
- package/dist/filesystem/filesystem-service.d.ts.map +1 -1
- package/dist/filesystem/filesystem-service.js +18 -15
- package/dist/filesystem/path-validator.cjs +16 -7
- package/dist/filesystem/path-validator.d.ts +10 -3
- package/dist/filesystem/path-validator.d.ts.map +1 -1
- package/dist/filesystem/path-validator.js +16 -7
- package/dist/filesystem/types.d.ts +4 -0
- package/dist/filesystem/types.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.cjs +19 -1
- package/dist/llm/executor/stream-processor.d.ts +3 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +19 -1
- package/dist/llm/executor/turn-executor.cjs +219 -30
- package/dist/llm/executor/turn-executor.d.ts +62 -10
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +219 -30
- package/dist/llm/executor/types.d.ts +28 -0
- package/dist/llm/executor/types.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.cjs +36 -28
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +36 -28
- package/dist/llm/services/factory.cjs +3 -2
- package/dist/llm/services/factory.d.ts +3 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +3 -2
- package/dist/llm/services/vercel.cjs +34 -6
- package/dist/llm/services/vercel.d.ts +23 -3
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +34 -6
- package/dist/logger/v2/schemas.cjs +4 -0
- package/dist/logger/v2/schemas.d.ts +16 -0
- package/dist/logger/v2/schemas.d.ts.map +1 -1
- package/dist/logger/v2/schemas.js +4 -0
- package/dist/logger/v2/transport-factory.cjs +4 -1
- package/dist/logger/v2/transport-factory.d.ts.map +1 -1
- package/dist/logger/v2/transport-factory.js +4 -1
- package/dist/logger/v2/transports/silent-transport.cjs +33 -0
- package/dist/logger/v2/transports/silent-transport.d.ts +15 -0
- package/dist/logger/v2/transports/silent-transport.d.ts.map +1 -0
- package/dist/logger/v2/transports/silent-transport.js +10 -0
- package/dist/session/chat-session.cjs +20 -11
- package/dist/session/chat-session.d.ts +9 -4
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +20 -11
- package/dist/session/compaction-service.cjs +139 -0
- package/dist/session/compaction-service.d.ts +81 -0
- package/dist/session/compaction-service.d.ts.map +1 -0
- package/dist/session/compaction-service.js +106 -0
- package/dist/session/session-manager.cjs +146 -0
- package/dist/session/session-manager.d.ts +50 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +146 -0
- package/dist/session/title-generator.cjs +2 -2
- package/dist/session/title-generator.js +2 -2
- package/dist/systemPrompt/in-built-prompts.cjs +36 -0
- package/dist/systemPrompt/in-built-prompts.d.ts +18 -1
- package/dist/systemPrompt/in-built-prompts.d.ts.map +1 -1
- package/dist/systemPrompt/in-built-prompts.js +25 -0
- package/dist/systemPrompt/manager.cjs +22 -0
- package/dist/systemPrompt/manager.d.ts +10 -0
- package/dist/systemPrompt/manager.d.ts.map +1 -1
- package/dist/systemPrompt/manager.js +22 -0
- package/dist/systemPrompt/registry.cjs +2 -1
- package/dist/systemPrompt/registry.d.ts +1 -1
- package/dist/systemPrompt/registry.d.ts.map +1 -1
- package/dist/systemPrompt/registry.js +2 -1
- package/dist/systemPrompt/schemas.cjs +7 -0
- package/dist/systemPrompt/schemas.d.ts +13 -13
- package/dist/systemPrompt/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.js +7 -0
- package/dist/tools/error-codes.cjs +1 -0
- package/dist/tools/error-codes.d.ts +1 -0
- package/dist/tools/error-codes.d.ts.map +1 -1
- package/dist/tools/error-codes.js +1 -0
- package/dist/tools/errors.cjs +17 -0
- package/dist/tools/errors.d.ts +9 -0
- package/dist/tools/errors.d.ts.map +1 -1
- package/dist/tools/errors.js +17 -0
- package/dist/tools/internal-tools/provider.cjs +3 -2
- package/dist/tools/internal-tools/provider.d.ts +1 -1
- package/dist/tools/internal-tools/provider.d.ts.map +1 -1
- package/dist/tools/internal-tools/provider.js +3 -2
- package/dist/tools/tool-manager.cjs +77 -4
- package/dist/tools/tool-manager.d.ts +18 -0
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +78 -5
- package/dist/tools/types.d.ts +5 -3
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/index.cjs +3 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -53,7 +53,7 @@ class FileSystemService {
|
|
|
53
53
|
blockedPaths: config.blockedPaths || [".git", "node_modules/.bin", ".env"],
|
|
54
54
|
blockedExtensions: config.blockedExtensions || [".exe", ".dll", ".so"],
|
|
55
55
|
maxFileSize: config.maxFileSize || DEFAULT_MAX_FILE_SIZE,
|
|
56
|
-
enableBackups: config.enableBackups ??
|
|
56
|
+
enableBackups: config.enableBackups ?? false,
|
|
57
57
|
backupPath: config.backupPath,
|
|
58
58
|
// Optional absolute override, defaults handled by getBackupDir()
|
|
59
59
|
backupRetentionDays: config.backupRetentionDays || 7,
|
|
@@ -99,7 +99,7 @@ class FileSystemService {
|
|
|
99
99
|
* @param filePath The file path to check (can be relative or absolute)
|
|
100
100
|
* @returns true if the path is within allowed paths, false otherwise
|
|
101
101
|
*/
|
|
102
|
-
isPathWithinAllowed(filePath) {
|
|
102
|
+
async isPathWithinAllowed(filePath) {
|
|
103
103
|
return this.pathValidator.isPathWithinAllowed(filePath);
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
@@ -137,7 +137,7 @@ class FileSystemService {
|
|
|
137
137
|
if (!this.initialized) {
|
|
138
138
|
throw import_errors.FileSystemError.notInitialized();
|
|
139
139
|
}
|
|
140
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
140
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
141
141
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
142
142
|
throw import_errors.FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
143
143
|
}
|
|
@@ -216,7 +216,7 @@ class FileSystemService {
|
|
|
216
216
|
});
|
|
217
217
|
const validFiles = [];
|
|
218
218
|
for (const file of files) {
|
|
219
|
-
const validation = this.pathValidator.validatePath(file);
|
|
219
|
+
const validation = await this.pathValidator.validatePath(file);
|
|
220
220
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
221
221
|
this.logger.debug(`Skipping invalid path: ${file}`);
|
|
222
222
|
continue;
|
|
@@ -347,7 +347,7 @@ class FileSystemService {
|
|
|
347
347
|
if (!this.initialized) {
|
|
348
348
|
throw import_errors.FileSystemError.notInitialized();
|
|
349
349
|
}
|
|
350
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
350
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
351
351
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
352
352
|
throw import_errors.FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
353
353
|
}
|
|
@@ -391,14 +391,14 @@ class FileSystemService {
|
|
|
391
391
|
if (!this.initialized) {
|
|
392
392
|
throw import_errors.FileSystemError.notInitialized();
|
|
393
393
|
}
|
|
394
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
394
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
395
395
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
396
396
|
throw import_errors.FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
397
397
|
}
|
|
398
398
|
const normalizedPath = validation.normalizedPath;
|
|
399
399
|
const fileContent = await this.readFile(normalizedPath);
|
|
400
|
-
|
|
401
|
-
const occurrences = (
|
|
400
|
+
const originalContent = fileContent.content;
|
|
401
|
+
const occurrences = (originalContent.match(
|
|
402
402
|
new RegExp(operation.oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g")
|
|
403
403
|
) || []).length;
|
|
404
404
|
if (occurrences === 0) {
|
|
@@ -412,21 +412,24 @@ class FileSystemService {
|
|
|
412
412
|
backupPath = await this.createBackup(normalizedPath);
|
|
413
413
|
}
|
|
414
414
|
try {
|
|
415
|
+
let newContent;
|
|
415
416
|
if (operation.replaceAll) {
|
|
416
|
-
|
|
417
|
+
newContent = originalContent.replace(
|
|
417
418
|
new RegExp(operation.oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
|
|
418
419
|
operation.newString
|
|
419
420
|
);
|
|
420
421
|
} else {
|
|
421
|
-
|
|
422
|
+
newContent = originalContent.replace(operation.oldString, operation.newString);
|
|
422
423
|
}
|
|
423
|
-
await fs.writeFile(normalizedPath,
|
|
424
|
+
await fs.writeFile(normalizedPath, newContent, options.encoding || DEFAULT_ENCODING);
|
|
424
425
|
this.logger.debug(`File edited: ${normalizedPath} (${occurrences} replacements)`);
|
|
425
426
|
return {
|
|
426
427
|
success: true,
|
|
427
428
|
path: normalizedPath,
|
|
428
429
|
changesCount: occurrences,
|
|
429
|
-
backupPath
|
|
430
|
+
backupPath,
|
|
431
|
+
originalContent,
|
|
432
|
+
newContent
|
|
430
433
|
};
|
|
431
434
|
} catch (error) {
|
|
432
435
|
throw import_errors.FileSystemError.editFailed(
|
|
@@ -518,10 +521,10 @@ class FileSystemService {
|
|
|
518
521
|
return { ...this.config };
|
|
519
522
|
}
|
|
520
523
|
/**
|
|
521
|
-
* Check if a path is allowed
|
|
524
|
+
* Check if a path is allowed (async for non-blocking symlink resolution)
|
|
522
525
|
*/
|
|
523
|
-
isPathAllowed(filePath) {
|
|
524
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
526
|
+
async isPathAllowed(filePath) {
|
|
527
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
525
528
|
return validation.isValid;
|
|
526
529
|
}
|
|
527
530
|
}
|
|
@@ -34,7 +34,7 @@ export declare class FileSystemService {
|
|
|
34
34
|
* @param filePath The file path to check (can be relative or absolute)
|
|
35
35
|
* @returns true if the path is within allowed paths, false otherwise
|
|
36
36
|
*/
|
|
37
|
-
isPathWithinAllowed(filePath: string): boolean
|
|
37
|
+
isPathWithinAllowed(filePath: string): Promise<boolean>;
|
|
38
38
|
/**
|
|
39
39
|
* Get the list of configured allowed paths.
|
|
40
40
|
* Useful for displaying to users when directory approval is needed.
|
|
@@ -90,8 +90,8 @@ export declare class FileSystemService {
|
|
|
90
90
|
*/
|
|
91
91
|
getConfig(): Readonly<FileSystemConfig>;
|
|
92
92
|
/**
|
|
93
|
-
* Check if a path is allowed
|
|
93
|
+
* Check if a path is allowed (async for non-blocking symlink resolution)
|
|
94
94
|
*/
|
|
95
|
-
isPathAllowed(filePath: string): boolean
|
|
95
|
+
isPathAllowed(filePath: string): Promise<boolean>;
|
|
96
96
|
}
|
|
97
97
|
//# sourceMappingURL=filesystem-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem-service.d.ts","sourceRoot":"","sources":["../../src/filesystem/filesystem-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EACH,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,EAEZ,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,UAAU,EACV,aAAa,EAGhB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAQ1D;;;;GAIG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,WAAW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wB,GAAG,IAAI;IAIpE;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IA+ErF;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAwEhF;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;IAqGtF;;OAEG;IACG,SAAS,CACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,gBAAqB,GAC/B,OAAO,CAAC,WAAW,CAAC;IA0DvB;;OAEG;IACG,QAAQ,CACV,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,aAAa,EACxB,OAAO,GAAE,eAAoB,GAC9B,OAAO,CAAC,UAAU,CAAC;IAuEtB;;OAEG;YACW,YAAY;IA0B1B;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IA6D1C;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,gBAAgB,CAAC;IAIvC;;OAEG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAI1D"}
|
|
@@ -21,7 +21,7 @@ class FileSystemService {
|
|
|
21
21
|
blockedPaths: config.blockedPaths || [".git", "node_modules/.bin", ".env"],
|
|
22
22
|
blockedExtensions: config.blockedExtensions || [".exe", ".dll", ".so"],
|
|
23
23
|
maxFileSize: config.maxFileSize || DEFAULT_MAX_FILE_SIZE,
|
|
24
|
-
enableBackups: config.enableBackups ??
|
|
24
|
+
enableBackups: config.enableBackups ?? false,
|
|
25
25
|
backupPath: config.backupPath,
|
|
26
26
|
// Optional absolute override, defaults handled by getBackupDir()
|
|
27
27
|
backupRetentionDays: config.backupRetentionDays || 7,
|
|
@@ -67,7 +67,7 @@ class FileSystemService {
|
|
|
67
67
|
* @param filePath The file path to check (can be relative or absolute)
|
|
68
68
|
* @returns true if the path is within allowed paths, false otherwise
|
|
69
69
|
*/
|
|
70
|
-
isPathWithinAllowed(filePath) {
|
|
70
|
+
async isPathWithinAllowed(filePath) {
|
|
71
71
|
return this.pathValidator.isPathWithinAllowed(filePath);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -105,7 +105,7 @@ class FileSystemService {
|
|
|
105
105
|
if (!this.initialized) {
|
|
106
106
|
throw FileSystemError.notInitialized();
|
|
107
107
|
}
|
|
108
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
108
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
109
109
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
110
110
|
throw FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
111
111
|
}
|
|
@@ -184,7 +184,7 @@ class FileSystemService {
|
|
|
184
184
|
});
|
|
185
185
|
const validFiles = [];
|
|
186
186
|
for (const file of files) {
|
|
187
|
-
const validation = this.pathValidator.validatePath(file);
|
|
187
|
+
const validation = await this.pathValidator.validatePath(file);
|
|
188
188
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
189
189
|
this.logger.debug(`Skipping invalid path: ${file}`);
|
|
190
190
|
continue;
|
|
@@ -315,7 +315,7 @@ class FileSystemService {
|
|
|
315
315
|
if (!this.initialized) {
|
|
316
316
|
throw FileSystemError.notInitialized();
|
|
317
317
|
}
|
|
318
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
318
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
319
319
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
320
320
|
throw FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
321
321
|
}
|
|
@@ -359,14 +359,14 @@ class FileSystemService {
|
|
|
359
359
|
if (!this.initialized) {
|
|
360
360
|
throw FileSystemError.notInitialized();
|
|
361
361
|
}
|
|
362
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
362
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
363
363
|
if (!validation.isValid || !validation.normalizedPath) {
|
|
364
364
|
throw FileSystemError.invalidPath(filePath, validation.error || "Unknown error");
|
|
365
365
|
}
|
|
366
366
|
const normalizedPath = validation.normalizedPath;
|
|
367
367
|
const fileContent = await this.readFile(normalizedPath);
|
|
368
|
-
|
|
369
|
-
const occurrences = (
|
|
368
|
+
const originalContent = fileContent.content;
|
|
369
|
+
const occurrences = (originalContent.match(
|
|
370
370
|
new RegExp(operation.oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g")
|
|
371
371
|
) || []).length;
|
|
372
372
|
if (occurrences === 0) {
|
|
@@ -380,21 +380,24 @@ class FileSystemService {
|
|
|
380
380
|
backupPath = await this.createBackup(normalizedPath);
|
|
381
381
|
}
|
|
382
382
|
try {
|
|
383
|
+
let newContent;
|
|
383
384
|
if (operation.replaceAll) {
|
|
384
|
-
|
|
385
|
+
newContent = originalContent.replace(
|
|
385
386
|
new RegExp(operation.oldString.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"),
|
|
386
387
|
operation.newString
|
|
387
388
|
);
|
|
388
389
|
} else {
|
|
389
|
-
|
|
390
|
+
newContent = originalContent.replace(operation.oldString, operation.newString);
|
|
390
391
|
}
|
|
391
|
-
await fs.writeFile(normalizedPath,
|
|
392
|
+
await fs.writeFile(normalizedPath, newContent, options.encoding || DEFAULT_ENCODING);
|
|
392
393
|
this.logger.debug(`File edited: ${normalizedPath} (${occurrences} replacements)`);
|
|
393
394
|
return {
|
|
394
395
|
success: true,
|
|
395
396
|
path: normalizedPath,
|
|
396
397
|
changesCount: occurrences,
|
|
397
|
-
backupPath
|
|
398
|
+
backupPath,
|
|
399
|
+
originalContent,
|
|
400
|
+
newContent
|
|
398
401
|
};
|
|
399
402
|
} catch (error) {
|
|
400
403
|
throw FileSystemError.editFailed(
|
|
@@ -486,10 +489,10 @@ class FileSystemService {
|
|
|
486
489
|
return { ...this.config };
|
|
487
490
|
}
|
|
488
491
|
/**
|
|
489
|
-
* Check if a path is allowed
|
|
492
|
+
* Check if a path is allowed (async for non-blocking symlink resolution)
|
|
490
493
|
*/
|
|
491
|
-
isPathAllowed(filePath) {
|
|
492
|
-
const validation = this.pathValidator.validatePath(filePath);
|
|
494
|
+
async isPathAllowed(filePath) {
|
|
495
|
+
const validation = await this.pathValidator.validatePath(filePath);
|
|
493
496
|
return validation.isValid;
|
|
494
497
|
}
|
|
495
498
|
}
|
|
@@ -32,7 +32,7 @@ __export(path_validator_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(path_validator_exports);
|
|
34
34
|
var path = __toESM(require("node:path"), 1);
|
|
35
|
-
var
|
|
35
|
+
var fs = __toESM(require("node:fs/promises"), 1);
|
|
36
36
|
class PathValidator {
|
|
37
37
|
config;
|
|
38
38
|
normalizedAllowedPaths;
|
|
@@ -67,7 +67,7 @@ class PathValidator {
|
|
|
67
67
|
/**
|
|
68
68
|
* Validate a file path for security and policy compliance
|
|
69
69
|
*/
|
|
70
|
-
validatePath(filePath) {
|
|
70
|
+
async validatePath(filePath) {
|
|
71
71
|
if (!filePath || filePath.trim() === "") {
|
|
72
72
|
return {
|
|
73
73
|
isValid: false,
|
|
@@ -79,7 +79,7 @@ class PathValidator {
|
|
|
79
79
|
try {
|
|
80
80
|
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
81
81
|
try {
|
|
82
|
-
normalizedPath =
|
|
82
|
+
normalizedPath = await fs.realpath(normalizedPath);
|
|
83
83
|
} catch {
|
|
84
84
|
}
|
|
85
85
|
} catch (error) {
|
|
@@ -135,8 +135,16 @@ class PathValidator {
|
|
|
135
135
|
/**
|
|
136
136
|
* Check if path is within allowed paths (whitelist check)
|
|
137
137
|
* Also consults the directory approval checker if configured.
|
|
138
|
+
* Uses the sync version since the path is already normalized at this point.
|
|
138
139
|
*/
|
|
139
140
|
isPathAllowed(normalizedPath) {
|
|
141
|
+
return this.isPathAllowedSync(normalizedPath);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Synchronous path allowed check (for already-normalized paths)
|
|
145
|
+
* This is used internally when we already have a canonicalized path
|
|
146
|
+
*/
|
|
147
|
+
isPathAllowedSync(normalizedPath) {
|
|
140
148
|
if (this.normalizedAllowedPaths.length === 0) {
|
|
141
149
|
return true;
|
|
142
150
|
}
|
|
@@ -169,9 +177,10 @@ class PathValidator {
|
|
|
169
177
|
}
|
|
170
178
|
/**
|
|
171
179
|
* Quick check if a path is allowed (for internal use)
|
|
180
|
+
* Note: This assumes the path is already normalized/canonicalized
|
|
172
181
|
*/
|
|
173
182
|
isPathAllowedQuick(normalizedPath) {
|
|
174
|
-
return this.
|
|
183
|
+
return this.isPathAllowedSync(normalizedPath) && !this.isPathBlocked(normalizedPath);
|
|
175
184
|
}
|
|
176
185
|
/**
|
|
177
186
|
* Check if a file path is within the configured allowed paths (from config only).
|
|
@@ -187,12 +196,12 @@ class PathValidator {
|
|
|
187
196
|
* @example
|
|
188
197
|
* ```typescript
|
|
189
198
|
* // Check if path needs directory approval
|
|
190
|
-
* if (!pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
|
|
199
|
+
* if (!await pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
|
|
191
200
|
* // Request directory access approval
|
|
192
201
|
* }
|
|
193
202
|
* ```
|
|
194
203
|
*/
|
|
195
|
-
isPathWithinAllowed(filePath) {
|
|
204
|
+
async isPathWithinAllowed(filePath) {
|
|
196
205
|
if (!filePath || filePath.trim() === "") {
|
|
197
206
|
return false;
|
|
198
207
|
}
|
|
@@ -201,7 +210,7 @@ class PathValidator {
|
|
|
201
210
|
try {
|
|
202
211
|
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
203
212
|
try {
|
|
204
|
-
normalizedPath =
|
|
213
|
+
normalizedPath = await fs.realpath(normalizedPath);
|
|
205
214
|
} catch {
|
|
206
215
|
}
|
|
207
216
|
} catch {
|
|
@@ -41,7 +41,7 @@ export declare class PathValidator {
|
|
|
41
41
|
/**
|
|
42
42
|
* Validate a file path for security and policy compliance
|
|
43
43
|
*/
|
|
44
|
-
validatePath(filePath: string): PathValidation
|
|
44
|
+
validatePath(filePath: string): Promise<PathValidation>;
|
|
45
45
|
/**
|
|
46
46
|
* Check if path contains traversal attempts
|
|
47
47
|
*/
|
|
@@ -49,14 +49,21 @@ export declare class PathValidator {
|
|
|
49
49
|
/**
|
|
50
50
|
* Check if path is within allowed paths (whitelist check)
|
|
51
51
|
* Also consults the directory approval checker if configured.
|
|
52
|
+
* Uses the sync version since the path is already normalized at this point.
|
|
52
53
|
*/
|
|
53
54
|
private isPathAllowed;
|
|
55
|
+
/**
|
|
56
|
+
* Synchronous path allowed check (for already-normalized paths)
|
|
57
|
+
* This is used internally when we already have a canonicalized path
|
|
58
|
+
*/
|
|
59
|
+
private isPathAllowedSync;
|
|
54
60
|
/**
|
|
55
61
|
* Check if path matches blocked patterns (blacklist check)
|
|
56
62
|
*/
|
|
57
63
|
private isPathBlocked;
|
|
58
64
|
/**
|
|
59
65
|
* Quick check if a path is allowed (for internal use)
|
|
66
|
+
* Note: This assumes the path is already normalized/canonicalized
|
|
60
67
|
*/
|
|
61
68
|
isPathAllowedQuick(normalizedPath: string): boolean;
|
|
62
69
|
/**
|
|
@@ -73,12 +80,12 @@ export declare class PathValidator {
|
|
|
73
80
|
* @example
|
|
74
81
|
* ```typescript
|
|
75
82
|
* // Check if path needs directory approval
|
|
76
|
-
* if (!pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
|
|
83
|
+
* if (!await pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
|
|
77
84
|
* // Request directory access approval
|
|
78
85
|
* }
|
|
79
86
|
* ```
|
|
80
87
|
*/
|
|
81
|
-
isPathWithinAllowed(filePath: string): boolean
|
|
88
|
+
isPathWithinAllowed(filePath: string): Promise<boolean>;
|
|
82
89
|
/**
|
|
83
90
|
* Check if path is within config-allowed paths only (no approval checker).
|
|
84
91
|
* Used for prompting decisions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../../src/filesystem/path-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,2BAA2B,CAAW;IAC9C,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,wBAAwB,CAAuC;gBAE3D,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY;IAsB1D;;;;;OAKG;IACH,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAKpE;;OAEG;
|
|
1
|
+
{"version":3,"file":"path-validator.d.ts","sourceRoot":"","sources":["../../src/filesystem/path-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,sBAAsB,CAAW;IACzC,OAAO,CAAC,2BAA2B,CAAW;IAC9C,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,wBAAwB,CAAuC;gBAE3D,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY;IAsB1D;;;;;OAKG;IACH,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAKpE;;OAEG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAyE7D;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAaxB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAyBzB;;OAEG;IACH,OAAO,CAAC,aAAa;IAyBrB;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO;IAInD;;;;;;;;;;;;;;;;;;OAkBG;IACG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA8B7D;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;CAG9B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../chunk-PTJYTZNU.js";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
4
|
class PathValidator {
|
|
5
5
|
config;
|
|
6
6
|
normalizedAllowedPaths;
|
|
@@ -35,7 +35,7 @@ class PathValidator {
|
|
|
35
35
|
/**
|
|
36
36
|
* Validate a file path for security and policy compliance
|
|
37
37
|
*/
|
|
38
|
-
validatePath(filePath) {
|
|
38
|
+
async validatePath(filePath) {
|
|
39
39
|
if (!filePath || filePath.trim() === "") {
|
|
40
40
|
return {
|
|
41
41
|
isValid: false,
|
|
@@ -47,7 +47,7 @@ class PathValidator {
|
|
|
47
47
|
try {
|
|
48
48
|
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
49
49
|
try {
|
|
50
|
-
normalizedPath =
|
|
50
|
+
normalizedPath = await fs.realpath(normalizedPath);
|
|
51
51
|
} catch {
|
|
52
52
|
}
|
|
53
53
|
} catch (error) {
|
|
@@ -103,8 +103,16 @@ class PathValidator {
|
|
|
103
103
|
/**
|
|
104
104
|
* Check if path is within allowed paths (whitelist check)
|
|
105
105
|
* Also consults the directory approval checker if configured.
|
|
106
|
+
* Uses the sync version since the path is already normalized at this point.
|
|
106
107
|
*/
|
|
107
108
|
isPathAllowed(normalizedPath) {
|
|
109
|
+
return this.isPathAllowedSync(normalizedPath);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Synchronous path allowed check (for already-normalized paths)
|
|
113
|
+
* This is used internally when we already have a canonicalized path
|
|
114
|
+
*/
|
|
115
|
+
isPathAllowedSync(normalizedPath) {
|
|
108
116
|
if (this.normalizedAllowedPaths.length === 0) {
|
|
109
117
|
return true;
|
|
110
118
|
}
|
|
@@ -137,9 +145,10 @@ class PathValidator {
|
|
|
137
145
|
}
|
|
138
146
|
/**
|
|
139
147
|
* Quick check if a path is allowed (for internal use)
|
|
148
|
+
* Note: This assumes the path is already normalized/canonicalized
|
|
140
149
|
*/
|
|
141
150
|
isPathAllowedQuick(normalizedPath) {
|
|
142
|
-
return this.
|
|
151
|
+
return this.isPathAllowedSync(normalizedPath) && !this.isPathBlocked(normalizedPath);
|
|
143
152
|
}
|
|
144
153
|
/**
|
|
145
154
|
* Check if a file path is within the configured allowed paths (from config only).
|
|
@@ -155,12 +164,12 @@ class PathValidator {
|
|
|
155
164
|
* @example
|
|
156
165
|
* ```typescript
|
|
157
166
|
* // Check if path needs directory approval
|
|
158
|
-
* if (!pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
|
|
167
|
+
* if (!await pathValidator.isPathWithinAllowed('/external/project/file.ts')) {
|
|
159
168
|
* // Request directory access approval
|
|
160
169
|
* }
|
|
161
170
|
* ```
|
|
162
171
|
*/
|
|
163
|
-
isPathWithinAllowed(filePath) {
|
|
172
|
+
async isPathWithinAllowed(filePath) {
|
|
164
173
|
if (!filePath || filePath.trim() === "") {
|
|
165
174
|
return false;
|
|
166
175
|
}
|
|
@@ -169,7 +178,7 @@ class PathValidator {
|
|
|
169
178
|
try {
|
|
170
179
|
normalizedPath = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(workingDir, filePath);
|
|
171
180
|
try {
|
|
172
|
-
normalizedPath =
|
|
181
|
+
normalizedPath = await fs.realpath(normalizedPath);
|
|
173
182
|
} catch {
|
|
174
183
|
}
|
|
175
184
|
} catch {
|
|
@@ -138,6 +138,10 @@ export interface EditResult {
|
|
|
138
138
|
path: string;
|
|
139
139
|
changesCount: number;
|
|
140
140
|
backupPath?: string | undefined;
|
|
141
|
+
/** Original content before edit (for diff generation) */
|
|
142
|
+
originalContent: string;
|
|
143
|
+
/** New content after edit (for diff generation) */
|
|
144
|
+
newContent: string;
|
|
141
145
|
}
|
|
142
146
|
/**
|
|
143
147
|
* Path validation result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/filesystem/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,MAAM,MAAM,cAAc,GACpB,OAAO,GACP,MAAM,GACN,OAAO,GACP,SAAS,GACT,MAAM,GACN,OAAO,GACP,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,KAAK,CAAC;AAEZ;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CAChB;AA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
49
|
actualTokens = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
50
50
|
finishReason = "unknown";
|
|
51
51
|
reasoningText = "";
|
|
52
|
+
reasoningMetadata;
|
|
52
53
|
accumulatedText = "";
|
|
53
54
|
logger;
|
|
54
55
|
/**
|
|
@@ -81,6 +82,9 @@ class StreamProcessor {
|
|
|
81
82
|
break;
|
|
82
83
|
case "reasoning-delta":
|
|
83
84
|
this.reasoningText += event.text;
|
|
85
|
+
if (event.providerMetadata) {
|
|
86
|
+
this.reasoningMetadata = event.providerMetadata;
|
|
87
|
+
}
|
|
84
88
|
if (this.streaming) {
|
|
85
89
|
this.eventBus.emit("llm:chunk", {
|
|
86
90
|
chunkType: "reasoning",
|
|
@@ -210,7 +214,12 @@ class StreamProcessor {
|
|
|
210
214
|
await this.contextManager.updateAssistantMessage(
|
|
211
215
|
this.assistantMessageId,
|
|
212
216
|
{
|
|
213
|
-
tokenUsage: usage
|
|
217
|
+
tokenUsage: usage,
|
|
218
|
+
// Persist reasoning text and metadata for round-tripping
|
|
219
|
+
...this.reasoningText && { reasoning: this.reasoningText },
|
|
220
|
+
...this.reasoningMetadata && {
|
|
221
|
+
reasoningMetadata: this.reasoningMetadata
|
|
222
|
+
}
|
|
214
223
|
}
|
|
215
224
|
);
|
|
216
225
|
}
|
|
@@ -222,6 +231,9 @@ class StreamProcessor {
|
|
|
222
231
|
provider: this.config.provider,
|
|
223
232
|
model: this.config.model,
|
|
224
233
|
tokenUsage: usage,
|
|
234
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
235
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
236
|
+
},
|
|
225
237
|
finishReason: this.finishReason
|
|
226
238
|
});
|
|
227
239
|
}
|
|
@@ -283,6 +295,9 @@ class StreamProcessor {
|
|
|
283
295
|
provider: this.config.provider,
|
|
284
296
|
model: this.config.model,
|
|
285
297
|
tokenUsage: this.actualTokens,
|
|
298
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
299
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
300
|
+
},
|
|
286
301
|
finishReason: "cancelled"
|
|
287
302
|
});
|
|
288
303
|
return {
|
|
@@ -304,6 +319,9 @@ class StreamProcessor {
|
|
|
304
319
|
provider: this.config.provider,
|
|
305
320
|
model: this.config.model,
|
|
306
321
|
tokenUsage: this.actualTokens,
|
|
322
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
323
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
324
|
+
},
|
|
307
325
|
finishReason: "cancelled"
|
|
308
326
|
});
|
|
309
327
|
return {
|
|
@@ -8,6 +8,8 @@ import { LLMProvider } from '../types.js';
|
|
|
8
8
|
export interface StreamProcessorConfig {
|
|
9
9
|
provider: LLMProvider;
|
|
10
10
|
model: string;
|
|
11
|
+
/** Estimated input tokens before LLM call (for analytics/calibration) */
|
|
12
|
+
estimatedInputTokens?: number;
|
|
11
13
|
}
|
|
12
14
|
export declare class StreamProcessor {
|
|
13
15
|
private contextManager;
|
|
@@ -21,6 +23,7 @@ export declare class StreamProcessor {
|
|
|
21
23
|
private actualTokens;
|
|
22
24
|
private finishReason;
|
|
23
25
|
private reasoningText;
|
|
26
|
+
private reasoningMetadata;
|
|
24
27
|
private accumulatedText;
|
|
25
28
|
private logger;
|
|
26
29
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-processor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/stream-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,IAAI,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAmB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,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;IACH,OAAO,CAAC,gBAAgB,CAAgD;IAExE;;;;;;;;;OASG;gBAES,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,eAAe,EACzB,eAAe,EAAE,eAAe,EAChC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,qBAAqB,EACrC,MAAM,EAAE,YAAY,EACZ,SAAS,GAAE,OAAc,EACzB,gBAAgB,CAAC,EAAE,GAAG,CAC1B,MAAM,EACN;QAAE,eAAe,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,UAAU,GAAG,UAAU,CAAA;KAAE,CACzE,YAAA;IAKC,OAAO,CACT,QAAQ,EAAE,MAAM,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,GACzD,OAAO,CAAC,qBAAqB,CAAC;YAubnB,sBAAsB;YAKtB,gBAAgB;IAO9B;;;;OAIG;YACW,2BAA2B;CAmC5C"}
|
|
@@ -27,6 +27,7 @@ class StreamProcessor {
|
|
|
27
27
|
actualTokens = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
|
|
28
28
|
finishReason = "unknown";
|
|
29
29
|
reasoningText = "";
|
|
30
|
+
reasoningMetadata;
|
|
30
31
|
accumulatedText = "";
|
|
31
32
|
logger;
|
|
32
33
|
/**
|
|
@@ -59,6 +60,9 @@ class StreamProcessor {
|
|
|
59
60
|
break;
|
|
60
61
|
case "reasoning-delta":
|
|
61
62
|
this.reasoningText += event.text;
|
|
63
|
+
if (event.providerMetadata) {
|
|
64
|
+
this.reasoningMetadata = event.providerMetadata;
|
|
65
|
+
}
|
|
62
66
|
if (this.streaming) {
|
|
63
67
|
this.eventBus.emit("llm:chunk", {
|
|
64
68
|
chunkType: "reasoning",
|
|
@@ -188,7 +192,12 @@ class StreamProcessor {
|
|
|
188
192
|
await this.contextManager.updateAssistantMessage(
|
|
189
193
|
this.assistantMessageId,
|
|
190
194
|
{
|
|
191
|
-
tokenUsage: usage
|
|
195
|
+
tokenUsage: usage,
|
|
196
|
+
// Persist reasoning text and metadata for round-tripping
|
|
197
|
+
...this.reasoningText && { reasoning: this.reasoningText },
|
|
198
|
+
...this.reasoningMetadata && {
|
|
199
|
+
reasoningMetadata: this.reasoningMetadata
|
|
200
|
+
}
|
|
192
201
|
}
|
|
193
202
|
);
|
|
194
203
|
}
|
|
@@ -200,6 +209,9 @@ class StreamProcessor {
|
|
|
200
209
|
provider: this.config.provider,
|
|
201
210
|
model: this.config.model,
|
|
202
211
|
tokenUsage: usage,
|
|
212
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
213
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
214
|
+
},
|
|
203
215
|
finishReason: this.finishReason
|
|
204
216
|
});
|
|
205
217
|
}
|
|
@@ -261,6 +273,9 @@ class StreamProcessor {
|
|
|
261
273
|
provider: this.config.provider,
|
|
262
274
|
model: this.config.model,
|
|
263
275
|
tokenUsage: this.actualTokens,
|
|
276
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
277
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
278
|
+
},
|
|
264
279
|
finishReason: "cancelled"
|
|
265
280
|
});
|
|
266
281
|
return {
|
|
@@ -282,6 +297,9 @@ class StreamProcessor {
|
|
|
282
297
|
provider: this.config.provider,
|
|
283
298
|
model: this.config.model,
|
|
284
299
|
tokenUsage: this.actualTokens,
|
|
300
|
+
...this.config.estimatedInputTokens !== void 0 && {
|
|
301
|
+
estimatedInputTokens: this.config.estimatedInputTokens
|
|
302
|
+
},
|
|
285
303
|
finishReason: "cancelled"
|
|
286
304
|
});
|
|
287
305
|
return {
|