fix frontend invoke result handling
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
export const CONFIG_URL = import.meta.env.DEV ? "/config.json" : "./config.json";
|
export const CONFIG_URL = import.meta.env.DEV ? "/config.json" : "./config.json";
|
||||||
|
|
||||||
|
export function unwrapInvokeResponse(payload) {
|
||||||
|
return payload && typeof payload === "object" && "result" in payload
|
||||||
|
? payload.result
|
||||||
|
: 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();
|
||||||
@@ -36,11 +42,12 @@ export function signInUrl(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function callSkill(config, skillName, args) {
|
export async function callSkill(config, skillName, args) {
|
||||||
return 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function needsInvokeSession(config, session) {
|
export function needsInvokeSession(config, session) {
|
||||||
|
|||||||
Reference in New Issue
Block a user