Skip to content

Commit 545b122

Browse files
committed
propagate a query parameter for ai server changes
1 parent 55b4f73 commit 545b122

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

pxtlib/browserutils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,21 @@ namespace pxt.BrowserUtils {
14511451
return url;
14521452
}
14531453

1454+
export function getCopilotServerParam(): "ppe" | "prod" | undefined {
1455+
if (typeof window === "undefined") return undefined;
1456+
const query = pxt.Util.parseQueryString(window.location.search || "");
1457+
const value = (query["useCopilotServer"] || "").toLowerCase();
1458+
return value === "ppe" || value === "prod" ? (value as "ppe" | "prod") : undefined;
1459+
}
1460+
1461+
export function appendCopilotServerQueryParam(url: string): string {
1462+
const value = getCopilotServerParam();
1463+
if (!value) return url;
1464+
const params = new URLSearchParams();
1465+
params.set("useCopilotServer", value);
1466+
return appendUrlQueryParams(url, params);
1467+
}
1468+
14541469
export function legacyCopyText(element: HTMLInputElement | HTMLTextAreaElement) {
14551470
element.focus();
14561471
element.setSelectionRange(0, 9999);

teachertool/src/services/backendRequests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function loadTestableCollectionFromDocsAsync<T>(fileNames: string[]
9090
}
9191

9292
export async function askCopilotQuestionAsync(shareId: string, question: string): Promise<string | undefined> {
93-
const url = `/api/copilot/question`;
93+
const url = pxt.BrowserUtils.appendCopilotServerQueryParam(`/api/copilot/question`);
9494

9595
question = pxt.Util.cleanData(question);
9696

webapp/src/cloud.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@ export async function aiErrorExplainRequest(
697697
outputFormat: "tour_json" | "text",
698698
locale: string
699699
): Promise<string | undefined> {
700-
const startUrl = `/api/copilot/startexplainerror`;
701-
const statusUrl = `/api/copilot/explainerrorstatus`;
700+
const startUrl = pxt.BrowserUtils.appendCopilotServerQueryParam(`/api/copilot/startexplainerror`);
701+
const statusUrl = pxt.BrowserUtils.appendCopilotServerQueryParam(`/api/copilot/explainerrorstatus`);
702702

703703
const data = { lang, code, errors, target, outputFormat, locale };
704704

0 commit comments

Comments
 (0)