feat: add advanced context actions and optional translation

This commit is contained in:
golem
2026-10-05 15:38:16 -06:00
parent 33c4dad00f
commit 5308932bf1
34 changed files with 1579 additions and 159 deletions
+46
View File
@@ -0,0 +1,46 @@
import { normalizeLanguage } from '../lib/settings.js';
import { prepareAction } from '../lib/prepare-action.js';
export function createDialogController({ payload, open, render, close }) {
let request = structuredClone(payload.request);
let state = { ...payload.preparation, busy: false };
let cancelled = false;
const show = () => render({ ...state });
show();
return {
cancel() {
if (state.busy || cancelled) return;
cancelled = true;
request = null;
close();
},
async submit(language) {
if (cancelled || state.busy || state.kind === 'error') return;
if (state.kind === 'language') {
const normalized = normalizeLanguage(language);
if (!normalized) {
state.message = 'Enter a language using up to 100 characters.';
show(); return;
}
request.language = normalized;
state = { ...prepareAction(request), busy: false };
show();
if (state.kind !== 'ready') return;
}
if (!['ready', 'shortened'].includes(state.kind)) return;
state.busy = true;
state.message = '';
show();
try {
await open(state.url, request.settings.openIn);
cancelled = true;
request = null;
close();
} catch {
state.busy = false;
state.message = 'Could not open ChatGPT. Please try again or cancel.';
show();
}
},
};
}