Skip to content

Commit adb66e3

Browse files
authored
Merge pull request #463 from jaseci-labs/jac-gpt/feat_streaming
Jac gpt/feat streaming
2 parents 83de854 + f262974 commit adb66e3

10 files changed

Lines changed: 1000 additions & 276 deletions

File tree

jac-gpt-fullstack/components/ChatMessage.cl.jac

Lines changed: 50 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ import from "@tabler/icons-react" {
1919
# Monaco Editor - React wrapper
2020
import from "@monaco-editor/react" { Editor }
2121

22-
# Monaco initialization utilities
23-
import from "..utils/monaco_initializer" { setupMonacoEditor, defineJacTheme }
22+
# Syntax highlighting utilities
23+
import from "..utils/syntax_highlighting" { highlightJacCode }
24+
25+
# Jac syntax highlighting CSS
26+
import "..styles/jacSyntax.css";
2427

2528

2629
"""Generic code block component with copy functionality (for non-Jac languages)."""
@@ -98,67 +101,30 @@ def:pub CodeBlock(language: str, code: str, children: any = null) -> any {
98101
}
99102

100103

101-
"""Monaco Jac code block with TextMate syntax highlighting."""
102-
def:pub JacMonacoBlock(code: str) -> any {
104+
"""Lightweight Jac code block with tokenizer-based syntax highlighting."""
105+
def:pub JacCodeBlock(code: str) -> any {
106+
console.log("=== JacCodeBlock rendered ===");
107+
console.log("Code to highlight:", code);
108+
103109
has copied: bool = false;
104-
editorRef = useRef(null);
105-
monacoRef = useRef(null);
106-
has themeApplied: bool = false;
107-
has contentHeight: any = 400; # Default height
110+
has highlightedCode: str = code;
108111

109112
def handleCopy() -> None {
110113
navigator.clipboard.writeText(code);
111114
copied = true;
112115
setTimeout(lambda { copied = false; }, 2000);
113116
}
114117

115-
# Handle before mount - define theme before editor is created
116-
async def handleBeforeMount(monaco: any) -> None {
117-
try {
118-
# Define the centralized Jac theme before the editor mounts
119-
defineJacTheme(monaco);
120-
121-
# Register Jac language if not already registered
122-
languages = monaco.languages.getLanguages();
123-
isJacRegistered = languages.some(lambda lang: any { return lang.id == "jac"; });
124-
125-
if not isJacRegistered {
126-
monaco.languages.register({ id: "jac" });
127-
}
128-
} except Exception as error {
129-
}
130-
}
131-
132-
# Handle Monaco mount - setup editor instance with pre-loaded syntax
133-
async def handleOnMount(editor: any, monaco: any) -> None {
134-
editorRef.current = editor;
135-
monacoRef.current = monaco;
136-
137-
try {
138-
grammarConfig = await setupMonacoEditor(monaco, editor);
139-
140-
if not grammarConfig {
141-
return;
142-
}
143-
144-
if grammarConfig {
145-
monaco.languages.setLanguageConfiguration("jac", grammarConfig);
146-
}
147-
148-
await Reflect.construct(Promise, [lambda resolve: any { setTimeout(resolve, 100); }]);
149-
150-
# Get Monaco's calculated content height
151-
if editorRef.current {
152-
height = editorRef.current.getContentHeight();
153-
contentHeight = height;
154-
editorRef.current.updateOptions({ readOnly: true });
155-
}
156-
157-
themeApplied = true;
158-
159-
} except Exception as error {
160-
}
161-
}
118+
# Highlight code on mount and when code changes
119+
useEffect(lambda {
120+
console.log("=== useEffect triggered for highlighting ===");
121+
console.log("Calling highlightJacCode with:", code);
122+
highlightJacCode(code).then(lambda result: any {
123+
console.log("=== Highlighting complete ===");
124+
console.log("Result:", result);
125+
highlightedCode = result;
126+
});
127+
}, [code]);
162128

163129
copyLabel = "Copy code";
164130
copyColor = "gray";
@@ -200,51 +166,23 @@ def:pub JacMonacoBlock(code: str) -> any {
200166
</Tooltip>
201167
</Group>
202168
203-
<Box style={{"height": f"{contentHeight}px"}}>
204-
<Editor
205-
height="100%"
206-
width="100%"
207-
language="jac"
208-
value={code}
209-
theme="jac-theme"
210-
beforeMount={handleBeforeMount}
211-
onMount={handleOnMount}
212-
loading="Loading editor..."
213-
options={{
214-
"readOnly": true,
215-
"minimap": { "enabled": false },
216-
"scrollBeyondLastLine": false,
217-
"lineNumbers": "on",
218-
"fontSize": 13,
219-
"lineHeight": 20,
220-
"fontFamily": "JetBrains Mono, Consolas, Monaco, monospace",
221-
"automaticLayout": true,
222-
"wordWrap": "on",
223-
"renderLineHighlight": "none",
224-
"contextmenu": false,
225-
"folding": false,
226-
"glyphMargin": false,
227-
"lineDecorationsWidth": 0,
228-
"lineNumbersMinChars": 3,
229-
"overviewRulerBorder": false,
230-
"scrollbar": {
231-
"vertical": "hidden",
232-
"horizontal": "auto",
233-
"verticalScrollbarSize": 0,
234-
"horizontalScrollbarSize": 8
235-
},
236-
"padding": { "top": 8, "bottom": 8 }
169+
<Box px="md" py="sm" style={{"overflowX": "auto"}}>
170+
<pre
171+
className="jac-code"
172+
style={{
173+
"margin": "0",
174+
"padding": "0",
175+
"fontSize": "13px",
176+
"lineHeight": "1.5",
177+
"fontFamily": "Monaco, Menlo, Ubuntu Mono, monospace",
178+
"whiteSpace": "pre-wrap",
179+
"wordBreak": "break-word",
180+
"color": "#d4d4d4",
181+
"background": "transparent"
237182
}}
183+
dangerouslySetInnerHTML={{ "__html": highlightedCode }}
238184
/>
239185
</Box>
240-
241-
{not themeApplied and (
242-
<Box px="md" py="xs">
243-
<Text size="xs" c="dimmed" fs="italic">
244-
Loading syntax highlighting...
245-
</Text>
246-
</Box>
247-
)}
248186
</Paper>
249187
</Box>;
250188
}
@@ -280,10 +218,16 @@ def:pub ChatMessage(message: str, isUser: bool, timestamp: any = null) -> any {
280218
# Bot message: Markdown enabled
281219
components = {
282220
"code": lambda props: any -> any {
221+
console.log("=== Code component called ===");
222+
console.log("Props:", props);
223+
283224
className = props.className or "";
284225
children = props.children;
285226
isInline = not className.includes("language-");
286227

228+
console.log("className:", className);
229+
console.log("isInline:", isInline);
230+
287231
language = "";
288232
if className.includes("language-") {
289233
parts = className.split("language-");
@@ -293,22 +237,29 @@ def:pub ChatMessage(message: str, isUser: bool, timestamp: any = null) -> any {
293237
}
294238
}
295239

240+
console.log("Detected language:", language);
241+
296242
codeContent = String(children);
297243
if codeContent.endsWith("\n") {
298244
codeContent = codeContent.slice(0, -1);
299245
}
300246

247+
console.log("Code content:", codeContent);
248+
301249
# Block code
302250
if not isInline and language {
303-
# Use Monaco for Jac code
251+
# Use lightweight tokenizer for Jac code
304252
if language == "jac" {
305-
return <JacMonacoBlock code={codeContent} />;
253+
console.log("Rendering JacCodeBlock");
254+
return <JacCodeBlock code={codeContent} />;
306255
}
307256

257+
console.log("Rendering CodeBlock for language:", language);
308258
# Use simple block for other languages
309259
return <CodeBlock language={language} code={codeContent} />;
310260
}
311261

262+
console.log("Rendering inline code");
312263
# Inline code
313264
return <Code
314265
style={{

0 commit comments

Comments
 (0)