mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
Preserve Go and Zen OAuth routing while fixing authentication, secret redaction, streaming, transport, and configuration issues. Refresh README and management guides in four languages while preserving sponsors, LinuxDo acknowledgements, and Linux/Docker quick start instructions.
33 lines
767 B
JavaScript
33 lines
767 B
JavaScript
// Shared console state with a minimal change subscription so page modules
|
|
// re-render independently.
|
|
const state = {
|
|
config: null,
|
|
monitor: null,
|
|
debug: null,
|
|
lastPlayground: null,
|
|
};
|
|
|
|
const listeners = new Map();
|
|
|
|
export function get(key) {
|
|
return state[key];
|
|
}
|
|
|
|
export function clear() {
|
|
for (const key of Object.keys(state)) state[key] = null;
|
|
}
|
|
|
|
export function set(key, value) {
|
|
state[key] = value;
|
|
const subscribers = listeners.get(key);
|
|
if (!subscribers) return;
|
|
for (const handler of [...subscribers]) handler(value);
|
|
}
|
|
|
|
export function on(key, handler) {
|
|
let subscribers = listeners.get(key);
|
|
if (!subscribers) listeners.set(key, (subscribers = new Set()));
|
|
subscribers.add(handler);
|
|
return () => subscribers.delete(handler);
|
|
}
|