mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 08:00:59 +00:00
Simplify ConsoleRuntimeProvider to batch-send logs at completion only
This commit is contained in:
parent
af0297cd16
commit
6983ad4eaa
1 changed files with 8 additions and 31 deletions
|
|
@ -33,8 +33,8 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
||||||
info: console.info,
|
info: console.info,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Track pending logs (not yet confirmed sent)
|
// Collect logs locally, send at completion
|
||||||
const pendingLogs: Array<{ method: string; text: string; args: any[] }> = [];
|
const collectedLogs: Array<{ method: string; text: string; args: any[] }> = [];
|
||||||
|
|
||||||
["log", "error", "warn", "info"].forEach((method) => {
|
["log", "error", "warn", "info"].forEach((method) => {
|
||||||
(console as any)[method] = (...args: any[]) => {
|
(console as any)[method] = (...args: any[]) => {
|
||||||
|
|
@ -48,44 +48,21 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
||||||
})
|
})
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
const logEntry = { method, text, args };
|
// Collect log for batch send at completion
|
||||||
|
collectedLogs.push({ method, text, args });
|
||||||
// Add to pending logs
|
|
||||||
pendingLogs.push(logEntry);
|
|
||||||
|
|
||||||
// Try to send immediately (fire-and-forget)
|
|
||||||
if ((window as any).sendRuntimeMessage) {
|
|
||||||
(window as any)
|
|
||||||
.sendRuntimeMessage({
|
|
||||||
type: "console",
|
|
||||||
method,
|
|
||||||
text,
|
|
||||||
args, // Send raw args for provider collection
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// Remove from pending on successful send
|
|
||||||
const index = pendingLogs.indexOf(logEntry);
|
|
||||||
if (index !== -1) {
|
|
||||||
pendingLogs.splice(index, 1);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
// Keep in pending array if send fails
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always log locally too
|
// Always log locally too
|
||||||
(originalConsole as any)[method].apply(console, args);
|
(originalConsole as any)[method].apply(console, args);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register completion callback to send any remaining logs
|
// Register completion callback to send all collected logs
|
||||||
if ((window as any).onCompleted) {
|
if ((window as any).onCompleted) {
|
||||||
(window as any).onCompleted(async (_success: boolean) => {
|
(window as any).onCompleted(async (_success: boolean) => {
|
||||||
// Send any logs that haven't been sent yet
|
// Send all collected logs
|
||||||
if (pendingLogs.length > 0 && (window as any).sendRuntimeMessage) {
|
if (collectedLogs.length > 0 && (window as any).sendRuntimeMessage) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pendingLogs.map((logEntry) =>
|
collectedLogs.map((logEntry) =>
|
||||||
(window as any).sendRuntimeMessage({
|
(window as any).sendRuntimeMessage({
|
||||||
type: "console",
|
type: "console",
|
||||||
method: logEntry.method,
|
method: logEntry.method,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue