mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Cleanup
This commit is contained in:
1 parent
9a6058fedb
commit
bacf6f2869
4 files changed
+22
-21
No files matched your search
@@ -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<ChatPaneRef, ChatPaneProps>(({
|
||||
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<File[]>([]);
|
||||
@@ -133,6 +135,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
|
||||
// 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<ChatPaneRef, ChatPaneProps>(({
|
||||
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(),
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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<void> {
|
||||
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<string> {
|
||||
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(),
|
||||
|
||||
@@ -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 (
|
||||
<div className="p-6 space-y-6">
|
||||
@@ -60,11 +62,16 @@ export function SystemSettings() {
|
||||
<Input
|
||||
id="esm-url"
|
||||
type="url"
|
||||
value={config.esmUrl}
|
||||
onChange={(e) => 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"
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user