wip: refactoring tui

This commit is contained in:
adamdottv
2025-05-30 12:29:27 -05:00
parent 437de4ee36
commit 6ebbcb3179
3 changed files with 41 additions and 13 deletions

View File

@@ -97,13 +97,15 @@ export const view = Tool.define({
`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;
const raw = lines.slice(offset, offset + limit).map((line) => {
return line.length > MAX_LINE_LENGTH
? line.substring(0, MAX_LINE_LENGTH) + "..."
: line;
});
const content = raw.map((line, index) => {
return `${(index + offset + 1).toString().padStart(5, "0")}| ${line}`;
});
const preview = raw.slice(0, 20).join("\n");
let output = "<file>\n";
output += content.join("\n");
@@ -121,6 +123,9 @@ export const view = Tool.define({
return {
output,
metadata: {
preview,
},
};
},
});