From 73f43efbe74004e291c70edbac4c308a3e0c122c Mon Sep 17 00:00:00 2001 From: parththakkar106 Date: Mon, 20 Jul 2026 19:11:39 +0530 Subject: [PATCH] Let the in-play Scripts panel show each script's code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The panel only showed a name + on/off toggle, so demo (server-owned) scripts — which never appear on the personal Scripts page — had no in-app way to inspect their code. AdventureScriptOut already ships the hook sources, so add a "View code" expander that renders the non-empty hooks (library / onInput / onModelContext / onOutput) read-only. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01TEpWMjnfPqzZ13nPMoGhs5 --- frontend/src/index.css | 39 ++++++++++++++++++++++++++++++ frontend/src/pages/Play.jsx | 47 +++++++++++++++++++++++++++++++------ 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index 39832f0..cc6b757 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -440,6 +440,45 @@ button:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: n animation: panel-in 0.25s ease both; } +/* ---------- In-play script viewer ---------- */ + +.adv-script { + border-bottom: 1px solid var(--border); + padding: 10px 0; +} +.adv-script-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; } +.adv-script-desc { font-size: 0.82rem; margin-top: 4px; } +.linklike { + border: none; + background: none; + padding: 0; + color: var(--accent-bright); + font-size: 0.8rem; + cursor: pointer; + flex-shrink: 0; +} +.linklike:hover { text-decoration: underline; } +.adv-script-code { margin-top: 8px; } +.adv-script-hook { + font-size: 0.72rem; + text-transform: uppercase; + letter-spacing: 0.08em; + color: var(--text-dim); + margin: 8px 0 2px; +} +.adv-script-code pre { + margin: 0; + padding: 10px; + background: var(--bg-input); + border: 1px solid var(--border); + border-radius: 6px; + overflow-x: auto; + font-family: var(--font-mono, monospace); + font-size: 0.76rem; + line-height: 1.5; + white-space: pre; +} + /* ---------- Left status drawer (script state) ---------- */ .status-drawer { diff --git a/frontend/src/pages/Play.jsx b/frontend/src/pages/Play.jsx index 87fe660..1baa335 100644 --- a/frontend/src/pages/Play.jsx +++ b/frontend/src/pages/Play.jsx @@ -283,8 +283,16 @@ function MemoryPanel({ adventure, setAdventure, refreshKey }) { ) } +const SCRIPT_HOOKS = [ + ['Shared library', 'library_js'], + ['onInput', 'input_js'], + ['onModelContext', 'context_js'], + ['onOutput', 'output_js'], +] + function ScriptsPanel({ advId }) { const [scripts, setScripts] = useState(null) + const [openId, setOpenId] = useState(null) useEffect(() => { api.listAdventureScripts(advId).then(setScripts).catch(() => setScripts([])) @@ -306,13 +314,38 @@ function ScriptsPanel({ advId }) { } return (
- {scripts.map((s) => ( - - ))} + {scripts.map((s) => { + const hooks = SCRIPT_HOOKS.filter(([, f]) => (s[f] || '').trim()) + const open = openId === s.id + return ( +
+
+ + +
+ {s.description &&
{s.description}
} + {open && ( +
+ {hooks.length === 0 ? ( +
This script has no code.
+ ) : ( + hooks.map(([label, f]) => ( +
+
{label}
+
{s[f]}
+
+ )) + )} +
+ )} +
+ ) + })}
) }