"use strict";
const INTENT_URL = "/api/session/intent";
const OPEN_URL = "/api/session/open";
function fetchImpl(override) {
if (typeof override === "function") return override;
if (typeof fetch === "function") return fetch;
return null;
}
export async function postIntent(intent, override) {
const f = fetchImpl(override);
if (!f || !intent) return [];
try {
const res = await f(INTENT_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(intent),
});
if (!res || !res.ok) return [];
const data = await res.json();
return (data && Array.isArray(data.patches) && data.patches) || [];
} catch (_err) {
return [];
}
}
export async function openSession(resource, pane, override) {
const f = fetchImpl(override);
if (!f) return null;
const query = `?resource=${encodeURIComponent(resource)}&pane=${encodeURIComponent(pane)}`;
try {
const res = await f(OPEN_URL + query, { method: "GET" });
if (!res || !res.ok) return null;
const data = await res.json();
return (data && data.scene) || null;
} catch (_err) {
return null;
}
}