fix frontend invoke result handling

This commit is contained in:
2026-07-19 13:08:00 -03:00
parent aa6db7ee0b
commit c585055a32

View File

@@ -1,6 +1,13 @@
export const CONFIG_URL = import.meta.env.DEV ? "/config.json" : "./config.json";
const MAX_CSV_BYTES = 64 * 1024;
export function unwrapInvokeResponse(payload) {
if (!payload || typeof payload !== "object") return payload;
if ("result" in payload) return payload.result;
if ("output" in payload) return payload.output;
return payload;
}
export async function requestJson(url, init = {}) {
const response = await fetch(url, { credentials: "same-origin", ...init });
const text = await response.text();
@@ -39,11 +46,12 @@ export function signInUrl(config) {
export async function callSkill(config, skillName, args) {
try {
return await requestJson(`${config.endpoints.invoke}/${encodeURIComponent(skillName)}`, {
const payload = await requestJson(`${config.endpoints.invoke}/${encodeURIComponent(skillName)}`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ arguments: args }),
});
return unwrapInvokeResponse(payload);
} catch (err) {
if (err.status === 401) {
const target = signInUrl(config);
@@ -55,10 +63,7 @@ export async function callSkill(config, skillName, args) {
}
export function unwrapA2AResult(response) {
if (!response || typeof response !== "object") return response;
if ("result" in response) return response.result;
if ("output" in response) return response.output;
return response;
return unwrapInvokeResponse(response);
}
export async function fileToBrowserUpload(file) {