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
+9 -9
View File
@@ -2,7 +2,7 @@
//
// Every ChatGPT parameter below is undocumented by OpenAI and has broken before.
// This module's contract is only that it emits a well-formed URL; whether
// ChatGPT honours model / temporary-chat / hints is out of our control, which is
// ChatGPT honours temporary-chat / hints is out of our control, which is
// why each is independently omittable and every label is hint-strength.
//
// The root path is mandatory: chatgpt.com/search began returning 404 in
@@ -15,7 +15,7 @@ export const MAX_URL_CHARS = 8000;
// Fraction of the kept text within which a whitespace cut is preferred.
const WHITESPACE_WINDOW = 0.9;
function applyTemplate(template, query) {
export function applyTemplate(template, query) {
if (query === "") {
return "";
}
@@ -33,10 +33,6 @@ function applyTemplate(template, query) {
}
function addOptionalParams(url, settings) {
const model = typeof settings.model === "string" ? settings.model.trim() : "";
if (model !== "") {
url.searchParams.set("model", model);
}
if (settings.temporaryChat) {
url.searchParams.set("temporary-chat", "true");
}
@@ -56,9 +52,6 @@ function lastWhitespaceIndex(text) {
}
// Returns the longest prefix of `prompt` whose finished URL fits the budget.
// The guarantee assumes `settings` came through mergeSettings(): only `q` is
// ever trimmed, so a model longer than MAX_MODEL_CHARS could blow the budget on
// its own and leave no room for `q` at all. Every real caller goes via load().
// Slicing happens by CODE POINT on the decoded string, so a surrogate pair can
// never be split and a percent-escape can never be severed (encoding happens
// afterwards, via URLSearchParams).
@@ -106,3 +99,10 @@ export function buildChatGptUrl(settings, rawQuery) {
addOptionalParams(url, settings);
return url.href;
}
// Encode a complete prompt without silently shortening it.
export function serializePrompt(settings, prompt) {
const url = new URL(BASE);
if (prompt) url.searchParams.set("q", prompt);
return addOptionalParams(url, settings).href;
}