This commit is contained in:
2025-11-03 20:25:09 -08:00
parent eb084e1f07
commit 84f64cfd46
4 changed files with 18 additions and 35 deletions

View File

@@ -2,7 +2,7 @@ services:
webui: webui:
image: minimax image: minimax
ports: ports:
- "3000:3000" - "4000:3000"
volumes: volumes:
- ./data:/app/data - ./data:/app/data
env_file: env_file:

View File

@@ -28,7 +28,6 @@ export async function GET(request: NextRequest) {
const filename = `${name}.rhai`; const filename = `${name}.rhai`;
const filepath = join(saveDir, filename); const filepath = join(saveDir, filename);
// Check if file exists
if (!existsSync(filepath)) { if (!existsSync(filepath)) {
return NextResponse.json( return NextResponse.json(
{ error: `Script "${name}" not found` }, { error: `Script "${name}" not found` },
@@ -36,7 +35,6 @@ export async function GET(request: NextRequest) {
); );
} }
// Read and return file content
const content = await readFile(filepath, "utf8"); const content = await readFile(filepath, "utf8");
return NextResponse.json({ return NextResponse.json({

View File

@@ -1,31 +1,41 @@
import { NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { readdir } from "fs/promises"; import { readdir } from "fs/promises";
import { join } from "path";
import { existsSync } from "fs"; import { existsSync } from "fs";
import { SAVE_CONFIG } from "@/lib/saveConfig"; import { SAVE_CONFIG } from "@/lib/saveConfig";
export async function GET() { const headers = {
"Cache-Control": "no-store, no-cache, must-revalidate, proxy-revalidate",
Pragma: "no-cache",
Expires: "0",
};
export async function GET(_request: NextRequest) {
try { try {
const saveDir = SAVE_CONFIG.SAVE_DIRECTORY; const saveDir = SAVE_CONFIG.SAVE_DIRECTORY;
console.log(saveDir);
// If save directory doesn't exist, return empty array // If save directory doesn't exist, return empty array
if (!existsSync(saveDir)) { if (!existsSync(saveDir)) {
return NextResponse.json({ scripts: [] }); return NextResponse.json({ scripts: [] }, { headers });
} }
// Read directory and filter for .rhai files // Read directory and filter for .rhai files
const files = await readdir(saveDir); const files = await readdir(saveDir);
console.log(files);
const scripts = files const scripts = files
.filter((file) => file.endsWith(".rhai")) .filter((file) => file.endsWith(".rhai"))
.map((file) => file.replace(".rhai", "")) .map((file) => file.replace(".rhai", ""))
.sort(); // Sort alphabetically .sort(); // Sort alphabetically
return NextResponse.json({ scripts }); return NextResponse.json({ scripts }, { headers });
} catch (error) { } catch (error) {
console.error("List scripts error:", error); console.error("List scripts error:", error);
return NextResponse.json( return NextResponse.json(
{ error: "Failed to list scripts" }, { error: "Failed to list scripts" },
{ status: 500 } { status: 500, headers }
); );
} }
} }

View File

@@ -42,28 +42,6 @@ fn step_max(board) {
const AGENTS = { const AGENTS = {
// special-cased below // special-cased below
Self: undefined, Self: undefined,
Random: `fn random_action(board) {
let symb = rand_symb();
let pos = rand_int(0, 10);
let action = Action(symb, pos);
while !board.can_play(action) {
let symb = rand_symb();
let pos = rand_int(0, 10);
action = Action(symb, pos);
}
return action;
}
fn step_min(board) {
return random_action(board);
}
fn step_max(board) {
return random_action(board);
}`,
}; };
export default function Playground() { export default function Playground() {
@@ -126,10 +104,7 @@ export default function Playground() {
// Combine hardcoded agents with saved scripts, ensuring Self and Random are first // Combine hardcoded agents with saved scripts, ensuring Self and Random are first
const combinedAgents = [ const combinedAgents = [
"Self", "Self",
"Random", ...Object.keys(AGENTS).filter((key) => key !== "Self"),
...Object.keys(AGENTS).filter(
(key) => key !== "Self" && key !== "Random"
),
...scripts, ...scripts,
]; ];