summaryrefslogtreecommitdiffhomepage
path: root/js/src/tool/view.ts
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-05-21 10:30:39 -0400
committerDax Raad <[email protected]>2025-05-26 12:40:17 -0400
commite01afb407c4b3eb50e85e7356b0be9489fb26eba (patch)
treed2aef91ec1894376c4d5a99ea2d11f6ad32b68de /js/src/tool/view.ts
parentf0f55bc75ff2bbc6690ae61c771a46de7c2bb17d (diff)
downloadopencode-e01afb407c4b3eb50e85e7356b0be9489fb26eba.tar.gz
opencode-e01afb407c4b3eb50e85e7356b0be9489fb26eba.zip
add tool tests
Diffstat (limited to 'js/src/tool/view.ts')
-rw-r--r--js/src/tool/view.ts12
1 files changed, 4 insertions, 8 deletions
diff --git a/js/src/tool/view.ts b/js/src/tool/view.ts
index 2da0ab0f3..5b429c63d 100644
--- a/js/src/tool/view.ts
+++ b/js/src/tool/view.ts
@@ -40,7 +40,7 @@ TIPS:
- For code exploration, first use Grep to find relevant files, then View to examine them
- When viewing large files, use the offset parameter to read specific sections`;
-export const ViewTool = Tool.define({
+export const view = Tool.define({
name: "view",
description: DESCRIPTION,
parameters: z.object({
@@ -84,29 +84,25 @@ export const ViewTool = Tool.define({
throw new Error(`File not found: ${filePath}`);
}
const stats = await file.stat();
- if (stats.isDirectory())
- throw new Error(`Path is a directory, not a file: ${filePath}`);
- if (stats.size > MAX_READ_SIZE) {
+ if (stats.size > MAX_READ_SIZE)
throw new Error(
`File is too large (${stats.size} bytes). Maximum size is ${MAX_READ_SIZE} bytes`,
);
- }
const limit = params.limit ?? DEFAULT_READ_LIMIT;
const offset = params.offset || 0;
const isImage = isImageFile(filePath);
- if (isImage) {
+ if (isImage)
throw new Error(
`This is an image file of type: ${isImage}\nUse a different tool to process images`,
);
- }
const lines = await file.text().then((text) => text.split("\n"));
const content = lines.slice(offset, offset + limit).map((line, index) => {
line =
line.length > MAX_LINE_LENGTH
? line.substring(0, MAX_LINE_LENGTH) + "..."
: line;
- return `${index + offset + 1}|${line}`;
+ return `${(index + offset + 1).toString().padStart(5, "0")}| ${line}`;
});
let output = "<file>\n";