Skip to content

A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.

fix(claude): 面板页的语言跟插件(引擎)走,不跟浏览器

chipfightera493812b44df
diff --git a/plugin/src/panel-web.js b/plugin/src/panel-web.js
index 4d8a62f..c406b98 100644
--- a/plugin/src/panel-web.js
+++ b/plugin/src/panel-web.js
@@ -1,8 +1,9 @@
// Purpose: v0.4 — runs the panel (panel.html) as a page of its own for a Claude Code session: the engine serves the
// page at /__cam/panel?session=<id> with this script before the panel's own (proxy.ts), and the Claude plugin's mod
// links to it; it opens in a browser, Claude Desktop's own pane or another. It stands in for the MCP Apps host
-// (window.camHost): it answers ui/initialize with the browser's language, theme and height, and turns the panel's
-// tool calls into the engine's local panel API (/__cam/claude/…). The panel itself is the same file Codex shows.
+// (window.camHost): it answers ui/initialize with the plugin's language, the browser's theme and the window's height,
+// and turns the panel's tool calls into the engine's local panel API (/__cam/claude/…). The panel itself is the same
+// file Codex shows.
// Input: the panel's JSON-RPC messages; the session id in the page's address. Output: replies as message events.
(() => {
const session = new URLSearchParams(location.search).get("session") ?? "";
@@ -14,9 +15,31 @@
};
const query = (params) => new URLSearchParams({ session, ...params }).toString();
const darkQuery = window.matchMedia?.("(prefers-color-scheme: dark)");
- const context = () => ({ locale: navigator.language, theme: darkQuery?.matches ? "dark" : "light", containerDimensions: { height: window.innerHeight } });
+ // The panel's language is the plugin's (the engine's, as for the placeholders), as Codex gives it Codex's own; the
+ // browser's only until the engine answers.
+ let lang = null;
+ let told = null;
+ const context = () => {
+ told = lang ?? navigator.language;
+ return { locale: told, theme: darkQuery?.matches ? "dark" : "light", containerDimensions: { height: window.innerHeight } };
+ };
+ async function panel() {
+ const state = await api(`/__cam/claude/panel?${query({})}`);
+ if (typeof state?.lang === "string") {
+ lang = state.lang;
+ if (told !== null && told !== lang) {
+ told = lang;
+ changed({ locale: lang });
+ }
+ }
+ return state;
+ }
+ async function initialize(params) {
+ await panel().catch(() => null);
+ return { protocolVersion: params?.protocolVersion, hostContext: context() };
+ }
async function tool(name, args = {}) {
- if (name === "cam_panel") return { content: [], structuredContent: await api(`/__cam/claude/panel?${query({})}`) };
+ if (name === "cam_panel") return { content: [], structuredContent: await panel() };
if (name === "cam_set_selection") {
return { content: [], structuredContent: await api(`/__cam/claude/select?${query({})}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(args) }) };
}
@@ -32,7 +55,7 @@
post(message) {
// Notifications (the frame's height, initialized) need no answer here: the page has the whole window.
if (message.id === undefined) return;
- const answer = message.method === "ui/initialize" ? Promise.resolve({ protocolVersion: message.params?.protocolVersion, hostContext: context() })
+ const answer = message.method === "ui/initialize" ? initialize(message.params)
: message.method === "tools/call" ? tool(message.params?.name, message.params?.arguments)
: Promise.resolve({});
answer.then(