All MicroEvals
import { useMutation, useQuery, type QueryKey, type ...
Create MicroEval

import { useMutation, useQuery, type QueryKey, type ...

Prompt

import { useMutation, useQuery, type QueryKey, type UseQueryOptions, } from '@tanstack/react-query'; export type ChatMessage = { role: 'user' | 'assistant'; content: string; }; export type WorkspaceEntry = { path: string; name: string; kind: 'file' | 'directory'; size: number; language?: string | null; }; export type WorkspaceFile = { path: string; content: string; language?: string | null; size?: number; modifiedAt?: string; revision?: string; bytesWritten?: number; }; export type WorkspaceTree = { root: string; entries: WorkspaceEntry[]; total: number; offset: number; limit: number; truncated: boolean; }; export type AgentStatus = { model: string; endpoint: string; configured: boolean; maxSteps: number; wallMs: number; capabilities: string[]; tools: string[]; }; export type Checkpoint = { id: string; label: string; createdAt: string; fileCount: number; totalBytes: number; [key: string]: unknown; }; export type CommandResult = { stdout: string; stderr: string; exitCode: number; durationMs: number; command: string; cwd?: string; timedOut?: boolean; cancelled?: boolean; }; type QueryOverrides<T> = { query?: Pick< UseQueryOptions<T, Error, T, QueryKey>, 'enabled' | 'queryKey' | 'staleTime' | 'refetchOnWindowFocus' >; }; async function requestJson<T>(input: RequestInfo | URL, init?: RequestInit): Promise<T> { const response = await fetch(input, { ...init, headers: { Accept: 'application/json', ...(init?.body ? { 'Content-Type': 'application/json' } : {}), ...init?.headers, }, }); const text = await response.text(); let payload: unknown = null; if (text) { try { payload = JSON.parse(text); } catch { payload = text; } } if (!response.ok) { const message = typeof payload === 'object' && payload !== null && 'error' in payload && typeof payload.error === 'string' ? payload.error : typeof payload === 'string' ? payload : `Request failed with HTTP ${response.status}.`; throw new Error(message); } return payload as T; } function normalizeWorkspaceEntry(entry: Partial<WorkspaceEntry>): WorkspaceEntry { const path = String(entry.path ?? '').replace(/^\/+/, '').replace(/\/+$/, ''); const name = entry.name || path.split('/').filter(Boolean).at(-1) || path; return { path, name, kind: entry.kind === 'directory' ? 'directory' : 'file', size: Number.isFinite(Number(entry.size)) ? Number(entry.size) : 0, language: entry.language ?? null, }; } function normalizeWorkspaceTree(payload: WorkspaceTree): WorkspaceTree { return { root: String(payload?.root ?? ''), entries: Array.isArray(payload?.entries) ? payload.entries.map((entry) => normalizeWorkspaceEntry(entry)) : [], total: Number(payload?.total ?? 0), offset: Number(payload?.offset ?? 0), limit: Number(payload?.limit ?? 0), truncated: Boolean(payload?.truncated), }; } export function getGetWorkspaceTreeQueryKey(): QueryKey { return ['/api/workspace/tree']; } export function getGetAgentStatusQueryKey(): QueryKey { return ['/api/agent/status']; } export function getGetWorkspaceFileQueryKey(params: { path: string }): QueryKey { return ['/api/workspace/file', params.path]; } export function getListCheckpointsQueryKey(): QueryKey { return ['/api/workspace/checkpoints']; } export function useGetWorkspaceTree(overrides?: QueryOverrides<WorkspaceTree>) { const queryKey = overrides?.query?.queryKey ?? getGetWorkspaceTreeQueryKey(); return useQuery({ queryKey, queryFn: async () => normalizeWorkspaceTree(await requestJson<WorkspaceTree>('/api/workspace/tree')), ...overrides?.query, }); } export function useGetAgentStatus(overrides?: QueryOverrides<AgentStatus>) { const queryKey = overrides?.query?.queryKey ?? getGetAgentStatusQueryKey(); return useQuery({ queryKey, queryFn: () => requestJson<AgentStatus>('/api/agent/status'), ...overrides?.query, }); } export function useGetWorkspaceFile( params: { path: string }, overrides?: QueryOverrides<WorkspaceFile>, ) { const queryKey = overrides?.query?.queryKey ?? getGetWorkspaceFileQueryKey(params); return useQuery({ queryKey, queryFn: () => requestJson<WorkspaceFile>(`/api/workspace/file?path=${encodeURIComponent(params.path)}`), ...overrides?.query, }); } export function useListCheckpoints(overrides?: QueryOverrides<Checkpoint[]>) { const queryKey = overrides?.query?.queryKey ?? getListCheckpointsQueryKey(); return useQuery({ queryKey, queryFn: async () => { const payload = await requestJson<{ checkpoints?: Checkpoint[] }>('/api/workspace/checkpoints'); return Array.isArray(payload?.checkpoints) ? payload.checkpoints : []; }, ...overrides?.query, }); } type MutationVariables<T> = { data: T }; export function useWriteWorkspaceFile() { return useMutation({ mutationFn: (variables: MutationVariables<{ path: string; content: string; revision?: string }>) => requestJson<WorkspaceFile>('/api/workspace/file', { method: 'POST', body: JSON.stringify(variables.data), }), }); } export function useRunWorkspaceCommand() { return useMutation({ mutationFn: (variables: MutationVariables<{ command: string; cwd?: string; timeoutMs?: number }>) => requestJson<CommandResult>('/api/workspace/command', { method: 'POST', body: JSON.stringify(variables.data), }), }); } export function useCreateCheckpoint() { return useMutation({ mutationFn: (variables: MutationVariables<{ label: string }>) => requestJson<Checkpoint>('/api/workspace/checkpoints', { method: 'POST', body: JSON.stringify(variables.data), }), }); } export function useRestoreCheckpoint() { return useMutation({ mutationFn: (variables: { id: string }) => requestJson<Checkpoint>(`/api/workspace/checkpoints/${encodeURIComponent(variables.id)}/restore`, { method: 'POST', body: JSON.stringify({}), }), }); } Send back the complete code with all the fixes. Fix each of the listed errors one by one, making sure to actually correct them so that there are 0 errors remaining. Keep the original imports, since the files exist. Write out every single character; do not abbreviate anything. Fix every error. There must be exactly one file. Do not write anything else; just output the complete code, and it must not contain any comments. Never, under any circumstances, use simplified, substitute, dummy, simulated, or fake code. Write the entire file as complete, unabridged, production-ready code in a single code block. It must be 100% error-free, a complete, error-free file, and must be submitted as a downloadable file. These requirements are mandatory and must be strictly adhered to. If no list of errors is provided, you must find all the errors and fix them. If there were comments in the original code, delete them. And most importantly: YOU MUST NEVER SIMPLIFY!