@nextclaw/kernel 0.1.17 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +32 -5
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -3566,6 +3566,37 @@ function getPanelAppBridgeScript() {
|
|
|
3566
3566
|
});
|
|
3567
3567
|
}
|
|
3568
3568
|
|
|
3569
|
+
function unwrapServiceActionResult(result) {
|
|
3570
|
+
if (!result || typeof result !== "object") {
|
|
3571
|
+
return result;
|
|
3572
|
+
}
|
|
3573
|
+
if (Object.prototype.hasOwnProperty.call(result, "structuredContent") && result.structuredContent !== undefined) {
|
|
3574
|
+
return result.structuredContent;
|
|
3575
|
+
}
|
|
3576
|
+
const content = Array.isArray(result.content) ? result.content : undefined;
|
|
3577
|
+
if (content && content.length === 1 && content[0]?.type === "text" && typeof content[0].text === "string") {
|
|
3578
|
+
try {
|
|
3579
|
+
return JSON.parse(content[0].text);
|
|
3580
|
+
} catch {
|
|
3581
|
+
return content[0].text;
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
return result;
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
function resolveBridgeData(entry, data) {
|
|
3588
|
+
if (entry.method === "list") {
|
|
3589
|
+
return Array.isArray(data.data?.actions) ? data.data.actions : [];
|
|
3590
|
+
}
|
|
3591
|
+
if (entry.method === "invoke") {
|
|
3592
|
+
return unwrapServiceActionResult(data.data?.result);
|
|
3593
|
+
}
|
|
3594
|
+
if (entry.method === "agent.generateObject") {
|
|
3595
|
+
return data.data?.result;
|
|
3596
|
+
}
|
|
3597
|
+
return data.data;
|
|
3598
|
+
}
|
|
3599
|
+
|
|
3569
3600
|
window.addEventListener("message", (event) => {
|
|
3570
3601
|
const data = event.data;
|
|
3571
3602
|
if (!data || data.type !== responseType || typeof data.requestId !== "string") {
|
|
@@ -3577,11 +3608,7 @@ function getPanelAppBridgeScript() {
|
|
|
3577
3608
|
}
|
|
3578
3609
|
pending.delete(data.requestId);
|
|
3579
3610
|
if (data.ok) {
|
|
3580
|
-
entry.resolve(
|
|
3581
|
-
entry.method === "invoke" || entry.method === "agent.generateObject"
|
|
3582
|
-
? data.data?.result
|
|
3583
|
-
: data.data
|
|
3584
|
-
);
|
|
3611
|
+
entry.resolve(resolveBridgeData(entry, data));
|
|
3585
3612
|
return;
|
|
3586
3613
|
}
|
|
3587
3614
|
const error = new Error(data.error?.message || "NextClaw panel bridge request failed.");
|