From bacf6f2869326c1199fd9449015008e0a97e5669 Mon Sep 17 00:00:00 2001 From: Chad Curtis Date: Wed, 8 Oct 2025 04:44:13 +0000 Subject: [PATCH] Cleanup --- src/components/Shakespeare/ChatPane.tsx | 5 ++++- src/lib/tools/BuildProjectTool.test.ts | 12 ++---------- src/lib/tools/BuildProjectTool.ts | 9 ++++----- src/pages/SystemSettings.tsx | 17 ++++++++++++----- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 6d08e63f..e6f965f1 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -13,6 +13,7 @@ import { useAISettings } from '@/hooks/useAISettings'; import { useFS } from '@/hooks/useFS'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useKeepAlive } from '@/hooks/useKeepAlive'; +import { useAppContext } from '@/hooks/useAppContext'; import { useAIChat } from '@/hooks/useAIChat'; import { useProviderModels } from '@/hooks/useProviderModels'; import { ModelSelector } from '@/components/ModelSelector'; @@ -77,6 +78,7 @@ export const ChatPane = forwardRef(({ const { git } = useGit(); const { user } = useCurrentUser(); const { models } = useProviderModels(); + const { config } = useAppContext(); const [input, setInput] = useState(''); const [showScrollToBottom, setShowScrollToBottom] = useState(false); const [attachedFiles, setAttachedFiles] = useState([]); @@ -133,6 +135,7 @@ export const ChatPane = forwardRef(({ // Initialize AI chat with tools const cwd = `/projects/${projectId}`; + const esmUrlRef = useRef(config.esmUrl); const customTools = useMemo(() => { const baseTools = { git_commit: new GitCommitTool(fs, cwd, git), @@ -141,7 +144,7 @@ export const ChatPane = forwardRef(({ text_editor_str_replace: new TextEditorStrReplaceTool(fs, cwd), npm_add_package: new NpmAddPackageTool(fs, cwd), npm_remove_package: new NpmRemovePackageTool(fs, cwd), - build_project: new BuildProjectTool(fs, cwd), + build_project: new BuildProjectTool(fs, cwd, esmUrlRef.current), typecheck: new TypecheckTool(fs, cwd), nostr_read_nip: new NostrReadNipTool(), nostr_fetch_event: new NostrFetchEventTool(), diff --git a/src/lib/tools/BuildProjectTool.test.ts b/src/lib/tools/BuildProjectTool.test.ts index b9a1585d..980de28d 100644 --- a/src/lib/tools/BuildProjectTool.test.ts +++ b/src/lib/tools/BuildProjectTool.test.ts @@ -1,7 +1,6 @@ import { describe, it, expect, beforeEach, vi } from 'vitest'; import { BuildProjectTool } from './BuildProjectTool'; import type { JSRuntimeFS } from '../JSRuntime'; -import type { AppConfig } from '../../contexts/AppContext'; // Mock the build functions vi.mock('../build', () => ({ @@ -12,7 +11,6 @@ import { buildProject } from '../build'; describe('BuildProjectTool', () => { let mockFS: JSRuntimeFS; - let mockConfig: AppConfig; let tool: BuildProjectTool; beforeEach(() => { @@ -26,15 +24,9 @@ describe('BuildProjectTool', () => { mkdir: vi.fn(), } as unknown as JSRuntimeFS; - mockConfig = { - theme: 'light', - relayUrl: 'wss://relay.nostr.band', - deployServer: 'shakespeare.wtf', - esmUrl: 'https://esm.shakespeare.diy', - language: 'en', - }; - tool = new BuildProjectTool(mockFS, '/test/project', mockConfig); + + tool = new BuildProjectTool(mockFS, '/test/project', 'https://esm.shakespeare.diy'); }); it('should have correct description', () => { diff --git a/src/lib/tools/BuildProjectTool.ts b/src/lib/tools/BuildProjectTool.ts index 35762892..c250d945 100644 --- a/src/lib/tools/BuildProjectTool.ts +++ b/src/lib/tools/BuildProjectTool.ts @@ -1,26 +1,25 @@ import type { Tool } from "./Tool"; import type { JSRuntimeFS } from "../JSRuntime"; -import type { AppConfig } from "../../contexts/AppContext"; import { buildProject } from "../build"; export class BuildProjectTool implements Tool { private fs: JSRuntimeFS; private cwd: string; - private config: AppConfig; + private esmUrl: string; readonly description = "Build the project using esbuild. Creates optimized production files in the dist directory."; - constructor(fs: JSRuntimeFS, cwd: string, config: AppConfig) { + constructor(fs: JSRuntimeFS, cwd: string, esmUrl: string) { this.fs = fs; this.cwd = cwd; - this.config = config; + this.esmUrl = esmUrl; } async execute(): Promise { try { // Build and write the project files const result = await buildProject({ - esmUrl: this.config.esmUrl, + esmUrl: this.esmUrl, fs: this.fs, projectPath: this.cwd, domParser: new DOMParser(), diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index 756ed080..ef0fecd2 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -1,5 +1,6 @@ import { Settings2, ArrowLeft, Globe } from "lucide-react"; import { useTranslation } from 'react-i18next'; +import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -13,6 +14,7 @@ export function SystemSettings() { const isMobile = useIsMobile(); const navigate = useNavigate(); const { config, updateConfig } = useAppContext(); + const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl); return (
@@ -60,11 +62,16 @@ export function SystemSettings() { updateConfig((current) => ({ - ...current, - esmUrl: e.target.value, - }))} + value={esmUrlInput} + onChange={(e) => { + // Strip trailing slash on save. + const value = e.target.value; + setEsmUrlInput(value); + updateConfig((current) => ({ + ...current, + esmUrl: value.replace(/\/+$/, ''), + })); + }} className="w-full max-w-xs" placeholder="https://esm.shakespeare.diy" />