diff --git a/content/scenario-builder/.gitignore b/content/scenario-builder/.gitignore new file mode 100644 index 0000000..5ef6a52 --- /dev/null +++ b/content/scenario-builder/.gitignore @@ -0,0 +1,41 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/versions + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# env files (can opt-in for committing if needed) +.env* + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/content/scenario-builder/eslint.config.mjs b/content/scenario-builder/eslint.config.mjs new file mode 100644 index 0000000..05e726d --- /dev/null +++ b/content/scenario-builder/eslint.config.mjs @@ -0,0 +1,18 @@ +import { defineConfig, globalIgnores } from "eslint/config"; +import nextVitals from "eslint-config-next/core-web-vitals"; +import nextTs from "eslint-config-next/typescript"; + +const eslintConfig = defineConfig([ + ...nextVitals, + ...nextTs, + // Override default ignores of eslint-config-next. + globalIgnores([ + // Default ignores of eslint-config-next: + ".next/**", + "out/**", + "build/**", + "next-env.d.ts", + ]), +]); + +export default eslintConfig; diff --git a/content/scenario-builder/next.config.ts b/content/scenario-builder/next.config.ts new file mode 100644 index 0000000..3e228d4 --- /dev/null +++ b/content/scenario-builder/next.config.ts @@ -0,0 +1,33 @@ +import type { NextConfig } from "next"; +import { networkInterfaces } from "os"; + +const getLocalIPs = () => { + const ips: string[] = ["localhost", "127.0.0.1"]; + const nets = networkInterfaces(); + for (const name of Object.keys(nets)) { + for (const net of nets[name] || []) { + if (net.family === "IPv4" && !net.internal) { + ips.push(net.address); + } + } + } + return ips; +}; + +const nextConfig: NextConfig = { + allowedDevOrigins: getLocalIPs(), + async headers() { + return [ + { + source: "/api/:path*", + headers: [ + { key: "Access-Control-Allow-Origin", value: "*" }, + { key: "Access-Control-Allow-Methods", value: "GET,POST,PUT,DELETE,OPTIONS" }, + { key: "Access-Control-Allow-Headers", value: "Content-Type, Authorization" }, + ], + }, + ]; + }, +}; + +export default nextConfig; diff --git a/content/scenario-builder/package.json b/content/scenario-builder/package.json new file mode 100644 index 0000000..e1fee15 --- /dev/null +++ b/content/scenario-builder/package.json @@ -0,0 +1,27 @@ +{ + "name": "scenario-builder", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "eslint" + }, + "dependencies": { + "next": "16.2.10", + "react": "19.2.4", + "react-dom": "19.2.4", + "@omnia/core": "workspace:*" + }, + "devDependencies": { + "@tailwindcss/postcss": "^4", + "@types/node": "^20", + "@types/react": "^19", + "@types/react-dom": "^19", + "eslint": "^9", + "eslint-config-next": "16.2.10", + "tailwindcss": "^4", + "typescript": "^5" + } +} diff --git a/content/scenario-builder/postcss.config.mjs b/content/scenario-builder/postcss.config.mjs new file mode 100644 index 0000000..61e3684 --- /dev/null +++ b/content/scenario-builder/postcss.config.mjs @@ -0,0 +1,7 @@ +const config = { + plugins: { + "@tailwindcss/postcss": {}, + }, +}; + +export default config; diff --git a/content/scenario-builder/public/file.svg b/content/scenario-builder/public/file.svg new file mode 100644 index 0000000..004145c --- /dev/null +++ b/content/scenario-builder/public/file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/scenario-builder/public/globe.svg b/content/scenario-builder/public/globe.svg new file mode 100644 index 0000000..567f17b --- /dev/null +++ b/content/scenario-builder/public/globe.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/scenario-builder/public/next.svg b/content/scenario-builder/public/next.svg new file mode 100644 index 0000000..5174b28 --- /dev/null +++ b/content/scenario-builder/public/next.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/scenario-builder/public/vercel.svg b/content/scenario-builder/public/vercel.svg new file mode 100644 index 0000000..7705396 --- /dev/null +++ b/content/scenario-builder/public/vercel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/scenario-builder/public/window.svg b/content/scenario-builder/public/window.svg new file mode 100644 index 0000000..b2b2a44 --- /dev/null +++ b/content/scenario-builder/public/window.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/content/scenario-builder/src/app/api/world/route.ts b/content/scenario-builder/src/app/api/world/route.ts new file mode 100644 index 0000000..d3badad --- /dev/null +++ b/content/scenario-builder/src/app/api/world/route.ts @@ -0,0 +1,127 @@ +import { NextResponse } from "next/server"; +import Database from "better-sqlite3"; +import { WorldState, Entity, SQLiteRepository, AttributeVisibility } from "@omnia/core"; +import path from "path"; + +const DB_PATH = path.resolve("/home/sortedcord/Projects/omnia_umbrella/omnia/omnia.db"); + +function getRepo() { + const db = new Database(DB_PATH); + // Enable foreign keys + db.exec("PRAGMA foreign_keys = ON;"); + return { repo: new SQLiteRepository(db), db }; +} + +export async function GET(request: Request) { + try { + const { searchParams } = new URL(request.url); + const id = searchParams.get("id"); + + const { repo, db } = getRepo(); + + try { + if (id) { + const world = repo.loadWorldState(id); + if (!world) { + return NextResponse.json({ error: `World with ID ${id} not found` }, { status: 404 }); + } + + // Serialize world + const serialized = { + id: world.id, + attributes: Array.from(world.attributes.values()).map(attr => ({ + name: attr.name, + value: attr.getValue(), + visibility: attr.getVisibility(), + allowedEntities: Array.from(attr.getAllowedEntities()) + })), + entities: Array.from(world.entities.values()).map(entity => ({ + id: entity.id, + attributes: Array.from(entity.attributes.values()).map(attr => ({ + name: attr.name, + value: attr.getValue(), + visibility: attr.getVisibility(), + allowedEntities: Array.from(attr.getAllowedEntities()) + })) + })) + }; + return NextResponse.json(serialized); + } else { + // List all worlds + const rows = db.prepare("SELECT id FROM objects WHERE type = 'world'").all() as { id: string }[]; + const worlds = []; + for (const row of rows) { + const world = repo.loadWorldState(row.id); + if (world) { + const nameAttr = world.attributes.get("name")?.getValue() || "Unnamed World"; + worlds.push({ + id: world.id, + name: nameAttr + }); + } + } + return NextResponse.json({ worlds }); + } + } finally { + db.close(); + } + } catch (error) { + console.error("API GET Error:", error); + const message = error instanceof Error ? error.message : "Internal Server Error"; + return NextResponse.json({ error: message }, { status: 500 }); + } +} + +export async function POST(request: Request) { + try { + const payload = await request.json(); + if (!payload.id) { + return NextResponse.json({ error: "World ID is required" }, { status: 400 }); + } + + const { repo, db } = getRepo(); + + try { + const world = new WorldState(payload.id); + + // Add attributes to world + if (payload.attributes && Array.isArray(payload.attributes)) { + for (const attr of payload.attributes) { + world.addAttribute( + attr.name, + attr.value, + attr.visibility || AttributeVisibility.PUBLIC, + attr.allowedEntities ? new Set(attr.allowedEntities) : null + ); + } + } + + // Add entities to world + if (payload.entities && Array.isArray(payload.entities)) { + for (const ent of payload.entities) { + const entity = new Entity(ent.id); + if (ent.attributes && Array.isArray(ent.attributes)) { + for (const attr of ent.attributes) { + entity.addAttribute( + attr.name, + attr.value, + attr.visibility || AttributeVisibility.PRIVATE, + attr.allowedEntities ? new Set(attr.allowedEntities) : null + ); + } + } + world.addEntity(entity); + } + } + + repo.saveWorldState(world); + return NextResponse.json({ success: true, worldId: world.id }); + } finally { + db.close(); + } + } catch (error) { + console.error("API POST Error:", error); + const message = error instanceof Error ? error.message : "Internal Server Error"; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/content/scenario-builder/src/app/favicon.ico b/content/scenario-builder/src/app/favicon.ico new file mode 100644 index 0000000..718d6fe Binary files /dev/null and b/content/scenario-builder/src/app/favicon.ico differ diff --git a/content/scenario-builder/src/app/globals.css b/content/scenario-builder/src/app/globals.css new file mode 100644 index 0000000..fc83d7b --- /dev/null +++ b/content/scenario-builder/src/app/globals.css @@ -0,0 +1,6 @@ +body { + font-family: sans-serif; + padding: 10px; + background-color: white; + color: black; +} diff --git a/content/scenario-builder/src/app/layout.tsx b/content/scenario-builder/src/app/layout.tsx new file mode 100644 index 0000000..976eb90 --- /dev/null +++ b/content/scenario-builder/src/app/layout.tsx @@ -0,0 +1,33 @@ +import type { Metadata } from "next"; +import { Geist, Geist_Mono } from "next/font/google"; +import "./globals.css"; + +const geistSans = Geist({ + variable: "--font-geist-sans", + subsets: ["latin"], +}); + +const geistMono = Geist_Mono({ + variable: "--font-geist-mono", + subsets: ["latin"], +}); + +export const metadata: Metadata = { + title: "Create Next App", + description: "Generated by create next app", +}; + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( + +
{children} + + ); +} diff --git a/content/scenario-builder/src/app/page.tsx b/content/scenario-builder/src/app/page.tsx new file mode 100644 index 0000000..7ced5af --- /dev/null +++ b/content/scenario-builder/src/app/page.tsx @@ -0,0 +1,586 @@ +"use client"; + +import { useState, useEffect } from "react"; + +function generateUUID(): string { + if (typeof window !== "undefined" && window.crypto && window.crypto.randomUUID) { + return window.crypto.randomUUID(); + } + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0; + const v = c === "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); +} + +interface Attribute { + name: string; + value: string; + visibility: "PUBLIC" | "PRIVATE"; + allowedEntities: string[]; +} + +interface Entity { + id: string; + attributes: Attribute[]; +} + +interface WorldData { + id: string; + attributes: Attribute[]; + entities: Entity[]; +} + +export default function Home() { + const [worldsList, setWorldsList] = useState<{ id: string; name: string }[]>([]); + const [selectedWorldId, setSelectedWorldId] = useState| Attribute Name | +Value | +Visibility | +ACL (Allowed Entities for PRIVATE) | +Action | +
|---|---|---|---|---|
| {attr.name} | ++ updateWorldAttributeValue(attr.name, e.target.value)} + /> + | ++ + | +
+ {attr.visibility === "PRIVATE" ? (
+
+ {worldData.entities.length === 0 ? (
+ No entities in world to grant access to
+ ) : (
+ worldData.entities.map((e) => {
+ const entName = e.attributes.find(a => a.name === "name")?.value || e.id;
+ return (
+
+ );
+ })
+ )}
+
+ ) : (
+ N/A (Visible to all)
+ )}
+ |
+ + + | +
No entities found in this world. Click "+ Add New Entity" to add one.
+ ) : ( + worldData.entities.map((entity, index) => { + const entName = entity.attributes.find(a => a.name === "name")?.value || "Unnamed Entity"; + const entInputState = newEntityAttribute[entity.id] || { name: "", value: "", visibility: "PRIVATE" }; + + return ( +| Attribute Name | +Value | +Visibility | +ACL (Allowed Entities for PRIVATE) | +Action | +
|---|---|---|---|---|
| {attr.name} | ++ updateEntityAttributeValue(entity.id, attr.name, e.target.value)} + /> + | ++ + | +
+ {attr.visibility === "PRIVATE" ? (
+
+ {worldData.entities.filter(e => e.id !== entity.id).length === 0 ? (
+ No other entities in world to grant access to
+ ) : (
+ worldData.entities
+ .filter(e => e.id !== entity.id)
+ .map((e) => {
+ const otherName = e.attributes.find(a => a.name === "name")?.value || e.id;
+ return (
+
+ );
+ })
+ )}
+
+ ) : (
+ N/A (Visible to all)
+ )}
+ |
+ + + | +