mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 18:05:11 +00:00
Pass return value through execution-complete message instead of logging
- Return value now passed to window.complete(error, returnValue) - execution-complete message includes returnValue field - SandboxResult interface updated to include returnValue - executionConsumer passes returnValue in resolved promise - Return values properly captured and available to callers
This commit is contained in:
parent
9a3f01fcb8
commit
5fc3857666
2 changed files with 5 additions and 8 deletions
|
|
@ -16,6 +16,7 @@ export interface SandboxResult {
|
||||||
console: Array<{ type: string; text: string }>;
|
console: Array<{ type: string; text: string }>;
|
||||||
files?: SandboxFile[];
|
files?: SandboxFile[];
|
||||||
error?: { message: string; stack: string };
|
error?: { message: string; stack: string };
|
||||||
|
returnValue?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -189,7 +190,7 @@ export class SandboxIframe extends LitElement {
|
||||||
} else if (message.type === "execution-complete") {
|
} else if (message.type === "execution-complete") {
|
||||||
completed = true;
|
completed = true;
|
||||||
cleanup();
|
cleanup();
|
||||||
resolve({ success: true, console: logs, files });
|
resolve({ success: true, console: logs, files, returnValue: message.returnValue });
|
||||||
return true;
|
return true;
|
||||||
} else if (message.type === "execution-error") {
|
} else if (message.type === "execution-error") {
|
||||||
completed = true;
|
completed = true;
|
||||||
|
|
@ -335,11 +336,6 @@ export class SandboxIframe extends LitElement {
|
||||||
|
|
||||||
const returnValue = await userCodeFunc();
|
const returnValue = await userCodeFunc();
|
||||||
|
|
||||||
// Log return value if present
|
|
||||||
if (returnValue !== undefined) {
|
|
||||||
console.log('Return value:', returnValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call completion callbacks before complete()
|
// Call completion callbacks before complete()
|
||||||
if (window.__completionCallbacks && window.__completionCallbacks.length > 0) {
|
if (window.__completionCallbacks && window.__completionCallbacks.length > 0) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -349,7 +345,7 @@ export class SandboxIframe extends LitElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await window.complete();
|
await window.complete(null, returnValue);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error?.stack || error?.message || String(error));
|
console.error(error?.stack || error?.message || String(error));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
||||||
|
|
||||||
// Expose complete() method for user code to call
|
// Expose complete() method for user code to call
|
||||||
let completionSent = false;
|
let completionSent = false;
|
||||||
(window as any).complete = async (error?: { message: string; stack: string }) => {
|
(window as any).complete = async (error?: { message: string; stack: string }, returnValue?: any) => {
|
||||||
if (completionSent) return;
|
if (completionSent) return;
|
||||||
completionSent = true;
|
completionSent = true;
|
||||||
|
|
||||||
|
|
@ -138,6 +138,7 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
||||||
console.log("Reporting execution complete");
|
console.log("Reporting execution complete");
|
||||||
await (window as any).sendRuntimeMessage({
|
await (window as any).sendRuntimeMessage({
|
||||||
type: "execution-complete",
|
type: "execution-complete",
|
||||||
|
returnValue,
|
||||||
});
|
});
|
||||||
console.log("Execution completed");
|
console.log("Execution completed");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue