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