Skip to content

Commit

Permalink
push
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltan Erdos committed Sep 30, 2024
1 parent 292370d commit ea03109
Show file tree
Hide file tree
Showing 8 changed files with 3,339 additions and 37 deletions.
8 changes: 3 additions & 5 deletions packages/code/src/@/components/app/diff-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { editor } from "@/external/monaco-editor";
import { useThrottle } from "@uidotdev/usehooks";
import React, { memo, useEffect, useRef } from "react";

export interface DiffEditorProps {
Expand All @@ -15,8 +14,8 @@ export interface DiffEditorProps {


export const DiffEditor: React.FC<DiffEditorProps> = memo(({
original: _original = "",
modified: _modified = "",
original = "",
modified = "",
minHeight,
maxHeight,
editorHeight= minHeight || 200,
Expand All @@ -26,8 +25,7 @@ export const DiffEditor: React.FC<DiffEditorProps> = memo(({
const containerRef = useRef<HTMLDivElement>(null);
const diffEditorRef = useRef<editor.IStandaloneDiffEditor | null>(null);

const original = useThrottle(_original, 100);
const modified = useThrottle(_modified, 100);



useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/code/src/hooks/messageProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function createOnUpdateFunction({
lastSuccessCut: startPos,
hash: md5(lastCode),
});
console.table(mod.actions[mod.actions.length - 1]);
// console.table(mod.actions[mod.actions.length - 1]);
} else {
mod.actions.push({
TRIED: TRIED + 1,
Expand Down
42 changes: 19 additions & 23 deletions packages/code/src/hooks/useErrorHandling.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { throttle } from "es-toolkit";
import { useCallback, useState } from "react";

export const useErrorHandling = (engine: string) => {
Expand All @@ -7,30 +6,27 @@ export const useErrorHandling = (engine: string) => {
>(null);

const throttledTypeCheck = useCallback(
throttle(
async (initialLoadRef: React.MutableRefObject<boolean>) => {
if (engine === "monaco") {
const { editor, languages } = await import("@/external/monaco-editor");
const model = editor.getModels()[0];
const worker = await languages.typescript
.getTypeScriptWorker();
const client = await worker(model.uri);
const diagnostics = await client.getSemanticDiagnostics(
model.uri.toString(),
);
async (initialLoadRef: React.MutableRefObject<boolean>) => {
if (engine === "monaco") {
const { editor, languages } = await import("@/external/monaco-editor");
const model = editor.getModels()[0];
const worker = await languages.typescript
.getTypeScriptWorker();
const client = await worker(model.uri);
const diagnostics = await client.getSemanticDiagnostics(
model.uri.toString(),
);

if (diagnostics.length > 0 && !initialLoadRef.current) {
Object.assign(globalThis, { diagnostics });
console.error("TypeScript error:", diagnostics);
setErrorType("typescript");
} else {
setErrorType((prevErrorType) => prevErrorType === "typescript" ? null : prevErrorType);
}
if (diagnostics.length > 0 && !initialLoadRef.current) {
Object.assign(globalThis, { diagnostics });
console.error("TypeScript error:", diagnostics);
setErrorType("typescript");
} else {
setErrorType((prevErrorType) => prevErrorType === "typescript" ? null : prevErrorType);
}
initialLoadRef.current = false;
},
1000,
),
}
initialLoadRef.current = false;
},
[engine],
);

Expand Down
5 changes: 2 additions & 3 deletions packages/code/src/services/AIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { messagesPush } from "@/lib/chat-utils";
import { ContextManager } from "@/lib/context-manager";
import type { Message, MessageContent } from "@/lib/interfaces";
import type { ICode } from "@/lib/interfaces";
import { throttle } from "es-toolkit"; // Reverted back to es-toolkit
import { anthropicSystem, gptSystem, reminder } from "../config/aiConfig";
import { extractCodeStructure, extractCurrentTask } from "../utils/contextUtils";

Expand Down Expand Up @@ -122,8 +121,8 @@ export class AIService {
throw new Error("Response body is not readable!");
}

const throttleUpdate = throttle(onUpdate, this.config.updateThrottleMs);
const content = await this.streamHandler.handleStream(reader, throttleUpdate);
// const throttleUpdate = (onUpdate, this.config.updateThrottleMs);
const content = await this.streamHandler.handleStream(reader, onUpdate);
return content;
} catch (error) {
console.error("Error handling streaming response:", error);
Expand Down
9 changes: 4 additions & 5 deletions packages/code/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { processImage } from "@/lib/process-image";
import { renderApp } from "@/lib/render-app";
import { prettierCss } from "@/lib/shared";
import { wait } from "@/lib/wait";
import { throttle } from "es-toolkit";
import { renderPreviewWindow } from "./renderPreviewWindow";
import { mineFromCaches } from "./utils/mineCss";

Expand Down Expand Up @@ -222,10 +221,10 @@ export const main = async () => {
(() => {
try {
cSess.sub(
throttle((sess: ICodeSession) => {
(sess: ICodeSession) => {
const { i, code, transpiled } = sess;
console.table({ i, code, transpiled });
}, 100),
},
);
} catch (error) {
console.error("Error in cSess subscription:", error);
Expand All @@ -235,13 +234,13 @@ export const main = async () => {
const handleDehydratedPage = () => {
try {
cSess.sub(
throttle((sess: ICodeSession) => {
(sess: ICodeSession) => {
const { html, css } = sess;
const root = document.getElementById("embed");
if (root && html && css) {
root.innerHTML = `<style>${css}</style><div>${html}</div>`;
}
}, 100),
},
);
} catch (error) {
console.error("Error handling dehydrated page:", error);
Expand Down
Binary file not shown.
Loading

0 comments on commit ea03109

Please sign in to comment.