praxis-agent 0.46.4 → 0.46.5
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/tools/local-tools.js +16 -1
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { mkdir, mkdtemp, open, realpath, stat, writeFile, } from 'node:fs/promis
|
|
|
4
4
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, } from 'node:path';
|
|
5
5
|
import { homedir, tmpdir } from 'node:os';
|
|
6
6
|
import sharp from 'sharp';
|
|
7
|
+
import { countTokens } from '@anthropic-ai/tokenizer';
|
|
7
8
|
import { commandShell, commandShellArguments, } from '../platform/command-shell.js';
|
|
8
9
|
import { BoundedProcessRunner, joinedProcessOutput, } from '../platform/bounded-process-runner.js';
|
|
9
10
|
import { globFiles } from './glob.js';
|
|
@@ -462,6 +463,8 @@ function truncateOutput(content, maxBytes) {
|
|
|
462
463
|
? `${retained.content}\n[output truncated]`
|
|
463
464
|
: retained.content;
|
|
464
465
|
}
|
|
466
|
+
const TEXT_READ_MAX_BYTES = 256 * 1024;
|
|
467
|
+
const TEXT_READ_MAX_TOKENS = 25_000;
|
|
465
468
|
function abortError() {
|
|
466
469
|
return new DOMException('Tool execution aborted', 'AbortError');
|
|
467
470
|
}
|
|
@@ -1037,8 +1040,20 @@ export class LocalToolRegistry {
|
|
|
1037
1040
|
: selected
|
|
1038
1041
|
.map((line, index) => `${(offset === 0 ? 0 : offset) + index}\t${line}`)
|
|
1039
1042
|
.join('\n');
|
|
1043
|
+
if (!notebook) {
|
|
1044
|
+
const contentBytes = Buffer.byteLength(content);
|
|
1045
|
+
if (contentBytes > TEXT_READ_MAX_BYTES) {
|
|
1046
|
+
throw new Error(`Read result is ${contentBytes} bytes, which exceeds the ${formatKilobytes(TEXT_READ_MAX_BYTES)} limit. Use offset and limit to read specific portions.`);
|
|
1047
|
+
}
|
|
1048
|
+
const contentTokens = countTokens(content);
|
|
1049
|
+
if (contentTokens > TEXT_READ_MAX_TOKENS) {
|
|
1050
|
+
throw new Error(`Read result is ${contentTokens} tokens, which exceeds the ${TEXT_READ_MAX_TOKENS} token limit. Use offset and limit to read specific portions.`);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1040
1053
|
return {
|
|
1041
|
-
content:
|
|
1054
|
+
content: notebook
|
|
1055
|
+
? truncateOutput(content, this.maxOutputBytes)
|
|
1056
|
+
: content,
|
|
1042
1057
|
isError: false,
|
|
1043
1058
|
accessedPaths: [filePath],
|
|
1044
1059
|
...(notebook
|