Skip to content

Commit 4b508d6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6df8150 commit 4b508d6

File tree

6 files changed

+4562
-4401
lines changed

6 files changed

+4562
-4401
lines changed

frontend/src/core/ai/context/providers/cell-output.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { displayCellName } from "@/core/cells/names";
99
import { isOutputEmpty } from "@/core/cells/outputs";
1010
import type { OutputMessage } from "@/core/kernel/messages";
1111
import type { JotaiStore } from "@/core/state/jotai";
12-
import { Logger } from "@/utils/Logger";
1312
import { parseHtmlContent } from "@/utils/dom";
13+
import { Logger } from "@/utils/Logger";
1414
import { type AIContextItem, AIContextProvider } from "../registry";
1515
import { contextToXml } from "../utils";
1616
import { Boosts } from "./common";
@@ -65,7 +65,6 @@ function isMediaMimetype(
6565
return false;
6666
}
6767

68-
6968
export class CellOutputContextProvider extends AIContextProvider<CellOutputContextItem> {
7069
readonly title = "Cell Outputs";
7170
readonly mentionPrefix = "@";

frontend/src/utils/__tests__/dom.test.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ import { ansiToPlainText, parseHtmlContent } from "../dom";
55

66
describe("parseHtmlContent", () => {
77
test("strips HTML tags and returns plain text", () => {
8-
const htmlString = '<span style="color: red;">Error: Something went wrong</span>';
8+
const htmlString =
9+
'<span style="color: red;">Error: Something went wrong</span>';
910
const result = parseHtmlContent(htmlString);
1011
expect(result).toBe("Error: Something went wrong");
1112
});
1213

1314
test("handles ANSI color span tags", () => {
14-
const htmlString = '<span style="color:#d03050;">ERROR</span>: <span style="color:#8ad03a;">File not found</span>';
15+
const htmlString =
16+
'<span style="color:#d03050;">ERROR</span>: <span style="color:#8ad03a;">File not found</span>';
1517
const result = parseHtmlContent(htmlString);
1618
expect(result).toBe("ERROR: File not found");
1719
});
1820

1921
test("normalizes whitespace", () => {
20-
const htmlString = '<span> Multiple \n\n spaces and \t tabs </span>';
22+
const htmlString = "<span> Multiple \n\n spaces and \t tabs </span>";
2123
const result = parseHtmlContent(htmlString);
2224
expect(result).toBe("Multiple spaces and tabs");
2325
});
@@ -35,13 +37,15 @@ describe("parseHtmlContent", () => {
3537
});
3638

3739
test("handles nested HTML elements", () => {
38-
const htmlString = '<div><span>Traceback:</span><pre><code> File "test.py", line 1\n print("hello"</code></pre></div>';
40+
const htmlString =
41+
'<div><span>Traceback:</span><pre><code> File "test.py", line 1\n print("hello"</code></pre></div>';
3942
const result = parseHtmlContent(htmlString);
4043
expect(result).toBe('Traceback: File "test.py", line 1 print("hello"');
4144
});
4245

4346
test("handles complex ANSI-converted HTML with styles", () => {
44-
const htmlString = '<span style="background:#fff;color:#000"> File "</span><span style="background:#fff;color:#0000ff">test.py</span><span style="background:#fff;color:#000">", line </span><span style="background:#fff;color:#008000">1</span>';
47+
const htmlString =
48+
'<span style="background:#fff;color:#000"> File "</span><span style="background:#fff;color:#0000ff">test.py</span><span style="background:#fff;color:#000">", line </span><span style="background:#fff;color:#008000">1</span>';
4549
const result = parseHtmlContent(htmlString);
4650
expect(result).toBe('File "test.py", line 1');
4751
});
@@ -55,33 +59,42 @@ describe("ansiToPlainText", () => {
5559
});
5660

5761
test("handles multiple ANSI color codes", () => {
58-
const ansiString = "\x1b[32mSUCCESS:\x1b[0m \x1b[34mOperation completed\x1b[0m successfully";
62+
const ansiString =
63+
"\x1b[32mSUCCESS:\x1b[0m \x1b[34mOperation completed\x1b[0m successfully";
5964
const result = ansiToPlainText(ansiString);
6065
expect(result).toBe("SUCCESS: Operation completed successfully");
6166
});
6267

6368
test("handles ANSI bold and color combinations", () => {
64-
const ansiString = "\x1b[1;31mBOLD RED ERROR:\x1b[0m \x1b[33mWarning message\x1b[0m";
69+
const ansiString =
70+
"\x1b[1;31mBOLD RED ERROR:\x1b[0m \x1b[33mWarning message\x1b[0m";
6571
const result = ansiToPlainText(ansiString);
6672
expect(result).toBe("BOLD RED ERROR: Warning message");
6773
});
6874

6975
test("handles Python traceback with ANSI codes", () => {
70-
const ansiString = "\x1b[0;36m File \"\x1b[0m\x1b[0;32mtest.py\x1b[0m\x1b[0;36m\", line \x1b[0m\x1b[0;32m1\x1b[0m\x1b[0;36m, in \x1b[0m\x1b[0;35m<module>\x1b[0m\n\x1b[0;31mNameError\x1b[0m: name 'undefined_var' is not defined";
76+
const ansiString =
77+
"\x1b[0;36m File \"\x1b[0m\x1b[0;32mtest.py\x1b[0m\x1b[0;36m\", line \x1b[0m\x1b[0;32m1\x1b[0m\x1b[0;36m, in \x1b[0m\x1b[0;35m<module>\x1b[0m\n\x1b[0;31mNameError\x1b[0m: name 'undefined_var' is not defined";
7178
const result = ansiToPlainText(ansiString);
72-
expect(result).toBe('File "test.py", line 1, in <module> NameError: name \'undefined_var\' is not defined');
79+
expect(result).toBe(
80+
"File \"test.py\", line 1, in <module> NameError: name 'undefined_var' is not defined",
81+
);
7382
});
7483

7584
test("handles error messages with background colors", () => {
76-
const ansiString = "\x1b[41;37m CRITICAL ERROR \x1b[0m \x1b[31mSystem failure detected\x1b[0m";
85+
const ansiString =
86+
"\x1b[41;37m CRITICAL ERROR \x1b[0m \x1b[31mSystem failure detected\x1b[0m";
7787
const result = ansiToPlainText(ansiString);
7888
expect(result).toBe("CRITICAL ERROR System failure detected");
7989
});
8090

8191
test("handles complex stack trace with mixed formatting", () => {
82-
const ansiString = "Traceback (most recent call last):\n \x1b[36mFile \"\x1b[32m/path/to/file.py\x1b[36m\", line \x1b[32m42\x1b[36m, in \x1b[35mfunction_name\x1b[0m\n \x1b[31mraise ValueError(\"Something went wrong\")\x1b[0m\n\x1b[31mValueError\x1b[0m: Something went wrong";
92+
const ansiString =
93+
'Traceback (most recent call last):\n \x1b[36mFile "\x1b[32m/path/to/file.py\x1b[36m", line \x1b[32m42\x1b[36m, in \x1b[35mfunction_name\x1b[0m\n \x1b[31mraise ValueError("Something went wrong")\x1b[0m\n\x1b[31mValueError\x1b[0m: Something went wrong';
8394
const result = ansiToPlainText(ansiString);
84-
expect(result).toBe('Traceback (most recent call last): File "/path/to/file.py", line 42, in function_name raise ValueError("Something went wrong") ValueError: Something went wrong');
95+
expect(result).toBe(
96+
'Traceback (most recent call last): File "/path/to/file.py", line 42, in function_name raise ValueError("Something went wrong") ValueError: Something went wrong',
97+
);
8598
});
8699

87100
test("handles empty string", () => {
@@ -97,26 +110,34 @@ describe("ansiToPlainText", () => {
97110
});
98111

99112
test("handles whitespace and newlines correctly", () => {
100-
const ansiString = "\x1b[31m Error: \x1b[0m\n\n \x1b[33m Warning \x1b[0m ";
113+
const ansiString =
114+
"\x1b[31m Error: \x1b[0m\n\n \x1b[33m Warning \x1b[0m ";
101115
const result = ansiToPlainText(ansiString);
102116
expect(result).toBe("Error: Warning");
103117
});
104118

105119
test("handles JavaScript error stack trace", () => {
106-
const ansiString = "\x1b[31mReferenceError\x1b[0m: \x1b[33mvariable\x1b[0m is not defined\n at \x1b[36mObject.<anonymous>\x1b[0m (\x1b[32m/path/to/script.js\x1b[0m:\x1b[33m5\x1b[0m:\x1b[33m1\x1b[0m)";
120+
const ansiString =
121+
"\x1b[31mReferenceError\x1b[0m: \x1b[33mvariable\x1b[0m is not defined\n at \x1b[36mObject.<anonymous>\x1b[0m (\x1b[32m/path/to/script.js\x1b[0m:\x1b[33m5\x1b[0m:\x1b[33m1\x1b[0m)";
107122
const result = ansiToPlainText(ansiString);
108-
expect(result).toBe("ReferenceError: variable is not defined at Object.<anonymous> (/path/to/script.js:5:1)");
123+
expect(result).toBe(
124+
"ReferenceError: variable is not defined at Object.<anonymous> (/path/to/script.js:5:1)",
125+
);
109126
});
110127

111128
test("handles Rust panic with ANSI formatting", () => {
112-
const ansiString = 'thread \'\x1b[32mmain\x1b[0m\' panicked at \'\x1b[31massertion failed: `(left == right)`\x1b[0m\'\n \x1b[36mleft\x1b[0m: `\x1b[33m5\x1b[0m`\n \x1b[36mright\x1b[0m: `\x1b[33m10\x1b[0m`';
129+
const ansiString =
130+
"thread '\x1b[32mmain\x1b[0m' panicked at '\x1b[31massertion failed: `(left == right)`\x1b[0m'\n \x1b[36mleft\x1b[0m: `\x1b[33m5\x1b[0m`\n \x1b[36mright\x1b[0m: `\x1b[33m10\x1b[0m`";
113131
const result = ansiToPlainText(ansiString);
114-
expect(result).toBe("thread 'main' panicked at 'assertion failed: `(left == right)`' left: `5` right: `10`");
132+
expect(result).toBe(
133+
"thread 'main' panicked at 'assertion failed: `(left == right)`' left: `5` right: `10`",
134+
);
115135
});
116136

117137
test("handles mix of 8-bit and 256-color ANSI codes", () => {
118-
const ansiString = "\x1b[38;5;196mBright Red\x1b[0m and \x1b[38;5;46mBright Green\x1b[0m text";
138+
const ansiString =
139+
"\x1b[38;5;196mBright Red\x1b[0m and \x1b[38;5;46mBright Green\x1b[0m text";
119140
const result = ansiToPlainText(ansiString);
120141
expect(result).toBe("Bright Red and Bright Green text");
121142
});
122-
});
143+
});

frontend/src/utils/dom.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const ansiUp = new AnsiUp();
88

99
/**
1010
* Extracts plain text content from HTML by removing all HTML tags and normalizing whitespace.
11-
*
11+
*
1212
* @param htmlString The HTML string to parse
1313
* @returns Plain text content with HTML tags removed and whitespace normalized
1414
*/
@@ -33,7 +33,7 @@ export function parseHtmlContent(htmlString: string): string {
3333
/**
3434
* Converts ANSI escape sequences to plain text by first converting to HTML and then stripping HTML tags.
3535
* This is useful for console output that may contain ANSI color codes or formatting.
36-
*
36+
*
3737
* @param ansiString String that may contain ANSI escape sequences
3838
* @returns Plain text with ANSI codes removed and HTML stripped
3939
*/
@@ -45,12 +45,12 @@ export function ansiToPlainText(ansiString: string): string {
4545
try {
4646
// Convert ANSI escape sequences to HTML
4747
const htmlString = ansiUp.ansi_to_html(ansiString);
48-
48+
4949
// Strip HTML tags and return clean text
5050
return parseHtmlContent(htmlString);
5151
} catch (error) {
5252
Logger.error("Error converting ANSI to plain text:", error);
5353
// If conversion fails, return the original string
5454
return ansiString;
5555
}
56-
}
56+
}

0 commit comments

Comments
 (0)